Skip to content

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

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

gabrielsteglich wants to merge 2 commits 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
Contributor

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.

@memorypressure

Copy link
Copy Markdown

Reviewed at merge with current main 3faac55 (clean merge): no game data or embedded blobs in the diff; the new present_regions cropping math reads correctly (64-bit intermediates, bounds-checked before narrowing, present_rect_fits guards). The dxgi_swapchain and count tests need a cmake plus Windows/GPU build, which this verification environment deliberately does not run — CI windows/linux-gpu jobs are the authority for that half. Nothing on main touched these eight files since your base, so no supersession. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only review).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 63c9f4c on Intel UHD 770 (driver 32.0.101.7088), Windows 11 (10.0.26300), MSVC 19.44, Vulkan SDK 1.4.357.0: partial, the Present1 dirty-rectangle and scroll cases did not run here.

  • dxgi_swapchain_count_test: exit 0, "buffer counts, scroll, dirty overlap, failed present, resize rollback".
  • xbox_present_test: "all cases pass", exit 0, with many "[rt] d3d12: present failed (VkResult -11)" lines on stderr that I did not trace.
  • dxgi_swapchain_test: exit 1 at the CreateSwapChainForHwnd host comparison (40 of 45 mismatch, host 0x887a0022), before its Present1 cases, so it gives no result for this PR. The session had no interactive window station. d3d12_present_test exits 77 with "SKIP: the process has no interactive window station".

Main was not run here, so I cannot say whether the dxgi_swapchain_test failure is unrelated to the change.

AI-assisted.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested b0ceb822e merged into main 1cc6e3c12 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "dxgi|present" --output-on-failure: 8/8 passed (dxgi_swapchain, dxgi_swapchain_count, dxgi_device, d3d12_present, xbox_present, xbox_present_readback_size, vk_presenter_sync, vk_presenter_capture_colour).

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested b0ceb82 merged with main 8575d36 on Windows 11, MSVC 14.51, Ninja RelWithDebInfo, default GPU selection (LEONIDA_VK_DEVICE not set; the tests do not print the device name, so I am not naming it): pass
Merge via real git merge, clean (auto-merged docs/d3d12_vulkan.md, d3d12_com.cpp/.h, dxgi_swapchain_test.cpp). Built dxgi_swapchain_test, dxgi_swapchain_count_test, d3d12_present_test, xbox_present_test; ctest dxgi_swapchain, dxgi_swapchain_count, d3d12_present, xbox_present: 4/4 passed.
Negative control: reverting runtime/shims/dxgi_swapchain.h, dxgi_com.cpp, d3d12_com.cpp and d3d12_com.h to main makes dxgi_swapchain_count_test fail to compile against the new API (VulkanSwapchain::create with 7 args, present with 2 args, present_scroll_copy, PresentRegions), so the new test cannot pass without the PR's source change. This is a compile failure, not a behavioural failure.
Not run: Linux (needs a GPU runtime build), Intel selection.

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.

9 participants