A bit confusion over how SDL3 handles shaders

(I’m very new to SDL3 and if my question doesn’t make sense, please point me out.)

I just learned that SDL3 now supports modern GPU backends. I checked the overview on Github, but got a bit confused over this:

The SDL3 GPU API only cares about compiled shader binaries, and it accepts several different formats. So if you want to force Vulkan behind the scenes and only provide SPIR-V binaries, or use Direct3D 12 and provide DXIL, or provide several binary formats and use several different backends, you can do that and not worry about this at all .

Does it mean the user has to handle shader compilation themselves? And they have to write the same shader in different languages for different platforms, like HLSL for Windows, MSL for Mac and WGSL for WebGPU? How about the consoles?

1 Like

Technically, yes.

But the developers have also released SDL_shadercross, a library/utility that allows you to provide a shader written in HLSL or GLSL (compiled to SPIRV) which will then translate your shader to other supported shader formats.

You can include SDL_shadercross as a library and ship it with your application (which means having to ship its dependency libraries like SPIRV-Cross) or use it as a command-line tool to translate your shader offline and then just ship the compiled shaders with your application.