Skip to content

D3D-494: Fix ANV pipeline statistics for transfers - #4792

Closed
gut0to wants to merge 4 commits into
ProjectLeonida:mainfrom
gut0to:gut0to/d3d-494-anv-stat-query-transfers
Closed

gut0to wants to merge 4 commits into
ProjectLeonida:mainfrom
gut0to:gut0to/d3d-494-anv-stat-query-transfers

Conversation

@gut0to

@gut0to gut0to commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

Intel Mesa ANV may count internal compute work used to implement Vulkan transfers in active D3D12 pipeline-statistics queries. The planner now splits statistics segments around transfer commands only for the Intel open-source Mesa driver, and the emitter closes the active query before each transfer and starts the next segment afterward. The existing segment summation combines the results.

Adds synthetic coverage for ordinary and overlapping statistics queries. The emission regression checks the actual order: begin query, end query, native copy, begin query, end query. The workaround stays disabled for other drivers.

Work item: D3D-494 (claimed in the D3D12 coordination issue). Related report and standalone Vulkan repro: #4709.

Validation

  • Passed after the emission fix: replay_query_edges on Windows (CPU-side synthetic test).
  • Independent Windows/MSVC validation reported replay_query_edges_test and d3d12_vulkan_device_test passing at 0555b56; the latter had two existing C4456 warnings.
  • Intel ANV hardware repro: not run; this machine has an AMD RX 6600, and WSL2 is unavailable.
  • No game files.

AI-assisted (GPT-6).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Built and ran replay_query_edges_test at 0555b563b on Windows 11, RTX 5070 Ti: exit 0, heap boundaries, chunking, persistent queries, predicated copies and queue ownership passed; git diff --check clean.

Pipeline statistics for transfers now use the ANV-correct query path: the shim and replay handle the transfer stage in the statistics query instead of reading a zeroed slot; the added edge test covers the heap boundaries, chunking, persistent queries, predicated copies and queue ownership. No blocking issue.

@shdann

shdann commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

At 0555b563, the planner splits a statistics query around an ordinary buffer copy. The emitter leaves segment 0 active during the copy. It then ends segment 1 before it starts segment 1. The new test checks the plan and passes. The same test fails when it emits the planned commands.

To reproduce, insert this block immediately before CommandList overlapping_transfer; in runtime/test/replay_query_edges_test.cpp:

    auto probe_pool = make_segment_pool(15);
    c.values[probe_pool->pool].resize(2);
    QueryReplay probe_batch;
    expect(probe_batch.plan(transfer_split, {}, 0, true, probe_pool)
           == ReplayResult::success, "plan probe");
    c.events.clear();
    try { emit(transfer_split, {}, vk); }
    catch (...) {
        for (auto& e : c.events) std::printf("%s\n", e.c_str());
        throw;
    }

Build and run replay_query_edges_test. The mock records begin_query, native_copy. It then reports end inactive query and exits 1. The expected order is begin_query, end_query, native_copy, begin_query, end_query.

I also emitted the existing transfer_control list with the workaround off. It records begin_query, native_copy, end_query and passes. The unmodified test also passes. I ran these checks on Windows 11 with MSVC and the CPU mock. No Intel hardware is needed to reproduce this command sequence.

Please apply the planned end and begin operations around the native copy. Please also check the other transfer paths and keep an emission check in the regression test.

AI-assisted.

Fix verified at e84c51f on Windows 11 with MSVC. The original emission probe records begin_query, end_query, native_copy, begin_query, end_query and exits 0. I also emitted the overlapping two-query case. It closes the active physical segment before the copy and opens the next segment after it. The updated replay_query_edges_test passes. These are CPU mock results. Intel ANV hardware behavior remains untested here.

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 0555b56 merged with main 98fa503 on Windows (MSVC 14.51, RelWithDebInfo): pass

  • replay_query_edges_test (CPU only): passes, exit 0. d3d12_vulkan_device_test (shim changed) builds with only the two C4456 warnings that main already has (fixed by runtime test: remove two MSVC C4456 shadowing warnings in d3d12_vulkan_device_test #4781).
  • Negative control: with runtime/src and runtime/shims restored from main, the new test fails to build (C2039: 'exclude_transfers_from_pipeline_statistics' is not a member of ReplayFunctions); with the PR files back it passes again.
  • Not run: the ANV detection (VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA) in the shim needs an Intel Mesa driver, which is not available here; the test only covers the planner with the flag set directly.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

@shdann Thanks for catching this: the planner had assigned segment boundaries, but replay was not emitting them around the native transfer. Fixed in e84c51f: the active query now ends before the transfer and the next segment begins after it. The emission regression asserts the full begin_query, end_query, native_copy, begin_query, end_query sequence. The same command-level guard covers every transfer variant in the classifier; existing per-helper brackets are skipped inside that guard to avoid duplicate query operations. replay_query_edges passes on the updated branch.

@Kam471 and @kapitche, thanks for the independent test and build checks. The Intel ANV hardware run remains outstanding.

@tupacfan04

Copy link
Copy Markdown
Contributor

Tested e84c51fb on Windows 11 x64 (MSVC 19.51.36260.0, NVIDIA RTX 5070, driver 621.24, Vulkan SDK 1.4.363.0): pass.

  • replay_query_edges_test: exit 0. The new emission assertion records exactly begin_query, end_query, native_copy, begin_query, end_query, and the overlapping two-query case sums both sides of the transfer as expected.
  • d3d12_vulkan_device_test: builds (only the two pre-existing C4456 warnings) and passes end to end on the RTX 5070 through the Xbox-ABI proxy, including queries and the non-Intel driver path. The new driver-properties query correctly leaves the workaround off here and does not affect device creation.

Not run: Intel ANV hardware — no Intel GPU available, so the VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA detection remains untested on real hardware. The planner/emitter behavior is covered by the CPU mock.

No game data used. AI-assisted verification.

@abilliontokens

Copy link
Copy Markdown
Contributor

Tested e84c51fbe92e0061d6fe51eb7ad437e3b856a322 on NVIDIA GeForce RTX 5060 Ti (621.24, Windows 11): pass.

Worktree at the PR head, runtime built with scripts/build_runtime.ps1 (MSVC 14.44, RelWithDebInfo), Vulkan pinned to the RTX 5060 Ti (driver 621.24.0.0). The ANV-specific workaround is inert on NVIDIA; this confirms the build and the affected tests pass with no regression on a non-Intel device.

Command and result:

ctest --test-dir runtime/build -R 'replay_query_edges|d3d12_vulkan_device' --output-on-failure
  -> d3d12_vulkan_device ... Passed (11.83 sec)
  -> replay_query_edges  ... Passed (0.01 sec)

python -I -m compileall -q make_game.py tools tests is clean. Synthetic tests only, no game files, no Intel ANV hardware.

@memorypressure

Copy link
Copy Markdown

Verified at head e84c51f merged with main 3faac55 at check time by read-only review (no build or GPU run from this host): all Command alternatives used by statistics_transfer_command exist in command_list.h, the split is opt-in per driverID, the segment-split RAII mirrors the existing statistics pattern, and the replay_query_edges additions are already registered in CTest. No supersession (no D3D-494 work on main). Two flags for a maintainer: no CI checks are scheduled on this branch at all, and the new ctest needs a run on an ANV machine to say anything about the driver-specific path. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only review).

@searyecheesepeaceful

Copy link
Copy Markdown

Tested e84c51f on Intel UHD 630 (CFL GT2, subgroup 8..32), Mesa 25.2.8 ANV, Ubuntu 24.04, LEONIDA_VK_DEVICE=Intel: the new check passes, the ANV counter claim is not shown, and vk_predicated_copy_test fails here on this head and on main.

  • replay_query_edges_test (the check "emitted statistics segments bracket the transfer command"): exit 0, "heap boundaries, chunking, persistent queries, predicated copies and queue ownership passed". It also exits 0 with LEONIDA_VK_DEVICE=NoSuchDevice, so it is host-side and proves the emitted command order, not what the ANV driver counts.
  • vk_command_replay_test: exit 0 on "Intel(R) UHD Graphics 630 (CFL GT2)". With NoSuchDevice: exit 1, "no Vulkan 1.3 device ... matches".
  • vk_predicated_copy_test: exit 1 at "line 138: value==0" (the statistics words after the predicated copy, a loop over 11 words starting at UINT64_MAX), and the same "line 138: value==0" on main 3faac55 in the same slot. ctest -R "replay|predicated": 10 of 11 passed, the failure being vk_predicated_copy.

A CSInvocations value read back from ANV after a transfer was not measured here.

AI-assisted.

@junaydirfan

Copy link
Copy Markdown

Tested e84c51fb (the PR head; it conflicts with current main in runtime/src/vulkan_replay.h) on Linux (CachyOS), Intel Raptor Lake-S iGPU (Xe-LP) with Mesa ANV 26.3.1, and RTX 4080 Laptop with NVIDIA 620.73.04. That Intel GPU is the one that reproduces #4709. The workaround fixes the count on ANV. vk_predicated_copy_test as it stands doesn't use the workaround, though, so it still fails.

vk_predicated_copy_test Intel ANV 26.3.1 RTX 4080
as in the PR fail, line 138: value==0 pass
exclude_transfers_from_pipeline_statistics forced on pass pass
  • Why the test still fails: runtime/test/vk_predicated_copy_test.cpp:40 builds VulkanContext(d.device_proc,d.device,true,true), so the new constructor argument keeps its default of false. The driverID check is only in the D3D12 shim. That is why @gertify still saw line 138 on UHD 630.
  • With VulkanContext context(d.device_proc,d.device,true,true,false,false,true); on line 40, the test passes on ANV: the statistics words after the 17-byte copy read 0. It also still passes on NVIDIA with the split forced on, so the extra segments are harmless where the driver doesn't need them.
  • vulkaninfo gives DRIVER_ID_INTEL_OPEN_SOURCE_MESA for this GPU, so the shim's check would turn the workaround on here. I couldn't run that path myself, because d3d12_vulkan_device_test is Windows-only.
  • Full ctest at the PR head: Intel 49/50, the one failure being vk_predicated_copy (as above). RTX 4080: 50/50. replay_query_edges_test passes on both.

Suggestion: have the test read VkPhysicalDeviceDriverProperties::driverID and pass the flag the same way the shim does. Then vk_predicated_copy passes on ANV, and it covers the workaround on real hardware rather than just the CPU mock.

junaydirfan added a commit to junaydirfan/Leonida that referenced this pull request Nov 23, 2026
@gut0to
gut0to force-pushed the gut0to/d3d-494-anv-stat-query-transfers branch from e84c51f to 42ea27e Compare November 23, 2026 14:40
@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks for the hardware report. I rebased this PR on current main and updated vk_predicated_copy_test to read VkPhysicalDeviceDriverProperties::driverID. The test now enables exclude_transfers_from_pipeline_statistics only for VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA, so it exercises the workaround automatically on ANV and keeps it disabled for other drivers.

The update is in 42ea27eec. git diff --check passes. I could not build locally because CMake/Ninja are unavailable in this environment, so I did not run the GPU test here. The Intel ANV run reported above covers the behavior; the updated test should now cover the driver-detection path as well. AI-assisted.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

Follow-up validation on this host: vk_predicated_copy_test, replay_query_edges_test and d3d12_vulkan_device_test all built with MSVC 19.44.35228. ctest -R 'replay_query_edges|vk_predicated_copy|d3d12_vulkan_device' passed 3/3. The Vulkan test selected Intel Iris Xe Graphics. This host does not run Mesa ANV, so a Mesa ANV machine is still needed to verify the driver-ID path end to end. AI-assisted.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 42ea27eec merged into main 1cc6e3c12 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass (regression check only; the ANV-specific split is for the Intel open-source Mesa driver and was not exercised on NVIDIA).

  • ctest -R "query_edges|predicated_copy" --output-on-failure: 4/4 passed (vk_predicated_copy, d3d12_predicated_copy, predicated_copy, replay_query_edges).

AI-assisted (Claude Code).

@junaydirfan

Copy link
Copy Markdown

Tested 42ea27ee (the PR head) on Linux (CachyOS), on the Mesa ANV machine: pass, and the driver-ID path is taken.

GPU driver vk_predicated_copy_test replay_query_edges_test
Intel Raptor Lake-S iGPU (Xe-LP) Mesa ANV 26.3.1 pass pass
RTX 4080 Laptop NVIDIA 620.73.04 pass pass

Negative control on the same build: with the test file from 473230135 (the flag never set), ANV fails again at line 138: value==0, as before. So on ANV the pass comes from the new driverID check turning the workaround on, and on NVIDIA the workaround stays off and the test still passes.

The head is based on e0999da5. Against current main 21e72aab it conflicts again in runtime/src/vulkan_replay.h.

junaydirfan added a commit to junaydirfan/Leonida that referenced this pull request Nov 23, 2026
@gut0to
gut0to force-pushed the gut0to/d3d-494-anv-stat-query-transfers branch from 42ea27e to 51a690a Compare November 23, 2026 16:10
@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (0c46fa16b); the new head is 51a690a. The rebase preserved both the current mesh-statistics segmentation from main (D3D-291) and the ANV transfer segmentation/emission path (D3D-494). git diff --check is clean.

Windows/MSVC 19.44.35228 RelWithDebInfo validation after the rebase:

  • vk_predicated_copy: passed on Intel Iris Xe.
  • replay_query_edges: passed, including the transfer-emission sequence.
  • d3d12_vulkan_device: builds but currently fails at runtime/test/d3d12_vulkan_device_test.cpp:6564 (tiles == 1). This is the already-known current-main slot-78 proxy regression documented and fixed separately by d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125; the output logs slot 78 routed to SetFrameIntervalX. It is outside this PR's diff.

The ANV end-to-end driver-ID path remains covered by @junaydirfan's Mesa ANV verification above. AI-assisted.

@junaydirfan

Copy link
Copy Markdown

51a690a3 doesn't build on Linux (GCC): runtime/test/replay_query_predication_test.cpp still calls the two planners with one argument, and this PR makes the bool required.

replay_query_predication_test.cpp:664:33: error: too few arguments to function 'void leonida::plan_statistics_segments(PreparedList&, bool)'
replay_query_predication_test.cpp:742:52: error: too few arguments to function 'leonida::ReplayResult leonida::plan_overlapping_statistics_segments(PreparedList&, bool)'

The MSVC run above built only three targets, which is why it didn't show up there. Passing false at the two calls, which keeps their old behaviour, fixes it:

@@ -661,7 +661,7 @@ int main() {
             const bool begin = std::holds_alternative<BeginQuery>(list.commands()[i]);
             prepared.queries.push_back({i, &statistics_heap, begin});  // as prepare() records statistics_active
         }
-        plan_statistics_segments(prepared);
+        plan_statistics_segments(prepared, false);
         expect(prepared.statistics_segment_count == 4, "mixed list: three segments and one for the mesh-only query");
         expect(prepared.statistics_mesh == std::vector<std::uint8_t>({0, 1, 0, 1}),
                "mixed list: vertex, mesh, vertex, then the mesh-only query's mesh segment");
@@ -739,7 +739,7 @@ int main() {
             const bool begin = std::holds_alternative<BeginQuery>(list.commands()[i]);
             prepared.queries.push_back({i, &statistics_heap, begin});
         }
-        expect(plan_overlapping_statistics_segments(prepared) == ReplayResult::success, "plan overlap-mesh list");
+        expect(plan_overlapping_statistics_segments(prepared, false) == ReplayResult::success, "plan overlap-mesh list");
         expect(prepared.statistics_segment_count == 4, "overlap-mesh: four segments");
         expect(prepared.statistics_mesh == std::vector<std::uint8_t>({0, 1, 1, 0}),
                "overlap-mesh: vertex, mesh, mesh, vertex");

With that change, ctest passes 63/63 on both the Intel Raptor Lake-S iGPU (Mesa ANV 26.3.1) and the RTX 4080 Laptop (NVIDIA 620.73.04), including vk_predicated_copy. The head merges cleanly with main 8575d36e.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

Follow-up on the rebase validation: I independently built and ran #7125 on this Windows/Intel Iris Xe host; d3d12_vulkan_device now passes 1/1. That confirms the earlier tiles == 1 failure on the rebase was the known slot-78 regression in current main, not this PR. Details: #7125 (comment). AI-assisted.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks — fixed in 40ff4bc3f.

Both direct planner calls in replay_query_predication_test.cpp now pass false, preserving their pre-transfer-splitting behavior. I built the affected target with MSVC 19.44 and ran:

ctest --test-dir runtime/build-vs -C RelWithDebInfo -R ^replay_query_predication$ --output-on-failure
1/1 passed

git diff --check was clean before committing. This closes the GCC compile break while keeping the new transfer flag explicit at every call site.

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 51a690a merged with main 8575d36 on native Windows 11, MSVC 14.51, Ninja RelWithDebInfo: concern
Clean merge, but the merged tree does not build in full: runtime/test/replay_query_predication_test.cpp lines 664 and 742 still call plan_statistics_segments(prepared) and plan_overlapping_statistics_segments(prepared) with one argument, error C2660 (the planners now take exclude_transfers). This matches the Linux GCC report above. The test file is not touched by the PR.
Built only the PR's targets (-k 0): replay_query_edges and vk_predicated_copy built and passed 2/2 (ctest -R 'replay_query_edges|vk_predicated_copy').
Negative control: with vulkan_backend.h, vulkan_replay.h and d3d12_vulkan_device.cpp reverted to main, both new tests fail to compile (exclude_transfers_from_pipeline_statistics missing, VulkanContext 7-arg constructor missing), so they depend on the change. The stale binaries still ran and passed in that step, so that ctest result means nothing.

@TillusStark26

Copy link
Copy Markdown

Tested the updated head 40ff4bc3f on NVIDIA GeForce RTX 3050 (6 GB, Ampere, driver 621.14, Vulkan 1.4.357), Windows 11, MSVC (VS 2022 Build Tools, RelWithDebInfo), Vulkan SDK 1.4.363.1 (synthetic CTest fixtures, no game files, AI-assisted): pass (confirms replay_query_predication_test.cpp now builds cleanly and non-ANV Vulkan path stays green).

  • Built replay_query_edges_test, replay_query_predication_test, and vk_predicated_copy_test (-DLEONIDA_REQUIRE_VULKAN=ON).
  • ctest -R ^(replay_query_edges|replay_query_predication|vk_predicated_copy)$ --output-on-failure: 3/3 passed (vk_predicated_copy 0.52s, replay_query_predication 0.04s, replay_query_edges 0.04s).

@douline

douline commented Nov 23, 2026

Copy link
Copy Markdown

ANV hardware run, as asked in the claim: tested 40ff4bc3 merged onto main dde82f27 (clean merge) on an Intel Arc A770 (DG2), Mesa ANV 25.2.8, Ubuntu 24.04, LEONIDA_VK_DEVICE=a770. Pass: the PR does what it says on ANV.

Note: #5065 (D3D-518) also splits pipeline statistics around transfers on ANV. The two overlap, so a maintainer may want to keep only one. AI-assisted (Claude Code).

@junaydirfan

Copy link
Copy Markdown

Retested 40ff4bc3 merged into main dde82f27 (clean) on Linux (CachyOS), GCC: it builds, and ctest passes 63/63 on both the Intel Raptor Lake-S iGPU (Xe-LP, Gfx12; Mesa ANV 26.3.1) and the RTX 4080 Laptop (NVIDIA 620.73.04), including vk_predicated_copy, which fails on main on that Intel GPU. Together with @douline's A770 run, that covers both Gfx12 and Gfx12.5 on ANV.

@gut0to

gut0to commented Nov 23, 2026

Copy link
Copy Markdown
Author

@junaydirfan Thanks for the GCC retest and the 63/63 CTest results on both Xe-LP and NVIDIA. Together with the A770 report, the Intel ANV path is now validated across both GPU generations. The potential overlap with #5065 is visible in both PRs; I will leave merge/rebase priority to the maintainers as described in the coordination policy. No code change is needed from this report. AI-assisted.

@douline

douline commented Nov 23, 2026

Copy link
Copy Markdown

Tested 40ff4bc merged onto main 867d922 (clean) on Intel Arc A770 (DG2, Gfx12.5), Mesa ANV 25.2.8, Ubuntu 24.04 / Linux 7.0: pass.

This overlaps my #5065 (D3D-518), which splits only around buffer transfers. #4792 also covers image copies, clears, resolves and the acceleration-structure commands, so it is a superset. If #4792 lands first, I'll close #5065.

No game files. AI-assisted (Claude Code).

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.