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

Memory leak in Vulkan Renderer #17363

Closed
iejeecee opened this issue Oct 27, 2024 · 2 comments · Fixed by #17782
Closed

Memory leak in Vulkan Renderer #17363

iejeecee opened this issue Oct 27, 2024 · 2 comments · Fixed by #17782
Labels

Comments

@iejeecee
Copy link

Describe the bug

The Vulkan Command Buffers created in the function ImportedSemaphore.SubmitSemaphore in the file Avalonia.Vulkan.VulkanExternalObjectsFeature.cs are never released causing a memory leak.

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Vulkan/VulkanExternalObjectsFeature.cs#L171

Adding a call to _pool.FreeFinishedCommandBuffers() at the beginning of the function fixes the leak, but I cannot oversee if this breaks something unintentionally

void SubmitSemaphore(VulkanSemaphore? wait, VulkanSemaphore? signal)
{
    _pool.FreeFinishedCommandBuffers();

    var buf = _pool.CreateCommandBuffer();
    buf.BeginRecording();
    _context.DeviceApi.CmdPipelineBarrier(
        buf.Handle,
        VkPipelineStageFlags.VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
        VkPipelineStageFlags.VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
        0,
        0,
        IntPtr.Zero,
        0,
        IntPtr.Zero,
        0,
        null);
    
    buf.EndRecording();
    buf.Submit(wait != null ? new[] { wait }.AsSpan() : default,
        new[] { VkPipelineStageFlags.VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT },
        signal != null ? new[] { signal }.AsSpan() : default);
}

To Reproduce

E.g running the GpuInterop sample (with a Vulkan backend) and continuously modifying the teapot causing the screen to update. You can observe the memory leak in Task Manager on Windows

Expected behavior

Expected behavior is that the amount of memory allocated doesn't keep increasing while moving the teapot around

Avalonia version

11.1.4

OS

Windows

Additional context

No response

@iejeecee iejeecee added the bug label Oct 27, 2024
@Gillibald
Copy link
Contributor

@kekekeks

@kekekeks
Copy link
Member

We probably want to do that once per frame rather than in random parts of the codebase (like we currently do with ImportImage).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants