Skip to content

rdna2spirv: f32 constants are module-scope OpConstants, not a bitcast at each use (-2.4% SPIR-V) - #4391

Open
mrp1no wants to merge 6 commits into
ItsNotRexed:mainfrom
mrp1no:shader-float-constants
Open

mrp1no wants to merge 6 commits into
ItsNotRexed:mainfrom
mrp1no:shader-float-constants

Conversation

@mrp1no

@mrp1no mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

New SHADER item. Claim: #4257 (comment)

Gen.fconst wrote every f32 constant as OpBitcast %float %c<bits> in the function body, at each use. On a corpus sample (133 shaders, 5.29 M body lines) that was 185,918 bitcasts, 3.5% of all body lines. 81% of them are the same FLT_MIN of flush_f32.

Change

  1. rdna2spirv. A finite normal f32 value, or +0, is now one module-scope OpConstant %float per value (%cf_<bits>), declared right after the module's uint constants.
  2. tests/semantic/test_module_float_constants.py.
    • Assembles 4,013 f32 patterns (edge values plus random normals) exactly as fconst writes them, and checks every constant word: through spirv_asm.py always, and through spirv-as when it is on PATH.
    • Checks which values are hoisted, and that nothing is hoisted after the freeze.
    • Checks that a translated module declares FLT_MIN once and still runs in the semantic interpreter.
  3. test_alu_sincos: its negative control sabotages 2*pi in the new form.

Measured on my own 1.0.2.1 corpus (counts only)

main aa2988cc this PR
shard 0/40, translated / spirv-val 663 / 663 663 / 663
shard 0/40, total SPIR-V 500.1 MiB 488.2 MiB (−2.4%), 623 modules smaller (median −1.7%, up to −4.2%)
20 largest modules 224 MiB 221 MiB

Every distinct constant the shard uses (13) assembles to its exact bits with both assemblers.

The saving is in bytes and ids. Drivers fold these bitcasts anyway, so this mostly shortens parsing and the module's id space. With #4345 (SHADER-771) the two together remove most of the per-flush overhead.

Tests

  • Semantic suite: 7,456 tests. The only failures are the ones main aa2988cc already has: test_loop_ballot_barrier (5), test_cmp_class_f64 (2) and test_mutations' legacy-multiply anchor (2, fixed by tests/semantic: re-anchor the v_mul_legacy_f32 mutation after the flush change #3883). test_alu_sincos' turn-scaling negative control looked for 2*pi as the uint literal; a third commit points it at the module-scope constant, and it still catches the sabotage.
  • GPU suite, RTX 3060 (NVIDIA 610.88, Windows 11), scripts/run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed. Same as main on the same machine.

Independent of #2298's optional optimizer pass. Counts only; no shader names or data from the corpus. AI-assisted (Claude Code).

🤖 Generated with 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.

Ran this at b8548bbb on Windows 11: tests/semantic/test_module_float_constants.py -> 4 tests, OK; tests/semantic/test_alu_sincos.py -> 30 tests, OK; git diff --check clean.

The translator now emits f32 constants as module-scope OpConstants instead of a bitcast at each use; the sincos test's sabotage was updated to the constant form, and both suites pass. No blocking issue.

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

AI-assisted Windows CPU review at b8548bbb. Scratch merging #4391 and #4345 (630a57d4) onto 03b09a08 in either order produced tree 7c0833495530dfbfce6f91f2165bb6253ade8d6a.

A synthetic pixel module with 770 repeated legacy MUL/MAD/MAC operations measured 809,508 bytes on main, 747,956 with #4391, 649,076 with #4345, and 599,876 combined (−25.90% for this fixture). Both assembler outputs agreed except for the generator word and all validated for Vulkan 1.2. All four trees returned the same interpreted output words, including the negative underflow zero and positive legacy zero. The combined focused semantic suites passed 44/44, and the 4,013-pattern checks passed with both assemblers.

An injected late fconst call confirms the freeze fallback when the uint backing constant already exists. A deliberately fresh late 7.25 still references a missing uint constant. This was a scratch-only injection, not an observed input regression. No GPU or corpus measurements.

@MKmajster

Copy link
Copy Markdown

Tested b8548bb on NVIDIA GeForce RTX 3070 (Ampere, 32-wide), driver 617.42, Windows 11 24H2. No result changes against main aa2988c, with only tools/ differing on the same runtime build:

  • run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed on both. All 210 result lines are identical.
  • valu_fuzz --family f16 --wave 32 and --family mem --wave 32 (seed 13, 150 programs each): 150/150 match on both.
  • Size: the suite's translated fixtures total 6,523,016 bytes of SPIR-V here vs 6,542,984 on main (−0.3%). These are small hand-written shaders with few f32 literals, so the corpus number in the description is the meaningful one.

No game files. AI-assisted (Claude).

@mrbean56

Copy link
Copy Markdown

Tested b8548bbb8f on Linux (Debian 13), Python 3.13.5, SPIRV-Tools v2026.4 built from release tag ef96ed7: pass.

  • python -I tests/semantic/test_module_float_constants.py: 4 tests OK. The 4,013-pattern sample (edges + random finite normals) assembles to the exact bit pattern through both tools/spirv_asm.py and spirv-as; the negative-zero, subnormal, Inf and NaN patterns stay as bitcasts.
  • python -I tests/semantic/test_alu_sincos.py: 30 tests OK, including the re-pointed turn-scaling negative control.
  • End to end, a synthetic PS using v_sin/cos/sqrt/rsq/rcp/log/exp/fract_f32 hoists %cf_00000000 = OpConstant %float 0.0, %cf_3e800000 0.25, %cf_3f000000 0.5 and %cf_40c90fdb 6.2831854820251465; the module passes spirv-val --target-env vulkan1.2 v2025.1 and the excluded values still use OpBitcast in the body.

No GPU, no game data. AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 no-regression check at head b8548bb (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build on AppleClang 17).

python -I scripts/run_gpu_tests.py --build runtime/build/linux: 213 shaders translated, 213 pass spirv-val; 127/210 passed, 76 skipped, 7 failed — identical to upstream/main aa2988c on this M2. The seven failures are the known MoltenVK expected set listed in PR #2909, none introduced by this change. Head fetched read-only, no rebase/edit/push. Synthetic shaders and counts only; no game files.

AI-assisted.

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

Compared b8548bbb with aa2988cc on Windows 11 build 26300, AMD Radeon RX 6800 (AMD 26.11.2 / 32.0.21045.29003, Vulkan 1.4.315), AMDGPU llvm-mc 23.1.5 and SPIRV-Tools v2026.4. Both runs used the same standalone Vulkan harnesses.

  • Native scripts/run_gpu_tests.py --require-pass: all 214 synthetic modules translated and passed spirv-val on both commits. Both runs reported 195 passed, 15 skipped and 0 failed. All 83 retained raw readbacks were byte-identical.
  • For the 214 indexed synthetic modules, total SPIR-V went from 6,541,344 to 6,521,376 bytes (−0.31%). 40 modules were smaller. This is a size measurement for the synthetic suite.
  • test_module_float_constants.py and test_alu_sincos.py passed all 34 tests, including the comparison against the native assembler.

AI-assisted (OpenAI Codex). Synthetic inputs only.

@Proudnoob4

Copy link
Copy Markdown
Contributor

Independent RTX 4080 check (Windows 10 22H2, driver 621.01): no result changes between 03b09a08 and b8548bbb, with the same Vulkan test binaries on both sides.

  • Both runs translated and validated all 214 GPU fixtures. Each full run exited 1 with 163 passes, 46 skips, and one setup error: ps_ssharp couldn't launch vk_sampler_test.exe (WinError 2).
  • After building that helper, the filtered ps_ssharp run passed at both revisions: eight cases, 4,096 pixels each, exact. Across the full run and filtered retry, that's 164 passes and 46 skips per revision. I did not rerun the full suite after building the helper.
  • At the PR head, test_module_float_constants.py (4 tests) and test_alu_sincos.py (30 tests) both passed.

This checks the GPU fixtures, not whole-corpus pipeline creation or execution.

@theswiss24

Copy link
Copy Markdown

Tested b8548bbb merged onto main 03b09a08 (clean) on two NVIDIA GPUs, test programs built from main 03b09a08: pass on both.

GPU driver, OS llvm-mc run_gpu_tests.py
RTX 4070 (Ada) 621.24, Windows 11 21.1.8 195/210 passed, 15 skipped, 0 failed
RTX 2060 SUPER (Turing) 580.178.04, Ubuntu 24.04 20.1.2 195/210 passed, 15 skipped, 0 failed

Every test has the same result as on main on both cards. LEONIDA_W64_EMULATE=1 on both. I haven't run a corpus comparison of the size change. No game files.

Tested and written by Claude (Claude Code), posting from @theswiss24's account.

@tupacfan04

Copy link
Copy Markdown
Contributor

APPROVE (b8548bbb) with nits, merge clean. New tests 4/4, test_alu_sincos 30/30, 159+53 targeted float tests, regen_fixtures --check and compileall clean. The full semantic suite has 7 failures/2 errors, but replaying those modules on base gives identical failures, so they are pre-existing. Negative control: on base the new tests fail (3/3 plus the reworked sin/cos sabotage).

Dedup works: one declaration per bit pattern, 4,013 decimal patterns round-trip through both assemblers, a translated PS validates, and the freeze is safe (no fconst calls after tools/rdna2spirv.py:12208).

Nits: no blank line between fconst_value and dconst (:5022); and +0/0.5/1.0 duplicate existing %f0/%fhalf_g/%f1 (:12131,12244) - e.g. both %f0 ... 0 and %cf_00000000 ... 0.0 appear, slightly undercutting the "one per value" claim.

AI-assisted review, no game files, no GPU.

@troythedecoyx

Copy link
Copy Markdown
Contributor

Two unit tests under tests/ (not tests/semantic/) fail with this PR and pass on main 03b09a08. They match the SPIR-V text of the scale constant, which is now %cf_<bits> instead of OpConstant %uint <bits> + OpBitcast:

test main 03b09a0 merged with b8548bb merged with d1d9a2f
python -I tests/test_f64_conversion.py OK (1 test) FAILED FAILED (failures=4)
python -I tests/test_rcp_iflag_mods.py OK (5 tests) FAILED FAILED (failures=14)

Every failure is a missing pattern, for example:

tests/test_f64_conversion.py:45  Missing SPIR-V instruction: OpConstant %uint 1073741824   (mul:2; also 0x40800000 mul:4, 0x3F000000 div:2)
tests/test_rcp_iflag_mods.py:72  Missing SPIR-V instruction: OpConstant %uint 1073741824   (and OpBitcast %float %c3f000000 / %c40800000)

So the result itself isn't wrong: both tests need the same update test_alu_sincos.py got, i.e. to look for %cf_40000000 = OpConstant %float 2.0 (or %fhalf_g for 0.5 after d1d9a2f). The full semantic suite only shows main's existing 7 failures and 2 errors, the same names as on main, which is probably why the earlier runs missed these two.

Everything else here matches main on an RTX 4060 Ti (Ada, 32-wide), NVIDIA 621.24, Windows 11, MSVC 2022, merged onto 03b09a08: ctest 154/154; run_gpu_tests.py 214/214 translated and pass spirv-val, 164/210 passed and 46 skipped with LEONIDA_W64_EMULATE=0, and 195/210 passed and 15 skipped with =1. Zero failures in both modes, the same as main.

AI-assisted (Claude Code); I ran the tests and read the output.

@Bushyon

Bushyon commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d1d9a2f on AMD Radeon RX 7800 XT (RDNA3), RADV Mesa 26.2.6 (ACO), Vulkan 1.4.354, subgroup 32..64, Fedora 44; llvm-mc 22.1.8, GCC 16.2.1. First AMD run. No GPU result changes against the base aa2988cc translator on the same runtime build (b8548bb gave the same):

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@troythedecoyx Thanks, you're right: I had only run tests/semantic on this branch. Fixed in the latest commit.

  • tests/test_f64_conversion.py and tests/test_rcp_iflag_mods.py now look for the scale as OpConstant %float <repr of the value>. That covers %cf_40000000 … 2.0, %cf_40800000 … 4.0 and %fhalf_g … 0.5.
  • I then ran the whole of tests/ outside tests/semantic and found a third test of the same kind, tests/test_translate.py::test_gather4_l_literal_lod_bounds_feed_mip_selection. Its MIN_LOD/MAX_LOD bounds 0.25 and 0.75 are now module-scope constants, and the test looks for them that way.
  • pytest tests --ignore=tests/semantic -n 10 (Windows 11, Python 3.15.2) now fails exactly as main does: the same 8 failures on both trees (test_build_llvm_mc_batch, test_meta_to_xml_paths, test_check_no_game_data, test_u16_high_half, each with its own open fix).

@tupacfan04 your two nits are in d1d9a2f9. +0, 1 and 0.5 are now %f0, %f1 and %fhalf_g, and the translated-module test checks that no two float constants share a value. The missing blank line is fixed too.

AI-assisted (Claude Code).

@Proudnoob4

Copy link
Copy Markdown
Contributor

Whole-corpus A/B on my 1.0.2.1 copy (Windows 10, Vulkan SDK 1.4.363.1). This is for the earlier head b8548bbb against 03b09a08; it does not cover the later translator change in d1d9a2f9.

  • All three runs translated 26,503 inputs: base with spirv-as, PR with spirv-as, and PR with --assembler python. All three validated exactly the same 26,422; the other 81 were already invalid at the base. I checked the eight shard markers and indexes per run against the merged indexes and actual module sets.
  • On the 26,422 matched modules, spirv-as output fell from 17,881.2 to 17,454.9 MiB (−2.38%). 24,579 modules shrank, none grew, and 1,843 were byte-identical. The 20 largest by baseline size went from 227.1 to 223.8 MiB.
  • On shard 0/40, all 663 inputs validated on both sides, and size fell from 500.1 to 488.2 MiB (−2.39%).
  • At b8548bbb, every one of the 26,422 validated binaries matched byte-for-byte between the two assemblers except for the generator word (0x70000 vs 0x0).

These are translation, validation, and binary-size measurements, not pipeline compile time or runtime performance.

@rafaelpssz

Copy link
Copy Markdown
Contributor

Game-copy check of d1d9a2f9, the "GPU; game copy" slot nobody had taken: shard 0/20 of my own 1.0.2.1 corpus (1,326 real shaders, every stage). Translated with main d0835dd9 and with this PR, both --no-asm, same spirv-val. Windows, counts only.

main #4391
translated 1,326 / 1,326 1,326 / 1,326
pass spirv-val 1,323 1,323
SPIR-V bytes (the 1,323 valid) 1,021,987,316 997,396,756 (−2.41%)
modules larger than on main – 0 (89 the same size, 1,234 smaller)

@Proudnoob4

Copy link
Copy Markdown
Contributor

Follow-up at 06238113 (Windows 10, same 1.0.2.1 shard 0/40): both spirv-as and --assembler python translated and validated all 663 inputs, and all 663 binaries match once the generator word is ignored. The matched output totals were 524,397,824 bytes at base 03b09a08, 511,877,904 at earlier head b8548bbb, and 511,871,408 at 06238113 (−2.39% vs base). 379 binaries changed between the two PR revisions. The updated f64, reciprocal, module-constant, and literal-LOD checks also pass here (11 targeted tests). This rerun covers the shard only; the whole-corpus result above remains pinned to b8548bbb.

@Kev-Ball

Copy link
Copy Markdown

Tested 06238113 on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the complete synthetic GPU suite with LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --require-pass. 195/210 cases passed, 15 skipped, 0 failed. This is translated GPU execution with wave64 emulated on 32-lane Ampere subgroups.

AI-assisted verification with synthetic inputs.

@ricardotanaka

Copy link
Copy Markdown

Tested the current head 06238113 merged onto main 3eb4410b (clean) on AMD Radeon RX 7600 (RDNA 3, subgroup 32..64) with the AMD Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11 Pro 26200, MSVC 19.44, Vulkan SDK 1.4.363.0: pass, no result changes. The run above on RDNA 3 used RADV on Linux, so this is the first one on AMD's own compiler.

  • One runtime build (scripts/build_runtime.ps1 on the merged tree). scripts/run_gpu_tests.py --build <that build> from this head and from main 3eb4410b, natively and with LEONIDA_W64_EMULATE=1.
  • All four runs: 202/217 passed, 15 skipped, 0 failed.
  • Head vs main, per mode: the same 217 PASS/SKIP lines, test by test. The only difference is the temp folder in the paths.

AI-assisted (Claude Code).

mrp1no added a commit to mrp1no/Leonida that referenced this pull request Nov 23, 2026
It sat between self.consts and self.n, the lines ItsNotRexed#4391 also adds to, so the two PRs conflicted there whichever
merged second. No change in behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Merge-order note: 06218d94 makes test_which_values_are_hoisted build a whole Gen("ps") instead of Gen.__new__ with a few attributes. Its fallback for -0/subnormal/inf/NaN calls tof, which keeps state of its own once #4510 lands, so the old test failed on the merge of the two PRs. With this commit, and #4510's bb4548f9 (no more adjacent edits in Gen.__init__), the two merge cleanly and pass together on main 0db7fed5. No translator change. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 06218d94 merged with main 7b7d73f8 on Windows 11, RTX 4080 SUPER + Intel UHD 770 (MSVC 14.51): pass, no GPU result changes. (The GPU suites ran at the previous head 06238113; 06218d94 differs from it only in tests/semantic/test_module_float_constants.py, so the translator the GPUs ran is the same. That test I re-ran at 06218d94.)

  • Full runtime build at the merge (504 targets), then scripts/run_gpu_tests.py --build runtime/build (217 cases, llvm-mc 23.1.6, spirv-as from the Library bin):
    • RTX 4080 SUPER: 170 passed, 47 skipped, 0 failed.
    • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*): 150 passed, 67 skipped, 0 failed.
  • Control: main 7b7d73f8 (its own tools/, scripts/ and test shaders) against the same test programs, same machine: 170/47/0 on NVIDIA and 150/67/0 on Intel, and the per-case PASS/SKIP lists are identical to the PR's on both GPUs.
  • tests/semantic/test_module_float_constants.py (4 tests, none skipped with spirv-as on PATH; at 06238113 it had 1 skipped without it), test_alu_sincos.py (30), tests/test_f64_conversion.py, tests/test_rcp_iflag_mods.py and tests/test_translate.py all OK at the merge.
  • Negative control (tools/rdna2spirv.py from main, everything else from the PR): test_module_float_constants.py (at 06218d94) gives 2 failures + 2 errors and test_alu_sincos.py 1 failure.

Not run here: a corpus translation of my own copy (the shard checks above already cover that).

@lunarminus

Copy link
Copy Markdown

Tested 06218d94 merged onto main d0835dd9, with the full game corpus of my own 1.0.2.1 copy and on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass. I ran the corpus at 06238113. tools/rdna2spirv.py is identical between that head and 06218d94; only tests/semantic/test_module_float_constants.py changed.

Corpus (CPU, counts only): rdna2spirv.py --shard i/8 ×8 + --merge, native mode as make_game.py picks it on this GPU, d0835dd9 vs this PR:

translated spirv-val-valid
d0835dd9 26,503 26,422
this PR 26,503 26,422
  • The 81 invalid modules are the same set with the same error ("requires a previous definition", the aa2988cc regression Translator: constants assemble asks for late are defined too #3902 fixes). No module becomes invalid.
  • 24,579 of the 26,422 valid modules change.
  • The reflection data in index.json is identical for all 26,422. That covers bindings, push-constant bytes, capabilities, extensions, features, inputs/outputs, interpolants, subgroup size and the wave64 fields.

GPU / CPU

  • scripts/run_gpu_tests.py: 196/210 passed, 14 skipped, 0 failed, native and with LEONIDA_W64_EMULATE=1. 214/214 translated and valid. Every test line is identical to d0835dd9 without the PR, in both modes.
  • tests/semantic/test_module_float_constants.py + test_alu_sincos.py: OK.
  • pytest tests/test_f64_conversion.py: 1 passed (6 subtests). tests/test_rcp_iflag_mods.py: 5 passed (23 subtests).

AI-assisted (Claude Code).

@VeTkN

VeTkN commented Nov 23, 2026

Copy link
Copy Markdown

Complement to the full-corpus run above, which used native mode: the same pair in --wave64-emulate mode (what make_game.py picks on a 32-wide GPU). d1d9a2f merged onto main d0835dd (clean) against d0835dd; tools/rdna2spirv.py is the same at the current head 06218d9. All 26,503 listings of my own 1.0.2.1 package (llvm-mc 21.1.8), Windows 11, Ryzen 5 5500X3D, Python 3.14.7, SPIRV-Tools v2026.4.

  • Translated: 26,503 / 26,503 on both. Pass spirv-val: 26,473 on both, the same modules (0 lost, 0 new). The 30 invalid ones fail with the same error class ("requires a previous definition") on both sides.
  • Total SPIR-V: 17,988.7 MiB on main, 17,562.1 MiB with this PR (−2.37%).
  • 24,602 modules changed, all smaller (median −1.69%, at most −4.54%); 1,871 are byte-identical.
  • test_module_float_constants.py: 4 tests OK. test_alu_sincos.py: 30 tests OK.
  • Control: translating 665 of main's modules a second time gave identical bytes.

Counts only, no game data.

AI-assisted (Claude).

mrp1no and others added 6 commits November 23, 2026 12:39
… at each use

Gen.fconst wrote every f32 constant as OpBitcast %float %c<bits> in the
function body at each use. On a corpus sample that was 3.5% of all body
lines (185,918 of 5.29 M over 133 shaders), 81% of them the FLT_MIN of
flush_f32.

A finite normal value or +0 is now one OpConstant %float per value,
declared with the module's uint constants and written as repr() of its
exact value: spirv-as reads decimal straight to binary32 and
tools/spirv_asm.py via binary64 (ItsNotRexed#3911), and both give these exact bits
because the value is exactly representable in both. -0, subnormals, inf
and NaN keep the bitcast. fconsts_frozen is set when the module's
constants are written, so an fconst after that falls back to the bitcast
instead of naming a constant nobody declares (the %c80 failure ItsNotRexed#4071
fixes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…semblers

test_module_float_constants.py assembles 4,013 f32 bit patterns (edge
values and random normals) as fconst writes them and checks every
constant word: through tools/spirv_asm.py always, and through spirv-as
when it is on PATH. It also checks which values are hoisted (normals and
+0, not -0, subnormals, inf or NaN, nothing after the freeze) and that a
translated module declares FLT_MIN once and still runs in the semantic
interpreter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The turn-scaling negative control looked for 2*pi as the uint literal
1086918619 (0x40c90fdb) that the per-use bitcast referenced. It is now the
module-scope constant %cf_40c90fdb = OpConstant %float <exact decimal>, so
the control finds that line and sabotages its value to 1.0. It passes with
this branch and still fails the sabotaged module; with main's translator
it fails at the lookup, as it should.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fhalf_g

Every module already declares %f0 and %f1, and %fhalf_g when uses_fhalf is set, so a hoisted %cf_ of the same value
was a second declaration of it (@tupacfan04's review). fconst now returns those, and the translated-module test
checks that no two float constants have the same value. Also the missing blank line before dconst.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_f64_conversion and test_rcp_iflag_mods looked for an output modifier's scale as `OpConstant %uint` + `OpBitcast
%float`, and test_gather4_l_literal_lod_bounds_feed_mip_selection did the same for its MIN_LOD/MAX_LOD bounds. fconst
now declares them as `OpConstant %float` with repr() of the value (%fhalf_g for 0.5), so they look for that
(@troythedecoyx's review). tests/ outside tests/semantic now fails exactly as main does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It made one with Gen.__new__ and set only the attributes fconst used. The fallback for -0, subnormals, inf and NaN
calls tof, so once tof keeps state of its own (ItsNotRexed#4510's bitcast_from) that Gen lacked it and the test failed on the
merge of the two PRs. Gen("ps") has every attribute; the uses_fhalf check reads its initial False.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 561b65a8 (now 18290ea0). Two conflicts in tools/rdna2spirv.py, both with both sides kept:

Both suites against a 561b65a8 baseline on the same machine (Windows 11, CPython 3.15, llvm-conda tools on PATH):

  • pytest tests/semantic -n 10: no failures, the same as main.
  • pytest tests --ignore=tests/semantic -n 10: the same 8 failures as main, all outside the translator (bcpack/bink/first_look/opus/world_names host-permission tests and the llvm-mc parity fixture). No new ones.

AI-assisted (Claude Code).

@mrp1no
mrp1no force-pushed the shader-float-constants branch from 06218d9 to 18290ea Compare November 23, 2026 12:06
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 18290ea on AMD RADV RAPHAEL_MENDOCINO (Ryzen 9 9950X3D iGPU), subgroup 32..64: the full run_gpu_tests.py suite prints "216/232 passed, 16 skipped" with no FAIL lines; the skips are the rows that are run by a d3d12 test (vs_m3, vs_m2, ps_m3 and similar). tests/test_translate.py gives 633 passed, tests/test_f64_conversion.py and tests/test_rcp_iflag_mods.py 6 passed, and tests/semantic test_module_float_constants (4 tests) and test_alu_sincos (30 tests) pass. I did not run main on this GPU, so I cannot compare the fixture counts with an earlier baseline.

AI-assisted.

@Proudnoob4

Copy link
Copy Markdown
Contributor

Re-checked the rebased head 18290ea0 on my own 1.0.2.1 corpus (shard 0/40, counts only). Windows 10, CPU only.

  • Validation. I ran main 561b65a8 with spirv-as, and this head with spirv-as and with --assembler python. Each gives 663 / 663 translated and passing spirv-val, on the same 663 modules.
  • Assemblers. At this head both assemblers give byte-identical modules, apart from the generator word, in 663 / 663.
  • Size. SPIR-V goes from 426,681,524 to 414,155,108 bytes (−2.94%). 623 modules are smaller, 40 the same size and none larger. The changed ones have a median of −2.01%, ranging from −0.11% to −5.25%.
  • Tests. test_module_float_constants (4) and test_alu_sincos (30) pass.

The saving is the same 12,526,416 bytes I measured for 06238113 against 03b09a08. The percentage is higher only because main's own output for this shard dropped from 524,397,824 to 426,681,524 bytes in between. I didn't rerun the whole corpus at this head.

AI-assisted.

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.