summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-10 11:02:58 -0700
committerGitHub <noreply@github.com>2025-07-10 18:02:58 +0000
commitaa3cc1e79315592e9b22fccd77fc27fef0c09762 (patch)
tree46b780e3b2237049fdb6b2a778894c5d3d501a86 /source
parentc1d07df3ede2e0d87d81a8d10429ae5df88519e1 (diff)
Fix SV_VertexID and SV_InstanceID crash with -preserve-params in SPIR-V emitter (#7691)
* Initial plan * Fix SV_VertexID and SV_InstanceID crash with -preserve-params in SPIR-V emitter Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix transformation layer to handle unused builtin params properly This ensures that builtin decorations are correctly transformed for unused parameters with -preserve-params, preventing the SPIR-V emitter from seeing un-translated builtins like sv_vertexid. Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Format code according to project style Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp12
1 files changed, 12 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);
}
}
}