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

Closed
leonida/mandy
quietfold wants to merge 0 commits from perf/rt-rect-list-geometry-preamble-and-tests into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

quietfold commented 2026-11-25 17:01:24 +00:00

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.
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.
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 17:01:35 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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.
RenoThaGutta commented 2026-11-28 04:58:10 +00:00

Independent RTX 4080 validation of 57b853a46ed1dc614cbaf7d03afaa8c84bc6c9d6 on Windows 11 Pro 25H2, NVIDIA 621.01, x64 MSVC 19.51.36244 (RelWithDebInfo). Inputs were generated from handwritten synthetic fixtures. No GTA VI files were used.

MEASURED on baseline 02f71ccfe78160997a02950607be583af87e1180 with and without the three PR changes:

  • The original d3d12_rect_list test passed on both builds under Khronos Vulkan validation. The patched build passed rect_list_geometry (1/1).
  • Identical capture-only instrumentation recorded eight 64 × 64 RGBA32F frames per run. All 32,768 pixels matched bit for bit in each paired run: default lazy creation, eager creation, and default with Vulkan validation. That is zero changed pixels across 98,304 comparisons.
  • Four 10-minute lifecycle runs with validation enabled completed 466 create/render/destroy cycles. Lazy completed 116 on each build and eager completed 117 on each build. Each run matched its own first readback throughout and logged zero validation errors.
  • Repeated the core comparison on newer main ef8fbf09f3ba00460e1c08102b096b76702a70b6. All eight frames again matched bit for bit. The two synthetic fallback-pipeline tests passed on each build.

Independent evidence review completed. AI-assisted: OpenAI Codex.

Independent RTX 4080 validation of `57b853a46ed1dc614cbaf7d03afaa8c84bc6c9d6` on Windows 11 Pro 25H2, NVIDIA 621.01, x64 MSVC 19.51.36244 (RelWithDebInfo). Inputs were generated from handwritten synthetic fixtures. No GTA VI files were used. **MEASURED** on baseline `02f71ccfe78160997a02950607be583af87e1180` with and without the three PR changes: - The original `d3d12_rect_list` test passed on both builds under Khronos Vulkan validation. The patched build passed `rect_list_geometry` (1/1). - Identical capture-only instrumentation recorded eight 64 × 64 RGBA32F frames per run. All 32,768 pixels matched bit for bit in each paired run: default lazy creation, eager creation, and default with Vulkan validation. That is zero changed pixels across 98,304 comparisons. - Four 10-minute lifecycle runs with validation enabled completed 466 create/render/destroy cycles. Lazy completed 116 on each build and eager completed 117 on each build. Each run matched its own first readback throughout and logged zero validation errors. - Repeated the core comparison on newer main `ef8fbf09f3ba00460e1c08102b096b76702a70b6`. All eight frames again matched bit for bit. The two synthetic fallback-pipeline tests passed on each build. Independent evidence review completed. AI-assisted: OpenAI Codex.
lixonik reviewed 2026-11-28 15:54:20 +00:00
lixonik left a comment
No description provided.
Reviewed `57b853a46` merged locally with `main` `c1ecf04ed` for the rectangle-list package in #2464. The flat lookups preserve the previous last-wins behavior, and the generated geometry module was byte-identical to main across 60 synthetic cases, varying locations, PointSize, and the function body length. The new `rect_list_geometry_test` passes against both implementations, consistent with its role as a behavior-preservation test. CPU microbenchmark of the generator on Ubuntu 22.04 under WSL2, GCC 11.4 `-O2`, four locations, median of seven alternating A/B batches of 2,500 calls each. Each call also checked its output against main. A repeat produced the same pattern. | Synthetic function body | Main | Main + PR | | --- | ---: | ---: | | 8 OpNops | 3.07 us/call | 1.93 us/call | | 16,384 OpNops | 31.56 us/call | 1.91 us/call | | 65,536 OpNops | 119.19 us/call | 1.94 us/call | This measures CPU-side geometry shader generation only. The same changed files pass `check_no_game_data.py` and `git diff --check`. The heads of #1970 and #2478 also merge cleanly in `git merge-tree`. AI-assisted.
OreoFR commented 2026-11-29 03:14:47 +00:00

Verified by OreoFR

  • Base: main aa918e5d9 + PR head 57b853a46
  • Test: ctest -R ^rect_list_geometry$
  • Red on main: passes (the new test covers behaviour already on main)
  • Green with the PR: passes; package builds, full ctest shows no new failure (4 d3d12 GPU tests timed out once under load and pass on a serial rerun)
  • Verdict: NO RED (optimization; the new test also passes on main). Since the test, main moved to c8bf0e7b6 and the PR now conflicts with it in runtime/CMakeLists.txt
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

Note: shares runtime/CMakeLists.txt with the open #2566; a rebase may be needed if #2566 lands first.

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `aa918e5d9` + PR head `57b853a46` - Test: `ctest -R ^rect_list_geometry$` - Red on main: passes (the new test covers behaviour already on main) - Green with the PR: passes; package builds, full ctest shows no new failure (4 d3d12 GPU tests timed out once under load and pass on a serial rerun) - Verdict: NO RED (optimization; the new test also passes on main). Since the test, main moved to `c8bf0e7b6` and the PR now conflicts with it in `runtime/CMakeLists.txt` - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 Note: shares `runtime/CMakeLists.txt` with the open #2566; a rebase may be needed if #2566 lands first. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:40:15 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.