Skip to content

DXGI: support dirty rectangles and scrolling in Present1 - #4826

Open
gabrielsteglich wants to merge 1 commit into
ItsNotRexed:mainfrom
gabrielsteglich:feat/dxgi-present1-dirty-scroll
Open

gabrielsteglich wants to merge 1 commit into
ItsNotRexed:mainfrom
gabrielsteglich:feat/dxgi-present1-dirty-scroll

Conversation

@gabrielsteglich

@gabrielsteglich gabrielsteglich commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue #4683.

Depends on: #4231, #4610 for merge-order conflicts. The change builds directly on main (98fa503f).

What and why

Implement incremental Present1 for HWND FLIP_SEQUENTIAL swapchains. Start from the last accepted frame, copy the scrolled region, then overlay the app’s dirty pixels. Write the result back into the logical backbuffer so the app sees the composed pixels when that slot comes around again. Use the DIRECT queue supplied by the app.

A resize resets the frame history. Stage the new sequential ring and history before retiring the old swapchain so an allocation failure leaves the previous frame and buffers usable. The scope is composition on one DIRECT queue per swapchain. Sequential ResizeBuffers1 requires the same queue for each buffer, and presentation still blits the composed frame to WSI.

Tested

Head 63c9f4ca against main at 98fa503f. Windows 11 Pro 26300, Visual Studio 2022 Build Tools (MSVC 19.44.35229, Windows SDK 10.0.26100.0), Vulkan SDK 1.4.363.0, RTX 3090 on 621.01, x64 RelWithDebInfo with core and synchronization validation enabled.

  • dxgi_swapchain passed with two DIRECT queues and no host wait between rendering and the partial present. It read the composed pixels from the reacquired slot. dxgi_swapchain_count, d3d12_present, and xbox_present also passed.
  • The CPU swapchain fixture exercises scroll and dirty overlap, preservation of the last accepted frame after a failed present, allocation failure before WSI replacement, and retry after native creation or acquisition fails.
  • Native Windows D3D12 and the Vulkan shim matched 15 screen samples and five exact readback pixels from a reacquired backbuffer. The probe covered scroll in both directions, scroll without dirty rectangles, overlapping dirty updates, resize, and DXGI_PRESENT_TEST. Vulkan validation reported zero errors.
  • Full runtime CTest passed with 157 passes, 8 skips, and 1 disabled test.

AI-assisted (Codex). No game data, keys, or decryption.

@Atomic258

Copy link
Copy Markdown

Tested 63c9f4cae4b9e3ebf049575db7b08310b1377a5b on native Windows 11, NVIDIA GeForce RTX 5090 (617.42), Vulkan SDK 1.4.363.0, MSVC 14.44/Ninja.

  • Built via cmd /c C:\Users\Nick\build-verify-4826.bat (vcvars64, SDK/PATH setup, then cmake --build runtime\build --target dxgi_swapchain_test dxgi_swapchain_count_test).
  • ctest --test-dir runtime/build -R '^dxgi_swapchain(_count)?$' -V --timeout 90: 2/2 passed both normally (1.24 s) and with LEONIDA_VK_VALIDATION=1 (0.97 s). The GPU test confirmed validation was on and reported 0 validation errors, passed Present1 dirty/scroll and ResizeBuffers, and matched all 45 CreateSwapChainForHwnd descriptions against the host runtime. The count test passed buffer counts, scroll, dirty overlap, failed present, and resize rollback.
  • Red control: git restore --source=HEAD^ -- runtime/shims/dxgi_com.cpp, leaving the PR tests intact. Rebuilt and ran ctest --test-dir runtime/build -R '^dxgi_swapchain$' -V --timeout 90 with validation enabled: failed with FAIL: FLIP_DISCARD rejects Present1 dirty rectangles (CTest exit 8). Restored the head file, rebuilt, and reran both tests with validation: 2/2 passed. git status --porcelain was empty.

AI-assisted (Devin); no game files.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 63c9f4ca on Windows 11 with the NVIDIA GeForce RTX 4090 (32.0.16.2101) and AMD Radeon(TM) Graphics (32.0.21043.5001): pass.

I built dxgi_swapchain_test and dxgi_swapchain_count_test with MSVC in RelWithDebInfo. I ran ctest --test-dir build -C RelWithDebInfo -R "^dxgi_swapchain(_count)?$" -V once per adapter. Both tests passed in each run. The Vulkan test identified the selected adapter. It checked readback from the reacquired buffer after a partial present.

I checked the scroll helper against a pixel-by-pixel reference for a 4×3 frame. All 5,940 combinations of a nonempty destination rectangle and offsets from −5 to 5 horizontally and −4 to 4 vertically matched. This includes rectangles with no available source pixels.

For the negative control, I linked the PR's GPU test against the runtime from merge base 98fa503f. Both runs exited 1 at the first changed FLIP_DISCARD dirty-rectangle check. Vulkan validation layers were unavailable. This run covers the two focused tests.

AI-assisted.

@XFlawless1

Copy link
Copy Markdown
Contributor

Tested 63c9f4ca merged with main de671352 (clean merge) on Windows 11 Pro 26300, MSVC 19.44, Vulkan SDK 1.4.363.0, RelWithDebInfo via scripts/build_runtime.ps1, LEONIDA_VK_VALIDATION=1: pass on both GPUs.

RTX 5080, driver 621.14 Radeon iGPU of the Ryzen 7 9800X3D (RDNA2), driver 32.0.21042.62
dxgi_swapchain, dxgi_swapchain_count, d3d12_present, xbox_present pass pass
full ctest 167/167 166/167 (see below)

No validation messages in either run.

The one Radeon failure, d3d12_sparse_queue_family_contract, isn't from this PR. Plain main de671352 fails it the same way, 3 of 3 runs. The test binary crashes (0xC0000005) in vkDestroyDevice, and only when the API dump layer and Khronos validation are both loaded, as the checker loads them. Either layer alone passes. I'm reporting it separately in the coordination issue.

Native Present1, compared. I wrote a small native D3D12/DXGI probe to check the PR's argument rules against the OS. It used a 64x64 window and two buffers, presented once with empty parameters first, then made each call. Results were the same on the RTX 5080 and WARP:

call FLIP_SEQUENTIAL FLIP_DISCARD
empty DXGI_PRESENT_PARAMETERS S_OK S_OK
one dirty rect S_OK DXGI_ERROR_INVALID_CALL
dirty rect + scroll rect/offset S_OK DXGI_ERROR_INVALID_CALL
dirty rect with DXGI_PRESENT_TEST DXGI_ERROR_INVALID_CALL DXGI_ERROR_INVALID_CALL
pPresentParameters = nullptr access violation inside DXGI (not reached)

This matches the PR. Dirty or scroll regions are refused on non-sequential swapchains and with DXGI_PRESENT_TEST. Where native crashes on null parameters, the PR returns DXGI_ERROR_INVALID_CALL, so no app can rely on the native behavior. Before this PR, Present1 ignored the regions and presented on FLIP_DISCARD, so this is a deliberate change, but it is the one native makes.

I also read the scroll crop in present_regions.h against the DXGI_PRESENT_PARAMETERS definition (the scroll rect is the destination, and the source is the destination minus the offset). It crops both to the old frame consistently.

AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

ACCEPT. Built /W4 with MSVC 19.51; dxgi_swapchain, dxgi_swapchain_count, d3d12_present and xbox_present pass on an RTX 5070 with zero validation errors. A native D3D11 DXGI probe confirms every rejection rule: FLIP_DISCARD with dirty/scroll is DXGI_ERROR_INVALID_CALL; a partial FLIP_SEQUENTIAL frame before the first full one is invalid; a scroll offset beyond the rect is invalid; and PRESENT_TEST with hints is invalid. Composition is verified by the literal-pixel dxgi_swapchain_count_test expectations. Merge clean vs b87e5c41, and the stated dependencies are already merged.

Minor, bandwidth only: runtime/shims/dxgi_swapchain.h:458 copies the full frame every present and writes it back at :544, plus two extra full-size images per sequential chain.

Approve. AI-assisted review, no game files.

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