Recursive AI
LibraryC#Available

oneshader

An HLSL compiler for .NET, written in C# with no dependency beyond .NET itself. Modern HLSL goes in; SPIR-V, Metal Shading Language and WGSL come out, during dotnet build.

dotnet add package RecursiveAI.OneShader.Build

A quick look

Put Shaders/Sprite.hlsl in a project. After dotnet build, the compiled shader and C# that matches its layout are in your assembly, with no reflection and no file I/O at run time.

The generated bindings
Program.csC#
using MyGame.Shaders;   // <RootNamespace>.Shaders
 
// embedded SPIR-V
ReadOnlySpan<byte> vs = Sprite.VSMain.SpirV;
// explicit layout, Size = 64
var frame = new Sprite.Frame { ViewProjection = camera };
uint set = Sprite.Bindings.Atlas.Set, binding = Sprite.Bindings.Atlas.Binding;
What it does

What it does

Shader errors are build errors

A mistake shows up on the HLSL line with a stable code, such as error OSH0300: 'Atlass' is not declared. Did you mean 'Atlas'?, not as a black screen at run time.

C# that matches the shader

Constant buffers, vertex inputs and bindings become blittable structs whose offsets equal the compiled shader’s, so a CPU/GPU layout mismatch fails the build.

Three targets from one front end

SPIR-V for Vulkan 1.2+ by default; Metal Shading Language and WGSL are opt-in per project. A feature a target can’t express is a diagnostic naming the target.

Checked against DXC and real GPUs

SPIR-V is validated with spirv-val and run on the GPU next to DXC’s output. WGSL goes through naga and a browser WebGPU run, MSL through Apple’s compiler and Metal.

Performance

About 2.4× faster than DXC as a NativeAOT binary

Compiling 68 corpus entry points, one process each, against the released DXC binary with SPIR-V output, warm. Every one of the 68 is faster.

Every result and the method

The packages

Go further