SDL_CreateGPUShader(3)
π NAME π
okay bestie, so this page is SDL_CreateGPUShader(3) β it lives in the SDL3 FUNCTIONS section of the manual, and it's literally the glow-up moment where a shader gets born β¨. Short version: SDL_CreateGPUShader creates a shader you'll use when you're building a graphics pipeline. That's it, that's the vibe. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_gpu.h>
SDL_GPUShader * SDL_CreateGPUShader(
SDL_GPUDevice *device,
const SDL_GPUShaderCreateInfo *createinfo);
π¦ DESCRIPTION π¦
no cap, this is the part you actually need to read π. Shader resource bindings must be authored to follow a particular order, and that order depends on the shader format you're using. So pick your fighter and match the layout exactly, fr fr.
π For SPIR-V shaders, use the following resource sets:
For vertex shaders:
0: Sampled textures, followed by storage textures, followed by storage buffers1: Uniform buffers
For fragment shaders:
2: Sampled textures, followed by storage textures, followed by storage buffers3: Uniform buffers
π For DXBC and DXIL shaders, use the following register order:
For vertex shaders:
(t[n], space0): Sampled textures, followed by storage textures, followed by storage buffers(s[n], space0): Samplers with indices corresponding to the sampled textures(b[n], space1): Uniform buffers
For pixel shaders:
(t[n], space2): Sampled textures, followed by storage textures, followed by storage buffers(s[n], space2): Samplers with indices corresponding to the sampled textures(b[n], space3): Uniform buffers
π For MSL/metallib, use the following order:
[[texture]]: Sampled textures, followed by storage textures[[sampler]]: Samplers with indices corresponding to the sampled textures[[buffer]]: Uniform buffers, followed by storage buffers. Vertex buffer 0 is bound at[[buffer(14)]], vertex buffer 1 at[[buffer(15)]], and so on. Rather than manually authoring vertex buffer indices, use the[[stage_in]]attribute which will automatically use the vertex input information from theSDL_GPUGraphicsPipeline.
okay so, next thing: shader semantics other than system-value semantics do not matter in D3D12 π. And for ease of use, the SDL implementation assumes that non system-value semantics will all be TEXCOORD. So if you're using HLSL as the shader source language, your vertex semantics should start at TEXCOORD0 and increment like so: TEXCOORD1, TEXCOORD2, etc. And if you wish to change the semantic prefix to something other than TEXCOORD, you can use SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING with SDL_CreateGPUDeviceWithProperties(). iconic behavior honestly π
There are optional properties that can be provided through props. These are the supported properties:
SDL_PROP_GPU_SHADER_CREATE_NAME_STRINGβ a name that can be displayed in debugging tools. (yes bestie, name your babies, future-you debugging at 3am will thank you π«Ά)
β FUNCTION PARAMETERS β
deviceβ a GPU Context.createinfoβ a struct describing the state of the shader to create.
π₯ RETURN VALUE π₯
Returns a shader object on success, or NULL on failure π. And when it's NULL, call SDL_GetError() for more information β that's your group chat receipts, go read them.
π AVAILABILITY π
This function is available since SDL 3.2.0. periodt.
π SEE ALSO π
and that's the whole page, bestie π this one shipped as part of Simple Directmedia Layer, version SDL 3.4.18 β written by the SDL crew, mwah, tysm for the GPU API, we are obsessed π§β¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms