rdna2spirv: decode only the components a typed load writes; fconst is an OpConstant (SHADER-FORMAT-DECODE-ONE-COMPONENT) #2439
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2439
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2439"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@OreoFR on GitHub · 2026-11-27 07:58 UTC · original
OreoFR:shader-format-decode-one→main· +498 −113 · 18 files · 3 commits · merged 2026-11-27 11:48 UTCClaimed in the coordination issue as: SHADER-FORMAT-DECODE-ONE-COMPONENT
What and why
Two code-size changes in
tools/rdna2spirv.py. Neither changes a value.A typed load decodes only the components it writes. A
buffer_load_format_*that takes its format from the V# went through four shared functions,%fmt_dec_c0…%fmt_dec_c3, and every load called all four, even_x. There is now one function,%fmt_dec(format, element, component). A load calls it once per register it writes, with the component that register's DST_SEL field picks (DST_SEL - 4). For DST_SEL 0, 1 or a reserved code,kwraps past 3 and the call's value is thrown away, as before. So_xmakes 1 call,_xy2 and_xyzw4. The function body is the old per-component code: it computes the channel width and bit offset for each of the four components, as before, and the component parameter picks one with three selects. The rest of the decode is shared and unchanged. It is the same value by construction. The DST_SEL chain at each site is nowsel - 4 < 4 ? bounded(decode(sel - 4)) : sel == 1 ? one : 0, the same function ofselas the old five-way chain. MTBUF (tbuffer_load_format_*, a fixed format) and the stores are not touched. A store already makes one encode call per site.fconstgives anOpConstant %float.fconstused to emit a newOpBitcast %floatof the uint constant at every use, and so didtofof a uint constant (float literal operands). Both now return one cachedOpConstant %floatper bit pattern:%f0and%f1for 0 and 1,%fc<bits>for the others.touof such a constant gives the uint constant back, as it did through the bitcast.float_literalwrites the literal so that it assembles to the same 32 bits:0x1.8p+128, payload as stored).Checked on 24 tricky patterns, NaN payloads included, with SPIRV-Tools 2026.4
spirv-asandtools/spirv_asm.py. The three test interpreters (spirv_mini_interp,spirv_wave_interp,tests/spirv_interp.py) now read that hex-float spelling. Before, onlyspirv_asmdid. Two tests that inspected the old bitcast form now follow the constant (test_alu_sincos's sabotage control,test_image_store_dmask's analyzer), and so doestest_bitcast_round_trip's bareGen.New tests:
tests/semantic/test_buffer_format_decode_one.pywith the hand-written fixturesfixtures/typed_load_runtime_{x,xy,xyzw}.asm. The V# comes from the push constants, so the format and DST_SEL are run-time values. The test counts theOpFunctionCalls to%fmt_decper load (1, 2 and 4). It checks the values against the reference decode for 15 formats and a code outside the table, with identity, swizzled, constant and reserved selectors, and out of bounds. It also checks that_xand_xymatch the first registers of_xyzwfor all 128 codes with random selectors.tests/semantic/test_fconst_constant.py: the literal assembles back to the same bits (+-0, the smallest and largest denormals, the largest finite values, +-inf, quiet and signalling NaNs with payloads), one constant per value with no instruction emitted, and a translated module (v_sin_f32,v_cvt_norm_i16_f16) whose constants keep their bits and still give the expected words.The
docs/design.mdrow "Run-time format decode cost" described the four functions. It now describes the one function and how it was checked. No rule changes.Tested
Translator suite,
python -I scripts/run_semantic_tests.py tests/semantic: 502 files, 6,385 tests, 0 failed (plainmain: 500 files, 6,374 tests, 0 failed). The standalonetests/test_*.pythat translate or interpret SPIR-V pass too: 67 underpython -I, and 1,406 pytest tests withtests/requirements.txt.test_rcp_iflag_modsandtest_translate's gather LOD-bounds test now expect the float constant.Equivalence with
main: 22,528 typed loads through the mini interpreter, all bit-identical, translated bymainand by this branch. The loads covered_x,_xy,_xyz,_xyzw,d16_x,d16_xy,d16_xyzandd16_xyzw, all 128 format codes, random DST_SEL, byte alignments 0-3,num_recordsfrom 0 to in bounds, and random words plus NaN, infinity and denormal patterns. That script is local only.tools/buffer_format_fuzz.py --self-test: ok before and after. Its other modes need an AMD hardware oracle, and the translator side of its model istest_buffer_formats_all.py, which passes.GPU tests (
scripts/run_gpu_tests.py, llvm-mc 23.1.6):cs_buf_fmt8,cs_fmt_1010102,cs_fmt_d16_xyz,cs_fmt_int_narrow,cs_fmt_sint32,cs_fmt_xy_xyz,cs_fmt_all(336/336 words) andcs_tbuffer_store;d3d12_buffer_uav_test(cs_buf_typed, typed buffer UAVs) passes: 21,394 values, error 0;mainwith the same build on this GPU:cs_imgatomic_ext(6 of 64 sint words) andcs_texture_uav(a format without formatless storage access).Corpus slice (
--limit 300 --wave64-emulate): 300 translated and 300 passspirv-val, onmainand on this branch. The modules go from 78,480,168 to 74,512,388 bytes (−5.1%).Module size, 3 shaders retranslated locally with the make_game flags (
--wave64-emulate). Every module passesspirv-valbefore and after:%fmt_deccalls…CS_ScreenProbes_ActivateProbes…CS_RaytracingResolve_…The claim estimated −28% for ActivateProbes with single-component loads. The real gain is smaller. In a minimal program, a
_xload costs 200 instructions at its site onmainand 189 here (_xyzw: 236 → 216). The calls and the select chain were only a small part of it. The rest is the address, the bounds check, the five dword loads, the window shift and the DST_SEL kind test, and this PR does not change any of that. On top of that, each module drops three of the four decode bodies. 3,281 sites × 11 instructions is about the 36,900 instructions that ActivateProbes loses. I did not measurevkCreateComputePipelinestime: a retail test run was using the GPU.GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11.
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no behaviour change)🤖 Generated with Claude Code
@ecox982745 on GitHub · 2026-11-27 08:19 UTC · original
First compute pipeline creation on RTX 4090. I compared
22a8be16cwith its parentd1dff7949on Windows 11, NVIDIA 616.64. With eight typed loads, the median first creation went from 154.8 to 68.0 ms for_xand from 160.6 to 179.3 ms for_xyzw. The PR was faster in all 72 paired measurements of_x,_xyand_xyz. Full-width loads were slower in 23 of 24 pairs, even though their binaries also shrank._x_xy_xyz_xyzwEach row uses synthetic, wave64-emulated compute programs with a runtime buffer descriptor. The eight sites read distinct offsets 256 bytes apart. All components returned by each load feed a per-lane integer checksum. I checked the emitted decoder call counts: four per site on the base and one through four on the PR, according to width.
Method. For each site count and width I varied a live integer literal across 12 matched program pairs, shuffling pair order and running each revision first six times. Each module ran in a fresh process. I timed only
vkCreateComputePipelines, with a null application pipeline cache, driver caching left enabled, and validation off. Times in the table are per-revision medians. Percentages are median paired changes. Immediate recreation on the same device took 3.0–6.3 µs across the group medians.Correctness. All 192 timed dispatches matched the CPU reference for their 64 output words and preserved every other word in the 4 KiB buffer. The timed case used RGBA8_UINT with a Z/X/W/Y swizzle. I then reused one pair per shape with an RGBA32_UINT descriptor selecting W/1/Z/X. All 16 of those dispatches matched under Khronos validation, with zero validation errors. All 192 timed modules passed Vulkan 1.2 SPIR-V validation.
These measurements cover first pipeline creation for small synthetic modules on this driver. The size and load-width mix of a game module could change its result. Measurement claim
@GrahamboJangles on GitHub · 2026-11-27 09:15 UTC · original
Reviewed head
22a8be16cvs based1dff7949on Windows 11, CPython 3.13.14 (and reran the quick suites on 3.14.9), no GPU, no game data. Coordination re-read first: both #1608 entries for this item readdone: SHADER-FORMAT-DECODE-ONE-COMPONENT -> #2439, and no other open PR carries the tag. @ecox982745's RTX 4090 timing comparison is independent of what I ran below.Passing at head (Windows, python3 -I, per file): the two new suites
test_buffer_format_decode_one.py6 OK (1.8 s) andtest_fconst_constant.py5 OK; the rewrittentest_format_decode_table.py4 OK; and the touched consumers untouched-count-wise:test_rdna2spirv_decode.py25 OK,test_rcp_iflag_mods.py5 OK,test_alu_sincos.py30 OK,test_bitcast_round_trip.py3 OK,test_image_store_dmask.py13 OK. Method counts base→head for every modified test file are unchanged (4→4, 25→25, 5→5, 30→30, 3→3, 13→13): the new coverage is the two new files (+6 and +5 methods) plus tightened assertions, nothing replaced.py_compileclean on all touched .py including both interpreter edits. (tests/test_translate.pyneeds pytest, which isn't on this box — not run here.)Discrimination run: copied the base
d1dff7949tools/into a scratch tree together with the head branch's wholetests/semantic/layer, then ran head's test files against the base translator:test_format_decode_table.pyFAILED 2/4 (the shared-decode pin wants%fmt_dec = OpFunctionwith the%uintcomponent parameter; base emits%fmt_dec_c0..c3per-component functions),test_buffer_format_decode_one.pyFAILED 3/6,test_fconst_constant.pyFAILED (10 failures, 54 errors). So all three new/changed pins genuinely catch the old emit. And the failures are confined to shape/count pins — the value-by-value fixtures elsewhere agree between old and new output, which matches the PR's "values bit-identical" claim on the paths I can run.One trap worth recording for future reviewers: pointing
LEONIDA_TOOLS_DIR/PYTHONPATHat a basetools/copy does NOT swap the translator for the semantic suite —tests/semantic/support.pysits in the script directory and shadows it (sys.path[0]). The mixed-tree copy above is what actually works.What I did not check here: the GPU side (first-pipeline-creation timings, shader-size deltas on the RTX 4090 are @ecox982745's, reproduced below), and the corpus-wide 22,528-typed-load comparison is the author's. What I verified is the interpreter-side contract: values identical, shared decode function shape pinned (and its size bound
test_the_decode_is_smallstill passing),fconstnow a realOpConstant %floatwith bitcast removal, and the single rewritten line indocs/design.md(the run-time format decode cost row) now matches the emitted shape I saw: one shared%fmt_decwith the component as the last parameter, called once per written register.Merge state at read time:
mergeable=true,mergeStateStatus=unstable, checks still settling, none failed.No findings on the change. AI-assisted (Hermes agent); the runs above are reproducible on any CPython box without a GPU.
@GrahamboJangles on GitHub · 2026-11-27 10:17 UTC · original
Heads-up: stdlib-tests-linux is red at this head —
tests/test_f64_conversion.pystill pins the old uint-constant-plus-bitcast scale shape that this PR removes.Failing job: https://github.com/ubiquitarianism/leonida/actions/runs/45962173838/job/140385835209 —
test_output_modifiersfails 4/4 parametrized cases (mul:2,mul:4,div:2,clamp div:2),check_conversionline 45:Reproduced locally at this head (
22a8be16cd), pure Python, no GPU:Root cause is exactly the fconst change. For the
mul:2scale the old translator emits, on main:and at this head:
So the disassembly no longer contains an
OpConstant %uint <bits>for the scale, and the test's pin (result(rf"OpConstant %uint {scale_bits}")followed byOpBitcast %float {constant}) can never match. The other suites this PR touches stay green, and #2438 / #2435 havestdlib-tests-linuxpassing, so the regression is specific to this branch —tests/test_f64_conversion.pyis just not in the PR's changed-file set.The emitted form looks semantically fine: the literals here (2.0, 4.0, 0.5) are exact f32 and the
%fc<bits:x>id encodes the exact bit pattern, so a minimal fix is to re-pin the test to the new shape rather than revert anything, e.g. incheck_conversionreplace the constant/bitcast pair with:which keeps the bit-exactness assertion (the id names the raw bits) without pinning the literal's textual form. Everything before/after that section of
check_conversionmatched the new emission unchanged in my run, so this is the only stale pin.Environment for the local runs: CPython 3.13.14 (the repo's activated venv), Windows host, repo clone at head via
gh pr checkout, exact commandpython tests/test_f64_conversion.py -v.@timbot103 on GitHub · 2026-11-27 10:41 UTC · original
Independently verified head
22a8be16con Windows 11 Pro 26200, Vulkan SDK1.4.363.0, WSLllvm-mc 21.1.8, across both NVIDIA GeForce RTX 5080 (Blackwell, driver616.64) and AMD Radeon(TM) Graphics (driver25.10.30.02), no game files:test_buffer_format_decode_one.py: 6/6 OKtest_fconst_constant.py: 5/5 OKtest_format_decode_table.py: 4/4 OKtest_bitcast_round_trip.py: 3/3 OKtest_alu_sincos.py: 30/30 OKtest_image_store_dmask.py: 13/13 OKtools/valu_fuzz.py --wave both --emulate --programs 120 --seed 20261126(960/960 shader executions matched):--family mem: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)--family f16: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)--family mem: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)--family f16: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)scripts/run_gpu_tests.py --require-passwithLEONIDA_VK_VALIDATION=1:--filter cs_fmt(cs_fmt_1010102,cs_fmt_d16_xyz,cs_fmt_int_narrow,cs_fmt_sint32,cs_fmt_xy_xyz): 5/5 PASS on RTX 5080 and 5/5 PASS on AMD Radeon, 0 validation errors.--filter cs_buf(cs_buf_fmt8,cs_buf_load_sub,cs_buf_swizzle,cs_buf_tail): 4/4 runnable PASS on RTX 5080 and 4/4 runnable PASS on AMD Radeon, 0 validation errors (cs_buf_counterandcs_buf_typedskipped as expected).No regressions observed on Blackwell or AMD Radeon. AI-assisted.
@aslan2142 on GitHub · 2026-11-27 10:48 UTC · original
Reviewed at
22a8be16c. Holding for one fix.tests/test_f64_conversion.pyhas 4 failures (thestdlib-tests-linuxcheck is red) and passes onmain. It still expectsOpConstant %uintwhere this change now emits a float constant. If the new constant is intended, update the test; if not, the rule changed more than it should.main2859d0c9b, its own new tests andtest_ci_registrationpass, and the Wine suite on the integrated RDNA2 GPU (RADV, Mesa 26.3.1) shows no test going from pass to fail beyond two known flaky ones.AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
@OreoFR on GitHub · 2026-11-27 11:33 UTC · original
Fixed in
53d138d2d, on top of a merge of currentmain(63185f4a3, which includes #2418, #2440 and #2432; no conflicts).The 4 failures were the
mul:2,mul:4,div:2andclamp div:2cases oftest_output_modifiers. All 4 were about the text form only. The constant is intended:fconstandtof()of a uint constant now emit one cached%fc<bits> = OpConstant %floatinstead ofOpConstant %uintplus anOpBitcastat each use. The values are unchanged. I checked this by translating all 6 cases withmain'stools/and with this branch's, and comparing the two:OpFConvertis identical once the bitcast is replaced by the float constant and the temporary ids are renumbered.spirv-asandspirv-val --target-env vulkan1.2, and its binary holds a 4-wordOpConstantwhose value word is exactly that bit pattern.Test change (
tests/test_f64_conversion.py): the check now looks for%fc<scale bits> = OpConstant %float <lit>and asserts that<lit>gives back exactlyscale_bitsas an f32. It then expectsOpFMulwith that id. The rest of the data flow is pinned as before (the clamp NaN select,FClamp, the bitcast to uint and the store).Local runs (Windows 11, CPython 3.13,
python -I, no GPU):tests/test_f64_conversion.py: OK.stdlib-tests-linuxloop (same file filter as ci.yml): 508 files and 8334 tests. 5 files fail here, and each fails the same way onmainon this Windows host.test_run_game_wineneedsfcntl.test_bink_names,test_opus_tags,test_world_namesandtest_calibrated_texture_extracheck Windows path or permission messages. None of them comes from this change.scripts/run_semantic_tests.py tests/semantic: 502 files, 6385 tests, 0 failed.scripts/check_no_game_data.pyon the changed files: clean.AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-27 11:48 UTC · original
Merging
53d138d2donmain63185f4a3.tests/test_f64_conversion.pyhold from22a8be16cis fixed (checks%fc<bits> = OpConstant %floatand its f32 bit round-trip).53d138d2d(Linux,python3 -I, no game data):test_ci_registration.py(18/18), fullstdlib-testsloop (508/508 files),run_semantic_tests.py(502 files, 6,385 tests, 0 failed),pytest tests/test_translate.py(720 passed),buffer_format_fuzz.py --self-test,spirv-as/spirv-val(24/24TRICKYliterals bit-exact andtyped_load_runtime_{x,xy,xyzw}valid), andcheck_no_game_data.pyclean.22a8be16c, which already passed independent GPU checks on RTX 4090 (@ecox982745), RTX 5080 and AMD Radeon (@timbot103), and the Wine iGPU suite (RADV, Mesa 26.3.1).AI-assisted review (Antigravity, Gemini).