Shaders: lower sub-dword LDS reads and writes #101
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!101
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/101/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?
@Yaekai on GitHub · 2026-11-24 00:30 UTC · original
Yaekai:feat/shader-lds-subdword→main· +192 −33 · 1 files · 2 commits · closed without mergingLower byte and 16-bit LDS reads and writes in
crates/victory-shader/src/emit/lower.rs:ds_read_u8,ds_read_i8,ds_read_u16,ds_read_i16, and the_d16/_d16_hivariants): load the enclosing 32-bit LDS dword (addr >> 2), shift by the byte/half offset within the dword, zero- or sign-extend to 32 bits, and for_d16/_d16_hipreserve the untouched half of the destination VGPR (vialow_half/ newhigh_half).ds_write_b8,ds_write_b16,ds_write_b8_d16_hi,ds_write_b16_d16_hi): extract the source byte/halfword and update the enclosing 32-bit LDS dword with atomicAnd(clear mask) followed by atomicOr(shifted value) inside the execution guard so concurrent lanes writing adjacent bytes or halves within the same 32-bit dword do not race.Verification
cargo test -p victory-shader— 57/57 passed.rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower.rs— clean.victory translate --validateonshaders.rpf(26,084 programs): cleared all 9an LDS write of bytes or halvesand all 7an LDS read of bytes or halvesfailures, increasing emitted &dxil.dll-validated compute shaders from 1,693 → 1,709 emitted and 1,670 → 1,686 validated (+16/16 validated, 0 new validator errors), including live world compute shadergrass_batch_floating_veg_tess:MSTS_VS_Transform_AddWaterSurfaceDelta_e4f46870_Wrapped.@Raxstreams on GitHub · 2026-11-24 00:34 UTC · original
Testing this right now, I ran into the same bug
@DaviTostes on GitHub · 2026-11-24 00:36 UTC · original
Tested
c78ccf7stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).cargo test --workspace: 155 passed, 0 failed, 3 ignored; merge with #39 clean.AI-assisted (DeepSeek V4.1 Flash coding agent).
@Raxstreams on GitHub · 2026-11-24 00:36 UTC · original
This made it further but I'm still not getting a world render but the PR is sound.
@DaviTostes on GitHub · 2026-11-24 00:50 UTC · original
Follow-up after looking at the rest of the queue:
crates/victory-shader/src/emit/lds_tests.rs(434 lines) with it; this branch adds no#[test]s. Whichever of the two goes in, the other should be closed so the author's work is not repeated.git diff main pr-101removes 209 lines fromcrates/victory-loader/src/crash.rs(the CLWB handler). Merging keeps main's version, but the PR as displayed should be rebased so reviewers see only the LDS change.cargo test -p victory-shaderon this head is green on Linux if the crate builds alone; in the full workspace thevictory-gpuE0425 still needs #112. Stacked on #39 earlier it was 155 passed / 0 failed (no new tests).No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
@Yaekai on GitHub · 2026-11-24 02:31 UTC · original
Thanks @DaviTostes! Rebased cleanly onto
d2a4baeand addedlds_subdword_reads_and_writes_lowerin4baaee7covering odd-offset byte/halfword writes and all sub-dword read /_d16/_d16_hivariants (cargo test -p victory-shader: 71/71 passed).@ghost on GitHub · 2026-11-24 05:50 UTC · original
Review note on head
4baaee7: fords_read_*_d16/_d16_hi,low_half(crates/victory-shader/src/emit/lower.rs:5290) keeps the destination's other half by reading its old value withinst.read(Reg::V(reg)), and falls back to 0 when that isNone.On
main,ir.rseffects()(theFields::Dsarm, around line 842) adds ads_readdestination only to the written registers, andInst::readonly searches the read list. So for these readsinst.readis alwaysNoneand the kept half is always zeroed: a_d16read clears the high 16 bits, a_d16_hiread clears the low 16.#116 fixes this in
effects():This PR would need the same, plus a test that writes a known value to the destination first and checks the other half survives.
Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and
mainatd2a4bae. Context: the triage in #366.@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.@alexdeliu on GitHub · 2026-11-24 17:22 UTC · original
Merged onto
main@ffe310eb, this PR (9fbd7e9f) no longer compiles its tests.crates/victory-shader/src/emit/lower.rs:7471callsresource::trackwith 3 arguments. Since6638098cit takes a 4th,lanes: Option<&Structured>; main's tests passSome(&st)withlet st = structure::structure(&p).unwrap();.Checked with CI's steps (both clippy runs with
-D warnings,cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87@fuzeofficlal on GitHub · 2026-11-24 17:28 UTC · original
Reviewed
9fbd7e9and ran sub-dword LDS roundtrip + cross-lane exchange tests on NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics iGPU, Microsoft D3D12 WARP, anddxil.dll(VICTORY_D3D12_DEBUG=1).Found three issues — including a silent 16-bit odd-byte / cross-dword truncation bug — and verified a clean 32-bit fix on top of
9fbd7e9infuzeofficlal/VIctory@5b98cf2(branchfix/sub-dword-lds-d16-101):at & 3 == 1) and cross-dword (at & 3 == 3) truncation (emit/lower.rs:2204, 2264):let lane_mask = self.s.m.i32(if bytes == 1 { 3 } else { 2 });masks bit 0 off 16-bit byte addresses:at % 4 == 1,ds_read_{u16,i16}*/ds_write_b16*read or overwritebytes[0..2]instead ofbytes[1..3].at % 4 == 3, RDNA2 hardware spans the high byte oflds[index]and the low byte oflds[index + 1](reading0/ dropping writes past the end of LDS), whereas& 2rounds back tobytes[2..4].off_in_word = at & 3plus a pure 32-bitbegin_guarded(Some(off_in_word == 3 && index + 1 < lds_dwords))block forbytes == 2handles bothbyte 1andbyte 3accurately without enablingflags::INT64or issuing extra atomics on aligned accesses.ds_read_*_d16/_d16_hi(ir.rs:843):regs(d, &mut r)?whenname.starts_with("ds_read") && name.contains("_d16")documents the untouched-half read dependency directly on the instruction rather than relying only on the trailing implicitEXECvector destination read.#566(emit/lower.rs:7471):lds_subdword_reads_and_writes_lowerneedslet st = structure::structure(&p).unwrap();passed as the 4th argument toresource::track(&p, &native.layout, native.stage, Some(&st)).Verification (
5b98cf2)dxil.dllvalidation + container hash check: passedds_write_b8/ds_write_b16+ chainedds_read_u16_d16/ds_read_u16_d16_hi+ odd-offset (1,3,511end-of-LDS) roundtrip tests withVICTORY_D3D12_DEBUG=1(0debug layer errors):Pull request closed