Shaders: fix duplicate latch folding, unreachable phi edges, and replace_const caching in DXIL bitcode #110
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/110"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Zettrox/ztrx. Originally posted by hamdog0203 on 2026-11-25T12:07:29Z.
Summary
Fixes three correctness bugs in the DXIL bitcode module/emitter (
crates/victory-shader/src/emit/bitcode.rs), adapted fromMarvisak/VIctory#1145forztrx:Module::write): When two distinct empty latch blocks branch back to the same loop header from the same predecessor (e.g. aCondBrwhose two arms carry different incoming phi values into the header), folding both latches mapped both back-edges onto the same predecessor block ID in the emittedPHI, causingdxil.dllvalidation to fail withPHI node has multiple entries for the same basic block with different incoming values!. Folding is now guarded sofold[*p].is_none(),fold[h].is_none(), andfolded_edges.insert((*p, h))prevent chained or duplicate(predecessor, header)folds.PHIincoming edges (Module::reachable,Module::live,Module::write,census::census):livepreviously seeded instructions from unreachable blocks and followed allOp::Phiincoming values, whileModule::writeemittedPHIentries for unreachable predecessors (whose value IDs were unassignedu32::MAX, panicking withuse of a void value).reachable()now computes reachability and reverse postorder once (reused by bothModule::writeandcensus::census),live(&seen)skips unreachable blocks and unreachable phi edges, andModule::writeomits unreachable incoming edges when writingOp::Phi. (This fixes raw/unoptimized emission underVICTORY_SHADER_OPT=0as well as any module reachingwrite()with dead predecessors.)const_idscache entry inModule::replace_const: Mutatingself.consts[o]left the old constant value mapped tooinself.const_ids, so subsequent calls requesting the original constant could receive the mutated constant ID.replace_constnow removes the previous cache entry when it still points too.Negative Control (unpatched
main90b529f)Verified in a separate detached worktree on
90b529fwith only the new tests applied:replace_const_evicts_old_cache_key: failed (assertion left != right failed: left: Const(0), right: Const(0)).two_empty_latches_to_same_header_validate: failed DXIL validation (PHI node has multiple entries for the same basic block with different incoming values!).phi_with_unreachable_predecessor_validates: panicked inbitcode.rs:761(use of a void value).Verification (at
fa28c62)Environment: Windows 11 x64 (
26200.9974), NVIDIA GeForce RTX 4060 (8 GB, Wave32, driver621.35), Microsoft WARP, Windows SDKdxil.dll(10.0.26100.0),rustc 1.98.1.cargo test --locked -p victory-shader --lib -- replace_const_evicts_old_cache_key two_empty_latches_to_same_header_validate phi_with_unreachable_predecessor_validates written_bytes_unchanged worklist_liveness_matches_passes unread_phis_are_dropped --nocapture: 6 passed, 0 failed (bothfinish_with(0)and defaultfinish()validated viadxil.dlland created compute pipelines on both RTX 4060 and WARP with no skips;written_bytes_unchangedconfirms byte-identical output on existing valid shaders).cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings).cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings).cargo test --workspace --locked: all crates passed with 0 failures (victory1,victory_core11,victory_formats24 / 4 ignored,victory_game2,victory_gpu110 / 1 ignored,victory_hle95 +no_dll_planting1,victory_loader24 +load_probe2 +title_dlls1,victory_pe7,victory_pipeline4,victory_shader213 / 2 ignored,xtask4 includingrepository_passes_policy)..githooks/pre-commit: passed (asset policy: 3 files ok).Imported from Zettrox/ztrx. Originally posted by Aniseto on 2026-11-25T15:07:16Z.
Ran the DXIL bitcode tests at
fa28c62(clean PR head onmain90b529f):System
rust-toolchain.toml), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (VICTORY_DXIL), debug buildResults
cargo test --locked -p victory-shader --lib -- replace_const_evicts_old_cache_key two_empty_latches_to_same_header_validate phi_with_unreachable_predecessor_validates written_bytes_unchanged worklist_liveness_matches_passes unread_phis_are_dropped --nocapture: 6 passed, 0 failed, 0 ignored, 209 filtered out (exit 0)cargo test --locked -p victory-shader --lib -- --test-threads=1: 213 passed, 0 failed, 2 ignored (exit 0)What this adds
The thread already has the author's RTX 4060 (Ampere) run with the Windows SDK
dxil.dll10.0.26100.0. This adds a Blackwell wave32 part with DXIL validator 1.9.2609.5: the two shader tests that previously failed DXIL validation and the cache test pass here, andwritten_bytes_unchangedstill passes.Not tested
The title's shader pack, live pipeline creation, retail runs,
VICTORY_SHADER_OPT=0raw emission, a WARP control lane, the console compiler's DXC, release profile, AMD and Intel GPUs.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.