Shaders: MUBUF sub-dword loads (buffer_load_ubyte, sbyte, ushort, sshort and the d16 forms) #1571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1572"
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?
Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T19:19:33Z.
What's wrong
Lower::buffer()refuses every MUBUF load narrower than a dword, so the program is dropped. One of the world's busiest computes,28918b7150a7aad5(575 to 848 dropped dispatches per frame in our RTX 4070 runs of the open world), reads packed 16-bit fields through a raw root UAV:With main + #489 + #1077 the program gets that far and stops there (#1077 lists
buffer_load_ushortamong what is left).What the fix does
Source: AMD RDNA2 ISA, MUBUF loads
(https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf):
buffer_load_ubyte/sbyte/ushort/sshortzero- or sign-extend the field at the byte address to 32 bits;*_d16/*_d16_hiwrite one half of the VGPR and keep the other.off & ~3), shift it right by(off & 3) * 8.shl+lshr/ashrby32 - width._d16: merge with the register's old value (old & 0xFFFF0000 | x & 0xFFFF, orold & 0xFFFF | x << 16for_hi).rawBufferLoads. A constant buffer is still refused ("a sub-dword read of a constant buffer").115 lines in
lower.rs, 65 of test.How it behaves after
Offline,
translate --list --validate(dxil.dll 1.9) on28918b7150a7aad5:Test:
sub_dword_buffer_loads_read_the_field_at_the_byte_addressruns all ten opcodes on every byte of two stored dwords (offsets 4..=11; halfwords 4..=10, including the one at byte 7 across both dwords), on hardware (RTX 4070) and WARP. The harness UAV grows from 1 to 4 dwords so a shader can write and read back.cargo clippy --workspace --all-targets -- -D warningsis clean,cargo test --workspacepasses (victory-shader: 121 passed, 1 ignored),cargo xtask policyis clean.Overlap
#164 also lowers these loads, as part of a larger change (integer memory atomics and sub-dword buffer accesses, about 1.6k lines). This PR is only the MUBUF load part, so it can be reviewed on its own. If #164 lands first, this one can be closed.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T19:30:32Z.
Review: APPROVED
Verified locally merged onto
origin/main(Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib sub_dword_buffer_loads_read_the_field_at_the_byte_address— passed on RTX 5090 hardware and underVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— okClean lowering of MUBUF sub-dword loads (
buffer_load_ubyte/sbyte/ushort/sshortandd16forms) with end-to-end GPU+WARP verification. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T19:32:00Z.
Verified commit
0c16661on Windows 11 / AMD Radeon RX 9060 XT (RDNA4,gfx1200, SM 6.6) + WARP:cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (including the new MUBUF sub-dword andd16load GPU tests).AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:42:41Z.
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.buffer_load_ubyte/sbyte/ushort/sshort (and byte/short stores) are lowered in main (lower.rs 8344-8357); only the MUBUF _d16 variants might be left. Same topic as #164 #1536.
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