Overview#
The MSL syntax is inspired by the Metal Shading Language. It contains 32 attributes in the YotsubaShader.MslSyntax package, whose namespace has the same name. They are generated below from its sources.
using YotsubaShader.MslSyntax;
public struct VertexOutput
{
[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.
using YotsubaShader.Language;
using YotsubaShader.MslSyntax;
public struct InputExamples
{
[attribute(0)] public Vector4 Value1;
// Barycentric coordinates
[barycentric_coord] public Vector4 BarycentricCoordinates;
// Base instance
[base_instance] public uint BaseInstance;
// Base vertex
[base_vertex] public uint BaseVertex;
// Front-facing flag
[front_facing] public bool FrontFacingFlag;
// Instance index
[instance_id] public uint InstanceIndex;
// Primitive index
[primitive_id] public uint PrimitiveIndex;
// Sample index
[sample_id] public uint SampleIndex;
// Subgroup id
[simdgroup_index_in_threadgroup] public uint SubgroupId;
// Number of subgroups
[simdgroups_per_threadgroup] public uint NumberOfSubgroups;
// Subgroup invocation id
[thread_index_in_simdgroup]
public UInt3 SubgroupInvocationId;
// Local invocation index
[thread_index_in_threadgroup]
public uint LocalInvocationIndex;
// Global invocation id
[thread_position_in_grid] public UInt3 GlobalInvocationId;
// Local invocation id
[thread_position_in_threadgroup]
public UInt3 LocalInvocationId;
// Workgroup id
[threadgroup_position_in_grid] public UInt3 WorkgroupId;
// Number of workgroups
[threadgroups_per_grid] public UInt3 NumberOfWorkgroups;
// Subgroup size
[threads_per_simdgroup] public uint SubgroupSize;
// Workgroup size (built-in value)
[threads_per_threadgroup] public UInt3 WorkgroupSize;
// Vertex index
[vertex_id] public uint VertexIndex;
}
Input and output attributes#
Apply to values that can be received or produced, depending on the stage.
using YotsubaShader.Language;
using YotsubaShader.MslSyntax;
public struct InputOutputExamples
{
// Clip-space position (vertex output)
[position] public Vector4 ClipSpacePosition;
// Render target layer
[render_target_array_index] public uint RenderTargetLayer;
// Sample mask
[sample_mask] public uint SampleMask;
// Viewport index
[viewport_array_index] public uint ViewportIndex;
}
Output attributes#
Apply to fields, parameters and return values the stage produces.
using YotsubaShader.Language;
using YotsubaShader.MslSyntax;
public struct OutputExamples
{
// Clip distance
[clip_distance] public float ClipDistance;
[color] public Vector4 Value2;
// Fragment depth (output)
[depth] public float FragmentDepth;
// Stencil reference (output)
[stencil] public uint StencilReference;
}
Resource attributes#
Declare uniforms, buffers, textures, samplers and binding slots.
using YotsubaShader.Language;
using YotsubaShader.MslSyntax;
using YotsubaShader.MslSyntax.Resources;
public class ResourceExamples
{
[buffer(0)] public float Value1;
[constant] public float Value2;
[device] public float Value3;
[sampler(0)] public float Value4;
[texture(0)] public float Value5;
}
Supporting types#
Structs, classes and enums used together with the attributes.
using YotsubaShader.Language;
using YotsubaShader.MslSyntax;
public class Types
{
public YotsubaShader.MslSyntax.Resources.Types.depth2d<float> depth2dGenericValue;
public YotsubaShader.MslSyntax.Resources.Types.sampler SamplerValue;
public YotsubaShader.MslSyntax.Resources.Types.texture1d<float> texture1dGenericValue;
public YotsubaShader.MslSyntax.Resources.Types.texture2d<float> texture2dGenericValue;
public YotsubaShader.MslSyntax.Resources.Types.texture2d_array<float> texture2d_arrayGenericValue;
public YotsubaShader.MslSyntax.Resources.Types.texture3d<float> texture3dGenericValue;
public YotsubaShader.MslSyntax.Resources.Types.texturecube<float> texturecubeGenericValue;
}
