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

Open
github-bot wants to merge 1 commit from github-bot/gh-1970 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 17:01 UTC · original
IlyassRS3:perf/rt-rect-list-geometry-preamble-and-tests → main · +286 −32 · 3 files · 1 commits · open

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.
**@⁠IlyassRS3** on GitHub · 2026-11-25 17:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1970) `IlyassRS3:perf/rt-rect-list-geometry-preamble-and-tests` → `main` · +286 −32 · 3 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:13:08 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 17:01 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 17:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1970#pullrequestreview-6061682490) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1970/head:github-bot/gh-1970'
git switch 'github-bot/gh-1970'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1970'
git switch 'github-bot/gh-1970'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1970'
git switch 'github-bot/gh-1970'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1970'
git switch 'main'
git merge --squash 'github-bot/gh-1970'
git switch 'main'
git merge --ff-only 'github-bot/gh-1970'
git switch 'main'
git merge 'github-bot/gh-1970'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.