Shaders: guard heap-direct texture read marks with EXEC #2666
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2668"
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 Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T17:47:17Z.
Summary
In
crates/victory-shader/src/emit/lower.rs,Lower::imagecalledLower::mark_view_read(index)afterimage_opwithout passing the instruction's per-laneEXECguard (self.guard(b, i)?), unlikeLower::image_op(which guards VGPR writes and UAV stores/atomics) andLower::mark_view_write(which gates its bitmap load and atomic OR withbegin_guarded).As a result, predicated-off lanes (
EXEC == 0, e.g. afterv_cmpx_*without a branch) or inactive lanes carrying stale/fallback descriptor indices (Source::LanePhi/Source::Fetched) still readVIEW_READSand set read-mark bits for texture slots that no active lane actually read, causing unnecessary demand materialization of unread placed textures.Changes
crates/victory-shader/src/emit/lower.rs:Option<V>per-laneguardfromLower::image_opand pass it fromLower::imageintoLower::mark_view_read(index, guard).raw_dwordload, clear check, and inneratomicBinOp.i32inbegin_guarded(guard)/end_guarded(outer, &[])(leaving unguardedguard == Nonepaths completely unchanged).crates/victory-shader/src/emit/memory_tests.rs:heap_direct_texture_reads_skip_marks_when_exec_is_zero(v_cmpx_ne_u32 exec_lo, v0, v0, assertingmarked == []) andheap_direct_texture_reads_mark_with_partial_exec(v_cmpx_eq_u32 exec_lo, 0, v0across 2 threads, asserting only[VIEW_READS + 1]).Verification
heap_direct_texture_reads_skip_marks_when_exec_is_zerofails on both RTX 5090 and WARP, recording[VIEW_READS + 1]instead of[].emit::memory_tests(6/6 on WARP, all 3 heap-direct texture read tests on both RTX 5090 and WARP withdxil.dllvalidation) pass.cargo clippy -p victory-shader --all-targets -- -D warnings— pass (0 warnings).cargo xtask policy— pass (184 files ok).Note:
memory_tests.rsusesvec![0u32; shader.user_data_dwords().max(1) as usize]for the test helper's user-data slice so the test runs cleanly on NVIDIA independently of the host-side fix in #2587 / #2596 (#2571); it merges cleanly with either.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:55:55Z.
Reviewed: marking view reads under the EXEC guard is the correct fix — a texture read on an inactive lane was previously marking its view as read, which feeds copy decisions. The
lowered?propagation preserves the old error behavior (marks only on success) and the outer guard wraps the atomic marking block. CI green.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T17:58:37Z.
Independent Windows verification of PR #2668 (head
12fdbc9), Rust/Cargo 1.100.0 MSVC, synthetic tests only, no game data, no source edits.cargo test --locked -p victory-shader --lib heap_direct_texture_reads -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_indexon the PR head: 2 passed, 0 failed, 273 filtered. Both new tests pass:emit::memory_tests::heap_direct_texture_reads_skip_marks_when_exec_is_zeroandemit::memory_tests::heap_direct_texture_reads_mark_with_partial_exec.13f91cawith the same filter: 0 tests (the new tests are absent).cargo test --locked -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index-> 268 passed, 3 failed, 3 ignored, 1 filtered. The three failures are the known hardware-specific ones (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware); they reproduce with identical assertions on unmodified base13f91ca, so they are not regressions from this PR.heap_direct_texture_reads_mark_their_heap_indexterminates withSTATUS_ACCESS_VIOLATIONon both this head and unmodified base, so it was excluded.No regression attributable to the PR found. AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by Mericas77 on 2026-11-25T18:28:16Z.
Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head
12fdbc9againstmain13f91ca.cargo test -p victory-shader --lib memory_tests -- --test-threads=1, without any skip: 6/6 pass, hardware and WARP, including the two new tests andheap_direct_texture_reads_mark_their_heap_index. Onmainthat last test alone still ends the process with0xc0000005here (#2571).577839a) cherry-picked on top: 6/6.cargo test -p victory-shader --lib --locked(with--skip heap_direct_texture_reads_mark_their_heap_index, which crashes the process onmainhere, #2571):main266 passed / 3 failed / 3 ignored, this PR 268 / 3 / 3. The 3 failures are the known NVIDIA ones onmain(a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware) and are the same.One thing worth saying in the description: the test no longer crashes on NVIDIA because of the
ud = vec![0u32; shader.user_data_dwords().max(1) as usize]change inmemory_tests.rs, which works around #2571 in this one test. The host-side fixes (#2587, #2596) do the same for every caller; with either of them merged, the.max(1)is no longer needed. The two don't conflict (I tested the combination).No game data; the title was not run.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:23:39Z.
Automated triage for the maintainers.
Merge candidate.
Lower::image(crates/victory-shader/src/emit/lower.rs) now passes the instruction's EXEC guard (returned byimage_op) tomark_view_read, which wraps its bitmap load and atomic OR inbegin_guarded/end_guarded, asmark_view_writealready does. Lanes that are off no longer mark texture slots as read, so placed textures nobody read are not made on demand. Active lanes still mark, so nothing that is read can go unmarked, and marks are still only emitted when lowering succeeds. The guarded blocks nest and close in reverse order, and the BVH path returns no guard because it uses no views. The two new tests check zero EXEC and partial EXEC; the existing test moves into a shared helper. The helper's.max(1)on the user-data size sidesteps #2571 for this test only. It merges cleanly; CIcheck: passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-25T22:53:54Z.
Measured in the #2571 comparison: the crash is avoided only in the rewritten test (#2587's host-level test still crashes on an RTX 4060), and the EXEC-guard change is independent and adds no failures: https://github.com/Marvisak/VIctory/issues/2571#issuecomment-7176908308 (AI-assisted)
Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-26T00:17:21Z.
With #2668 and #2724 combined, disabling
EXECleftVIEW_READSempty on both arms of a mixed descriptor phi. WithEXECenabled, only the slot actually read was marked, including when the fixed arm was taken.For a table starting at heap slot 30 and a runtime index of 5, the fixed arm selects slot 31 and the computed arm selects slot 37.
+nmeans that only bitVIEW_READS + nwas set.EXEC569aa6ad)12fdbc9e)+31+37+31+31+37+37I tested both PR heads separately and merged them locally. The compiler changes merged cleanly. Only the shared helper in
emit/memory_tests.rsneeded a conflict resolution. On an Apple M1 (macOS 14.7, Rust 1.98.1), I reused the synthetic Wave32 shader from #2722 and insertedv_cmpx_ne_u32immediately beforeimage_load. A runtime input toggledEXECindependently of the branch and index, so both mask states ran the same emitted code.I replayed that code on the CPU with a distinct texel per slot and checked the entire bitmap. Across two table bases and three runtime indices, all 24 masked invocations of the combined mixed-phi shader made zero bitmap loads and zero atomic ORs. With
EXECenabled, the expected texel reached shared memory and a second read of the same slot issued no further atomic OR. The CPU replay still invokedtextureLoadwithEXECoff, but its result never reached shared memory. These measurements cover shader-side marking. D3D12 device traffic was outside the test.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:27:35Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (dxil.dllvalidator active):VICTORY_WARP=1 cargo test -p victory-shader --lib emit::memory_tests: 7 passed, 0 failed (including newheap_direct_texture_reads_skip_marks_when_exec_is_zeroandheap_direct_texture_reads_mark_with_partial_exec; WARP used due to pre-existing#2571on NVIDIA hardware).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.