Repository navigation
rdna2spirv: demand-driven %fmt_dec_dyn for 1/2/3-component buffer_load_format - #811
SweatierKey wants to merge 2 commits into
Conversation
|
Tested
AI-assisted; synthetic fixtures only, no game data. |
qhukz13
left a comment
There was a problem hiding this comment.
Checked 7bddb1b (Linux, CPU only, no game files). Merges cleanly with current main.
- Tests pass:
tests/test_rdna2spirv_decode.py(26), and throughunittest discover(these files set up nosys.pathof their own)test_format_decode_table.py,test_buffer_formats_all.py,test_buffer_load_format.py,test_buffer_format_narrow_int.py,test_buffer_tbuffer_format_d16.py,test_tbuffer_load_format.py,test_buffer_format_d16_hi_absent.py. - The new
DST_SELbranch keeps the old mapping: 0 -> 0, 1 ->dst1(not gated byin_b, SHADER-429), 2/3 -> 0, 4..7 -> the decoded channel gated byin_b. - Mutations with
semantic_mutants(with #734's logic mutations), all seven format files run together:- the dynamic-channel block in
fmt_dec_component(k is None, lines 3329-3350): 30 of 30 caught; - the demand-driven
DST_SELbranch (lines 3698-3708): 17 of 19 caught, the d16 path included.
- the dynamic-channel block in
The two survivors are both on line 3698, the OpBitFieldUExtract of each output's DST_SEL:
UExtract->SExtractis equivalent: the value is compared unsigned (>= 4) and masked with& 3afterwards.- A field width of 4 instead of 3 survives, and that one is real: it mixes the low bit of the next output's
DST_SELinto this one, so an output withDST_SEL0..3 would read the decoded channel whenever the next selector is odd. One case pins it: a dynamic-formatbuffer_load_format_x(or_xy) whose x selector is 0 (or 1) and whose y selector is 5 must give 0 (or 1.0 / 1) in x, not the decoded channel.
Otherwise LGTM; the call-count drop on the large compute shaders is a nice win.
|
Thanks @qhukz13 for running |
|
Thanks — confirmed on 5c7a8bb: |
Claimed in the coordination issue as: SHADER-FMT-DEC-DEMAND (#14 (comment))
What and why
Previously, every dynamic-format
buffer_load_format_{x,xy,xyz,xyzw}(and_d16_{x,xy,xyz,xyzw}) calledformat_decode_call, which invoked all four per-component functions%fmt_dec_c0..c3even for 1-componentbuffer_load_format_xloads, then swizzled byDST_SELand discarded 1–3 decoded components (75% dead work for_x, 50% for_xy, 25% for_xyz). Large compute shaders with thousands ofbuffer_load_format_xinstructions emitted up to13,124%fmt_dec_c*calls per shader.This change introduces a single shared branch-free dynamic-channel helper
%fmt_dec_dyn(fmt, words, chan)(reusingGen.fmt_dec_component(None, params)with branch-freechan % ncompselection) used on demand by 1/2/3-component dynamic-format loads:buffer_load_format_x/_d16_xemits 1%fmt_dec_dyncall instead of 4 (-75%).buffer_load_format_xy/_d16_xyemits 2 calls instead of 4 (-50%).buffer_load_format_xyz/_d16_xyzemits 3 calls instead of 4 (-25%).buffer_load_format_xyzw/_d16_xyzwcontinues using%fmt_dec_c0..c3unchanged.<4-component loads omit%fmt_dec_c0..c3entirely; shaders mixing_xyzwand<4-component loads share a single%fmt_norm_bitsdefinition.DST_SELhandling (0 -> 0,1 -> dst1even when OOB per SHADER-429, reserved2/3 -> 0,4..7 -> in_b ? dec : 0withchan = sel & 3) is bit-exact with the 4-component path.Aggregate impact across 15 cached large compute shaders (counts only):
35,200 -> 8,849(-74.9%); SPIR-V lines drop from7,017,898 -> 6,915,894(-102,004lines). All modules passspirv-val --target-env vulkan1.2.Tested
python3 -I tests/test_rdna2spirv_decode.py: 26/26 passed (including newtest_format_decode_dyn_call_builds_and_caches_function).LEONIDA_REQUIRE_SPIRV_TOOLS=1 PYTHONPATH=tests/semantic:tools python3 tests/semantic/test_format_decode_table.py: 7/7 passed (exhaustive check across all 128 format codes with rotatedDST_SELon_xyz, all 8DST_SELvalues in-bounds & OOB on_x, mixed_xyzw+_xdeduplication of%fmt_norm_bits, branch-free verification, and exact call-count assertions).LEONIDA_REQUIRE_SPIRV_TOOLS=1 python3 -I scripts/run_semantic_tests.py tests/semantic: 465 files, 6111 tests, 0 failures.python3 -I tests/test_docs_links.py(16/16),python3 -I tests/test_text_write_line_endings.py(3/3),python3 -I scripts/check_no_game_data.py,python3 -m compileall -q make_game.py tools tests: all passed.vk_compute_test.exe+spirv-val --target-env vulkan1.2): all 7 format compute fixtures passed with 816/816 exact readback words (cs_buf_swizzle8/8,cs_fmt_101010264/64,cs_fmt_int_narrow136/136,cs_fmt_sint3264/64 exercising mixed%fmt_dec_dyn+%fmt_dec_c*,cs_fmt_all336/336,cs_fmt_xy_xyz128/128 exercising 22%fmt_dec_dyncalls,cs_fmt_d16_xyz80/80 exercising 6%fmt_dec_dyncalls).GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 616.92, Windows 11
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.