mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:30:53 +01:00
[PR #1068] [CLOSED] rdna2spirv: form MUBUF byte offsets in 64 bits (SHADER-MUBUF-OFFSET-WRAP) #1107
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1107
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1068
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:split/shader-mubuf-offset-wrap📝 Commits (1)
a656d4frdna2spirv: form MUBUF byte offsets in 64 bits (SHADER-MUBUF-OFFSET-WRAP)📊 Changes
4 files changed (+212 additions, -26 deletions)
View changed files
📝
docs/buffer_bounds.md(+5 -0)📝
docs/design.md(+1 -1)➕
tests/semantic/test_buffer_offset_wrap.py(+173 -0)📝
tools/rdna2spirv.py(+33 -25)📄 Description
Claimed in the coordination issue as: SHADER-MUBUF-OFFSET-WRAP (claim).
Part of the split of #984 (first child). Depends on: none. Overlaps: none found (searched open and merged pull requests for
buffer_address, stride, index and offset wrap; #513 changes the CBV's V# stride in the runtime, not the translator's address arithmetic; #1021 editsdocs/design.mdnear the swizzled-buffer row).What and why
Gen.buffer_addressintools/rdna2spirv.pyforms the byte offset of every MUBUF/MTBUF access,off + soffset + index * stride(and the swizzled form), in 32 bits and adds it to the 48-bit V# base. The hardware does not wrap there: the RDNA2 ISA (8.1.5) gives the address as base + stride * index + offset with a 48-bit base, and onlyoff(vaddr + inst_offset) wraps at 32 bits. So an index of0xFFFFFFFFwith a 20-byte stride addresses base + 0x13_FFFF_FFEC on the console, while the translated shader turns it into base − 20:OOB_SELECT 3(raw) checksoffset + soffsetagainstNUM_RECORDSand does not look at the index;OOB_SELECT 2(disabled) checks only that the buffer is not empty.Both let the wrapped access through, so a store writes 20 bytes below the buffer and a load reads them. When the view is one slice of a larger pool that is mapped as a whole, that is a silent write into a neighbour's records.
The change forms the linear and the swizzled offset as a 64-bit value and adds that to the base. Nothing else changes: each mode checks exactly what it checked before, and a literal V# and a run-time V# take the same path.
What changed since the first version
The first version also treated every offset above
0xFFFFFFFFas out of range. The reviews showed two faults in that, and both are fixed by removing the bound instead of patching it:What this does not do
docs/d3d12_vulkan.md), so there an offset of 4 GiB or more always leaves the arena. Whether the runtime should refuse an address outside the arena is a separate decision, with the arena size as the bound and not 2^32. It is not part of this pull request.b9b57e2), credited in the source. It was not measured by us on AMD hardware; the contract row anddocs/buffer_bounds.mdsay so. Someone with thetools/hw_oraclesetup could pin it with one probe (raw view, stride 20, index −1).Cost: two or three 64-bit conversions and adds and one 64-bit multiply per access, now for every access including folded structured views (the first version left those alone). On a sample of 200 compute programs of a retail library (translated locally with
--wave64-emulate, not included) 114 modules change and the 200 grow by 0.45 % together; all 200 passspirv-valbefore and after.Tested
Linux (CachyOS, kernel 7.3.5), Python 3.14, LLVM
llvm-mc23.1.5 and SPIRV-Tools v2026.4 from the distribution. GPU suite on an NVIDIA GeForce RTX 4070, driver 620.73.04.python3 -I tests/semantic/test_buffer_offset_wrap.py: 8 tests pass. With the translator of the base commit the same file has 13 failing subtests: index −1 in raw and disabled mode with a literal and a run-time V# (4), the mapped 5 GiB offset in disabled mode (2), a structured index belowNUM_RECORDSwhose product passes 4 GiB in modes 0 and 1 (4), a swizzled offset past 4 GiB with a literal and a run-time V# (2), andoff 0xFFFFFFF0 + soffset 0x20(1). The swizzled control below 4 GiB passes on both. The swizzled cases were added after a review noted that the swizzled path had moved to 64 bits without a case above 4 GiB.python3 -I scripts/run_semantic_tests.py tests/semantic: 471 files, 6,176 tests, 0 files failed.tests/the wayci.ymlruns them: 520 files, 519 pass.tests/test_imhex_patterns.pyfails (6 of its 9 tests) and fails the same way on the base commit, so it is not from this change.python3 -I scripts/check_no_game_data.py: passes.python3 -I scripts/run_gpu_tests.py(run on the head before the swizzled tests were added; the translator has not changed since): 261 shaders translate and passspirv-val; 202 of 252 tests pass, 49 are skipped and 1 fails (cs_imgstore_cube). The run with the base commit's translator gives the same 202, 49 and 1, test for test. The harness programs came from an older native build on this machine (2026-11-23) and were not rebuilt for this, which is the likely reason for that one failure; it is not a result of this change.Not run by us: native Windows, macOS, an AMD GPU, the
tools/hw_oracleprobe. A reviewer ran the GPU suite on an AMD RX 9070 XT (236 of 252 pass, 16 skipped, 0 failed) one01626be9, which has the same translator as this head.GPUs tested: NVIDIA GeForce RTX 4070 (translation only; see above for what is not measured on hardware).
AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.
Checklist
32950551eand merges cleanly into currentmain.docs/design.md("Buffer bounds checking"), with how it was confirmed and what is not measured.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.