summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp12
-rw-r--r--tests/spirv/sv-vertex-id-preserve-params.slang13
2 files changed, 25 insertions, 0 deletions
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index 1a34a9877..fc1bcfa5a 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -4006,6 +4006,13 @@ void legalizeTargetBuiltinVar(GLSLLegalizationContext& context)
user->replaceUsesWith(sub);
}
});
+
+ // For unused parameters (like with -preserve-params), also update the builtin
+ // decoration to ensure SPIR-V emitter sees the correct builtin
+ IRBuilder builder(varInst);
+ builder.addTargetBuiltinVarDecoration(
+ varInst,
+ IRTargetBuiltinVarName::SpvInstanceIndex);
}
// Repalce SV_VertexID with gl_VertexIndex - gl_BaseVertex.
else if (builtinVarName == IRTargetBuiltinVarName::HlslVertexID)
@@ -4032,6 +4039,11 @@ void legalizeTargetBuiltinVar(GLSLLegalizationContext& context)
user->replaceUsesWith(sub);
}
});
+
+ // For unused parameters (like with -preserve-params), also update the builtin
+ // decoration to ensure SPIR-V emitter sees the correct builtin
+ IRBuilder builder(varInst);
+ builder.addTargetBuiltinVarDecoration(varInst, IRTargetBuiltinVarName::SpvVertexIndex);
}
}
}
diff --git a/tests/spirv/sv-vertex-id-preserve-params.slang b/tests/spirv/sv-vertex-id-preserve-params.slang
new file mode 100644
index 000000000..6bf4bfb89
--- /dev/null
+++ b/tests/spirv/sv-vertex-id-preserve-params.slang
@@ -0,0 +1,13 @@
+//TEST:SIMPLE(filecheck=SPIRV): -entry VertexMain -stage vertex -target spirv -preserve-params
+//TEST:SIMPLE(filecheck=SPIRV): -entry VertexMain -stage vertex -target spirv -emit-spirv-directly -preserve-params
+
+// Test for https://github.com/shader-slang/slang/issues/7689
+// SV_VertexID combined with -preserve-params should not crash
+
+// SPIRV: OpEntryPoint
+
+[shader("vertex")]
+float4 VertexMain(uint vertexId: SV_VertexID, uint instanceId: SV_InstanceID) : SV_Position
+{
+ return float4(0.0);
+} \ No newline at end of file