Repository navigation
Shaders: LDS halfwords straddling two dwords, and hardware tests of byte and halfword LDS accesses - #1795
Shaders: LDS halfwords straddling two dwords, and hardware tests of byte and halfword LDS accesses#1795dragoso wants to merge 2 commits into
Conversation
catminou4
left a comment
There was a problem hiding this comment.
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests (valu_tests/host) are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.
LDS halfwords straddling two dwords + hardware tests of byte/halfword access: build_cs/run/halfword/model_read harness, halfword() classifier. 21K diff — the straddling-dword case is the classic LDS aliasing bug; good that it has hardware-side tests (Windows-gated).
|
In This also matters with #1769: that PR bounds accesses that go through Small test gap: Static review (AI-assisted), read against |
|
@rminzao thanks, both fixed in
@catminou4 thanks for the macOS run. Tested on Windows 11, RTX 5060 Ti and WARP: the 8 LDS tests pass. AI use: Claude Code (Claude Opus 5.5) made this change, ran the tests and posted this comment. |
|
Ran on NVIDIA at
AI-assisted (Claude Code); run on our machine. |
30b4479 to
949aff8
Compare
…yte and halfword LDS accesses A halfword at byte 3 of a dword takes its high byte from byte 0 of the next one: an RDNA2 measurement showed the hardware reads and writes the two bytes at the address across the dword boundary, where the byte and halfword LDS lowering took halfwords as aligned. Reads now OR in the next dword's byte 0, and writes clear and set it with one more and/or atomic pair, selected so other halfwords touch nothing past their own dword. No branch or loop. emit/lds_tests.rs runs synthetic GFX10 compute programs (hand-encoded, nothing from any title) on the host GPU and WARP against a model of the console's LDS: every read form (with the d16 halves) and write form at every byte address from 2 to 7, and 64 lanes writing neighbouring bytes and halfwords of shared dwords. They take the GPU tests' one-at-a-time lock. On main they fail only for the straddling halfwords. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lds_straddle indexed the dword after a halfword at byte 3 without a bound, so a halfword at the last byte of LDS read and wrote one element past the group-shared array. It now straddles only when that dword is in the allocation; past the end the high byte reads 0 and its write is dropped, as out-of-bounds LDS accesses do on the console. The tests now take halfwords at byte 7 too (the straddle into dword 2), and a new one reads and writes a halfword at byte 511 of a 512-byte allocation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
949aff8 to
8da3572
Compare
What
mainnow lowers byte and halfword LDS reads and writes itself (0b35b7f), with the same approach this PR had (shift and extend, the d16 halves,and/oratomics for writes). This PR is now just what that implementation doesn't cover:ds_read_u16at address 3 reads bytes 3-4 across the dword boundary, and the writes do the same. Before this, the lowering took halfwords as aligned and read or wrote the wrong bytes there. Reads now OR in the next dword's byte 0. Writes clear and set it with one moreand/oratomic pair, selected so other halfwords touch nothing past their own dword. No branch or loop. A halfword at the last byte of the program's LDS has no next dword: its high byte reads 0 and its write is dropped, as out-of-bounds accesses do. A newlds_straddlehelper sits next tolds_shift.shortcut:comment now says what the hardware keeps: the highest lane's value, measured on RDNA2. The lowering still leaves the OR of the values. A compare-exchange loop would be exact, but extra divergent loops have hung the AMD driver before.Tests
emit/lds_tests.rs: synthetic GFX10 compute programs (hand-encoded, nothing from any title), lowered, validated bydxil.dllwhen present, and run on the hardware GPU and WARP against a model of the console's LDS:They take the GPU tests' one-at-a-time lock (
valu_tests::ONE_AT_A_TIME). Onmainthey fail only for the straddling halfwords.Tested on Windows 11, NVIDIA RTX 5060 Ti and WARP: the LDS tests pass. In
cargo test --workspace --no-fail-fast, the only failures are 5 that fail the same way onmain70564ae on this machine:victory-shaderstride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware, andvictory-gpudescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views.cargo clippy -p victory-shader --all-targetsis clean, andcargo xtask policyis ok. Not run on AMD at this head.🤖 Generated with Claude Code