Skip to content

rdna2spirv: a float inline constant in a 64-bit integer operand is its f64 encoding (measured on RDNA2) - #2443

Open
evilclanker9000 wants to merge 9 commits into
ItsNotRexed:mainfrom
evilclanker9000:claude/hw-f64-inline
Open

evilclanker9000 wants to merge 9 commits into
ItsNotRexed:mainfrom
evilclanker9000:claude/hw-f64-inline

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-HW-F64-INLINE (claim)

Depends on: #2060 (this branch is based on it; it extends that PR's "64-bit operand literals" row and sits next to its imm64 helper).

What and why

The translator rejected a float inline constant (0.5, 1.0, 2.0, 4.0, their negatives, 1/(2π)) in a 64-bit integer operand: s_mov_b64 s[8:9], -2.0 raised Unsupported: s_mov_b64 source, and the same for the 64-bit SALU/VALU ops below (... source, ... operands, mask operand). I measured what RDNA2 does natively with the hardware oracle: the operand reads the constant's f64 encoding, the same 64 bits an f64 op reads, whatever the integer type (b64, u64 or i64).

  • s_mov_b64 s[8:9], -2.0 gives 0xC0000000_00000000, 1.0 gives 0x3FF00000_00000000, 0.5 gives 0x3FE00000_00000000.
  • 1/(2π) gives the f64 constant 0x3FC45F30_6DC9C882, not the f32 one widened. llvm-mc prints it as 0.15915494309189532 in a 64-bit operand.

Fix (tools/rdna2spirv.py):

Tested

  • Hardware measurement.
    • Setup: AMD Radeon RDNA2 iGPU (gfx1036, Ryzen 9 9950X3D), Windows 11, driver 26.10.1, tools/hw_oracle HIP launcher, rocm-sdk-core clang.
    • Method: one raw kernel per case through int_hw_probe's Case helpers, in wave32 and wave64.
    • Coverage: all nine constants in 27 ops (the ones above plus s_ff1_i32_b64 and v_add_f64), 243 cases.
    • Results: wave32 and wave64 gave the same words, the f64 encoding in every case.
    • With this change the translator (spirv_mini_interp) matches the hardware in all 225 cases it translates and runs. The other 18: s_ff1_i32_b64 (left out, see above), and v_add_f64, which the translator already handled but spirv_mini_interp cannot run because it has no doubles. Before the change, every case except v_add_f64 was Unsupported.
  • New GPU test runtime/test/shaders/cs_w32_f64inl.asm.
    • Contents: eight words derived by hand in its header (s_mov_b64 -2.0 and 1/(2π), s_lshl_b64 1.0, s_bcnt1_i32_b64 -4.0, s_ashr_i64 -0.5, s_cmp_eq_u64 4.0, v_lshlrev_b64 0.5, v_mad_u64_u32 -1.0). Registered in check.py and scripts/run_gpu_tests.py. The same shader is the semantic fixture tested by tests/semantic/test_f64_inline.py, against a plain-Python reference.
    • Results: run_gpu_tests.py --filter cs_w32_f64inl gives PASS 3221225472 1841940610 4278190080 3 4227727360 1 1071644672 3220176896 on the NVIDIA GeForce RTX 5080 (driver 616.92, device: NVIDIA GeForce RTX 5080 (subgroup 32..32)) and on the AMD Radeon RDNA2 iGPU (driver 26.10.1, device: AMD Radeon(TM) Graphics (subgroup 32..64)).
  • Red/green. Without the change (on rdna2spirv: a 32-bit literal in an i64 operand is sign-extended, as on RDNA2 #2060's branch and on main), test_f64_inline errors with Unsupported: s_mov_b64 source. With it, the test passes.
  • Negative control. I made f64_inline return the f32 bits instead of the f64 bits (one line). The GPU test then fails on both GPUs (FAIL 0 1841940610 3 3 4294967295 0 0 0). I reverted the change afterwards.
  • python -m unittest discover -s tests/semantic, python tests/semantic/regen_fixtures.py --check, python -I tests/test_shader_checks.py and python -m compileall -q tools tests pass.

AI-assisted.

Checklist

  • 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.

…does

Measured natively on gfx1036 with the hardware oracle: a 32-bit literal in a
64-bit integer operand is sign-extended where the operand is i64 (s_ashr_i64,
s_bfe_i64, s_flbit_i32_i64, v_ashrrev_i64, v_mad_i64_i32 S2) and
zero-extended where it is b64/u64. The translator zero-extended every
literal. New imm64() helper, design.md row, GPU test cs_w32_lit64 and its
semantic fixture.

AI-assisted.
# Conflicts:
#	runtime/test/shaders/check.py
…s f64 encoding

Measured natively on gfx1036 with the hardware oracle (243 cases, wave32 and
wave64): 0.5, 1.0, 2.0, 4.0, their negatives and 1/(2pi) in a 64-bit integer
operand of the SALU/VALU b64/u64/i64 ops read the constant's f64 bits, as an
f64 operand does (s_mov_b64 s[8:9], -2.0 gives 0xC0000000_00000000). The
translator rejected them. New f64_inline() and INT64_SRCS, design.md row
extended, GPU test cs_w32_f64inl and its semantic fixture. s_ff1_i32_b64 is
left out (ItsNotRexed#1409 fixes its high word).

AI-assisted.
@Rainmaker33

Copy link
Copy Markdown

Tested f0ac4de on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main 4947579. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; overlay layers off. Harness programs from a CMake build of that main.

  • scripts/run_gpu_tests.py: 141/187 pass, 46 skipped (wave64), no failures (main: 139/185).
  • cs_w32_f64inl: 3221225472 1841940610 4278190080 3 4227727360 1 1071644672 3220176896. cs_w32_lit64: 4160749568 4294967295 48 4294967295 4294967295 8 32 4294967295.
  • tests/semantic/test_f64_inline.py and test_lit64_sext.py: OK.

@Doorriiaann

Copy link
Copy Markdown

Tested f0ac4de on NVIDIA GeForce RTX 3070 (Ampere, subgroup 32..32), driver 610.57.04 (Vulkan 1.4.341), Debian 13 (kernel 6.12.115): pass. Adds Linux to @Rainmaker33's Windows run; both new programs run natively at wave32 here.

Base is main 4947579; runtime/build/linux built from each side; llvm-mc 21.1.8, SPIRV-Tools v2025.5, GCC 14.2.0.

main 4947579 this PR
cs_w32_f64inl (not present) PASS native, PASS with LEONIDA_W64_EMULATE=1
cs_w32_lit64 (not present) PASS native, PASS with LEONIDA_W64_EMULATE=1
scripts/run_gpu_tests.py 139/185 passed, 46 skipped 141/187 passed, 46 skipped
LEONIDA_W64_EMULATE=1 scripts/run_gpu_tests.py 170/185 passed, 15 skipped 172/187 passed, 15 skipped
python -I -m unittest discover -s tests/semantic 2567 tests OK 2573 tests OK

Negative control: this PR's test_f64_inline.py and test_lit64_sext.py on main fail 3 of 3 each (test_translated_shader and both runners' test_gpu_runners_expect_the_same_words).

AI-assisted: yes

@emirduran707

Copy link
Copy Markdown
Contributor

Tested f0ac4de on AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (LLPC, Vulkan driver 2.0.395), Windows 11 Pro 10.0.26300, subgroup 32..64: pass. This adds an AMD card with native 64-wide subgroups to the two NVIDIA runs above.

  • run_gpu_tests.py --filter cs_w32_f64inl and --filter cs_w32_lit64: 1/1 pass each, native and with LEONIDA_W64_EMULATE=1. Same words as @Rainmaker33's run:
    • cs_w32_f64inl: 3221225472 1841940610 4278190080 3 4227727360 1 1071644672 3220176896
    • cs_w32_lit64: 4160749568 4294967295 48 4294967295 4294967295 8 32 4294967295
  • Whole suite (native wave64): 192 shaders translated, 192 pass spirv-val; 172/187 passed, 15 skipped, 0 failed (main 4947579 here: 170/185, 15 skipped). The skips are the 14 fixtures the d3d12_* tests run, and ps_w64x_readlane (see check.py: judge ps_w64x_readlane where vk_harness required 64 (its line has no "required") #2085).
  • build.py + check.py: 206 shaders translated, 206 pass spirv-val; 161 of 165 pass, 4 skipped; both new tests ok.
  • CPU: python -I -m unittest discover -s tests/semantic -p test_f64_inline.py 3 OK, -p test_lit64_sext.py 3 OK, tests/test_shader_checks.py 60 OK, tests/test_run_gpu_tests.py 30 OK, tests/semantic/regen_fixtures.py --check clean. I did not run the whole tests/semantic suite.

Test programs: an MSVC 14.44 build of 4947579, this PR's base; the PR changes no C++ or CMake. llvm-mc 21.1.8 (native), Vulkan SDK 1.4.363.0. This is the translated fixtures on RDNA4, not a native measurement of these operands. No game files. AI-assisted (Claude Code).

@tumbione

Copy link
Copy Markdown
Contributor

Tested f0ac4dec (includes #2060) on NVIDIA GeForce RTX 5090, driver 616.56, Windows 11 (10.0.26300): pass

llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. Test programs built with scripts/build_runtime.ps1 from 49475796, this branch's merge base; the branch changes no C++ or CMake, so they match this commit.

Run Result
run_gpu_tests.py --filter cs_w32_f64inl, 3 runs pass 3/3: 3221225472 1841940610 4278190080 3 4227727360 1 1071644672 3220176896
run_gpu_tests.py --filter cs_w32_lit64, 3 runs pass 3/3: 4160749568 4294967295 48 4294967295 4294967295 8 32 4294967295
Same two tests with tools/rdna2spirv.py from 49475796 cs_w32_f64inl: missing .spv (translation failed); cs_w32_lit64: fails with 134217728 0 32 0 0 8 32 4294967295. Both pass again with this branch's translator
Full run_gpu_tests.py 141/187 passed, 46 skipped, 0 failed (main 49475796 here: 139/185, 46 skipped)
python -I -m unittest discover -s tests/semantic 2573 tests OK (3 skipped)
test_f64_inline.py, test_lit64_sext.py, tests/test_shader_checks.py, regen_fixtures.py --check 3 OK, 3 OK, 60 OK, exit 0

No game data involved. AI-assisted (Claude Code): it ran everything above on this machine.

@SashaTun

Copy link
Copy Markdown
Contributor

Tested f0ac4dec on NVIDIA GeForce RTX 5060 (driver 621.01, Windows 11, Vulkan API 1.4.357): pass.

  • python -I runtime/test/shaders/build.py <out>: 206 shaders, 206 translated, 206 pass spirv-val.
  • python -I runtime/test/shaders/check.py <out> runtime\build: 129 of 165 pass, 36 skipped, 0 failed; cs_w32_lit64 is ok, cs_w32_f64inl skips natively (the device cannot run that shader at 64 lanes on request).
  • With the wave64 emulation for this 32-wide device (LEONIDA_W64_EMULATE=1 for both build.py and check.py): 161 of 165 pass, 4 skipped, 0 failed, and the new fixture cs_w32_f64inl is ok. So the f64 encoding of a float inline constant in a 64-bit integer operand is confirmed on NVIDIA as well.
  • python -m unittest discover -s tests/semantic: 2573 tests, OK.

AI-assisted run.

@lunisahdidouch

Copy link
Copy Markdown

Tested f0ac4de on an RX 9070 (RDNA4), AMD 26.11.1 (LLPC), Vulkan 1.4.359, Windows 11: pass

Both new tests pass natively: cs_w32_f64inl and cs_w32_lit64 give the expected words. Full run_gpu_tests.py: 172/187 passed, 15 skipped, nothing failed, rest identical to main 4947579. tests/semantic passes (2573 tests, OK).

AI-assisted

@throny

throny commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Real-corpus check of f0ac4dec against main 49475796 (my own Xbox Series 1.0.2.1 copy, 26,503 disassembled shaders; Windows 11, Python 3.13, spirv-val from Vulkan SDK 1.4.363.0, CPU only). Counts only.

  • Incidence, float inline constant in an INT64_SRCS operand: 360 sites in 6 shaders. All are s_mov_b64 of -1.0 into an SGPR pair; no other op or constant occurs.
  • Incidence, 32-bit literal with bit 31 set in an i64 operand (the new imm64() sign extension): 0 of 26,503 shaders.
  • Reachability: all 360 sites come after the shader's first s_endpgm, in files that also contain invalid instruction encoding lines (trailing data disassembled as code). With the PR, the changed handlers were called 0 times while those shaders translated.
  • Translation (--no-asm --wave64-emulate, the 6 affected shaders plus 200 unaffected controls):
main PR
translated 206 206
spirv-val valid 206 206
.spv bytes changed (affected / controls) 0 / 0
fail→pass / pass→fail 0 / 0
  • test_f64_inline.py 3/3 OK, test_lit64_sext.py 3/3 OK.

No regression, and no effect on reachable corpus code.

AI-assisted (Claude Code).

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Rechecked in real wave64 with the hw_oracle fix in #2961: same words.

AI-assisted.

Conflicts:
	docs/design.md
	runtime/test/shaders/check.py
	scripts/run_gpu_tests.py
	tests/semantic/regen_fixtures.py

AI-assisted.
@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Rechecked in game MODE (IEEE off, DX10_CLAMP on, f32 denorm flush): same words. AI-assisted.

runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tests/semantic/regen_fixtures.py

AI-assisted.
@crastinator

Copy link
Copy Markdown
Contributor

Tested f2bc01f merged into main aa2988cc (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New tests pass natively: cs_w32_f64inl (3221225472 1841940610 4278190080 3 4227727360 1 1071644672 3220176896); cs_w32_lit64 (4160749568 4294967295 48 4294967295 4294967295 8 32 4294967295).
  • Whole run_gpu_tests.py: 198/212 native, 198/212 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 47/47.
  • tests/semantic/test_f64_inline.py, tests/semantic/test_lit64_sext.py: 6 passed, 20 subtests passed.

No game files. AI-assisted (Claude Code).

Conflicts: docs/design.md

AI-assisted.
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 2e5961d on Intel UHD 630 (CFL GT2), Mesa 25.2.8 ANV, Ubuntu 24.04, LEONIDA_VK_DEVICE=Intel: pass.

  • scripts/run_gpu_tests.py --filter cs_w32_f64inl: 1 shaders: 1 translated, 1 pass spirv-val; PASS cs_w32_f64inl 3221225472 1841940610 4278190080 3 4227727360 1 1071644672 3220176896; 1/1. LEONIDA_VK_DEVICE=NoSuchDevice fails with "no Vulkan physical device matches", so the Intel device ran it.
  • scripts/run_gpu_tests.py --filter cs_w32_lit64: 1/1 passed.
  • tests/semantic test_f64_inline and test_lit64_sext: Ran 6 tests, OK. regen_fixtures.py --check: clean. tests/test_shader_checks.py: OK.

AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 2e5961d97685265bed3f3fb53b134c40958fedd0 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

At 2e5961d9 the stock cs_w32_f64inl fixture matched all eight expected words on Linux RTX 5090. To check the full inline 1/(2π) encoding, I changed the first output to read the high register of the same s_mov_b64 whose low register supplies the second output. The readback was high 0x3fc45f30, low 0x6dc9c882. Both dispatches passed SPIR-V validation and their eight-word checks. This measures the translated shader.

AI-assisted verification.

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 2e5961d9 with an operand-form sweep. The 64-bit compares and qsad/mqsad still refuse a float inline constant; a five-line addition to INT64_SRCS covers them.

Method. llvm-mc 21.1.8 (-mcpu=gfx1030) chose the legal source kinds for each VALU op that rdna2spirv names, plus the v_cmp/v_cmpx families. That gave 21,898 forms over 433 ops: every source position as SGPR, M0, VCC, EXEC, null, integer and float inline constants and a literal, in e32 and e64. Each form went through rdna2spirv.translate as a one-instruction pixel shader, on main 3faac557 and on this head.

Result on 2e5961d9. 20 forms newly translate: the b64 shifts' S1 and v_mad_u64_u32/v_mad_i64_i32 S2 with 0.5 and -4.0, in e32 and e64. No form that translates on main is refused here.

Still Unsupported (a float inline constant in a 64-bit integer operand):

  • v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64} and the same v_cmpx_*, S0 or S1, e32 and e64: 192 forms (v_cmp_eq_i64 source).
  • v_qsad_pk_u16_u8 and v_mqsad_pk_u16_u8, S0 or S2: 16 forms.

They hit the same rule as the PR's other 64-bit integer operands. The compares read through src64_data, which has no fimm case. Suggested change:

     **dict.fromkeys(("v_mad_u64_u32", "v_mad_i64_i32"), (4,)),
+    **dict.fromkeys((f"v_cmp_{c}_{t}" for c in ("f", "lt", "eq", "le", "gt", "ne", "ge", "t") for t in ("i64", "u64")),
+                    (1, 2)),
+    **dict.fromkeys((f"v_cmpx_{c}_{t}" for c in ("f", "lt", "eq", "le", "gt", "ne", "ge", "t") for t in ("i64", "u64")),
+                    (0, 1)),
+    **dict.fromkeys(("v_qsad_pk_u16_u8", "v_mqsad_pk_u16_u8"), (1, 3)),
 }

With that change on 2e5961d9:

Check Result
The 208 forms all translate
Each form against the same program with s[20:21] holding the constant's f64 encoding (wave32, spirv_wave_interp, lanes at the constant, +1 and below) 272 of 272 programs export the same words
Example: v_cmp_eq_u64 vcc_lo, 0.5, v[2:3] true only in the lane where v[2:3] = 0x3FE00000_00000000
test_f64_inline.py, test_lit64_sext.py, test_alu_qsad.py, test_alu_mqsad_u32.py, test_mutations.py, test_ps_semantics.py, tests/test_isa_coverage.py, tests/test_sad_diff.py OK

The 272 programs include the forms whose constant is in a 32-bit position, which already translated.

Caveats

  • This extends the PR's measured rule to these operands; I did not measure the compares on AMD hardware (no RDNA GPU here).
  • src64_data also zero-extends a 32-bit literal in the compares. The PR's literal rule measures i64 sign-extension on five other ops, so the i64 compares may need it too. That is not measured either.
  • EXEC and VCC as 64-bit compare sources stay refused (masks as data, Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) #293).

Environment: Linux 7.0 with Python 3.14.4 (equivalence runs); Linux 6.18 with Python 3.13.5 (sweep); CPU only.

AI-assisted (Claude Code).

runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tests/semantic/regen_fixtures.py

AI-assisted.
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested ecbc6f7d4c9213517efe31a6d09726d48464f923 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

After the merge from main, I ran the two synthetic wave32 fixtures separately through the GPU test runner. Each filter produced one named PASS row, matched all eight expected words, and passed SPIR-V validation.

  • cs_w32_f64inl returned 0xc0000000 for the high word of inline −2.0 and 0x6dc9c882 for the low word of inline 1/(2π).
  • cs_w32_lit64 returned 0xf8000000 for the signed arithmetic shift and 0x00000008 for the high word of the b64 left-shift control.

This run covers the two registered fixtures. The additional vector compare and QSAD operand forms in the earlier review are outside their coverage.

AI-assisted verification.

@shipped-it

Copy link
Copy Markdown

Tested ecbc6f7d4c9 on AMD Radeon RX 7900 XTX, RADV NAVI31 (Vulkan 1.4.354), Linux: build clean; full GPU suite on the PR head — 218/234 passed, 16 skipped, 0 failed; new fixtures cs_w32_f64inl and cs_w32_lit64 pass both in the full suite and filtered; semantic test_f64_inline+test_lit64_sext 6 tests OK. VERDICT: pass. AI-assisted (omp coding assistant).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

tools/rdna2spirv.py now widens 32-bit literals by the operand's type: sign-extended for i64 operands and zero-extended for b64/u64 ones, via a new imm64() helper. Float inline constants in 64-bit integer operands are converted to their f64 encoding through f64_inline() and the new INT64_SRCS table. Two GPU shaders (cs_w32_lit64, cs_w32_f64inl) with hand-derived words, semantic tests, fixtures and extensive design docs back the 144- and 243-case native gfx1036 measurements.

Why merge

The translator previously zero-extended every literal and rejected float immediates in 64-bit integer operands, misreading five i64 source forms and blocking valid shaders. Both behaviors are now measured against hardware and covered on GPU and CPU.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

tools/rdna2spirv.py now widens 32-bit literals by the operand's type: sign-extended for i64 operands and zero-extended for b64/u64 ones, via a new imm64() helper. Float inline constants in 64-bit integer operands are converted to their f64 encoding through f64_inline() and the new INT64_SRCS table. Two GPU shaders (cs_w32_lit64, cs_w32_f64inl) with hand-derived words, semantic tests, fixtures and extensive design docs back the 144- and 243-case native gfx1036 measurements.

Why merge

The translator previously zero-extended every literal and rejected float immediates in 64-bit integer operands, misreading five i64 source forms and blocking valid shaders. Both behaviors are now measured against hardware and covered on GPU and CPU.

Verdict: Approve

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.