Skip to content

BUILD-858: Lower dynamic scalar-buffer bounds to word pairs - #2986

Open
kacper-serewis wants to merge 13 commits into
ItsNotRexed:mainfrom
kacper-serewis:shader/dynamic-bounds-pair
Open

kacper-serewis wants to merge 13 commits into
ItsNotRexed:mainfrom
kacper-serewis:shader/dynamic-bounds-pair

Conversation

@kacper-serewis

@kacper-serewis kacper-serewis commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: #2463

BUILD-858 · current claim · claim

Head 48281e60 integrates official main 4c52ce27 and published #2463 3de4f0fb. The published dependency tree matched the previously integrated dependency. The contract retains main’s updated instruction-encoding checks. All eight CPU address-lowering tests and seven printed-encoding tests passed. On NVIDIA GeForce RTX 5070, driver 616.56, all eight synthetic modules passed Vulkan 1.2 spirv-val and returned the expected value in native and lowered forms for raw and strided bounds, including a product above 4 GiB.

Earlier validation

Rebased head 72e1d7a1 includes main f847748c and #2463 at 6ed0f368. The eight address tests pass. Against the integrated dependency alone, the dynamic-bounds test fails because the module retains Int64. On the RTX 5070 (616.56), four raw/structured boundary cases matched in both native and lowered form, including a product above 2³². All eight synthetic modules passed Vulkan 1.2 spirv-val. Full semantic discovery ran 7,330 tests successfully with one expected failure. Translator pytest reported 562 passed and four skipped.

Historical validation at 81924a5 and its predecessors

This branch adds one commit on #2463 at 65e64c2. Dynamic scalar-buffer bounds choose NUM_RECORDS when stride is zero and NUM_RECORDS × stride otherwise. The pass selects both words with the same predicate and uses OpUMulExtended for a multiply of two widened uints. Unsupported producers preserve the entire input module.

On Windows, semantic discovery passed all 2,575 tests. The focused address suite passed all eight, including both selector values, a nonzero high word on either arm and a full-width multiply control. The translator pytest suite passed 526 with two skips. On an RTX 5070, driver 616.56, eight synthetic readbacks matched across native and lowered forms, covering raw and structured bounds on both sides of the limit.

Private integration with #2904 at 5ddfabc, Vulkan SDK 1.4.363.0, five local programs per configuration:

Configuration Translated Vulkan 1.2 spirv-val Int64 Float64
Soft f64 5 5 5 0
Soft f64, address lowering off 5 5 5 0
Native f64 5 5 5 5

The five soft outputs match the prior address-opt-out binaries byte for byte. Full-width normalized-format multiplication and data-dependent shifts still require Int64. Tracker finding. Retail validation was static. Only synthetic code, tests and contract documentation are included.

AI-assisted with Codex.

c4k3ss and others added 3 commits November 22, 2026 19:02
…HADER-423)

Every PhysicalStorageBuffer address the generator builds is one idiom:
widen a dword, shift the high word by 32, OR, add or subtract, AND,
narrow or shift right by 32, compare two such values, convert to a
pointer. lower_addr64 runs on the assembled module: when a shader's only
64-bit integers are that idiom, each value becomes a (low, high) pair of
uints with OpIAddCarry / OpISubBorrow into the high word, compares go
high word first, and the pair is a uvec2 bitcast to the pointer (as
GL_EXT_buffer_reference_uvec2). The module drops OpCapability Int64, so
index.json stops listing shaderInt64 for it; devices with buffer device
addresses but no shaderInt64 (Intel) can run those modules. A shader
with any other 64-bit integer use keeps Int64. --int64-addresses opts
out. spirv_mini_interp learns the uint-pair-to-pointer bitcast.

Tests: tests/semantic/test_addr64_lowering.py (both forms read the same
word with a plain sum, a low-word carry and a 64-bit wrap; dropping the
carry is caught; a 64-bit data op keeps Int64). run_gpu_tests.py: 190
shaders pass spirv-val; RTX 5070 Ti 139/185 native, 170/185 emulated;
RDNA2 gfx1036 iGPU 170/185; 0 failures. 103 of the 117 shaders that
touch memory no longer declare Int64.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…eck it in the interpreter, docs wording

- tests/test_translate.py test_cs_store_packed_atomic_pointers pinned the
  OpConvertUToPtr form of the atomics' array pointer; it is the uvec2
  OpBitcast since lower_addr64 (OpConvertUToPtr with --int64-addresses),
  so it accepts both (reported by @zneel on ItsNotRexed#2463).
- spirv_mini_interp's pointer bitcast checks the source's declared type
  (a 2-component 32-bit integer vector), not only the runtime tuple, so
  an invalid 64-bit pair cannot pass the test oracle (@richardsenra).
- docs/design.md: the contract row describes the idiom the pass handles
  (narrowing and the logical shift by 32 included) and what keeps Int64
  (@richardsenra).

pytest tests/test_translate.py: 526 passed, 2 skipped. tests/semantic:
2,573 OK.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s, arithmetic shift by 32)

A global_* access with a negative instruction offset sign-extends it
through a 64-bit signed integer (OpSConvert %long, OpBitcast %ulong)
before the add, and a few paths shift a 64-bit value right
arithmetically by 32. The pass now lowers those as well: the
sign-extended dword is (value, value >> 31 arithmetic), the shift by 32
is (high, high >> 31), and a bitcast between the 64-bit integer types is
the same word pair. The rewrite's 32-bit constants are declared once the
body is done (they are made while it is rewritten). Review point from
@UNYTIX on ItsNotRexed#2463.

tests/semantic/test_addr64_lowering.py: three global_load cases with
negative and positive offsets read the same word in both forms, and the
lowered module has no Int64 or %long. cs_global_neg_offset now runs
without Int64 (RDNA2 gfx1036 iGPU: 170/185, 190/190 spirv-val); 13 of
the 117 memory-touching test shaders keep Int64 (was 14). tests/semantic
2,573 OK; pytest tests/test_translate.py 526 passed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
test_buffer_store_format's emission check accepts the uvec2 OpBitcast of
the store's address as well as OpConvertUToPtr (--int64-addresses), and
test_loop_ballot_barrier's local interpreter turns a (low, high) uint
pair bitcast to a PhysicalStorageBuffer pointer into the same "phys"
address OpConvertUToPtr gives (its OpBitcast was the identity, so the
pair reached OpAccessChain as a list). Both were added to main after
this branch's base (reported by @davidesidoti on ItsNotRexed#2463).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@CharlyRien

Copy link
Copy Markdown

Tested 81924a5 (merged on current main) on RTX 3090, driver 616.56, Windows 11 23H2: pass. With this translator change, run_gpu_tests.py gives 143/189 passed, 46 skipped (wave64 on a 32-wide GPU), the same as main on this GPU. ctest matches main here too: 3 failures, all known on this machine (d3d12_shader_cache, a host-runtime crash on 23H2, see #2167; and d3d12_vulkan_device / d3d12_typeless_rtv, see #2498).

AI-assisted test run.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Tested 81924a5d merged onto main 16282101 on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5, subgroup 32..64), Mesa 25.2.8, Ubuntu 24.04, LLVM 23.1.6, SPIRV-Tools 2026.4: pass.

  • python -I scripts/run_gpu_tests.py --build runtime/build/linux: 172/189 passed, 15 skipped, identical per test to plain main 16282101 on this machine. The two failures in both runs, cs_signed_zero_nan and cs_w32_salu64, are the known Mesa 25.2 RADV ones (GPU test results (one comment per GPU and driver) #166, docs/testing.md).
  • tests/semantic/test_addr64_lowering.py: 8 passed, 14 subtests; tests/test_translate.py: 541 passed, 4 skipped.
  • No dedicated GPU probe from me for this one, so this is a no-regression check of the whole suite rather than a hardware check of the new lowering.

gfx1151 is RDNA 3.5, not RDNA2: this shows the translated SPIR-V gives the modelled words on a real driver, not that RDNA2 hardware does. AI-assisted (Claude Code).

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested 81924a5 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.

Semantic tests:

  • python3 tests/semantic/test_addr64_lowering.py — 8/8 OK
  • tests/test_translate.py uses pytest (not installed on this Deck) and was not run.

Full GPU suite (run from PR worktree against main runtime build):

  • python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build — 170/185 passed, 15 skipped, 0 failed. Total/skip count differs from current-main baseline (175/189 pass, 14 skip) likely due to PR-branch script/test-set version skew vs main runtime build; no failures observed.

Note: tested PR head as submitted (PR description lists dependency on #2463).

AI-assisted (OpenCode).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 48281e6 merged onto main aa2988c on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed. main aa2988c gives 164/210, 46 skipped, 0 failed. All 214 test shaders translate and pass spirv-val.
  • tests/semantic/test_addr64_lowering.py: ran 8 tests in 1.788s; OK.
  • tests/semantic/test_buffer_store_format.py: ran 39 tests in 0.175s; OK.
  • tests/semantic/test_loop_ballot_barrier.py: FAILED (failures=3, errors=2). It fails the same way on main aa2988c without this PR: that's kacper-serewis's finding on Coordinating who works on what (19) (moved to #3918) #3796, which Vonsek has claimed.

AI-assisted (Claude Code).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILD-858 independent GPU validation of local integration candidate e1e09ada (not the published head). Windows RTX 5070, driver 616.56, subgroup 32. Native Int64 and lowered modules each passed Vulkan 1.2 validation and all seven synthetic dispatches, comparing every byte of a 256-byte readback. At offset 8 a four-byte read returned zero for limits 8 and 11 and the sentinel at limit 12. Limits of 2^32 and 2^32+8 also returned the sentinel. This exercises high-word bounds arithmetic on a small allocation. Only the native module declared Int64; the lowered module used OpUMulExtended. AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILD-858 pushed e1e09ad. Depends on: #2463. Full semantic discovery: 6,253 cases versus main’s 6,245, with the same three loop-ballot failures, two errors, four skips and one expected failure. All 789 focused checks passed. Both prior and current tips translated and validated 200/200 cached shaders. The earlier 14 RTX 5070 readbacks on driver 616.56 apply to this exact head. AI-assisted.

@DenRakEiw

Copy link
Copy Markdown
Contributor

Tested PR #2986 (e1e09adacfb91b9ed27b867735593606499789c8) on Windows 11 / Python 3.12.10.

  • Trial merge against origin/main (d974c88a): clean (exit 0), git diff --cached --check passed.
  • Tests:
    • python -I tests/test_translate.py: failed with ModuleNotFoundError: No module named 'rdna2spirv' (test_translate.py is a pytest suite relying on tests/conftest.py); python -m pytest tests/test_translate.py: 596 skipped (llvm-mc, spirv-as, and spirv-val are not installed on this host).
    • python -m unittest discover -s tests/semantic -p test_addr64_lowering.py: Ran 8 tests in 1.065s — OK (CPU spirv_mini_interp checks).
    • python -I tests/test_docs_design_rows.py: Ran 4 tests in 0.045s — OK
    • Modified semantic test checks: test_buffer_atomic_fminmax_and_align.py (10 tests — OK), test_buffer_store_format.py (39 tests — OK), test_wave64_emulate_opt.py (22 tests — OK).
  • Code read: lower_addr64() in tools/rdna2spirv.py rewrites 64-bit buffer-address idioms (including OpUMulExtended bounds, OpSelect, signed global_* offsets, and OpConvertUToPtr) into 32-bit (low, high) %uint pairs ending in OpBitcast from %v2uint_a and drops OpCapability Int64 unless --int64-addresses is set or any non-idiom 64-bit op/reference forces a fallback.

AI-assisted review (Gemini 4 Neon).

@MuratK20

Copy link
Copy Markdown

Tested 6a5a453, Windows 11, Python 3.13.5.

  • On the PR's own head: tests/semantic/test_wave64_emulate_opt.py 26/26 OK.
  • Merged on main 1cc6e3c: main's test_slist_live_out_scalar_and_src_scc_end_to_end errors with NotImplementedError: unsupported op OpUMulExtended from step_until_barrier in test_wave64_emulate_opt.py (line 541). Main alone passes 29/29. The SPIR-V emitted on main now uses OpUMulExtended, and the merged interpreter doesn't handle it. SHADER-423: 64-bit buffer addresses as 32-bit pairs, without Int64 #2463 (same files) does not hit this.
  • The other touched test files pass merged (test_addr64_lowering 8, test_buffer_atomic_fminmax_and_align 10, test_buffer_store_format 39, test_loop_ballot_barrier 15).
  • scripts/run_gpu_tests.py on the RDNA2 iGPU (gfx1036, AMD 32.0.13036.4): 214/235 pass, identical to main.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants