runtime: stop inner_coverage_requirements scan at SPIR-V preamble boundary (RT-CONSERVATIVE-RASTER-PREAMBLE-STOP) #1982

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

@⁠IlyassRS3 on GitHub · 2026-11-25 17:20 UTC · original
IlyassRS3:perf/rt-conservative-raster-preamble-stop → main · +84 −0 · 2 files · 1 commits · open

Item ID: RT-CONSERVATIVE-RASTER-PREAMBLE-STOP (claimed in #1608)

Summary

inner_coverage_requirements() in runtime/src/conservative_raster.h is called on every shader stage of every graphics PSO (runtime/shims/d3d12_vulkan_device.cpp:8459), yet previously walked the entire SPIR-V binary word-by-word through all debug names, decorations, types, constants, globals, and function bodies.

Per SPIR-V Logical Layout (§2.4), OpCapability (17) and OpExecutionMode (16) strictly precede all debug (OpString/OpSource*/OpName/OpMemberName/OpModuleProcessed), annotation (OpDecorate*/OpGroup*), type/constant/global (OpType*/OpConstant*/OpVariable/OpUndef), and function (OpFunction) sections.

  • Stop scanning as soon as the opcode enters any post-execution-mode section (after validating the instruction's word-count framing, so truncated preamble/boundary instructions are still rejected).
  • Expand runtime/test/conservative_raster_test.cpp with coverage for short/empty inputs, wrong magic, header-only modules, full modules with large bodies, boundary truncation rejection, and early-stop verification across OpName, OpDecorate, OpTypeVoid, OpConstant, OpVariable, and OpFunction.

Benchmarks (-O2, bit-exact A/B vs full-module scan)

  • 12k-word ordinary PS (12,033 words): 4,678.4 ns → 8.4 ns (553.65× faster)
  • 50k-word large PS (50,033 words): 10,261.8 ns → 8.6 ns (1,189.21× faster)
  • 50k-word inner-coverage + post-depth PS (50,033 words): 10,033.8 ns → 10.0 ns (1,007.15× faster)

Testing & Disclosure

  • AI-assisted: yes
  • GPUs tested: none (macOS host, CPU-only portable unit test and A/B benchmark)
  • clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror runtime/test/conservative_raster_test.cpp: PASS
  • clang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror runtime/test/conservative_raster_test.cpp: PASS
  • clang++ -std=c++20 -O2 -Wall -Wextra -Werror runtime/test/conservative_raster_test.cpp: PASS
  • python3 -I scripts/check_no_game_data.py runtime/src/conservative_raster.h runtime/test/conservative_raster_test.cpp: PASS
  • python3 -I tests/test_text_write_line_endings.py: PASS (3/3)
**@⁠IlyassRS3** on GitHub · 2026-11-25 17:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1982) `IlyassRS3:perf/rt-conservative-raster-preamble-stop` → `main` · +84 −0 · 2 files · 1 commits · open Item ID: `RT-CONSERVATIVE-RASTER-PREAMBLE-STOP` (claimed in #1608) ## Summary `inner_coverage_requirements()` in `runtime/src/conservative_raster.h` is called on every shader stage of every graphics PSO (`runtime/shims/d3d12_vulkan_device.cpp:8459`), yet previously walked the entire SPIR-V binary word-by-word through all debug names, decorations, types, constants, globals, and function bodies. Per SPIR-V Logical Layout (§2.4), `OpCapability` (17) and `OpExecutionMode` (16) strictly precede all debug (`OpString`/`OpSource*`/`OpName`/`OpMemberName`/`OpModuleProcessed`), annotation (`OpDecorate*`/`OpGroup*`), type/constant/global (`OpType*`/`OpConstant*`/`OpVariable`/`OpUndef`), and function (`OpFunction`) sections. - Stop scanning as soon as the opcode enters any post-execution-mode section (after validating the instruction's word-count framing, so truncated preamble/boundary instructions are still rejected). - Expand `runtime/test/conservative_raster_test.cpp` with coverage for short/empty inputs, wrong magic, header-only modules, full modules with large bodies, boundary truncation rejection, and early-stop verification across `OpName`, `OpDecorate`, `OpTypeVoid`, `OpConstant`, `OpVariable`, and `OpFunction`. ## Benchmarks (`-O2`, bit-exact A/B vs full-module scan) - 12k-word ordinary PS (12,033 words): 4,678.4 ns → **8.4 ns** (**553.65×** faster) - 50k-word large PS (50,033 words): 10,261.8 ns → **8.6 ns** (**1,189.21×** faster) - 50k-word inner-coverage + post-depth PS (50,033 words): 10,033.8 ns → **10.0 ns** (**1,007.15×** faster) ## Testing & Disclosure - AI-assisted: yes - GPUs tested: none (macOS host, CPU-only portable unit test and A/B benchmark) - `clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror runtime/test/conservative_raster_test.cpp`: PASS - `clang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror runtime/test/conservative_raster_test.cpp`: PASS - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror runtime/test/conservative_raster_test.cpp`: PASS - `python3 -I scripts/check_no_game_data.py runtime/src/conservative_raster.h runtime/test/conservative_raster_test.cpp`: PASS - `python3 -I tests/test_text_write_line_endings.py`: PASS (3/3)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:13:45 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 17:20 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:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1982#pullrequestreview-6061960070) · **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/1982/head:github-bot/gh-1982'
git switch 'github-bot/gh-1982'

Merge

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