Class ShaderConverter
- Namespace
- ShadowDusk.Compiler
- Assembly
- ShadowDusk.Compiler.dll
One auto-detecting entry point per output kind, for callers that receive shaders without a
trustworthy file extension. Each method detects the source language from the text
(ShaderFormatDetector), routes an .fx effect or HLSL-compatible Slang to
the same pipeline the format-specific entry points use, and returns an
UnsupportedInput error (code SD0650) without compiling
anything when the input is not one of those two.
public static class ShaderConverter
- Inheritance
-
ShaderConverter
- Inherited Members
Remarks
Telling "not mine" from "broken": a failed result whose errors contain a UnsupportedInput error means nothing was attempted, so a caller that chains loaders can try the next one. Any other failure (a compile error, an AmbiguousInput error, an include error) is a real error in a recognized shader and should be reported.
GLSL input (Glsl) is reported as unsupported here:
its converter is the separate ShadowDusk.ShaderToy package, which this package does
not reference. Call ShaderToyConverter.Convert first, then pass its .fx
output to any method on this class.
The format-specific entry points (EffectCompiler, SlangFrontend, SkslConverter, RaylibConverter) are unchanged and remain the way to force a format.
Fields
UnsupportedInputCode
The diagnostic code of an UnsupportedInput error.
public const string UnsupportedInputCode = "SD0650"
Field Value
Methods
CanConvert(string, string?)
Whether the methods on this class would try to convert source. Cheap:
a text scan, no compile. False means the input is not a format this package reads, and a
caller can hand it to something else. True means the conversion will be attempted and
any failure is a real error; that includes ambiguous input, which fails loudly.
public static bool CanConvert(string source, string? nameHint = null)
Parameters
sourcestringThe shader source text.
nameHintstringOptional file name; see Detect(string, string?).
Returns
Compile(IShaderCompiler, string, CompilerOptions, string?, CancellationToken)
Detects the format of source and compiles it with
compiler to the target in options (MonoGame, KNI,
FNA). Slang is converted to .fx first, exactly as
ConvertToFx(string, SlangConvertOptions) does.
public static Result<CompiledShader, ShaderError[]> Compile(IShaderCompiler compiler, string source, CompilerOptions options, string? nameHint = null, CancellationToken cancellationToken = default)
Parameters
compilerIShaderCompilerThe compiler to run, usually an EffectCompiler.
sourcestringThe shader source text.
optionsCompilerOptionsCompilation settings, as for Compile(string, CompilerOptions, CancellationToken).
nameHintstringOptional file name; used for detection ties and in diagnostics.
cancellationTokenCancellationTokenObserved between pipeline stages.
Returns
CompileAsync(IShaderCompiler, string, CompilerOptions, string?, CancellationToken)
Asynchronous counterpart of Compile(IShaderCompiler, string, CompilerOptions, string?, CancellationToken); same detection and routing.
public static Task<Result<CompiledShader, ShaderError[]>> CompileAsync(IShaderCompiler compiler, string source, CompilerOptions options, string? nameHint = null, CancellationToken cancellationToken = default)
Parameters
compilerIShaderCompilerThe compiler to run, usually an EffectCompiler.
sourcestringThe shader source text.
optionsCompilerOptionsCompilation settings, as for CompileAsync(string, CompilerOptions, CancellationToken).
nameHintstringOptional file name; used for detection ties and in diagnostics.
cancellationTokenCancellationTokenToken used to cancel a long-running compile.
Returns
ConvertToRaylib(string, RaylibConvertOptions, string?, CancellationToken)
Detects the format of source and converts it to a raylib fragment
shader: Convert(string, RaylibConvertOptions, CancellationToken) for an .fx effect,
ConvertSlang(string, RaylibConvertOptions, CancellationToken) for Slang. A raylib-style GLSL .fs file
is GLSL input, so it is reported as unsupported and can be loaded by raylib directly.
public static Result<RaylibShader, ShaderError[]> ConvertToRaylib(string source, RaylibConvertOptions options, string? nameHint = null, CancellationToken cancellationToken = default)
Parameters
sourcestringThe shader source text.
optionsRaylibConvertOptionsConversion options; see RaylibConvertOptions.
nameHintstringOptional file name; used only for detection ties.
cancellationTokenCancellationTokenObserved between pipeline stages.
Returns
ConvertToSksl(string, SkslConvertOptions, string?, CancellationToken)
Detects the format of source and converts it to an SkSL fragment
shader: Convert(string, SkslConvertOptions, CancellationToken)
for an .fx effect, ConvertSlang(string, SkslConvertOptions, CancellationToken) for Slang.
public static Result<SkslConversion, ShaderError[]> ConvertToSksl(string source, SkslConvertOptions options, string? nameHint = null, CancellationToken cancellationToken = default)
Parameters
sourcestringThe shader source text.
optionsSkslConvertOptionsConversion options; see SkslConvertOptions.
nameHintstringOptional file name; used only for detection ties.
cancellationTokenCancellationTokenObserved between pipeline stages.