Skip to content

API ShaderCross

Eduard Gushchin edited this page Jun 12, 2026 · 2 revisions

SDL_shadercross API

Back to API Reference

Shader translation, compilation, and reflection functions.

  • Functions: 15
  • Functions with XML docs: 15

ShaderCross

ShaderCross.CompileComputePipelineFromSPIRV

public static IntPtr CompileComputePipelineFromSPIRV(IntPtr device, in ShaderCross.SPIRVInfo info, in ShaderCross.ComputePipelineMetadata metadata, uint props);

SDL declaration

extern SDL_DECLSPEC SDL_GPUComputePipeline * SDLCALL SDL_ShaderCross_CompileComputePipelineFromSPIRV(SDL_GPUDevice *device, const SDL_ShaderCross_SPIRV_Info *info, const SDL_ShaderCross_ComputePipelineMetadata *metadata, SDL_PropertiesID props);

Compile an SDL GPU compute pipeline from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from ShaderCross.CompileSPIRVFromHLSL.

Parameters

Name Type Description
device IntPtr the SDL GPU device.
info in ShaderCross.SPIRVInfo a struct describing the shader to transpile.
metadata in ShaderCross.ComputePipelineMetadata a struct describing shader metadata. Can be obtained from ShaderCross.ReflectComputeSPIRV.
props uint a properties object filled in with extra shader metadata.

Returns

a compiled SDL_GPUComputePipeline.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.CompileComputePipelineFromSPIRV(System.IntPtr,SDL3.ShaderCross.SPIRVInfo@,SDL3.ShaderCross.ComputePipelineMetadata@,System.UInt32)

ShaderCross.CompileDXBCFromHLSL

public static IntPtr CompileDXBCFromHLSL(in ShaderCross.HLSLInfo info, out UIntPtr size);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXBCFromHLSL(const SDL_ShaderCross_HLSL_Info *info, size_t *size);

Compile to DXBC bytecode from HLSL code via a SPIRV-Cross round trip. You must SDL.Free the returned buffer once you are done with it.

These are the optional properties that can be used:

  • ShaderCross.Props.ShaderDebugEnableBoolean: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
  • ShaderCross.Props.ShaderDebugNameString: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
  • ShaderCross.Props.ShaderCullUnusedBindingsBoolean: When true, indicates that the compiler should cull unused shader resources. This behavior is disabled by default.
  • ShaderCross.Props.HLSLSkipSPIRVRoundtripBoolean: When true, the SPIRV roundtrip is skipped. This behavior is disabled by default. Do not use this property if your shader uses Structured Buffers.

Parameters

Name Type Description
info in ShaderCross.HLSLInfo a struct describing the shader to transpile.
size out UIntPtr filled in with the bytecode buffer size.

Returns

an SDL_malloc'd buffer containing DXBC bytecode.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.CompileDXBCFromHLSL(SDL3.ShaderCross.HLSLInfo@,System.UIntPtr@)

ShaderCross.CompileDXBCFromSPIRV

public static IntPtr CompileDXBCFromSPIRV(in ShaderCross.SPIRVInfo info, out UIntPtr size);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXBCFromSPIRV(const SDL_ShaderCross_SPIRV_Info *info, size_t *size);

Compile DXBC bytecode from SPIRV code.

Parameters

Name Type Description
info in ShaderCross.SPIRVInfo a struct describing the shader to transpile.
size out UIntPtr filled in with the bytecode buffer size.

Returns

an SDL_malloc'd buffer containing DXBC bytecode.

Remarks

You must SDL_free the returned buffer once you are done with it.

XML member id: M:SDL3.ShaderCross.CompileDXBCFromSPIRV(SDL3.ShaderCross.SPIRVInfo@,System.UIntPtr@)

ShaderCross.CompileDXILFromHLSL

public static IntPtr CompileDXILFromHLSL(in ShaderCross.HLSLInfo info, out UIntPtr size);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXILFromHLSL(const SDL_ShaderCross_HLSL_Info *info, size_t *size);

Compile to DXIL bytecode from HLSL code via a SPIRV-Cross round trip. You must SDL.Free the returned buffer once you are done with it.

These are the optional properties that can be used:

  • ShaderCross.Props.ShaderDebugEnableBoolean: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
  • ShaderCross.Props.ShaderDebugNameString: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
  • ShaderCross.Props.ShaderCullUnusedBindingsBoolean: when true, indicates that the compiler should cull unused shader resources. This behavior is disabled by default.
  • ShaderCross.Props.HLSLSkipSPIRVRoundtripBoolean: when true, the SPIRV roundtrip is skipped. This behavior is disabled by default. Do not use this property if your shader uses Structured Buffers.

Parameters

Name Type Description
info in ShaderCross.HLSLInfo a struct describing the shader to transpile.
size out UIntPtr filled in with the bytecode buffer size.

Returns

an SDL_malloc'd buffer containing DXIL bytecode.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.CompileDXILFromHLSL(SDL3.ShaderCross.HLSLInfo@,System.UIntPtr@)

ShaderCross.CompileDXILFromSPIRV

public static IntPtr CompileDXILFromSPIRV(in ShaderCross.SPIRVInfo info, out UIntPtr size);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXILFromSPIRV(const SDL_ShaderCross_SPIRV_Info *info, size_t *size);

Compile DXIL bytecode from SPIRV code.

Parameters

Name Type Description
info in ShaderCross.SPIRVInfo a struct describing the shader to transpile.
size out UIntPtr filled in with the bytecode buffer size.

Returns

an SDL_malloc'd buffer containing DXIL bytecode.

Remarks

You must SDL_free the returned buffer once you are done with it.

XML member id: M:SDL3.ShaderCross.CompileDXILFromSPIRV(SDL3.ShaderCross.SPIRVInfo@,System.UIntPtr@)

ShaderCross.CompileGraphicsShaderFromSPIRV

public static IntPtr CompileGraphicsShaderFromSPIRV(IntPtr device, ref ShaderCross.SPIRVInfo info, ref ShaderCross.GraphicsShaderResourceInfo resourceInfo, uint props);

SDL declaration

extern SDL_DECLSPEC SDL_GPUShader * SDLCALL SDL_ShaderCross_CompileGraphicsShaderFromSPIRV(SDL_GPUDevice *device, const SDL_ShaderCross_SPIRV_Info *info, const SDL_ShaderCross_GraphicsShaderMetadata *metadata, SDL_PropertiesID props);

Compile an SDL GPU shader from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from ShaderCross.CompileSPIRVFromHLSL.

Parameters

Name Type Description
device IntPtr the SDL GPU device.
info ref ShaderCross.SPIRVInfo a struct describing the shader to transpile.
resourceInfo ref ShaderCross.GraphicsShaderResourceInfo a struct describing resource info of the shader. Can be obtained from ShaderCross.ReflectGraphicsSPIRV.
props uint a properties object filled in with extra shader metadata.

Returns

a compiled SDL_GPUShader

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.CompileGraphicsShaderFromSPIRV(System.IntPtr,SDL3.ShaderCross.SPIRVInfo@,SDL3.ShaderCross.GraphicsShaderResourceInfo@,System.UInt32)

ShaderCross.CompileSPIRVFromHLSL

public static IntPtr CompileSPIRVFromHLSL(ref ShaderCross.HLSLInfo info, out UIntPtr size);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileSPIRVFromHLSL(const SDL_ShaderCross_HLSL_Info *info, size_t *size);

Compile to SPIRV bytecode from HLSL code. You must SDL.Free the returned buffer once you are done with it.

These are the optional properties that can be used:

  • ShaderCross.Props.ShaderDebugEnableBoolean: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
  • ShaderCross.Props.ShaderDebugNameString: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
  • ShaderCross.Props.ShaderCullUnusedBindingsBoolean: when true, indicates that the compiler should cull unused shader resources. This behavior is disabled by default.

Parameters

Name Type Description
info ref ShaderCross.HLSLInfo a struct describing the shader to transpile.
size out UIntPtr filled in with the bytecode buffer size.

Returns

an SDL_malloc'd buffer containing SPIRV bytecode.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.CompileSPIRVFromHLSL(SDL3.ShaderCross.HLSLInfo@,System.UIntPtr@)

ShaderCross.GetHLSLShaderFormats

public static SDL.GPUShaderFormat GetHLSLShaderFormats();

SDL declaration

extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_ShaderCross_GetHLSLShaderFormats(void);

Get the supported shader formats that HLSL cross-compilation can output

Returns

GPU shader formats supported by HLSL cross-compilation.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.GetHLSLShaderFormats

ShaderCross.GetSPIRVShaderFormats

public static SDL.GPUShaderFormat GetSPIRVShaderFormats();

SDL declaration

extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_ShaderCross_GetSPIRVShaderFormats(void);

Get the supported shader formats that SPIRV cross-compilation can output

Returns

GPU shader formats supported by SPIRV cross-compilation.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.GetSPIRVShaderFormats

ShaderCross.Init

public static bool Init();

SDL declaration

extern SDL_DECLSPEC bool SDLCALL SDL_ShaderCross_Init(void);

Initializes SDL_shadercross

Returns

true on success, false otherwise.

Thread safety

This should only be called once, from a single thread.

XML member id: M:SDL3.ShaderCross.Init

ShaderCross.Quit

public static void Quit();

SDL declaration

extern SDL_DECLSPEC void SDLCALL SDL_ShaderCross_Quit(void);

De-initializes SDL_shadercross

Thread safety

This should only be called once, from a single thread.

XML member id: M:SDL3.ShaderCross.Quit

ShaderCross.ReflectComputeSPIRV

public static IntPtr ReflectComputeSPIRV(IntPtr bytecode, UIntPtr bytecodeSize, uint props);

SDL declaration

extern SDL_DECLSPEC SDL_ShaderCross_ComputePipelineMetadata * SDLCALL SDL_ShaderCross_ReflectComputeSPIRV(const Uint8 *bytecode, size_t bytecode_size, SDL_PropertiesID props);

Reflect compute pipeline info from SPIRV code.

Parameters

Name Type Description
bytecode IntPtr the SPIRV bytecode.
bytecodeSize UIntPtr the length of the SPIRV bytecode.
props uint a properties object filled in with extra shader metadata, provided by the user.

Returns

A metadata struct on success, null otherwise.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.ReflectComputeSPIRV(System.IntPtr,System.UIntPtr,System.UInt32)

ShaderCross.ReflectGraphicsSPIRV

public static IntPtr ReflectGraphicsSPIRV(IntPtr bytecode, UIntPtr bytecodeSize, uint props);

SDL declaration

extern SDL_DECLSPEC SDL_ShaderCross_GraphicsShaderMetadata * SDLCALL SDL_ShaderCross_ReflectGraphicsSPIRV(const Uint8 *bytecode, size_t bytecode_size, SDL_PropertiesID props);

Reflect graphics shader info from SPIRV code. If your shader source is HLSL, you should obtain SPIR-V bytecode from ShaderCross.CompileSPIRVFromHLSL. This must be freed with SDL.Free when you are done with the metadata.

Parameters

Name Type Description
bytecode IntPtr the SPIRV bytecode.
bytecodeSize UIntPtr the length of the SPIRV bytecode.
props uint a properties object filled in with extra shader metadata, provided by the user.

Returns

A metadata struct on success, null otherwise. The struct must be free'd when it is no longer needed.

Thread safety

It is safe to call this function from any thread.

XML member id: M:SDL3.ShaderCross.ReflectGraphicsSPIRV(System.IntPtr,System.UIntPtr,System.UInt32)

ShaderCross.TranspileHLSLFromSPIRV

public static IntPtr TranspileHLSLFromSPIRV(in ShaderCross.SPIRVInfo info);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_TranspileHLSLFromSPIRV(const SDL_ShaderCross_SPIRV_Info *info);

Transpile to HLSL code from SPIRV code.

You must SDL_free the returned string once you are done with it. These are the optional properties that can be used:

  • ShaderCross.Props.SPIRVPSSLCompatibilityBoolean: generates PSSL-compatible shader.

Parameters

Name Type Description
info in ShaderCross.SPIRVInfo a struct describing the shader to transpile.

Returns

an SDL_malloc'd string containing HLSL code.

XML member id: M:SDL3.ShaderCross.TranspileHLSLFromSPIRV(SDL3.ShaderCross.SPIRVInfo@)

ShaderCross.TranspileMSLFromSPIRV

public static IntPtr TranspileMSLFromSPIRV(in ShaderCross.SPIRVInfo info);

SDL declaration

extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_TranspileMSLFromSPIRV(const SDL_ShaderCross_SPIRV_Info *info);

Transpile to MSL code from SPIRV code.

You must SDL.Free the returned string once you are done with it. These are the optional properties that can be used:

  • ShaderCross.Props.SPIRVMSLVersionString: specifies the MSL version that should be emitted. Defaults to 1.2.0.

Parameters

Name Type Description
info in ShaderCross.SPIRVInfo a struct describing the shader to transpile.

Returns

an SDL_malloc'd string containing MSL code.

XML member id: M:SDL3.ShaderCross.TranspileMSLFromSPIRV(SDL3.ShaderCross.SPIRVInfo@)