Skip to content

d3d12_present_test: check the presented images through the capture, GDI screen read only where it works - #1908

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Jolymmiles:mac/d3d12-present-capture-check
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Jolymmiles:mac/d3d12-present-capture-check

Conversation

@Jolymmiles

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: item 3 of #1745 (comment) (d3d12_present on a Mac under Wine)

What and why

d3d12_present failed on a Mac under Wine at line 311: pixel != CLR_INVALID.

The swapchain recreation path is fine. The present failed (VkResult -1000001004) lines (twice) and (-1) in the log are the test's own injections:

  • a failed surface-format query;
  • a failed second semaphore during recreation;
  • fail_next_submit = VK_ERROR_OUT_OF_HOST_MEMORY.

I bracketed each injection with temporary markers, and each line falls inside its own. The test already says "0 real out-of-date presents". MVK_CONFIG_LOG_LEVEL=2 shows MoltenVK creating the swapchains at exactly 320×240 and 400×300 (contents scale 1.0).

What fails is the last step. It reads the colour back from the screen with GDI, and Wine's macOS driver can't do that. A standalone probe shows GetPixel on the screen DC returns CLR_INVALID even for a pixel GDI itself painted, and BitBlt from the screen fails as well. The window DC returns Wine's white GDI surface, not the Metal layer's content.

The change, test and docs only, no runtime change:

  • The test turns on the presenter's capture (enable_capture(), the path xbox_present_test already requires in CI). It checks that the whole presented image holds the clear colour at the swapchain's size three times: after the first 60 frames, after the resize to 400×300, and at the end. So the presented image is checked on every platform.
  • The on-screen GDI check stays where GDI can read the screen. Only when GetPixel returns CLR_INVALID does the test print why and skip that one step; a wrong colour on screen still fails. Note this also applies on Windows, where CLR_INVALID used to fail the test; the capture check covers the colour there now.
  • Before the injections the test says that the next three present failed lines are expected. They have been read as a fault at least twice, including the Intel UHD 770 finding in Coordinating who works on what (6) (moved to #1548) #1380. That finding failed at a different line (the on-screen colour, std::abs(r - 51) …), and this PR doesn't claim to fix it.

Tested

Apple M3 Max, macOS 27.3, Wine 11.0 (CrossOver 26.3's loader) with MoltenVK 1.4.3 (main 5189f8de with SPIRV-Cross 57e4efcc). Windows build cross-compiled on the Mac with clang-cl 23.1.6, lld-link 22.1.8 and the xwin 10.0.26100 SDK (runtime/cmake/clang-cl-xwin.cmake).

  • d3d12_present under Wine: before, FAIL (pixel != CLR_INVALID); after, PASS ("colour confirmed in the presented images"). I re-ran it myself after the delegate's run.
  • Negative control: with the clear colour changed, the test fails at the first capture check (presented image 320x240: 51,153,204 at 0,0).
  • xbox_present_test and vk_presenter_sync_test pass under Wine.
  • Native ctest (runtime/build/mac, MoltenVK): 33/33.
  • Not run on Linux Wine/llvmpipe or native Windows. The capture path is the one xbox_present_test already exercises there in CI.

No game files. AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

…DI screen read only where it works

Under Wine's macOS driver the test failed at its last step, the GDI read of the screen: GetPixel on the screen DC
returns CLR_INVALID there for every pixel, even one GDI painted itself (BitBlt from the screen DC fails too), and
the window's own DC holds Wine's GDI surface (white), not the image presented through the Metal layer. The
presenter itself was fine: all the injected-failure checks passed, MoltenVK made 320x240 and 400x300 swapchains
at contents scale 1.0, and the driver reported no out-of-date presents. The "present failed" lines in that log
(VkResult -1000001004 twice, then -1 = VK_ERROR_OUT_OF_HOST_MEMORY) are the test's own injections; markers around
them showed each line inside its injection.

The test now enables the presenter's capture and checks the whole presented image for the clear colour at the
swapchain's size after the first 60 frames, after the resize and at the end, on every platform. The screen check
stays where GDI can read the screen; a CLR_INVALID there is reported and skipped instead of failing. The test also
says on stderr that the next three "present failed" lines are expected, since they were read as faults twice.
Checked under CrossOver's Wine 11 with MoltenVK 1.4.3 on an Apple M3 Max: the test passes, and with the clear
colour changed the capture check fails at the first 60 frames.

@Serrambi Serrambi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 17a27f23 and tested on NVIDIA GeForce RTX 5070 Ti (driver 610.88, Windows 11 Pro, MSVC 19.50.35719.0, Vulkan SDK 1.4.363.0): approve.

Code review (runtime/test/d3d12_present_test.cpp, docs/d3d12_vulkan.md, runtime/README.md)

  • Enabling presenter->enable_capture() and checking the captured swapchain image after the initial 60 frames, after the 400×300 resize, and after the injected failure cases validates the actual presented pixels even when GetPixel(screen, ...) cannot read the screen (CLR_INVALID / non-foreground window).
  • Announcing the three expected injected [rt] d3d12: present failed lines before running them makes stderr much clearer.
  • Minor non-blocking note: presented_image_is_clear_colour() handles both VK_FORMAT_B8G8R8A8_UNORM and VK_FORMAT_B8G8R8A8_SRGB swizzles while comparing raw bytes against linear 51, 153, 230, which is exact on UNORM swapchains and would encode differently if a surface ever chose an _SRGB format.

Checks on 17a27f23

  • d3d12_present_test.exe (default): passed (EXIT=0, capture colour confirmed; the window is not in front: on-screen colour check skipped)
  • d3d12_present_test.exe (LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 Vulkan validation errors, capture colour confirmed)
  • ctest --test-dir runtime/build --output-on-failure -R "^d3d12_present$": passed 1/1

@opit80

opit80 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested on native Windows + NVIDIA at head 17a27f23, since the PR notes this environment was not run locally.

  • GPU: NVIDIA GeForce RTX 5070 Ti (driver 617.42); Windows 11; MSVC 19.44; Vulkan SDK 1.4.363.0.
  • cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build runtime/build --parallel 4 — clean build, no new warnings in the changed test.
  • ctest --test-dir runtime/build --output-on-failure — 111/113 passed (8 skipped, 1 disabled).
  • LEONIDA_VK_VALIDATION=1 d3d12_present_test.exe — exit 0, 0 VUIDs, 0 validation errors. The new capture checks pass after the first 60 frames, after the resize to 400x300, and after the injected failures; GDI read back screen pixel 51,153,229 (cleared to 51,153,230), so the colour is confirmed both in the presented images and on screen.
  • LEONIDA_VK_VALIDATION=1 ctest — 111/113 passed; the only VUID (VUID-vkDestroyPipeline-pipeline-00765) and the two failing tests (d3d12_compute, d3d12_draw) are pre-existing on the merge base and unrelated to this change.

@JRamos1993

JRamos1993 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 17a27f2, merged onto main 4eb6155 (no conflicts), on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, fresh RelWithDebInfo build:

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 98e9acf 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