Yotsuba Shader
English

One shader. Five ways to write it.

The five syntax projects declare C# attributes inspired by HLSL, GLSL, MSL, SPIR-V, and WGSL. Their concepts are intended to share an output path; the complete compiler pipeline is still in development. WGSL authoring attributes exist, while WGSL output is planned for 2027.


Triangle.cs
using YotsubaShader.Language;
using YotsubaShader.HlslSyntax;
using YotsubaShader.HlslSyntax.Resources;

public struct VertexOutput
{
    [SV_Position]
    public Vector4 Position;
}

public class Triangle
{
    [register(RegisterPrefix.u, 0)]
    public RWStructuredBuffer<float> Output;

    [ShaderStage(Stage.Vertex)]
    public VertexOutput Vertex([SV_VertexID] uint id)
    {
        VertexOutput output = new VertexOutput();
        output.Position = new Vector4(0, 0, 0, 1);
        return output;
    }

    [ShaderStage(Stage.Fragment)]
    [return: SV_Target(0)]
    public Vector4 Fragment(VertexOutput input)
    {
        return new Vector4(1, 0.4f, 0.7f, 1);
    }

    [ShaderStage(Stage.Compute)]
    [numthreads(8, 8, 1)]
    public void Compute([SV_DispatchThreadID] UInt3 id)
    {
    }
}

The same concept, five spellings

Triangle.cs
using YotsubaShader.Language;
using YotsubaShader.HlslSyntax;

public struct VertexOutput
{
    // Clip-space position (vertex output)
    [SV_Position]
    public Vector4 Position;
}

public class BuiltIns
{
    [ShaderStage(Stage.Vertex)]
    public VertexOutput Vertex(
        // Vertex index
        [SV_VertexID] uint vertex,
        // Instance index
        [SV_InstanceID] uint instance)
    {
        VertexOutput output = new VertexOutput();
        output.Position = new Vector4(vertex, instance, 0, 1);
        return output;
    }

    [ShaderStage(Stage.Fragment)]
    public Vector4 Fragment(
        // Fragment coordinate
        [SV_Position] Vector4 coord)
    {
        return new Vector4(coord.X, coord.Y, 0, 1);
    }

    [ShaderStage(Stage.Compute)]
    // Workgroup size (method attribute)
    [numthreads(8, 8, 1)]
    public void Compute(
        // Global invocation id
        [SV_DispatchThreadID] uint id)
    {
        uint index = id;
    }
}

Full built-in reference