From 7cd5d339e52b1c77a1d97c322fabc65f4e5e7c65 Mon Sep 17 00:00:00 2001 From: Andrej Benedik Date: Fri, 20 Mar 2026 13:05:48 +0100 Subject: [PATCH] Fixed creating RenderTarget when using Vulkan backend (#20952) * Updated VulkanContext.TryGetFeature to also provide IVulkanKhrSurfacePlatformSurfaceFactory This also fixed creating new RenderTarget when using Vulkan backend, see issue #20824 * Prevent duplicate check if _renderTarget is null --- .../Composition/Server/ServerCompositionTarget.cs | 12 ++++++++---- src/Avalonia.Vulkan/VulkanContext.cs | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs b/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs index 81a3c09b35..e8ae84eb03 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs @@ -149,12 +149,16 @@ namespace Avalonia.Rendering.Composition.Server try { - if (_renderTarget == null && !_compositor.IsReadyToCreateRenderTarget(_surfaces())) + if (_renderTarget == null) { - IsWaitingForReadyRenderTarget = IsEnabled; - return; + if (!_compositor.IsReadyToCreateRenderTarget(_surfaces())) + { + IsWaitingForReadyRenderTarget = IsEnabled; + return; + } + + _renderTarget = _compositor.CreateRenderTarget(_surfaces()); } - _renderTarget ??= _compositor.CreateRenderTarget(_surfaces()); } catch (RenderTargetNotReadyException) { diff --git a/src/Avalonia.Vulkan/VulkanContext.cs b/src/Avalonia.Vulkan/VulkanContext.cs index 6667055e8c..8691e55a05 100644 --- a/src/Avalonia.Vulkan/VulkanContext.cs +++ b/src/Avalonia.Vulkan/VulkanContext.cs @@ -41,6 +41,10 @@ internal class VulkanContext : IVulkanPlatformGraphicsContext { if (featureType == typeof(IVulkanContextExternalObjectsFeature)) return _externalObjectsFeature; + + if (featureType == typeof(IVulkanKhrSurfacePlatformSurfaceFactory)) + return _surfaceFactory; + return null; } @@ -71,4 +75,4 @@ internal class VulkanContext : IVulkanPlatformGraphicsContext throw new VulkanException("Unable to find a suitable platform surface"); } -} \ No newline at end of file +}