dxgi_swapchain: retired swapchain, stale buffer count, unsupported surface, blit filter and composite alpha (RT-SWAPCHAIN-MOCK-FINDINGS) #2493
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2493"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T19:15:32Z.
Claimed in the coordination issue as: RT-SWAPCHAIN-MOCK-FINDINGS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226211984). This is item 2 (a-d) of @kevincommits' finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7225705196). 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):vkCreateSwapchainKHR.oldSwapchainis retired even when the call fails (VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933). The shim kept the handle inswapchain_, kept acquiring from it, and passed it asoldSwapchainagain on the next resize. It is now destroyed together with its buffers. This matches the host, where a failedResizeBuffersleaves the swap chain with no buffers (dxgi_swapchain_testalready compares that part with the host).destroy_offscreen()ran first. Whencreate_offscreen_backbuffers()then failed,exposed_count_still held the oldBufferCountbut there was no ring.image(i)andresource_binding(i)then indexed the native images out of bounds (4 exposed over 2 native images in the repro), andpresent()skipped the blit. Nothing is exposed now until the new buffers exist.ResizeBufferswith count 0 still keeps the swap chain's count: a newbuffer_count_holds the last count that was built, whereexposed_count_was used before.create()skipped the support check.VK_FILTER_LINEARunconditionally. It now uses NEAREST for a 1:1 blit. A scaling blit uses LINEAR only when the format hasSAMPLED_IMAGE_FILTER_LINEARwith optimal tiling (VUID-vkCmdBlitImage-filter-02001), asvulkan_present.halready does.vkGetPhysicalDeviceFormatPropertiesis loaded as an optional function; without it the blit is NEAREST.compositeAlphais now the first mode the surface offers, opaque first, instead of alwaysOPAQUE.Tested
dxgi_swapchain_count_test(mock driver, no GPU) gains one case per finding:oldSwapchain, and a later resize recovers and presents.image(i)/resource_binding(i)for 0..3, and a refused present. A later resize recovers.create()checks support again.INHERIToffered, and with opaque and inherit both offered.Each case runs even when an earlier one fails. On
main(43a9d562d, header reverted), all four fail:With the change, the test passes, including the existing failed-resize cases.
ctest -R "dxgi|swapchain|present": 16/17 pass, includingdxgi_swapchain,dxgi_host_parity,dxgi_host_answers,dxgi_waitable_latencyandd3d12_present. The failure isxbox_present, which also fails onmainon 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T21:37:26Z.
Review: APPROVED
Reviewed the diff and tested locally on Windows 11 (MSVC 19.44, Ninja Release).
create()destroys the newly createdVkSurfaceKHRon unsupported queue-family presentation so a latercreate()does not skip surface-support checking.vkCreateSwapchainKHRcallsdestroy_swapchain()to retire/clear the old swapchain and exposed buffers (avoiding VUIDoldSwapchain-01933), whilebuffer_count_retains the last successfulBufferCountso a subsequentresize(..., 0)preserves it.exposed_count_ = 0beforecreate_offscreen_backbuffers()ensures a failed offscreen ring leaves no stale buffer count exposed.blit_filter_selectsVK_FILTER_NEARESTfor 1:1 blits or formats lackingVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT, andcompositeAlphaselects the first supported mode fromcaps.supportedCompositeAlpha(OPAQUEpreferred).dxgi_swapchain_count_testand ranctest --output-on-failure -V -R dxgi_swapchain_count: 1/1 passed (3 cases: extra native images, min above request, request above min; 4 failed-resize cases; 4 mock-driver findings).AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:01:51Z.
Reviewed at head
15566d2a8on Windows 11 (MSVC 202219.44).Verification
dxgi_swapchain_count_test.dxgi_swapchain_count_test: passed.Notes (non-blocking)
dxgi_swapchain.h:151-183,306-318,567-632;dxgi_com.cpp:390-429).dxgi_swapchain.h:585-589): Narrow the comment stating a retired swapchain cannot present — Vulkan still allows presenting images acquired before retirement; discarding it is for DXGI recovery (preventing further acquisition or reuse asoldSwapchain).Approve.
AI-assisted review + local MSVC verification.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T09:50:51Z.
Red/green: the PR's test fails on main and passes with this PR (checked by OreoFR).
Runtime batch of 20 PRs tested by OreoFR (full build, ctest without the game, Python suite, translator): same results as main
09c153948, RTX 4070 Laptop / Windows 11.AI-assisted (Claude Code, Claude Opus 5.5)
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:03:02Z.
Verified by OreoFR
09c153948+ PR head15566d2a8; integration package 1 of 6 (20 PRs, merged without conflict)AI-assisted (Claude Code, Claude Opus 5.5).