Skip to content

dxgi: implement Adapter::EnumOutputs and IDXGIOutput6 (D3D-313) - #2976

Open
nightsale wants to merge 1 commit into
ItsNotRexed:mainfrom
nightsale:feat/dxgi-outputs
Open

nightsale wants to merge 1 commit into
ItsNotRexed:mainfrom
nightsale:feat/dxgi-outputs

Conversation

@nightsale

Copy link
Copy Markdown
Contributor

Implements D3D-313 (IDXGIAdapter::EnumOutputs, IDXGIOutput..IDXGIOutput6, and IDXGISwapChain::GetContainingOutput).

Claim: #2516 (comment) (tracked as D3D-313 in #313).
Base: main (77444fa0), no dependencies on open PRs.

Summary of changes

  • runtime/shims/dxgi_com.h: switch from <dxgi1_5.h> to <dxgi1_6.h> for IDXGIOutput6 and DXGI_OUTPUT_DESC1.
  • runtime/shims/dxgi_com.cpp:
    • Enumerate Win32 displays via EnumDisplayMonitors, GetMonitorInfoW, and EnumDisplaySettingsW, placing the primary monitor at index 0 and keeping a 1920x1080@60 headless fallback.
    • Collect, deduplicate, and sort supported scanout display modes (up to a bounded driver enumeration limit) and dynamically load dwmapi.dll (DwmFlush) with a Sleep(16) fallback for WaitForVBlank.
    • Implement Output final : public IDXGIOutput6 (IUnknown, IDXGIObject including GetParent, GetDesc/GetDesc1, GetDisplayModeList/GetDisplayModeList1, FindClosestMatchingMode/FindClosestMatchingMode1, WaitForVBlank, GetFrameStatistics, TakeOwnership/ReleaseOwnership, overlay/hardware-composition queries, DuplicateOutput/DuplicateOutput1), matching measured host dxgi.dll edge cases (including DXGI_ERROR_MORE_DATA preserving copied count).
    • Wire Adapter::EnumOutputs (E_INVALIDARG on null output, DXGI_ERROR_NOT_FOUND out of range) and SwapChain::GetContainingOutput (MonitorFromWindow(..., MONITOR_DEFAULTTONEAREST) match with output 0 fallback).
  • runtime/test/dxgi_swapchain_test.cpp:
    • Add synthetic unit checks for EnumOutputs, Output::GetParent, GetDesc/GetDesc1, GetDisplayModeList/1 (two-pass, DXGI_ERROR_MORE_DATA, unsupported formats), FindClosestMatchingMode/1, WaitForVBlank, GetFrameStatistics, CheckHardwareCompositionSupport, CheckOverlaySupport, SupportsOverlays, DuplicateOutput, SwapChain::GetContainingOutput, and host dxgi.dll comparison (Optimus/multi-GPU safe).

Verification

  • AI-assisted: yes (AI-assisted).
  • Environment: Windows + MSVC + Ninja (RelWithDebInfo), NVIDIA GeForce RTX 3060, driver 621.24, LEONIDA_VK_VALIDATION=1 (no game data, synthetic tests only).
  • Build (.\scripts\build_runtime.ps1): exit 0 (0 warnings in dxgi_com.cpp / dxgi_swapchain_test.cpp).
  • Direct test (.\runtime\build\dxgi_swapchain_test.exe): exit 0, PASS (0 Vulkan validation errors).
  • Full CTest (ctest --test-dir runtime\build --output-on-failure -j4): 100% tests passed, 0 tests failed out of 121 (114 passed including dxgi_swapchain, d3d12_present, xbox_present; 7 skipped: shader_library_corpus, bink_decode, fsr_dispatch, bvh_builder, bink_audio, d3d12_rgb9e5_rtv, d3d12_first_light; 1 disabled: gameinput).
  • Python & translator semantic checks:
    • python -m compileall -q make_game.py tools tests -> exit 0
    • python -I make_game.py --help -> exit 0
    • python -I tests/test_docs_links.py -> 5 tests OK
    • python -I tests/test_ctest_registration.py -> 4 tests OK
    • python -m unittest discover -s tests/semantic -> 4137 tests OK

@Ryderadzeee

Copy link
Copy Markdown
Contributor

Independent Windows verification (AI-assisted) of f59c09d3 integrated with main at 16282101. Release x64 on Windows 11 build 26300 with an RX 9070 XT (32.0.32029.2010) and Ryzen integrated Radeon Graphics (32.0.21045.29003). The only monitor was connected to the RX 9070 XT.

Both dxgi_swapchain and d3d12_present passed on each GPU, selected separately with LEONIDA_VK_DEVICE. Vulkan validation was off. The foreground-window color check skipped on both runs.

A native DXGI/D3D12 probe and temporary logging in the shim test measured these results using synthetic HWND swap chains:

Adapter and API Native DXGI This PR
RX 9070 XT, EnumOutputs 1 output 1 output
RX 9070 XT, GetContainingOutput S_OK, nearest monitor S_OK, same monitor
RX 9070 XT, IDXGIOutput6::GetDesc1 10 bits per color 8 bits per color
Integrated Radeon, EnumOutputs 0 outputs 1 output, the RX 9070 XT's monitor
Integrated Radeon, GetContainingOutput DXGI_ERROR_UNSUPPORTED S_OK, the RX 9070 XT's monitor

On the RX 9070 XT, the output name, desktop bounds, rotation, and color space matched. The shim's host comparison checks the first output only when the corresponding native adapter exposes one, so it misses the integrated Radeon case. Adding a zero-output case for an adapter without an attached monitor would cover this topology, including the GetContainingOutput result.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested f59c09d on Windows 11, RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1): ctest -R "dxgi_swapchain|d3d12_present|xbox_present" (MSVC, RelWithDebInfo, LEONIDA_VK_DEVICE set per run, device line confirmed, validation off) — pass on both, 3/3 each.

  • RTX 5080: dxgi_swapchain, d3d12_present, xbox_present all passed.
  • AMD Radeon (gfx1036): all three passed.
    Not run: the full ctest suite and the Python checks listed in the PR.

AI-assisted.

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested f59c09d (merged onto main 1628210) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0, three monitors on the one card: pass

I also compared the shim with host DXGI output by output, using a local copy of dxgi_swapchain_test with an extra block (not committed):

  • EnumOutputs: same order, device names and desktop coordinates on all three outputs (primary DISPLAY2 at 0, DISPLAY1 at -1920, DISPLAY3 at 2560). NOT_FOUND at index 3 from both.

  • GetDisplayModeList counts, the same for R8G8B8A8, B8G8R8A8, R10G10B10A2 and R16G16B16A16_FLOAT:

    output shim host host with DXGI_ENUM_MODES_SCALING
    0 (2560x1080) 42 82 122
    1 (1920x1080) 160 312 464
    2 (1920x1080) 100 195 290

    The gap is the scaling copies. Host DXGI lists every non-native resolution twice, once with DXGI_MODE_SCALING_UNSPECIFIED and once with CENTERED; the native one appears once. With DXGI_ENUM_MODES_SCALING it adds a STRETCHED copy as well. The shim lists each mode once, with UNSPECIFIED, and its count doesn't change with the flag.

  • Refresh rates differ. The host gives the exact rational value, the shim gives dmDisplayFrequency as N/1. FindClosestMatchingMode for 1280x720 R8G8B8A8:

    output shim host
    0 75/1 74991/1000
    1 144/1 144001/1000
    2 59/1 60000/1001

    On output 2 the 59.94 Hz mode comes out as 59/1 because dmDisplayFrequency truncates. A title that compares rates exactly, or requests 60, may not find the mode it expects. The host's closest match also has Scaling 2 (STRETCHED) where the shim has 0.

  • None of this fails a test, so it's not a blocker. It may be worth a follow-up, e.g. QueryDisplayConfig for the exact rational rates, and listing the CENTERED/STRETCHED copies.

AI-assisted (Claude).

@steamaze0

Copy link
Copy Markdown

Tested f59c09d on NVIDIA RTX 5060 Ti (Blackwell), NVIDIA 621.01 (Vulkan 1.4.357), Windows 11, VS Build Tools 2022 (MSVC) + Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0: pass.

  • dxgi_swapchain: PASS (Adapter::EnumOutputs / IDXGIOutput6), with LEONIDA_VK_VALIDATION=1.
  • ctest --output-on-failure -j4 (validation on): 121 passed, 0 failed (game-data/optional skipped) — same as main, no regression.

AI-assisted (Qoder): I built the full runtime with MSVC and ran ctest.

@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independently tested f59c09d3 on a hybrid Windows 11 (26200) laptop, MSVC 19.44 x64 Release. Selected each Vulkan device with LEONIDA_VK_DEVICE and confirmed it in all three logs. dxgi_swapchain, d3d12_present and xbox_present passed 3/3 on Radeon 780M (26.11.2) and 3/3 on RTX 5060 Laptop (621.01), with Khronos validation on and no VUIDs. The DXGI fixture exercises output enumeration, IDXGIOutput6 descriptors/modes and GetContainingOutput. The foreground on-screen color check skipped on both adapters. Synthetic inputs only. AI-assisted testing and reporting.

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested f59c09d3, applied alone on main 16282101: the tests pass; three differences from the host's DXGI that the test does not look at.
Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE. Both monitors (3440x1440 and 1920x1080) are connected to the RTX 3070.

  • The test change alone does not build on main ('IDXGIOutput6': undeclared identifier: the switch to <dxgi1_6.h> is in the shim header), so there is no failing run of the test without the shim change.
  • Whole change: 0 errors, 0 warnings. dxgi_swapchain_test, d3d12_present_test and xbox_present_test exit 0 on both GPUs.
  • Host values from a small native DXGI program on this machine, the layer's from two temporary printf lines in the test:
native DXGI this change
RTX 3070, EnumOutputs 2 outputs 2 outputs
Radeon iGPU, EnumOutputs 0 outputs 2 outputs (the RTX 3070's monitors)
Radeon iGPU, GetContainingOutput not measured S_OK
output 0, GetDisplayModeList count for B8G8R8A8 / R10G10B10A2 / R16G16B16A16_FLOAT 309 / 309 / 309 159 / 159 / 159
output 0, FindClosestMatchingMode (R8G8B8A8, 1280x720) 1280x720 at 164999/1000, Scaling 2 1280x720 at 165/1, Scaling 0
output 0, GetDesc1 BitsPerColor, ColorSpace 8, 0 8, 0
  • So the adapter without a monitor that the earlier comment here measured shows on this machine too: the layer gives the iGPU the other adapter's outputs, and the host comparison in the test is skipped when the host adapter has none.
  • Two more, not reported before: the mode list is about half as long as the host's (I did not look at which entries are missing), and refresh rates come back as whole Hz where the host gives the exact rational.

Not checked: LEONIDA_VK_VALIDATION=1, a monitor on the iGPU, an HDR display.

@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Follow-up DXGI comparison at f59c09d3, Windows 11 (26200), Radeon 780M + RTX 5060 Laptop. Instrumented the existing test to query the corresponding native adapter by LUID and the shim adapter under the same display configuration.

  • Native Radeon exposes 0 outputs, while the shim exposes 2. Native RTX and shim RTX both expose 2.
  • On the RTX, native vs shim mode counts for BGRA8 / RGB10A2 / RGBA16F are 90/90/90 vs 46/46/46 on DISPLAY1 and 49/49/49 vs 40/40/40 on DISPLAY2. The 1280×720 closest mode on DISPLAY1 was 165/1 on both, but native scaling was 2 and shim scaling 0. This setup did not reproduce a fractional refresh-rate difference.
  • DISPLAY1 with Windows HDR off: native GetDesc1 returned 10 bpc / color space 0, shim 8 bpc / color space 0. With HDR active (verified via Windows DisplayConfig), native switched to 10 bpc / color space 12, while the shim stayed at 8 bpc / color space 0. DISPLAY2 stayed at 8 bpc / color space 0 on both. Restored the original HDR-off state and verified it through DisplayConfig.
  • The existing DXGI CTest still passed with validation on, including the RTX run with HDR active. This tests reported output capabilities, not HDR rendering. No game data. AI-assisted testing and reporting.

@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@nightsale I verified an opt-in regression check in the existing DXGI fixture. It compares BitsPerColor and ColorSpace from the shim and native IDXGIOutput6 for the same display on the same DXGI adapter LUID. On the RTX 5060 Laptop, the check fails with native 10 bpc / SDR versus shim 8 bpc / SDR with HDR off, and native 10 bpc / PQ BT.2020 versus shim 8 bpc / SDR with HDR on. The default fixture passed with the opt-in disabled. Windows HDR was returned to its original off state and verified. No game data; AI-assisted.

Would you prefer this as a follow-up after #2976, or in this PR? My preference is a follow-up that queries native GetDesc1 for the matching HMONITOR and keeps the current SDR defaults for the headless fallback. The test can compare a freshly created factory in whichever color mode Windows is already using, without toggling system HDR in CTest.

@Catskan

Catskan commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested f59c09d on Sapphire RX 9070 XT Nitro+ (AMD 26.11.2 LLPC, driverVersion 2.0.416), Windows 11 26200, MSVC: pass.

  • scripts\build_runtime.ps1 builds.
  • Full ctest, run from a desktop session, has 0 failed out of 129. That includes dxgi_swapchain.
  • 7 tests were skipped: they need the game package or optional tools. gameinput is disabled in the default configure.

AI-assisted run.

@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I tested a local follow-up on f59c09d3: match the real output by HMONITOR across native DXGI adapters, use its GetDesc1 color and luminance fields, and keep the shim's existing monitor identity and headless SDR defaults. The opt-in native comparison that failed before now passes on the RTX 5060 Laptop with Windows HDR off and on. The full dxgi_swapchain test also passes on Radeon 780M in both states with validation enabled (native Radeon exposes no output, so the strict native comparison runs on RTX). Restored and verified the original HDR-off state. This is descriptor coverage only. I have a local patch ready to submit separately if that fits your plan. AI-assisted.

@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Follow-up on the local GetDesc1 patch: I simulated an empty Win32 monitor enumeration and exercised the shim through EnumOutputs and IDXGIOutput6::GetDesc1 on the RTX 5060 Laptop GPU. It exposed one synthetic 1920x1080 output with a null HMONITOR, 8-bit RGB full-range BT.709, and min/max/full-frame luminance of 0/80/80 cd/m². This was a simulation with the monitors connected. After removing the temporary probe, I rebuilt and reran the full dxgi_swapchain_test successfully. AI-assisted.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested f59c09d merged onto main f847748 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 141/141.
  • dxgi_swapchain: pass 20 of 20 runs, and pass under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

- Upgrade dxgi_com.h to dxgi1_6.h for IDXGIOutput6 / DXGI_OUTPUT_DESC1.
- Enumerate Win32 monitors via EnumDisplayMonitors / EnumDisplaySettingsW with headless 1920x1080@60 fallback.
- Implement Output (IDXGIOutput..IDXGIOutput6) and wire Adapter::EnumOutputs and SwapChain::GetContainingOutput against host dxgi.dll behavior.
- Add D3D-313 unit and host-comparison coverage in dxgi_swapchain_test.cpp (synthetic, no game data).

AI-assisted.
@nightsale

Copy link
Copy Markdown
Contributor Author

Rebased onto main (4c52ce2, head $finalHash) to resolve the merge conflicts with #2974 (IDXGIFactory7 in dxgi_com.h / dxgi_com.cpp), #2876 (ResizeTarget / GetContainingOutput context), and dxgi_swapchain_test.cpp (budget-change event test block).

Thank you all for the thorough cross-GPU testing (@Ryderadzeee, @Vonsek, @FaKL-Code, @steamaze0, @Doffi4, @zzEmmazz, @Catskan, @JRamos1993)!

Re-verified after the rebase ($finalHash on main 4c52ce2, Windows + MSVC Ninja RelWithDebInfo, NVIDIA GeForce RTX 3060, driver 621.24, LEONIDA_VK_VALIDATION=1, synthetic tests only, no game data, AI-assisted):

  • .\scripts\build_runtime.ps1: exit � (� warnings in modified files).
  • .\runtime\build\dxgi_swapchain_test.exe (LEONIDA_VK_VALIDATION=1): exit �, PASS (� Vulkan validation errors).
  • ctest --test-dir runtime\build --output-on-failure -j4 (LEONIDA_VK_VALIDATION=1): 135 of 136 active tests passed (including Docs: measured world placement/streaming composition #117 dxgi_swapchain in 1.79s, d3d12_present, xbox_present; 8 skipped: shader_library_corpus, �ink_decode, �ink_play_headless, sr_dispatch, �vh_builder, �ink_audio, d3d12_rgb9e5_rtv, d3d12_first_light; 1 disabled: gameinput). The single failure under -j4 (Index shader hashes and vertex signatures #36 winhttp_offline from 4c52ce2, unrelated to DXGI) passed 2/2 (50 check(s), 0 failure(s)) when run standalone (.\runtime\build\winhttp_offline_test.exe).
  • Python checks: compileall (exit �), make_game.py --help (exit �), ests/test_docs_links.py (6 tests OK), ests/test_ctest_registration.py (4 tests OK).

@mtrw00w

mtrw00w commented Nov 22, 2026

Copy link
Copy Markdown

claiming: D3D-286 — investigate and fix the d3d12_compute device proxy reference-count failure

@mtrw00w

mtrw00w commented Nov 22, 2026

Copy link
Copy Markdown

status: D3D-286 — already fixed on main by 9e65c21. Current main aa2988c passes d3d12_compute 25/25 on Windows 11 / RX 6800 XT. Releasing D3D-286.

claiming: D3D-425 — fix the KHR TLAS ARRAY_OF_POINTERS handling and add a synthetic regression test.

@Rossrocha

Copy link
Copy Markdown

Tested on AMD Radeon RX 6600 (RDNA2, gfx1032), Windows 11, Adrenalin 26.11.2 (Vulkan driver 32.0.21045.29003).

PR head 1ae9cee1 merged onto main aa2988cc, fresh MSVC build:

  • dxgi_swapchain_test: PASS with and without LEONIDA_VK_VALIDATION=1 (0 validation errors)
  • ctest: 153/153 passed, and 153/153 with LEONIDA_VK_VALIDATION=1
  • run_gpu_tests.py: 195/210 passed, 15 skipped (expected), native and with LEONIDA_W64_EMULATE=1

No regressions on this hardware.

@mesterember104-cpu

Copy link
Copy Markdown

Tested f59c09d on Tiger Lake (Xe-LP) iGPU 0x9a78, driver 32.0.101.7088, Windows 11, MSVC 14.44: pass

Full ctest -C RelWithDebInfo: 110/112 pass — the 2 failures are the known Intel-main pair (d3d12_buffer_tiles, d3d12_descriptor), failing the same way on main, untouched by this PR. Skips: shader_library_corpus, vk_sync_validation, d3d12_queue_wait, d3d12_rgb9e5_rtv, d3d12_first_light; gameinput Disabled (built without SDL3 — the PR does not touch it).

dxgi_swapchain_test.exe run directly with LEONIDA_VK_VALIDATION=1: PASS, 0 validation errors — including the new checks (Adapter::EnumOutputs with real monitors via EnumDisplayMonitors, IDXGIOutput6/GetDesc1, GetDisplayModeList/FindClosestMatchingMode, WaitForVBlank/DwmFlush path, SwapChain::GetContainingOutput, host dxgi.dll comparisons). Game-gated bonus data on this machine: bink_decode, bink_audio, pe_loader, pe_loader_bounds all PASS against the package DLLs.

AI-assisted (GLM, operated by the account owner).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown

Tested 1ae9cee1 merged onto main d974c88a (clean merge) on NVIDIA GeForce RTX 5080, Linux 580.65.06, runtime cross-built with clang-cl and run under Wine 11: pass for the GDKX boot step 3.

A synthetic guest (no game data) running through gta6rt --run gets its device from D3D12XboxCreateDevice. It then does the title's step 3: QueryInterface(IDXGIDevice1), GetAdapter, EnumOutputs(0).

  • On main: QI and GetAdapter return S_OK. EnumOutputs(0) returns 0x887a0002 (DXGI_ERROR_NOT_FOUND).
  • With this PR: all three return S_OK, and the output is \\.\DISPLAY1.
  • Regression check: the guest's 8 frame-ID back buffers still read back exact (786,432 of 786,432 pixels).

Next step for a guest, outside this PR: PresentX and the frame events are not reachable yet. Every queue slot from 19 to 127 returns E_NOTIMPL, as runtime/README says ("their queue and device slots are unmeasured").

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

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.