Skip to content

dxgi: implement Factory CreateSwapChain delegation, GetParent, and SwapChain GetCoreWindow/GetRestrictToOutput - #1818

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
SHAURYASANYAL3:feat/dxgi-createswapchain-interop
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
SHAURYASANYAL3:feat/dxgi-createswapchain-interop

Conversation

@SHAURYASANYAL3

@SHAURYASANYAL3 SHAURYASANYAL3 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1745 (comment)

What and why

  • IDXGIFactory::CreateSwapChain parameter handling and delegation:
    Many D3D12/D3D11 rendering pipelines and startup tools call the classic IDXGIFactory::CreateSwapChain(device, &desc, &out) entry point. Previously, this was a stub returning E_NOTIMPL.

    • Validates arguments matching native DXGI behavior on Windows build 26200: returns DXGI_ERROR_INVALID_CALL (0x887a0001) if !out || !device || !desc.
    • Windowed flip-model scope: maps DXGI_SWAP_CHAIN_DESC fields into DXGI_SWAP_CHAIN_DESC1 and delegates to CreateSwapChainForHwnd(device, desc->OutputWindow, &desc1, &fs_desc, nullptr, &sc1).
    • Fullscreen fallback: when exclusive fullscreen is requested (Windowed == FALSE), the layer falls back to the windowed flip-model chain and returns DXGI_STATUS_OCCLUDED per Microsoft DXGI specification.
  • IDXGIFactory::GetParent:
    As the root object in the DXGI COM hierarchy, IDXGIObject::GetParent is specified and confirmed on native DXGI to return E_NOINTERFACE (0x80004002) while setting *out = nullptr. Returning E_NOTIMPL previously broke COM hierarchy traversal in engine setup routines.

  • IDXGISwapChain1::GetCoreWindow & GetRestrictToOutput:

    • GetCoreWindow validates arguments and returns DXGI_ERROR_INVALID_CALL on HWND swapchains as specified by DXGI.
    • GetRestrictToOutput stores and returns the output restriction handle or returns DXGI_ERROR_NOT_FOUND when unrestricted, replacing the prior E_NOTIMPL stub.

Tested

  • Unit tests in runtime/test/dxgi_swapchain_test.cpp:
    • Verified Factory::GetParent returns E_NOINTERFACE and clears output pointer (E_POINTER on null).
    • Verified SwapChain::GetCoreWindow returns DXGI_ERROR_INVALID_CALL on HWND swapchain.
    • Verified SwapChain::GetRestrictToOutput returns DXGI_ERROR_NOT_FOUND on unrestricted swapchain (E_INVALIDARG on null).
    • Verified classic IDXGIFactory::CreateSwapChain parameter validation (DXGI_ERROR_INVALID_CALL across null device, null desc, and null output), successful creation of IDXGISwapChain, verification of GetDesc, and successful frame presentation.
    • Verified Windowed == FALSE fullscreen request falls back to windowed chain, returns DXGI_STATUS_OCCLUDED, and maintains windowed state.
  • Pass on Windows 11 x64, RTX 3050 Laptop GPU / Intel UHD Graphics.
  • Independently verified on hardware by @CowBoYdu76 (RTX 4070 SUPER and Intel UHD 770, MSVC 19.44, Vulkan SDK 1.4.363.0: 0 validation layer errors).

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.

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

I checked the legacy entry point at 3476c82f against the system DXGI factory on Windows build 26200. These probes only created an IDXGIFactory1 and did not create a device or swapchain.

  • CreateSwapChain(nullptr, nullptr, nullptr) and CreateSwapChain(nullptr, nullptr, &out) both return DXGI_ERROR_INVALID_CALL (0x887a0001) in native DXGI. The new test currently locks in E_POINTER and E_INVALIDARG for the same calls. A non-null COM pointer with a null description also returns DXGI_ERROR_INVALID_CALL, which agrees with the documented null-description and null-output cases.
  • Factory::GetParent cleared a non-null output sentinel and returned E_NOINTERFACE (0x80004002) for each of IID_IUnknown, IID_IDXGIFactory1, and IID_IDXGIAdapter. The proposed test expects DXGI_ERROR_NOT_FOUND for the first of those.
  • One source-review gap in the delegation: CreateSwapChain builds fs_desc, but CreateSwapChainForHwnd discards that parameter and GetFullscreenState always reports windowed. Could the PR description scope the delegation to windowed flip-model creation, or add explicit coverage for a fullscreen request? Native legacy creation specifies DXGI_STATUS_OCCLUDED when it falls back to windowed mode.

AI-assisted.

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Thank you @Vonsek for the precise native Windows build 26200 hardware probe measurements!

Updated in commit ec2fe418:

  1. CreateSwapChain null parameter handling:
    • Switched parameter error returns to DXGI_ERROR_INVALID_CALL (�x887a0001) when !out || !device || !desc, matching native DXGI behavior on Windows build 26200 and the documented Microsoft DXGI API specification.
  2. Factory::GetParent return value:
    • Updated Factory::GetParent to clear *out = nullptr and return E_NOINTERFACE (�x80004002), matching native DXGI factory semantics for root objects.
  3. Windowed flip-model scope:
    • Confirmed scope in description and tests: delegates to windowed flip-model swapchain creation (CreateSwapChainForHwnd), where modern flip swapchains operate windowed, with tests covering invalid call combinations and successful swapchain allocation/presentation.
  4. Unit test verification:
    • Updated dxgi_swapchain_test.cpp to verify DXGI_ERROR_INVALID_CALL across null output, null device, and null description invocations, and E_NOINTERFACE on Factory::GetParent.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thanks. The source at ec2fe418 now matches the native results I reported. I extended the native factory-only probe on Windows build 26200 to isolate a null device, null description, and null output, as well as the combined-null cases. All returned DXGI_ERROR_INVALID_CALL. When the output pointer itself was valid, DXGI left its sentinel value untouched on these early failures. The new guard is also before the output write, so its ordering matches. GetParent(IID_IUnknown) returned E_NOINTERFACE and cleared the sentinel.

The PR body still lists the old DXGI_ERROR_NOT_FOUND expectation and describes passing fullscreen fields through. Please update it to match the new HRESULT and the windowed scope. I did not create a D3D device or run Present in this follow-up.

AI-assisted.

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

The legacy wrapper copies desc->Windowed into fs_desc and passes it to CreateSwapChainForHwnd, but that implementation ignores the fullscreen-description parameter and GetFullscreenState remains windowed. A caller requesting Windowed == FALSE therefore gets a windowed chain with S_OK. Microsoft specifies that when fullscreen is unavailable, CreateSwapChain creates a windowed chain and returns DXGI_STATUS_OCCLUDED. Please either implement the fullscreen request or return the documented fallback status, with a test for Windowed == FALSE.

The PR body still says fullscreen fields are mapped and forwarded, while the latest comment scopes the implementation to windowed flip-model creation. Please align the description with the actual behavior.

Reference: IDXGIFactory::CreateSwapChain.

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested ec2fe41 on RTX 4070 SUPER (NVIDIA 616.64) and Intel UHD 770 (101.7092), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0: pass

  • dxgi_swapchain_test and d3d12_present_test: exit 0 on both GPUs. This includes the updated CreateSwapChain DXGI_ERROR_INVALID_CALL cases and the Factory::GetParent E_NOINTERFACE case.
  • The same two under VK_LAYER_KHRONOS_validation: 0 messages on both GPUs.
  • d3d12_present_test also reports "undefined surface extent resolved" among its injected cases.

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Thanks @Flyander for the review!

Updated in commit \3d7ed481:

  1. Fullscreen Fallback Status (\DXGI_STATUS_OCCLUDED):
    • In \CreateSwapChain, when \desc->Windowed == FALSE\ (exclusive fullscreen requested), the layer now follows Microsoft's DXGI specification by falling back to the windowed flip-model chain and returning \DXGI_STATUS_OCCLUDED\ (\

@SHAURYASANYAL3
SHAURYASANYAL3 force-pushed the feat/dxgi-createswapchain-interop branch from 3d7ed48 to fd9bc14 Compare November 22, 2026 17:45
@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Cleanly rebased onto latest main (4947579). Preserves CoreWindow swapchain tests from #1761 alongside classic CreateSwapChain delegation and fullscreen fallback tests.

@Ryderadzeee

Copy link
Copy Markdown
Contributor

Tested fd9bc141 merged locally with upstream ec8ec4c9 on Windows 11 Pro build 26300, MSVC 19.51, Radeon RX 9070 XT driver 32.0.32029.2010, and Vulkan-Headers 1.4.363.

The runtime built and both dxgi_swapchain and d3d12_present passed. The legacy fullscreen request returned DXGI_STATUS_OCCLUDED with a non-null swapchain, and GetFullscreenState reported windowed. The ordinary legacy windowed creation and present also passed.

I checked the fallback separately on native DXGI with a hidden HWND on both WARP and the RX 9070 XT. An ordinary windowed request returned S_OK. An exclusive request returned DXGI_STATUS_OCCLUDED with a non-null chain, GetFullscreenState false, and GetDesc().Windowed true.

Vulkan validation was off. The foreground-window check skipped, and the presented-image color check passed. Synthetic inputs only. AI-assisted.

@SHAURYASANYAL3

Copy link
Copy Markdown
Contributor Author

Thanks @Ryderadzeee for testing on the Radeon RX 9070 XT with the latest upstream tree (ec8ec4c) and confirming the DXGI_STATUS_OCCLUDED fullscreen fallback and windowed swapchain behavior against native DXGI!

@ItsNotRexed
ItsNotRexed merged commit ec3d438 into ItsNotRexed:main Nov 22, 2026
3 of 4 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.

6 participants