Interface IDxcShaderCompiler
- Namespace
- ShadowDusk.HLSL.Dxc
- Assembly
- ShadowDusk.HLSL.dll
Compiles preprocessed HLSL to SPIR-V or DXBC using DXC. NOT thread-safe: do not share a single instance across concurrent compilations. Create one instance per parallel worker or serialize access.
public interface IDxcShaderCompiler
Methods
Compile(DxcCompileRequest, CancellationToken)
Synchronous counterpart of CompileAsync(DxcCompileRequest, CancellationToken): compiles the request on the
calling thread. The DXC compile itself is synchronous work on every host —
CompileAsync(DxcCompileRequest, CancellationToken) is only a thread-offload (desktop) or one-time-module-load
(WASM) shell over this — so both entry points produce identical bytes by
construction. On the browser/WASM host the DXC module must already be loaded
(IShaderCompiler.InitializeAsync); otherwise a clear ShaderError
(SD1903) is returned. Never blocks on a task internally.
Result<PlatformBlob, ShaderError> Compile(DxcCompileRequest request, CancellationToken cancellationToken = default)
Parameters
requestDxcCompileRequestThe compile request: source, entry point, profile, and flags.
cancellationTokenCancellationTokenToken checked before the compile starts.
Returns
- Result<PlatformBlob, ShaderError>
The compiled PlatformBlob on success, or a ShaderError carrying the DXC diagnostics on failure.
CompileAsync(DxcCompileRequest, CancellationToken)
Compiles a preprocessed HLSL request to a SPIR-V or DXBC blob via DXC.
Task<Result<PlatformBlob, ShaderError>> CompileAsync(DxcCompileRequest request, CancellationToken cancellationToken = default)
Parameters
requestDxcCompileRequestThe compile request: source, entry point, profile, and flags.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<Result<PlatformBlob, ShaderError>>
The compiled PlatformBlob on success, or a ShaderError carrying the DXC diagnostics on failure.
Preprocess(DxcPreprocessRequest, CancellationToken)
Preprocess-only (-P): expand #includes, #defines and conditional
directives into a single flat HLSL text WITHOUT compiling — no entry point, stage,
or profile. Used by the zero-technique fallback in the pipeline to macro-expand the
stock-effect TECHNIQUE(...) declarations into literal technique blocks
the FX pre-parser can read. Synchronous (the DXC preprocessor is in-process work on
every host).
Result<string, ShaderError> Preprocess(DxcPreprocessRequest request, CancellationToken cancellationToken = default)
Parameters
requestDxcPreprocessRequestThe preprocess request: source, file name, and macro defines.
cancellationTokenCancellationTokenToken checked before preprocessing starts.
Returns
- Result<string, ShaderError>
The expanded HLSL text on success, or a ShaderError carrying the DXC diagnostics on failure.