[PR #1970] runtime: preamble-only flat scan, safe type lookups, and portable CPU test for rect_list_geometry #1976

Open
opened 2026-11-26 21:19:36 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1970
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: perf/rt-rect-list-geometry-preamble-and-tests


📝 Commits (1)

  • 57b853a runtime: preamble-only flat scan, safe lookups, and portable unit test for rect_list_geometry

📊 Changes

3 files changed (+286 additions, -32 deletions)

View changed files

📝 runtime/CMakeLists.txt (+3 -0)
📝 runtime/src/rect_list_geometry.h (+65 -32)
➕ runtime/test/rect_list_geometry_test.cpp (+218 -0)

📄 Description

Claim: RT-RECT-LIST-GEOMETRY-PREAMBLE-AND-TESTS (claim comment #7168816576 on #1608).

Fixes & Optimizations (runtime/src/rect_list_geometry.h)

  1. Stop scanning the vertex shader at OpFunction (preamble-only): OpType*, OpDecorate, and global Output OpVariable declarations all precede the first OpFunction (SPIR-V logical layout §2.4), so scanning tens of thousands of body instructions during graphics PSO creation was wasted work.
  2. Overflow-safe framing check: replaced i + n > vertex_words.size() with n > vertex_words.size() - i.
  3. Eliminate 5 std::map/std::set RB-trees and silent operator[] lookups:
    • Replaced types, variable_type, location, builtin, and outputs with 4 flat sorted vectors (stable_sort + upper_bound preserving exact last-wins semantics) and explicit find_type() / find_kv() checks instead of types[...] silent default-insertion on missing IDs.
  4. Remove dead head vector and pre-reserve output buffers: pre-reserves annotations, globals, body, vars, io_vars, corners, emitted, and out, and emits OpEntryPoint directly into out without a temporary entry vector.
  5. Add portable CPU-only CTest rect_list_geometry (runtime/test/rect_list_geometry_test.cpp): previously only the GPU test d3d12_rect_list_test.cpp exercised rect_list_geometry.h.

Verification

  • AI-assisted: yes.
  • GPUs tested: none (host is macOS arm64; no retail files).
  • Added runtime/test/rect_list_geometry_test.cpp (8 test groups verifying generated SPIR-V header/bound/capability/memory-model/entry-point/all-4-execution-modes/decorations/6-EmitVertex/2-EndPrimitive, position-only shaders, PointSize allowed, unsorted/duplicate Locations, large body skipped identically, non-SPIR-V/short/zero-len/truncated refusal, missing Position refusal, ClipDistance/Layer refusal, vec3/uvec4/dangling-type-id refusal).
  • Ran rect_list_geometry_test cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror
  • Bit-exact A/B benchmark at -O2 vs main (best of 5 runs, Apple Silicon):
small_vs_2loc_200w     (   199 words): base=   1.60 us  new=  0.93 us  speedup= 1.73x
med_vs_8loc_8kw        (  8097 words): base=   5.23 us  new=  1.71 us  speedup= 3.07x
large_vs_16loc_50kw    ( 50161 words): base=  17.20 us  new=  2.76 us  speedup= 6.24x
  • Ran python3 -I scripts/check_no_game_data.py on all 3 changed files and python3 -I tests/test_text_write_line_endings.py: all passed.

🔄 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/1970 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/rt-rect-list-geometry-preamble-and-tests` --- ### 📝 Commits (1) - [`57b853a`](https://github.com/ubiquitarianism/leonida/commit/57b853a46ed1dc614cbaf7d03afaa8c84bc6c9d6) runtime: preamble-only flat scan, safe lookups, and portable unit test for rect_list_geometry ### 📊 Changes **3 files changed** (+286 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+3 -0) 📝 `runtime/src/rect_list_geometry.h` (+65 -32) ➕ `runtime/test/rect_list_geometry_test.cpp` (+218 -0) </details> ### 📄 Description Claim: `RT-RECT-LIST-GEOMETRY-PREAMBLE-AND-TESTS` (claim comment `#7168816576` on #1608). ### Fixes & Optimizations (`runtime/src/rect_list_geometry.h`) 1. **Stop scanning the vertex shader at `OpFunction` (preamble-only)**: `OpType*`, `OpDecorate`, and global `Output` `OpVariable` declarations all precede the first `OpFunction` (SPIR-V logical layout §2.4), so scanning tens of thousands of body instructions during graphics PSO creation was wasted work. 2. **Overflow-safe framing check**: replaced `i + n > vertex_words.size()` with `n > vertex_words.size() - i`. 3. **Eliminate 5 `std::map`/`std::set` RB-trees and silent `operator[]` lookups**: - Replaced `types`, `variable_type`, `location`, `builtin`, and `outputs` with 4 flat sorted vectors (`stable_sort` + `upper_bound` preserving exact last-wins semantics) and explicit `find_type()` / `find_kv()` checks instead of `types[...]` silent default-insertion on missing IDs. 4. **Remove dead `head` vector and pre-reserve output buffers**: pre-reserves `annotations`, `globals`, `body`, `vars`, `io_vars`, `corners`, `emitted`, and `out`, and emits `OpEntryPoint` directly into `out` without a temporary `entry` vector. 5. **Add portable CPU-only CTest `rect_list_geometry`** (`runtime/test/rect_list_geometry_test.cpp`): previously only the GPU test `d3d12_rect_list_test.cpp` exercised `rect_list_geometry.h`. ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (host is macOS arm64; no retail files). - Added `runtime/test/rect_list_geometry_test.cpp` (8 test groups verifying generated SPIR-V header/bound/capability/memory-model/entry-point/all-4-execution-modes/decorations/6-EmitVertex/2-EndPrimitive, position-only shaders, PointSize allowed, unsorted/duplicate Locations, large body skipped identically, non-SPIR-V/short/zero-len/truncated refusal, missing Position refusal, ClipDistance/Layer refusal, vec3/uvec4/dangling-type-id refusal). - Ran `rect_list_geometry_test` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror` - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror` - Bit-exact A/B benchmark at `-O2` vs `main` (best of 5 runs, Apple Silicon): ```text small_vs_2loc_200w ( 199 words): base= 1.60 us new= 0.93 us speedup= 1.73x med_vs_8loc_8kw ( 8097 words): base= 5.23 us new= 1.71 us speedup= 3.07x large_vs_16loc_50kw ( 50161 words): base= 17.20 us new= 2.76 us speedup= 6.24x ``` - Ran `python3 -I scripts/check_no_game_data.py` on all 3 changed files and `python3 -I tests/test_text_write_line_endings.py`: all passed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1976
No description provided.