Repository navigation
GPU+shader: back structured buffer views with raw descriptors for NVIDIA rawBufferLoad - #2178
n-romanovich wants to merge 3 commits into
Conversation
5dbc85b to
9124d69
Compare
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib shader_cache::— 3 passed, 0 failedcargo test -p victory-shader --lib emit::stride_tests::— 5 passed, 1 failed on RTX 5090: directly fixesa_heap_buffer_read_by_element_takes_the_views_strideon NVIDIA! (The 1 remaining failure,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, is the separate NVIDIA 1M view-heap cap issue covered by #2177/#2121.)cargo clippy -p victory-gpu -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean raw-descriptor backing for structured buffer views on NVIDIA with cache-key inclusion. Looks good.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked (shader half; the GPU half is Windows-only).
144 passed / 0 failed / 2 ignored. Structured buffer views backed with raw descriptors — descriptor backing change; mixed gpu+shader, relates to #2128's typed null descriptors.
…y #2178) Port of Marvisak/VIctory#2178 by n-romanovich (GPL-3.0-or-later). Structured SRV/UAVs become R32_TYPELESS raw views (aligned, 4-byte elements), so NVIDIA's rawBufferLoad does not multiply offsets by the stride; the translator lowers table/scalar structured reads as raw byte addresses with the length divided by the stride, gated by the new emit setting that is also part of the shader cache key. Adapted to ours: the key keeps the view count and page-table flag (raw structured appended), and the computed-view address words. lower.rs stays under the 512 KiB asset policy.
Offline measurement on a retail dumpResult: no count change against I merged head 9124d69 onto No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
Shader tests on NVIDIA AdaI ran
So on Ada this PR fixes AI-assisted (Claude Code). |
|
Offline A/B on an RTX 3060 Ti (8 GiB, NVIDIA 616.56), Ryzen 7 5700X3D, 32 GiB RAM, Windows 11 Pro build 26200. Both Series X runs used the diagnostic build, one GPU list at a time, fresh caches and the default shader loop limit. The control ( Adding this PR ( AI-assisted testing. Code-only integration branch: https://github.com/Capi360/VIctory/tree/codex/rtx-3060-ti-current-raw-views I also tested a follow-up for structured views whose offset in the host buffer is a valid element offset but is not 16-byte aligned. This PR can leave those views structured even when the shader expects raw access. The follow-up uses the same aligned copy when creating and refreshing the view. The targeted D3D12 regression test passed on the RTX 3060 Ti. The later indirect compute reset still reproduced. Code: Capi360@9aad41f |
|
RTX 2060 6 GB (Turing), driver 621.40, Windows 11, on
The gather test still fails here because 🤖 Generated with Claude Code |
|
On my RTX 5080, #2178 fixed the structured-buffer read at byte offset 0. I found a remaining case through the production descriptor path. With a 12-byte record stride, views starting at bytes 12, 24 and 36 returned the wrong data. A shader querying one of those 32-record views also got 10 records. Offsets 0 and 48 worked, and moving the same data from offset 12 to offset 0 restored all 32 values. I tested on Windows 11 build 26300.10075, NVIDIA driver 621.40 and built-in WARP 10.0.26100.10068. The baseline combines this head
The candidate aligns the raw SRV start down to 16 bytes, retains the original end, and records the leading dwords in the slot’s stride entry. The translated read adds that offset, and the dimensions query subtracts it. The original GPU backing stays shared. After the change, both readers saw the value 31 written by lane 31, including the offset-12 reader that previously returned zero. All tested views reported the expected 32 records. The change covers SRV reads. Displaced views whose expanded byte length exceeds the 32-bit offset range retain the previous handling. These are synthetic GPU readbacks. Game frame times remain unmeasured. Read-side fix · Four opt-in tests The fix and tests are separate commits that can be cherry-picked onto the combined baseline. To rerun the exact published tree from a VIctory checkout in PowerShell: git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/structured-srv-readbacks
git worktree add --detach ../victory-srv-readbacks FETCH_HEAD
Set-Location ../victory-srv-readbacks
$env:VICTORY_D3D12_WARP = '0'
cargo test -p victory-gpu --all-features --lib --locked structured_srv_readbacks -- --ignored --nocapture --test-threads=1
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --all-features --lib --locked structured_srv_readbacks -- --ignored --nocapture --test-threads=1 |
Vendor matrix and an in-game measurement (RTX 5080, AMD RDNA2 iGPU)We ran into the same NVIDIA behaviour independently, in our own tree (upstream
Driver at the time of writing: 616.56; the version during the 24 Nov measurements was not recorded. What this means for the change here:
In the world, one compute dispatch ( Not measured: this PR's own head on our machine. (Measurements and write-up AI-assisted, Claude Code.) |
|
@Qedycik, thanks for checking both vendors and measuring the slow world dispatch. Could you try the aligned-start SRV patch on your RDNA2 iGPU? The published test tree is If you still have that world scene handy, could you also compare the same scene on the same adapter and settings before and after the patch? The exact A/B is |
|
Automated triage for the maintainers. Needs work: needs the maintainer's decision. It now merges cleanly into The PR makes structured buffer views raw (
Generated by Claude Code |
9124d69 to
e1b447c
Compare
|
@Marvisak, updated
|
…DIA rawBufferLoad
e1b447c to
d234b68
Compare
…fers # Conflicts: # crates/victory-gpu/src/descriptor/host.rs # crates/victory-gpu/src/draw.rs
|
I measured the alignment fallback on CPU refresh at submission still took 23.6–24.4 µs unaligned versus 6.0–6.9 µs aligned, even though the unaligned case refreshed fewer bytes in this synthetic layout. All 311,040 GPU-read dwords matched. The timings exclude GPU execution and fence waits. Benchmark, p95 values, and reproduction command. Code and hardware testing assisted by Codex. |
|
In-game on NVIDIA Ampere, against W from #1968 (
With this PR, world frames were 0.40-5.4 s (median 0.84 s over 79 samples, one every 10 s). Peaks were 7.6 GB of video memory and about 31 GB of Windows commit. 170 compute pipelines were still refused by the host (the WaveSize(64) set, #2220). So on this card the structured-to-raw change is what removes W's 11 s. That fits the cause in #1968 (W's loop bound read from a structured view). Without the change, #2167 alone left W unchanged here (my comment there). I have not tried the overlapping #2464 or #1887 in-game, so this does not choose between the approaches. It also does not isolate the cost of the extra 16-byte-aligned copies: the base never got far enough for a frame-time comparison. Tests on this card with this PR merged (base as above): One of the two runs of this build ended at boot with the title's own AI-assisted (Claude Code); the runs are on my machine. |
…raw view gathers_at_a_level_match_the_hardware reads each lane's record (offset, u, v, level) by byte offset through a structured view (stride 16). On NVIDIA a raw load through a structured descriptor multiplies the offset by the stride (Marvisak#2178), so every lane read zeros and every lane failed with the gather of (0, 0) at level 0, [0, 1, 0, 0], including the native gather the test compares against: it looked like a gather bug, and is none. The records go through a raw view, as Marvisak#2178 does for stride_tests. On an RTX 5090 the test then passes on the hardware and on WARP; the gathers were right all along. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@n-romanovich I ran the GPU-write case on
The fixture initializes the allocation once. A translated shader writes one dword per 12-byte record through a placed UAV. After a fence, a second translated shader reads the same bytes through five placed SRVs. All 1,600 untouched field values matched on the current head. All 544 mismatches were in the field the GPU had written, through a reader with a different origin. For example, a writer at byte 12 and a reader at byte 24 share 31 records. All 31 returned their initial value. The 32nd, non-overlapping record retained its expected value. This exercises an additional case beyond CPU-initialized reads and the reported in-game timing improvement. This test-only commit is directly on git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2178-overlapping-gpu-writes
git switch --detach ec6ea83c94ddd956b84fce4c2167ad1ead3aeae2
$env:VICTORY_D3D12_WARP = '0'
cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1
$env:VICTORY_D3D12_WARP = '1'
cargo test -p victory-gpu --all-features --lib --locked gpu_writes_visible_through_overlapping_views -- --ignored --nocapture --test-threads=1The per-view aligned copies can contain different versions of the same GPU-written bytes. The shared-backing control is one measured reference for preserving visibility. Synthetic D3D12 readbacks, AI-assisted with Codex. |
Summary
On NVIDIA hardware, executing DXIL
rawBufferLoad(ByteAddressBuffer) against a D3D12StructuredBufferdescriptor (StructureByteStride > 0) multiplies the byte offset byStructureByteStride, corrupting reads and returning zeros pastwidth / stride(as exposed bystride_tests::a_heap_buffer_read_by_element_takes_the_views_stride).This change:
StructureByteStride > 0, 4-byte-aligned element size) toDXGI_FORMAT_R32_TYPELESSwithD3D12_BUFFER_{SRV,UAV}_FLAG_RAWinbuffer_srvandbuffer_uav(HostHeapstill records the original element stride inVIEW_STRIDES).set_host_raw_structured/host_raw_structuredinvictory_shader::emit(enabled byvictory-gpuand included inshader_cache::key) so indexed/scalar-loaded structured buffers in descriptor tables also lower to raw byte-address reads, writes, atomics, andgetDimensions / stride.stride_tests::a_heap_buffer_read_by_element_takes_the_views_strideto pass a raw heap descriptor (Stride::Raw) alongside theVIEW_STRIDEStable, matching theemitmodule contract.Verification
Tested on NVIDIA GeForce RTX 5060 Ti:
cargo test --release -p victory-shader --lib -- stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride diff_tests:6 passed; 0 failedcargo test --release -p victory-gpu --lib -- shader_cache::tests:3 passed; 0 failed