victory-shader: lift remaining DXR 1.1 RayQuery Phase 3 fallback patterns #431
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/431"
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 Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T10:44:49Z.
Summary
Implements Wave 11B: DXR 1.1 Hardware RT
RayQueryPhase 3 incrates/victory-shader/src/emit/lower/rayquery/analyze.rs, soundly lifting the remaining 4 fallback patterns that previously kept most active RT shaders on the slow inline software BVH path, plus fixing 3 pre-existing soundness /bvh32lifting issues discovered during adversarial review.Changes in
crates/victory-shader/src/emit/lower/rayquery/analyze.rsis_iter_overflow_state_cndmask,feeds_latch_state_direct_or_iter_cap):v_cndmask_b32 v_state, 0, incoming_state, (v_iter < K)(both polarities) strictly when targeting traversal state (!tmax_phi && feeds_latch_state_check),K >= 1024, andv_iteris proven to be a pure unguarded+1(v_add_nc_u32) loop counter initialized to a constant< Koutsideloop_blocksand never mutated insidecb_site_set.opaque_sets_state_zeroscan insearch_blk[..ni]to inspect the full pre-callback slice (not just the last 4 instructions) and follow verified watchdog clamps.old_dstwalking:is_callback_only_user_accumulator+cb_val_routes_raw_bvh_ptr: allows non-tmax/non-hit_*/non-flags/non-stateVGPR header PHIs proven untouched on every non-callback path (including non-callbacktri_merge_blockarms and inline inactiveold_dstlanes) to accumulatecand_t(viav_min_f32, unguardedv_cndmask_b32, or inner-guardedv_cndmask_b32) verbatim in the emitted callback without routing rawcur_tri/cur_instpointers.tri_merge_blockPHI validation into two passes so direct candidatehit_*_phibindings are populated before evaluating callback-only user accumulators.read_old_dst_inactive(bounded 16-hop walk past earlier same-block callback writes whose guardpgsatisfiespg => cur_gandcb_exec_within_entry) so inline same-guard scratch writes before commitv_cndmask_b32still verify opaque-lane preservation.(def_blk, def_idx, excl_g)inval_has_explicit_read(u.0 == db && u.1 > di && ug => eg, cleared across blocks/PHIs) so dead staging header PHIs overwritten and read solely under the same guardgbefore unconditional overwrite do not falsely poison Pattern B.emit_rq(cb_bound_vals) fromread_in_cbinclassify_live_outsand stopsvalue_touches_cb_sitesatpb == header(ignoring dead unguarded full overwrites), preventingcur_tri/cur_instheader PHIs from being misclassified as non-dominating accumulators.find_callback_accumulator_nextto require every non-callback arm ofmerge_blockPHIs (and non-callback-touchingcb_blocksarms) to preservehp, reject non-callback modifications insideloop_blocks, requirest.guards[site.0][site.1].is_some()forCallbackKind::Inlinedefs, and require a single consistent update value across arms.bvh32lifting & soundness fixes:is_dominating_search_guard+ an O(1) SSA EXEC-chain fallback (exec_chain_proves_neg_cmp, immune to BDDMAX_MEETbudget exhaustion on large multi-query shaders) to provebvh32cur_trileaf-fetch copies underv_cmpx_ne_u32 EXEC, k, xunconditionally executed on all lanes reachingsearch_blkvia a separatev_cmp_eq_u32 mask, k, xbranch.s_and_saveexec_b32/64non-opaque callback entry fed by!(1 == v_opaque)/(1 != v_opaque)wherev_opaqueis an unguardedv_and_or_b32(tri_dw12, 1, ...)dominatingsearch_blk, and includesv_and_or_b32(tri_dw12, 1, ...)intri_accept_blockdetection.hit_and_cb_blocks(including all blocks inloop_blocks \ {latch}dominated bytri_accept_block/tri_block) and excludeshit_and_cb_blocks(exceptheader) fromiter_counter_phisso side-effecting updates inside unrecognized triangle-hit branches are never zeroed as BVH scratch orIterOverflowZero.Soundness Unit Tests (
crates/victory-shader/src/emit/rayquery_tests.rs)Added 5 comprehensive positive + negative unit tests (22 subcases total, all validated with
dxil.dll):post_merge_iter_overflow_watchdog_lifts_and_rejects_unsound_clamps(2 positives + 6 negatives: wrong polarity, threshold< 1024, dynamic init, callback-mutated counter, guarded increment, non-zero fallback)callback_only_user_accumulator_cand_t_flows_lift_and_reject_unsound(3 positives + 3 negatives: opaque-mutated accumulator, rawcur_trirouting throughtri_merge_blockPHI,tmax_phiv_min_f32mutation)dead_staging_header_phi_same_guard_overwrite_and_inline_inactive_old_dst(2 positives + 2 negatives: post-loop explicit read outside guardg, wider pre-callback scratch clobber of opaque lanes)callback_prebound_cand_phi_and_non_dominating_accumulator_enforcement(positive pre-boundcur_triPHI + negative opaque-modifiedmerge_blockPHI)s_and_saveexec_inverted_opacity_callback_entry_lifts_and_rejects_unrelated(positive inverted opacity entry + negative unrelated compare)Corpus Lifting & DXIL Validation Results (64 cached BVH shaders)
main)perf/w11b-rayquery-phase3)bvh64queries liftedbvh32queries lifteddxil.dllvalidation failures56 VALID,0 INVALID)Fallback counts across the 4 target patterns on the 64-shader corpus:
bvh64: unrecognized candidate flow through tri_merge_block PHI: 12 -> 0 (100% eliminated)bvh64: callback accumulator PHI update does not dominate callback exit: 0 remaining (100% eliminated on pre-bound candidate PHIs while preserving dominance enforcement)bvh64: callback commit cndmask has mismatched attribute kind or invalid old value: 4 -> 2 (remaining 2 already lift 6/8 and 1/8 queries and fail closed on genuine old-value mismatches)bvh32: post-merge commit flow uses conditional or modified move: 13 -> 3 (all pure iteration-overflow watchdogs lifted 100%; remaining 3 are partial multi-query shaders already lifting 6/15–6/63 queries)Verification
cargo test -p victory-shader -- rayquery: 63 / 63 passedcargo clippy --workspace --all-targets -- -D warnings: 0 warningscargo xtask policy: 365 files okanalyze.rs403,838 B,rayquery_tests.rs308,824 B(well under655,360 B)Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T11:01:42Z.
Triage (
2fb54dcb, CIcheckPASS,MERGEABLE):+1,743/-132acrossrayquery/analyze.rs+rayquery_tests.rs, zero new toggles), however Gate 2 Adversarial Soundness Audit (#282comment7409489168) flaggedCHANGES REQUESTED — 5 [P0], 2 [P1].triage: needs workpending fixes + Gate 2 clean re-audit + Gate 3VICTORY_HW_RT=1verification.Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T11:54:46Z.
Gate 2 Soundness Audit Fixes (
81b07f8, synced withorigin/main)All 5
[P0]and 2[P1]Gate 2 findings from issue #282 comment7409489168are fixed and covered by positive + negative unit tests (all validated withdxil.dll):1-to-1 Fix Checklist
[P0]Inverted dynamic-opacitys_and_saveexec_b32/64pre-callback lane bit (collect_bool_atoms/eval_pre_callback_lane_bit)atom_forced_bycheck against callback entryEXEC(ce) andst.reach[search_blk]incollect_bool_atoms, bindingv_cmp_eq_u32(1, v_opaque)toPreboundLane::Const(false)instead oftrue.v_cmp_eq_u32/v_cmp_ne_u32againstv_opaqueandcur_tri/cur_instineval_pre_callback_lane_bit, and madeeval_pre_callback_lane_bitfail closed (Err) on unknown/unprovable pre-callbackAtom::Lanes.s_and_saveexec_inverted_opacity_callback_entry_lifts_and_rejects_unrelatedto assertPreboundLane::Const(false)on the opacity compare atom, evaluate the lowered commit mask underprebound_lanes(proving it is not constant-folded tofalse), and reject unprovable pre-callback lane bits.[P0]Opaque-lane mutations & post-merge discards of user accumulators (find_callback_accumulator_next&is_callback_only_user_accumulator)entry_exec: Bool(ce) onCallback, added sharedcollect_opaque_preserved_vals+compute_post_merge_reachable, and enforcedcb_exec_within_entry_mask+read_old_dst_inactive_valacrossCallbackKind::Inlineand Case 1bCallbackKind::Blocks(includingtri_merge_blockPHIs reached by!celanes and failing closed on unguarded writes reachable by!celanes).loop_blocks \ cb_blocksPHI infind_callback_accumulator_nextwhere apost_merge_reachablepredecessor drops the update back tohp.callback_accumulator_inline_case1b_opaque_mutation_and_post_merge_discard(7 positive + negative subcases covering Inline, Case 1bfind_callback_accumulator_next, Case 1bis_callback_only_user_accumulator, and post-merge discard).[P0]Synthetic sentinel leakage incb_val_routes_raw_bvh_ptr/cb_acc_routes_synthetic_sentinelv_mov_b32/v_cndmask_b32-only walk with unified path-sensitivecb_val_routes_syntheticwalking allFields::Valu,Fields::Sop, andFields::Dsexplicit data reads (and guardedold_dst), stopping only atFields::Flatloads, lane masks, and hardware-backed candidate/committed attributes, rejectingcur_tri,cur_inst,inv_d,cand_flags,committed_tri_old, andcommitted_inst_old(while pruning provably infeasible consecutive forwardif/elsecross-edges viast.bools.meet_seen).v_add_nc_u32(cur_tri, 4)(Blocks + Inline) andv_add_f32(acc, inv_d)throughtri_merge_blockPHIs.[P0]Cross-lane reads inval_has_explicit_read&v_writelane_b32inread_old_dst_inactive_valis_lane_local_read_inst(rejecting DPP,v_readlane_b32/v_readfirstlane_b32/v_writelane_b32/v_permlane*/v_movrel*/v_swaprel*, allFields::Ds, and implicit-derivativeFields::Imageops) before treating a guarded same-block read as dead on!eglanes, plus consecutive forward-edge infeasibility pruning for deadif/elsecross-edges.read_old_dst_inactive_valandcollect_opaque_preserved_valsonv_writelane_b32.v_readfirstlane_b32and inlinev_writelane_b32clobber.[P0]Non-invariant header PHIs read inside callback (classify_live_outs)is_invariant_header_phi(or!val_has_explicit_read) whenever a non-live-out header PHI hasread_in_cb == trueand is not a valid callback-only accumulator across all back-edges — failing closed withErr(...)instead of silently freezing at pre-loop init.non_invariant_header_phi_read_in_callback_fails_closed(positive invariant PHI + negative 2-PHI shift-register + negative outside-callback mutated counter).[P1]Iteration-overflow watchdog remaining-iteration margin & realcb_site_setinopaque_sets_state_zeroc0 >= thresholdtoc0 > threshold.saturating_sub(1024)inis_iter_overflow_state_cndmask.opaque_sets_state_zerosearch_blk[..ni]scan to run afterextract_callback_regionwith the real&cb_site_set.c0 = 65534, K = 65535and opaque-onlyv_state = 0with a callback-mutated watchdog counter.[P1]Wave64 mask matching inis_non_opaque_mask/nonop_idx&s_mov_b32-onlycollapse_scalar_mov_phis_and_saveexec_b64/s_xor_b64/s_mov_b64vs_b32strictly byp.wave64, required inline-1(Operand::Const(193)) for 64-bits_xor_b64, and verified matching(lo, hi)mask write/read pairs across Wave64 producers.collapse_scalar_mov_phitos_mov_b32.wave64_inverted_opacity_callback_entry_mask_matching(positive Wave64 inverted opacity + negative high-dword clobber + negative 32-bit literal0xFFFFFFFFins_xor_b64).Updated 64 Cached BVH Shader Corpus & DXIL Validation Results
main)81b07f8)bvh64queries liftedbvh32queries lifteddxil.dllvalidationVerification
cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-shader -- rayquery: 66 / 66 passedcargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings: 0 warningscargo +1.98.1-x86_64-pc-windows-gnu xtask policy: 368 files okanalyze.rs421,799 B,rayquery_tests.rs329,874 B,emit_rq.rs58,190 B,rayquery.rs29,866 B(all well under655,360 B)Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-04T12:01:30Z.
Updated triage (
c6523513, rebased onto8503d1de, CIIN_PROGRESS,MERGEABLE):#282comment7410830192):VERIFIED CLEAN (0 P0, 0 P1)— all 7 prior findings (5 P0 + 2 P1) resolved.triage: needs work->triage: needs gpu test— awaiting CIcheckPASS + Gate 3VICTORY_HW_RT=1GPU verification.