Skip to content

Commit

Permalink
support SV_ViewIndex for Metal (#6103)
Browse files Browse the repository at this point in the history
Co-authored-by: Yong He <yonghe@outlook.com>
  • Loading branch information
fairywreath and csyonghe authored Jan 16, 2025
1 parent edf5e9f commit 9167e0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion source/slang/slang-ir-legalize-varying-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,9 @@ class LegalizeMetalEntryPointContext : public LegalizeShaderEntryPointContext
}
case SystemValueSemanticName::ViewID:
{
result.isUnsupported = true;
result.systemValueName = toSlice("amplification_id");
result.permittedTypes.add(builder.getBasicType(BaseType::UInt));
result.permittedTypes.add(builder.getBasicType(BaseType::UInt16));
break;
}
case SystemValueSemanticName::ViewportArrayIndex:
Expand Down
17 changes: 15 additions & 2 deletions tests/hlsl-intrinsic/system-values-draw-parameters.slang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//TEST:SIMPLE(filecheck=CHECK_HLSL): -entry main -stage vertex -target hlsl
//TEST:SIMPLE(filecheck=CHECK_METAL): -entry main -stage vertex -target metal

StructuredBuffer<float> scales;

struct VSInput
{
uint vertexID : SV_VertexID;
Expand All @@ -16,19 +18,30 @@ struct VSOutput

VSOutput main(VSInput input,
uint startVertexLocation : SV_StartVertexLocation,
uint startInstanceLocation : SV_StartInstanceLocation)
uint startInstanceLocation : SV_StartInstanceLocation,
uint viewIndex : SV_ViewID)
{
VSOutput output;

float x = (float)(input.vertexID + startVertexLocation) * 0.1f;
float y = (float)(input.instanceID + startInstanceLocation) * 0.2f;
output.position = float4(x, y, 0.0f, 1.0f);
output.position = float4(x, y, 0.0f, 1.0f) * scales[viewIndex];

// CHECK_SPIRV: BuiltIn BaseVertex
// CHECK_GLSL: gl_BaseVertex
// CHECK_HLSL: SV_StartVertexLocation
// CHECK_METAL: base_vertex

// CHECK_SPIRV: BuiltIn BaseInstance
// CHECK_GLSL: gl_BaseInstance
// CHECK_HLSL: SV_StartInstanceLocation
// CHECK_METAL: base_instance

// CHECK_SPIRV: BuiltIn ViewIndex
// CHECK_GLSL: gl_ViewIndex
// CHECK_HLSL: SV_ViewID
// CHECK_METAL: amplification_id

return output;
}

0 comments on commit 9167e0d

Please sign in to comment.