Repository navigation
dxgi: keep DXGI_SCALING_NONE on HWND swapchains and present it unscaled (D3D-444) - #4231
Exopus-0x65f7ad0 wants to merge 1 commit into
Conversation
…ed (D3D-444) An HWND swapchain created with DXGI_SCALING_NONE reported STRETCH from GetDesc1 and its back buffer was stretched to the window. Host DXGI (Windows 11, RTX 5060 Ti) keeps NONE and draws the back buffer unscaled at the top-left corner; it also refuses ASPECT_RATIO_STRETCH (CoreWindow and composition only) and values past it with DXGI_ERROR_INVALID_CALL on an HWND swapchain, which the layer accepted. - GetDesc1 reports the Scaling the swapchain was created with. - Present's copy from the back buffer to the window's image follows it (runtime/src/present_scaling.h): STRETCH fills the window as before; NONE copies texel for texel to the top-left, cropped, nearest filter; ASPECT_RATIO_STRETCH (CoreWindow swapchains) keeps the aspect ratio, centred. What the copy doesn't cover is cleared to opaque black. - CreateSwapChainForHwnd refuses ASPECT_RATIO_STRETCH and bad values; CreateSwapChainForCoreWindow still takes ASPECT_RATIO_STRETCH. present_scaling_test: the rectangles for each mode (CPU only). dxgi_swapchain_test: the refused values, and a NONE swapchain smaller than its window keeps NONE and presents (clean under validation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 7464bef on Windows 11, MSVC BuildTools 2022 (Ninja, RelWithDebInfo, -j 4), PR head on top of main aa2988c: fail, does not build. The new What did run: AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Build failure at 7464bef2 on Windows 11, MSVC /W4, LEONIDA_BUILD_WINDOWS_RUNTIME=ON:
present_scaling.h(20): error C2011: 'leonida::PresentRect': 'struct' type redefinition
vulkan_present.h(50): note: see declaration of 'leonida::PresentRect'
d3d12_vulkan_device.cpp(7391): error C2664: 'VulkanPresenter::present(..., const leonida::PresentRect *, ...)'
runtime/src/present_scaling.h adds struct PresentRect { src_width, src_height, dst_x, dst_y, dst_width, dst_height, scaled, covers }, but runtime/src/vulkan_present.h already declares struct PresentRect { left, top, right, bottom } in the same leonida namespace, and d3d12_vulkan_device.cpp includes both (transitively). The standalone present_scaling_test compiles, but the runtime target that includes the presenter does not, so the windows build cannot link this branch.
Suggested fix: rename the new struct (e.g. ScalingRect/PresentBlitRect) and its uses in present_scaling.h/present_scaling_test.cpp, or reuse the existing PresentRect with an explicit conversion at the call site. Nothing else in the diff looked wrong; I could not run the swapchain/scaling tests until this compiles.
Claim: #4084 (D3D-444, found by @jeremygold02)
Problem
An HWND swapchain created with
DXGI_SCALING_NONEreportedDXGI_SCALING_STRETCHfromGetDesc1(dxgi_com.cpphard-coded it), and Present stretched its back buffer to the window (dxgi_swapchain.hblitted to the full surface extent). A title asking for unscaled output got a stretched image.Measured on host DXGI for a flip-model HWND swapchain (Windows 11, RTX 5060 Ti, driver 621.14), creating each
DXGI_SCALINGand readingGetDesc1back:ScalingCreateSwapChainForHwndGetDesc1().ScalingmainSTRETCH(0)NONE(1)ASPECT_RATIO_STRETCH(2)Change
GetDesc1reports theScalingthe swapchain was created with.runtime/src/present_scaling.h(present_rect, pure arithmetic) gives Present's copy from the back buffer to the window's image: STRETCH fills the window (as before, linear filter); NONE copies texel for texel to the top-left corner, cropped where the back buffer is larger, nearest filter; ASPECT_RATIO_STRETCH (reachable only fromCreateSwapChainForCoreWindow) scales to the largest aspect-keeping size, centred. Whatever the copy doesn't cover is cleared to opaque black first (vkCmdClearColorImage, then a transfer→transfer barrier), so it's never the undefined contents of a freshly acquired image.CreateSwapChainForHwndrefusesASPECT_RATIO_STRETCHand values past it withDXGI_ERROR_INVALID_CALL, as the host does;CreateSwapChainForCoreWindow(which shared the HWND path) still acceptsASPECT_RATIO_STRETCH.Tests
present_scaling_test(ctestpresent_scaling, CPU only): the rectangles for each mode, smaller/larger/same-size back buffers, letterboxing, rounding, an empty source and sizes near 2^16 (64-bit products). 14 cases, OK.dxgi_swapchain_test:ASPECT_RATIO_STRETCH, 3 and 4 areDXGI_ERROR_INVALID_CALLon an HWND swapchain; a 64x48NONEswapchain in a 128x128 window keepsNONEinGetDesc1and presents (the clear-then-unscaled-copy path). Onmainit fails at the first check (the layer creates anASPECT_RATIO_STRETCHHWND swapchain). With the change: PASS, also withLEONIDA_VK_VALIDATION=1(0VUIDmessages).cmake --build+ctest -C RelWithDebInfo -j6: 137/137 passed, 8 skipped/disabled for missing game files, Bink or SDL, as onmain.tests/test_ctest_registration.py: OK.Limitations
present_rect's unit test and the Vulkan commands by the validation run.IDXGIFactory::CreateSwapChainstill maps toSTRETCH, as before.AI-assisted (Claude Code). Tested on Windows 11 with an RTX 5060 Ti, driver 621.14.