Skip to content

Shaders: zero-initialize the streams variable - #3447

Merged
xen2 merged 1 commit into
stride3d:masterfrom
xen2:fix/streams-zero-init
Sep 18, 2026
Merged

xen2 merged 1 commit into
stride3d:masterfrom
xen2:fix/streams-zero-init

Conversation

@xen2

@xen2 xen2 commented Sep 18, 2026

Copy link
Copy Markdown
Member

PR details

SinglePassWireframeShader (the Bepu debug wireframe) stopped compiling on 4.4.0-beta7 with
error X4000: variable '_2168' used without having been completely initialized.

Two commits caused it, both in beta7 and neither in beta6:

  • ba272d0 made streams = input[i] read the members the stage input does not carry back from
    streams instead of zeroing them, so writing only part of one leaves the rest undefined. The
    wireframe shader writes EdgeA.xyz and never EdgeA.w.
  • f45e1de dropped ForceZeroInitializedVariables, which had been zero-initializing SPIRV-Cross
    hoisted temporaries and hiding that. Its replacement, requires_phi_undef_zero_init, only covers
    loop variables.

The private streams variable now gets an OpConstantNull initializer, so reading a member before
it is written is defined. Members the shader does write are dead stores that spirv-opt drops.
ForceZeroInitializedVariables stays off on purpose: it hides real undefined reads.

ShaderCompilerVersion.Effect goes 0 -> 1. The change is mix-time, so the per-class SPIR-V cache
stays valid, and the checked-in precompiled bytecodes are unaffected.

Test

GeometryStreamsAssignThenPartialWriteCompilesWithFxc runs fxc on the translated geometry
shader 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.

`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.
@xen2 xen2 added ci-enduser Run the end-user sample screenshot + packaging suite on this PR ci-editor Run the GameStudio editor screenshot suite on this PR ci-ios Run the iOS game test suite on this PR ci-android Run the Android game test suite on this PR labels Sep 18, 2026
@xen2
xen2 merged commit 2712b6f into stride3d:master Sep 18, 2026
52 checks passed
@xen2
xen2 deleted the fix/streams-zero-init branch September 18, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-android Run the Android game test suite on this PR ci-editor Run the GameStudio editor screenshot suite on this PR ci-enduser Run the end-user sample screenshot + packaging suite on this PR ci-ios Run the iOS game test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant