Skip to content

rdna2spirv: 64-bit buffer addresses without Int64, so shaders run without shaderInt64 (SHADER-423) - #850

Open
c4k3ss wants to merge 6 commits into
ProjectLeonida:mainfrom
c4k3ss:shader/addr-no-int64
Open

c4k3ss wants to merge 6 commits into
ProjectLeonida:mainfrom
c4k3ss:shader/addr-no-int64

Conversation

@c4k3ss

@c4k3ss c4k3ss commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-423 (#14 (comment)), carried over from the upstream repository, where it was open with ten independent GPU test reports when the repository went private.

What and why

Translated shaders declared OpCapability Int64 only because of buffer addresses: the translator builds each PhysicalStorageBuffer address as a 64-bit integer (zero-extend, shift by 32, OR, add an offset, convert to pointer). A device without shaderInt64 (Intel) refuses every such module, although the shader's own arithmetic is 32-bit.

lower_addr64 (tools/rdna2spirv.py, run in assemble() on the finished module text) rewrites that address arithmetic into pairs of 32-bit words: adds and subtracts through OpIAddCarry / OpISubBorrow, the shift-by-32 / OR / AND / narrowing / sign-extension / 64-bit bitcast forms the address idiom uses, pair compares, and OpConvertUToPtr of a 64-bit value as OpBitcast of a two-component uint vector to the pointer. A value is either lowered completely or left alone; when nothing 64-bit remains, the Int64 capability is dropped. Shaders that use 64-bit integers as data keep it. --int64-addresses keeps the previous form.

Also in this PR: tests/semantic/test_addr64_lowering.py (7 tests, including negative offsets through global_load), the two test interpreters learn the pair pointer form, six existing tests accept either address form, and the docs/design.md contract row "64-bit addresses without Int64".

Tested

On main d0da7dade, Windows 11 26200, llvm-mc 23.1.6, Vulkan SDK 1.4.363, MSVC 14.44:

  • Touched semantic files: test_addr64_lowering 7, test_buffer_atomic_fminmax_and_align 10, test_buffer_store_format 39, test_loop_ballot_barrier 15, test_wave64_emulate_opt 31, all OK. pytest tests/test_translate.py tests/test_rdna2spirv_xdxr_rules.py: 675 passed.
  • scripts/run_gpu_tests.py, test programs built from this head: 258 of 258 shaders translate and pass spirv-val; 198/249 passed, 49 skipped, 2 failed. The two failures, cs_imgload_tfe and cs_imgload_d16_tfe, fail identically with this main's own translator on the same programs (--filter cs_imgload: 2/4 both ways, same texel values), so they are not from this change.
  • Upstream, the same diff (it applies to this main without conflicts) was run by ten independent testers with no regression against their main: NVIDIA RTX 2060, 4080, 5080, 5090; AMD RX 5700 XT (RDNA1), RX 6800 and a Steam Deck (RDNA2), RX 9070 XT (RDNA4), gfx1036 iGPUs on the Windows driver; Windows, Linux/RADV.
  • Not tested here: an Intel GPU. The change is what makes that possible; I have none.

GPUs tested: NVIDIA RTX 5070 Ti, driver 621.24, Windows 11

AI-assisted: yes (Claude Code); built and tested on the machine above.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

lower_addr64 rewrites the assembled module's 64-bit address arithmetic (the zero-extend, shift-by-32, OR/AND, add and
subtract with carry, narrowing, sign-extension, 64-bit bitcasts and pair compares the address idiom uses) into uint
pairs and an OpBitcast of a 2x32 vector to the PhysicalStorageBuffer pointer, and drops OpCapability Int64 when
nothing else needs it, so translated shaders run on devices without shaderInt64. --int64-addresses keeps the 64-bit
form. Semantic tests for the lowering, the interpreters learn the pair pointer form, design.md row.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@c4k3ss
c4k3ss marked this pull request as ready for review November 24, 2026 14:38

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Audited and verified. Implements lowering of 64-bit buffer device address arithmetic into 32-bit uint pairs (OpIAddCarry, OpISubBorrow, etc.) and vector pointer bitcasting, dropping the Int64 / shaderInt64 Vulkan capability requirement for devices lacking 64-bit integer support. Preserves 64-bit path under --int64-addresses. Comprehensive semantic test suite in ests/semantic/test_addr_no_int64.py and contract docs updated in docs/design.md. Approved.

@Sangonapou

Copy link
Copy Markdown
Contributor

Tested 4f2628f on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, regression check

Runtime built at this head with scripts\build_runtime.ps1 (MSVC 19.51); llvm-mc 23.1.6, SPIRV-Tools 2026.4. No game files.

  • CPU: tests/semantic/test_addr64_lowering.py 7 OK.
  • GPU suite with the lowered addresses: 258 shaders, 258 translated, 258 pass spirv-val; native 198/249 passed, 49 skipped; LEONIDA_W64_EMULATE=1 230/249 passed, 17 skipped. The only failures are cs_imgload_tfe / cs_imgload_d16_tfe, which fail the same way on main on this card (tests: correct resident TFE status expectations (SHADER-1266) #892).

This GPU has shaderInt64, so it shows the 32-bit-pair addresses compute the same results as before on NVIDIA; the case the PR is for (a device without shaderInt64) needs an Intel or similar run.

@titoreinaldo

Copy link
Copy Markdown

Intel Arc readback at 4f2628f83f390e0d25b30bf15718dbbd02852517. On Windows 11 Pro 26H2 build 26300.9974, driver 32.0.101.8132, the exact-head vk_compute_test printed Intel(R) Arc(TM) Graphics (subgroup 8..32) on all 12 dispatches. Selected with VK_LOADER_DRIVERS_SELECT=*igvk* and LEONIDA_VK_DEVICE=Intel(R) Arc(TM) Graphics. Built Release with LLVM-MinGW 23.1.6.

Handwritten synthetic case Address-pair default --int64-addresses reference
Per-lane global_load_dword, offsets −252, −4, +12, +276 bytes 4/4 passed, no Int64 capability or type 4/4 passed, Int64 present
Scalar s_load_dword Passed, no Int64 capability or type Passed, Int64 present
Genuine s_lshl_b64 used to compute the address Passed, Int64 retained Passed, Int64 retained

12/12 passed, 0 failed, 0 skipped. Each dispatch compared all 256 readback words with the CPU expectation, including 224 untouched words. All 12 binaries also passed spirv-val --target-env vulkan1.2. For the −4 case, intentionally expecting offset 0 produced differences in all 32 result lanes. The existing seven test_addr64_lowering.py tests passed as well. This Intel driver supports shaderInt64. The five default address-only modules ran with that device feature disabled by the harness.

Reproduce the signed-offset case

Use the PR’s tests/semantic/test_addr64_lowering.py::translate(name, body_lines, lowered=True) helper. Repeat with lowered=False for the legacy module. For each of the four offsets substitute the signed decimal value below. The helper supplies the 32×1×1 workgroup and final s_endpgm.

v_lshlrev_b32 v1, 2, v0
v_add_nc_u32 v2, 512, v1
v_mov_b32 v3, 0
global_load_dword v4, v[2:3], off offset:-4
s_waitcnt vmcnt(0)
buffer_store_dword v4, v1, s[0:3], 0 offen
s_waitcnt vmcnt(0)

Initialize 256 little-endian uint32s with w[i] = (0x6b120000 + i * 0x10203) & 0xffffffff. Assemble and validate the generated text, then dispatch once:

spirv-as --target-env vulkan1.2 case.spvasm -o case.spv
spirv-val --target-env vulkan1.2 case.spv
spirv-dis case.spv
$env:VKC_OUT_WORDS = "256"
$env:VKC_SUBGROUP_SIZE = "32"
$env:VKC_HEAP_INIT = "heap.bin"
$env:VKC_DUMP = "out.bin"
.\vk_compute_test.exe case.spv 1 dump

Read out.bin. Lane t must contain w[128 + offset/4 + t] and words 32–255 must match the input. For the scalar case all 32 lanes read byte address 256. The 64-bit-data control computes 256 as 16 << 4 in an SGPR pair before that scalar load.

AI-assisted with OpenAI Codex. All buffers and shaders were synthetic.

c4k3ss and others added 2 commits November 25, 2026 18:58
After the merge of main, Gen.host_addr sign-extends every 48-bit effective
VA with a shift left and an arithmetic shift right by 16 (a 32-bit shift
amount). lower_addr64 knew only shifts by 32, so every address kept Int64
and the lowering did nothing. A shift by 1..31 of a (low, high) pair now
becomes the two words' shifts with the bits that cross between them; the
amount may be a 32-bit or a 64-bit constant.

test_addr64_lowering gains a negative 48-bit VA case (bit 47 set, read
below the heap base), compared with the Int64 form in spirv_mini_interp.

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

c4k3ss commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased by merging main fe1553456 (775 commits since the base); the only conflict was the docs/design.md table row.

Main's Gen.host_addr now sign-extends every 48-bit effective VA (a shift left and an arithmetic shift right by 16, with a 32-bit shift amount). lower_addr64 knew only shifts by 32, so after the merge it refused every module and the lowering did nothing (all 7 semantic tests failed). Commit da9e7492b makes a shift by 1..31 of a (low, high) pair the two words' shifts with the bits that cross between them, with the amount read as a 32-bit or 64-bit constant; shifts by a variable amount or by more than 32 still keep Int64. The contract row and the code comment say so. test_addr64_lowering.py gains a negative 48-bit VA case (bit 47 set, so the read lands below the heap base), compared with the Int64 form in spirv_mini_interp.

Tested on main fe1553456, Windows 11 26200, RTX 5070 Ti (NVIDIA 621.24), llvm-mc 23.1.6, Vulkan SDK 1.4.363:

  • test_addr64_lowering 8 OK; test_rdna2spirv_xdxr_rules 6, test_buffer_atomic_fminmax_and_align 11, test_buffer_store_format 39, test_loop_ballot_barrier 15, test_wave64_emulate_opt 33, all passed.
  • scripts/run_gpu_tests.py with the lowering: 209/264 passed, 54 skipped, 1 failed (cs_imgatomic_ext: 6 of 64 sint words differ, word 32 = 0x0badf00d), runtime and test tools built from this main with scripts/build_runtime.ps1 (MSVC). With this main's own translator on the same build and programs: 209/264, 54 skipped, the same cs_imgatomic_ext failure with the same words. Same failures both ways, so none are from this change.
  • Of the suite's 274 translated programs, 242 need no Int64 with the lowering; 98 did without it before (the rest are 64-bit data ops: cs_w32_salu64, cs_w32_shift64, ps_vcmp_64, the typed-format tests).

AI-assisted (Claude Code); a second tool reviewed the shift formulas for every amount 1..32 against integer arithmetic and validated 192 lowered synthetic modules with spirv-val.

c4k3ss and others added 2 commits November 26, 2026 13:30
…and variable left shift

After the second merge of main (RT-POST-LOAD-GPU-MEMORY, 9f98dcc), the
buffer address idiom also holds the full index * stride product in 64 bits,
a left shift by the element-size log read from the V# (a 32-bit value, not
a constant), and a 64-bit compare against 0xFFFFFFFF for the range check.
The pass refused every such module and kept Int64.

A 64-bit multiply becomes the low words' product, its high word from the
four 16-bit half products (plain 32-bit multiplies, which the three test
interpreters run), plus each low word times the other's high word. A left
shift by a 32-bit value becomes the shift by k & 31 on both words with the
crossing bits, the words moved up once k >= 32. The contract row and the
code comment say so.

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

c4k3ss commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Merged main a73a57e13 (440 commits since the last merge; the conflict was the same docs/design.md row).

Main's RT-POST-LOAD-GPU-MEMORY (9f98dcc61) put three more 64-bit forms into the buffer address idiom: the full index * stride product (OpIMul %ulong, so an index that lands past 32 bits is out of range), a left shift by the element-size log read from the V# (a 32-bit value, not a constant), and the range compare against 0xFFFFFFFF. The pass refused every such module and the lowering did nothing again. Commit c621105e6: a 64-bit multiply becomes the low words' product with its high word from the four 16-bit half products (plain 32-bit multiplies, which the three test interpreters run; no OpUMulExtended), plus each low word times the other's high word; a left shift by a 32-bit value becomes the shift by k & 31 on both words with the crossing bits, the words moved up once k >= 32. A right shift by a variable amount still keeps Int64. The contract row and the code comment say so.

Tested on main a73a57e13, Windows 11 26200, RTX 5070 Ti (NVIDIA 621.24), llvm-mc 23.1.6, Vulkan SDK 1.4.363:

  • test_addr64_lowering 8 OK; test_rdna2spirv_xdxr_rules 6, test_buffer_atomic_fminmax_and_align 11, test_buffer_store_format 39, test_loop_ballot_barrier 15, test_wave64_emulate_opt 33, all passed.
  • scripts/run_gpu_tests.py with the lowering, runtime and test tools built from this main with scripts/build_runtime.ps1 (MSVC): 211/268 passed, 55 skipped, 2 failed (cs_imgatomic_ext: 6 of 64 sint words differ; cs_texture_uav: "texture view format lacks the required formatless storage image access: 98"). With this main's own translator on the same build and programs: 211/268, 55 skipped, the same two failures with the same words. So neither is from this change.
  • Of the suite's 277 translated programs, 245 need no Int64 with the lowering.

AI-assisted (Claude Code); a second tool checked the multiply and shift lowering against integer arithmetic (20,121 products, 13,504 shifts).

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026
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.

4 participants