Shaders: integer memory atomics and sub-dword buffer accesses #164
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!164
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/164/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?
@r4tedx on GitHub · 2026-11-24 01:02 UTC · original
r4tedx:shader/memory-forms→main· +1624 −142 · 8 files · 2 commits · closed without mergingMeasured on the title's shaders (by a tester)
EduAzevedo ran
victory translate --jobs 8 --listover the retail shaders (v1.0.2.1, 26,148 programs) onmaind2a4baeand on this head3bbc9ba, compared program by program (result): 0 programs gained, 0 programs lost. No refusal reason changes.So this PR does not change what translates in this title today. It adds coverage and is tested on synthetic programs only; it can wait behind PRs that unblock programs the title uses.
What
The memory instruction families were only partly lowered; a refused form fails its whole shader.
fn ds):inc,dec,rsub,mskorwith and without_rtn, andds_wrap_rtn_b32, as compare-exchange loops after the RDNA 2 ISA's definitions. The 64-bit integer forms (arithmetic, min/max, bitwise, compare-store, exchange,wrxchg2,wrxchg2st64). A shader that uses a 64-bit LDS atomic gets onei64groupshared allocation that every access width shares, so dword accesses still alias it (they become compare-exchange updates of their half); such shaders declare SM 6.6's 64-bit atomics on groupshared memory.fn buffer): signed and unsigned byte and halfword loads, byte and short stores, the unformatted D16 forms;sub,inc,dec,csub(clamps at zero, returns the previous value) and the 13 integer_x2atomics. Sub-dword stores mask the affected bytes with a compare-exchange per dword, so concurrent writes to neighbouring bytes are not lost.s_load_dword{,x2,x4,x8,x16}through traced root SRVs and CBVs.Still refused, each with its reason: floating-point LDS and buffer atomics (need the console's MODE denormal state), LDS
src2forms,addtid,ds_condxchg32_rtn_b64, global stores and atomics, general FLAT and scratch, scalar stores and atomics, partial or offset typed stores, indexed MTBUF loads.Not included: byte and halfword LDS reads and writes, which #101 and #116 cover.
Not verified
No game files were used. Semantics are from AMD's RDNA 2 ISA reference (sections 12.13-12.14) and LLVM's
DSInstructions.td/BUFInstructions.td. Whole-dword and atomic accesses are taken as naturally aligned; odd-address halves follow the unaligned-access mode, including a half that spans two dwords.Checked on RDNA2 hardware by a reviewer (Lyrnc, a Radeon integrated GPU, gfx1036, probes assembled by the AMD driver):
ds_inc_rtn_u32,ds_dec_rtn_u32,ds_rsub_rtn_u32,ds_mskor_rtn_b32andds_wrap_rtn_b32match the definitions used here on 492 of 492 value triples each, andglobal_atomic_csub(the same operation asbuffer_atomic_csub) on 364 of 364 pairs; every_rtnform returns the old value. Not probed there: the 64-bit forms and the sub-dword buffer accesses. It is desktop RDNA2 silicon, not the console's.Tested
Windows 11, NVIDIA RTX 5070, synthetic only:
dxil.dllvalidation): atomic return and stored values, zero limits, wrapping, sign extension, preserved D16 halves, contended byte stores, out-of-bounds accesses, 64-bit atomics sharing the dword allocation. They all stop at unsupported instructions onmain.memory_opcode_refusals, ignored by default) lists the refusals across the memory opcode tables.cargo test -p victory-shader: 78 passed, 1 ignored. clippy: nothing new.cargo xtask policy: ok.Stays out of
fn image(#48),buffer_format(#25) and wave/lane code.AI-assisted; no game assets were used.
🤖 Generated with Claude Code
@DaviTostes on GitHub · 2026-11-24 01:19 UTC · original
Tested
3bbc9baon Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-shader: 56 passed, 0 failed, 1 ignored (2 test binaries), including the 10 tests this PR adds.emit::memory_tests::memory_opcode_refusals(opcode coverage report).victory-gpuE0425.No game data used.
@Lyrnc on GitHub · 2026-11-24 06:09 UTC · original
RDNA2 hardware check of the ISA definitions this PR implements for the new LDS atomics and
csub: all match.AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. In a HIP kernel (assembled by the AMD driver's amd_comgr), each lane works on its own LDS dword: store
tmp, run the_rtnatomic withdata(anddata2), read the dword back. There are 492 triples: all combinations of0, 1, 2, 5, 0x7fffffff, 0x80000000, 0xfffffffe, 0xfffffffffortmpanddata, withdata2in0, 3, 0xffffffff, plus 300 random. RDNA2 desktop silicon, not the console's. No game data.ds_inc_rtn_u32tmp >= data ? 0 : tmp + 1ds_dec_rtn_u32tmp == 0 || tmp > data ? data : tmp - 1ds_rsub_rtn_u32data - tmpds_mskor_rtn_b32(tmp & ~data) | data2ds_wrap_rtn_b32tmp >= data ? tmp - data : tmp + data2global_atomic_csub(same op asbuffer_atomic_csub)tmp >= data ? tmp - data : 0csubran on 364tmp/datapairs in device memory (in host-coherent memory the atomic does not take effect, so don't be surprised if a test on such memory shows nothing). The 64-bit forms and the sub-dword buffer accesses were not probed.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.
@r4tedx on GitHub · 2026-11-24 06:27 UTC · original
@Lyrnc thank you. That is the check this PR could not do for itself: its GPU tests compare the translation against CPU references written from the same ISA text, so they cannot catch a misreading of the text. Six of the definitions now have 492 (364 for
csub) agreeing triples on RDNA2 silicon behind them, including that the_rtnforms return the old value.I have put the result in the description under "Not verified", with what it leaves open as you state it: the 64-bit forms, the sub-dword buffer accesses, and that it is desktop RDNA2, not the console's.
Your note on host-coherent memory is useful for anyone writing such a probe; nothing in this PR depends on it.
Nothing was run for this note. AI-assisted.
@DeerSilver on GitHub · 2026-11-24 10:51 UTC · original
Tested head
141fde5merged ontomainffe310eon NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only.Merged onto current
main, the test build fails.6638098("per-lane descriptors chosen by control flow", merged with #566 at 09:53) added a fourth argument toresource::track:There's no text conflict, so GitHub still shows the PR as mergeable, but merging it as it is would break
cargo testonmain. The call this PR adds needs the fourth argument.main's own tests passSome(&st);Nonekeeps the old three-argument behaviour.With
, Noneadded locally to that one call, everything passes:memory_opcode_refusalsis#[ignore]as committed):lds_integer_atomic_updateslds_64_bit_atomics_share_the_dword_allocationlds_paired_exchangesbuffer_bytes_and_halvesbuffer_integer_atomic_updatesbuffer_64_bit_atomicsbuffer_concurrent_byte_storesstructured_buffer_memory_uses_index_and_member_offsetglobal_and_scalar_loads_through_root_viewscargo test --workspace --locked: 351 passed, 0 failed, 7 ignored, against 342 passed / 6 ignored onmain.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.AI-assisted (Claude Code).
@r4tedx on GitHub · 2026-11-24 11:02 UTC · original
@DeerSilver, fixed in
e469b7cagainstmainatffe310e. The memory test helper already builds the structured control flow, so it now passesSome(&st)toresource::track, matching the other emitter tests.cargo test --workspace --lockedpassed locally (351 passed, 7 ignored), andcargo clippy --workspace --all-targets --locked -- -D warningspassed. Thanks for catching the break on the merged tree.AI-assisted (Codex).
@Marvisak on GitHub · 2026-11-25 00:19 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/host.rs,crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/memory_tests.rs,crates/victory-shader/src/emit/mod.rs,crates/victory-shader/src/emit/shader.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@r4tedx on GitHub · 2026-11-25 04:38 UTC · original
Closing this. The change is not wrong; this title does not use the forms it adds, and bringing it up to
main(319 commits on, conflicting in five files) would clear no program.The numbers. Local title data (v1.0.2.1, the main shader archive), offline, CPU only; counts and reasons only.
main's own binary at940d32f(shader-info --disasm) over the archive's 26,503 shader containers. All 26,084 programs in it decode, so the pass sees every instruction. None of the forms this PR adds occurs:inc,dec,rsub,mskororwrap_rtn, and no 64-bit atomic (arithmetic, min/max, bitwise, compare-store, exchange);sub,inc,decorcsub, and no_x2atomic.global_load_ushort(2 containers), and each occurs in programs that validate onmain.main: 16-bit LDS reads and writes (ds_read_u16in 15 containers,ds_write_b16in 10, and theird16_hiforms), plain 64-bit LDS writes (ds_write_b64190,ds_write2_b64195), the formatted D16 buffer loads and stores (38, 37 and 65 containers), and the 32-bit buffer atomics, signed min/max, swap and compare-swap included.main940d32f(translate --validate --list, 25,889 programs counted): 23,918 validate; the translator refuses 298, under 10 reasons. None names an atomic or a sub-dword access.main: 0 gained, 0 lost.Limits. The pass covers that one archive, not shaders anywhere else in the title. It did not look at the scalar
s_load_*loads this PR also routes through traced root views; for those I only have the count, where no refusal names them. A refused program reports only its first reason, so for the forms the title does use, a refused operand form could still sit behind another reason in the programsmainrefuses at emit; by instruction name there is none.The branch
shader/memory-formsstays on the fork at825dbd9; if a program that needs one of these forms turns up, in this title or another, I will reopen this on currentmain.Thank you @Lyrnc for checking the LDS atomics and
csubagainst RDNA2 hardware, @DeerSilver and @DaviTostes for the test runs, and @EduAzevedo for the count that first showed it gains nothing here.AI-assisted
Pull request closed