indirect clamp: a draw record of 2^23 vertices or more runs empty and free (RT-INDIRECT-DRAW-UNFILLED-COUNT) #2378

Manually merged
github merged 2 commits from github-bot/gh-2378 into main 2026-11-26 18:47:45 +00:00 AGit
Owner

@⁠kawaii-shakal on GitHub · 2026-11-26 16:31 UTC · original
kawaii-shakal:indirect-draw-unfilled-count → main · +294 −239 · 5 files · 2 commits · merged 2026-11-26 18:43 UTC

Claimed in the coordination issue as: RT-INDIRECT-DRAW-UNFILLED-COUNT

Depends on: #2230 (conflicts only in the generated runtime/src/indirect_clamp_spv.h: whichever of the two lands
second regenerates it from the merged indirect_clamp.comp)

What and why

indirect_clamp.comp treats a draw record as unfilled only when all of its words are 0xFFFFFFFF. A slot with a
garbage count and its other words set is cut to 2^24 vertices and charged 2^24 units against the list's 2^27 budget.
Eight such slots use up the budget, and every real draw after them in the list runs empty. That shows up as objects
missing for a frame, or as flicker.

A census in codec-d/cool_fox's fork of VIctory found 90 records of 2^24 vertices in one list of the title. That fork
treats 2^23 vertices an instance or more as unfilled (its docs/findings.md and crates/victory-gpu/src/indirect.rs).
It suspects such records behind outdoor flicker; nothing in this PR confirms that link. No code of it is used.

With this PR, a draw or indexed-draw record of 2^23 or more vertices (or indices) an instance runs empty, keeps its
locations and charges nothing. It is counted as clamped and zeroed, as unfilled slots already are. Draws under 2^23 are
unchanged, including the 2^26 vertex-instance bound.

  • indirect_clamp.comp: unfilled_draw = 2^23; such a record's count and instances become 0, at cost 0.
  • vulkan_indirect_clamp.h: indirect_clamp_unfilled_draw for the tests.
  • indirect_clamp_spv.h: regenerated with glslangValidator 15.1.0 (-V --target-env vulkan1.2 -Os --spirv-val).
  • docs/d3d12_vulkan.md: the clamp's paragraph says so.

Tested

  • indirect_clamp_test. The old garbage-count cases now expect an empty record. New cases:

    • 2b: 2^23 - 1 vertices stay, with their instances cut; 2^23 runs empty;
    • 2c: 16 garbage counts ahead of a real draw in one list. With the old shader the real draw ran empty (checked by
      building the test against the old indirect_clamp_spv.h: 2c fails). With this one it runs.

    The list-budget case now spends the budget with a real 2^22 x 16 draw instead of a 2^24 one.

  • Full ctest on the branch merged with current main (fbf100b1): 112 of 112 pass.

GPUs tested: Mesa lavapipe (llvmpipe, LLVM 19.1.7), Ubuntu 24.04 container. Not run on a hardware GPU or with the game.

AI-assisted: yes (Claude Code)

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. (n/a: no
    translator change)

🤖 Generated with Claude Code

**@⁠kawaii-shakal** on GitHub · 2026-11-26 16:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2378) `kawaii-shakal:indirect-draw-unfilled-count` → `main` · +294 −239 · 5 files · 2 commits · merged 2026-11-26 18:43 UTC Claimed in the coordination issue as: RT-INDIRECT-DRAW-UNFILLED-COUNT Depends on: #2230 (conflicts only in the generated `runtime/src/indirect_clamp_spv.h`: whichever of the two lands second regenerates it from the merged `indirect_clamp.comp`) ### What and why `indirect_clamp.comp` treats a draw record as unfilled only when all of its words are 0xFFFFFFFF. A slot with a garbage count and its other words set is cut to 2^24 vertices and charged 2^24 units against the list's 2^27 budget. Eight such slots use up the budget, and every real draw after them in the list runs empty. That shows up as objects missing for a frame, or as flicker. A census in codec-d/cool_fox's fork of VIctory found 90 records of 2^24 vertices in one list of the title. That fork treats 2^23 vertices an instance or more as unfilled (its `docs/findings.md` and `crates/victory-gpu/src/indirect.rs`). It suspects such records behind outdoor flicker; nothing in this PR confirms that link. No code of it is used. With this PR, a draw or indexed-draw record of 2^23 or more vertices (or indices) an instance runs empty, keeps its locations and charges nothing. It is counted as clamped and zeroed, as unfilled slots already are. Draws under 2^23 are unchanged, including the 2^26 vertex-instance bound. - `indirect_clamp.comp`: `unfilled_draw = 2^23`; such a record's count and instances become 0, at cost 0. - `vulkan_indirect_clamp.h`: `indirect_clamp_unfilled_draw` for the tests. - `indirect_clamp_spv.h`: regenerated with glslangValidator 15.1.0 (`-V --target-env vulkan1.2 -Os --spirv-val`). - `docs/d3d12_vulkan.md`: the clamp's paragraph says so. ### Tested - `indirect_clamp_test`. The old garbage-count cases now expect an empty record. New cases: - 2b: 2^23 - 1 vertices stay, with their instances cut; 2^23 runs empty; - 2c: 16 garbage counts ahead of a real draw in one list. With the old shader the real draw ran empty (checked by building the test against the old `indirect_clamp_spv.h`: 2c fails). With this one it runs. The list-budget case now spends the budget with a real 2^22 x 16 draw instead of a 2^24 one. - Full `ctest` on the branch merged with current main (fbf100b1): 112 of 112 pass. GPUs tested: Mesa lavapipe (llvmpipe, LLVM 19.1.7), Ubuntu 24.04 container. Not run on a hardware GPU or with the game. AI-assisted: yes (Claude Code) ### 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The clamp cut a garbage draw count to 2^24 vertices and charged it against the
list's 2^27-unit budget. Only records whose words are all 0xFFFFFFFF were
treated as unfilled. A slot with a garbage count but other words set therefore
cost 2^24 units, so eight such records used up the budget and every real draw
after them in the list ran empty.

A census in codec-d/cool_fox's fork of VIctory found 90 records of 2^24
vertices in one list, and that fork treats 2^23 vertices an instance or more as
unfilled. Here such a record now runs empty, keeps its locations and charges
nothing. Draws under 2^23 are unchanged.

indirect_clamp_test: the old garbage cases now expect an empty record. New
cases check the 2^23 edge and 16 garbage counts ahead of a real draw, which ran
empty with the old shader and runs with this one. The list-budget case uses a
real 2^22 x 16 draw. indirect_clamp_spv.h was regenerated with glslangValidator
15.1.0 (-V --target-env vulkan1.2 -Os).

Tested: full ctest (108 tests) on Linux with Mesa lavapipe (llvmpipe, LLVM 19.1.7).

Changes made by Claude Code (AI-assisted).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:35:56 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 17:48 UTC · original

I ran the committed clamp shader at 41332d4665 on a physical RTX 4090 (Windows 11, NVIDIA 616.64). The stock indirect_clamp_test passed with Vulkan validation enabled and zero validation errors.

I also compared the draw records written back by the GPU against an independent expected value for every word. Each synthetic list had 96 records, spanning two 64-invocation workgroups. The six valid draws included one at the cutoff minus one. The other 90 records had counts at or above the cutoff. The 32 cases covered ordinary and indexed draws, packed and 32-byte strides, uncounted commands and count-buffer values before, at, and after the workgroup boundary.

Clamp shader Batches matching all expected words and counters
Upstream baseline merged into this PR, fbf100b1b1 8/32
PR head, 41332d4665 32/32
This PR combined locally with #2230 at 7a761696dc 32/32

For the uncounted indexed list with a 32-byte stride, the PR zeroed the counts of all 90 oversized records, preserved their location fields and all six valid draws, and reported zero records over budget. The matrix only reads the clamped arguments back. All three shader binaries passed Vulkan 1.2 SPIR-V validation.

In the local combination, the only Git conflict was the generated indirect_clamp_spv.h. Regenerating it from the automatically merged GLSL with glslang 16.6.0 also let the combined stock test pass with zero validation errors. This verifies the clamp behavior. The effect on in-game flicker is still unmeasured.

AI-assisted hardware verification with OpenAI Codex (GPT-6).

**@⁠ecox982745** on GitHub · 2026-11-26 17:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2378#issuecomment-7199683664) I ran the committed clamp shader at `41332d4665` on a physical RTX 4090 (Windows 11, NVIDIA 616.64). The stock `indirect_clamp_test` passed with Vulkan validation enabled and zero validation errors. I also compared the draw records written back by the GPU against an independent expected value for every word. Each synthetic list had 96 records, spanning two 64-invocation workgroups. The six valid draws included one at the cutoff minus one. The other 90 records had counts at or above the cutoff. The 32 cases covered ordinary and indexed draws, packed and 32-byte strides, uncounted commands and count-buffer values before, at, and after the workgroup boundary. | Clamp shader | Batches matching all expected words and counters | | --- | ---: | | Upstream baseline merged into this PR, `fbf100b1b1` | 8/32 | | PR head, `41332d4665` | 32/32 | | This PR combined locally with #2230 at `7a761696dc` | 32/32 | For the uncounted indexed list with a 32-byte stride, the PR zeroed the counts of all 90 oversized records, preserved their location fields and all six valid draws, and reported zero records over budget. The matrix only reads the clamped arguments back. All three shader binaries passed Vulkan 1.2 SPIR-V validation. In the local combination, the only Git conflict was the generated `indirect_clamp_spv.h`. Regenerating it from the automatically merged GLSL with glslang 16.6.0 also let the combined stock test pass with zero validation errors. This verifies the clamp behavior. The effect on in-game flicker is still unmeasured. AI-assisted hardware verification with OpenAI Codex (GPT-6).
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 18:02 UTC · original · reviewed

Built and ran indirect_clamp on Windows 11 with MSVC and NVIDIA GeForce RTX 5070 (610.88). CTest passed, including the synthetic records just below and at the new threshold and a subsequent slot retaining its budget. Title workload coverage was outside this run.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 18:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2378#pullrequestreview-6078730189) · **reviewed** Built and ran `indirect_clamp` on Windows 11 with MSVC and NVIDIA GeForce RTX 5070 (610.88). CTest passed, including the synthetic records just below and at the new threshold and a subsequent slot retaining its budget. Title workload coverage was outside this run. AI-assisted.
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:30 UTC · original · reviewed

macOS arm64 / GPU check of #2378 (RT-INDIRECT-DRAW-UNFILLED-COUNT). This is a Vulkan compute pass and a GPU test, so it runs here on two drivers.

Tested head 41332d466 merged onto main bdbc7e923 as merge 6738bf9d6 (clean; the branch has two commits, one an upstream-main merge).

Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, MoltenVK 1.4.0; KosmicKrisp = Mesa 26.3.0 (32-wide subgroups). glslangValidator here is 16.6.0.

The GPU test runs, and the control bites

  • Built indirect_clamp_test from the merge and ran it directly:
    • MoltenVK: exit 0, 91 record(s) clamped in 4116 call(s), 1 count(s), validation errors 0.
    • KosmicKrisp: exit 0, same line, validation errors 0.
  • main bdbc7e923 with its own (old) test: exit 0 on both drivers, 72 record(s) clamped in 4113 call(s), validation errors 0. The totals differ because the test itself gained cases, not because the pass counts differently on unchanged cases.
  • Negative control: new test kept, runtime/src/indirect_clamp_spv.h and indirect_clamp.comp put back to main's (the header constant indirect_clamp_unfilled_draw stays, because the new test references it and would not otherwise compile): build OK, run exits 1 with 6 CHECK failed lines - words[0] == 0 && words[1] == 0 (line 177), the 2^23 - 1 vs 2^23 pair (191, 192), and the 16-garbage-records-then-a-real-draw case (204, 205). That is the regression the PR describes.
  • python -I tests/test_indirect_clamp_telemetry.py: OK; the counter offsets in the regenerated header are unchanged.
  • The checked-in SPIR-V was not byte-compared: this machine's glslangValidator is 16.6.0 while the header says 15.1.0, and the modules differ from word 3 (the id bound, 0x2ad vs 0x309). The functional run above is the check that the checked-in bytes implement the new rule.

No regressions

  • Semantic suite: 500 files / 6,367 tests / 0 files failed at the merge, the same as main.
  • The 268 shader fixtures were not re-run: this PR touches no translator code. The same-main baseline from this session is 195 PASS / 3 FAIL / 70 SKIP (MoltenVK) and 190 / 5 / 73 (KosmicKrisp).

Findings

  1. indirect_clamp_max_vertices (2^24) is now unreachable for draw and indexed draw: a count ≥ 2^23 becomes 0, and a count < 2^23 is min(count, 2^24) == count, so the clamp never fires. runtime/src/indirect_clamp.comp:46,111 keeps a dead constant, and docs/d3d12_vulkan.md:4341 still lists "2^24 vertices or indices" as a bound, which is no longer true (the new sentence three lines below says 2^23 records run empty). Either cut unfilled records at max_vertices (2^24) - which still catches the 2^24 records the census found - or drop the constant and fix the limits list.
  2. The 2^23 boundary is taken from codec-d/cool_fox's fork, and the body is explicit that the flicker link is unconfirmed. A legitimate draw of 8.4M-16.7M vertices, which ran before (the old clamp kept the count below 2^24 and clamped only above it), now runs empty and is only visible as records_clamped. Since the census's garbage records are 2^24, cutting at 2^24 would solve the same problem with twice the headroom and without a new class of dropped draws; if 2^23 is deliberate (e.g. the title's largest real draw is known to be below it), a corpus count from the title's own indirect arguments would settle it. The test pins 2^23 as designed, so this is a design question, not a test gap.
  3. For other reviewers: the new test references leonida::indirect_clamp_unfilled_draw, so a RED control that reverts the whole implementation (header plus shader) fails at compile time (no member named 'indirect_clamp_unfilled_draw'), not at a CHECK. Reverting only indirect_clamp_spv.h (and .comp) is the control that shows the 6 failures, as above.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-26 18:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2378#pullrequestreview-6079002918) · **reviewed** **macOS arm64 / GPU check of #2378** (RT-INDIRECT-DRAW-UNFILLED-COUNT). This is a Vulkan compute pass and a GPU test, so it runs here on two drivers. Tested head `41332d466` merged onto `main` `bdbc7e923` as merge `6738bf9d6` (clean; the branch has two commits, one an upstream-main merge). Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, MoltenVK 1.4.0; KosmicKrisp = Mesa 26.3.0 (32-wide subgroups). `glslangValidator` here is 16.6.0. **The GPU test runs, and the control bites** - Built `indirect_clamp_test` from the merge and ran it directly: - MoltenVK: exit 0, `91 record(s) clamped in 4116 call(s), 1 count(s), validation errors 0`. - KosmicKrisp: exit 0, same line, `validation errors 0`. - `main` `bdbc7e923` with its own (old) test: exit 0 on both drivers, `72 record(s) clamped in 4113 call(s)`, validation errors 0. The totals differ because the test itself gained cases, not because the pass counts differently on unchanged cases. - Negative control: new test kept, `runtime/src/indirect_clamp_spv.h` and `indirect_clamp.comp` put back to `main`'s (the header constant `indirect_clamp_unfilled_draw` stays, because the new test references it and would not otherwise compile): build OK, run exits 1 with 6 `CHECK failed` lines - `words[0] == 0 && words[1] == 0` (line 177), the `2^23 - 1` vs `2^23` pair (191, 192), and the 16-garbage-records-then-a-real-draw case (204, 205). That is the regression the PR describes. - `python -I tests/test_indirect_clamp_telemetry.py`: OK; the counter offsets in the regenerated header are unchanged. - The checked-in SPIR-V was not byte-compared: this machine's glslangValidator is 16.6.0 while the header says 15.1.0, and the modules differ from word 3 (the id bound, `0x2ad` vs `0x309`). The functional run above is the check that the checked-in bytes implement the new rule. **No regressions** - Semantic suite: 500 files / 6,367 tests / 0 files failed at the merge, the same as `main`. - The 268 shader fixtures were not re-run: this PR touches no translator code. The same-main baseline from this session is 195 PASS / 3 FAIL / 70 SKIP (MoltenVK) and 190 / 5 / 73 (KosmicKrisp). **Findings** 1. `indirect_clamp_max_vertices` (2^24) is now unreachable for draw and indexed draw: a count ≥ 2^23 becomes 0, and a count < 2^23 is `min(count, 2^24) == count`, so the clamp never fires. `runtime/src/indirect_clamp.comp:46,111` keeps a dead constant, and `docs/d3d12_vulkan.md:4341` still lists "2^24 vertices or indices" as a bound, which is no longer true (the new sentence three lines below says 2^23 records run empty). Either cut unfilled records at `max_vertices` (2^24) - which still catches the 2^24 records the census found - or drop the constant and fix the limits list. 2. The 2^23 boundary is taken from codec-d/cool_fox's fork, and the body is explicit that the flicker link is unconfirmed. A legitimate draw of 8.4M-16.7M vertices, which ran before (the old clamp kept the count below 2^24 and clamped only above it), now runs empty and is only visible as `records_clamped`. Since the census's garbage records are 2^24, cutting at 2^24 would solve the same problem with twice the headroom and without a new class of dropped draws; if 2^23 is deliberate (e.g. the title's largest real draw is known to be below it), a corpus count from the title's own indirect arguments would settle it. The test pins 2^23 as designed, so this is a design question, not a test gap. 3. For other reviewers: the new test references `leonida::indirect_clamp_unfilled_draw`, so a RED control that reverts the whole implementation (header plus shader) fails at compile time (`no member named 'indirect_clamp_unfilled_draw'`), not at a CHECK. Reverting only `indirect_clamp_spv.h` (and `.comp`) is the control that shows the 6 failures, as above. No game files. AI-assisted.
github manually merged commit e57bc63bc5 into main 2026-11-26 18:47:45 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 18:43 UTC · original

Merging.

  • Why: a draw record with a garbage count of 2^23 vertices or more now runs empty and costs nothing against the list's budget, so such records no longer empty the real draws after them.
  • Tested on main f107ae044 + this PR (41332d466), Mesa 26.3.1:
    • indirect_clamp_test, validation on, three runs each on llvmpipe, the integrated RDNA2 GPU and the RX 7900 XTX (RADV): passes, with no kernel fault. With main's shader the new cases fail.
    • Linux runtime ctest: 113/113 pass.
    • Windows suite under Wine: 423 pass and 23 fail on both main and the merge; no test changed.
    • test_ci_registration.py, the docs tests and check_no_game_data.py pass.
    • The committed indirect_clamp_spv.h is not byte-identical to a rebuild with glslang 16.6.0. With IDs renumbered the only difference is three empty branch and label pairs, which fits the PR's 15.1.0, and the test also passes with the rebuilt header.
  • Not tested: no world run. In our runs today the clamp reported no record with a garbage count that main did not already empty, so a run here could not show the change.

Notes for a follow-up, none blocking:

  • Garbage instance counts still use up the budget: a small count with garbage instances costs up to 2^26, so two such records are enough, not eight.
  • A real draw of 2^23 or more vertices per instance is now dropped, and nothing shows the title never issues one. 2^24 (max_vertices, now unused) would drop fewer.
  • The limits list in the docs still names 2^24.

Thanks @⁠kawaii-shakal.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

**@⁠aslan2142** on GitHub · 2026-11-26 18:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2378#issuecomment-7200774907) Merging. - **Why:** a draw record with a garbage count of 2^23 vertices or more now runs empty and costs nothing against the list's budget, so such records no longer empty the real draws after them. - **Tested on `main` `f107ae044` + this PR** (`41332d466`), Mesa 26.3.1: - `indirect_clamp_test`, validation on, three runs each on llvmpipe, the integrated RDNA2 GPU and the RX 7900 XTX (RADV): passes, with no kernel fault. With `main`'s shader the new cases fail. - Linux runtime `ctest`: 113/113 pass. - Windows suite under Wine: 423 pass and 23 fail on both `main` and the merge; no test changed. - `test_ci_registration.py`, the docs tests and `check_no_game_data.py` pass. - The committed `indirect_clamp_spv.h` is not byte-identical to a rebuild with glslang 16.6.0. With IDs renumbered the only difference is three empty branch and label pairs, which fits the PR's 15.1.0, and the test also passes with the rebuilt header. - **Not tested:** no world run. In our runs today the clamp reported no record with a garbage count that `main` did not already empty, so a run here could not show the change. Notes for a follow-up, none blocking: - Garbage instance counts still use up the budget: a small count with garbage instances costs up to 2^26, so two such records are enough, not eight. - A real draw of 2^23 or more vertices per instance is now dropped, and nothing shows the title never issues one. 2^24 (`max_vertices`, now unused) would drop fewer. - The limits list in the docs still names 2^24. Thanks @⁠kawaii-shakal. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
This discussion has been locked. Commenting is limited to contributors.
No description provided.