Skip to content

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

Open
Vonsek wants to merge 7 commits into
ItsNotRexed:mainfrom
Vonsek:claude/hw-f64-inline
Open

Vonsek wants to merge 7 commits into
ItsNotRexed:mainfrom
Vonsek:claude/hw-f64-inline

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

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

@Vonsek

Vonsek commented Nov 22, 2026

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

Vonsek commented Nov 22, 2026

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

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.

9 participants