Shaders: guard heap-direct texture read marks with EXEC #2668
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2668
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-25 17:47 UTC · original
fuzeofficlal:fix/shader-guard-view-read-marks→main· +98 −66 · 2 files · 1 commits · openSummary
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.@kotekompotek on GitHub · 2026-11-25 17:55 UTC · original
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.@cloph-dsp on GitHub · 2026-11-25 17:58 UTC · original
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).
@Mericas77 on GitHub · 2026-11-25 18:28 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 22:23 UTC · original
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
@KainanP on GitHub · 2026-11-25 22:53 UTC · original
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: #2571 (AI-assisted)
@rezioliver-collab on GitHub · 2026-11-26 00:17 UTC · original
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.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.