Class DxcShaderCompiler
Compiles preprocessed HLSL to SPIR-V or DXBC via Vortice.Dxc. NOT thread-safe: do not share across concurrent compilations. Create one instance per parallel worker or serialize via a lock/channel.
public sealed class DxcShaderCompiler : IDxcShaderCompiler, IDisposable
- Inheritance
-
DxcShaderCompiler
- Implements
- Inherited Members
Constructors
DxcShaderCompiler()
Creates the DXC compiler instance from ShadowDusk's pinned DXC natives (on Windows,
with the pinned dxil.dll validating and signing DXIL). If those natives cannot
be guaranteed, every compile returns an SD0219 error instead.
public DxcShaderCompiler()
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.
public 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.
public 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.
Dispose()
Releases the native DXC compiler instance.
public void Dispose()
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).
public 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.