Skip to content

Runtime: support overlapping ordinary occlusion queries (D3D-15) - #940

Merged
ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/overlapping-occlusion-queries
Nov 22, 2026
Merged

ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
gabrielsteglich:fix/overlapping-occlusion-queries

Conversation

@gabrielsteglich

Copy link
Copy Markdown
Contributor

Claimed in coordination issue #634 as the D3D-15 follow-up for overlapping ordinary OCCLUSION queries.

What and why

Ordinary D3D12 occlusion queries can overlap. Vulkan replay now splits those scopes into non-overlapping physical queries and sums the applicable 64-bit sample counts on the GPU at resolve time. In-flight submissions retain their physical query pools, so a later command list can resolve a result even when subsequent submissions overwrite the same logical slot.

Pipeline-statistics limitation. A resolve that needs to sum multiple intervals returns ReplayResult::unsupported while a pipeline-statistics query is active. The internal dispatch would otherwise change CSInvocations.

Tested

Tested 747d1c34c042451de63b2624ca09c090b020b7e3 (rebased onto main at 067d3e8) on an NVIDIA GeForce RTX 3090 with driver 621.01, Windows 11 build 26200, MSVC 19.44, and Vulkan SDK 1.4.363.0.

Synthetic draw case Vulkan replay (samples) Native D3D12 on RTX 3090 D3D12 WARP
Crossing queries 80 / 20 80 / 20 80 / 20
Nested queries 84 / 16 84 / 16 84 / 16

vk_overlapping_occlusion passed with Vulkan validation and synchronization validation enabled. It also covered a 261-interval sum, resolving under a false predicate and in a later list, destination offsets, and overwriting logical slots while earlier submissions waited on a fence. command_list, d3d12_vulkan_device, vk_command_replay_test, d3d12_com_test, and depth24_convert_test passed after rebasing.

Checklist

  • All shader and draw inputs were synthetic. No game data, keys, or decryption were used.
  • Runtime-only change. No shader translator rule changed.

AI-assisted implementation and testing.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 747d1c3 on Windows 11 with two GPUs on one machine (MSVC 14.51, full shader toolchain):

RTX 4080 SUPER (32.0.16.1714) Intel UHD 770 (32.0.101.6129)
ctest 34/34 33/34

The one Intel failure is d3d12_vulkan_device's OPTIONS19.SupportedSampleCountsWithNoOutputs mismatch, which fails on main too (reported in #634). It isn't from this PR, and the occlusion tests pass on both vendors.

@evilclanker9000

Copy link
Copy Markdown
Contributor

I checked that the crossing-query results count covered samples with 4× MSAA on 747d1c34c042451de63b2624ca09c090b020b7e3. I added a real 4-sample R32_FLOAT color attachment, hardware average resolve, and readback to a private copy of the fixture. Each physical interval draws a fullscreen triangle writing 1.0 over a zero clear, with scissors of 8×8, 4×4, and 2×2 respectively. Logical query A covers the first two intervals and B the last two.

Enabled samples Resolved color inside each scissor Sample counts from the three images A, resolved while B was active Final A / B
mask 0x5 (two of four) 0.5 128 / 32 / 8 160 160 / 40
mask 0x1 (one of four) 0.25 64 / 16 / 4 80 80 / 20

Every one of the 192 resolved pixels per run matched the CPU geometry/color reference on each adapter, including zeros outside each scissor. Changing only the sample mask halved both query totals while retaining identical pixel coverage. The checked-in vk_overlapping_occlusion CTest also passed on each GPU.

Windows 11, RTX 5080 (32.0.16.1692) and AMD Radeon Graphics (32.0.21045.16010), core and synchronization validation enabled. As in the PR fixture, the native Vulkan draws run at the physical query boundaries. Leonida's production replay records the boundaries and resolves the logical query counts. This adds MSAA coverage to the PR's existing 1× native D3D12 comparison.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested 747d1c3 on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 19.44 (VS generator, RelWithDebInfo), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: pass

Code read: I compiled occlusion_sum.comp with glslangValidator -V --target-env vulkan1.0 -Os -g0, and it gives the same 276 words as occlusion_sum_spirv.h. Committing ended and the saved segment ranges only after a successful submit is a nice fix, since a failed submission used to leave the heap half updated. Keeping each batch's physical pools alive in its command slot until that ticket completes covers resolving in a later list.

Three things, none blocking for the current tests:

AI-assisted (Claude Code).

@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 747d1c3 on AMD RDNA2 iGPU and RTX 5070: pass.

Windows 11 Home 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo (scripts\build_runtime.ps1), LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~. One PC, two GPUs, picked with VK_LOADER_DRIVERS_SELECT: AMD Radeon iGPU of a Ryzen 7 9800X3D (RDNA2, 1002:13C0, AMD 2026.04.17, subgroup 32..64) and NVIDIA GeForce RTX 5070 (Blackwell, 617.42, subgroup 32).

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

@gabrielsteglich

Copy link
Copy Markdown
Contributor Author

Hi @ItsNotRexed and maintainers, could you review this PR when you have a chance?

All 11 GitHub checks passed on 747d1c3. Independent runs confirmed vk_overlapping_occlusion on NVIDIA (RTX 4080 SUPER, RTX 3070, and RTX 5070), AMD (RDNA2 iGPU), and Intel (UHD 770). The Intel run also reproduced an OPTIONS19.SupportedSampleCountsWithNoOutputs failure on main. RTX 4080 SUPER and Intel results · RTX 3070 results · AMD and RTX 5070 results

Thanks to everyone who tested it.

@quackottu quackottu 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.

Tested 747d1c3 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 34
  • vk_overlapping_occlusion_test (changed here): exit=1 validation=0 | line 300: argc == 3
  • 38 test programs in the build pass with 0 validation errors
  • Not run (they take an input file, not covered here): vk_overlapping_occlusion_test
  • d3d12_clear_test fails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as on main 4a36bb1 here, so not from this PR; #521 addresses it

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested 747d1c3 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass (no regression against main).

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest with validation on: 34/34 pass.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and the Khronos validation layer: d3d12_com_test, d3d12_descriptor_test, d3d12_fence_timing_test, d3d12_fence_waiter_test, d3d12_gcl8_test, d3d12_method_variants_test, d3d12_node_mask_test, d3d12_resource_desc_test, d3d12_sampler2_test, d3d12_state_map_test, d3d12_typeless_rtv_test, d3d12_uav_clear_test, d3d12_vulkan_device_test, vk_command_replay_test pass, with 0 validation messages (no VUIDs).
  • d3d12_clear_test fails, the same as on plain main dcd8ecf on this GPU (NVIDIA rounds the 0.5 clear on 8-bit UNORM/SNORM down, Vulkan 7f, WARP 80, plus one depth-format-55 case). This is not caused by this PR.
  • vk_overlapping_occlusion (new) passes under ctest with validation on.

The vk_* harness tests that need translated SPIR-V weren't run. No game files used. AI-assisted run (Claude Code).

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Retested after the merge: 0029a87 on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 19.44 (VS generator, RelWithDebInfo), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: still passes

What changed since my run on 747d1c3: the code commit is the same, so the new parts are the merge and 0029a87. I read the merge with --remerge-diff, and the resolution looks right:

  • emit() gets main's &open_labels, and close_labels uses your local replay copy, which carries sum_occlusion.
  • main's conditional_rendering flag is replaced by predicate.buffer throughout, and the depth-24 lambda restarts the predicate from it.
  • In replay(), main's zero_clear_unavailable check runs before queries.plan, so a refused list leaves the query state untouched.
  • enable_occlusion_sums and the timestamp period share one if before main's debug-utils block. CMake keeps vk_device_pick_test and the d3d12_descriptor test, and drops only the duplicate glslangValidator lookup.

0029a87 makes the benchmark plan and commit the query batch the way VulkanQueue::execute does, counting the plan in prepare and the commit and free in emit. It's test-only.

Heads-up: main moved again while I was testing (now 48ad23f). #743 and #990 touch vulkan_backend.h and vulkan_replay.h, and this branch conflicts with it in those two files. Still true: this and #889 conflict with each other in four files (d3d12_vulkan.md, d3d12_vulkan_device.cpp, vulkan_backend.h, vulkan_replay.h).

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 0060d50 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.

8 participants