runtime: support dynamic topologies in indirect draws and report per-reason skip counts (RT-INDIRECT-TOPOLOGIES-AND-STATS) #1896

Manually merged
github merged 1 commit from gh-pr/1896/head into gh-pr/1896/base 2026-11-26 10:10:29 +00:00
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 15:00 UTC · original
IlyassRS3:fix/rt-indirect-topologies-and-stats → main · +506 −23 · 5 files · 1 commits · merged 2026-11-25 19:28 UTC

Item ID: RT-INDIRECT-TOPOLOGIES-AND-STATS (claimed in #1608).

Context

In retail world-frame runs on RTX 5080 (#1608, @DadaCap), 93% of indirect graphics calls were skipped at recording (recorded=4096 emitted=3918 record_skips=53405) with the only logged skip reasons being mesh indirect and topology, while [rt] indirect graphics: only printed aggregate totals without breaking down counts by reason.

Both d3d12_com.cpp (record_indirect) and vulkan_replay.h (prepare_draw) previously gated stateful indirect draws to D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST (4) only, even though graphics pipelines already enable VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY and VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE, emit_commands() already sets dynamic topology and strip primitive restart before emitting vkCmdDraw*Indirect*, and prepare_draw() already selects the GraphicsPipeline::rectangle_stage geometry-shader variant for console RECTLIST (17).

Changes

  1. Shared indirect topology predicate (runtime/src/indirect_draw_stats.h, runtime/shims/d3d12_com.cpp, runtime/src/vulkan_replay.h):

    • Added leonida::indirect_stats::topology_supported(uint32_t) allowing all D3D_PRIMITIVE_TOPOLOGY values that detail::vulkan_topology() maps directly without CPU vertex/index-count expansion: POINTLIST (1), LINELIST (2), LINESTRIP (3), TRIANGLELIST (4), TRIANGLESTRIP (5), *_ADJ (10..13), and console RECTLIST (17).
    • UNDEFINED (0), QUADLIST (19, requires CPU count/4 expansion), and patch lists (33..64) remain skipped with indirect_stats::topology.
    • When an indirect RECTLIST draw targets a synchronous (!async_build) pipeline that cannot build a rectangle_stage variant (e.g., already has a GS, no geometryShader, or unsupported VS outputs), prepare_draw() skips the indirect draw cleanly with indirect_stats::topology instead of failing the whole command list with ReplayResult::unsupported (direct draws retain unsupported).
    • Aligned record_indirect's viewport check in runtime/shims/d3d12_com.cpp with record_draw's any_nonempty_viewport() so multi-viewport draws with an empty slot 0 and non-empty slot >0 are not dropped.
  2. Per-reason skip counters (runtime/src/indirect_draw_stats.h):

    • Track atomic per-reason counts in Counts::by_reason[reason_count], incremented before note(event) so power-of-2 reports include the triggering skip.
    • Counts::report() preserves the exact [rt] indirect graphics: recorded=... emitted=... record_skips=... replay_skips=... prefix and appends a single-line [reason=count, ...] breakdown when any skip reason is non-zero.
  3. Portable unit tests (runtime/test/indirect_topology_and_stats_test.cpp, runtime/CMakeLists.txt):

    • Verifies topology_supported() across 0..100, full prepare + emit replay across all 10 supported topologies (indexed/non-indexed, fixed/counted, all strip_cut / index-format combinations), RECTLIST built-in GS vs rectangle_stage variant vs unexpandable safe skip (with and without vk.compiles), direct-draw unsupported preservation, unsupported topology skips, Counts::report() formatting, and concurrent skip() accounting.

Verification

  • AI-assisted: yes.
  • GPUs tested: none (macOS host, CPU-only portable Vulkan-Headers harness; no game files used).
  • indirect_topology_and_stats_test.cpp (Clang 20, C++20, -Wall -Wextra -Werror):
    • ASan + UBSan: PASS
    • TSan: PASS (4-thread concurrent skip() race check)
    • -O2 × 3: PASS
  • Existing regression suites under ASan + UBSan:
    • runtime/test/d3d12_state_map_test.cpp: PASS (including topology_quad_list skip assertion)
    • runtime/test/replay_pipeline_compiles_test.cpp: PASS
  • Mutation test vs main: TRIANGLESTRIP indirect draw fails on main (emitted=0) and passes on this branch (emitted=1).
  • Hygiene: python3 -I scripts/check_no_game_data.py on all 5 touched files and python3 -I tests/test_text_write_line_endings.py passed.
**@⁠IlyassRS3** on GitHub · 2026-11-25 15:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1896) `IlyassRS3:fix/rt-indirect-topologies-and-stats` → `main` · +506 −23 · 5 files · 1 commits · merged 2026-11-25 19:28 UTC Item ID: `RT-INDIRECT-TOPOLOGIES-AND-STATS` (claimed in #1608). ### Context In retail world-frame runs on RTX 5080 (#1608, `@DadaCap`), 93% of indirect graphics calls were skipped at recording (`recorded=4096 emitted=3918 record_skips=53405`) with the only logged skip reasons being `mesh indirect` and `topology`, while `[rt] indirect graphics:` only printed aggregate totals without breaking down counts by reason. Both `d3d12_com.cpp` (`record_indirect`) and `vulkan_replay.h` (`prepare_draw`) previously gated stateful indirect draws to `D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST` (`4`) only, even though graphics pipelines already enable `VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY` and `VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE`, `emit_commands()` already sets dynamic topology and strip primitive restart before emitting `vkCmdDraw*Indirect*`, and `prepare_draw()` already selects the `GraphicsPipeline::rectangle_stage` geometry-shader variant for console `RECTLIST` (`17`). ### Changes 1. **Shared indirect topology predicate (`runtime/src/indirect_draw_stats.h`, `runtime/shims/d3d12_com.cpp`, `runtime/src/vulkan_replay.h`)**: - Added `leonida::indirect_stats::topology_supported(uint32_t)` allowing all `D3D_PRIMITIVE_TOPOLOGY` values that `detail::vulkan_topology()` maps directly without CPU vertex/index-count expansion: `POINTLIST` (1), `LINELIST` (2), `LINESTRIP` (3), `TRIANGLELIST` (4), `TRIANGLESTRIP` (5), `*_ADJ` (10..13), and console `RECTLIST` (17). - `UNDEFINED` (0), `QUADLIST` (19, requires CPU `count/4` expansion), and patch lists (33..64) remain skipped with `indirect_stats::topology`. - When an indirect `RECTLIST` draw targets a synchronous (`!async_build`) pipeline that cannot build a `rectangle_stage` variant (e.g., already has a GS, no `geometryShader`, or unsupported VS outputs), `prepare_draw()` skips the indirect draw cleanly with `indirect_stats::topology` instead of failing the whole command list with `ReplayResult::unsupported` (direct draws retain `unsupported`). - Aligned `record_indirect`'s viewport check in `runtime/shims/d3d12_com.cpp` with `record_draw`'s `any_nonempty_viewport()` so multi-viewport draws with an empty slot 0 and non-empty slot >0 are not dropped. 2. **Per-reason skip counters (`runtime/src/indirect_draw_stats.h`)**: - Track atomic per-reason counts in `Counts::by_reason[reason_count]`, incremented before `note(event)` so power-of-2 reports include the triggering skip. - `Counts::report()` preserves the exact `[rt] indirect graphics: recorded=... emitted=... record_skips=... replay_skips=...` prefix and appends a single-line `[reason=count, ...]` breakdown when any skip reason is non-zero. 3. **Portable unit tests (`runtime/test/indirect_topology_and_stats_test.cpp`, `runtime/CMakeLists.txt`)**: - Verifies `topology_supported()` across `0..100`, full `prepare` + `emit` replay across all 10 supported topologies (indexed/non-indexed, fixed/counted, all `strip_cut` / index-format combinations), `RECTLIST` built-in GS vs `rectangle_stage` variant vs unexpandable safe skip (with and without `vk.compiles`), direct-draw `unsupported` preservation, unsupported topology skips, `Counts::report()` formatting, and concurrent `skip()` accounting. ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (macOS host, CPU-only portable Vulkan-Headers harness; no game files used). - `indirect_topology_and_stats_test.cpp` (Clang 20, C++20, `-Wall -Wextra -Werror`): - ASan + UBSan: PASS - TSan: PASS (4-thread concurrent `skip()` race check) - `-O2` × 3: PASS - Existing regression suites under ASan + UBSan: - `runtime/test/d3d12_state_map_test.cpp`: PASS (including `topology_quad_list` skip assertion) - `runtime/test/replay_pipeline_compiles_test.cpp`: PASS - Mutation test vs `main`: `TRIANGLESTRIP` indirect draw fails on `main` (`emitted=0`) and passes on this branch (`emitted=1`). - Hygiene: `python3 -I scripts/check_no_game_data.py` on all 5 touched files and `python3 -I tests/test_text_write_line_endings.py` passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:10:27 +00:00
github manually merged commit 79a76a75c3 into gh-pr/1896/base 2026-11-26 10:10:29 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 15:00 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 15:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1896#pullrequestreview-6060049293) · **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.
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-25 15:07 UTC · original · reviewed

Reviewed diff and independently verified commit 79a76a75c on native Windows 11 + MSVC + NVIDIA Ampere GPU (filling in the Windows/MSVC/GPU verification noted as untested in the PR description, against main 71a769d7d):

Environment

  • OS: Windows 11 26H2 (build 26300.9711)
  • Compiler: VS 2022 Build Tools (MSVC 19.44.35230.0, Ninja, RelWithDebInfo)
  • Vulkan SDK: 1.4.363.0
  • GPU: NVIDIA GeForce RTX 3070 Ti (Ampere, 8192 MiB), driver 617.14, Vulkan 1.4.351

Checks run

  • git diff --check: clean
  • Clean isolated MSVC 19.44 build of all 7 targets: 0 errors
  • indirect_topology_and_stats_test: PASS (verified all 10 supported topologies, RECTLIST fallback/safe skip, and per-reason breakdown [mesh=500, topology=11, divisor=500])
  • d3d12_state_map_test: PASS (verified new per-reason summary line [topology=1, first_instance=1, entry=1, robust_index=1, count_limit=1, multi_draw=1, count_feature=1, raw_count_limit=1, argument_usage=1, count_usage=1, divisor=1, index_view=1, stateless=4])
  • replay_pipeline_compiles_test: PASS
  • d3d12_execute_indirect_validation_test (LEONIDA_VK_VALIDATION=1): PASS, 0 validation errors (51 parity cases (WARP=live, HW=NVIDIA GeForce RTX 3070 Ti), positive GPU dispatch ok, 0 failures, [pipeline=10])
  • d3d12_indirect_zero_test (LEONIDA_VK_VALIDATION=1): PASS, 0 validation errors (matched WARP and native RTX 3070 Ti)
  • d3d12_indirect_rt_test (LEONIDA_VK_VALIDATION=1): PASS, 0 validation errors
  • vk_command_replay_test (LEONIDA_VK_VALIDATION=1): PASS, 0 validation errors (cases A–L)

Diff notes

  • topology_supported() cleanly matches the dynamic topologies supported by detail::vulkan_topology() plus console RECTLIST (17), while keeping UNDEFINED, QUADLIST, and patch lists skipped.
  • Routing indirect_rect_variant away from vk.compiles into synchronous pipeline->variant(unbound) ensures an unexpandable synchronous pipeline cleanly records a replay_skip (topology) instead of failing the whole command list with unsupported, while preserving unsupported for direct draws.
  • Counts::report() preserves the existing log prefix, bounds-checks snprintf writes, and increments by_reason[reason] before note(event) so power-of-2 reports include the triggering skip.

Not checked

  • Retail world-frame boot profiling or a GPU execution test specifically issuing non-TRIANGLELIST indirect draws end-to-end through ExecuteIndirect.

LGTM from this Windows 11 + MSVC + NVIDIA RTX 3070 Ti verification (AI-assisted verification; synthetic test fixtures only, no game data).

**@⁠madvillain91** on GitHub · 2026-11-25 15:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1896#pullrequestreview-6060157323) · **reviewed** Reviewed diff and independently verified commit `79a76a75c` on native Windows 11 + MSVC + NVIDIA Ampere GPU (filling in the Windows/MSVC/GPU verification noted as untested in the PR description, against `main` `71a769d7d`): ### Environment - OS: Windows 11 26H2 (build 26300.9711) - Compiler: VS 2022 Build Tools (MSVC `19.44.35230.0`, Ninja, `RelWithDebInfo`) - Vulkan SDK: `1.4.363.0` - GPU: NVIDIA GeForce RTX 3070 Ti (Ampere, 8192 MiB), driver `617.14`, Vulkan `1.4.351` ### Checks run - `git diff --check`: clean - Clean isolated MSVC 19.44 build of all 7 targets: 0 errors - `indirect_topology_and_stats_test`: **PASS** (verified all 10 supported topologies, `RECTLIST` fallback/safe skip, and per-reason breakdown `[mesh=500, topology=11, divisor=500]`) - `d3d12_state_map_test`: **PASS** (verified new per-reason summary line `[topology=1, first_instance=1, entry=1, robust_index=1, count_limit=1, multi_draw=1, count_feature=1, raw_count_limit=1, argument_usage=1, count_usage=1, divisor=1, index_view=1, stateless=4]`) - `replay_pipeline_compiles_test`: **PASS** - `d3d12_execute_indirect_validation_test` (`LEONIDA_VK_VALIDATION=1`): **PASS, 0 validation errors** (`51 parity cases (WARP=live, HW=NVIDIA GeForce RTX 3070 Ti), positive GPU dispatch ok, 0 failures`, `[pipeline=10]`) - `d3d12_indirect_zero_test` (`LEONIDA_VK_VALIDATION=1`): **PASS, 0 validation errors** (matched WARP and native RTX 3070 Ti) - `d3d12_indirect_rt_test` (`LEONIDA_VK_VALIDATION=1`): **PASS, 0 validation errors** - `vk_command_replay_test` (`LEONIDA_VK_VALIDATION=1`): **PASS, 0 validation errors** (cases A–L) ### Diff notes - `topology_supported()` cleanly matches the dynamic topologies supported by `detail::vulkan_topology()` plus console `RECTLIST` (17), while keeping `UNDEFINED`, `QUADLIST`, and patch lists skipped. - Routing `indirect_rect_variant` away from `vk.compiles` into synchronous `pipeline->variant(unbound)` ensures an unexpandable synchronous pipeline cleanly records a `replay_skip` (`topology`) instead of failing the whole command list with `unsupported`, while preserving `unsupported` for direct draws. - `Counts::report()` preserves the existing log prefix, bounds-checks `snprintf` writes, and increments `by_reason[reason]` before `note(event)` so power-of-2 reports include the triggering skip. ### Not checked - Retail world-frame boot profiling or a GPU execution test specifically issuing non-`TRIANGLELIST` indirect draws end-to-end through `ExecuteIndirect`. LGTM from this Windows 11 + MSVC + NVIDIA RTX 3070 Ti verification (AI-assisted verification; synthetic test fixtures only, no game data).
Author
Owner

@⁠DadaCap on GitHub · 2026-11-25 18:16 UTC · original · edited 2026-11-25 18:17 UTC

Retail result in the world phase (RTX 5080, NVIDIA 621.24, Windows 11; merged onto #1592, #424/#429 and the rest of the tree of 7167396852, native_hashes.txt and fspx_gfx present), one run each:

without this with this
indirect record_skips 2,322 at 32,768 recorded, all "topology" 0 at 39,267
VS_TiledLighting + TL_PS_* pipeline builds 0 (three logs) 181

So the tiled deferred lighting was never drawn without it: the G-buffer held a textured scene while the HDR buffer had only sky and emissive lights. No device loss in the run with it (26 minutes).

Two notes, neither against this pull request:

  • those 181 pipelines took 1,164 s between them here, about 6 s each at the median;
  • the surfaces are not right yet: in one frame the lit buffer holds NaN and infinity on clothes and hair, and later frames are black (edited: I first wrote "maximum" and "skin is 0", which was my dump decoding infinity and NaN that way). I am looking into that and can't yet say what it depends on.

indirect_topology_and_stats passes on my tree. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠DadaCap** on GitHub · 2026-11-25 18:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1896#issuecomment-7170686676) · edited 2026-11-25 18:17 UTC Retail result in the world phase (RTX 5080, NVIDIA 621.24, Windows 11; merged onto #1592, #424/#429 and the rest of the tree of [7167396852](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608), `native_hashes.txt` and `fspx_gfx` present), one run each: | | without this | with this | |---|---|---| | indirect `record_skips` | 2,322 at 32,768 recorded, all "topology" | **0** at 39,267 | | `VS_TiledLighting` + `TL_PS_*` pipeline builds | 0 (three logs) | **181** | So the tiled deferred lighting was never drawn without it: the G-buffer held a textured scene while the HDR buffer had only sky and emissive lights. No device loss in the run with it (26 minutes). Two notes, neither against this pull request: - those 181 pipelines took 1,164 s between them here, about 6 s each at the median; - the surfaces are not right yet: in one frame the lit buffer holds NaN and infinity on clothes and hair, and later frames are black (edited: I first wrote "maximum" and "skin is 0", which was my dump decoding infinity and NaN that way). I am looking into that and can't yet say what it depends on. `indirect_topology_and_stats` passes on my tree. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠KushGene on GitHub · 2026-11-25 19:04 UTC · original

Independent RX 6700 XT readback report for 79a76a75c against parent 3d4f66123. Indirect triangle strips produced the same image as direct strips on this card.

Six offscreen pixel-test variants Parent PR
Original triangle-list fixture 6/6 passed 6/6 passed
Four-vertex triangle-strip fixture 0/6 passed 6/6 passed, twice

I adapted only the geometry, arguments and pixel-rendering topology in runtime/test/d3d12_stateful_indirect_pixels.cpp: each quad uses four strip vertices, indexed draws use four indices with base vertex 1, and the expected 64×64 RGBA image and byte-for-byte comparison are unchanged. I applied the same test-only patch to both revisions; runtime code came from the indicated commit.

On the parent, a direct single draw filled the expected 576 red pixels; the indirect draw emitted nothing and missed all 576. The two-record case missed 1,152 pixels. The parent fixtures stop on their first failed non-indexed comparison, before testing the indexed case. On the PR, all 18 indirect image comparisons per run matched both the direct rendering and the expected colors at every pixel. This includes DRAW and DRAW_INDEXED, single and multi-record draws, and GPU count-buffer inputs 0/1/2/3 with maxCount=2. The PR's indirect_topology_and_stats CTest also passed.

Fedora 45, RX 6700 XT (NAVI22), Mesa RADV 26.2.7, Wine Staging 11.21, clang-cl/LLD 23.1.5, RelWithDebInfo. Synthetic triangle-strip coverage only; mesh dispatch, other topologies, retail world geometry and FPS were outside this run. AI-assisted (Codex). Coordination claim.

**@⁠KushGene** on GitHub · 2026-11-25 19:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1896#issuecomment-7171791467) Independent RX 6700 XT readback report for `79a76a75c` against parent `3d4f66123`. Indirect triangle strips produced the same image as direct strips on this card. | Six offscreen pixel-test variants | Parent | PR | |---|---:|---:| | Original triangle-list fixture | 6/6 passed | 6/6 passed | | Four-vertex triangle-strip fixture | 0/6 passed | 6/6 passed, twice | I adapted only the geometry, arguments and pixel-rendering topology in `runtime/test/d3d12_stateful_indirect_pixels.cpp`: each quad uses four strip vertices, indexed draws use four indices with base vertex 1, and the expected 64×64 RGBA image and byte-for-byte comparison are unchanged. I applied the same test-only patch to both revisions; runtime code came from the indicated commit. On the parent, a direct single draw filled the expected 576 red pixels; the indirect draw emitted nothing and missed all 576. The two-record case missed 1,152 pixels. The parent fixtures stop on their first failed non-indexed comparison, before testing the indexed case. On the PR, all 18 indirect image comparisons per run matched both the direct rendering and the expected colors at every pixel. This includes DRAW and DRAW_INDEXED, single and multi-record draws, and GPU count-buffer inputs 0/1/2/3 with maxCount=2. The PR's `indirect_topology_and_stats` CTest also passed. Fedora 45, RX 6700 XT (NAVI22), Mesa RADV 26.2.7, Wine Staging 11.21, clang-cl/LLD 23.1.5, RelWithDebInfo. Synthetic triangle-strip coverage only; mesh dispatch, other topologies, retail world geometry and FPS were outside this run. AI-assisted (Codex). [Coordination claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 19:28 UTC · original

Merged, thanks! Tested 79a76a75c merged onto main with the full Windows suite under Wine (llvmpipe and a RADV iGPU): indirect_topology_and_stats is the only change from main, and it passes on both devices. It also fails with the old gate. The 6700 XT readback and the RTX 5080 retail run in this thread back it up.

  • Checked on main b904919ab + 79a76a75c: it merges cleanly; the semantic suite passes (491 files, 6,312 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 5 changed files.

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

**@⁠aslan2142** on GitHub · 2026-11-25 19:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1896#issuecomment-7172341381) Merged, thanks! Tested `79a76a75c` merged onto `main` with the full Windows suite under Wine (llvmpipe and a RADV iGPU): `indirect_topology_and_stats` is the only change from `main`, and it passes on both devices. It also fails with the old gate. The 6700 XT readback and the RTX 5080 retail run in this thread back it up. - **Checked on `main` `b904919ab` + `79a76a75c`:** it merges cleanly; the semantic suite passes (491 files, 6,312 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 5 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.