GPU: how to render depth to a higher subresource?
It seems that SDL_BeginGPURenderPass always binds the first subresource of the depth texture. SDL_GPUDepthStencilTargetInfo has no mip_level and layer_or_depth_plane fields, and the backends seem to pass zero for these to the underlying APIs. Is this feature not available in SDL_gpu? This is needed when rendering shadow maps for point lights into cubemaps. Without it one would have to render into a temporary texture and then issue a copy.
We overlooked the case where someone would want to render into a depth cubemap. We're going to need a BeginRenderPass2 eventually anyway to support graphics stage storage writes. For now you can just use the copy workaround and we'll provide a path for this later.
I arrived here after also attempting to render a point light into a depth cubemap. Looking forward to being able to do that without extra copying. thanks.
EDIT:
I think i am stuck.
Attempting to create a depth cubemap for a point light.
- Create a single depth texture with usage
SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER; - Create a cubemap depth texture with usage
SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER; - Loop 6 times
- Render into single depth texture - and then Blit into "blitInfo.destination.layer_or_depth_plane = i; " face of the cubemap.
Error:
Blit destination texture must be created with the COLOR_TARGET usage flag
Change step 2 to create with usage:
SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
Error:
'!"For depth textures: usage cannot contain any flags except for DEPTH_STENCIL_TARGET and SAMPLER"'
I've run into the same issue as @Gibbon99. Anyone know a way around this? If I disable debugging when creating the SDL_GPUDevice it works fine. Is there a reason you can't allow blitting depth textures and require a color target? I see the cubemap in renderdoc and it looks correct.
I've located in the source code line 2785 of SDL_gpu.c the following...
if ((dstHeader->info.usage & SDL_GPU_TEXTUREUSAGE_COLOR_TARGET) == 0) {
SDL_assert_release(!"Blit destination texture must be created with the COLOR_TARGET usage flag");
failed = true;
}
if (IsDepthFormat(srcHeader->info.format)) {
SDL_assert_release(!"Blit source texture cannot have a depth format");
failed = true;
}
Vulkan provides a very robust built-in blit functionality, but the other APIs do not. Implementing a blit that is Vulkan-conformant on every backend is extremely difficult, so we decided to simplify the capabilities of our blit function. The reason the debug check is there is because if you run this code on something other than the Vulkan backend it will fail.
Basically, it's hard for us to provide a blit function that works for absolutely every combination of parameters, but it's easy for the client to just set up a pipeline to do the specific blit they want. If you need to blit depth data you can just set up a render pipeline to do that.
At any rate this is a different thing from the original issue, so let's please stay on topic.
Makes sense, thanks for the info. I will go down that route.
Bump