Repository navigation
rdna2spirv: f32 constants are module-scope OpConstants, not a bitcast at each use (-2.4% SPIR-V) - #4391
rdna2spirv: f32 constants are module-scope OpConstants, not a bitcast at each use (-2.4% SPIR-V)#4391mrp1no wants to merge 6 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Tested b8548bb on NVIDIA GeForce RTX 3070 (Ampere, 32-wide), driver 617.42, Windows 11 24H2. No result changes against
No game files. AI-assisted (Claude). |
|
Tested
No GPU, no game data. AI-assisted. |
|
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).
AI-assisted. |
TG0000
left a comment
There was a problem hiding this comment.
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 passedspirv-valon 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.pyandtest_alu_sincos.pypassed all 34 tests, including the comparison against the native assembler.
AI-assisted (OpenAI Codex). Synthetic inputs only.
|
Independent RTX 4080 check (Windows 10 22H2, driver 621.01): no result changes between
This checks the GPU fixtures, not whole-corpus pipeline creation or execution. |
|
Tested
Every test has the same result as on Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
|
APPROVE ( 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 Nits: no blank line between AI-assisted review, no game files, no GPU. |
|
Two unit tests under
Every failure is a missing pattern, for example: So the result itself isn't wrong: both tests need the same update Everything else here matches AI-assisted (Claude Code); I ran the tests and read the output. |
|
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
|
|
@troythedecoyx Thanks, you're right: I had only run
@tupacfan04 your two nits are in AI-assisted (Claude Code). |
|
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
These are translation, validation, and binary-size measurements, not pipeline compile time or runtime performance. |
|
Game-copy check of
|
|
Follow-up at |
|
Tested Ran the complete synthetic GPU suite with AI-assisted verification with synthetic inputs. |
|
Tested the current head
AI-assisted (Claude Code). |
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>
|
Merge-order note: |
|
Tested
Not run here: a corpus translation of my own copy (the shard checks above already cover that). |
|
Tested Corpus (CPU, counts only):
GPU / CPU
AI-assisted (Claude Code). |
|
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.
Counts only, no game data. AI-assisted (Claude). |
… 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>
|
Rebased onto
Both suites against a
AI-assisted (Claude Code). |
06218d9 to
18290ea
Compare
|
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. |
|
Re-checked the rebased head
The saving is the same 12,526,416 bytes I measured for AI-assisted. |
New SHADER item. Claim: #4257 (comment)
Gen.fconstwrote every f32 constant asOpBitcast %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 sameFLT_MINofflush_f32.Change
rdna2spirv. A finite normal f32 value, or +0, is now one module-scopeOpConstant %floatper value (%cf_<bits>), declared right after the module's uint constants.repr()of its exact value.spirv-asreads decimal straight to binary32, andtools/spirv_asm.pyreads it via binary64 (spirv_asm changes decimal f16 and f32 constant bits #3911). Both give these exact bits, because the value is exactly representable in both formats.fconsts_frozenis set once the module's constants are written. Anyfconstafter that point falls back to the bitcast, instead of naming a constant nobody declares, which is how%c80brokeaa2988cc(rdna2spirv: declare the format-size table's constants with the rest of them #4071).tests/semantic/test_module_float_constants.py.fconstwrites them, and checks every constant word: throughspirv_asm.pyalways, and throughspirv-aswhen it is on PATH.FLT_MINonce and still runs in the semantic interpreter.test_alu_sincos: its negative control sabotages 2*pi in the new form.Measured on my own 1.0.2.1 corpus (counts only)
mainaa2988ccspirv-valEvery 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
mainaa2988ccalready has:test_loop_ballot_barrier(5),test_cmp_class_f64(2) andtest_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.scripts/run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed. Same asmainon 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