HLSL: Zero-init OpUndef Phi incomings to avoid uninitialized reads#2616
Merged
HansKristian-Work merged 1 commit intoKhronosGroup:mainfrom Apr 27, 2026
Merged
HLSL: Zero-init OpUndef Phi incomings to avoid uninitialized reads#2616HansKristian-Work merged 1 commit intoKhronosGroup:mainfrom
HansKristian-Work merged 1 commit intoKhronosGroup:mainfrom
Conversation
5593ac8 to
5e4061f
Compare
HansKristian-Work
approved these changes
Apr 27, 2026
Contributor
HansKristian-Work
left a comment
There was a problem hiding this comment.
Seems reasonable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an
OpPhihasOpUndefon an incoming edge, SPIRV-Cross emitted a read of the source variable. If that source was uninitialized too, FXC rejects the HLSL withX4555orX4000.OpUndefallows any value per spec, so we substitute zero:flush_phi: emitlhs = 0when the Phi source isOpUndef.= 0whenstatic_expressionisOpUndef, via a newundef_loop_variable_initializer_suffixhelper.This 2nd version also make sure to not affect GLSL which doesn't need it.
Test
Added
shaders-hlsl-no-opt/asm/comp/phi-undef-loop.asm.comp— a minimal SPIR-V loop withOpUndefas the preheader Phi incoming.Without the patch, the generated HLSL is:
With the patch,
_19is declared asuint _19 = 0u;and FXC accepts it.