Cross-platform shader compiler and runtime library
The nshader command-line tool provides shader compilation, inspection, and extraction capabilities.
nshader <command> [options]
| Command | Description |
|---|---|
compile |
Compile HLSL shader to nshader format |
info |
Display shader information |
extract |
Extract a specific backend and stage to a file |
help |
Display help message |
version |
Display version information |
Compile HLSL shader source files to the nshader binary format.
nshader compile [<input.hlsl>] -o <output.nshader> [options]
| Option | Description |
|---|---|
<input.hlsl> |
Default input file for all stages |
--vertex-source <file> |
Source file for vertex shader (overrides default) |
--fragment-source <file> |
Source file for fragment shader (overrides default) |
--compute-source <file> |
Source file for compute shader (overrides default) |
Each active stage requires a source from either the default input file or its stage-specific --*-source flag. This allows you to:
| Option | Description |
|---|---|
--vertex <entry> |
Vertex shader entry point function name |
--fragment <entry> |
Fragment shader entry point function name |
--compute <entry> |
Compute shader entry point function name |
At least one shader stage must be specified.
| Option | Description |
|---|---|
-D <NAME[=VALUE]> |
Add preprocessor define (applies to all stages) |
--D-vertex <NAME[=VALUE]> |
Add define for vertex stage only |
--D-fragment <NAME[=VALUE]> |
Add define for fragment stage only |
--D-compute <NAME[=VALUE]> |
Add define for compute stage only |
Global defines (-D) are applied to all stages. Stage-specific defines (--D-*) are applied only to that particular stage. Both can be used together and combined.
| Option | Description |
|---|---|
-o <file> |
Output nshader file (required) |
-I <directory> |
Include directory for shader code |
--debug |
Enable debug information in compiled shaders |
--debug-name <name> |
Set debug name for the shader |
--preserve-bindings |
Don’t cull unused resource bindings |
| Option | Description |
|---|---|
--disable-dxil |
Disable DirectX Intermediate Language backend |
--disable-dxbc |
Disable DirectX Bytecode backend |
--disable-msl |
Disable Metal Shading Language backend |
--disable-spv |
Disable SPIR-V backend |
By default, all available backends are enabled. Use these flags to exclude specific backends from compilation.
Single source file for all stages:
nshader compile shader.hlsl -o shader.nshader \
--vertex VSMain --fragment PSMain
Separate source files for each stage:
nshader compile \
--vertex VSMain --vertex-source vertex.hlsl \
--fragment PSMain --fragment-source fragment.hlsl \
-o shader.nshader
Default source with override for one stage:
nshader compile common.hlsl -o shader.nshader \
--vertex VSMain \
--fragment PSMain --fragment-source custom_pixel.hlsl
Compute shader with defines:
nshader compile blur.hlsl -o blur.nshader \
--compute main -D KERNEL_SIZE=5 -D USE_SHARED_MEMORY
Stage-specific defines:
nshader compile shader.hlsl -o shader.nshader \
--vertex VSMain --D-vertex INSTANCED=1 \
--fragment PSMain --D-fragment USE_TEXTURES
Combining global and stage-specific defines:
nshader compile shader.hlsl -o shader.nshader \
-D DEBUG=1 \
--vertex VSMain --D-vertex MAX_BONES=64 \
--fragment PSMain --D-fragment ENABLE_SHADOWS
Selective backend compilation:
nshader compile shader.hlsl -o shader.nshader \
--vertex main --disable-dxbc --disable-msl
With include directory and debug info:
nshader compile shader.hlsl -o shader.nshader \
--vertex VSMain --fragment PSMain \
-I ./shaders/include \
--debug --debug-name "MainShader"
Display information about a compiled nshader file.
nshader info <shader.nshader> [options]
| Option | Description |
|---|---|
-v, --verbose |
Show detailed information including bindings and metadata |
Basic info:
nshader info shader.nshader
Output:
Shader: shader.nshader
Type: Graphics
Backends (3):
- DXIL
- MSL
- SPIR-V
Stages (2):
Vertex:
Entry Point: VSMain
Fragment:
Entry Point: PSMain
Verbose info:
nshader info shader.nshader --verbose
Output includes additional details like sampler counts, storage buffers, uniform buffers, and input/output bindings for each stage.
Extract a specific backend and stage from a compiled nshader file to a separate file.
nshader extract <shader.nshader> <backend> <stage> -o <output>
| Value | Description |
|---|---|
dxil |
DirectX Intermediate Language |
dxbc |
DirectX Bytecode |
msl |
Metal Shading Language |
spv |
SPIR-V |
| Value | Description |
|---|---|
vertex |
Vertex shader stage |
fragment |
Fragment shader stage |
compute |
Compute shader stage |
Extract SPIR-V vertex shader:
nshader extract shader.nshader spv vertex -o vertex.spv
Extract Metal fragment shader:
nshader extract shader.nshader msl fragment -o fragment.metal
Extract DXIL compute shader:
nshader extract shader.nshader dxil compute -o compute.dxil
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Error (invalid arguments, compilation failure, file not found, etc.) |
The CLI tool uses SDL_shadercross for compilation, which may have platform-specific backend availability:
| Backend | Windows | macOS | Linux |
|---|---|---|---|
| DXIL | Yes | No | No |
| DXBC | Yes | No | No |
| MSL | Yes | Yes | Yes |
| SPIR-V | Yes | Yes | Yes |
Use nshader info to check which backends are present in a compiled shader.