Browse Source
Auto free finished vulkan command buffers in gpu interop feature implementation (#17782)
pull/17812/head
Nikita Tsukanov
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
7 additions and
4 deletions
-
src/Avalonia.Vulkan/Interop/VulkanCommandBufferPool.cs
-
src/Avalonia.Vulkan/VulkanExternalObjectsFeature.cs
|
|
|
@ -7,13 +7,15 @@ namespace Avalonia.Vulkan.Interop; |
|
|
|
internal class VulkanCommandBufferPool : IDisposable |
|
|
|
{ |
|
|
|
private readonly IVulkanPlatformGraphicsContext _context; |
|
|
|
private readonly bool _autoFree; |
|
|
|
private readonly Queue<VulkanCommandBuffer> _commandBuffers = new(); |
|
|
|
private VkCommandPool _handle; |
|
|
|
public VkCommandPool Handle => _handle; |
|
|
|
|
|
|
|
public VulkanCommandBufferPool(IVulkanPlatformGraphicsContext context) |
|
|
|
public VulkanCommandBufferPool(IVulkanPlatformGraphicsContext context, bool autoFree = false) |
|
|
|
{ |
|
|
|
_context = context; |
|
|
|
_autoFree = autoFree; |
|
|
|
var createInfo = new VkCommandPoolCreateInfo |
|
|
|
{ |
|
|
|
sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, |
|
|
|
@ -53,6 +55,9 @@ internal class VulkanCommandBufferPool : IDisposable |
|
|
|
|
|
|
|
public unsafe VulkanCommandBuffer CreateCommandBuffer() |
|
|
|
{ |
|
|
|
if (_autoFree) |
|
|
|
FreeFinishedCommandBuffers(); |
|
|
|
|
|
|
|
var commandBufferAllocateInfo = new VkCommandBufferAllocateInfo |
|
|
|
{ |
|
|
|
sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, |
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ internal unsafe class VulkanExternalObjectsFeature : IVulkanContextExternalObjec |
|
|
|
var uuid = new Span<byte>(physicalDeviceIDProperties.deviceUUID, 16).ToArray(); |
|
|
|
if (uuid.Any(b => b != 0)) |
|
|
|
DeviceUuid = uuid; |
|
|
|
_pool = new VulkanCommandBufferPool(_context); |
|
|
|
_pool = new VulkanCommandBufferPool(_context, true); |
|
|
|
} |
|
|
|
|
|
|
|
public IReadOnlyList<string> SupportedImageHandleTypes { get; } |
|
|
|
@ -111,10 +111,8 @@ internal unsafe class VulkanExternalObjectsFeature : IVulkanContextExternalObjec |
|
|
|
|
|
|
|
public IVulkanExternalImage ImportImage(IPlatformHandle handle, PlatformGraphicsExternalImageProperties properties) |
|
|
|
{ |
|
|
|
_pool.FreeFinishedCommandBuffers(); |
|
|
|
if (!SupportedImageHandleTypes.Contains(handle.HandleDescriptor)) |
|
|
|
throw new NotSupportedException(); |
|
|
|
|
|
|
|
|
|
|
|
return new ImportedImage(_context, _pool, handle, properties); |
|
|
|
} |
|
|
|
|