Shaders: LDS halfwords straddling two dwords, and hardware tests of byte and halfword LDS accesses #116
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!116
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/116/head"
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 00:39 UTC · original
dragoso:shader/lds-sub-dword→main· +661 −1 · 3 files · 3 commits · closed without mergingWhat
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 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
ds_read_{u,i}{8,16}, their _d16/_d16_hi forms, and ds_write_b{8,16} (and _d16_hi) went untranslated. Reads load the dword holding the data, shift it down and extend it; the d16 forms fill one half of the VGPR and keep the other, which the IR now records as a read of the destination. Writes clear the bytes and set them with two atomics, so lanes writing other bytes of the same dword at once keep theirs. Synthetic GFX10 compute programs check every form against a model of the console's LDS on the host GPU and WARP, including 64 lanes writing neighbouring bytes of shared dwords. Co-Authored-By: Claude Opus 5.5 <[email protected]>@DaviTostes on GitHub · 2026-11-24 00:51 UTC · original
Tested
8504777on Arch Linux x86_64, rustc 1.98.1:cargo test -p victory-shader: 54 passed, 0 failed (2 test binaries), including the newcrates/victory-shader/src/emit/lds_tests.rsthis PR adds (434 lines).victory-gpu(host_resource), which #112 fixes.crates/victory-shader/src/emit/lower.rs, presumably because #112 reformats the workspace. The shader crate itself builds and tests fine, so this is a rebase/format conflict, not a semantic one — but it needs a rebase before the workspace suite can be run on top of it.No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
@ghost on GitHub · 2026-11-24 00:51 UTC · original · edited 2026-11-24 01:08 UTC
Correction (later the same night): with more runs,
maincrashes too.cargo test -q -p victory-shader --libonmain9aef3d9gave0xC0000005in 3 of 25 runs on this card, so the crash itself is already onmain(parallel GPU tests on AMD). This PR's two tests make it far more frequent (4 of 5 runs with theldsfilter) but don't cause it. The table below stands; its "0 crashes in 12 runs" row was just too few runs.AMD run: the new tests pass one at a time, but the test process crashes (
0xC0000005, access violation) whenbyte_and_halfword_writesandbyte_and_halfword_readsrun at the same time, which is cargo's default.Head
8504777as is (it conflicts with currentmain9aef3d9), on an AMD Radeon RX 9060 XT (RDNA4), driver 32.0.32029.2010, Ryzen 7 5800X3D, Windows 11 Pro 26200, Rust 1.98.1, debug:cargo test -q -p victory-shader …)lds(default threads)c0000005 0 c0000005 c0000005 c0000005lds -- --test-threads=10 0 0 0 0lds_testsalone (--exact), 3 runs each0--exactwrites + readsc0000005 0 0 c0000005 0 0--exactwrites +lanes_share_dwords0(6 runs)--exactreads +lanes_share_dwords0(6 runs)--libon this head--libon your base8fe0b74--libandvalu_testsonmain9aef3d9(7 GPU tests also in parallel)So it comes from these two tests running side by side, not from parallel GPU tests in general. The output stops after the non-GPU tests print
ok, so it dies inside the GPU part. Each test makes its own hardware and WARPHost, so I couldn't tell which of the two crashes. A one-at-a-time run ofcargo test --workspacepasses (250 / 0 / 3 on this head), but the default parallel run is what CI and other testers will hit.AI use
@Lyrnc on GitHub · 2026-11-24 06:08 UTC · original
RDNA2 hardware measurement of the read forms and of the two
shortcut:cases: every read form matches. The two shortcut cases behave differently on the hardware, so here is what it does in case you want to close them.Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr), one wave of 32: 16 lanes store distinct dwords to LDS, then lane
ireads at byte addressiwith each form. The d16 destinations are preset to0xaaaa5555. Then all 32 lanes write the same byte, and the same halfword, at once. RDNA2 desktop silicon in HIP's LDS alignment mode, not necessarily the console's mode. No game data.ds_read_u8,ds_read_i8ds_read_u16,ds_read_i16ds_read_u8_d16,ds_read_u8_d16_hi,ds_read_i8_d16ds_read_u16_d16,ds_read_u16_d16_hiSo the extension and the kept half are as in this PR.
The two shortcut cases:
ds_read_u16at 3 gives bytes 3-4). Under the "2-aligned" shortcut an odd address reads the wrong bytes. This may depend on the LDS alignment mode the console sets, which I can't see from here.lane + 1to byte0x101withds_write_b8: the dword became0x00002000, so byte 1 =0x20, the highest lane's value. Or-ed together it would be0x3f. Same withds_write_b16of(lane + 1) * 0x0101to0x202:0x20200200, lane 31 again. So the console-side answer for the same-byte race is "highest active lane wins". A per-lane compare-exchange would match it, at the cost of the loop you wanted to avoid.AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
@Exorion1er on GitHub · 2026-11-24 09:33 UTC · original
Three PRs implement LDS byte and halfword accesses, and they differ in coverage:
mainir.rslds_tests.rs, 4 testsir.rschange (so the old VGPR may not be kept)_d16_hiwrites)So they're alternatives, not copies: this PR is the most complete and best tested, and #571 is the only one handling straddling halves. They all edit the same code in
lower.rs.Checked by reading the diffs. Not run. AI-assisted (Claude Code).
@catminou4 on GitHub · 2026-11-24 11:04 UTC · original
Triage note: same feature as #101 and #632 — byte/halfword LDS reads and writes were refused with "an LDS read/write of bytes or halves".
lower.rsalone; I approved it after a clean test-merge with current main (shader tests green on macOS).This one currently has
mergeable=falseagainst main and additionally changesir.rs/mod.rs— worth a look at whether that broader surface is needed, or whether #101's narrower change suffices. Flagging the triple overlap so review effort isn't tripled.@dragoso on GitHub · 2026-11-24 18:47 UTC · original
Thanks for the runs and the review. Where things stand at
c853a6a, rebased on currentmainwith no conflicts:valu_tests::ONE_AT_A_TIME, from74a9d33), so they no longer dispatch at the same time as each other or the other GPU tests.cargo test --workspacepasses with the default parallel threads.c853a6a. A halfword at byte 3 now takes its high byte from byte 0 of the next dword, for reads and writes, without a branch or loop. The tests now cover every byte address from 2 to 7, odd and straddling halves included. They fail on the previous lowering and pass on the GPU and WARP.shortcut:comment now says the hardware keeps the highest lane's value (your measurement), not one arbitrary lane's.ir.rssurface (@catminou4): that change is gone. The IR already records a vector destination as a read, so the d16 forms keep the other half without it. The PR now touches onlylower.rs,mod.rs(test module) and the newlds_tests.rs.Tested on Windows 11, NVIDIA RTX 5060 Ti and WARP:
cargo test --workspaceok,cargo clippy -p victory-shader --all-targetsclean,cargo xtask policyok. Not run on AMD.AI use: Claude Code (Claude Opus 5.5) wrote the change, ran the tests above and posted this comment.
@ghost on GitHub · 2026-11-24 20:12 UTC · original
@dragoso
c853a6aon the card that crashed before: RX 9060 XT (RDNA 4), Adrenalin 32.0.32029.2010, Windows 11. I ran thevictory-shadertest binary with its default parallel test threads: 125 passed, 0 failed, 1 ignored. All four LDS tests passed:opcodes,byte_and_halfword_reads,byte_and_halfword_writesandlanes_share_dwords. The earlier 0xC0000005 when the LDS tests overlapped did not occur in 1 run.Not tested: the full
cargo test --workspace.AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@dragoso on GitHub · 2026-11-24 22:34 UTC · original
Rescoped at
87c86f0.mainnow has its own byte and halfword LDS lowering (0b35b7f), the same approach as this PR, so I dropped this PR's version and rebased what's left ontomain70564ae:main's code;lds_tests.rs, ported torange::buildand the newHostShaderfields.On plain
mainthe tests fail only for the straddling halfwords; with this PR they pass on the RTX 5060 Ti and WARP. That also makes #101, #571 and #632 mostly redundant withmain. Only #571 handled the straddling case.@ghost: thanks for the RX 9060 XT run. That was on the previous head. The tests haven't changed in substance, but this head isn't tested on AMD.
AI use: Claude Code (Claude Opus 5.5) made this change, ran the tests and posted this comment.
@dragoso on GitHub · 2026-11-24 22:44 UTC · original
The rescoped change (straddling halfwords on top of
main's own byte/halfword LDS lowering, plus the hardware tests) is now in #1795.Pull request closed