Skip to content

Runtime: split pipeline statistics around predication and footprint helpers (D3D-162 follow-up) - #1899

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
hadagalberto:stats-helpers
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
hadagalberto:stats-helpers

Conversation

@hadagalberto

Copy link
Copy Markdown
Contributor

Claimed in coordination issue #1745 as a follow-up to D3D-162 (#1519) and #1624.

What and why

Replay refused three commands while a pipeline-statistics query was active, because their compute dispatches would count in the application's CSInvocations:

docs/d3d12_vulkan.md listed all three under "Not implemented yet".

They now get the segment split #1519 gave query resolves:

  • Split. The statistics query ends its current physical segment right before the helper dispatch and begins the next one right after it. The query's result is the per-counter sum of its segments (statistics_sum.comp).
  • Numbering. Query resolves and these helpers share one segment numbering, so a query can mix both in any order.
  • Placement. The markers for non-query commands live on detail::Prepared. emit() places them around capture_predicate, emit_predicated_copy and the depth24 conversion parts. The segment ends and begins all fall outside any rendering scope.
  • Without a segment pool (the single-list replay(), or a queue without the summation helper), the three commands are still refused while statistics are active. The refusal happens in prepare() before any helper scratch is allocated (the property D3D-162: Keep footprint conversions out of pipeline statistics #1624 added), and again in QueryReplay::plan. prepare() takes statistics_helpers, which defaults to false.

Tests

All new GPU checks run under the Khronos validation layer:

  • vk_predicated_copy: captures, rebinding, executing and suppressed predicated copies inside an otherwise empty statistics query. The bytes stay exact and all 11 counters are 0.
  • depth24_convert: both conversion directions for D24 and RGB96 inside a statistics query. The results are unchanged and all 11 counters are 0.
  • d3d12_predicated_copy: the same check through the D3D12 layer, compared with WARP.
  • replay_query_predication (CPU): the exact emitted order for a capture, a predicated copy, a footprint copy and a resolve in one query, and the refusal without a pool.
  • predicated_copy and typeless_rtv (CPU): both preparation modes. The refusal path allocates nothing.

Tested on Windows 11, MSVC 14.51, Vulkan SDK 1.4.363.0, AMD driver 26.11.2, with LEONIDA_VK_VALIDATION=1:

  • Radeon RX 7900 XTX (RDNA3), on main 6a6704d: CTest 107/109. The two failures, d3d12_compute (device proxy ref count, line 515) and d3d12_draw (vkDestroyPipeline while in use), fail the same way on unmodified main 6a6704d.
  • Ryzen 9 7900X3D's Radeon Graphics (RDNA2 iGPU, LEONIDA_VK_DEVICE=Radeon(TM)): the 9 tests this PR touches or depends on (predication, depth24, typeless RTV, occlusion) all pass.
  • scripts/run_gpu_tests.py: 164/173, 9 skipped, no VUID in the output.

No game files. AI-assisted: implemented by OpenAI Codex, then reviewed, rebuilt and tested with Claude Code.

🤖 Generated with Claude Code

…elpers (D3D-162)

Replay refused SetPredication, predicated buffer copies and D24/RGB96 footprint conversions while a
pipeline-statistics query was active (ItsNotRexed#1624 added the last), because their compute dispatches would count in the
application's CSInvocations. They now get the segment split ItsNotRexed#1519 gave resolves: the statistics query ends its
current physical segment right before the helper dispatch and begins the next right after it, and its result is
the per-counter sum of the segments. Query resolves and these helpers share one segment numbering. The markers for
non-query commands live on detail::Prepared, and emit() places them around capture_predicate,
emit_predicated_copy and the depth24 conversion parts, outside any rendering scope.

Without a statistics segment pool (the single-list replay(), or a queue without the summation helper), the three
commands are still refused while statistics are active, before any helper scratch is allocated (prepare() takes
statistics_helpers, false by default) and again in QueryReplay::plan.

Tests (Khronos validation on): vk_predicated_copy and depth24_convert run their helpers inside an otherwise empty
statistics query. Their results stay byte-exact and all 11 counters are 0. d3d12_predicated_copy compares with
WARP the same way. replay_query_predication checks the emitted order for a capture, a predicated copy, a footprint
copy and a resolve in one query, and the refusal without a pool. predicated_copy and typeless_rtv check both
preparation modes.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Serrambi Serrambi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 0bde4c82 and tested on NVIDIA GeForce RTX 5070 Ti (driver 610.88, Windows 11 Pro, MSVC 19.50.35719.0, Vulkan SDK 1.4.363.0): approve.

Code review (runtime/src/vulkan_backend.h, runtime/src/vulkan_replay.h, and tests/docs)

  • plan_statistics_segments() cleanly unifies SetPredication captures, predicated buffer copies, D24/RGB96 footprint conversions (p.has_depth24), and non-timestamp resolves under one physical statistics segment sequence.
  • QueryReplay::plan() refuses statistics_helpers-marked lists cleanly with ReplayResult::unsupported when no statistics_pool is present, and prepare(..., statistics_helpers = false) continues to reject those helpers inside an active pipeline-statistics query before allocating scratch/descriptors (verified by predicated_copy_test and replay_query_predication_test case 8).
  • In emit(), p.has_depth24 only runs inside one mutually exclusive upload (p.binding.image) or readback (else) branch around depth24_parts, while Predication and predicated_copy cleanly bracket their helper dispatches with end_statistics() / begin_statistics(), keeping vkCmdEndQuery / vkCmdResetQueryPool / vkCmdBeginQuery compliant with VK_EXT_conditional_rendering.

Checks on 0bde4c82

  • vk_predicated_copy_test.exe (LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 Vulkan validation errors)
  • depth24_convert_test.exe, d3d12_predicated_copy_test.exe (LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 validation errors)
  • ctest --test-dir runtime/build --output-on-failure -R "^(replay_query_predication|predicated_copy|typeless_rtv|vk_predicated_copy|depth24_convert|d3d12_predicated_copy|vk_overlapping_occlusion|vk_binary_occlusion|d3d12_query_rules)$" (default): 8/8 passed (depth24_convert, vk_overlapping_occlusion, vk_binary_occlusion, d3d12_predicated_copy, d3d12_query_rules, typeless_rtv, predicated_copy, replay_query_predication)
  • Same ctest subset under LEONIDA_VK_VALIDATION=1 (GPU tests depth24_convert, vk_overlapping_occlusion, vk_binary_occlusion, d3d12_predicated_copy, d3d12_query_rules): 5/5 passed, 0 validation errors

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 0bde4c82 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Vulkan SDK 1.4.363: pass.

AI-assisted (Claude Code).

@SirKingg

Copy link
Copy Markdown
Contributor

Tested 0bde4c8 on NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088, Windows 11 build 26300 (MSVC 14.44 / VS 2022 Build Tools, Windows SDK 10.0.26100.0, Ninja, RelWithDebInfo): pass for everything this PR touches.

No game files used. AI-assisted testing.

@ItsNotRexed
ItsNotRexed merged commit 12bad64 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants