Skip to content

DXGI: queue Present after held D3D12 rendering - #6672

Draft
hah346 wants to merge 3 commits into
ItsNotRexed:mainfrom
hah346:dxgi-held-present
Draft

hah346 wants to merge 3 commits into
ItsNotRexed:mainfrom
hah346:dxgi-held-present

Conversation

@hah346

@hah346 hah346 commented Nov 23, 2026

Copy link
Copy Markdown

Depends on: #6357

Claim: #6603 (comment)

A D3D12 queue Wait on an unsignalled fence can keep command lists in software. If DXGI presents the VkImage immediately, later replay writes to a presented image. This queues Present alongside the held work and waits on the rendering queue's progress timeline when blitting. DXGI advances the logical buffer index and present count upon acceptance. The native images are separate from the DXGI buffer ring, which allows accepted frames to wrap through the ring before the first frame reaches Vulkan.

A native Windows probe on RTX 2060 and WARP accepted three non-waitable Presents on a two-buffer chain, then returned DXGI_ERROR_WAS_STILL_DRAWING. ResizeBuffers and final Release drained pending frames after the gate was signalled. The DXGI regression test covers both behaviors.

Windows 11 / MSVC 19.51 / RTX 2060 with Khronos validation: vk_queue_present_order, dxgi_device, dxgi_swapchain and dxgi_swapchain_count all passed. A synthetic guest using gta6rt matched all 2,048 rendered pixels. AI-assisted implementation and testing. No game files.

The DXGI path performs a blit on every present. Its performance has not been measured.

hah346 and others added 3 commits November 23, 2026 17:01
Pass the maintenance1 flag and provide the queue idle and semaphore entry points required by the Vulkan loader. AI-assisted.
Depends on ItsNotRexed#6357. AI-assisted implementation and testing.

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

Request changes: presenting a frame can block submission to an unrelated Vulkan queue for the duration of a GPU wait. The new stable-backbuffer path always enters blit_to_swapchain; that function holds the device-wide submit_mutex_ while waiting indefinitely for blit_fence_ (runtime/shims/dxgi_swapchain.h:462-467, 545-546, reached from the changed code at lines 225-226 and 634). If progress on the presenting queue depends on a later submission from another queue, the other submission cannot take the mutex and neither queue can progress.

I reproduced the lock contention with a scratch-only variant of dxgi_swapchain_test.cpp: create two distinct D3D12 direct queues; submit a Vulkan timeline-semaphore wait with value 1 directly to the first queue's VkQueue, leaving it unsignalled; call Present on the first queue; 200 ms later call Signal on a D3D12 fence through the second queue. A watchdog checks the second Signal for 800 ms and then host-signals the Vulkan semaphore to release the test. With Present, the second Signal was blocked until the watchdog released the gate; without Present, it returned before the watchdog. Both calls eventually succeeded and Vulkan synchronization validation reported zero errors. The unsignalled Vulkan wait is deliberately injected to model stalled GPU work; this is not a pure D3D12 reproducer. The watchdog prevents a permanent hang. The existing independent-queue test uses a callback that does not do Vulkan work, so it does not exercise this path.

Independent AI-assisted review at fd75475f530f2fc373bf7dbd999b38447f38b5a7; Windows 11 build 26300, MSVC 19.44.35230, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RTX 4070 Ti driver 610.88; synthetic inputs only, no game files. Dependency #6357 is included through e9678b9a and remains open.

  • Under vcvars64.bat: cmake -S runtime -B <build> -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo and cmake --build <build> --target dxgi_swapchain_test dxgi_swapchain_count_test dxgi_device_test vk_sync_validation_selftest vk_queue_test -j 4 passed.
  • With LEONIDA_VK_VALIDATION=1, VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1, and VK_LOADER_LAYERS_DISABLE=~implicit~: ctest --test-dir <build> -R "^(vk_queue_present_order|vk_sync_validation|dxgi_device|dxgi_swapchain|dxgi_swapchain_count)$" -V --timeout 120 passed 5/5. The canary found the deliberate write hazard and none after its barrier. The swapchain test reported zero validation errors, 45 host-description comparisons with zero mismatches, three accepted held presents/fourth refused, and held-frame resize/release drain.
  • Negative control: in a separate scratch source copy, deliberately bypassing enqueue_present ordering made vk_queue_present_order fail at present_values.empty(); this was fault injection, not a baseline build.
  • A scratch liveness probe as described above failed with Present and passed without Present. It used the no-maintenance fallback.
  • In a separate scratch variant, enabling VK_KHR_get_surface_capabilities2, VK_KHR_surface_maintenance1, VK_KHR_swapchain_maintenance1 and its feature, then setting info.swapchain_maintenance1=true, made ctest --test-dir <scratch-build> -R "^dxgi_swapchain$" -V --timeout 120 pass with zero validation errors, including the held-frame resize and release cases.

The committed swapchain test does not enable maintenance1; the liveness probe did not exercise it. Ring wrapping was checked through index/count and readback assertions, not a visual comparison of different frames after wrapping. Device loss, injected present/resize failures, and rendering through a different ResizeBuffers1 queue were not exercised. No approval or merge.

@memorypressure

Copy link
Copy Markdown

FAIL-class: rebase, do not close. runtime/test/vk_queue_test.cpp conflicts with current main because #6281 (deterministic stall injection) and #5110 (check_queue_slots()) reworked the same main() head since your base. Nothing is superseded — resolution is mechanical: keep both the --present-order gate and the new check_queue_slots() call. The CMake vk_queue_present_order entry is otherwise correct; C++ parts not built here. Also: no CI checks reported on the branch. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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.

3 participants