Repository navigation
Shaders: zero-initialize the streams variable - #3447
Merged
Merged
Conversation
`streams = input[i]` reads the members the stage input does not carry back from streams, so writing only part of one left the rest undefined and fxc rejected the translated HLSL with X4000. Stride.BepuPhysics.Debug's SinglePassWireframeShader writes EdgeA.xyz and never EdgeA.w, so it stopped compiling. Bumps ShaderCompilerVersion.Effect: the change is mix-time, so the per-class SPIR-V cache stays valid. Test: GeometryStreamsAssignThenPartialWriteCompilesWithFxc, running fxc on the translated geometry shader. Full suite 840/840.
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.
PR details
SinglePassWireframeShader(the Bepu debug wireframe) stopped compiling on 4.4.0-beta7 witherror X4000: variable '_2168' used without having been completely initialized.Two commits caused it, both in beta7 and neither in beta6:
streams = input[i]read the members the stage input does not carry back fromstreamsinstead of zeroing them, so writing only part of one leaves the rest undefined. Thewireframe shader writes
EdgeA.xyzand neverEdgeA.w.ForceZeroInitializedVariables, which had been zero-initializing SPIRV-Crosshoisted temporaries and hiding that. Its replacement,
requires_phi_undef_zero_init, only coversloop variables.
The private
streamsvariable now gets anOpConstantNullinitializer, so reading a member beforeit is written is defined. Members the shader does write are dead stores that spirv-opt drops.
ForceZeroInitializedVariablesstays off on purpose: it hides real undefined reads.ShaderCompilerVersion.Effectgoes 0 -> 1. The change is mix-time, so the per-class SPIR-V cachestays valid, and the checked-in precompiled bytecodes are unaffected.
Test
GeometryStreamsAssignThenPartialWriteCompilesWithFxcruns fxc on the translated geometryshader and fails with the same X4000 without the fix. Nothing in the suite ran fxc before, which is
why this was not caught. Suite 840/840.