VRAM leak with vuilkan external memory + opengl memory objects
In our xrdesktop project we have to create and destroy many textures shared with external memory between OpenGL and Vulkan.
This works fine the proprietary nvidia driver. After destroying the OpenGL and Vulkan texture, the VRAM is free to be reused.
On radv+radeonsi however, after destroying the OpenGL and Vulkan textures, the VRAM usage is not reduced, only when the process exits is the VRAM released. It is unclear if this is an issue in radv or radeonsi. We may also lack a step in cleanup, but haven't found an indication for that in the specs.
The flow is roughly
- create vulkan texture
- export fd for vulkan texture memory with external memory
- import fd into opengl texture with memory object
- delete opengl texture
- destroy vulkan texture (vkFreeMemory etc.)
A gobject based example application is in this repository: https://gitlab.freedesktop.org/xrdesktop/gulkan.git
If glew >= 2.1 and glfw3 is installed, then the example
build/tests/test_texture_external is compiled with
meson build; ninja -C build.
The first two tests this example executes are trivial and work fine. The third one is the interesting one:
= Testing external textures = Heap 0: usage 0.25 budget 5397.96 MB Heap 1: usage 0.00 budget 184.04 MB Heap 2: usage 0.57 budget 5661.70 MB Free texture VRAM before: 5789400 Free texture VRAM after: 3765336 OpenGL: Leaked: ~ 1976.62 MB Vulkan: Leaked ~ 1976.62 MB Heap 0: usage 0.25 budget 3421.34 MB Heap 1: usage 0.00 budget 3.35 MB Heap 2: usage 0.57 budget 5640.54 MB
I understand that this VRAM usage is not necessarily accurate, but you can check that it indicates a problem by increasing the loop variable in
_test_leak. With enough runs, the entire VRAM, GTT/system ram fills up and the OOM killer has to kill the example.