Skip to content

Shaders: texture reads at a computed table entry keep their read mark (#2722) - #2724

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/computed-table-read-marks
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/computed-table-read-marks

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

Since 2d6c0df, Lower::handle notes a texture read's read mark only when the descriptor comes from the resource heap itself (is_heap_direct). A read through a table sets none, on the grounds that "the host makes table slots for the draw".

The host only makes the entries the used-resource list names: draw::State::tables makes one table_entry per entry, and fresh tables only up to the last listed entry. A table read at a computed entry reaches a slot that may lie past those. Examples are a descriptor array indexed by data, s_load_dwordx8 with an SGPR soffset, or a per-lane or waterfall descriptor load.

If that slot holds a placed texture the host left null (52d14b1), nothing makes it, and the view reads null. Before 2d6c0df every texture read set its mark, so the slot was made after the first submission that read it.

What the fix does

A texture read keeps its mark unless its descriptor is a table entry at a fixed offset on every path. That is the case 2d6c0df meant to skip, and the new Lower::fixed_table_entry tests it with the existing entry_address. Heap-direct reads mark as before, and fixed-entry table reads still emit no bitmap access. The "Read marks" module note in emit/mod.rs is updated to match.

Tests

emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index gains a table read at a computed entry: v_readfirstlane_b32 s6, v0, then s_lshl_b32 s6, s6, 5 as the load's soffset.

  • It asserts that the read is marked and is not heap-direct.
  • The fixed-entry table read still asserts that it marks nothing.

Results, run on Linux with cargo xwin under Wine and vkd3d-proton:

  • Without the lower.rs change, the test fails at memory_tests.rs:703 ("a read at a computed table entry is marked"). With it, the test passes.
  • The emit::memory_tests module passes 4/4.
  • The whole victory-shader lib suite was run one test per process, on this head and with only lower.rs reverted. The results are identical except for this test: 254 ok, 14 failed, 2 crashed and 3 ignored with the fix.
  • The failures and crashes are the same tests on both builds. They are host quirks of lavapipe and Wine: the semantics and hardware comparisons, 64-bit image atomics, stub_pipeline_is_created, and a few synthetic DPP or gather tests.

Not tested

  • On Windows hardware or WARP. The test's GPU part skips without an SM 6.6 WARP device, and the new assertions are on the lowering, which needs no device.
  • In game.
  • This conflicts with Shaders: guard heap-direct texture read marks with EXEC #2668, which adds an EXEC guard to the same read marks and edits the same test. Whichever lands second needs a small rebase.

Fixes #2722

No game data. Found and written with AI assistance (Claude Code), reviewed and run locally.

🤖 Generated with Claude Code

What was wrong: since 2d6c0df only texture views the program takes from
the resource heap itself set a read mark; reads through a table set none,
because "the host makes table slots for the draw". The host makes only the
entries the used-resource list names (`draw::State::tables`: one `table_entry`
per entry, the whole range only for tables made afresh). A table read at
a computed offset (a descriptor array indexed by data: `s_load_dwordx8`
with an SGPR soffset, a per-lane or waterfall load) may reach any slot
past those, and a slot there holding a placed texture left null was made
by its read mark before 2d6c0df; now nothing makes it and the view reads
null for good.

What changed: a texture read sets its mark unless its descriptor is a
table entry at a fixed offset on every path (`Lower::fixed_table_entry`),
the case 2d6c0df meant to skip. Heap-direct reads mark as before.

Test: `heap_direct_texture_reads_mark_their_heap_index` gains a table
read at a computed entry (soffset from `v_readfirstlane`, shifted by 5);
it was not marked before, it is now. The fixed-entry table read still
marks nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz

Copy link
Copy Markdown
Contributor Author

Windows run of this head (569aa6a) on windows-latest, WARP, cargo test --workspace --locked --no-fail-fast -- --test-threads=1: https://github.com/BastienRodz/VIctory/actions/runs/45679288906

  • victory-shader lib: 270 passed, 0 failed, 3 ignored, including emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index.
  • Every other crate in the workspace: no failures.

@kotekompotek

Copy link
Copy Markdown

Correct carve-out: the mark is now skipped only for the case 2d6c0df actually meant - a table entry at a fixed offset on every path, which is exactly what the used-resource list enumerates and the host makes. fixed_table_entry via leaves()+entry_address()+root==Table covers descriptor arrays and per-lane loads (whose leaves aren't Loaded-with-fixed-address). The test's SGPR-soffset variant reproduces #2722's shape precisely.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification and code review of 569aa6a (on 13f91ca):

Verification (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • WARP (VICTORY_WARP=1, dxil.dll active): cargo test --locked -p victory-shader --lib emit::memory_tests -> 4 passed, 0 failed (including updated heap_direct_texture_reads_mark_their_heap_index).
  • RTX 5090: root_views_read_their_copy_and_zeros_past_it, title_memory_is_read_and_written_at_computed_addresses, and writes_through_views_mark_their_pages all pass (heap_direct_texture_reads_mark_their_heap_index hits the pre-existing 13f91ca NVIDIA 0xc0000005 crash from Shader tests: heap_direct_texture_reads_mark_their_heap_index kills the test process on a real GPU (RTX 5070, main 67e8ae1) #2571).
  • WARP victory-gpu: 198 passed, 0 failed, 1 ignored.

Review & Merge-Ordering Notes

  • Replacing is_heap_direct(src) with !fixed_table_entry(src) cleanly preserves VIEW_READS marks for computed table entries (dynamic soffset, waterfall, or mixed Phi/Select leaves) while still skipping fixed UsedResource table slots; heap_index / fetched_index handle RootType::Table offsets accurately.
  • Complementary with Shaders: guard heap-direct texture read marks with EXEC #2668 (12fdbc9e): git merge-tree merges crates/victory-shader/src/emit/lower.rs cleanly with zero conflicts so computed table-entry read marks automatically inherit Shaders: guard heap-direct texture read marks with EXEC #2668's per-lane EXEC guard (only memory_tests.rs has a small conflict around lower_with in heap_direct_texture_reads_mark_their_heap_index).

@pablogonz12

Copy link
Copy Markdown
Contributor

AMD/RADV offline check of the head commit (no game run).

  • Hardware / stack: RX 9070 XT, Mesa 26.3.1 RADV, GE-Proton11-14; base = origin/main 13f91ca.
  • Method: the 751-program world-shader dump, translated by each tree's own victory-shader --example retranslate, then dxil-spirv (master), spirv-val --target-env vulkan1.3, and a real vkCreateCompute/GraphicsPipelines on RADV (vkpipe, one process per program, so a driver crash or hang is recorded per program rather than stopping the batch).
  • Offline only: pipelines are created, never bound or drawn, so wrong pixels and ISA-level miscompiles are out of reach here.
    Result, base 13f91ca vs head 569aa6a: both translate 749 / 751 (the same 2 refused in both: a lane mask read as data is not supported). 0 of the 751 programs' DXIL bytes change, and no pipeline result or time differs.

So the dump set does not exercise the path this PR changes (none of these 751 world shaders reads a texture through a computed table entry with a read mark to keep), which means the offline check can neither confirm nor refute the fix — the unit test in the branch is the only evidence, and victory-shader's test target does not build on Linux (its tests use the Windows validator module), so I could not run it here. No objection from this side; a Windows/WARP CI run plus that test is what should decide.

Not tested in a game run; not tested on NVIDIA.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent WARP/CPU verification for head 569aa6a against origin/main 13f91ca. State check: open, non-draft, clean merge-tree; no oni-swr comment found.

Environment: Windows x64, Rust 1.98.1 (48a229cea 2026-09-01), Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11); WARP/D3D12 WARP env vars set; CARGO_TARGET_DIR=D:\victory-warp-2720-target.

Commands/results:

  • Baseline: cargo test --locked -p victory-shader emit::memory_tests:: — 4 passed; cargo test --locked -p victory-shader --lib — 267 passed, 3 failed, 3 ignored; cargo clippy --locked -p victory-shader --all-targets -- -D warnings — pass.
  • PR: same targeted command — 4 passed; full --lib — 267 passed, 3 failed, 3 ignored; strict Clippy — pass.
  • The same three baseline WARP failures reproduce on this head: a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out.
  • Negative control: restored the old heap-direct-only marking condition; heap_direct_texture_reads_mark_their_heap_index failed, including the computed table-entry assertion.

Review: no additional correctness issue found in the changed fixed-table-entry carve-out.

Not tested: physical GPU, retail title/game behavior, release build. AI disclosure: Codex (gpt-6-luna).

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks, both of you.

@pablogonz12, that measurement cuts both ways, and both halves are worth having:

  • None of those 751 world programs reads a texture through a computed table entry, so this PR doesn't change what any of them sees today.
  • It also costs them nothing. 2d6c0df was about not loading the bitmap word after every table read, and that saving is fully kept: no extra bitmap access in any of the 751.

What the PR guards is the case 2d6c0df's message rules out ("a view read through a table cannot be a slot left null"), which a descriptor array read at a computed table entry still hits. It goes back to the marking main did before 2d6c0df for that case only.

@passerbyyhx

Copy link
Copy Markdown

I ran the computed-entry shader itself on a GeForce RTX 4090 Laptop GPU (621.14) and on Microsoft WARP. Both adapters gave identical readbacks. With the same computed PSO and the table starting at slot 2, entry 0 read red and set only VIEW_READS + 2. Entry 1 read blue and set only VIEW_READS + 3. Keeping entry 1 and moving the table base to slot 1 gave red and VIEW_READS + 2. The fixed-entry shader read the correct color with no read marks. A zero-group dispatch left both outputs clear.

With the identical fixture and only lower.rs restored from 13f91ca, all colors stayed correct on both adapters but every computed-entry read mark was missing. The test failed on the first expected bit. This verifies executed shader marking. Runtime materialization and game workloads were outside the test.

Reproducer and command against this PR’s branch. Test code and hardware verification assisted by Codex.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thank you, this is the evidence the PR was missing: the translated shader actually running on hardware and WARP. Entry 0 sets VIEW_READS + 2, entry 1 sets + 3, moving the base moves the bit, and the fixed entry sets none. With only lower.rs reverted, the colors stay right and the computed-entry marks are gone.

I'll keep this PR at its current size (+48/−23, with the lowering-level test). Your readback test is +212 lines in a new module, so it reviews better on its own or as a follow-up. It is linked here for the maintainer either way. If they'd rather have it in this PR, I'll merge your fork PR with your authorship kept.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In crates/victory-shader/src/emit/lower.rs Lower::handle, a texture read now skips its read mark only when every leaf of the descriptor is a table entry at a fixed offset (fixed_table_entry, using the existing entry_address). Before, it was marked only when heap-direct (is_heap_direct). I checked the premise against main: draw::State::tables / table_entry in crates/victory-gpu/src/draw.rs make only the entries named in the used-resource list, so a descriptor array read at a computed table entry can reach a slot left null that nothing would ever make. Fixed-entry table reads still emit no bitmap access. The extended heap_direct_texture_reads_mark_their_heap_index test covers the computed case, and a reviewer's hardware/WARP readback confirmed the marks land on the right bits. CI (check) passes. Note that this and #2668 edit the same test, so whichever lands second needs a small rebase.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested merged onto origin/main (63bcca4) on Windows 11 x64 (dxil.dll validator active):

  • VICTORY_WARP=1 cargo test -p victory-shader --lib emit::memory_tests: 5 passed, 0 failed (including heap_direct_texture_reads_mark_their_heap_index with the computed table entry case; WARP used due to pre-existing #2571 on 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).

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified locally at 569aa6ad:

  • fixed_table_entry (crates/victory-shader/src/emit/lower.rs:5588) accurately distinguishes fixed root-table entries (entry_address(*load) with RootType::Table) from computed-offset table loads, waterfalls, Source::Built, and heap/dynamic paths, ensuring computed-table texture reads emit view_marks read bits while fixed-table reads stay unmarked.
  • cargo xtask policy (191 files ok), cargo clippy --all-targets --all-features (0 warnings), and rustfmt --check --edition 2024 (0 new diffs over HEAD) all pass.
  • emit::memory_tests passes 5/5 on WARP (VICTORY_WARP=1) and 4/5 on RTX 5090 (excluding the pre-existing baseline access violation in heap_direct_texture_reads_mark_their_heap_index); an isolated runtime probe of the computed-table image_load case also passes dxil.dll validation, RTX 5090, and WARP with the expected VIEW_READS + 2 bit set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: a texture read at a computed table entry sets no read mark, so a placed texture there stays null (since 2d6c0df)

8 participants