Class SkslConverter
Converts an HLSL .fx pixel shader to an SkSL runtime effect for SkiaSharp's
SKRuntimeEffect (issue #197). The route is the §2.3 seam:
HLSL → [DXC] → SPIR-V → [SPIRV-Cross] → modern GLSL → [convention mapper] → SkSL —
the same faithful front half as every ShadowDusk compile (no substitute compiler), branching
before the MonoGame GLSL rewriter and the MGFX writer.
What this is, honestly: a source-to-source converter judged by rendered-image
fidelity (owner decision 2026-08-13, resolving Phase 57 §3 for this case) — never
mgfxc-equivalence, because Skia has no reference compiler to be equivalent to, and
never a validation-matrix §1 backend. SkSL is source-only (SKRuntimeEffect has no
bytecode entry point) and runtime effects have no vertex stage and no varyings, which
bounds the convertible set to fragment-only, coordinate-driven effects with uniform inputs.
Everything outside that set is rejected loudly (SD0610–SD0613), never
silently narrowed.
public static class SkslConverter
- Inheritance
-
SkslConverter
- Inherited Members
Methods
Convert(string, SkslConvertOptions, Func<IDxcShaderCompiler>?, Func<ISpirvToGlslTranspiler>?, CancellationToken)
Convert(string, SkslConvertOptions, CancellationToken) with the same backend-injection seam EffectCompiler has, so a host without the native DXC/SPIRV-Cross (the browser/WASM host) can supply its own: the SAME faithful components compiled for that host, never a substitute compiler.
public static Result<SkslConversion, ShaderError[]> Convert(string fxSource, SkslConvertOptions options, Func<IDxcShaderCompiler>? dxcCompilerFactory, Func<ISpirvToGlslTranspiler>? glslTranspilerFactory, CancellationToken cancellationToken = default)
Parameters
fxSourcestringThe HLSL
.fxeffect source.optionsSkslConvertOptionsConversion options; see SkslConvertOptions.
dxcCompilerFactoryFunc<IDxcShaderCompiler>HLSL to SPIR-V frontend; null = bundled desktop DXC.
glslTranspilerFactoryFunc<ISpirvToGlslTranspiler>SPIR-V to GLSL transpiler; null = bundled SPIRV-Cross.
cancellationTokenCancellationTokenObserved between pipeline stages.
Returns
Convert(string, SkslConvertOptions, CancellationToken)
Converts the pixel shader of fxSource's single technique/pass to
SkSL, or returns the loud diagnostics for anything the SkSL model cannot hold.
public static Result<SkslConversion, ShaderError[]> Convert(string fxSource, SkslConvertOptions options, CancellationToken cancellationToken = default)
Parameters
fxSourcestringThe HLSL
.fxeffect source.optionsSkslConvertOptionsConversion options; see SkslConvertOptions.
cancellationTokenCancellationTokenObserved between pipeline stages.
Returns
ConvertSlang(string, SkslConvertOptions, CancellationToken)
Converts HLSL-compatible .slang source to SkSL through the built-in Slang frontend
(ConvertToFx(string, SlangConvertOptions), no extra package, every host): the Slang
becomes .fx text, then Convert(string, SkslConvertOptions, CancellationToken) applies every SkSL rule unchanged.
Slang-only constructs (SD0600) are refused by the frontend; for genuine Slang
(import, generics, interfaces) use ShadowDusk.Slang's
SlangCompiler.ConvertToSksl. Set SourceName to the
.slang name for diagnostics.
public static Result<SkslConversion, ShaderError[]> ConvertSlang(string slangSource, SkslConvertOptions options, CancellationToken cancellationToken = default)
Parameters
slangSourcestringThe Slang source; pixel entry marked
[shader("fragment")].optionsSkslConvertOptionsConversion options; see SkslConvertOptions.
cancellationTokenCancellationTokenObserved between pipeline stages.