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.
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.
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
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.
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 methodThe packages
- .Build
RecursiveAI.OneShader.Buildcompiles your*.hlslfiles duringdotnet build, embeds the targets you pick (OneShaderTargets), builds shader variants from keyword axes and generates the C# bindings. - The compiler
RecursiveAI.OneShadercompiles at run time, for tools and hot reload, with a layout-compatibility check and a compile cache. - .Tool
RecursiveAI.OneShader.Toolis theoneshadercommand, with DXC’s core flags, for CMake, Make and scripts. - Shaders
Vertex, pixel and compute shaders in modern HLSL, HLSL 2021 templates included. Wave and quad intrinsics on all three targets, specialization constants, and 16-bit and 64-bit types where the target has them.
- Pipeline layouts
Plain-data helpers turn a shader into the Vulkan, Metal or WebGPU layouts a renderer creates.
- Safe on text you didn’t write
Bad input yields diagnostics, never an exception or a stack overflow, and the front end is fuzzed. No
unsafecode and no reflection. - Version
1.2.0, the same for all three packages.
- .NET
.NET 10, built with the .NET SDK. NativeAOT and trimming are supported. MIT or Apache-2.0.