[PR #811] [CLOSED] rdna2spirv: demand-driven %fmt_dec_dyn for 1/2/3-component buffer_load_format #849

Closed
opened 2026-11-26 20:19:15 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/811
Author: @SweatierKey
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: feat/fmt-dec-demand-channels


📝 Commits (2)

  • 7bddb1b rdna2spirv: demand-driven %fmt_dec_dyn for 1/2/3-component buffer_load_format
  • 5c7a8bb tests: set odd DST_SEL_Y in _x selector matrix to kill 3->4 bitfield width mutant

📊 Changes

4 files changed (+207 additions, -28 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 tests/semantic/test_format_decode_table.py (+90 -0)
📝 tests/test_rdna2spirv_decode.py (+13 -0)
📝 tools/rdna2spirv.py (+103 -27)

📄 Description

Claimed in the coordination issue as: SHADER-FMT-DEC-DEMAND (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133732630)

What and why

Previously, every dynamic-format buffer_load_format_{x,xy,xyz,xyzw} (and _d16_{x,xy,xyz,xyzw}) called format_decode_call, which invoked all four per-component functions %fmt_dec_c0..c3 even for 1-component buffer_load_format_x loads, then swizzled by DST_SEL and discarded 1–3 decoded components (75% dead work for _x, 50% for _xy, 25% for _xyz). Large compute shaders with thousands of buffer_load_format_x instructions emitted up to 13,124 %fmt_dec_c* calls per shader.

This change introduces a single shared branch-free dynamic-channel helper %fmt_dec_dyn(fmt, words, chan) (reusing Gen.fmt_dec_component(None, params) with branch-free chan % ncomp selection) used on demand by 1/2/3-component dynamic-format loads:

  • buffer_load_format_x / _d16_x emits 1 %fmt_dec_dyn call instead of 4 (-75%).
  • buffer_load_format_xy / _d16_xy emits 2 calls instead of 4 (-50%).
  • buffer_load_format_xyz / _d16_xyz emits 3 calls instead of 4 (-25%).
  • buffer_load_format_xyzw / _d16_xyzw continues using %fmt_dec_c0..c3 unchanged.
  • Shaders containing only <4-component loads omit %fmt_dec_c0..c3 entirely; shaders mixing _xyzw and <4-component loads share a single %fmt_norm_bits definition.
  • DST_SEL handling (0 -> 0, 1 -> dst1 even when OOB per SHADER-429, reserved 2/3 -> 0, 4..7 -> in_b ? dec : 0 with chan = sel & 3) is bit-exact with the 4-component path.

Aggregate impact across 15 cached large compute shaders (counts only):

  • Dynamic format decode calls drop from 35,200 -> 8,849 (-74.9%); SPIR-V lines drop from 7,017,898 -> 6,915,894 (-102,004 lines). All modules pass spirv-val --target-env vulkan1.2.

Tested

  • python3 -I tests/test_rdna2spirv_decode.py: 26/26 passed (including new test_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 rotated DST_SEL on _xyz, all 8 DST_SEL values in-bounds & OOB on _x, mixed _xyzw + _x deduplication 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.
  • Real GPU execution (vk_compute_test.exe + spirv-val --target-env vulkan1.2): all 7 format compute fixtures passed with 816/816 exact readback words (cs_buf_swizzle 8/8, cs_fmt_1010102 64/64, cs_fmt_int_narrow 136/136, cs_fmt_sint32 64/64 exercising mixed %fmt_dec_dyn + %fmt_dec_c*, cs_fmt_all 336/336, cs_fmt_xy_xyz 128/128 exercising 22 %fmt_dec_dyn calls, cs_fmt_d16_xyz 80/80 exercising 6 %fmt_dec_dyn calls).

GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 616.92, Windows 11

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of 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.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/811 **Author:** [@SweatierKey](https://github.com/SweatierKey) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/fmt-dec-demand-channels` --- ### 📝 Commits (2) - [`7bddb1b`](https://github.com/ubiquitarianism/leonida/commit/7bddb1bce2fa3f257a537f66aeb2a348bd162f16) rdna2spirv: demand-driven %fmt_dec_dyn for 1/2/3-component buffer_load_format - [`5c7a8bb`](https://github.com/ubiquitarianism/leonida/commit/5c7a8bbd8b85274f72aa01eccc823c463cdff88a) tests: set odd DST_SEL_Y in _x selector matrix to kill 3->4 bitfield width mutant ### 📊 Changes **4 files changed** (+207 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `tests/semantic/test_format_decode_table.py` (+90 -0) 📝 `tests/test_rdna2spirv_decode.py` (+13 -0) 📝 `tools/rdna2spirv.py` (+103 -27) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-FMT-DEC-DEMAND (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133732630) ### What and why Previously, every dynamic-format `buffer_load_format_{x,xy,xyz,xyzw}` (and `_d16_{x,xy,xyz,xyzw}`) called `format_decode_call`, which invoked all four per-component functions `%fmt_dec_c0..c3` even for 1-component `buffer_load_format_x` loads, then swizzled by `DST_SEL` and discarded 1–3 decoded components (75% dead work for `_x`, 50% for `_xy`, 25% for `_xyz`). Large compute shaders with thousands of `buffer_load_format_x` instructions emitted up to `13,124` `%fmt_dec_c*` calls per shader. This change introduces a single shared branch-free dynamic-channel helper `%fmt_dec_dyn(fmt, words, chan)` (reusing `Gen.fmt_dec_component(None, params)` with branch-free `chan % ncomp` selection) used on demand by 1/2/3-component dynamic-format loads: - `buffer_load_format_x` / `_d16_x` emits **1** `%fmt_dec_dyn` call instead of 4 (`-75%`). - `buffer_load_format_xy` / `_d16_xy` emits **2** calls instead of 4 (`-50%`). - `buffer_load_format_xyz` / `_d16_xyz` emits **3** calls instead of 4 (`-25%`). - `buffer_load_format_xyzw` / `_d16_xyzw` continues using `%fmt_dec_c0..c3` unchanged. - Shaders containing only `<4`-component loads omit `%fmt_dec_c0..c3` entirely; shaders mixing `_xyzw` and `<4`-component loads share a single `%fmt_norm_bits` definition. - `DST_SEL` handling (`0 -> 0`, `1 -> dst1` even when OOB per SHADER-429, reserved `2/3 -> 0`, `4..7 -> in_b ? dec : 0` with `chan = sel & 3`) is bit-exact with the 4-component path. Aggregate impact across 15 cached large compute shaders (counts only): - Dynamic format decode calls drop from `35,200 -> 8,849` (`-74.9%`); SPIR-V lines drop from `7,017,898 -> 6,915,894` (`-102,004` lines). All modules pass `spirv-val --target-env vulkan1.2`. ### Tested - `python3 -I tests/test_rdna2spirv_decode.py`: 26/26 passed (including new `test_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 rotated `DST_SEL` on `_xyz`, all 8 `DST_SEL` values in-bounds & OOB on `_x`, mixed `_xyzw` + `_x` deduplication 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. - Real GPU execution (`vk_compute_test.exe` + `spirv-val --target-env vulkan1.2`): all 7 format compute fixtures passed with **816/816** exact readback words (`cs_buf_swizzle` 8/8, `cs_fmt_1010102` 64/64, `cs_fmt_int_narrow` 136/136, `cs_fmt_sint32` 64/64 exercising mixed `%fmt_dec_dyn` + `%fmt_dec_c*`, `cs_fmt_all` 336/336, `cs_fmt_xy_xyz` 128/128 exercising 22 `%fmt_dec_dyn` calls, `cs_fmt_d16_xyz` 80/80 exercising 6 `%fmt_dec_dyn` calls). GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 616.92, Windows 11 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:15 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#849
No description provided.