veldrid / veldrid

A low-level, portable graphics library for .NET.
https://veldrid.dev/
MIT License
2.5k stars 272 forks source link

[Vulkan] TextureView destroyed while still in use #182

Open sa-exe opened 5 years ago

sa-exe commented 5 years ago

If I understand correctly, now that the Vulkan backend uses reference counting, this should never happen.

A Vulkan validation error was encountered: [ErrorEXT] (ImageViewEXT)  [ VUID-vkDestroyImageView-imageView-01026 ] Object: 0x45e (Type = 14) | Cannot call vkDestroyImageView on ImageView 0x45e that is currently in use by a command buffer. The Vulkan spec states: All submitted commands that refer to imageView must have completed execution (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-vkDestroyImageView-imageView-01026)
   at Veldrid.Vk.VkGraphicsDevice.DebugCallback(UInt32 flags, VkDebugReportObjectTypeEXT objectType, UInt64 object, UIntPtr location, Int32 messageCode, Byte* pLayerPrefix, Byte* pMessage, Void* pUserData) in S:\mellinoe\veldrid\src\Veldrid\Vk\VkGraphicsDevice.cs:line 614
   at Vulkan.VulkanNative.vkDestroyImageView(VkDevice device, VkImageView imageView, VkAllocationCallbacks* pAllocator)
   at Veldrid.Vk.VkTextureView.DisposeCore() in S:\mellinoe\veldrid\src\Veldrid\Vk\VkTextureView.cs:line 95
   at Veldrid.Vk.ResourceRefCount.Decrement() in S:\mellinoe\veldrid\src\Veldrid\Vk\ResourceRefCount.cs:line 34
   at Veldrid.Vk.VkTextureView.Dispose() in S:\mellinoe\veldrid\src\Veldrid\Vk\VkTextureView.cs:line 87
   at Veldrid.Texture.Dispose() in S:\mellinoe\veldrid\src\Veldrid\Texture.cs:line 94
   at Veldrid.Vk.VkTexture.RefCountedDispose() in S:\mellinoe\veldrid\src\Veldrid\Vk\VkTexture.cs:line 390
   at Veldrid.Vk.ResourceRefCount.Decrement() in S:\mellinoe\veldrid\src\Veldrid\Vk\ResourceRefCount.cs:line 34
   at Veldrid.Vk.VkTexture.DisposeCore() in S:\mellinoe\veldrid\src\Veldrid\Vk\VkTexture.cs:line 383
   at Veldrid.Texture.Dispose() in S:\mellinoe\veldrid\src\Veldrid\Texture.cs:line 97

I haven't been able to extract a minimal repro yet. This only happens in a real project, when it tries to unload a few hundred textures in a row.

mellinoe commented 5 years ago

If I understand correctly, now that the Vulkan backend uses reference counting, this should never happen.

Yes, that's right. With the caveat that it is actually submitting the CommandList which increments the used resources ref counts. So if you record a command with a TextureView, delete the TextureView, and then submit the CommandList, you could potentially see this. Without that scenario, this shouldn't happen.