Vulkan validation error when creating a 3D texture for compute shader writing + sampling with SDL3 GPU
I want to create a 3D texture to write to in a compute shader and then use it as a sampler in a fragment shader. I don't know if it's only with 3D textures, this is the one I tried.
Validation Error: [ VUID-VkImageMemoryBarrier-oldLayout-01197 ] | MessageID = 0x124ffb34
vkCmdPipelineBarrier(): pImageMemoryBarriers[0].image (VkImage 0x880000000088) cannot transition the layout of aspect=1, level=0, layer=0 from VK_IMAGE_LAYOUT_GENERAL when the previous known layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.
The Vulkan spec states: If layouts are not ignored, oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED or the current layout of the image subresources affected by the barrier (https://docs.vulkan.org/spec/latest/chapters/synchronization.html#VUID-VkImageMemoryBarrier-oldLayout-01197)
Objects: 2
[0] VkCommandBuffer 0x55a5b45e4b40
[1] VkImage 0x880000000088In my case this is the texture: type: SDL_GPU_TEXTURE_3D format: SDL_GPU_TEXTUREFORMAT_R8_UNORM usage: SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE | SDL_GPU_TEXTUREUSAGE_SAMPLER width, height, depth: 256, 256, 256
It seems that as soon as I add the SDL_GPU_TEXTUREUSAGE_SAMPLER flag to the usage, the image is no longer bound as writable. I think this is an SDL bug.
I haven't tried it yet, but a solution could probably be using SDL_CopyGPUTextureToTexture to copy the texture to another texture. That's not very optimal of course.
Update: On my system the texture seems to work fine, even after the Vulkan error (read back to files), haven't tested if I can sample them in shader. Because I can't rely on this working everywhere.
Source: libsdl-org/SDL