Shaders: LDS reads and writes of a byte or half #632
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!632
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/632/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?
@itsRevela on GitHub · 2026-11-24 05:57 UTC · original
itsRevela:shaders/lds-bytes-halves→main· +241 −6 · 2 files · 1 commits · closed without mergingWhat
LDS accesses of a byte or a half, which stopped translation with
an LDS write of bytes or halves/an LDS read of bytes or halves:ds_write_b8,ds_write_b16,ds_write_b8_d16_hi,ds_write_b16_d16_hi: write only their part of the dword. The_d16_hiforms write the data's high half. An atomicANDclears the part, then an atomicORsets it, so lanes writing the other parts of the same dword keep theirs.ds_read_u8,ds_read_i8,ds_read_u16,ds_read_i16: load the dword, shift the part down, and zero- or sign-extend it.d16reads (ds_read_u8_d16,..._d16_hi, ...) are still refused. They write half of the register and keep the other half, and the IR records a DS destination as written only, never read. They now fail withan LDS read into half a register.As for whole dwords, addresses are taken as aligned to the access size.
Tests:
emit::valu_tests:build_valu_csgains an LDS-size variant (build_cs) and a DS encoder, andrun_casesa variant that takes the hosts to run on (run_cases_on).Why
In the opening cutscene, 2 programs per run stopped at these instructions; one of them has one
ds_write_b16and nineds_read_u16, so writes alone would only have moved the failure to the reads. Each dropped about 130 draws a frame. I found no issue or PR covering them.One semantic difference: if two lanes write different values to the same byte in one instruction, the clear/set pair can leave the OR of the values, where the hardware keeps one lane's value. Lanes writing different bytes or halves of one dword (byte arrays, packed halves) give the hardware's result exactly.
Tested
Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 3070 Ti (driver 32.0.16.1088), Rust 1.98.1, on
d2a4bae.New
emit::valu_tests::lds_bytes_and_halves_match_rdna2(real GPU). A one-thread program writes a dword to LDS, then:Results are checked against expected values on three input sets, with sign bits set and clear. It runs on hardware only: WARP refuses the compute pipeline of any program with LDS from this harness, a plain
ds_write_b32/ds_read_b32one too, so that's not new here.New
emit::lower::tests::lds_bytes_and_halves_lowerandlds_reads_into_half_a_register_are_refused. They need no GPU, so CI runs them.The fix matters. All three new tests fail with the two new branches replaced by the old refusals.
Crate checks:
cargo test -p victory-shader: 72 passed.cargo clippy -p victory-shader --tests: nothing in the changed files.cargo fmt -p victory-shader --check: clean.cargo xtask policy: ok.With the title (
diagbuild, Windows Sandbox vGPU): both programs that failed onmaintranslate. The run logs no LDS byte or half failures; untranslated programs went from 382 to 376 and translated ones from 1,634 to 1,647, with run-to-run variation.AI-assisted (Claude Code). The title runs used my own copy; no game data is in this PR.
🤖 Generated with Claude Code
@slint6614-dev on GitHub · 2026-11-24 07:47 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate, against maind2a4bae(emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.image_sample_o,image_sample_d_cl, the 108 biased 16-bit samples and the 573 "scalar memory read as data", but those mostly move to other reasons ("a descriptor's address or format read as data" 71 → 595, "an image address" 2 → 27), and the signature mismatches go 21 → 29 (input) and 25 → 26 (output).cargo test -p victory-shader --releasecrashed withSTATUS_ACCESS_VIOLATIONin 2 of 6 parallel runs (0 of 6 on main;--test-threads=1always passes, 76 tests). Possibly a race in one of the new tests.@catminou4 on GitHub · 2026-11-24 11:04 UTC · original
Triage note: this overlaps two other open PRs for the same feature — sub-dword LDS accesses (
ds_read_{u,i}{8,16}/_d16/_d16_hi,ds_write_b{8,16}/_d16_hi):cargo test -p victory-shader --lockedis green on the merged tree (macOS arm64, rustc 1.98.1).ir.rs/mod.rs/lds_tests.rs; currently conflicts with main (mergeable=false).This PR (#632) also conflicts with main. Three competing implementations of the same lowering — whichever the maintainer picks, the other two will need rebases. No objection to the approach itself; flagging so the overlap is visible before review time is spent three times.
@Marvisak on GitHub · 2026-11-25 00:26 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Byte and half LDS accesses are in main's ds(), including the d16 reads this PR still refuses.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed