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

Merged
Tyrannys merged 1 commit from upstream-pr/2493 into main 2026-11-28 09:51:08 +00:00
Tyrannys commented 2026-11-27 19:15:32 +00:00 (Migrated from github.com)

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):

  • (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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5531905348 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2493). Originally posted by [Tyrannys](https://github.com/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): - **(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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code)
lixonik commented 2026-11-27 21:37:26 +00:00 (Migrated from github.com)

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 created VkSurfaceKHR on unsupported queue-family presentation so a later create() does not skip surface-support checking.
  • Failed vkCreateSwapchainKHR calls destroy_swapchain() to retire/clear the old swapchain and exposed buffers (avoiding VUID oldSwapchain-01933), while buffer_count_ retains the last successful BufferCount so a subsequent resize(..., 0) preserves it.
  • Setting exposed_count_ = 0 before create_offscreen_backbuffers() ensures a failed offscreen ring leaves no stale buffer count exposed.
  • blit_filter_ selects VK_FILTER_NEAREST for 1:1 blits or formats lacking VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT, and compositeAlpha selects the first supported mode from caps.supportedCompositeAlpha (OPAQUE preferred).
  • Built dxgi_swapchain_count_test and ran ctest --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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6093539065 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2493#pullrequestreview-6093539065). Originally posted by [lixonik](https://github.com/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 created `VkSurfaceKHR` on unsupported queue-family presentation so a later `create()` does not skip surface-support checking. - Failed `vkCreateSwapchainKHR` calls `destroy_swapchain()` to retire/clear the old swapchain and exposed buffers (avoiding VUID `oldSwapchain-01933`), while `buffer_count_` retains the last successful `BufferCount` so a subsequent `resize(..., 0)` preserves it. - Setting `exposed_count_ = 0` before `create_offscreen_backbuffers()` ensures a failed offscreen ring leaves no stale buffer count exposed. - `blit_filter_` selects `VK_FILTER_NEAREST` for 1:1 blits or formats lacking `VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT`, and `compositeAlpha` selects the first supported mode from `caps.supportedCompositeAlpha` (`OPAQUE` preferred). - Built `dxgi_swapchain_count_test` and ran `ctest --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).
timbot103 commented 2026-11-28 02:01:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:01:51Z.


Reviewed at head 15566d2a8 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built dxgi_swapchain_count_test.
  • dxgi_swapchain_count_test: passed.

Notes (non-blocking)

  • Discarding the retired predecessor on failed native create, clearing exposed count before offscreen ring allocation while preserving the last successful count for zero-count retry, clearing/rechecking unsupported surface handles, picking advertised composite alpha bits, and checking optimal-tiling source features for linear scaling (with nearest for 1:1 blits) all look solid (dxgi_swapchain.h:151-183, 306-318, 567-632; dxgi_com.cpp:390-429).
  • Minor comment accuracy (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 as oldSwapchain).

Approve.

AI-assisted review + local MSVC verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232080559 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2493#issuecomment-7232080559). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T02:01:51Z. --- Reviewed at head `15566d2a8` on Windows 11 (MSVC 2022 `19.44`). ### Verification - Built `dxgi_swapchain_count_test`. - `dxgi_swapchain_count_test`: **passed**. ### Notes (non-blocking) - Discarding the retired predecessor on failed native create, clearing exposed count before offscreen ring allocation while preserving the last successful count for zero-count retry, clearing/rechecking unsupported surface handles, picking advertised composite alpha bits, and checking optimal-tiling source features for linear scaling (with nearest for 1:1 blits) all look solid (`dxgi_swapchain.h:151-183`, `306-318`, `567-632`; `dxgi_com.cpp:390-429`). - **Minor comment accuracy (`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 as `oldSwapchain`). Approve. AI-assisted review + local MSVC verification.
MoonEyes commented 2026-11-28 09:50:51 +00:00 (Migrated from github.com)

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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237505290 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2493#issuecomment-7237505290). Originally posted by [MoonEyes](https://github.com/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)
OreoFR commented 2026-11-28 22:03:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:03:02Z.


Verified by OreoFR

  • Base: main 09c153948 + PR head 15566d2a8; integration package 1 of 6 (20 PRs, merged without conflict)
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; full Python suite; translator suite
  • Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps)
  • Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; Python: the same 7 failing files as main, the PRs' 11 test files pass; translator: 0 failures
  • Verdict: CLEAN PACKAGE (no new failure vs main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246460087 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2493#issuecomment-7246460087). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:03:02Z. --- **Verified by OreoFR** - Base: main `09c153948` + PR head `15566d2a8`; integration package 1 of 6 (20 PRs, merged without conflict) - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; full Python suite; translator suite - Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps) - Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; Python: the same 7 failing files as main, the PRs' 11 test files pass; translator: 0 failures - Verdict: CLEAN PACKAGE (no new failure vs main) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2493
No description provided.