Browse Source

Auto free finished vulkan command buffers in gpu interop feature implementation (#17782)

release/11.2.3
Nikita Tsukanov 2 years ago
committed by Max Katz
parent
commit
9ad2ad61d8
  1. 7
      src/Avalonia.Vulkan/Interop/VulkanCommandBufferPool.cs
  2. 4
      src/Avalonia.Vulkan/VulkanExternalObjectsFeature.cs

7
src/Avalonia.Vulkan/Interop/VulkanCommandBufferPool.cs

@ -7,13 +7,15 @@ namespace Avalonia.Vulkan.Interop;
internal class VulkanCommandBufferPool : IDisposable internal class VulkanCommandBufferPool : IDisposable
{ {
private readonly IVulkanPlatformGraphicsContext _context; private readonly IVulkanPlatformGraphicsContext _context;
private readonly bool _autoFree;
private readonly Queue<VulkanCommandBuffer> _commandBuffers = new(); private readonly Queue<VulkanCommandBuffer> _commandBuffers = new();
private VkCommandPool _handle; private VkCommandPool _handle;
public VkCommandPool Handle => _handle; public VkCommandPool Handle => _handle;
public VulkanCommandBufferPool(IVulkanPlatformGraphicsContext context) public VulkanCommandBufferPool(IVulkanPlatformGraphicsContext context, bool autoFree = false)
{ {
_context = context; _context = context;
_autoFree = autoFree;
var createInfo = new VkCommandPoolCreateInfo var createInfo = new VkCommandPoolCreateInfo
{ {
sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
@ -53,6 +55,9 @@ internal class VulkanCommandBufferPool : IDisposable
public unsafe VulkanCommandBuffer CreateCommandBuffer() public unsafe VulkanCommandBuffer CreateCommandBuffer()
{ {
if (_autoFree)
FreeFinishedCommandBuffers();
var commandBufferAllocateInfo = new VkCommandBufferAllocateInfo var commandBufferAllocateInfo = new VkCommandBufferAllocateInfo
{ {
sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,

4
src/Avalonia.Vulkan/VulkanExternalObjectsFeature.cs

@ -92,7 +92,7 @@ internal unsafe class VulkanExternalObjectsFeature : IVulkanContextExternalObjec
var uuid = new Span<byte>(physicalDeviceIDProperties.deviceUUID, 16).ToArray(); var uuid = new Span<byte>(physicalDeviceIDProperties.deviceUUID, 16).ToArray();
if (uuid.Any(b => b != 0)) if (uuid.Any(b => b != 0))
DeviceUuid = uuid; DeviceUuid = uuid;
_pool = new VulkanCommandBufferPool(_context); _pool = new VulkanCommandBufferPool(_context, true);
} }
public IReadOnlyList<string> SupportedImageHandleTypes { get; } public IReadOnlyList<string> SupportedImageHandleTypes { get; }
@ -111,10 +111,8 @@ internal unsafe class VulkanExternalObjectsFeature : IVulkanContextExternalObjec
public IVulkanExternalImage ImportImage(IPlatformHandle handle, PlatformGraphicsExternalImageProperties properties) public IVulkanExternalImage ImportImage(IPlatformHandle handle, PlatformGraphicsExternalImageProperties properties)
{ {
_pool.FreeFinishedCommandBuffers();
if (!SupportedImageHandleTypes.Contains(handle.HandleDescriptor)) if (!SupportedImageHandleTypes.Contains(handle.HandleDescriptor))
throw new NotSupportedException(); throw new NotSupportedException();
return new ImportedImage(_context, _pool, handle, properties); return new ImportedImage(_context, _pool, handle, properties);
} }

Loading…
Cancel
Save