Shaders: LDS halfwords straddling two dwords, and hardware tests of byte and halfword LDS accesses #1795
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1795
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1795"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@dragoso on GitHub · 2026-11-24 22:44 UTC · original
dragoso:shader/lds-sub-dword→main· +562 −1 · 3 files · 2 commits · openWhat
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 onmain70564aeon 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
@rminzao on GitHub · 2026-11-24 23:09 UTC · original
lds_straddlehas no bound onindex + 1In
lds_straddle,after = index + 1is used as an element index into the LDS array with no check against the allocation. A compute program with 512 bytes of LDS doingds_read_u16/ds_write_b16at byte 511 then reads or writes element 128 of a[128 x i32]group-shared array. That's undefined and may hit a neighbouring variable. On hardware the high byte would read 0 and the write's high byte would be dropped.This also matters with #1769: that PR bounds accesses that go through
dword, butlds_straddlebuilds its second element directly, so even with both merged the straddling dword stays unbounded. Whichever lands second probably needs to givep2its own in-range check (read 0, drop the write).Small test gap:
lds_tests.rstests halfwords from byte 2 to 6, so the straddle at byte 7 (dword 1 into dword 2) isn't covered.Static review (AI-assisted), read against
mainat70564ae; nothing was run on a GPU.@dragoso on GitHub · 2026-11-24 23:12 UTC · original
@rminzao thanks, both fixed in
30b4479:index + 1: a halfword now counts as straddling only when the next dword is in the program's LDS (index + 1 < lds_dwords). Past the end its high byte reads 0 and its write is dropped, as you describe for the hardware. The low byte is read and written as before, so this doesn't depend on #1769: whichever lands second,p2is never out of range.a_halfword_at_the_end_of_lds:ds_read_u16andds_write_b16at byte 511 of a 512-byte allocation. One limitation: on the RTX 5060 Ti and WARP it also passes without the bound, because those devices happen to read 0 and drop the write out of range. So it pins the expected result, but on those devices it doesn't prove the bound. The bound comes from the lowering itself.@catminou4 thanks for the macOS run.
Tested on Windows 11, RTX 5060 Ti and WARP: the 8 LDS tests pass.
cargo test -p victory-shaderhas the same 3 failures asmain70564aeon this machine (twostride_testsheap-buffer tests andgathers_at_a_level_match_the_hardware).cargo clippy -p victory-shader --all-targetsis clean.AI use: Claude Code (Claude Opus 5.5) made this change, ran the tests and posted this comment.
@dragoso on GitHub · 2026-11-25 00:05 UTC · original
Ran on NVIDIA at
87c86f0: all 7 LDS tests pass. The 3 failures in the full crate also fail onmain; they are the ones already reported in #1835.Hardware: NVIDIA GeForce RTX 5060 Ti (Blackwell, 32-lane waves), driver 32.0.16.1742, Windows 11 Pro (build 26300), Rust 1.98.1 MSVC. DXGI adapter 0 is the RTX 5060 Ti, so the default device the tests create is this card, not the AMD iGPU on the same machine.
cargo test -p victory-shader --lib lds: 7 passed, 0 failed. That covers the opcodes, the byte and halfword reads and writes, and the straddling halfwords.cargo test -p victory-shader --lib(default parallel threads): 210 passed, 3 failed, 2 ignored. The 3 failures are:stride_tests::a_heap_buffer_read_by_element_takes_the_views_stridestride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerossynthetic_tests::gathers_at_a_level_match_the_hardwareAll three fail identically on
main70564aeon this card. Per #1835, the view heap they create is larger than NVIDIA's 1,000,000 limit, so they are unrelated to this PR.No crash with the parallel test threads.
AI-assisted (Claude Code); run on our machine.
@Marvisak on GitHub · 2026-11-25 06:25 UTC · original · edited 2026-11-25 22:18 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main(conflict incrates/victory-shader/src/emit/lower.rs). It will be reviewed again once it is rebased.From the earlier needs-work note, still open: say how the straddling LDS halfword behaviour was measured on RDNA2 (tool, GPU, driver), or give console evidence or documentation for the alignment mode the console uses.
Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.