sdlCreateGpuShader function

Pointer<SdlGpuShader> sdlCreateGpuShader(
  1. Pointer<SdlGpuDevice> device,
  2. Pointer<SdlGpuShaderCreateInfo> createinfo
)

Creates a shader to be used when creating a graphics pipeline.

Shader resource bindings must be authored to follow a particular order depending on the shader format.

For SPIR-V shaders, use the following resource sets:

For vertex shaders:

  • 0: Sampled textures, followed by storage textures, followed by storage buffers
  • 1: Uniform buffers

For fragment shaders:

  • 2: Sampled textures, followed by storage textures, followed by storage buffers
  • 3: Uniform buffers

For DXBC and DXIL shaders, use the following register order:

For vertex shaders:

  • (tn, space0): Sampled textures, followed by storage textures, followed by storage buffers
  • (sn, space0): Samplers with indices corresponding to the sampled textures
  • (bn, space1): Uniform buffers

For pixel shaders:

  • (tn, space2): Sampled textures, followed by storage textures, followed by storage buffers
  • (sn, space2): Samplers with indices corresponding to the sampled textures
  • (bn, 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 the SDL_GPUGraphicsPipeline.

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. If you are using HLSL as the shader source language, your vertex semantics should start at TEXCOORD0 and increment like so: TEXCOORD1, TEXCOORD2, etc. 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().

\param device a GPU Context. \param createinfo a struct describing the state of the shader to create. \returns a shader object on success, or NULL on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.1.3.

\sa SDL_CreateGPUGraphicsPipeline \sa SDL_ReleaseGPUShader

extern SDL_DECLSPEC SDL_GPUShader *SDLCALL SDL_CreateGPUShader( SDL_GPUDevice *device, const SDL_GPUShaderCreateInfo *createinfo)

Implementation

Pointer<SdlGpuShader> sdlCreateGpuShader(
    Pointer<SdlGpuDevice> device, Pointer<SdlGpuShaderCreateInfo> createinfo) {
  final sdlCreateGpuShaderLookupFunction = libSdl3.lookupFunction<
      Pointer<SdlGpuShader> Function(Pointer<SdlGpuDevice> device,
          Pointer<SdlGpuShaderCreateInfo> createinfo),
      Pointer<SdlGpuShader> Function(Pointer<SdlGpuDevice> device,
          Pointer<SdlGpuShaderCreateInfo> createinfo)>('SDL_CreateGPUShader');
  return sdlCreateGpuShaderLookupFunction(device, createinfo);
}