Skip to content

DXGI: present on the supplied Vulkan rendering queue - #6357

Open
hah346 wants to merge 2 commits into
ItsNotRexed:mainfrom
hah346:dxgi-main-present-order
Open

hah346 wants to merge 2 commits into
ItsNotRexed:mainfrom
hah346:dxgi-main-present-order

Conversation

@hah346

@hah346 hah346 commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue.

A synthetic guest on main at 561b65a used the factory from its Xbox device’s DXGI adapter, created two direct queues, and presented immediately after drawing on the second. Khronos validation reported SYNC-HAZARD-WRITE-RACING-WRITE because the swapchain presented on the factory’s Vulkan queue.

The swapchain now uses the supplied direct queue for allocation and presentation. When swapchain_maintenance1 is enabled, a per-image semaphore orders the draw before presentation and a present fence covers resource retirement. Other devices wait for the rendering queue before Present. This uses the existing adapter-factory path and is independent of #2098.

Windows 11, MSVC 19.51, RTX 2060 driver 616.64, Khronos synchronization validation. The guest matched all 2,048 pixels and presented without the hazard. dxgi_swapchain now presents before the caller waits on a fence. dxgi_swapchain, dxgi_swapchain_count and dxgi_device passed. AI-assisted implementation and testing.

@hah346

hah346 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Negative control on Windows 11 / RTX 2060 616.64 with Khronos synchronization validation. I copied only the byte-identical dxgi_swapchain_test.cpp from c54fe42 onto 561b65a and built it against the unmodified runtime. It failed with four WRITE_RACING_WRITE and READ_RACING_WRITE validation errors across native presentation and offscreen blitting. The same fixture passed on the PR.

Separate follow-up for deferred D3D12 work. A synthetic guest queues Wait on an unsignalled fence, submits a frame, calls Present, and signals the fence from the CPU after Present returns. On c54fe42 later readback matches, but Vulkan reports WRITE_AFTER_PRESENT and use of a non-acquired swapchain image when the held draw is released. The case fixed here has already-submitted rendering. DXGI also needs to order Present behind work the runtime still holds in software. AI-assisted verification.

@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: the Windows test build is broken. runtime/shims/dxgi_swapchain.h:116-119 adds a required maintenance1 constructor argument, but runtime/test/dxgi_swapchain_count_test.cpp:250-252 still supplies eight arguments. MSVC 19.44 reports C2661 building dxgi_swapchain_count_test. The fake Vulkan table also lacks the newly required vkQueueWaitIdle, vkCreateSemaphore and vkDestroySemaphore functions, so updating the argument alone would make load() fail instead of running the test.

Independent AI-assisted review and synthetic Windows 11 build 26300 testing at c54fe42, RTX 4070 Ti, NVIDIA 610.88, Vulkan SDK 1.4.363.0; no game files:

  • cmake -S runtime -B runtime\build-review -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo under vcvars64: passed.
  • cmake --build runtime\build-review --target dxgi_swapchain_test dxgi_swapchain_count_test dxgi_device_test vk_sync_validation_selftest -j 4: failed with the C2661 above. Building the same targets without dxgi_swapchain_count_test passed.
  • With LEONIDA_VK_VALIDATION=1 and VK_LOADER_LAYERS_DISABLE=~implicit~, ctest --test-dir runtime\build-review -C RelWithDebInfo -R "^(dxgi_swapchain|dxgi_device)$" -V --timeout 120: both passed; swapchain reports zero validation errors. The test requested two graphics queues and uses the second Vulkan queue for the D3D queue. Its device enables only VK_KHR_swapchain, so this covers the no-maintenance fallback, not maintenance1.
  • With the same environment, ctest --test-dir runtime\build-review -C RelWithDebInfo -R "^vk_sync_validation$" -V --timeout 120: passed; detected one deliberate write-after-write hazard and zero with a barrier.
  • A scratch copy of dxgi_swapchain_test.cpp, built with the same MSVC libraries and modified only to enable VK_KHR_get_surface_capabilities2, VK_KHR_surface_maintenance1, VK_KHR_swapchain_maintenance1 and its feature and set info.swapchain_maintenance1=true, passed on this GPU with synchronization validation and zero reported errors, including present and resize. This is not a committed regression test.

One additional ordering concern remains unverified: VulkanQueue holds Wait-before-Signal work on the CPU, whereas VulkanSwapchain::present submits directly to the underlying VkQueue. Please check a queue Wait on an as-yet-unsignaled fence followed by rendering and Present: a raw queue submit or idle may bypass the held work. Failure injection for present/resize, queue lifetime after releasing application references, and a swapchain rendered through a different ResizeBuffers1 queue were not exercised here. No approval or merge.

Pass the maintenance1 flag and provide the queue idle and semaphore entry points required by the Vulkan loader. AI-assisted.
@Ingenioeren

Copy link
Copy Markdown
Contributor

Tested the updated e9678b9 head on Radeon RX 6750 XT (driver 32.0.21045.29003), Windows 11 build 26200, MSVC 19.43, SDK 10.0.26100, Ninja RelWithDebInfo and Vulkan SDK 1.4.341.1. Both targets built. dxgi_swapchain passed with Khronos synchronization validation enabled, zero validation errors and zero mismatches across 45 native swapchain-description comparisons. dxgi_swapchain_count also passed the three stubbed image-count cases. This run covers the submitted-rendering path exercised by the PR test. Synthetic-only, AI-assisted.

@nelciojr

nelciojr commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested e9678b9a (merge base 561b65a8) on RTX 3060 (desktop), NVIDIA 621.24, Windows 11 Pro 26300, MSVC 19.44, Ninja, Vulkan SDK 1.4.363.0. AI-assisted (Claude Code). Pass.

  • Full tree builds. With LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1, vk_sync_validation (canary), dxgi_device, dxgi_swapchain and dxgi_swapchain_count pass 3/3.
  • Negative control: this PR's dxgi_swapchain_test.cpp, built against main 561b65a8, fails 3/3 with 8 WRITE_RACING_WRITE reports.
  • Full ctest (at c54fe423 plus the same test-stub fix): 246/247, the same as main. The one failure is d3d12_indirect_dispatch_count, fixed by d3d12_indirect_dispatch_count_test: its compute fixture reads the root UAV at s4:s5 (D3D-448 layout) #5792.

Side note: without swapchain_maintenance1, Present now calls vkQueueWaitIdle every frame (correct, but one CPU stall per frame).

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

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested e9678b9 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass, with one gap

  • The head moved from c54fe42 to e9678b9 while I was testing; everything below is on e9678b9.
  • ctest xbox_present_readback_size, vk_presenter_capture_colour, vk_presenter_sync, dxgi_device, d3d12_present, xbox_present, dxgi_swapchain, dxgi_swapchain_count, validation 0 and 1: 8 of 8 pass in both runs.
  • dxgi_swapchain_test.exe with LEONIDA_VK_VALIDATION=1 (the test turns on synchronization validation, dxgi_swapchain_test.cpp:350): exit 0, "PASS (... Present, ResizeBuffers; 0 validation errors)".
  • Negative control: runtime/shims (the six PR files) at 561b65a, the PR's dxgi_swapchain_test.cpp kept, built dxgi_swapchain_test and dxgi_device_test. Validation 0: exit 0. Validation 1: exit 1, "FAIL: 4 Vulkan validation errors" (2 x WRITE_RACING_WRITE in vkCmdPipelineBarrier, 1 x READ_RACING_WRITE in vkCmdBlitImage, 1 x WRITE_RACING_WRITE in vkQueuePresentKHR). This matches the RTX 2060 result already posted on the PR.
  • dxgi_swapchain_count_test does not compile against the base shims (dxgi_swapchain_count_test.cpp(262): no VulkanSwapchain::VulkanSwapchain overload takes 9 arguments), so it is not part of the control.
  • Gap: this driver exposes VK_KHR_swapchain_maintenance1 and VK_KHR_surface_maintenance1 (vulkaninfo), and info.swapchain_maintenance1 is set in d3d12_vulkan_device.cpp:8926. I did not confirm from the test output which present path dxgi_swapchain_test took, so I cannot say whether the maintenance1 branch ran.
  • Not done: a windowed run with a resize or occlusion change under synchronization validation.

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.

5 participants