Skip to content

DXGI swapchain: Present checks its arguments, ResizeBuffers refuses held buffers, 0 means the client area - #1128

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:dxgi-present-resize
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:dxgi-present-resize

Conversation

@quackottu

Copy link
Copy Markdown
Contributor

Three places where runtime/shims/dxgi_com.cpp differs from DXGI on the host, all measured with a probe on Windows 11 (RTX 5070 and WARP give the same answers). They also match Microsoft's docs.

  1. Present ignored its arguments. DXGI_PRESENT_TEST presented a frame and advanced the back buffer, and a sync interval above 4 was accepted. Now sync > 4 is DXGI_ERROR_INVALID_CALL and DXGI_PRESENT_TEST returns S_OK without presenting. Present1 forwards here, so it gets both.
  2. ResizeBuffers while the app holds a back buffer removed it from the VulkanContext and destroyed its image. DXGI refuses with DXGI_ERROR_INVALID_CALL and keeps the old size. BackBufferResource::held_by_app() (refs_ > 1) makes that check. Nothing inside the shim AddRefs a back buffer: the presenter and replay only hold its resource_id. So the check refuses only real app references.
  3. A zero width or height means the window's client area, both at creation and in ResizeBuffers (the usual ResizeBuffers(0, 0, 0, ...) after WM_SIZE). If either is 0, both come from GetClientRect, as on the host. The shim used 256x256 at creation and kept the old size on resize. When the client area is also 0, it falls back to those old values.
host measurement main this PR
Present(0, DXGI_PRESENT_TEST): S_OK, back buffer index stays 0 presents, index 0 → 1 S_OK, index stays 0
Present(5, 0): DXGI_ERROR_INVALID_CALL S_OK DXGI_ERROR_INVALID_CALL
ResizeBuffers with GetBuffer(0) held: DXGI_ERROR_INVALID_CALL, old size S_OK, image destroyed DXGI_ERROR_INVALID_CALL, old size
create 0x0 on a 320x240 client: 320x240 256x256 client area
ResizeBuffers(0, 0) and (0, 100) on a 400x300 client: 400x300 old size 400x300

Test: runtime/test/dxgi_swapchain_test.cpp gets checks for all of these. With main's dxgi_com.cpp it exits 1 at the first one (FAIL: Present(0, DXGI_PRESENT_TEST) presented a frame). With this change: PASS (...; 0 validation errors). Full ctest on Windows 11, RTX 5070 (621.24), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: 54/54. Only the known VUID-...-01387 that #1027 fixes shows up. Not changed here: host GetBuffer past the last buffer and ResizeBuffers(R32_UINT) return different codes from the shim (DXGI_ERROR_INVALID_CALL vs E_INVALIDARG, E_INVALIDARG vs DXGI_ERROR_UNSUPPORTED); the existing test asserts the latter. #1038 adds a block to the same test, and I'll rebase on whichever lands first.

AI-assisted.

…eld buffers, 0 means the client area

Measured on the host DXGI (RTX 5070 and WARP): Present(n > 4) is
DXGI_ERROR_INVALID_CALL and DXGI_PRESENT_TEST doesn't present;
ResizeBuffers while the app holds a back buffer is DXGI_ERROR_INVALID_CALL
and keeps the size; a zero width or height at creation or in ResizeBuffers
takes the window's client area. The shim presented on TEST, destroyed held
buffers, and used 256x256 / the old size.
@marquezinii

Copy link
Copy Markdown
Contributor

Tested a8b83d8 on NVIDIA GeForce RTX 5070, driver 621.24 (32.0.16.2124), Windows 11 26H2 (26300), MSVC 14.52 (VS Build Tools 18), RelWithDebInfo + Ninja: pass.

  • cmake --build runtime/build: clean, no new warnings.
  • ctest --test-dir runtime/build -C RelWithDebInfo: 53/53 passed (dxgi_swapchain passed, 0.63 s; gameinput disabled, no SDL3 here). Same 53/53 on main at c63773d before applying it.

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested a8b83d8 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass.

  • Build: 0 warnings. ctest: 55/55 passed (gameinput disabled).
  • dxgi_swapchain_test: PASS (CreateSwapChainForHwnd, GetBuffer + GetDesc, clear + readback, Present, ResizeBuffers), also PASS with LEONIDA_VK_VALIDATION=1 and 0 validation errors.

AI-assisted. No game files.

@BACONMANXDGOD

Copy link
Copy Markdown
Contributor

Tested a8b83d8: pass on both GPUs. Windows 11 26200, MSVC 19.44, Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1, applied to main c63773d (merges cleanly). GPUs: Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132) and RTX 5070 Ti Laptop (617.42), picked with VK_LOADER_DRIVERS_SELECT.

  • dxgi_swapchain_test: PASS (CreateSwapChainForHwnd, GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers; 0 validation errors) on the Intel iGPU and on the RTX.
  • Control: with c63773d's dxgi_com.cpp it fails on both GPUs: FAIL: Present(0, DXGI_PRESENT_TEST) presented a frame, plus a Vulkan validation error (an image used in a layout other than the one it was in).

No game files. AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 8fe22c7 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.

5 participants