Repository navigation
d3d12: fence event handles and invalid descriptor heap types answer as the host does (D3D round 4a) - #4609
d3d12: fence event handles and invalid descriptor heap types answer as the host does (D3D round 4a)#4609kapitche wants to merge 2 commits into
Conversation
…ypes answer as the host does (D3D round 4a) SetEventOnCompletion and SetEventOnMultipleFenceCompletion take the event handle before the fence value: a closed, pseudo or non-event handle is E_HANDLE and an event without EVENT_MODIFY_STATE is E_ACCESSDENIED on the RTX 4080 SUPER, the UHD 770 and WARP; the layer answered S_OK. GetDescriptorHandleIncrementSize of a heap type past DSV is 0 on the host, 32 here. d3d12_object_methods compares 74 queue, fence, resource, descriptor heap, allocator, list and device rows with both host adapters.
slopradish
left a comment
There was a problem hiding this comment.
Verified locally: built d3d12_object_methods_test from PR #4609's head with the local Vulkan headers, then ran it on this host (RTX 3090, native D3D12 + WARP comparison):
object methods: 74 rows compared with 2 host adapters, 0 differ
The change is sound: NtQueryObject is the right way to check both the handle type and granted access — DuplicateHandle cannot do the access check because it grants whatever access you ask for. Checking before reading the fence value matches host ordering, and keeping the null event's blocking meaning preserves existing behaviour. The descriptor-heap increment returning 0 for out-of-range types is a clean guard.
The test compares against two real host adapters and only counts rows where they agree, which avoids encoding a driver quirk as the expected answer. The two undocumented error codes are explicitly attributed to host measurement rather than claimed from spec.
No game data or keys involved.
Kam471
left a comment
There was a problem hiding this comment.
Built and ran d3d12_object_methods_test at 51e82d26 on Windows 11 25H2 (build 26200), RTX 5070 Ti, driver 621.24, non-elevated with Developer Mode off: exit 1, object methods: 74 rows compared with 2 host adapters, 8 differ. The difference is not in the fence fixes — it is the test's SetStablePowerState rows poisoning the shared host device.
What the run shows (LEONIDA_PROBE=1):
device: SetStablePowerState FALSE | layer 0 | host 80004005 | host 80004005 <-- DIFF
device: SetStablePowerState TRUE | layer 0 | host 80004005 | host 80004005 <-- DIFF
device1: SetEventOnMultipleFenceCompletion all, already complete | layer 1 | host ffffffffffffffff | ... <-- DIFF
device1: ... any, one pending | layer f4242 | host ffffffffffffffff | ... <-- DIFF
device1: ... all, one pending | layer f4242 | host ffffffffffffffff | ... <-- DIFF
device1: ... zero fences | layer 80070057 | host 0 | ... <-- DIFF
device1: ... invalid flags | layer 80070057 | host ffffffffffffffff | ... <-- DIFF
device1: ... invalid event handle | layer 80070006 | host ffffffffffffffff | ... <-- DIFF
I reproduced the cause with a standalone native-D3D12 probe (no repo code): on a fresh device CreateFence is S_OK; after SetStablePowerState(FALSE) returns 80004005 (no Developer Mode), the next CreateFence returns 887a0005 (DXGI_ERROR_DEVICE_REMOVED), and it stays removed. The test runs the two SetStablePowerState cases before the fence cases on the same host device, so every later fence case hits its -1 early-return sentinel on both host adapters; hosts_agree is true and the sentinel is compared as if it were a host answer. On a fresh device the same native calls return exactly the layer's answers (80070057, 80070057, 80070006), so the fence/descriptor fixes themselves look right.
Two things to fix before this can merge:
SetStablePowerStateind3d12_vulkan_device.cpp:4490returnsS_OKunconditionally; the host answersE_FAILwhen Developer Mode/the privilege is absent. Either implement that check or document and skip the row when the host fails.- The test must not let the
SetStablePowerStatecases remove the shared host device for later rows: run them last, give them a throwaway device, or detect a removed host device (aCreateFenceprobe) and mark the remaining rows host-unavailable. Treat the-1/-2/-3setup sentinels as "row not comparable", not as a host answer.
Everything else in the run matched (GetDescriptorHandleIncrementSize out-of-range → 0, the event-handle errors, resource/queue/descriptor rows). Happy to re-run once the rows are isolated.
…ces and is compared only where the host accepts it
|
Thanks, the diagnosis is right: the two Pushed ffa8037 (test only). I cannot reproduce the refusal here: Developer Mode is on on this machine ( |
|
Tested 1.
|
|
Tested head
AI-assisted (Devin). |
|
Corroborating data point on the AI-assisted (Devin). |
|
Tested ffa8037 on Intel UHD 770 (driver 32.0.101.7088), Windows 11, MSVC 19.44, Vulkan SDK 1.4.357: pass. |
|
Tested The row is So it isn't the event-handle change. It's a gap in the layer's
Happy to measure a fix on this card. AI-assisted (Claude Code). No game files. |
Claimed in #4421 (D3D round 4a): #4421 (comment)
What broke:
ID3D12Fence::SetEventOnCompletionandID3D12Device1::SetEventOnMultipleFenceCompletionnever looked at the event handle. Repro:fence->SetEventOnCompletion(1, CreateSemaphoreW(...)), a closed event,GetCurrentProcess()or0x1234all returnedS_OKand the wait was then never signalled. The host runtime (RTX 4080 SUPER, Intel UHD 770, WARP, all the same) answersE_HANDLE(0x80070006) for a handle that is not an event, before it reads the fence value, andE_ACCESSDENIED(0x80070005) for an event opened withoutEVENT_MODIFY_STATE. AlsoGetDescriptorHandleIncrementSizeof a heap type past DSV returned 32; the host returns 0.Fix:
check_event_handleind3d12_com.cppasksNtQueryObjectfor the handle's type and granted access (DuplicateHandlecannot be used for the access check, it grants any access) and both wait calls use it; the increment size is 0 for a type outside the enum. The null event keeps its blocking meaning. Microsoft's pages document neither error, so only the host-measured answers are implemented.Test: new
d3d12_object_methods_test(ctestd3d12_object_methods): 74 rows over command queue, fence, resource, descriptor heap, query heap, allocator, list and the device calls without a description, run on the layer and on the hardware and WARP host devices; a row counts only where both hosts agree. Rows the host faults on (a null fence or output) are left out, and so are a CPU or queueSignalbelow the fence's value (the host lowers the fence; a Vulkan timeline cannot, see theFencecomment),GetGPUVirtualAddressand the shader-visible GPU descriptor start (this test's Vulkan device has no address arena) andID3D12Resource1(#2590, #3374).Tested: Windows 11, MSVC 14.51, worktree built from this commit (only the needed targets).
d3d12_object_methods,d3d12_com,d3d12_fence_timing,d3d12_fence_events,d3d12_fence_waiter,d3d12_queue_wait,d3d12_queue_wait_timeout,d3d12_multithreadandd3d12_vulkan_devicepass on the RTX 4080 SUPER and on the Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*;d3d12_queue_waitis skipped on Intel by its own rule).d3d12_queue_wait_timeouttimed out once on the RTX during a run while a second build was going and passed on the rerun. Negative control: withd3d12_com.cppandd3d12_vulkan_device.cppfrom upstream/main the test fails with 15 rows differing on both GPUs (for examplefence: SetEventOnCompletion invalid handle: layer 0, host 80070006).Touches one region of each shim and one block in
runtime/CMakeLists.txt(before "Fences and timing"); the other two round 4 pull requests add their blocks elsewhere in that file.AI-assisted.