Repository navigation
GPU, Shaders: view structured buffers raw on host for NVIDIA heap reads (FIND-11) - #2885
jujumoneylol wants to merge 3 commits into
Conversation
|
Verified Before / After on RTX 5090 (FIND-11 confirmed fixed!)
Suite & Audit Notes
Great fix for NVIDIA — looks ready to merge. |
kotekompotek
left a comment
There was a problem hiding this comment.
Correct raw-view rules: R32_TYPELESS + FLAG_RAW is the only legal representation, gated on byte-length divisibility and u32 element count, with the 16-byte FirstElement alignment pushed down into view_align so for_view reserves a conforming copy. Complements #2873's format legalization. LGTM.
|
RTX 5060 8 GB (Blackwell), driver 621.01, Windows 11, Rust 1.98.1. I compared
The gather test is the other fixture named when #2357 was closed, and the reports above don't cover it. It passes here, and this PR doesn't change Unrelated note: Written with AI help (Claude Code); the numbers are from runs on my machine. |
fyernald
left a comment
There was a problem hiding this comment.
Ampere data point: RTX 3080 (617.42), Windows 10 19045, main 63bcca4 + #486 (Agility runtime for the shader tests) + #2596 (#2571), --test-threads=1.
victory-shader --lib |
victory-gpu --lib |
|
|---|---|---|
| base | 298 passed, 4 failed | 226 passed, 5 failed |
| + #2885 | 302 passed, 2 failed | 227 passed, 5 failed |
| + #2885 + #2461 | 303 passed, 1 failed | 230 passed, 3 failed |
- With this PR:
a_heap_buffer_read_by_element_takes_the_views_strideandgathers_at_a_level_match_the_hardwarepass, along with the new stride tests andstructured_buffer_views_stay_raw_on_host_and_keep_stride_table. Nothing new fails. - With #2461 as well: the two PRs merge cleanly onto
mainand with each other, and #2461 clears the heap-cap failures.- Shader suite: what's left is
pops_wait_loop_exits_immediately_for_inactive_lanes, which needs an SM 6.6 WARP that Windows 10 doesn't have. - GPU suite: the three left are the Windows 10 in-box-runtime failures that an Agility opt-in for the GPU test binary removes (see #2878).
- Shader suite: what's left is
So on this card the two together leave no NVIDIA-specific failure.
One scope note: unlike the raw views in #2878, which only apply on NVIDIA, this views structured buffers raw on every host, and getDimensions divides by the stride everywhere. The runs so far are NVIDIA and WARP, so a run on AMD hardware would close that.
@alonso49noob: the intermittent views_bound_while_another_slot_gets_its_texture_do_not_wait on main is a race between tests over the shared WHILE_PREPARING hook from 42ea09f. It's unrelated to this PR, and #2585 fixes it.
|
@jujumoneylol I found a WARP regression when a shader writes through one structured view and another shader reads the same records through a view with a different starting offset. The NVIDIA fix for reading the untouched fields also showed up in this comparison.
On this PR, both adapters returned all 1,600 untouched fields and all 160 newly written values read through the writer's own origin. All 544 stale words were reads of a GPU-written field through a different origin. For example, a writer at byte 12 and a reader at byte 24 share 31 records. Reader lane 0 should see the The fixture places 32-element views at byte offsets 0, 12, 24, 36 and 48 in a 432-byte write-watched title GPU buffer. Every access is inside its declared view. Each writer and reader runs in a separate fence-waited submission and schedules the same heap refresh that For the alignment fallback, the acceptance case I would keep is that the later SRV sees all 31 overlapping writes across differently aligned origins. The test-only commit directly on this PR can be run in a separate checkout with: git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2885-fenced-structured-readback
git switch --detach FETCH_HEAD
foreach ($adapter in '0', '1') {
$env:VICTORY_D3D12_WARP = $adapter
cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1
}Synthetic D3D12 readbacks on Windows. The game and AMD hardware remain untested here. AI-assisted with Codex. |
fyernald
left a comment
There was a problem hiding this comment.
Changing my earlier approval. @steven-seagull27's fixture (8c474d5) reproduces exactly on the RTX 3080 (617.42) / Windows 10. Hardware adapter, with an Agility opt-in for the GPU test binary (Windows 10's WARP has no SM 6.6, so no WARP row here):
| wrong words / 2,400 | RTX 3080 |
|---|---|
main 63bcca4 + fixture |
2,375 |
#2885 41773eb + fixture |
544 |
All 18 failing reads on this PR are the GPU-written field read through a different origin, as they describe. The pattern also shows the cause. The five origins are bytes 0, 12, 24, 36 and 48. The two that are 16-byte aligned, 0 and 48, see each other's writes: writer 0 → reader 4 and writer 4 → reader 0 are both clean. Every pair involving an origin that isn't 16-byte aligned is stale (29-31 of 32).
That matches the fallback in this PR: a raw view whose start isn't 16-byte aligned gets "a copy of its own bytes", which draw.rs's updated test now asserts for 456 = 8 mod 16. A write through one such copy never reaches another view of the same records. On hosts where structured views read correctly today (WARP: 0 wrong on main, presumably AMD too), that's a regression.
Two shapes that would keep one copy:
- View raw from the start rounded down to 16 bytes and add the remainder in the shader (the stride table already carries per-view data).
- Keep the native structured view where the start isn't 16-byte aligned. That still leaves NVIDIA's structured-read problem for those views, but doesn't break the others.
The fixture is a good acceptance test to carry into the PR. All 31 overlapping writes should be visible across differently aligned origins.
|
Automated triage for the maintainers. Thanks for Notes for the maintainer: every buffer handle now reads the stride table (a small per-access cost), and CI: passing. Generated by Claude Code |
…t of their own Review of Marvisak#2878: the NVIDIA raw-structured change in the shader crate's test host is a separate matter (and is to be checked against Marvisak#2885). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
… VIEW_STRIDES bias
|
Thanks @steven-seagull27, @fyernald, and the triage review — pushed 1. Overlapping structured views now share one host copy (no private copies for 4-byte-aligned starts)
2. No native structured descriptor fallback behind raw shader handles
Verification (
|
| Test / Check | GeForce GTX 1650 | Windows WARP |
|---|---|---|
overlap_test::gpu_writes_visible_through_overlapping_views |
0 / 2,400 wrong (PASS, 0 D3D12 errors) | 0 / 2,400 wrong (PASS, 0 D3D12 errors) |
stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions (bias=0 & bias=12) |
PASS | PASS |
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride + heap_indexed_structured_buffers_with_distinct_strides |
PASS | PASS |
victory-gpu descriptor::host::* + draw::tests (--test-threads=1) |
36/37 PASS (only pre-existing FIND-9 dynamic_slots_are_held_until_released) |
36/37 PASS (only FIND-9) |
victory-shader (stride_tests, diff_tests, lower::tests, waterfall_tests, synthetic_tests) |
63/64 PASS (only pre-existing FIND-9 a_heap_buffer_read_where_no_buffer_view_is_reads_zeros) |
— |
cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings (default & --all-features) |
0 warnings | — |
cargo xtask policy |
pass (192 files ok, lower.rs = 522,717 bytes) |
— |
|
Pushed one small cleanup/fix ($sha):
|
|
RTX 5080 (Blackwell), driver 621.40, title runs: with this PR in place of #2464 in the NVIDIA stack, the interior shots draw a character that #2464's tree draws as broken spikes, with no other change in what translates and no device removal in 600 s. For the choice between this PR and #2464 the triage mentions, measured in the title rather than synthetically. Trees:
The translation counts are identical, so the difference is in how the views are made. My guess is the unaligned structured origins this PR copies to aligned ones and #2464 leaves structured (steven-seagull27's 12/24/36-byte case), but I haven't traced which buffer the character reads. Synthetic, same tree: Not tested: AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine (sandboxed at Low integrity, game folder read-only), read the logs and frame captures, and wrote this report. |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified on RTX 5090 against origin/main (63bcca4):
cargo test -p victory-shader --lib emit::stride_tests:: -- --test-threads=1: 9/10 passed on RTX 5090 — notablya_heap_buffer_read_by_element_takes_the_views_stridenow passes on RTX 5090 (fails on cleanorigin/main), along with both new tests (heap_indexed_structured_buffers_with_distinct_stridesandtable_bound_structured_buffer_reads_by_element_and_dimensions). The single remaining failure (a_heap_buffer_read_where_no_buffer_view_is_reads_zeros) reproduces identically on cleanorigin/main.cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 16/16 passed (includingoverlap_test::gpu_writes_visible_through_overlapping_viewsandstructured_buffer_views_stay_raw_on_host_and_keep_stride_table).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed.cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.
Great NVIDIA fix (FIND-11): viewing structured buffers raw on the host makes heap-indexed structured buffer reads work cleanly on RTX 5090.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
The raw-view + VIEW_STRIDES 0..12-byte bias approach works cleanly on NVIDIA hardware — verified locally on Windows 11 with an RTX 5090 and WARP (git merge-tree against 63bcca43 clean, cargo clippy --workspace --all-targets [--all-features] -- -D warnings clean, cargo xtask policy 192 files ok):
descriptor::host::overlap_test::gpu_writes_visible_through_overlapping_views: passed (0/2400 mismatches) on RTX 5090, RTX 5090 +VICTORY_D3D12_DEBUG=1, and WARP +VICTORY_D3D12_DEBUG=1structured_buffer_views_stay_raw_on_host_and_keep_stride_tableandstructured_views_off_their_buffers_elements_get_their_own_copy: passed on RTX 5090, RTX 5090 Debug, and WARP Debugvictory-shaderstride_tests::+diff_tests::+waterfall_tests::: 19/20 passed on RTX 5090 + WARP (including both new structured-buffer tests; the lonea_heap_buffer_read_where_no_buffer_view_is_reads_zerosfailure reproduces identically onorigin/main63bcca43due to NVIDIA's 1M heap cap inemit::host).
Two correctness bugs should be fixed before merge:
1. Out-of-bounds VIEW_STRIDES root-SRV read and silently dropped raw_bias for dynamic-slot tables (crates/victory-gpu/src/descriptor/host.rs:129-143, 511-519)
Before this PR, table-bound structured buffers used native structured handles (12 | u, stride) and did not read VIEW_STRIDES. Now every table-bound structured buffer (u.stride >= 4) loads VIEW_STRIDES[index] via view_raw_bias(h) -> view_word(index) (lower.rs:1808-1815, 4646-4652) using the unclamped heap slot index from entry_heap_index/heap_index.
However, HostHeap::new allocates self.strides for only count.max(HEAP_VIEWS) dwords (host.rs:130), and write_stride drops any write with index >= self.count.max(HEAP_VIEWS) (host.rs:513). On uncapped heaps where count + extra > count.max(HEAP_VIEWS) (e.g. a title heap with count = 1_245_184 + DYNAMIC = 262_144, or count = 900_000 + 262_144 > HEAP_VIEWS), any fresh descriptor table placed in dynamic slots at index >= count.max(HEAP_VIEWS) has its raw_bias write silently dropped and causes the shader to read past the end of the VIEW_STRIDES root SRV (no hardware bounds check — garbage bias or GPU page fault / device removal).
Allocating strides (and marks symmetrically at lines 135 & 531) after (heap, count, extra) is resolved with (count + extra).max(views) entries, and checking index >= (self.count + self.dynamic).max(HEAP_VIEWS) in write_stride / set_mark, fixes this cleanly.
2. ClearUnorderedAccessViewUint/Float on a biased (bias = 4/8/12) structured UAV clobbers 4..12 preceding bytes in the shared host copy (descriptor/host.rs:1393-1415, draw.rs:1056-1085)
buffer_uav rounds FirstElement down by bias = offset & 15 (aligned = offset - bias) and sets NumElements = (total_bytes + bias) / 4, relying on translated shaders to skip the leading bias bytes via VIEW_STRIDES.
draw.rs::clear_unordered invokes ClearUnorderedAccessViewUint/Float directly on that biased raw host UAV without shader execution (and with unshifted rects). When bias > 0, D3D12 clears [aligned, aligned + raw_count * 4), overwriting the 4..12 bytes immediately preceding start inside the shared Shadow buffer — bytes outside buffer_range(&view) that readable did not even snapshot.
For bias > 0 structured UAVs, clear_unordered needs to restrict the clear to [bias / 4 .. raw_count) (via shifted/clamped D3D12_RECTs on the raw buffer UAV, or an exact 16-byte-aligned clear path) so preceding neighbor bytes in the shared copy are never overwritten.
3. Minor: getDimensions (num_records) with idxen == false on a table-bound structured buffer (crates/victory-shader/src/emit/lower.rs:4442-4455)
When a table-bound buffer with used.stride >= 4 is accessed via buffer_load with idxen == false (div_stride == None, !is_heap_direct), line 4445 skips subtracting view_raw_bias(h), returning total_bytes + bias instead of total_bytes. Including || used.is_some_and(|u| u.stride >= 4) in that condition handles it consistently.
|
Tested on NVIDIA Ada (the description has Turing): RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, this PR (
victory-gpu: 233 passed, 0 failed. Full workspace green. Details in #2317. AI-assisted (Claude). |
|
@jujumoneylol @fuzeofficlal I reproduced the structured UAV clear in review item 2 on native Windows. Both the RTX 5080 and inbox WARP gave the following results in two fresh runs per adapter and revision.
Each case starts with 32 distinct guard words in one allocated buffer. A six-record view with a 12-byte stride starts at a 0, 4, 8, or 12-byte bias. The test clears either the whole view or the relative word rectangle The fix uses an exact The commit applies directly to git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2885-structured-clear-range
git cherry-pick 22f19d9
$env:VICTORY_D3D12_DEBUG = '1'
$env:VICTORY_D3D12_WARP = '0'
cargo test -p victory-gpu --features diagnostics --lib structured_clears_preserve_neighbor_words -- --nocapture
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --features diagnostics --lib structured_clears_preserve_neighbor_words -- --nocaptureAI-assisted patch and tests, run locally. |
Summary
Fixes FIND-11 (tracked in #1633 / #1744): NVIDIA GPUs misread heap-indexed structured buffers when a DXIL raw handle (
ByteAddressBuffer, resource kind11) indexes into a host D3D12 structured buffer descriptor (DXGI_FORMAT_UNKNOWN,StructureByteStride > 0).Root Cause
In DXIL,
annotateHandle(createHandleFromHeap(idx), ResourceProperties)requires a compile-time constant resource kind andStructStrideInBytes. Because heap-indexed buffers have runtime-variable strides (loaded fromVIEW_STRIDES),victory-shaderlowers heap-indexed buffer accesses through raw handles ((11 | u, 0)) and computesbyte = index * view_stride[idx] + offset.Previously,
victory-gpucreated host D3D12 structured views (StructureByteStride = S) for structured buffers. On NVIDIA hardware (verified on Turing GTX 1650, matching the RTX 5070 report in #1744),rawBufferLoad(raw_handle, byte_offset, undef)against a structured descriptor dividesbyte_offset / 4and uses that as the element index at inner offset 0 — reading[101, 104, 107, 110, ...]instead of[200, 201, 202, ...]for a 12-byte stride buffer withoffset:4.Changes
crates/victory-gpu/src/descriptor/host.rs:StructureByteStride > 0, 4-byte-multiple byte length fitting inu32dwords) as host raw views (DXGI_FORMAT_R32_TYPELESS,FirstElement = offset / 4,NumElements = total_bytes / 4,StructureByteStride = 0,D3D12_BUFFER_{SRV,UAV}_FLAG_RAW), respecting D3D12's 16-byte raw-view alignment (D3D12_RAW_UAV_SRV_BYTE_ALIGNMENTviashadow::for_view(..., 16)in bothbuffer_srv/buffer_uavandview_copy).VIEW_STRIDESviaview_stride().structured_buffer_views_stay_raw_on_host_and_keep_stride_tableverifying host view creation,VIEW_STRIDESpreservation, and zero D3D12 debug-layer errors.crates/victory-gpu/src/draw.rs:structured_views_off_their_buffers_elements_get_their_own_copyfor 16-byte raw-view alignment (2 * 456 = 912uses the buffer's copy;456(8 mod 16) and100(4 mod 16) get exact copies).crates/victory-shader/src/emit/lower.rs:(11 | u, 0)) with explicitbyte = index * stride + offsetso descriptor kinds match the raw host views across both table-bound and heap-indexed paths.getDimensions(Fields::BufferandFields::Smem) through raw handles ((11 | u, 0)) and divide the returned byte count bystride(UDiv) to recover the element record count.crates/victory-shader/src/emit/host.rs&diff_tests.rs:Stride::Structuredto create host raw SRVs matchingvictory-gpu, while addingStride::PcStructuredfor DXC-compiled PC reference shaders indiff_tests.crates/victory-shader/src/emit/stride_tests.rs:heap_indexed_structured_buffers_with_distinct_strides(multiple distinct strides in one heap on hardware + WARP).table_bound_structured_buffer_reads_by_element_and_dimensions(table-boundidxen+offset:4+num_recordsviagetDimensionson hardware + WARP).Verification (NVIDIA GeForce GTX 1650 + WARP, Windows 11)
mainf3578e3):emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_strideFAILED onhardware: got[101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 0, ...]instead of[200..231].main842b0cb):emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride: PASS on bothhardware(GTX 1650) andwarp.emit::stride_tests::heap_indexed_structured_buffers_with_distinct_strides: PASS on bothhardwareandwarp.emit::stride_tests::table_bound_structured_buffer_reads_by_element_and_dimensions: PASS on bothhardwareandwarp.cargo test -p victory-shader --lib: 303 passed (only failure is the pre-existingFIND-9NVIDIA 1M view-heap cap testa_heap_buffer_read_where_no_buffer_view_is_reads_zeros).cargo test -p victory-gpu --lib: 227 passed including 20/20draw::testsandstructured_buffer_views_stay_raw_on_host_and_keep_stride_tablewithVICTORY_D3D12_DEBUG=1(only failures are the 2 pre-existingFIND-91M view-heap cap tests).cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: 0 warnings/errors.cargo check --workspace --all-targets: clean.cargo xtask policy: pass (asset policy: 191 files ok).Notes
FIND-11in Coordinating who works on what #1633.