Skip to content

BUILD-871: Decode normalized fractions with 32-bit shifts - #3018

Open
kacper-serewis wants to merge 13 commits into
ItsNotRexed:mainfrom
kacper-serewis:shader/norm-decode-dwords
Open

kacper-serewis wants to merge 13 commits into
ItsNotRexed:mainfrom
kacper-serewis:shader/norm-decode-dwords

Conversation

@kacper-serewis

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

Copy link
Copy Markdown
Contributor

Depends on: #2986
Depends on: #2463

BUILD-871 · claim · finding

Continuation claim. Head 405651b6 includes official main aa2988cc, #2986 at 48281e60 (tree 59b34567) and #2463 at 3de4f0fb. Eight normalized-format and eight address-lowering CPU tests passed. Six synthetic decode modules passed Vulkan 1.2 spirv-val. Every one of the 132,612 readback words for UNORM2/8/10/16 and SNORM8/16 matched on NVIDIA GeForce RTX 5070, driver 616.56. This run used synthetic data only.

Earlier validation

Rebased head fd3de3f7 builds on #2986 at 72e1d7a1, including main f847748c and #2463 at 6ed0f368. Both focused suites passed (eight address and eight normalized-format tests). The normalized-format suite reports 1,354 failed subtests on its immediate parent, which still emits Int64 for the decode. On the RTX 5070 (616.56), six synthetic modules passed Vulkan 1.2 spirv-val and all 132,612 readback words matched across UNORM2/8/10/16 and SNORM8/16. Full semantic discovery ran 7,332 tests successfully with one expected failure. Translator pytest reported 562 passed and four skipped.

Historical validation at 9a22b68 and its predecessors

Implementation commit 4b75d6e builds on #2986 at 81924a5. Merge commit 9a22b68 reconciles the contract table with current main. Align the magnitude to bit 31, repeat the n-bit pattern with shifts and ORs, then round from the 25th bit. A nonzero periodic tail rules out a halfway case. The signed decode retains saturation at the minimum code. The general address-pair pass keeps its fail-closed behavior.

On Windows, all eight normalized-format tests and all eight address-lowering tests passed. Semantic discovery passed 2,576 tests on the implementation branch. Both focused suites also passed after merging main. Translator pytest reported 526 passed and two skipped. An RTX 5070 (616.56) matched all 132,612 GPU readback words across every UNORM2/8/10/16 and SNORM8/16 encoding.

Privately combined with #2904 at 5ddfabc. Before and after the change, all five matching programs translated and passed spirv-val for Vulkan 1.2. Binary capability inspection found Int64 in five before and zero after, and Float64 in zero in both runs. Repeated translation, validation and binary capability inspection on merge head 9a22b68 with #2904, with the same result for all five. Verification of those five programs was static. GPU execution used synthetic inputs.

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>
@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested 9a22b68 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/unit tests:

  • python3 tests/semantic/test_norm_decode.py — 8/8 OK
  • 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:

  • python3 -I scripts/run_gpu_tests.py --build /home/deck/opencode/Leonida/runtime/build — 175/189 passed, 14 skipped, 0 failed. Skips are the expected D3D12-owned skips on this Deck.

Note: tested PR head as submitted (PR description lists dependencies on #2986/#2463).

AI-assisted (OpenCode).

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Tested 9a22b686 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), test_norm_decode.py 8 passed (1,370 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).

@Kam471 Kam471 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.

Verified on the PR head: test_norm_decode.py + test_addr64_lowering.py -> 16 passed, 1,384 subtests. On current main the new no-Int64 assertion gives 1,354 subtest failures, so the coverage is exercised. An independent uint32 emulation against exact integer RNE over all 131,070 inputs for n=1..16 gives 0 mismatches (65,777 round-ups, 16 mantissa carries); boundaries 0 -> 0x0, 1/65535 -> 0x37800080, 65534/65535 -> 0x3F7FFF00, 65535/65535 -> 0x3F800000; the maximum shift is 24 and the exponent never underflows. Mutations are non-vacuous (exponent 126->127 -> 1,327 subtest failures; >>8->>>9 -> 1,327; guard removed -> 869). No game data or absolute paths. Approve.

Caveats: the change is stacked on #2986 (lower_addr64), not BUILD-871 alone, and test_translate.py reports 545 skips locally because no amdgcn llvm-mc is present.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 405651b 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:

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.

6 participants