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

Fixing vulkan buffer destruction while in use. #7380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kecho
Copy link

@kecho kecho commented Mar 9, 2024

The function CreateOrResizeBuffer destroys vulkan buffers and memory while they could be alive and in use by the GPU.
This can be captured if the validation layer is used. Moreover this could cause very hard to track low repro crashes.

This fix ensures the device is idle before freeing GPU resources. An alternative solution is to have fence-style syncrhonization and a destruction queue, however this might add further complexity and is likely overkill for imgui. Since buffer recreation is relatively a low frequency operation I suspect this is enough.

Tested:

  • Home engine
  • Built vulkan examples.

@ocornut
Copy link
Owner

ocornut commented Apr 15, 2024

Hello,

Normally the ImGui_ImplVulkan_FrameRenderBuffers buffers are created for the maximum amount of in-flight frames.

What is your value for ImGui_ImplVulkan_InitInfo's MinImageCount and ImageCount and how do they related to your overall rendering setup? Perhaps those values should be increased to match your setup.

@ocornut
Copy link
Owner

ocornut commented Apr 30, 2024

@kecho Any update on this?

@kecho
Copy link
Author

kecho commented May 8, 2024

@ocornut sorry for the late reply. I have been busy with a new job.
Anyway, my setup has those two as the swap chain count, which is 2 on my application.
If my application goes beyond 2 frames it will wait on the aquire fence, so I am pretty sure that my application won't allocate beyond.

What I think is happening is that the vulkan validation sees that these buffers memory has been submitted already, and there's a possibility that the GPU is still processing.it. usually in vilkan and dx you'd push them to a delete queue and just poll it using a fence. Even if you are doubled buffered, because if you are trying to delete one buffer, you can't know if the GPU is still working with it. Effectively once a buffer has been submitted on a command you can't touch it until you know for sure the command has completed on the GPU, and I don't see how just double buffering would guarantee this. Maybe I am missing something? Sorry for the late reply again, very irresponsible of me

@kecho
Copy link
Author

kecho commented May 8, 2024

One more thing too, these are not image frame buffers. These seam to be raw buffers containing UI memory data.
I hit this validation issue when I click on the UI around and expand a panel, not when resizing the window.
Another important detail I forgot: my app is using the docking branch.

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

Successfully merging this pull request may close these issues.

None yet

2 participants