---
name: "SDL_CreateGPUShader"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_CreateGPUShader"
---

# SDL\_CreateGPUShader(3)

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

## NAME

SDL\_CreateGPUShader - Creates a shader to be used when creating a graphics pipeline.

## HEADER FILE

Defined in SDL3/SDL\_gpu.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**SDL\_GPUShader \* SDL\_CreateGPUShader(**     **SDL\_GPUDevice \*device,**     **const SDL\_GPUShaderCreateInfo \*createinfo);**

## DESCRIPTION

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:

• (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 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** ().

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.

## FUNCTION PARAMETERS

- *device*

  a GPU Context.

- *createinfo*

  a struct describing the state of the shader to create.

## RETURN VALUE

( **SDL\_GPUShader**\
  \*) Returns a shader object on success, or NULL on failure; call  **SDL\_GetError** () for more information.

## AVAILABILITY

This function is available since SDL 3.2.0.

## SEE ALSO

**•**(3), [**SDL\_CreateGPUGraphicsPipeline**(3)](/SDL_CreateGPUGraphicsPipeline/3.md), **•**(3), [**SDL\_ReleaseGPUShader**(3)](/SDL_ReleaseGPUShader/3.md)
