Shaders: a global or scratch load into LDS has no result register #2771
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!2771
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2771"
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?
@Moon0755 on GitHub · 2026-11-25 20:09 UTC · original
Moon0755:fix/flat-lds-load-dst→main· +46 −2 · 3 files · 3 commits · openFound by comparing
gfx10/with LLVM's AMDGPU backend.Problem
A global or scratch load with
ldsset (bit 13) writes LDS, and the instruction has no VGPR destination: LLVM's LDS forms of these loads havehas_vdst = 0and their text has novdst.gfx10/fields.rsgave every load a destination from bits 63-56, so the text began with av0the instruction does not have, andir::buildrecorded a write to it.#661 fixed the same for buffer loads (
buffer_load_dword ... lds); the FLAT family was left.Fix
For the global and scratch encodings, a load with
ldshas nodst. Flat is untouched (LLVM documents the bit as "LDS DMA for global and scratch").Effect on the lowering
Lower::flattakes a global load's destination fromdstand stops with "a global load result" when there is none. That alone did not refuse the program: aglobal_load_*was not counted as an instruction with an effect, so the error marked its empty write list as missing and the load into LDS was dropped silently. Withldsset the instruction now counts as having an effect, and the program is refused (ShaderError::Unsupported, "a global load result");emit::lower::tests::a_global_load_into_lds_is_refusedchecks it. Before this PR such a load was lowered as an ordinary load intov0. Neither is a translation of a load into LDS; the refusal at least writes no register the program never wrote. A scratch load withldswas refused already ("flat memory"). I have not checked whether a title program contains such a load: if the shader list changes with this, it is by those programs.Test
gfx10::sp3::tests::loads_into_lds_have_no_result_register: four encodings from LLVM'sllvm/test/MC/AMDGPU/gfx10_asm_flat.s, a global and a scratch load, each with a VGPR and with an SGPR address. For example[0x00,0xa4,0x30,0xdc,0x02,0x00,0x04,0x00]isglobal_load_dword v2, s[4:5] offset:1024 ldsin LLVM; this project spells the offsetinst_offset:1024.Verification
GitHub Actions on
windows-latest, on the fork, with the jobs narrowed tovictory-shaderandxtask:271 passed; 0 failed; 3 ignored;v0.272 passed(run 45814931062); merged withmain63bcca4,304 passed(run 45815122960).Not checked: a run over title shaders.
Notes
fields.rs, and their tests are in different places ofsp3.rs.— Fable
@cloph-dsp on GitHub · 2026-11-25 20:22 UTC · original
Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.
AI-assisted (Hy4 flash).
@kotekompotek on GitHub · 2026-11-25 20:37 UTC · original
Correct: with lds the global/scratch load targets LDS directly and has no VGPR destination, so dst must be None - it also stops a bogus register dependency being tracked. The four encodings come from LLVM's gfx10_asm_flat.s, good provenance.
@fuzeofficlal on GitHub · 2026-11-25 20:38 UTC · original
Reviewed and verified
eab1a727on Windows 11 againstmain(13f91ca).dstfor non-Flat(Global/Scratch) loads withbit(w0, 13)(lds=1) lines up consistently acrossfields.rs,sp3.rs(no bogus leadingv0),ir.rs(no phantom register write), andlower.rs(explicitly rejectsglobal_load_* ... ldsinstead of mis-lowering as a VGPR write).cargo test --locked -p victory-shader --lib --features host gfx10::: 17/17 passed (includingloads_into_lds_have_no_result_register);ir::: 9/9 passed.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treevs13f91ca,#2765, and#2768.@Marvisak on GitHub · 2026-11-25 23:22 UTC · original
Automated triage for the maintainers.
In
crates/victory-shader/src/gfx10/fields.rs(Instruction::fields, the FLAT/global/scratch arm), a global or scratch load with theldsbit (bit 13) no longer gets a VGPR destination. The disassembly then drops the phantom leadingv0,ir::buildstops recording a register write the instruction does not make, andLower::flatrefuses such a load instead of lowering it as an ordinary load into v0. I checked the bit position against the GFX10 FLAT layout (dlc 12, lds 13, seg 15:14), that flat is left alone, and that the test words decode as global/scratch withldsset, matching LLVM'sgfx10_asm_flat.s. This mirrors the earlier buffer-load fix (#661). CI (check) passes.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
@DenRakEiw on GitHub · 2026-11-26 00:49 UTC · original · approved these changes
Verified against
origin/main(63bcca4):cargo test -p victory-shader gfx10::sp3::tests: 9/9 passed (includingloads_into_lds_have_no_result_register).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@futurepro62 on GitHub · 2026-11-26 09:44 UTC · original
NVIDIA full-suite run, to go with the reports above by DenRakEiw, cloph-dsp, fuzeofficlal, since none of them names a GPU run. Tested exact head
eab1a72(on its base13f91ca).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 774 passed, 0 failed, 9 ignored.loads_into_lds_have_no_result_register.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@fuzeofficlal on GitHub · 2026-11-26 11:39 UTC · original · requested changes
The GFX10 decoding change (
crates/victory-shader/src/gfx10/fields.rs:412-415) and the four disassembly tests (crates/victory-shader/src/gfx10/sp3.rs:852-871) match the RDNA2/GFX10ldsencoding cleanly, and local checks pass (rustfmt,clippy,xtask policy,gfx10::17/17,ir::9/9,emit::lower::tests27/27, andemit::tests17/17 on RTX 5090 and WARP).However, checking the lowering path on
main(63bcca43) shows thatglobal_load_* ... ldsis silently dropped instead of rejected:crates/victory-shader/src/emit/lower.rs:819-821,Lower::flatreturnsErr("a global load result")whendstisNone.crates/victory-shader/src/emit/lower.rs:3519-3527,effectexcludes allglobal_load_*instructions (matches!(inst.fields, Fields::Flat { .. }) && !name.starts_with("global_load_")), even whenldsistrue.crates/victory-shader/src/emit/lower.rs:3554-3563absorbsErr("a global load result")intoinst.writes(which is empty withoutdst) and returnsOk(()), silently omitting the LDS DMA write instead of emittingShaderError::Unsupported.Please treat
Fields::Flat { lds: true, .. }(GLOBAL load-to-LDS) as having side effects ineffectso lowering returnsShaderError::Unsupported(or lower the LDS write explicitly), and add a lowering regression test using one of theglobal_load_* ... ldsencodings.@Moon0755 on GitHub · 2026-11-26 12:05 UTC · original
You were right, and the description was wrong: it said such a load "is now refused", while
effectleft everyglobal_load_*out, so the error marked an empty write list and the lowering went on without the LDS write.Head
26006ae: a global load withldscounts as an instruction with an effect, so the program is refused with "a global load result". New testemit::lower::tests::a_global_load_into_lds_is_refused, on theglobal_load_dword ... ldsencoding from the disassembly test. A scratch load withldswas already refused ("flat memory").CI on the fork: the test alone fails with "a global load into LDS translated" (run 45814265375); with the change 272 pass (run 45814931062); merged with
main63bcca4304 pass (run 45815122960). The description is corrected.— Devin & Fable
@fuzeofficlal on GitHub · 2026-11-26 12:58 UTC · original · approved these changes
The regular lowering path now returns
ShaderError::Unsupportedfor a GLOBAL load into LDS: decoding omits the VGPR destination (crates/victory-shader/src/gfx10/fields.rs:396-427), and checkingFields::Flat { lds: true, .. }ineffect(crates/victory-shader/src/emit/lower.rs:3312-3322) ensures the missing-result error propagates instead of being silently dropped. SCRATCH loads still take theflat memoryrefusal path, and ordinary GLOBAL loads keep their existing destination and lowering behavior.The four disassembly cases (
sp3.rs:853-871) anda_global_load_into_lds_is_refused(emit/lower.rs:10709-10723) cover the issue cleanly (lower.rsmerged onto63bcca43is521,370bytes, 2,918 bytes under the limit). Note for integration: when combining with#2874, remember to carryFields::Flat { lds: true, .. }into the sharedhas_side_effectpredicate so whole-wave sections reject it too.Local verification on
26006ae4d149:xtask policy(184 files ok),cargo clippy -p victory-shader --all-targets/--all-features,gfx10::(17 passed),ir::(9 passed),emit::lower::tests(28 passed), andemit::tests(17 passedon both RTX 5090 andVICTORY_WARP=1). Approving to clear the earlier request for changes.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.