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

Closed
opened 2026-11-26 21:19:22 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1896
Author: @IlyassRS3
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: fix/rt-indirect-topologies-and-stats


📝 Commits (1)

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

📊 Changes

5 files changed (+506 additions, -23 deletions)

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_com.cpp (+2 -2)
📝 runtime/src/indirect_draw_stats.h (+78 -19)
📝 runtime/src/vulkan_replay.h (+10 -2)
➕ runtime/test/indirect_topology_and_stats_test.cpp (+409 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1896 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/rt-indirect-topologies-and-stats` --- ### 📝 Commits (1) - [`79a76a7`](https://github.com/ubiquitarianism/leonida/commit/79a76a75c3fc1c58254d4371f208793416b26a6b) runtime: support dynamic topologies in indirect draws and report per-reason skip counts (RT-INDIRECT-TOPOLOGIES-AND-STATS) ### 📊 Changes **5 files changed** (+506 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_com.cpp` (+2 -2) 📝 `runtime/src/indirect_draw_stats.h` (+78 -19) 📝 `runtime/src/vulkan_replay.h` (+10 -2) ➕ `runtime/test/indirect_topology_and_stats_test.cpp` (+409 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:22 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1907
No description provided.