Skip to content

DXGI: validate flip-model swapchain formats - #1801

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Ryderadzeee:fix/dxgi-swapchain-formats
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Ryderadzeee:fix/dxgi-swapchain-formats

Conversation

@Ryderadzeee

Copy link
Copy Markdown
Contributor

Depends on: #1766

Claimed as a new D3D item in the coordination thread. The format change is the top commit.

Limit flip-model swapchain creation and explicit resize formats to BGRA8 UNORM, RGBA8 UNORM, RGB10A2 UNORM, and RGBA16 FLOAT. Reject invalid formats with the native HRESULT for each API before touching swapchain images. A resize with DXGI_FORMAT_UNKNOWN still preserves the current format. Microsoft’s flip-model format requirements.

Verification

  • Native WARP and RX 9070 XT agreed on nine format cases across CreateSwapChainForHwnd, ResizeBuffers, and ResizeBuffers1. The four supported formats succeeded. Explicit sRGB, typeless, and R32 UINT formats returned DXGI_ERROR_INVALID_CALL on creation and E_INVALIDARG on resize. UNKNOWN returned DXGI_ERROR_INVALID_CALL on creation and preserved the format on resize.
  • The new regression fails on upstream 89b047cd because the shim accepts a disallowed resize format. With the patch, an invalid format leaves the descriptors and back buffers usable, while a valid preserve-format resize still passes GPU readback.
  • Built the Windows runtime and ran dxgi_swapchain and d3d12_present on Windows 11 Pro build 26300, MSVC 19.51, RX 9070 XT driver 32.0.32029.2010, and Vulkan-Headers 1.4.363. Both passed with the count and format changes combined on upstream 003e7812. The window color was confirmed on screen. Vulkan validation was off. Synthetic inputs only.

AI-assisted.

@Taffyyy-ops

Taffyyy-ops commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 083e502 on NVIDIA GeForce RTX 5060 Laptop GPU (driver 621.24, Windows 11): pass — built runtime with MSVC 19.44 (Ninja, RelWithDebInfo, Vulkan validation layer not installed; LEONIDA_GAME_DIR unset). Ran:

  • dxgi_swapchain_test.exe (ctest -R dxgi_swapchain): PASS (0.70 s; CreateSwapChainForHwnd, GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers/ResizeBuffers1, invalid flip-model format rejection and DXGI_FORMAT_UNKNOWN preservation)
  • ctest -R dxgi_swapchain|d3d12_present|xbox_present|vk_presenter_sync: 4/4 passed (4.68 s)
  • Full ctest --test-dir runtime/build --output-on-failure: 90/90 executed passed, 0 failed (5 skipped: 4 game-data tests + d3d12_rgb9e5_rtv; 1 disabled: gameinput, no SDL3; glslangValidator/llvm-mc/spirv-as not installed so shader-dependent runtime tests were not built).

Note: d3d12_present_test passed with on-screen GDI colour check skipped (window not in front).

@mokkymiah

Copy link
Copy Markdown
Contributor

Tested 083e502e (the format commit on top of #1766's count commit) on NVIDIA GeForce RTX 3070, driver 621.01, Vulkan 1.4.357, Windows 11 x64.

  • dxgi_swapchain_test.exe: PASS, including LEONIDA_VK_VALIDATION=1: CreateSwapChainForHwnd, GetBuffer+GetDesc, clear+readback, Present and ResizeBuffers; 0 validation errors. The stacked DXGI: validate flip-model swapchain buffer counts #1766 count validation is in this run too.
  • d3d12_present_test.exe: PASS. 70 frames cleared and presented through the Xbox-ABI proxy, swapchain recreated on resize, the injected out-of-date/suboptimal cases counted apart, and the failed-recreation/failed-blit recovery paths exercised. The on-screen colour check printed its expected "window is not in front" skip; no validation messages.
  • Both were run against a runtime built from this head (MSVC 19.44, Ninja, RelWithDebInfo).

This is the first NVIDIA data point for the combined count+format checks; no game data used. AI-assisted.

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested 083e502 on RTX 4070 SUPER (NVIDIA 616.64) and Intel UHD 770 (101.7092), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0: pass

  • dxgi_swapchain_test and d3d12_present_test: exit 0 on both GPUs.
  • The same two under VK_LAYER_KHRONOS_validation: 0 messages on both GPUs.
  • d3d12_present_test logs the VK_ERROR_OUT_OF_DATE_KHR and injected-failure lines, as on main.

@Luna-OS

Luna-OS commented Nov 22, 2026

Copy link
Copy Markdown

Tested this PR's diff on main 003e781 on RTX 5070 Ti, NVIDIA 621.24, Windows 11, MSVC 14.44: pass

  • dxgi_swapchain: 3 of 3 runs pass. With only the test file applied (shim from main) it fails 3 of 3 at the first new check: CreateSwapChainForHwnd returned a swapchain for an invalid buffer count. The test stops there, so that run says nothing about the format checks on their own.

  • Full ctest -j 4: 102 of 103. The one failure is d3d12_draw, which fails the same way on main (Tests: wait for the bundle blend draws in d3d12_draw (fence 21, not 4) #1793).

  • Host DXGI on the same machine (a small probe, flip-discard swapchain on a D3D12 queue), identical on the RTX 5070 Ti and on WARP:

    • CreateSwapChainForHwnd with R8G8B8A8_UNORM_SRGB, B8G8R8A8_UNORM_SRGB, R8G8B8A8_TYPELESS, R32_UINT or UNKNOWN: DXGI_ERROR_INVALID_CALL (0x887A0001). R8G8B8A8_UNORM, R16G16B16A16_FLOAT and R10G10B10A2_UNORM succeed.
    • ResizeBuffers and ResizeBuffers1 with the first four formats: E_INVALIDARG (0x80070057), and GetDesc1 still reports the old format. UNKNOWN keeps the format and succeeds.
    • Buffer counts: create with 0, 1 or 17 gives DXGI_ERROR_INVALID_CALL; resize to 1 or 17 gives E_INVALIDARG and leaves the buffers as they were; resize to 0 keeps the count.

    These are the codes the PR returns.

  • This was run before DXGI: validate flip-model swapchain buffer counts #1766 was merged; I have not rebuilt on the main that includes it.

No game data used. AI-assisted: yes.

@RobertPattinson007

Copy link
Copy Markdown
Contributor

Tested 083e502 on NVIDIA GeForce RTX 3070 Ti (driver 617.42) and AMD Radeon Graphics, Ryzen 7 7800X3D iGPU (driver 32.0.21045.29003), Windows 11 build 26300, MSVC 19.44, Ninja, RelWithDebInfo: pass.

  • ctest -R "dxgi_swapchain|d3d12_present|xbox_present|vk_presenter_sync": 4/4 on each GPU (AMD selected with VK_DRIVER_FILES).
  • Full ctest on the RTX 3070 Ti: 97 of 98 run passed; 5 skipped (4 game-data tests, d3d12_rgb9e5_rtv), gameinput disabled (no SDL3). The one failure is d3d12_draw (bundle blend pixel), which fails the same way on the base 89b047cd on both GPUs: the known Runtime: carry bundle blend factors back to parent draws #1660 failure, not this change.
  • The PR's dxgi_swapchain_test.cpp built against the base code fails with CreateSwapChainForHwnd returned a swapchain for an invalid buffer count, so the new checks catch the old behaviour.

Code read: dxgi_to_vk_format is only used by the swapchain create and resize paths, so dropping the two sRGB entries does not affect anything else. The four remaining formats match the flip-model list on the DXGI_SWAP_CHAIN_DESC1 page.

Synthetic inputs only. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 2d32cd2 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
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.

7 participants