Repository navigation
Conversation
KernelSmoker
left a comment
There was a problem hiding this comment.
The new fits <= 0xFFFFFFFF predicate is applied in every OOB mode, which appears to reject valid mapped addresses above 4 GiB. The AMD RDNA2 ISA describes a 48-bit resource base and linear addressing as stride * index + offset; for OOB_SELECT=2 it specifies only NumRecords == 0 as the bounds check (“do not check bounds”). It does not define a 32-bit ceiling for the computed byte offset: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf (section 8.1.5, pp. 59–62).
I reproduced the regression with this PR’s translator and interpreter: mode 2, NumRecords=1, stride 20, index 0x10000000 gives byte offset 0x1_40000000 (5 GiB), but the store is suppressed. If that address is backed by the allocation, mode 2’s documented check should not reject it. The external observation cited here establishes that one much larger offset does not wrap back into the pool; it does not establish that every offset above 0xFFFFFFFF is out of range.
Please add a >32-bit but mapped-address case and limit the guard to the actual hardware address/range condition established by evidence. The new tests in this PR pass (4/4); existing test_buffer_oob_select.py (36/36) and test_vector_mem_mubuf.py (53/53) also pass locally, so this is a missing semantic boundary case rather than a test failure.
ff94bdd to
0c3c8d1
Compare
|
Review of #1068 (SHADER-MUBUF-OFFSET-WRAP) Head: ff94bdd (one commit on 3295055). Claim: #14 comment 7139398473 by the author, 17:34 UTC, six minutes before the PR was opened; it matches the scope. Environment: Windows 11, native Python 3 ( Commands and results
Findings
What I checked and found correct: the 64-bit linear form Verdict: the main change is correct for the case it targets (raw and disabled, run-time and literal), the test is real (5 failures without the change), and the PR merges cleanly with no overlapping open PR. Request changes on two points before merging: fix or document finding 1, and reword the "hardware observation / no effect" claim in finding 2, or measure it. Findings 3 and 4 are optional. AI-assisted. |
KernelSmoker
left a comment
There was a problem hiding this comment.
Follow-up on the updated head 0c3c8d166dcd1319f90598054f5cb26916eb1baf: I reran the added test file (4/4 pass) and independently reproduced the literal structured-mode boundary issue.
With a literal OOB_SELECT=1 V#, NUM_RECORDS=0xFFFFFFFF, stride 20, and index 0x0CCCCCCD, the index is in range but index * stride = 0x1_0000_0004. The translator's literal-mode shortcut omits fits; the local interpreter writes and reads 77 at wrapped base+4 (0x4004) instead of addressing base+0x1_0000_0004 (0x100004004). The same runtime V# takes the fits path, so descriptor-folding changes the result. This is a valid structured index by the documented mode-1 check, not an out-of-range index.
Please fix the literal mode-0/1 shortcut and add matched literal/runtime tests for a >32-bit product with index < NUM_RECORDS. My earlier concern also remains: the guard suppresses all runtime mode-2 offsets above 4 GiB even though that mode performs no bounds check. Tests passing on the current head do not cover either mapped-address case; no AMD hardware result is claimed here.
|
AI-assisted independent GPU verification (overnight shift, worker w4). Environment: Windows, Git Bash; runtime built RelWithDebInfo (Ninja, VS2022 BuildTools, SDK 10.0.26100, Vulkan SDK 1.4.363.0). AMD Radeon iGPU (RDNA2 gfx1035, driver 24.10.24, Vulkan 1.3.280, 128B push constants):
NVIDIA RTX 4070 SUPER (driver 610.88):
Translator tests:
Verdict: verified. The 32-bit buffer-offset wrap change breaks nothing on either GPU; the only AMD failures are the known mesh-shader driver crashes unrelated to this PR. |
0c3c8d1 to
e01626b
Compare
|
Thank you both for the reviews. You were right on the main point, so the branch is reworked instead of patched: the
One consequence is the opposite of the first version, so I want it to be explicit. Index −1 in mode 2 or 3 is now neither base − 20 nor dropped: it is an access tens of GiB past the base. The runtime's arena is at most 4095 MiB, so that address is always outside it, and on Vulkan that is undefined. If the project wants such an access refused, I think the bound should be the arena size and it should live where the arena is known, as a follow-up. If you would rather have it in this pull request, say so. Run on the new head (CachyOS, Python 3.14, llvm-mc 23.1.5, SPIRV-Tools v2026.4): 🤖 Generated with Claude Code |
|
AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo. Head
|
|
CPU check of
One gap: the new tests only use the linear path. The swizzled path also moved to 64 bits and has no case above 4 GiB. Not tested here: GPU, game corpus, what hardware does at such an address. AI-assisted (Claude Code) |
e01626b to
1c474b7
Compare
|
@thesubtleties thank you, that gap was real: the swizzled path moved to 64 bits and had no case above 4 GiB. Added to
The file now has 8 tests. With the base commit's translator 13 subtests fail (the two swizzled cases above 4 GiB are new among them; the control passes on both). Full semantic suite on the new head: 471 files, 6,176 tests, 0 files failed. The translator itself is unchanged since @iFeyz thank you for the RX 9070 XT run; the description now cites it. 🤖 Generated with Claude Code |
…RAP) The hardware adds index * stride (a full product) and soffset to the 48-bit V# base without wrapping at 32 bits (RDNA2 ISA 8.1.5: base + stride * index + offset). Only off = vaddr + inst_offset wraps. buffer_address formed the whole offset in 32 bits, so index 0xFFFFFFFF with a 20-byte stride became base - 20: OOB_SELECT 3 does not look at the index and 2 checks nothing, so a store wrote 20 bytes below the buffer and a load read them. The linear and the swizzled offset are now 64-bit values added to the base. No bound is added. Each mode checks what it checked before, for a literal and a run-time V# alike, and an access above 4 GiB that its mode allows is made at its 64-bit address. What such an access does when nothing is mapped there is not measured on the console and is undefined on Vulkan. The non-wrapping product was observed on hardware by five-star-recomp (ThatRecompDev, GPL-3, commit b9b57e2); the code and the test are new. tests/semantic/test_buffer_offset_wrap.py fails 13 ways with 32-bit arithmetic (linear and swizzled offsets). Contract row "Buffer bounds checking" in docs/design.md and docs/buffer_bounds.md say what is measured and what is taken over. AI-assisted (Claude Code). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1c474b7 to
a656d4f
Compare
|
@KernelSmoker I rebased this onto main at AI-assisted. |
tiguan26
left a comment
There was a problem hiding this comment.
Approving. Merged into current main (9f9a7c5) with no conflicts. test_buffer_offset_wrap.py passes, and the full translator suite gives 491 files / 6,300 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13).
I checked that no 32-bit offset survives in the address path. Both the linear and the swizzled forms now build wide as a %ulong. That covers index·stride as a full 64-bit product, soffset added in 64 bits, and the swizzled msb·stride + om4 shifted in 64 bits. The final base + wide takes it directly. Only vaddr + inst_offset still wraps at 32 bits, as the comment says, and the bound checks are untouched.
AI-assisted (Claude).
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