Xatian
Xatian

Reputation: 972

Is it valid according to the Vulkan specification to have a destroyed image still referenced by the descriptor set?

I'm developing an application using Vulkan and I have encountered an issue related to memory management and descriptor sets. In my application, I am using a shader that incorporates a texture array as follows:

layout(set = 0, binding = 1) uniform texture2D textures[count];

I'm also leveraging the feature descriptorBindingPartiallyBound, as I do not initially have all textures available when the application starts. At certain points, my descriptor set has some of the texture slots filled and is used by the shader without any problems.

The issue arises when I attempt to destroy one of the used textures and free its associated memory. To do this, I destroy the VkImageView, the VkImage, and free the VkMemory. This process happens in between frames, when nothing is accessing the descriptor set and all command buffers are reset. However, in the subsequent frame when I bind the descriptor set and try to draw again, Valgrind points out an error within the driver code. Subsequent attempts to submit the command buffer using vkQueueSubmit result in an error message --> "CS rejected"

My main question is: according to the Vulkan specification, is it valid to have a destroyed VkImageView still referenced by a descriptor set? The spec states that with descriptorBindingPartiallyBound enabled,

that descriptors in this binding that are not dynamically used need not contain valid descriptors at the time the descriptors are consumed

and

If a descriptor is not dynamically used, any resource referenced by the descriptor is not considered to be referenced during command execution.

To me this reads as "destroyed is fine as long as it is unused". But it does not work so ...

Any insights into whether this is an issue with my interpretation of the Vulkan spec or potentially a driver issue would be greatly appreciated. Thank you!

Upvotes: 0

Views: 667

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474226

"Invalid" and "destroyed" are not the same thing. Vulkan has an explicit requirement in both vkDestroyImage and vkDestroyImageView that the all commands which have been submitted that reference the image/view must have completed execution before calling that function: "all submitted commands that refer to image, either directly or via a VkImageView, must have completed execution"

So you have to make sure you're destroying the image/view after previous commands have completed but before you've submitted any new commands that use the descriptor. The standard specifically says, "Descriptors also become undefined if the underlying resource or view object is destroyed." So you should be fine after ensuring the above.

That being said, Valgrind can disagree on various matters, so it may be best to reset those descriptors to known values.

Upvotes: 2

Related Questions