RecursiveAI.OneShader 0.2.0-preview.1

This is a prerelease version of RecursiveAI.OneShader.
There is a newer version of this package available.
See the version list below for details.
dotnet add package RecursiveAI.OneShader --version 0.2.0-preview.1
                    
NuGet\Install-Package RecursiveAI.OneShader -Version 0.2.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RecursiveAI.OneShader" Version="0.2.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RecursiveAI.OneShader" Version="0.2.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="RecursiveAI.OneShader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RecursiveAI.OneShader --version 0.2.0-preview.1
                    
#r "nuget: RecursiveAI.OneShader, 0.2.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RecursiveAI.OneShader@0.2.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RecursiveAI.OneShader&version=0.2.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=RecursiveAI.OneShader&version=0.2.0-preview.1&prerelease
                    
Install as a Cake Tool

OneShader

A HLSL compiler for .NET, written in C#, with no dependency beyond .NET itself. Modern HLSL (Shader Model 6 style) for vertex, pixel and compute shaders goes in; SPIR-V for Vulkan comes out, with reflection: inputs and outputs, resource bindings, buffer layouts and thread-group sizes. NativeAOT and trimming are supported.

Preview. Version 0.2 targets Vulkan (SPIR-V). The API may still change before 1.0.

Most projects want RecursiveAI.OneShader.Build, which compiles *.hlsl during dotnet build and generates C# bindings. This package is the compiler itself, for compiling at run time (hot reload, tools) and for the support types the generated code uses.

Install

dotnet add package RecursiveAI.OneShader --prerelease

Target framework net10.0. The namespace is OneShader.

Quick start

using OneShader;

string source = File.ReadAllText("Shaders/Blur.hlsl");
CompileResult result = ShaderCompiler.Compile(source, "Shaders/Blur.hlsl", new CompileOptions
{
    Defines = [new("RADIUS", "4")],
    IncludeDirectories = ["Shaders/Common"],
});

foreach (var d in result.Diagnostics)
    Console.WriteLine(d);              // Shaders/Blur.hlsl(12,5): error OSH0300: ...

if (result.Success)
{
    ReadOnlySpan<byte> spirv = result.Find("PSMain", CompileTarget.SpirV)!.Data;
    var reflection = result.Reflection!;   // resources, bindings, buffer layouts, entry points
}

Errors are returned as diagnostics with file, line and column, never thrown. Includes can come from disk or from memory through CompileOptions.IncludeResolver. Output is deterministic.

Hot reload

During development, watch the HLSL file, recompile it with the runtime API and swap the new SPIR-V in, as long as the interface the C# was built against has not changed. Projects using the build package get that interface as Shaders.Sprite.Reflection (generated from Sprite.hlsl).

CompileResult result = ShaderCompiler.CompileFile("Shaders/Sprite.hlsl");   // diagnostics, not exceptions
watcher.Watch(result.Files);                                              // the file and its #includes, even after an error

if (!result.Success) { Print(result.Diagnostics); return; }                // keep running the last good shader

CompatibilityReport report = InterfaceCompatibility.Compare(Shaders.Sprite.Reflection, result.Reflection!);
if (report.IsCompatible)
    renderer.Replace(result.Find("PSMain", CompileTarget.SpirV)!.Data);
else
    Console.WriteLine(report);   // "Frame.Tint moved from offset 64 to 80" ... "Rebuild the project ..."

Compatible means everything the generated C# relies on is unchanged: constant-buffer and structured-buffer layouts (member offsets, types, array and matrix strides, sizes), vertex input locations, formats, offsets and stride, resource set, binding, kind, array size and stage visibility, the entry points present and their stages, and compute thread-group sizes. Edits to function bodies, new entry points, and resources that become visible to fewer stages are compatible. ShaderCompiler.Compile can be called from several threads at once. samples/HotReload is a complete console loop.

What works in 0.2

  • Vertex, pixel and compute shaders in modern HLSL (HLSL 2021): structs, functions, constant buffers, textures and samplers, structured and byte-address buffers, storage images, groupshared memory, barriers and atomics, and the preprocessor (#include, macros, #if).
  • SPIR-V for Vulkan 1.2, validated with spirv-val, and checked by running each shader in its test corpus on a GPU against the same shader compiled by DXC.
  • Buffer layouts and descriptor bindings follow the conventions DXC uses for Vulkan.

Known limits

  • SPIR-V only. Metal (MSL) and WebGPU (WGSL) output are in development; asking for them returns diagnostic OSH0002.
  • Unbounded resource arrays and wave intrinsics are not supported.

License

MIT OR Apache-2.0, at your option. Copyright © Recursive AI, LLC.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on RecursiveAI.OneShader:

Package Downloads
RecursiveAI.OneShader.Build

Compiles HLSL shaders during dotnet build: SPIR-V embedded in the assembly, shader errors as build errors on the HLSL line, and generated C# structs and binding constants laid out to match each shader.

RecursiveAI.OneGame.Gpu

Graphics API abstraction and render graph.

RecursiveAI.OneGame.Control

The control layer shared by the command line, the test API and live control.

RecursiveAI.OneGame.Host

The game host: window, input, fixed-step simulation, UI and render stage for one game, windowed or headless.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 0 10/27/2026
1.3.0 0 10/27/2026
1.2.0 0 10/27/2026
1.1.0 0 10/27/2026
1.0.0 130 10/25/2026
0.4.0-preview.1 50 10/25/2026
0.3.0-preview.1 46 10/25/2026
0.2.0-preview.1 47 10/25/2026
0.1.0-preview.1 45 10/25/2026