Skip to content

dxgi_swapchain: retired swapchain, stale buffer count, unsupported surface, blit filter and composite alpha (RT-SWAPCHAIN-MOCK-FINDINGS) - #2493

Open
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-swapchain-mock-findings
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-swapchain-mock-findings

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-SWAPCHAIN-MOCK-FINDINGS (#1608 (comment)). This is item 2 (a-d) of @kevincommits' finding (#1608 (comment)). Thanks for the mock-driver repros; the tests follow them.

Depends on: none. No other open PR touches runtime/shims/dxgi_swapchain.h.

What and why

VulkanSwapchain (runtime/shims/dxgi_swapchain.h, the DXGI shim's Vulkan swapchain):

  • (a) Retired swapchain kept after a failed vkCreateSwapchainKHR. oldSwapchain is retired even when the call fails (VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933). The shim kept the handle in swapchain_, kept acquiring from it, and passed it as oldSwapchain again on the next resize. It is now destroyed together with its buffers. This matches the host, where a failed ResizeBuffers leaves the swap chain with no buffers (dxgi_swapchain_test already compares that part with the host).
  • (b) Stale exposed count after a failed off-screen ring. destroy_offscreen() ran first. When create_offscreen_backbuffers() then failed, exposed_count_ still held the old BufferCount but there was no ring. image(i) and resource_binding(i) then indexed the native images out of bounds (4 exposed over 2 native images in the repro), and present() skipped the blit. Nothing is exposed now until the new buffers exist. ResizeBuffers with count 0 still keeps the swap chain's count: a new buffer_count_ holds the last count that was built, where exposed_count_ was used before.
  • (c) Unsupported surface kept. When the queue family cannot present to the new surface, the surface is now destroyed. Before, it was kept, so the next create() skipped the support check.
  • (d) Blit filter and composite alpha.
    • The present blit used VK_FILTER_LINEAR unconditionally. It now uses NEAREST for a 1:1 blit. A scaling blit uses LINEAR only when the format has SAMPLED_IMAGE_FILTER_LINEAR with optimal tiling (VUID-vkCmdBlitImage-filter-02001), as vulkan_present.h already does. vkGetPhysicalDeviceFormatProperties is loaded as an optional function; without it the blit is NEAREST.
    • compositeAlpha is now the first mode the surface offers, opaque first, instead of always OPAQUE.

Tested

dxgi_swapchain_count_test (mock driver, no GPU) gains one case per finding:

  • (a): a failed create destroys the retired swapchain, exposes nothing and cannot acquire. The next create passes no oldSwapchain, and a later resize recovers and presents.
  • (b): BufferCount 4 on 2 native images with the ring failing leaves 0 exposed buffers, a null image(i)/resource_binding(i) for 0..3, and a refused present. A later resize recovers.
  • (c): an unsupported surface is destroyed, and the second create() checks support again.
  • (d): the filter for a 1:1 blit, for a scaled blit on a filterable format and for a scaled blit on a format without linear filtering. The composite alpha with only INHERIT offered, and with opaque and inherit both offered.

Each case runs even when an earlier one fails. On main (43a9d562d, header reverted), all four fail:

FAIL: (a) the retired swapchain was not destroyed
FAIL: (b) 4 buffers exposed over 2 native images after the failed ring
FAIL: (c) the unsupported surface was kept
FAIL: (d) 1:1 blit: filter 1, expected 0

With the change, the test passes, including the existing failed-resize cases.

ctest -R "dxgi|swapchain|present": 16/17 pass, including dxgi_swapchain, dxgi_host_parity, dxgi_host_answers, dxgi_waitable_latency and d3d12_present. The failure is xbox_present, which also fails on main on this machine.

No game files.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

…rface, blit filter and composite alpha

Four VulkanSwapchain bugs from a mock-driver review (kevincommits, ubiquitarianism#1608):

- A failed vkCreateSwapchainKHR still retires its oldSwapchain
  (VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933). The retired
  swapchain was kept, acquired from, and passed as oldSwapchain again.
  It is now destroyed with its buffers, as the host's swap chain has no
  buffers after a failed ResizeBuffers.
- When the off-screen back buffers could not be made, exposed_count_
  kept the old BufferCount while there was no ring, so image() and
  resource_binding() indexed the native images out of bounds. Nothing
  is exposed until the new buffers exist. ResizeBuffers with count 0
  still keeps the last built BufferCount.
- A surface the queue family cannot present to was kept, and the next
  create() skipped the support check. It is destroyed.
- The present blit always used VK_FILTER_LINEAR. It is NEAREST for a
  1:1 blit, and LINEAR only when the format allows linear filtering
  (VUID-vkCmdBlitImage-filter-02001). The composite alpha is the first
  one the surface offers, opaque first.

dxgi_swapchain_count_test gains one case per finding, following the
repros.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant