Shaders: buffer loads of a table in the program's code #2084
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!2084
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2084"
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?
@rminzao on GitHub · 2026-11-25 04:31 UTC · original
rminzao:shaders-buffer-loads-through-code-tables→main· +404 −1 · 3 files · 3 commits · openClaimed in #1633 (claim).
Problem
A
buffer_load_*through a V# whose base is built arounds_getpc_b64(a constant table after the program's code) is refused:a descriptor built around a table in the code is not supported. #815 lists 20 upscaler compute programs failing on it. Scalar loads (s_buffer_load_dword*) andglobal_load_*of the same kind of table already read it throughcode_dword; only the VMEM buffer form falls through tohandle().Change
In
Lower::buffer, a load whose source is aSource::Builtdescriptor withaddress.param == CODEreads its dwords withcode_dword, at base +offset+offenVGPR +soffset+ (idxen? index × stride : 0), and extracts bytes/halfwords asflat()does. Out of range, it reads 0, per the V#'sOOB_SELECT(dword 3 bits 28-29):index >= num_recordsnum_records == 0offset + soffset + size > num_records, each dword of a multi-dword load checked on its own;index * stridemoves the address but is not checkedThese are the rules measured on RDNA2 (gfx1036) and RDNA1 (gfx1011) hardware by the Leonida project (its
docs/buffer_bounds.md, 732 cases; they match Mesa's GFX11 column ofac_descriptors.c, withsoffsetcounted), which this tree already cites for other measurements.code_dwordalone clamps to the table, which is not what the hardware returns.Still refused, each with its own reason: stores, atomics and typed loads of a code table; swizzled V#s or
ADD_TID_ENABLE;OOB_SELECT0 (whether the instruction offset counts in its stride check is unmeasured).Tested
Intel UHD Graphics (driver 31.0.101.4146), RTX 4050 Laptop (595.97) and WARP, Windows 11.
emit::memory_tests::code_table_buffer_loads_lower: the hand-assembled program decodes to the expected text, lowers and validates; anOOB_SELECT0 V# is refused. Onmain940d32fthis test fails with the refusal above.emit::memory_tests::code_table_buffer_loads_read_zeros_out_of_range: 32 lanes read a 64-dword table afters_endpgm, compared per lane with a CPU model:buffer_load_dword offen(lanes 29+ read 0),buffer_load_ubyte offen offset:1(lanes 30+, so the size counts),buffer_load_dwordx2withsoffset4 (lane 27 gets one dword and a 0), andbuffer_load_dword idxen offset:4with stride 8 and 21 records (lanes 21+). Passes on all three adapters (the RTX 4050 through a local, uncommitted switch of the test host to the high-performance adapter). With the zeroing turned off it fails.cargo test -p victory-shader --libon the Intel UHD: 240 passed, 9 failed;maingives 238 passed and the same 9 failures (all covered by other open PRs; see #1829).cargo clippy -p victory-shader --all-targets -- -D warnings, with and without--all-features: clean.rustfmt --check: no diffs in the new hunks.cargo xtask policy: ok.Not run: the title or the #815 programs themselves, and AMD hardware. The console part (gfx1013) is unmeasured; the rules hold on gfx1011 and gfx1036.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
A buffer load through a descriptor built around s_getpc_b64 was refused ("a descriptor built around a table in the code"), though scalar and global loads of the same tables already read them. Read the dwords from the code too, at base + offsets + index * stride, and give 0 where the descriptor's range check (OOB_SELECT 1-3) puts the access out of range, per dword for multi-dword loads. Stores, atomics, typed loads, swizzled descriptors and OOB_SELECT 0 stay refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>@jeremygold02 on GitHub · 2026-11-25 04:44 UTC · original
Triage verdict — Keep the VMEM code-table path, cover unaligned subword reads (
0077404)Evidence
main. Untyped VMEM loads can now read through the same code-table helper. The submitted fixtures cover raw and structured bounds, including a partially out-of-bounds multi-dword read. New lowering · Bounds fixtureChecks and limits
Next step
This verification was AI-assisted.
@sinan-cmyk on GitHub · 2026-11-25 09:03 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head 0077404b onto
main940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 10:32 UTC · original · edited 2026-11-26 02:16 UTC
Automated triage for the maintainers.
Merge candidate.
36d0a30is rebased and merges cleanly. InLower::buffer(crates/victory-shader/src/emit/lower.rs), an untyped load through aSource::Builtdescriptor atCODEnow goes tocode_table_buffer_load(newemit/lower/code_table.rs), which reads the dwords with the existingcode_dwordand appliesOOB_SELECT1/2/3 as the PR body describes (the offset checked for mode 3 already includesoffset,offenandsoffset, as built earlier inbuffer). Stores, atomics, typed loads, swizzled/ADD_TIDdescriptors andOOB_SELECT0 stay refused with their own reasons. The halfword at byte 3 now takes its high byte from the next dword; I checked the shift ((next << 1) << (31 - sh)is 0 atsh = 0andnext << 8atsh = 24), and the fixture covers it. The bounds rules cite hardware measurements and Mesa. CIcheckpasses, including the policy check now that the code moved out oflower.rs.On your replies: the boundary fix and the file-size correction match the diff; thanks for the follow-up.
Generated by Claude Code
@rminzao on GitHub · 2026-11-26 01:43 UTC · original
Rebased onto
main(63bcca4) and pushedb6d6be6, which handles the halfword boundary @jeremygold02 raised.A halfword at byte 3 of a dword now reads both bytes it spans: its high byte comes from the next dword. It ORs in
(next << 1) << (31 - shift), which isnext << (32 - shift)and 0 at shift 0, with no shift by 32. A byte can't cross, so it is unchanged. The bounds check was already per field (offset + 2 <= records), so a halfword whose second byte is past the records reads 0.The fixture adds
buffer_load_sshort v8, v1, s[12:15], 0 offen offset:3to every lane. That is a signed halfword across the dword boundary, and lane 29 is pastRAW_RECORDS.code_table_buffer_loads_read_zeros_out_of_rangematches the model on the Intel UHD, the RTX 4050 Laptop and WARP. With the new arm disabled it fails.Also dropped the comment's attribution of the
OOB_SELECTvalues. Thememory_tests.rsconflict was only the two branches' new tests both appended at the end.cargo test -p victory-shader --libon the Intel UHD: 293 passed, 11 failed, the same 11 asmain. Clippy andcargo xtask policyare clean.AI-assisted (Claude Code).
@rminzao on GitHub · 2026-11-26 01:45 UTC · original
Correction to the comment above:
cargo xtask policywas not clean. On currentmainthis PR putlower.rsat 525,127 bytes, past the 512 KiB limit, and CI failed onrepository_passes_policy.36d0a30moves the code-table load unchanged toemit/lower/code_table.rs, solower.rsis now 521,884 bytes. Policy, the xtask tests and clippy are clean, and the code-table tests pass on the Intel UHD and WARP.AI-assisted (Claude Code).
@DenRakEiw on GitHub · 2026-11-25 04:36 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib emit::memory_tests::— 5 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1(including the new code-table buffer load tests)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean lowering for buffer loads reading from a constant table embedded in the program's code, verified end-to-end on hardware and WARP. Looks good.
AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 05:09 UTC · original · approved these changes
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. Buffer loads of a table in the program's code — program-code table loads; relates to #2068's table-constant SRV fallback.
@fuzeofficlal on GitHub · 2026-11-26 17:05 UTC · original · approved these changes
Reviewed
36d0a303dd670928f9c82e09136a92bbc32fbd36(merged cleanly onto63bcca43) and verified on Windows 11 with an RTX 5090, WARP,dxil.dll, andVICTORY_D3D12_DEBUG=1.Moving the VMEM code-table load helper into
emit/lower/code_table.rskeepsemit/lower.rsgrowth small (521,884B,2,404B under the 512 KiB cap), cleanly separates descriptor base (base+extra) from instruction offsets (off+index * stride), and handles unaligned split 16-bit halfword shifts ((next << 1) << (31 - sh)) without shifting by 32.Non-blocking follow-up notes:
OOB_SELECT = 3,lower.rs:9438-9463folds*offset,OFFEN, andSOFFSETwith 32-bitBin::Addbeforecode_table_buffer_load, so a wrapping combination like VGPR offset0xffff_fffc+SOFFSET = 4arrives as0and bypasses the unsignedIULEcheck; preserving carry or checking components separately would close that wraparound edge case.OOB_SELECT = 2(empty and non-emptyNUM_RECORDS), dynamic descriptor base, and an explicit error when aCODEleaf appears inside aPhi/Selectwould broaden coverage further.Verification
xtask policy(192 files ok),cargo clippy(default &--all-features) clean,code_table.rsrustfmt-clean.dxil.dll+VICTORY_D3D12_DEBUG=1:code_table_buffer_loads_lowerandcode_table_buffer_loads_read_zeros_out_of_range(2/2 passed),emit::census_tests(1/1 passed), and the remainingemit::memory_tests(6/6 passed, skipping the pre-existingmain#2571crash inheap_direct_texture_reads_mark_their_heap_index).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.