Skip to content

D3D12: refuse query calls the list type can't hold, and CreateQueryHeap node masks above 1 - #1212

Merged
ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
quackottu:query-rules
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
quackottu:query-rules

Conversation

@quackottu

Copy link
Copy Markdown
Contributor

Windows D3D12 refuses several query uses that the Vulkan layer accepted. The new test measures each case against the host runtime on the default adapter and on WARP, and both give the same answers.

  • CreateQueryHeap refuses NodeMask > 1, because there is only one node. This overlaps Runtime: invalid-argument HRESULTs as the host runtime (D3D-49) #558, which handles node masks for other creation calls.
  • BeginQuery / EndQuery / ResolveQueryData check a query_allowed(type) helper. Direct lists take any query type, compute and copy lists take only TIMESTAMP, and bundles take none. A refused call makes Close fail, as on the host.
  • SetPredication is now refused on copy lists as well as bundles.
  • ExecuteCommandLists refuses a list whose timestamps use the wrong heap kind: copy lists need COPY_QUEUE_TIMESTAMP heaps and other lists need TIMESTAMP heaps. The layer only learns heap types at execution, so it reports invalid_query there and submits nothing. VulkanContext::query_heap_type(QueryHeapId) provides the lookup. The test checks only our side of these 3 cases; the host's answer for them isn't measured here.

New test: runtime/test/d3d12_query_rules_test.cpp. HRESULT codes are compared only as success or failure, because the layer returns E_INVALIDARG where the host sometimes returns E_FAIL. Pipeline-statistics heaps are left out because the test device doesn't enable pipelineStatisticsQuery.

Results (RTX 5070 + WARP, validation on):

  • With main's sources the test fails: 15 lines differ from the host GPU and the same 15 from WARP (node masks 2/3; occlusion and binary-occlusion queries on compute, copy and bundle lists; predication on copy lists), and all 3 wrong-kind timestamp lists execute.
  • With the fix there are 0 differences and 0 validation errors, and all 3 lists are refused.
  • Full ctest: 58 of 58 pass.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Collaborator

Tested be0e227 on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. ctest: 58/58 on the RTX 4080 SUPER, including the new d3d12_query_rules. On the Intel UHD 770, d3d12_query_rules also passes, and the 3 failures (d3d12_vulkan_device #962, d3d12_descriptor min-LOD, d3d12_copy_xfmt) also fail on main. With the merge-base runtime/shims/d3d12_com.cpp, d3d12_query_rules fails, so it covers the change.

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested be0e227 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass.

  • Build: 0 warnings. ctest: 59/59 passed.
  • d3d12_query_rules_test: exit 0, also with LEONIDA_VK_VALIDATION=1 and 0 validation errors. Every line printed "same" against the host runtime; timestamps were plausible on direct, compute and copy.

AI-assisted. No game files.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested be0e227 on AMD Radeon RX 9070 (RDNA4), AMD 26.11.2 + WARP, Windows 11 Pro 26300, MSVC 14.44, scripts\build_runtime.ps1: pass. This gives the host comparison a second vendor; the PR measured on an RTX 5070.

d3d12_query_rules_test on RX 9070 + WARP
this PR exit 0: 59 same: lines, 0 differences; the 3 wrong-kind timestamp lists are refused
control: the test with the merge-base (2e5c0f2) d3d12_com.cpp, d3d12_vulkan_device.cpp and vulkan_backend.h exit 1: 15 lines differ from AMD's D3D12 and the same 15 from WARP; all 3 wrong-kind timestamp lists execute (copy list, TIMESTAMP heap, direct list, COPY heap, compute list, COPY heap)

The 15 in the control are the same set as on the RTX 5070:

  • node masks 2/3 on heap types 0, 1 and 5;
  • occlusion and binary-occlusion begin/end and resolve on compute, copy and bundle lists;
  • bundle timestamp and resolve;
  • predication on copy lists.

So AMD's runtime and NVIDIA's agree on every case the test measures.

Full ctest on this PR: 58/58 (gameinput disabled, no SDL3).

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit a3ac0c8 into ProjectLeonida:main Nov 22, 2026
11 checks passed
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
- vulkan_backend.h: #1212's query_heap_type locked mutex_, which VulkanContext no longer has; query_pools_ is
  guarded by resource_mutex_ (add/remove take it unique), so the lookup takes it shared. The runtime didn't build.
- test_salu64_bitwise_data (#1207): its wave64 store went through a V# with word3 = 0 (OOB_SELECT 0, stride 0),
  out of range since #1104; it now uses the raw-buffer word3 the other semantic tests use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@troythedecoyx

Copy link
Copy Markdown
Contributor

Heads-up: be0e227 merges cleanly onto current main (c603b8f) but no longer compiles there, so this is a semantic conflict GitHub doesn't flag.

runtime\src\vulkan_backend.h(744): error C2065: 'mutex_': undeclared identifier
runtime\src\vulkan_backend.h(744): error C2641: cannot deduce template arguments for 'std::lock_guard'

The new query_heap_type() takes std::lock_guard lock(mutex_), but main's bb36812 ("lock split") replaced that mutex_ with resource_mutex_ (a std::shared_mutex) and tracker_mutex_. On main, add_query_pool / remove_query_pool now take std::unique_lock lock(resource_mutex_), so the reader just needs the shared side:

std::uint32_t query_heap_type(QueryHeapId id) {
    std::shared_lock lock(resource_mutex_);
    ...

With only that line changed, on Windows 11 Home, NVIDIA GeForce RTX 4060 Ti, driver 621.24 (32.0.16.2124), Vulkan SDK 1.4.363, MSVC (VS 2022), RelWithDebInfo + Ninja:

  • ctest: 60/60 passed (main alone is 59/59; the new one is d3d12_query_rules).
  • d3d12_query_rules_test run on its own: exit 0, every case same as the host (e.g. close compute resolve occlusion: fails, close bundle predication: fails, timestamps on direct/compute/copy: plausible).

So the PR itself looks right; it just needs a rebase onto main with that lock updated.

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.

6 participants