summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-01-16 12:19:47 -0500
committerGitHub <noreply@github.com>2025-01-16 09:19:47 -0800
commit9167e0d04c2d57593506feca94aacf73aad17b65 (patch)
tree4d406f0bc1ff48cde86b3830bbfe954e7c6f744a
parentedf5e9f97015a09fa0f2bed58d6a04744992d23f (diff)
support SV_ViewIndex for Metal (#6103)
Co-authored-by: Yong He <yonghe@outlook.com>
-rw-r--r--source/slang/slang-ir-legalize-varying-params.cpp4
-rw-r--r--tests/hlsl-intrinsic/system-values-draw-parameters.slang17
2 files changed, 18 insertions, 3 deletions
diff --git a/source/slang/slang-ir-legalize-varying-params.cpp b/source/slang/slang-ir-legalize-varying-params.cpp
index 69d62c8bf..9720084ba 100644
--- a/source/slang/slang-ir-legalize-varying-params.cpp
+++ b/source/slang/slang-ir-legalize-varying-params.cpp
@@ -3201,7 +3201,9 @@ protected:
}
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 ea84ac116..e45366939 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<float> 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;
}