Skip to content
AaronTian-stackPublic

About

CLI tool for batch compilation of Slang HLSL shaders

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SXC - Standalone Shader Compiler

SXC (Shader eXecution Compiler) is a standalone command line tool for batch compilation of Slang HLSL shaders, acting as a frontend for Slang to produce DXBC, DXIL, and SPIR-V.

SXC is heavily inspired by ShaderMake (MIT License), but with a key difference being that it does not create a individual subprocess for every shader compilation, which should result in lower overhead.

Features

  • Batch Compilation: Compile multiple shaders from configuration file
  • Parallel Processing: Uses Intel TBB for efficient multi-threaded compilation
  • Shader Permutations: Support for generating multiple variants with different defines
  • Multiple Shader Models: Support for SM 5.0 and SM 6.0 through 6.6
  • Library Profile Support: Compile DXIL libraries (lib / library)
  • Debug Support: Optional debug information generation
  • Incremental Rebuilds: Skips up-to-date shaders by checking file timestamps and include dependencies

Basic Usage

SXC.exe -c <config_file> -sm <shader_model> -ir <DXBC|DXIL|SPIRV> -out <output_dir> [options]

The output consists of one or more container files, each holding one or more native shader bytecode variants. The file extension depends on the selected -ir target: .dxbc_blob for DXBC, .dxil_blob for DXIL, and .spv_blob for SPIRV.

Required Arguments

  • -c, --config-path: Path to the configuration file
  • -sm, --shader-model: Target shader model (5_0 through 6_9)
  • -ir, --output-IR: Output representation (DXBC, DXIL, or SPIRV)
  • -out, --output: Output directory for compiled shaders

Optional Arguments

  • -i, --include-path: Additional include directories (can be specified multiple times)
  • -g, --global-defines: Global preprocessor defines for all shaders (can be specified multiple times)
  • -dbg, --embed-debug: Embed target-native debug information in all shaders
  • -f, --force: Force recompilation of shaders even if up-to-date
  • -o, --optimization: Default optimization level (O0, O1, O2, O3) [default: O3]

Note: Paths are resolved relative to the configuration file's directory location.

Configuration File Format

The configuration file contains one shader compilation job per line. Each line specifies the shader file and compilation parameters:

-p <shader_path> -st <shader_type> [-e <entry_point>] [options]

Configuration Parameters

  • -p, --path: Path to a native .slang or compatible .hlsl shader file
  • -e, --entry-point: Shader entry point function name (required for non-library shader types)
  • -st, --shader-type: Shader type (vs, ps, cs, lib)
  • -out, --output-dir: Override global output directory for this shader
  • -d, --define: Preprocessor defines (supports permutation syntax)
  • -o, --optimization: Override global optimization level

Shader Permutations

SXC supports generating multiple shader variants using define permutations:

-p shader.slang -e main -st vs -d FEATURE_A={0,1} -d FEATURE_B={0,1}

This will generate 4 shader variants:

  • FEATURE_A=0, FEATURE_B=0
  • FEATURE_A=0, FEATURE_B=1
  • FEATURE_A=1, FEATURE_B=0
  • FEATURE_A=1, FEATURE_B=1

All shader permutations are compiled and written to a single binary file. There is an additional .meta file generated to track permutation changes for incremental rebuild decisions.

To select a permutation at runtime, call SXC::ShaderBlob::find_shader() with its requested defines. The self-contained reader is available at include/shader_blob.h and does not depend on QhenkiX.

SDK package

Build and install SXC to create a platform-specific SDK containing the compiler, its runtime libraries, the shader blob reader, and CMake package metadata:

cmake --install build --config Release --prefix sdk

CMake consumers can then set SXC_ROOT to that sdk directory and load the exported SXC::Compiler and SXC::ShaderBlob targets with find_package(SXC CONFIG).

Building

Clone recursively so the pinned Slang dependency is available, then configure and build with CMake:

git clone --recurse-submodules https://github.com/AaronTian-stack/SXC.git
cd SXC
cmake --preset windows-release
cmake --build build --config Release --target SXC --parallel

On Linux, use the linux-release preset. SXC requires CMake 3.21 or newer and a C++20 compiler

Example

Configuration File (shaders.config)

-p basic_vs.slang -e main -st vs
-p basic_ps.slang -e main -st ps -d USE_TEXTURE={0,1}
-p compute.slang -e CSMain -st cs -o O2
-p raytracing_lib.slang -st lib

Command Line

SXC.exe -c shaders.config -sm 6_0 -ir DXIL -out compiled_shaders -i include_dir -g GLOBAL_DEFINE=1

Dependencies

About

CLI tool for batch compilation of Slang HLSL shaders

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages