Skip to content

Shader tests: heap buffer views are raw, as the host makes them - #2357

Closed
LICObr wants to merge 1 commit into
Marvisak:mainfrom
LICObr:shader-tests/raw-heap-views
Closed

LICObr wants to merge 1 commit into
Marvisak:mainfrom
LICObr:shader-tests/raw-heap-views

Conversation

@LICObr

@LICObr LICObr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Addresses parts 2 and 3 of #1835, the test-fixture ones: on NVIDIA, stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride and synthetic_tests::gathers_at_a_level_match_the_hardware. Part 1 (HEAP_VIEWS past NVIDIA's 1,000,000 cap) is a host design question with several open PRs and is not touched here.

Problem

A heap buffer read by element has no used-resource entry, so the translator addresses it as the hardware does (lower.rs, "A heap-indexed buffer read by element"). It computes element × the view's stride from the VIEW_STRIDES table, plus the offset, and issues a raw byte-address load (raw_view, kind 11). The offen reads in the synthetic test take the same raw path.

The host's own buffer views are raw: R32_TYPELESS, StructureByteStride = 0, BUFFER_SRV_FLAG_RAW (descriptor/host.rs). The two tests bound a structured view there instead (Stride::Structured(12) and Stride::Structured(16)).

A raw load through a structured view is outside what DXIL defines:

So on NVIDIA the tests failed on the fixture, not on the translation.

Scope: this covers the raw fixtures only. A structured SRV the title creates keeps its stride when the host makes its view (buffer_srv), and a raw load reaching such a view at runtime is the case still tracked in #1835 (comment).

Change

  • Both views are now Stride::Raw. The stride still comes from the table only (data: vec![4, 12]), so the stride test checks what it is named for.
  • No translator or host change.

Verification

The shader reads a heap buffer by element as the hardware does: element
times the view's stride (the host's table) plus the offset, as a raw
byte-address load. `a_heap_buffer_read_by_element_takes_the_views_stride`
and `gathers_at_a_level_match_the_hardware` bound a structured view
there instead (stride 12 and 16). A raw load through a structured view
is outside what DXIL defines: WARP and AMD read the byte address, NVIDIA
applies the view's stride on top and reads the wrong elements (Marvisak#1835).

The host makes every heap buffer view raw (`descriptor/host.rs`), so the
tests now bind raw views, and check what runs in the game.
@DrDarkDK

Copy link
Copy Markdown

I ran the two affected synthetic tests on native Windows with an RTX 4070 Ti (621.01). Both failed on 940d32f and passed on dd25e37.

  • a_heap_buffer_read_by_element_takes_the_views_stride: the parent returned [101, 104, 107, ...]; the PR passed the expected 200..231 readback.
  • gathers_at_a_level_match_the_hardware: the parent failed at lane 0 with [0, 1, 0, 0] versus [0, 0, 0, 0]. The raw fixture passed the full comparison, including lane 0.

One scope clarification for the description: buffer_srv preserves an explicit structured SRV’s stride when it creates the host view. This verifies the raw fixtures. The runtime structured-view case is still tracked in #1835.

AI-assisted with Codex.

@DenRakEiw DenRakEiw 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.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Using Stride::Raw for heap buffer views fixes a_heap_buffer_read_by_element_takes_the_views_stride on RTX 5090 (note: overlaps in scope with #2322 / #1887).
  • cargo test -p victory-shader a_heap_buffer_read_by_element_takes_the_views_stride: 1/1 passed on RTX 5090, 1/1 passed on WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

@LICObr

LICObr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for running it on real NVIDIA hardware, that's exactly the confirmation this needed. Good catch on the scope too: you're right that buffer_srv keeps a title-made structured SRV's stride, so "the host makes every heap buffer view raw" was too broad. I've updated the description to say this covers the raw fixtures only, with the runtime structured-view case still tracked in #1835, and added your results (including lane 0) under Verification.

@catminou4 catminou4 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.

Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — test-only: heap buffer views raw, as the host makes them.

@Calvix2k

Copy link
Copy Markdown
Contributor

Part 2 of #1835 is already in flight: #2322 (Shader tests: bind a structured view as the raw view the host makes) makes exactly that change — Stride::Structured yields a raw byte-address SRV, as victory-gpu binds title buffers, plus a test that pins StructureByteStride = 0 so a structured descriptor cannot come back.

The evidence behind it is in #2317: on the 5070 Ti the failure read 101 + 3·lane where the buffer's elements are 12 bytes — element 3·lane + 1, i.e. (12·lane + 4) × 12/4, the byte index the DXIL passes scaled by the descriptor's stride a second time. AMD and WARP take the byte index as written, which is why it passes everywhere else.

So if #2322 lands first, the stride_tests half of this PR disappears in the rebase and only your part 3 remains:

  • synthetic_tests::gathers_at_a_level_match_the_hardware — the RDNA2 rounding the test asserts (the comment in that file says the hardware rounds the exact product to 1/256 of a texel, half up, which WARP does not). That one is worth doing properly, and it is not a fixture question in the same sense: DXIL has no form for image_gather4_l at a non-zero level, so the expectation has to come from somewhere. Comparing against the same gather at level 0 with pre-multiplied coordinates, or skipping the non-zero-level case with a comment naming the vendor difference, are both defensible; the second is smaller and honest.

Not asking you to drop anything — just so neither of us is surprised when one of the two stride patches conflicts with the other. If yours is preferred for some reason, the test I add (a_structured_test_view_is_bound_as_the_host_binds_it) is the only thing worth carrying over from mine.

@qtLkz

qtLkz commented Nov 25, 2026

Copy link
Copy Markdown

Tested on an RTX 4070 Ti (NVIDIA driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned), on top of main 940d32f, cargo test -p victory-shader --lib --locked --no-fail-fast:

  • synthetic_tests::gathers_at_a_level_match_the_hardware: now passes
  • stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride: now passes
  • stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: still fails on this card, hardware: dispatch failed: invalid parameter at stride_tests.rs:347

Result: 246 passed, 1 failed, 3 ignored (on plain 940d32f: 244 passed, 3 failed).

For comparison on the same machine, #2322 (which fixes the shared test harness instead of the individual tests) makes all three pass: 249 passed, 0 failed, 3 ignored, see #2317 (comment). #2323 also targets the gather test only. These three PRs cover the same NVIDIA false failures, so only one of them should land; on NVIDIA, #2322 is the only one that clears all three.

AI-assisted (Claude).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (test fixture). Two synthetic tests bound a structured SRV for a buffer that the lowered code reads by byte address, using the stride from VIEW_STRIDES (lower.rs, "A heap-indexed buffer read by element"). The host makes such views raw (R32_TYPELESS, StructureByteStride: 0, BUFFER_SRV_FLAG_RAW in descriptor/host.rs), so switching both fixtures to Stride::Raw matches the host, and the stride still comes from the table only, so the stride test still tests what it is named for. No translator or host code changes. A contributor confirmed both tests fail before and pass after on an RTX 4070 Ti. Overlap: #2322 does this in the harness instead (and is needs-work because it also changes the PC reference path); #2323 is the gather half alone. One NVIDIA run reports #2322 also clears a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, which still fails with this PR (the heap-cap issue, #1744). CI: passing.


Generated by Claude Code

@Vedoxdev123

Copy link
Copy Markdown

Tested on Windows with AMD Ryzen 5 5600X + NVIDIA GeForce RTX 4060:

cargo test -p victory-shader -> 246 passed; 1 failed; 3 ignored (down from 3 failures on main).

  • emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride now passes
  • emit::synthetic_tests::gathers_at_a_level_match_the_hardware now passes
  • Only 1 failure remains: emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (hardware: dispatch failed: The parameter is incorrect.)

@fabianocoder

Copy link
Copy Markdown

Tested on NVIDIA GeForce RTX 3060 12 GB (driver 610.88, Windows 11).

cargo test -p victory-shader --lib --locked -- --test-threads=1

  • main (940d32f): 244 passed, 3 failed, 3 ignored
  • this PR (dd25e37): 246 passed, 1 failed, 3 ignored

Both a_heap_buffer_read_by_element_takes_the_views_stride and gathers_at_a_level_match_the_hardware now pass on hardware.
The remaining failure is a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (E_INVALIDARG, the HEAP_VIEWS cap from #1835 part 1), which this PR doesn't target

@fyernald fyernald 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.

The fix is right, and it does what it says on Windows 10 too: Windows 10 Pro 22H2 (19045), RTX 3080 (617.42), main + #486, cargo test -p victory-shader --lib --locked -- --test-threads=1:

victory-shader
base 244 passed / 3 failed
this PR (dd25e37) 246 / 1 (only a_heap_buffer_read_where_no_buffer_view_is_reads_zeros left: the heap cap)
this PR + #2461 247 / 0

One change before merging: the new comment in stride_tests.rs still says

A raw view, as the host makes every heap buffer view

You agreed in this thread that this is too broad. buffer_srv (crates/victory-gpu/src/descriptor/host.rs) passes the title's own description to CreateShaderResourceView, so a title's structured view stays structured. The PR description was updated, but this comment will outlive it. It also tells the next person looking at FIND-11 (the runtime's structured views on NVIDIA) that the runtime case can't happen. Something like this would match what the code does:

// A raw view, as this fixture's shader reads it (by byte address, the
// stride from the table alone). The runtime keeps a title's structured
// view as it is (`buffer_srv`): that case is #1835 / FIND-11.

The synthetic_tests.rs comment ("a raw view, as the host makes") has the same problem, though less strongly worded.

@alonso49noob

Copy link
Copy Markdown

First Blackwell run, and on the current head of main (13f91ca, 83 commits after the 940d32f used above): RTX 5060 8 GB, driver 621.01, Windows 11, Rust 1.98.1.

tree the two target tests cargo test -p victory-shader --lib
main 13f91ca both fail, same signatures as #1835: [101, 104, 107, …, 131, 0, …] and lane 0 [0, 1, 0, 0] aborts at the #2571 test
main + this PR (dd25e37) + #2587 (df8ee8e), local merge both pass, 3 of 3 270 passed, 1 failed, 3 ignored

This PR merges cleanly onto 13f91ca. #2587 is included only so the suite gets past the #2571 crash. The one failure left is a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (stride_tests.rs:352), the HEAP_VIEWS cap from #1835 part 1, which this PR does not target.

Written with AI help (Claude Code); the numbers are from runs on my machine.

@yumaste

yumaste commented Nov 25, 2026

Copy link
Copy Markdown

Verified on Windows 11 with an RTX 5080 Laptop GPU (driver 621.01).

Both targeted shader tests failed on 940d32f and passed with #2357 applied:

  • a_heap_buffer_read_by_element_takes_the_views_stride
  • gathers_at_a_level_match_the_hardware

I used the same local adapter-selection change in both runs and confirmed in the D3D12 logs that the NVIDIA GPU was used. Both tests also passed on WARP with the fix applied.

Test automation and write-up assisted by Codex.

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because the old fixtures are the faithful ones. The heap-indexed read gets its 12-byte stride from the view-stride table, which only a structured view gives, and the gather test's input is a table SRV with a used-resource stride; the runtime keeps such a view structured. Switching the fixtures to raw would make the tests describe a runtime main does not have, and hide the NVIDIA defect they currently show (#1835). The fix belongs in the runtime: raw host views for buffers the translator reads raw, or structured handles in the translation.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

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.