mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:20:53 +01:00
[PR #829] [CLOSED] rdna2spirv: branch-free table-driven %fmt_encode_fn and %fmt_size_tab reuse #865
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#865
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/829
Author: @SweatierKey
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:feat/fmt-encode-table📝 Commits (1)
ff1dd9crdna2spirv: branch-free table-driven %fmt_encode_fn and %fmt_size_tab reuse📊 Changes
3 files changed (+460 additions, -47 deletions)
View changed files
📝
docs/design.md(+1 -1)➕
tests/semantic/test_format_encode_table.py(+230 -0)📝
tools/rdna2spirv.py(+229 -46)📄 Description
Claimed in the coordination issue as: SHADER-FMT-ENCODE-TABLE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7134102086)
What and why
Previously,
Gen.format_encode_callemitted%fmt_encode_fnas a 77-branch sequentialif (fmt == code) { ... OpReturnValue; }chain (3,973 instructions, 154 branch/merge ops) plus a separate 157-instruction linear-select%fmt_size_fn(4,130 lines total). Shaders with multiple dynamicbuffer_store_format_*calls (such ascompute_graph_opswith up to 16 calls per shader) caused driver compilers to inline tens of thousands of instructions and thousands of branches.This change brings the store path up to parity with
SHADER-849's branch-free table-driven decode:%fmt_enc_tabpacking(enc_kind:4 | ncomp:3 | widths[0..3]:24 | br_swap:1)into 32 bits per 7-bit format code.%fmt_enc_chan(%v4uint_fmt)(134 lines, 0 branches) handling all 11 format kinds (f32,u32,i32,uint,sint,f16RTZ + NaN payload, single-rounded 64-bitunorm/uscaled/snorm/sscaled, and 10/11-bitufloat) with clamped safe shift widths.%fmt_encode_fn's 77-branch chain with a 145-line, 0-branch 4-channel packer calling%fmt_enc_chan4 times and preserving B/R-swapped formats 50/56 (DST_SEL = Z,Y,X,W) and two-component V#(x, y)vs(x, w)routing.%fmt_size_fnand reuses the existing 2-instruction table lookupGen.fmt_size_of(fmt)(%fmt_size_tab).Aggregate impact (counts only):
-93.2%instructions,-100%branches).compute_graph_opscompute modules, total.spvsize shrinks from 2,726,244 B -> 1,577,588 B (-42.1%), with 15/15 passingspirv-val --target-env vulkan1.2.Tested
LEONIDA_REQUIRE_SPIRV_TOOLS=1 PYTHONPATH=tests/semantic:tools python3 tests/semantic/test_format_encode_table.py: 4/4 passed (exhaustive bit-exact check across all 128 format codes, 2-component XYZW(x, w)routing, BGRA formats 50/56 with0xF2Evs0xFAC, 0 branches,%fmt_size_fnremoved,<400total lines,spirv-valclean).python3 -I tests/test_rdna2spirv_decode.py: 25/25 passed.LEONIDA_REQUIRE_SPIRV_TOOLS=1 python3 -I scripts/run_semantic_tests.py tests/semantic: 465 files, 6108 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 860/860 exact readback words (cs_fmt_101010264/64,cs_fmt_int_narrow136/136,cs_fmt_sint3264/64,cs_fmt_all336/336,cs_fmt_xy_xyz128/128,cs_fmt_d16_xyz80/80,cs_tbuffer_store52/52).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.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.