I’m trying to port a bloom effect to SDL GPU and have hit a snag. The bloom effect is implemented in a classic way where it downsamples and blurs along the mipmap pyramid of a render texture (mip #0 → mip #1, mip #1 → mip #2, etc.).
This requires binding the same texture both to a sampler and as a color target, but using different mip levels for reading/writing. It’s easy to select a mip to write to (using SDL_GPUColorTargetInfo), but I can’t find a way to limit what a sampler is allowed to read from to prevent a read/write conflict.
Is there a good way to do this?
What I tried:
I tried using min_lod and max_lod on SDL_GPUSamplerCreateInfo to force just one mip level, which is similar to how it was done in OpenGL using GL_TEXTURE_BASE_LEVEL/GL_TEXTURE_MAX_LEVEL.
GPU: same-texture read/write bindings at different mip levels and read-only depth+sampler usage? · Issue #13871 · libsdl-org/SDL · GitHub seems to suggest this would work, but it doesn’t seem to do anything, and looking at SDL_gpu_vulkan.c, it doesn’t seem like min_lod/max_lod affects anything other than the sampler.
Under the Vulkan backend, the end result is this:
Cannot use VkImage 0xb4d0000000b4d[?RenderBuffer:bloom] (layer 0, mip 1) with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL (specified by combined image sampler descriptor [VkDescriptorSet 0x9240000000924, Set 2, Binding 0, Index 0, variable "buffer_Bloom"]) that doesn't match the previous known layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL.
I assume this means that SDL GPU binds the whole texture to the sampler anyway, causing an image layout mismatch for the mip being written to since it’s trying to be both SHADER_READ_ONLY (due to being sampled) and COLOR_ATTACHMENT (due to being written to).