Repository navigation
Shaders: fix duplicate latch folding, unreachable phi edges, and replace_const caching in DXIL bitcode - #110
Open
hamdog0203 wants to merge 1 commit into
Open
hamdog0203 wants to merge 1 commit into
hamdog0203 wants to merge 1 commit into
Conversation
…ace_const caching in DXIL bitcode
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.
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).