Shaders: MUBUF sub-dword loads (buffer_load_ubyte, sbyte, ushort, sshort and the d16 forms) #1572
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!1572
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1572/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?
@iurysf on GitHub · 2026-11-24 19:19 UTC · original
iurysf:mubuf-sub-dword-loads→main· +180 −2 · 2 files · 1 commits · closed without mergingWhat'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.
_d16and_d16_hiloads #2003@geiyiliyabumo on GitHub · 2026-11-24 19:32 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 00:42 UTC · original
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