GraphicsAPI reference
Class CompiledShader
Namespace: MicroEngine.Graphics.Devices
Assembly: MicroEngine.Graphics.dll
Guide: The graphics device
A shader compiled ahead of time from one HLSL source into every format a tier-1 device may accept (DXIL for
Direct3D 12, SPIR-V for Vulkan, MSL for Metal), with the resource counts reflection found. It is what
microengine shaders writes (one .shader file per HLSL file) and what a game ships: nothing compiles at
run time. DescriptionFor picks the format a device should be given; a device without custom shaders
gets the typed GraphicsCapabilityException, as for any undeclared capability.
public sealed class CompiledShaderInheritance
Remarks
The file is UTF-8 JSON: {“format”:“microengine-shader”,“version”:1,“stage”:“vertex”|“fragment”,“source”:…,
“resources”:{“samplers”:n,“uniformBuffers”:n},“code”:{“dxil”|“spirv”|“msl”:{“entry”:…,“base64”:…}}}.
Binding rules are SDL_GPU’s (see ShaderResources).
Constructors
CompiledShader(ShaderStage, ShaderResources, IReadOnlyDictionary<ShaderFormat, ShaderCode>, string?)
Creates a compiled shader from its code in one or more formats.
public CompiledShader(ShaderStage stage, ShaderResources resources, IReadOnlyDictionary<ShaderFormat, ShaderCode> code, string? source = null)Parameters
stage ShaderStage
Stage.
resources ShaderResources
Reflected resource counts (the same for every format).
code IReadOnlyDictionary<ShaderFormat, ShaderCode>
Code by format; each key is exactly one format.
source string?
The source file it was compiled from, for diagnostics.
Exceptions
No code, a key that is not exactly one format, or an empty entry point or code.
Fields
FileExtension
The file extension of a compiled shader (“sprite.frag.hlsl” compiles to “sprite.frag.shader”).
public const string FileExtension = ".shader"Field Value
FormatVersion
The file format version this assembly reads and writes.
public const int FormatVersion = 1Field Value
Properties
Formats
The formats this shader has code for.
public ShaderFormat Formats { get; }Property Value
Resources
Reflected resource counts.
public ShaderResources Resources { get; }Property Value
Source
The source file it was compiled from, or null.
public string? Source { get; }Property Value
Stage
Stage.
public ShaderStage Stage { get; }Property Value
Methods
Create(IGraphicsDevice)
Creates the shader on device in the format DescriptionFor picks.
public Shader Create(IGraphicsDevice device)Parameters
device IGraphicsDevice
Returns
Exceptions
See DescriptionFor.
DescriptionFor(GraphicsCapabilities)
The description to give a device with capabilities: the format its API runs natively
(DXIL on Direct3D 12, MSL on Metal, SPIR-V on Vulkan), otherwise the first format both sides have.
public ShaderDescription DescriptionFor(GraphicsCapabilities capabilities)Parameters
capabilities GraphicsCapabilities
Returns
Exceptions
The device declares no custom shaders (Shaders), or none of the formats this shader was compiled for.
Parse(ReadOnlySpan<byte>)
Reads a compiled shader file.
public static CompiledShader Parse(ReadOnlySpan<byte> utf8Json)Parameters
utf8Json ReadOnlySpan<byte>
Returns
Exceptions
The data is not a compiled shader of a version this assembly reads.
ToBytes()
The file form of this shader (UTF-8 JSON, formats in a fixed order, so the same compilation gives the same bytes).
public byte[] ToBytes()Returns
byte[]
ToString()
public override string ToString()Returns
TryGetCode(ShaderFormat, out ShaderCode)
The code in format, if compiled for it.
public bool TryGetCode(ShaderFormat format, out ShaderCode code)Parameters
format ShaderFormat
code ShaderCode