Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Avalonia.Vulkan/Interop/VulkanCommandBufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,6 +55,9 @@ public void Dispose()

public unsafe VulkanCommandBuffer CreateCommandBuffer()
{
if (_autoFree)
FreeFinishedCommandBuffers();

var commandBufferAllocateInfo = new VkCommandBufferAllocateInfo
{
sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
Expand Down
4 changes: 1 addition & 3 deletions src/Avalonia.Vulkan/VulkanExternalObjectsFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public VulkanExternalObjectsFeature(VulkanContext context)
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; }
Expand All @@ -111,10 +111,8 @@ public CompositionGpuImportedImageSynchronizationCapabilities GetSynchronization

public IVulkanExternalImage ImportImage(IPlatformHandle handle, PlatformGraphicsExternalImageProperties properties)
{
_pool.FreeFinishedCommandBuffers();
if (!SupportedImageHandleTypes.Contains(handle.HandleDescriptor))
throw new NotSupportedException();


return new ImportedImage(_context, _pool, handle, properties);
}
Expand Down
Loading