Skip to content

Shaders: keep per-lane descriptors across redundant masked moves - #2078

Closed
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-joined-descriptor-redundant-write-750
Closed

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-joined-descriptor-redundant-write-750

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Closes #750.

Summary

  • Redundant masked v_mov_b32 step-back (Tracer::lane_value / redundant_vmov / same_in_lanes): when a plain v_mov_b32 executes under a narrowed EXEC mask (runs fails because inactive lanes retain the previous value), step back to Term::Value(old) only if every feasible path in active = known ∧ reach ∧ guard already holds the replacement dword wanted across prior v_mov_b32, v_cndmask_b32, and acyclic phi joins.
  • Equivalent 32-bit integer lane-compare linking (Tracer::feasible / cmp_atom): on top of meet and few_atoms, group up to 4 pure 32-bit integer v_cmp_* / v_cmpx_* relations (_u32 / _i32 eq/ne/lt/gt/ge/le, never float compares) so repeated or complemented guards after a control-flow join prune unreachable predecessor arms.

Testing

  • Added joined_descriptor_redundant_partial_write (repeated v_cmp_gt_u32 and complemented v_cmp_le_u32), joined_buffer_and_sampler_redundant_partial_writes (nested buffer and sampler joins), and the three negative conflict checks in joined_descriptor_conflicting_partial_writes_fail (other arm word, constant overwrite, wider mask).
  • Added end-to-end GPU/WARP dxil.dll-validated waterfall readbacks lanes_sample_after_redundant_masked_image_descriptor_write and lanes_sample_with_joined_sampler_after_redundant_masked_write (verified across NVIDIA RTX 5090, AMD Radeon RDNA2, and D3D12 WARP), plus cargo clippy and cargo xtask policy.

When a plain `v_mov_b32` writes under a narrowed `EXEC` mask, step back to the register's previous value if every feasible active path already holds the replacement dword. Link equivalent 32-bit integer lane compares on top of `meet` so repeated or complemented guards after a control-flow join prune unreachable predecessor arms (Marvisak#750).

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib emit::waterfall_tests:: — 7 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (including lanes_sample_after_redundant_masked_image_descriptor_write and lanes_sample_with_joined_sampler_after_redundant_masked_write)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean preservation of per-lane descriptors across redundant masked v_movs with strong end-to-end waterfall GPU+WARP tests. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

147 passed / 0 failed. Per-lane descriptors kept across redundant masked moves (+3 tests) — descriptor liveness across masked moves.

@YouKnowWh

Copy link
Copy Markdown

Independent check for #750 at PR head b404d60cfb8a1f0d9e275a0c24f349587e3f5468 against main 940d32f69b22265690a0b5a15d6ded572ba33baf.

  • On stock main the two identity moves (repeated and complementary comparisons) are both refused at 0x108. The cross-arm word, constant overwrite and widened-mask controls are also refused.
  • On this PR the Linux victory-shader --lib suite passed 147, failed 0, ignored 2. On Windows I also ran the new image and joined-sampler end-to-end cases with WARP only, making validator availability mandatory (dxil.dll 1.8.2502.11). The per-lane expected-value checks passed, including swapped samplers. The test adapter selection and validation diagnostics were local harness changes only.
  • Offline 1.0.2.1 archive census: victory translate shaders.rpf --validate --list --jobs 8. Both revisions scanned 26,503 containers. Comparing the 25,694 listed stage outcomes by original DXIL-part hash and stage, including repeated outcomes and refusal offsets, found zero differences. This compares translator/validator outcomes, not the generated instructions, visual output or hardware PSOs. The positive evidence for new coverage is the synthetic regression test.

A performance caveat for review: an earlier wall-clock comparison of a different local port of #1182 against main is not evidence of a slowdown in #2078. I selected three slow pixel containers from that local profile and ran them individually on stock main and this PR (fresh process, one worker, same CPU and validator, both orders). For example 6f06d377496b2eb7 validated in both processes on each revision: main 10.56 and 57.33 s; PR 20.40 and 0.82 s. A separate coarse tracing run on the PR spent ~3.5 ms in the initial resource tracking pass, ~201.0 s between entering emit_with and returning to validation, and ~39 ms validating. Another run spent <1 s in emission. An additional instrumented run spent 19.93 s in the first call to lower::lower, which returned successfully without the discard fallback. This locates the long interval on that input, not its underlying cause or a general speed change. No title launch or hardware GPU run; no game files attached.

AI-assisted local validation. Thanks for taking on the current-main PR.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The change looks careful. Tracer::lane_value steps back over a masked v_mov_b32 when redundant_vmov and same_in_lanes show that active lanes already hold the written dword. Tracer::feasible and cmp_atom link repeated or complemented 32-bit integer compares, which is sound because Atom::Lane is the compare bit before EXEC masking. The positive and negative tests, including the GPU/WARP readbacks, are good, and CI passes. The concern is value against cost. It adds about 450 lines to resource.rs, and feasible now replaces meet in runs and in the join path for every program. Yet the retail census in the comments found zero differences. When #1182 was closed, this refusal class was already at zero for the title's shaders in main.

What would change the verdict: a title shader (identified by hash, with no shader data) that this change lets translate, and a before/after translation-time comparison across the archive. The single-container timings in the comments are too noisy to rule out a slowdown.


Generated by Claude Code

@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Closing: main (da82e44) now lands nested/joined descriptor handling (59c78bb, ff47463, 850b66f), and this branch showed no corpus delta against main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shader resource tracking: redundant masked write after a per-lane descriptor join is refused (synthetic repro on #566)

5 participants