diff --git a/source/slang/slang-ir-legalize-varying-params.cpp b/source/slang/slang-ir-legalize-varying-params.cpp index 69d62c8bf8..9720084ba3 100644 --- a/source/slang/slang-ir-legalize-varying-params.cpp +++ b/source/slang/slang-ir-legalize-varying-params.cpp @@ -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: diff --git a/tests/hlsl-intrinsic/system-values-draw-parameters.slang b/tests/hlsl-intrinsic/system-values-draw-parameters.slang index ea84ac1165..e453669398 100644 --- a/tests/hlsl-intrinsic/system-values-draw-parameters.slang +++ b/tests/hlsl-intrinsic/system-values-draw-parameters.slang @@ -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 scales; + struct VSInput { uint vertexID : SV_VertexID; @@ -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; }