Repository navigation
Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA) - #2037
Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA)#2037desplmfao wants to merge 1 commit into
Conversation
…gned dword directly format_load aligned the offset of a field narrower than a dword with `off & !3` even when the offset was a constant. vkd3d-proton turns a raw load at a computed offset into a per-component raw access chain (stride 0), and on NVIDIA that load did not see the dword the same invocation had just stored through the buffer's other access (stride 16, per element): it read 0. A constant offset now gives a constant aligned address and shift, and the load takes the same access as the store. Fixes on an RTX 5080 (vkd3d-proton 3.2.0, Proton): normalized_buffer_formats_load_their_ends_exactly and tbuffer_d16_loads_pack_two_channels_per_dword. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 + WARP, Rust 1.98.1 MSVC):
cargo test -p victory-shader --lib emit::semantics_tests::— 32 passed, 0 failed (1 ignored) on RTX 5090 hardware + WARPcargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean aligned-dword direct load optimization for byte/half format loads at constant offsets on NVIDIA. Looks good.
AI-assisted (Gemini 4 Neon).
|
Triage verdict — Keep the constant-offset fix ( Evidence
Checks and limits
Next step
This verification was AI-assisted. |
Use the same dword alignment and byte shift without emitting arithmetic for constant offsets. Preserve the code path for computed offsets. Verified portable shader tests and Windows MSVC workspace test compilation.
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.
144 passed / 0 failed. Byte and half format loads at a constant offset load the aligned dword — offset normalization fix for narrow format loads.
|
Automated triage for the maintainers. In CI: passing ( Generated by Claude Code |
Offline measurement on a retail dumpResult: no count change against I merged head 8c0058b 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). |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed and verified against main (63bcca43) on Windows 11 with NVIDIA RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1 + dxil.dll) — clean, minimal fix and ready to merge:
- In
format_load(crates/victory-shader/src/emit/lower.rs:4936-4956), folding constantself.s.m.int_value(off)(o as u32) directly intoself.s.m.i32(o & !3)and shift(o & 3) * 8preserves exact alignment/bit-shift semantics while eliminating theBin::Andthat caused NVIDIA's backend to treat the load as a dynamic sub-dword offset and miss same-invocation writes to the same dword. - (Minor non-blocking notes: on
63bcca43,emit/lower.rssits at 521,213 B,3,075 Bunder the 512 KiB cap; unformatted sub-dword loads atlower.rs:9766-9767andraw_viewoffsets atlower.rs:1800still emit dynamicBin::And/Bin::Addif a similar follow-up is ever needed.)
Local verification:
victory-shader(tbuffer_d16/normalized_buffer_formats/half_buffer/d16_*/emit::lower::tests): 40/40 passed on RTX 5090 (DEBUG=1), 7/7 passed on WARP (DEBUG=1)cargo clippy --all-targets -- -D warnings+cargo xtask policy(191 files ok): 0 warnings
…at a constant offset load the aligned dword directly (NVIDIA)
…words alone Since Marvisak#2312 every compute program reads two host user-data dwords (DISPATCH_SLOT) past the title's. Tests merged in the PR refresh were written without them: Marvisak#2037's indexed CBV test panicked on the unexpected (Constants, 255) entry, Marvisak#2152's ds_permute test wrote the mask's high half into them (the program would run as if spread), Marvisak#3038's test counted them as spilled user data at index 16 and up, and Marvisak#171's GPU test set five of seven root constants. They now leave the two words at zero or skip them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
On NVIDIA (RTX 5080, vkd3d-proton 3.2.0 under Proton), two buffer-format tests on
mainread 0 where they stored a value:valu_tests::normalized_buffer_formats_load_their_ends_exactly:format 1 of 0xff = 0x00000000, want 1valu_tests::tbuffer_d16_loads_pack_two_channels_per_dword:d16 opcode 8 format 13 of 0x40003c00 = 0x00000000, want 0x00003c00Only formats narrower than a dword fail (8_UNORM, 16_FLOAT single channel); the 32-bit formats in the same tests pass.
Cause
format_loadaligns the offset of a byte or half field withoff & !3, even whenoffis a constant. In the SPIR-V that vkd3d-proton makes of it (VKD3D_SHADER_DUMP_PATH):OpRawAccessChainNV ... %uint_16 %uint_0 %uint_0 RobustnessPerElementNV, the same access as the test'sbuffer_store_dwordbefore it;0 & 0xFFFFFFFC:OpRawAccessChainNV ... %uint_0 %uint_0 %96 RobustnessPerComponentNV.On NVIDIA that second load does not see the dword the same invocation just stored through the first kind of access, and reads 0.
Change
When the offset is a constant,
format_loadcomputes the aligned address and the shift as constants, so the load takes the same access as the store. A computed offset is lowered as before.This doesn't fix a load at a computed offset after a store in the same invocation, if NVIDIA behaves the same way there. These two tests don't cover that case, and I haven't seen it in a test or in the title.
Tested
RTX 5080, Linux, proton-cachyos 11.0 with vkd3d-proton 3.2.0,
victory-shadertests with--test-threads 1:main(940d32f): 241 passed, 6 failedvalu_testspass.cargo clippyreports nothing new;cargo fmt --checkshows no diff in the changed lines.The other four failures on this machine
semantics_tests::rounding_matches_the_hardware(v_fract/v_floor/v_ceilof denormals): Shaders: floor, ceil and fract read denormals as zeros #1994 should fix it.stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros:dispatch failed: Invalid parameter.The test harness asks for a heap ofHEAP_VIEWS= 2,097,152 views, and vkd3d-proton refuses heaps over 1,041,451 on NVIDIA (Unsupported descriptor count 2097152 for heap type 0). GPU: size the view heap clamp from what the host takes (NVIDIA 1,000,000 cap) #1777 and GPU: view heaps on hosts capped below 2^21 descriptors #1779 address the capped heap and should fix it.semantics_tests::hosts_that_do_not_fuse_are_namedandtests::stub_pipeline_is_created: these come from running the tests under Wine. Wine's "WARP" adapter is not Microsoft's WARP, and vkd3d-proton doesn't check the DXIL digest. Neither is a translation problem.Related
#1669 and #1288 change the same branch of
format_load(fields at byte offsets that straddle or sit inside a dword). They don't touch constant offsets, but they may conflict textually with this change.AI-assisted (Claude Code).
🤖 Generated with Claude Code