Yotsuba Shader
Documentation

Reference

WGSL syntax attributes

Every attribute of the WGSL syntax: the @builtin(...), @group and @binding vocabulary of WebGPU, written with @ identifiers that remain valid C#.

Overview#

The WGSL syntax is inspired by WGSL (WebGPU). It contains 24 attributes in the YotsubaShader.WgslSyntax package, whose namespace has the same name. They are generated below from its sources.

C#
using YotsubaShader.WgslSyntax;

public struct VertexOutput
{
    [@builtin_position]
    public Vector4 Position;
}

These pages list declared attributes. They do not imply that every concept is lowered by Roslyn or supported by every output target. Vector names in the listings require compatible project types.

See the same concepts side by side in Built-in values across syntaxes and Resource attributes across syntaxes.

Input attributes#

Apply to fields, parameters and properties that receive values from the pipeline.

Input.cs
using YotsubaShader.Language;
using YotsubaShader.WgslSyntax;

public struct InputExamples
{
    // Front-facing flag
    [@builtin_front_facing] public bool FrontFacingFlag;
    // Global invocation id
    [@builtin_global_invocation_id]
    public UInt3 GlobalInvocationId;
    // Instance index
    [@builtin_instance_index] public uint InstanceIndex;
    // Local invocation id
    [@builtin_local_invocation_id]
    public UInt3 LocalInvocationId;
    // Local invocation index
    [@builtin_local_invocation_index]
    public uint LocalInvocationIndex;
    // Number of subgroups
    [@builtin_num_subgroups] public uint NumberOfSubgroups;
    // Number of workgroups
    [@builtin_num_workgroups] public UInt3 NumberOfWorkgroups;
    // Primitive index
    [@builtin_primitive_index] public uint PrimitiveIndex;
    // Sample index
    [@builtin_sample_index] public uint SampleIndex;
    // Subgroup id
    [@builtin_subgroup_id] public uint SubgroupId;
    // Subgroup invocation id
    [@builtin_subgroup_invocation_id]
    public UInt3 SubgroupInvocationId;
    // Subgroup size
    [@builtin_subgroup_size] public uint SubgroupSize;
    // Vertex index
    [@builtin_vertex_index] public uint VertexIndex;
    // Workgroup id
    [@builtin_workgroup_id] public UInt3 WorkgroupId;
}

Input and output attributes#

Apply to values that can be received or produced, depending on the stage.

InputOutput.cs
using YotsubaShader.Language;
using YotsubaShader.WgslSyntax;

public struct InputOutputExamples
{
    // Clip-space position (vertex output)
    [@builtin_position] public Vector4 ClipSpacePosition;
    // Sample mask
    [@builtin_sample_mask] public uint SampleMask;
    [@location(0)] public Vector4 Value3;
}

Output attributes#

Apply to fields, parameters and return values the stage produces.

Output.cs
using YotsubaShader.Language;
using YotsubaShader.WgslSyntax;

public struct OutputExamples
{
    // Clip distance
    [@builtin_clip_distances] public float ClipDistance;
    // Fragment depth (output)
    [@builtin_frag_depth] public float FragmentDepth;
}

Method attributes#

Apply to methods, for example to set a compute workgroup size.

Method.cs
using YotsubaShader.Language;
using YotsubaShader.WgslSyntax;

public class MethodExamples
{
    [ShaderStage(Stage.Compute)]
    [@workgroup_size(8)]
    public void Workgroup_sizeExample() { }
}

Resource attributes#

Declare uniforms, buffers, textures, samplers and binding slots.

Resource.cs
using YotsubaShader.Language;
using YotsubaShader.WgslSyntax;
using YotsubaShader.WgslSyntax.Resources;

public class ResourceExamples
{
    [@binding(0)] public float Value1;
    [@group(0)] public float Value2;
    [storage(storage_use.read_write)] public float Value3;
    [uniform] public float Value4;
}

Supporting types#

Structs, classes and enums used together with the attributes.

Type.cs
using YotsubaShader.Language;
using YotsubaShader.WgslSyntax;

public class Types
{
    public YotsubaShader.WgslSyntax.Resources.Types.sampler SamplerValue;
    public YotsubaShader.WgslSyntax.Resources.Types.sampler_comparison Sampler_comparisonValue;
    public YotsubaShader.WgslSyntax.Resources.storage_use Storage_useValue;
    public YotsubaShader.WgslSyntax.Resources.Types.texture_1d<float> texture_1dGenericValue;
    public YotsubaShader.WgslSyntax.Resources.Types.texture_2d<float> texture_2dGenericValue;
    public YotsubaShader.WgslSyntax.Resources.Types.texture_2d_array<float> texture_2d_arrayGenericValue;
    public YotsubaShader.WgslSyntax.Resources.Types.texture_3d<float> texture_3dGenericValue;
    public YotsubaShader.WgslSyntax.Resources.Types.texture_cube<float> texture_cubeGenericValue;
}
Copyright © 2026 Yotsuba Shader contributors · Licensing · GitHub