Skip to content

Shaders: path-sensitive reachability for missing values across phi joins (#736) - #1230

Closed
Ctrl-Alt-Haze wants to merge 2 commits into
Marvisak:mainfrom
Ctrl-Alt-Haze:fix/shader-736-reachability
Closed

Ctrl-Alt-Haze wants to merge 2 commits into
Marvisak:mainfrom
Ctrl-Alt-Haze:fix/shader-736-reachability

Conversation

@Ctrl-Alt-Haze

Copy link
Copy Markdown

Summary

Fixes #736 (#612 regression on phi reachability) while preserving #604 soundness and passing the two-join live descriptor word soundness control.

Changes

  • crates/victory-shader/src/structure.rs:
    • Added BoolSet<'a>, a non-mutating ROBDD overlay over &'a Bools (and, or, not, forget for loop back-edges, edge for reach[q] & exits[q], sat, bounded at MAX_OVERLAY_NODES = 65536 with conservative Bool::TRUE fallback on overflow).
  • crates/victory-shader/src/emit/lower.rs:
    • Replaced Shaders: a phi that only another read phi consumes is live too (#604) #612's path-blind read_phis transitive closure + global bad/Stop::Retry poisoning with single-pass path-sensitive missing-value taint tracking (ReadDep, ValueDeps, SinkRead, check_missing_reach) solved to a bounded fixpoint (MAX_TAINT_ROUNDS = 256 with conservative Bool::TRUE widening) in fill_phis.
    • Updated Lower::get (get_inner) so mask_dword (mask_ok && is_mask) does not falsely treat EXEC phis/predecessors as data reads.
    • Replaced silent old fallbacks in old_i32_of with lane-conditioned OldDep / direct_missing tracking (!guard for write_placed and ds atomic outside when guarded with a destination register; active lanes for place_bits, write_16(keep), and low_half while exempting only v_interp_p1lv_f16 accumulator reads), and routed float_src / v_fmac_f32 / self.floats cache hits through record_read so live missing values never silently drop.
    • Added negative and positive synthetic controls in lower::tests: preserved a_missing_value_stays_missing_through_two_live_joins (Shader emitter accepts an unsupported timestamp read after two SSA joins #604), added the two-join live structured-buffer descriptor-word control (a_live_descriptor_word_stays_missing_through_two_joins), old_register_missing_values_and_cached_floats_stay_refused, unknown_stride_load_stays_missing_when_live_and_lowers_when_overwritten, first_half_of_interpolation_stays_missing_when_live_and_lowers_when_overwritten, guarded_write_and_exec_mask_phi_lower_soundly, and loop_missing_value_refuses_on_back_edge_and_lowers_when_infeasible.
  • crates/victory-shader/src/emit/valu_tests.rs:
    • Added reachability_overwritten_missing_phis_match_on_host_and_warp executing correlated-overwrite descriptor-word, unknown-stride buffer_load_dword, and loop-invariant s_memtime shaders with dxil.dll validation on RTX 5070 Ti + WARP.

Verification

  • Hardware / Toolchain: Windows x64, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2135), WARP (VICTORY_WARP=1), Windows SDK 10.0.26100.0 dxil.dll, Rust 1.98.1, base ffe310eb.
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • cargo test --workspace --locked: 349 passed, 0 failed, 6 ignored (victory-shader 127/1 ign)
  • cargo test -p victory-shader --features host --locked (RTX 5070 Ti + WARP): 127 passed, 0 failed, 1 ignored
  • VICTORY_WARP=1 cargo test -p victory-shader --features host --locked (WARP): 127 passed, 0 failed, 1 ignored
  • cargo test -p victory-gpu --features diagnostics --locked & VICTORY_D3D12_WARP=1: 53 passed, 0 failed, 1 ignored each
  • rustfmt --edition 2024 --check on modified files: zero diffs on added/modified lines (valu_tests.rs completely clean).
  • Not tested: retail title corpus (no retail game assets used; synthetic tests only).

AI use: Written and verified locally with an AI coding swarm (gemini-4-hydrogen-high), then independently audited and tested on RTX 5070 Ti + WARP.

@pablogonz12

Copy link
Copy Markdown

Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 665 / 768 656 656

One program that translated on the base no longer does: a pixel program that now stops at "barycentrics read directly" (2 -> 3 pixel programs). Nothing else moves; worth a look whether your reachability change is meant to reach a barycentric read that the base folded away.

Not tested: in-game.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 3a00856: cargo test -p victory-shader passes, 127 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@Ctrl-Alt-Haze

Copy link
Copy Markdown
Author

@pablogonz12 Thank you for catching that pixel regression on the 768-program RADV check!

Root cause: Pixel shaders begin with Input::Barycentric (Val::Missing("barycentrics read directly")) in v0/v1. When a 16-bit or sub-dword op reuses v0/v1 (low_half, write_half, or SDWA UNUSED_PRESERVE in place_bits), the prior commit recorded OldDep / DirectMissing on the whole 32-bit Value without tracking bitmasks (0x0000_FFFF vs 0xFFFF_0000), so reading only the newly written lo16 or overwriting hi16 afterward falsely tripped "barycentrics read directly".

Fix (6f77efd):

  • Added 32-bit bitmask taint tracking (BitMaskCond, bitmask-aware ReadDep/OldDep/DirectMissing, Transfer::{Broadcast, Shift}) through partial writes (low_half, write_half, place_bits, v_fma_mix*, write_placed) and sub-dword reads (half_src, sdwa_src, v_and_b32/s_and_b32 constants, shifts, v_bfe_*/s_bfe_*, v_pack_b32_f16, v_pk_*, v_perm_b32, v_cvt_f32_ubyte*, v_mul_*24/v_mad_*24, export, image a16, buffer d16 store).
  • Added emit::lower::tests::pixel_barycentric_reuse_tracks_exact_bitmasks (6 positive lo16 / full-overwrite cases + 6 negative cases confirming untouched halves still refuse "barycentrics read directly") and emit::valu_tests::pixel_barycentric_reuse_16bit_and_sdwa_match_on_host_and_warp (live RTX 5070 Ti + WARP pixel shader readback).

Re-verified on 6f77efd:

  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): pass
  • cargo test --workspace --locked: 351 passed, 0 failed, 6 ignored (victory-shader 129/1 ign)
  • cargo test -p victory-shader --features host --locked (RTX 5070 Ti & VICTORY_WARP=1): 129 passed, 0 failed, 1 ignored each
  • cargo test -p victory-gpu --features diagnostics --locked (RTX 5070 Ti & VICTORY_D3D12_WARP=1): 53 passed, 0 failed, 1 ignored each

AI-assisted fix (gemini-4-hydrogen-high), independently audited and tested on RTX 5070 Ti + WARP; no game data.

@Ctrl-Alt-Haze

Copy link
Copy Markdown
Author

Rebased onto upstream main (70564ae) at 6bd5dd9 (commit 1 at 7c2f3ed, commit 2 at 6bd5dd9):

  • Confirmed desc_word_shader still fails on clean upstream/main 70564ae (Unsupported { offset: 76, what: "a descriptor's address or format read as data" }), so path-sensitive check_missing_reach remains necessary beyond a7fc47a / dead_on_edge.
  • Preserved dead_on_edge / never_taken edge pruning alongside check_missing_reach, kept buffer_guard on descriptor loads, preserved narrow16, fmac_half, and extra-offset packed image addressing from 70564ae, removed superseded low16, and added the new HostShader fields in valu_tests.rs.

Verified locally on Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP:

  • cargo xtask policy: passed (174 files ok)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default & --all-features): passed
  • Targeted reachability/missing tests: reachability_overwritten_missing_phis_match_on_host_and_warp passed, a_missing_value_stays_missing_through_two_live_joins passed, a_missing_value_on_a_path_no_lane_takes_is_dead passed, a_value_no_lane_from_its_edge_reads_needs_no_form passed, pixel_barycentric_reuse_16bit_and_sdwa_match_on_host_and_warp passed
  • Workspace non-gpu/non-shader crates (--locked -- --test-threads=1): victory 1 passed, victory-core 11 passed, victory-formats 23 passed / 4 ignored, victory-game 15 passed, victory-hle 99 passed (97 unit + 1 fidelityfx + 1 no_dll_planting), victory-loader 25 passed (22 unit + 2 load_probe + 1 title_dlls), victory-pe 7 passed, victory-pipeline 4 passed, xtask 4 passed
  • cargo test -p victory-gpu --locked -- --test-threads=1: 76 passed; 2 failed; 1 ignored (pre-existing on clean 70564ae: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views)
  • cargo test -p victory-shader --features host --locked (hardware): 215 passed; 3 failed; 2 ignored (pre-existing on clean 70564ae on RTX 5070 Ti: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware)
  • VICTORY_WARP=1 cargo test -p victory-shader --features host --locked: 216 passed; 2 failed; 2 ignored (pre-existing gathers_at_a_level_match_the_hardware + permutes_read_the_lane_named_and_zero_from_lanes_left_out which skips under VICTORY_WARP=1 and passed on RTX hardware)

@Ctrl-Alt-Haze
Ctrl-Alt-Haze force-pushed the fix/shader-736-reachability branch from 6f77efd to 6bd5dd9 Compare November 24, 2026 22:24
@Dathinel

Copy link
Copy Markdown
Contributor

Retested the cyclic regression fixture from #604/#612 on the rebased head 6bd5dd9 (Windows/MSVC). The two mutually dependent phis still preserve the live timestamp: lowering refuses it with the same diagnostic as the direct read. Making the timestamp dead or replacing it with a constant still lowers successfully. All four outcomes match #612.

To reproduce, add the test function to the existing tests in emit/lower.rs and run cargo test --locked -p victory-shader --features host --lib emit::lower::tests::timestamp_phi_cycle -- --exact --nocapture. One test ran and passed. This checks the emitter before GPU dispatch; game behavior is untested here. AI-assisted.

PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

now rebased, it replaces main's #736 fix (live_edges with never_taken/dead_on_edge in fill_phis, a7fc47a) with a 2.2k-line taint fixpoint and removes the never_taken/dead_on_edge use that main's emitted programs rely on; no measurement on the title's list.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: #612 stops 323 previously validated programs from translating

5 participants