Skip to content

dxgi_swapchain_test: check CreateSwapChainForHwnd against Microsoft's recorded answers - #4720

Open
kmorales13 wants to merge 2 commits into
ItsNotRexed:mainfrom
kmorales13:test/dxgi-swapchain-wine-answers
Open

kmorales13 wants to merge 2 commits into
ItsNotRexed:mainfrom
kmorales13:test/dxgi-swapchain-wine-answers

Conversation

@kmorales13

Copy link
Copy Markdown
Contributor

New TEST item (claim, from this finding).

What and why

dxgi_swapchain_test fails on main under Wine and Proton, before any of its own swap-chain checks run. The 45-case CreateSwapChainForHwnd comparison in compare_swap_chain_arguments has only the system DXGI as its reference. Under Wine that DXGI is Wine's, and under Proton it is DXVK's. Both accept 17 descriptions that Microsoft's DXGI refuses, for example scaling ASPECT_RATIO_STRETCH, the alpha modes, several flags and usages, and width or height 16385. Result: 18 mismatches, then FAIL.

Skipping the comparison under Wine would leave those 45 cases unchecked on Linux. So instead, each case now records Microsoft's HRESULT (want):

  • Everywhere: the layer must return the recorded answer.
  • Where the host runtime is Microsoft's: the live comparison stays, and the host must match the recorded answer too, so a wrong value in the table fails on Windows.
  • Under Wine (hostwine::host_is_wine(), as in the other host comparisons): only the recorded answers are checked, and the system d3d12.dll and dxgi.dll aren't loaded.

Where the answers come from

44 of the 45 are measured in #3531, on Windows with hardware adapters:

  • the per-case list in its description (RTX 5070);
  • zzEmmazz's per-bit table, the same on an RTX 3070, a Radeon iGPU and WARP;
  • dev-ewann's multi-fault cases at dac96d2d.

The 45th, usage 0, isn't listed there. The layer returns S_OK for it. #3531's full runs at dac96d2d matched the host on all 45 cases, on an RTX 5070 and an RX 7600 (AMD's driver). Neither later PR that touched dxgi_com.cpp (#3597, #3280) changed the usage check. So that answer is Microsoft's too.

The 16385 answers (E_INVALIDARG) are a hardware adapter's: WARP accepts 16385. A Windows machine whose default adapter is WARP fails this case, as it did before this change (ours vs host).

Tested

CachyOS Linux, Ryzen 7 7700X iGPU (RDNA2, RADV Mesa 26.3.1). Cross-built with clang-cl 23 and the xwin SDK, on main 98fa503f.

  • Wine 11.22: 45 descriptions checked against Microsoft's recorded answers, 0 mismatches, and dxgi_swapchain_test passes, including present, resize and readback, which never ran under Wine before. On main: 18 mismatches, FAIL.
  • Proton Experimental (DXVK dxgi, vkd3d-proton): same, 0 mismatches, PASS.
  • Negative control: with check_hwnd_swap_chain changed to accept DXGI_SCALING_ASPECT_RATIO_STRETCH, the Wine run fails on exactly that case (ours 0x00000000, recorded 0x887a0001).

Not tested: the native MSVC build and a Windows run, which I don't have. A run of dxgi_swapchain on Windows would confirm that the host matches all 45 recorded answers.

Neighbouring PRs, no shared lines: #4605 edits the adapter block of this test; #4362 adds Wine skips to six other tests; #3679 records Microsoft's answers for other tests.

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

… recorded answers

The 45-case CreateSwapChainForHwnd comparison only had the system DXGI as
its reference. Under Wine and Proton that is Wine's or DXVK's DXGI, which
accepts 17 descriptions Microsoft's refuses, so the test failed there with
18 mismatches before any of its own swap-chain checks ran.

Each case now records Microsoft's HRESULT on a hardware adapter, as
measured in ItsNotRexed#3531. The layer is checked against it everywhere. Where the
host runtime is Microsoft's, the live comparison stays, and the host must
match the recorded answer too. Under Wine the system d3d12.dll and dxgi.dll
are no longer loaded.
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 7b551ee on Windows 11 with an NVIDIA GeForce RTX 4090 and an AMD Radeon iGPU. Both runs pass.

I ran cmake --build build --config RelWithDebInfo --target dxgi_swapchain_test. I ran build/RelWithDebInfo/dxgi_swapchain_test.exe with LEONIDA_VK_DEVICE=4090 and then with LEONIDA_VK_DEVICE=Radeon. The device log confirms the selected adapter for each layer run. The native DXGI check uses the Windows default adapter.

All 45 descriptions match the recorded results and the native DXGI results on both runs. For a negative control, I changed the recorded result for usage 0 from S_OK to DXGI_ERROR_INVALID_CALL and rebuilt the test. Each run reports exactly one mismatch and exits with code 1. The layer and native DXGI both return 0x00000000 for that case.

NVIDIA driver 32.0.16.2101. AMD driver 32.0.21043.5001. Scope: the Windows swap-chain test.

AI-assisted.

@Kam471 Kam471 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.

Built and ran dxgi_swapchain_test at 7b551eeab on Windows 11, RTX 5070 Ti: PASS, CreateSwapChainForHwnd: 45 descriptions checked against Microsoft's recorded answers and the host runtime, 0 mismatches, 0 validation errors, exit 0; git diff --check clean.

The test now carries Microsoft's recorded answers as a second reference beside the live host runtime, so a host whose DXGI version changes a description no longer silently redefines the expectation, and a layer that matches neither is caught. No blocking issue.

@Atomic258

Copy link
Copy Markdown

Tested 7b551eea on Windows 11, MSVC 2022 BuildTools + Ninja, NVIDIA GeForce RTX 5090 (driver 617.42): pass.

  • dxgi_swapchain_test: CreateSwapChainForHwnd: 45 descriptions checked against Microsoft's recorded answers and the host runtime, 0 mismatches; full suite PASS with 0 validation errors. The recorded-answers path and the live host comparison agree on the Windows host � the Wine-side use of the same table is the part we cannot exercise here.

No game files. AI-assisted (Devin).

@ruvenesh

Copy link
Copy Markdown

Tested 7b551ee (merged onto main 98fa503, clean merge, one file) on RTX 3060, driver 580.178.04, Ubuntu 24.04, runtime cross-built with clang-cl 23.1.6 + xwin and run under Wine 9.0. AI-assisted (Claude Code); no game files.

The 45 recorded answers work: CreateSwapChainForHwnd: 45 descriptions checked against Microsoft's recorded answers, 0 mismatches, and the host comparison is skipped under Wine. On main the same run fails with 18 mismatches.

The test still fails under Wine, one step later: FAIL: ResizeBuffers(0, 0, 0) (the zero-size resize that takes the window's client area). I printed the results in a local copy: ResizeBuffers returns E_FAIL for a valid 300x200 client area. The swapchain is created fine at 300x200 (vkCreateSwapchainKHR = VK_SUCCESS), then vkAcquireNextImageKHR returns VK_ERROR_OUT_OF_DATE_KHR, and it stays that way through 4 s of retries, so it is not a late window resize.

Cause: the test window is never shown. create_test_window calls CreateWindowExW with WS_OVERLAPPEDWINDOW and no WS_VISIBLE or ShowWindow. A hidden window still has a real size on Windows. Under Wine/X11 it has no mapped X window to follow SetWindowPos, so the driver reports the new swapchain out of date at once.

Fix, three lines in create_test_window:

HWND w_ = CreateWindowExW(...);   // as now
if (w_) ShowWindow(w_, SW_SHOWNOACTIVATE);
return w_;

With that on top of this PR the whole test passes: 3 of 3 runs, dxgi_swapchain_test: PASS (CreateSwapChain, CreateSwapChainForHwnd, CreateSwapChainForCoreWindow, occlusion status, GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers; 0 validation errors).

@kmorales13, this fits in your PR if you want it, so Wine and Proton get a green test instead of the next failure.

Not covered: no native Windows run of the ShowWindow change. I expect it to be harmless, since the occlusion-status check passed under Wine, but a shown window can change what an occlusion test sees on a real desktop, and it flashes on screen briefly. No validation layer on this box.

Under Wine 9.0 on X11 (RTX 3060), ResizeBuffers(0, 0, 0) on the hidden
test window kept returning E_FAIL: vkAcquireNextImageKHR reported the new
swapchain out of date, because a never-mapped X window doesn't follow
SetWindowPos. Showing the window without activating it, as
d3d12_present_test and vk_presenter_sync_test already do, fixes that. Only
the main window is shown; the 45 comparison windows stay hidden.
@kmorales13

kmorales13 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@ruvenesh Added in 16d16dc, but only for the main test window, which is the one ResizeBuffers(0, 0, 0) resizes. The 45 comparison windows stay hidden, so they don't flash on Windows. The layer's DXGI_STATUS_OCCLUDED fallback doesn't depend on visibility and uses its own window.

I couldn't reproduce the failure here: Wine 11.22 with its X11 driver (on XWayland) and RADV passes ResizeBuffers with the hidden window. With the change it still passes under Wine 11.22 and Proton Experimental. A rerun on your Wine 9.0 box would confirm it fixes your case.

@Ty0x7

Ty0x7 commented Nov 23, 2026

Copy link
Copy Markdown

Independently tested dxgi_swapchain_test on Omarchy Linux with an NVIDIA RTX 3060 Ti, driver 615.78.08, and Wine 11.20 through XWayland. I cross-built the Windows tests with clang-cl 23.1.3 and xwin, then ran them with the same isolated Wine prefix on a real desktop display using ctest -R '^dxgi_swapchain$' -V.

Revision CreateSwapChainForHwnd argument checks ResizeBuffers Overall
Baseline 98fa503f8a19c3ed65df1f4f2f0e4571aa42c4f7 45 compared against Wine’s DXGI, 18 mismatches Not reached FAIL
Reviewed PR commit 7b551eeab2ba109249f506c052b85ee3d3b811d3 45 checked against recorded Microsoft results, 0 mismatches PASS, including ResizeBuffers(0, 0, 0) PASS
Updated PR head 16d16dc6cd5424363c49edf86554c555f8f84be7 45 checked against recorded Microsoft results, 0 mismatches PASS, including ResizeBuffers(0, 0, 0) PASS

The resize failure previously reported on an RTX 3060 under Wine 9.0 did not reproduce on this setup. I rebuilt and reran 16d16dc6 after the ShowWindow change and still got a full pass. Vulkan validation was off. Proton was outside this run. No game files used. AI-assisted with Codex.

CTest logs are included below with local workspace paths shortened.

CTest log — Baseline 98fa503
UpdateCTestConfiguration  from :<verification-root>/build/baseline/DartConfiguration.tcl
Parse Config file:<verification-root>/build/baseline/DartConfiguration.tcl
Test project <verification-root>/build/baseline
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 137
    Start 137: dxgi_swapchain

137: Test command: /usr/bin/wine "<verification-root>/build/baseline/dxgi_swapchain_test.exe"
137: Working Directory: <verification-root>/build/baseline
137: Test timeout computed to be: 120
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: pci id for fd 35: 10de:2489, driver (null)
137: pci id for fd 36: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: pci id for fd 35: 10de:2489, driver (null)
137: pci id for fd 36: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: [rt] d3d12: upload heaps in system memory (no Resizable BAR)
137: MESA-EGL: warning: pci id for fd 51: 10de:2489, driver (null)
137: pci id for fd 52: 10de:2489, driver (null)
137: pci id for fd 53: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 51: 10de:2489, driver (null)
137: pci id for fd 52: 10de:2489, driver (null)
137: pci id for fd 53: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 51: 10de:2489, driver (null)
137: CreateSwapChainForHwnd scaling ASPECT_RATIO_STRETCH: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd scaling 7: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd alpha PREMULTIPLIED: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd alpha STRAIGHT: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd alpha 9: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd flag NONPREROTATED: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd flag GDI_COMPATIBLE: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd flag FOREGROUND_LAYER: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd flag HW_PROTECTED: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd flag 0x4000: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd flag 0x80000000: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd usage SHARED: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd usage READ_ONLY: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd usage DISCARD_ON_PRESENT: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd usage UNORDERED_ACCESS: ours 0x887a0001, host 0x00000000
137: CreateSwapChainForHwnd width 16385: ours 0x80070057, host 0x00000000
137: CreateSwapChainForHwnd height 16385: ours 0x80070057, host 0x00000000
137: [rt] d3d12: QueryInterface: unknown IID {0ec870a6-5d7e-4c22-8cfc-5baae07616ed}
137: CreateSwapChainForHwnd a device, not a queue: ours 0x887a0001, host 0x887a0004
137: FAIL: CreateSwapChainForHwnd answers differ from the host runtime
137: CreateSwapChainForHwnd: 45 descriptions compared with the host runtime, 18 mismatches
1/1 Test #137: dxgi_swapchain ...................***Failed    7.07 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   7.07 sec

The following tests FAILED:
	137 - dxgi_swapchain (Failed)
Errors while running CTest
Output from these tests are in: <verification-root>/build/baseline/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
CTest log — Reviewed PR commit 7b551ee
UpdateCTestConfiguration  from :<verification-root>/build/pr-head/DartConfiguration.tcl
Parse Config file:<verification-root>/build/pr-head/DartConfiguration.tcl
Test project <verification-root>/build/pr-head
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 137
    Start 137: dxgi_swapchain

137: Test command: /usr/bin/wine "<verification-root>/build/pr-head/dxgi_swapchain_test.exe"
137: Working Directory: <verification-root>/build/pr-head
137: Test timeout computed to be: 120
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: pci id for fd 35: 10de:2489, driver (null)
137: pci id for fd 36: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: pci id for fd 35: 10de:2489, driver (null)
137: pci id for fd 36: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: [rt] d3d12: upload heaps in system memory (no Resizable BAR)
137: [rt] d3d12: QueryInterface: unknown IID {0ec870a6-5d7e-4c22-8cfc-5baae07616ed}
137: [rt] d3d12: QueryInterface: unknown IID {0ec870a6-5d7e-4c22-8cfc-5baae07616ed}
137: [rt] d3d12: QueryInterface: unknown IID {45d64a29-a63e-4cb6-b498-5781d298cb4f}
137: host D3D12 is Wine's, not Microsoft's: comparisons with the host are skipped
137: CreateSwapChainForHwnd: 45 descriptions checked against Microsoft's recorded answers, 0 mismatches
137: device: NVIDIA GeForce RTX 3060 Ti (GA104, Low Hash Rate) (validation off)
137: dxgi_swapchain_test: PASS (CreateSwapChain, CreateSwapChainForHwnd, CreateSwapChainForCoreWindow, occlusion status, GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers; 0 validation errors)
1/1 Test #137: dxgi_swapchain ...................   Passed    5.38 sec

The following tests passed:
	dxgi_swapchain

100% tests passed out of 1

Total Test time (real) =   5.39 sec
CTest log — Updated PR head 16d16dc
UpdateCTestConfiguration  from :<verification-root>/build/pr-current/DartConfiguration.tcl
Parse Config file:<verification-root>/build/pr-current/DartConfiguration.tcl
Test project <verification-root>/build/pr-current
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 137
    Start 137: dxgi_swapchain

137: Test command: /usr/bin/wine "<verification-root>/build/pr-current/dxgi_swapchain_test.exe"
137: Working Directory: <verification-root>/build/pr-current
137: Test timeout computed to be: 120
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: pci id for fd 35: 10de:2489, driver (null)
137: pci id for fd 36: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: pci id for fd 35: 10de:2489, driver (null)
137: pci id for fd 36: 10de:2489, driver (null)
137: MESA-EGL: warning: egl: failed to create dri2 screen
137: MESA-EGL: warning: pci id for fd 34: 10de:2489, driver (null)
137: [rt] d3d12: upload heaps in system memory (no Resizable BAR)
137: [rt] d3d12: QueryInterface: unknown IID {0ec870a6-5d7e-4c22-8cfc-5baae07616ed}
137: [rt] d3d12: QueryInterface: unknown IID {0ec870a6-5d7e-4c22-8cfc-5baae07616ed}
137: [rt] d3d12: QueryInterface: unknown IID {45d64a29-a63e-4cb6-b498-5781d298cb4f}
137: host D3D12 is Wine's, not Microsoft's: comparisons with the host are skipped
137: CreateSwapChainForHwnd: 45 descriptions checked against Microsoft's recorded answers, 0 mismatches
137: device: NVIDIA GeForce RTX 3060 Ti (GA104, Low Hash Rate) (validation off)
137: dxgi_swapchain_test: PASS (CreateSwapChain, CreateSwapChainForHwnd, CreateSwapChainForCoreWindow, occlusion status, GetBuffer+GetDesc, clear+readback, Present, ResizeBuffers; 0 validation errors)
1/1 Test #137: dxgi_swapchain ...................   Passed    5.47 sec

The following tests passed:
	dxgi_swapchain

100% tests passed out of 1

Total Test time (real) =   5.47 sec

@pwu2775-dev

Copy link
Copy Markdown
Contributor

Tested 7b551ee on Windows 11 (26300), MSVC 19.44 (VS 2022), scripts/build_runtime.ps1 (Ninja), RelWithDebInfo, NVIDIA GeForce RTX 4070 (driver 617.42, a hardware adapter): pass. This is the native Windows run the description lists as not done: CreateSwapChainForHwnd: 45 descriptions checked against Microsoft's recorded answers and the host runtime, 0 mismatches, so Microsoft's DXGI matches all 45 recorded answers here, including the two 16385 cases (E_INVALIDARG on a hardware adapter). ctest 173/173 (GameInput disabled, no SDL3).

I also read the host fallback: when the system DXGI/D3D12 can't be set up on Windows, have_host is false, only the second call per case is skipped, and the summary line then leaves out "and the host runtime", so the reduced check is visible in the output.

AI-assisted: read together with Codex (gpt-6.1-terra); I checked the fallback and summary against the code.

@memorypressure

Copy link
Copy Markdown

Reviewed on Linux; the C++ side is not buildable in this environment (no cmake/Windows run). The change reads sound: results are seeded to the recorded HRESULT, the host-side comparison runs only when a host device exists, and the previous null-Release path on hosts without D3D12 is gone. host_wine.h resolves in-dir and the ctest target is pre-existing. The recorded-answer table and Wine behaviour need the Windows CI leg (queued at review time) to confirm. The diff also carries the round-43 stacked base. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@tupacfan04

Copy link
Copy Markdown
Contributor

READY TO MERGE. Built the head (CMake/Ninja, MSVC 14.51) at /W4: clean. dxgi_swapchain_test 45/45 against both the recorded table and live Microsoft DXGI on an RTX 5070, and the existing dxgi_swapchain_count_test passes too. Negative control: flipping one want (effect DISCARD -> ok) fails with 1 mismatch and exit 1, so the table is really consulted. Merge clean vs origin/main.

One minor gap: runtime/test/dxgi_swapchain_test.cpp:176-185 sets have_host false if host D3D12 device creation fails, and the test then passes on table-only checks, silently dropping the live comparison the body promises for Windows (the printf at :312 drops the wording but prints no reason). Print why the host check was skipped.

Approve. AI-assisted review, no game files, no game data.

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