Recursive AI
oneshaderGoAvailable

oneshader for Go

A free, open-source HLSL shader compiler for Go, MIT or Apache-2.0. It compiles modern HLSL vertex, pixel and compute shaders to SPIR-V, Metal Shading Language, WGSL and DXIL, each with reflection.

Pure Go: no cgo and no dependencies. go generate turns your .hlsl files into Go structs laid out like the shader’s buffers, binding values and embedded compiled code.

go get recursiveai.org/go/oneshader@v1.0.0

Compile a shader

The README’s example as a whole program, run with Go 1.26.8 against v1.0.0 from the module proxy. One Compile call gives one blob per entry point and target.

Errors, go generate and the command line
double.hlslHLSL
RWStructuredBuffer<float> Values : register(u0);
 
[shader("compute")]
[numthreads(64, 1, 1)]
void main(uint3 id : SV_DispatchThreadID)
{
    Values[id.x] *= 2.0;
}
main.goGo
package main
 
import (
    "fmt"
    "log"
    "os"
 
    "recursiveai.org/go/oneshader"
)
 
func main() {
    src, err := os.ReadFile("double.hlsl")
    if err != nil {
        log.Fatal(err)
    }
    res, err := oneshader.Compile(src,
        oneshader.WithName("double.hlsl"),
        oneshader.WithTargets(
            oneshader.TargetSPIRV,
            oneshader.TargetMSL,
            oneshader.TargetWGSL))
    if err != nil {
        for _, d := range res.Errors() {
            fmt.Println(d)
        }
        os.Exit(1)
    }
    for _, b := range res.Blobs {
        fmt.Println(b.Entry, b.Stage, b.Target, len(b.Data), "bytes")
    }
    wgsl, _ := res.Find("main", oneshader.TargetWGSL)
    fmt.Print(string(wgsl.Data))
}
Shellsh
go mod init example.com/double
go get recursiveai.org/go/oneshader@v1.0.0
go run .
OutputGo 1.26.8
main Compute spirv 644 bytes
main Compute msl 635 bytes
main Compute wgsl 336 bytes
@group(0) @binding(0) var<storage, read_write> Values: array<u32>;
 
@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_id) a_main_id: vec3<u32>) {
  let v0 = a_main_id;
  let v1 = v0[0];
  let v2 = bitcast<f32>(Values[(v1 * 4u) >> 2u]);
  let v3 = v2 * 2.0f;
  Values[(v1 * 4u) >> 2u] = bitcast<u32>(v3);
  return;
}

Compile time

From the README at v1.0.0: one entry point to SPIR-V per process, median of 15 rounds, on an AMD Ryzen 9 7950X3D with Go 1.26.8 on Linux, one run on December 4, 2026.

Method and machine Every row

“Compile time against DXC 1.9.2609, the reference compiler, run as a native process, on a corpus of 106 entry points (105 compile; see below): 29 from a 2D renderer, 26 from a 3D PBR set, 24 compute kernels, 26 language-feature and type probes. Both tools compile one entry point to SPIR-V for Vulkan 1.2 at their default optimization, one process per entry point, with the blob written to disk. Every output passes spirv-val --target-env vulkan1.2.”

GroupTime vs DXC (geometric mean)
2D renderer3.02× faster
3D (PBR set)2.94× faster
compute2.89× faster
language features and types2.81× faster
All2.92× faster

“‘In process’ is Compile called from Go (go test -bench CorpusSPIRV -benchmem, median of 5 runs of 100 iterations), the cost a build tool pays per shader without a process start: the median is 0.47 ms and 3,774 allocations.”

README.md at v1.0.0

What it does