Skip to content

rdna2spirv: accept null source operands on f64 VALU ops - #3230

Open
eIBart0 wants to merge 2 commits into
ItsNotRexed:mainfrom
eIBart0:fix-f64-null-src
Open

eIBart0 wants to merge 2 commits into
ItsNotRexed:mainfrom
eIBart0:fix-f64-null-src

Conversation

@eIBart0

@eIBart0 eIBart0 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

On RDNA2, the null special operand (0x7d) reads 0 (+0.0 in binary64), and VOP3 source modifiers (neg, abs) still apply to it (e.g., -null yields -0.0).

Previously, binary64 VALU ops in tools/rdna2spirv.py rejected null source operands with Unsupported: <op> operand.

Changes

  • tools/rdna2spirv.py: extract Gen.src_f64_words() handling {k: special, t: null} -> (0, 0) (preserving VOP3 abs/neg modifiers) and use it across all implemented binary64 VALU ops (v_add_f64, v_cvt_f32_f64, v_rcp_f64, v_rsq_f64, v_sqrt_f64, v_frexp_mant_f64, v_frexp_exp_i32_f64).
  • tests/semantic/spirv_mini_interp.py: add OpTypeFloat 64, %v2uint_d <-> %double OpBitcast, OpFConvert, and binary64 arithmetic / GLSL.std.450 support so f64 semantic tests execute bit-exact in spirv_mini_interp.
  • tests/semantic/test_f64_null_src.py: new CPU-only semantic suite assembling RDNA2 (llvm-mc -mcpu=gfx1013), translating with tools/rdna2spirv.py, assembling & validating (spirv-as, spirv-val --target-env vulkan1.2), and executing in spirv_mini_interp for both null (+0.0) and -null / abs(null) / -abs(null) across all implemented _f64 VALU ops.

Verification (CPU-only)

  • Negative control against origin/main (16282101): tests/semantic/test_f64_null_src.py ran 8 tests and failed with 45 subtest errors (Unsupported: <op> operand).
  • Positive: tests/semantic/test_f64_null_src.py — 8/8 OK.
  • Regressions: test_alu_frexp_f64.py (8/8), test_vop3_const_mods.py (11/11), test_vopc_const_ordered.py (6/6), test_valu_rcp_fdiv.py (33/33), test_valu_f32_transcendentals.py (11/11), test_value_semantics.py (33/33), test_f64_conversion.py (1/1), test_f64_output_modifiers.py (2/2), test_f64_transcendentals.py (2/2), test_docs_design_rows.py (2/2), test_spirv_interp_bits.py (4/4) — all OK.

Claimed in #3047 (issuecomment-7084462395).

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

tests/semantic/test_f64_null_src.py:54-58 resolves llvm-mc, spirv-as and spirv-val at import time and raises RuntimeError("missing required tool: ...") when one is missing. The semantic-tests job (.github/workflows/ci.yml:148-162) installs none of them. On main's last green CI run, both semantic jobs skip the SPIR-V checks for that reason (skipped 'SPIRV-Tools not installed', skipped 'needs spirv-as and spirv-val'), so this module will fail that job on both runners.

Reproduced on Linux, Python 3.12, with the tools off PATH: python -m unittest discover -s tests/semantic -p test_f64_null_src.py gives RuntimeError: missing required tool: llvm-mc, FAILED (errors=1). With the tools present it passes (8 tests). A lookup inside the tests with skipUnless, as test_bary_fallback.py:223 does, would keep it from failing the suite. The fallback paths (D:\Leonida-work\..., C:\VulkanSDK\1.4.341.1\...) only exist on one machine.

AI-assisted (Devin); Linux, no GPU.

@da1chan9ha0

Copy link
Copy Markdown

Independent Vulkan GPU check of 6fde2cdac09bfe282cea7f1afc50fadca04a3612 against 162821017ea3c286c8bec860f3ff94f037912061. Windows 11 build 26300, GeForce RTX 4070 Laptop GPU, NVIDIA 621.24, Vulkan 1.4.357, subgroup 32, shaderFloat64 = true. Synthetic gfx1013 compute shaders assembled with LLVM 23.1.5.

  • Main rejected each of the seven null-source fixtures at translation. The PR translated all seven, and they all passed spirv-val --target-env vulkan1.2 (SPIRV-Tools v2026.4).
  • On the GPU, all 36/36 output words matched across 22 cases covering v_add_f64, v_cvt_f32_f64, v_sqrt_f64, v_frexp_mant_f64, and v_frexp_exp_i32_f64. Cases included null, -null, abs(null), and -abs(null), with null in either source position for add. Conversion, sqrt, and frexp mantissa preserved the expected signed-zero bits. Both revisions also matched 52/52 words per revision from register controls, and all unwritten words retained their sentinel.
  • The v_rcp_f64 and v_rsq_f64 zero-input fixtures went through translation and SPIR-V validation only. GPU controls with a register input of 4.0 returned 0.25 and 0.5, respectively, on both revisions.

The PR's own CPU suite also passed 8/8 with the tools available. The GPU results cover Leonida's Vulkan translation on this NVIDIA device.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 6fde2cd 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: 143/189 passed, 46 skipped, 0 failed. main 1628210 gives 143/189, 46 skipped, 0 failed. All 194 test shaders translate and pass spirv-val.
  • tests/semantic/test_f64_null_src.py: ran 8 tests in 3.290s; OK.

AI-assisted (Claude Code).

@eIBart0

eIBart0 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed in 4e30ea53, @ray3242. Dropped the local fallback paths and import-time RuntimeError; using _find_llvm_mc() + @unittest.skipUnless and shutil.which guards in validate_spirv.

Checked without tools on PATH (Ran 8 tests, OK (skipped=8), exit 0), with llvm-mc only (8/8 OK), and with llvm-mc + SPIRV-Tools (8/8 OK).

@evilclanker9000

Copy link
Copy Markdown
Contributor

Measured on gfx1036 (RDNA2, driver 26.10.1, game MODE) through raw hw_oracle kernels, one lane: null as a source of the binary64 VALU ops. v_add_f64 v[8:9], null, v[2:3] and v[2:3], null with 1.5 give 3ff8000000000000 (null = +0.0); -null is -0.0 (v_add_f64 -null, -0.0 -> 8000000000000000, -null, -null -> -0.0) and |null| is +0.0 (|null| + -0.0 -> 0), so the VOP3 modifiers do apply to it, as this PR says. v_rcp_f64 of null -> +inf (7ff0000000000000), of -null -> -inf; v_rsq_f64 null -> +inf; v_sqrt_f64 null -> +0, -null -> -0 (8000000000000000); v_cvt_f32_f64 null -> 0x00000000, -null -> 0x80000000; v_frexp_mant_f64 null -> +0, -null -> -0; v_frexp_exp_i32_f64 of either -> 0. I did not run this PR's translation; the script is local, not pushed.
AI-assisted.

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Rechecked at 4e30ea53 with llvm-mc, spirv-as and spirv-val off PATH (Python 3.12.16): python -I tests/semantic/test_f64_null_src.py gives Ran 8 tests ... OK (skipped=8) instead of the import-time RuntimeError, so my point is resolved. CPU only. AI-assisted (Devin).

@Impre-visible

Copy link
Copy Markdown

Tested 4e30ea5 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression.

Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.

  • spirv-val on the modules the PR's semantic tests translate (test_f64_null_src.py): distinct modules: 52, pass spirv-val: 52, rejected: 0
  • tests/semantic: 4150 OK
  • build.py: 214 shaders, 214 translated, 214 pass spirv-val; check.py: 132 of 167 pass, 35 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 194 shaders: 194 translated, 194 pass spirv-val; 143/189 passed, 46 skipped, 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 174/189 passed, 15 skipped, 0 failed

AI-assisted run (Claude). Synthetic programs only, no game files involved.

@jmorrison102-dev

Copy link
Copy Markdown

Tested 6fde2cda (full suites) and 4e30ea53 (the new test file only; the translator is identical) on an RTX 4090: pass, no regressions, native and with LEONIDA_W64_EMULATE=1. The 8 new tests in test_f64_null_src.py pass; on main's translator 7 of them error with Unsupported: <op> operand, as expected.

Conditions: NVIDIA GeForce RTX 4090, driver 621.24, Vulkan 1.4.357 (subgroup size 32), Windows 11 Home 26H2 build 26300.10075; llvm-mc 21.1.8 (gfx1013), SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), Python 3.14.7.

Commits: 6fde2cda and 4e30ea53 (this PR), main f847748c. "merged" is f847748c with 6fde2cda merged locally (git merge --no-commit, clean, not pushed). 4e30ea53 changes only tests/semantic/test_f64_null_src.py; there it gives 8 / 0 / 0, native and W64.

Pass / fail / skip (build.py: translated / spirv-val valid, of all shaders):

main native main W64 6fde2cd native 6fde2cd W64 merged native merged W64
ctest 132 / 0 / 9 132 / 0 / 9 121 / 0 / 9 121 / 0 / 9 132 / 0 / 9 132 / 0 / 9
run_gpu_tests.py 153 / 0 / 46 184 / 0 / 15 143 / 0 / 46 174 / 0 / 15 153 / 0 / 46 184 / 0 / 15
build.py 224 / 224 of 224 224 / 224 of 224 214 / 214 of 214 214 / 214 of 214 224 / 224 of 224 224 / 224 of 224
check.py 139 / 0 / 35 170 / 0 / 4 132 / 0 / 35 163 / 0 / 4 139 / 0 / 35 170 / 0 / 4
tests/semantic 7322 / 0 / 0 7322 / 0 / 0 4150 / 0 / 0 4150 / 0 / 0 7330 / 0 / 0 7330 / 0 / 0
test_f64_null_src.py 1 / 7 / 0 1 / 7 / 0 8 / 0 / 0 8 / 0 / 0 8 / 0 / 0 8 / 0 / 0

No test passes on main and fails on merged; merged differs from main only by the 8 new tests. On main and merged, tests/semantic reports OK (expected failures=1): one @unittest.expectedFailure test (test_alu_min3_max3_med3_16_hw.py:625), counted as a pass. In the main column, test_f64_null_src.py runs against main's tools/ (7 errors, all rdna2spirv.Unsupported: <op> operand; the v_cmp/v_cmpx test passes on main too). The 6fde2cda counts are lower only because the branch predates 1,224 commits on main.

frexp literal: the new literal branch in src_f64_words can't be reached from v_frexp_mant_f64 / v_frexp_exp_i32_f64. tools/shader_ir.py:195-200 sets f64_literal only for v_add_f64 and v_cvt_f32_f64, so a literal reaches the frexp site as a plain imm. A throwaway check (17 cases, literal and inline sources) gave identical output on main and merged: dead code for frexp, not a behaviour change.

Overlap: open #2863 rewrites the same two operand blocks and adds both frexp ops to f64_literal, which would make this branch reachable, so the two PRs need merging in a deliberate order.

CI import: with llvm-mc, spirv-as and spirv-val hidden from PATH (LLVM_MC and VULKAN_SDK unset), 6fde2cda fails to import test_f64_null_src (RuntimeError: missing required tool: llvm-mc; the suite exits 1, main's passes), confirming ray3242's point. 4e30ea53 gives OK (skipped=8), exit 0.

Rebase: the branch was 1,224 commits behind main when tested, and it now conflicts with current main in tests/semantic/spirv_mini_interp.py. A rebase would make it easier to review.

Tested with AI assistance (Claude Code).

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Checked 4e30ea53 against current main 3faac557. tools/rdna2spirv.py merges cleanly; the only conflict is in tests/semantic/spirv_mini_interp.py.

The PR's ops still take null after the merge. Main has since gained five f64 readers with their own operand code, and those still refuse it.

Method. llvm-mc 21.1.8 (-mcpu=gfx1030) selected the legal forms. Every f64 source position took null, in e32 and e64. Each form went through rdna2spirv.translate as a one-instruction pixel shader, on main and on main merged with this PR.

Ops On main Main + #3230
v_add_f64, v_cvt_f32_f64, v_rcp_f64, v_rsq_f64, v_sqrt_f64, v_frexp_mant_f64, v_frexp_exp_i32_f64 16 forms refused all 16 translate
v_cmp_*_f64, v_cmpx_*_f64 (the 14 predicates that read their operands) 112 refused still refused (compare_f64_cond, read_f64_words)
v_cmp_class_f64, v_cmpx_class_f64 S0 4 refused still refused (cmp_class_f64)
v_trunc_f64, v_ceil_f64, v_rndne_f64, v_floor_f64 8 refused still refused (their own src chain)
v_div_fixup_f64 S0..S2 6 refused still refused (d64_words)
v_div_fmas_f64 S0..S2 6 refused still refused (its local f64)

v_div_scale_f64 is refused on main in every form, so it is not counted. The remaining readers repeat the pair / f64_literal / fimm cases that src_f64_words already has. A rebase could route them through it, so null reads +0.0 in every f64 source, as the PR's summary states.

Environment: Linux 7.0, Python 3.14.4, CPU only; llvm-mc on Linux 6.18. 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