upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/dxgi_com.cpp
diff options
context:
space:
mode:
authorEwann <207907827+dev-ewann@users.noreply.github.com>2026-11-22 18:44:29 +0100
committerEwann <207907827+dev-ewann@users.noreply.github.com>2026-11-22 21:27:31 +0100
commite62744353bb61eefa06c14322fbdc965754ebe67 (patch)
treeb42a3e03da059ce0bd12c91a93d8d1ab95d312bd /runtime/shims/dxgi_com.cpp
parentf847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff)
DXGI: CreateSwapChainForHwnd refuses what the host runtime's DXGI refuses
Measured on RTX 5070 / 621.14: bitblt effects, window-incompatible scaling and alpha modes, flags outside 0x2/0x20/0x40/0x800/0x1000/0x2000, shared/read-only/discard-on-present/UAV usage, a null or non-queue device, null window/description/output are DXGI_ERROR_INVALID_CALL; a side above 16384 is E_INVALIDARG. dxgi_swapchain_test compares 40 descriptions with the host. The CoreWindow path keeps its old checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/dxgi_com.cpp')
-rw-r--r--runtime/shims/dxgi_com.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/runtime/shims/dxgi_com.cpp b/runtime/shims/dxgi_com.cpp
index 55683ea52..42558e621 100644
--- a/runtime/shims/dxgi_com.cpp
+++ b/runtime/shims/dxgi_com.cpp
@@ -836,6 +836,44 @@ public:
836 HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd(IUnknown* device, HWND hwnd, const DXGI_SWAP_CHAIN_DESC1* desc, 836 HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd(IUnknown* device, HWND hwnd, const DXGI_SWAP_CHAIN_DESC1* desc,
837 const DXGI_SWAP_CHAIN_FULLSCREEN_DESC*, IDXGIOutput* restrict_to_output, 837 const DXGI_SWAP_CHAIN_FULLSCREEN_DESC*, IDXGIOutput* restrict_to_output,
838 IDXGISwapChain1** out) override { 838 IDXGISwapChain1** out) override {
839 if (out) *out = nullptr;
840 if (const HRESULT hr = check_hwnd_swap_chain(device, hwnd, desc, out); FAILED(hr)) return hr;
841 return create_swap_chain(device, hwnd, desc, restrict_to_output, out);
842 }
843
844 // What the host runtime's DXGI refuses for a D3D12 swap chain on a window (dxgi_swapchain_test compares these,
845 // RTX 5070 / 621.14): a null queue, window, description or output, an ID3D12Device in place of the queue, the
846 // bitblt effects, a scaling or alpha mode a window can't present, a flag outside the ones a D3D12 window swap chain
847 // takes (MODE_SWITCH, DISPLAY_ONLY, FRAME_LATENCY_WAITABLE_OBJECT, ALLOW_TEARING, the holographic restriction and
848 // 0x2000), and a shared, read-only, discard-on-present or unordered-access buffer usage are
849 // DXGI_ERROR_INVALID_CALL; a side above 16384 is E_INVALIDARG.
850 static HRESULT check_hwnd_swap_chain(IUnknown* device, HWND hwnd, const DXGI_SWAP_CHAIN_DESC1* desc,
851 IDXGISwapChain1** out) {
852 if (!device || !hwnd || !desc || !out) return DXGI_ERROR_INVALID_CALL;
853 ID3D12CommandQueue* queue = nullptr;
854 if (FAILED(device->QueryInterface(IID_PPV_ARGS(&queue))) || !queue) return DXGI_ERROR_INVALID_CALL;
855 queue->Release();
856 if (desc->SwapEffect != DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL && desc->SwapEffect != DXGI_SWAP_EFFECT_FLIP_DISCARD)
857 return DXGI_ERROR_INVALID_CALL;
858 if (desc->Scaling != DXGI_SCALING_STRETCH && desc->Scaling != DXGI_SCALING_NONE) return DXGI_ERROR_INVALID_CALL;
859 if (desc->AlphaMode != DXGI_ALPHA_MODE_UNSPECIFIED && desc->AlphaMode != DXGI_ALPHA_MODE_IGNORE)
860 return DXGI_ERROR_INVALID_CALL;
861 constexpr UINT kWindowFlags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH | DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY |
862 DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT |
863 DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING | 0x1000u | 0x2000u;
864 if (desc->Flags & ~kWindowFlags) return DXGI_ERROR_INVALID_CALL;
865 constexpr DXGI_USAGE kRefusedUsage =
866 DXGI_USAGE_SHARED | DXGI_USAGE_READ_ONLY | DXGI_USAGE_DISCARD_ON_PRESENT | DXGI_USAGE_UNORDERED_ACCESS;
867 if (desc->BufferUsage & kRefusedUsage) return DXGI_ERROR_INVALID_CALL;
868 if (desc->Width > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION || desc->Height > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION)
869 return E_INVALIDARG;
870 return S_OK;
871 }
872
873 // The swap chain itself, for a window or (through its HWND) a CoreWindow. The CoreWindow path keeps only these
874 // checks: the host's rules for it (ASPECT_RATIO_STRETCH, for one) can't be compared without a real CoreWindow.
875 HRESULT create_swap_chain(IUnknown* device, HWND hwnd, const DXGI_SWAP_CHAIN_DESC1* desc,
876 IDXGIOutput* restrict_to_output, IDXGISwapChain1** out) {
839 if (!out) return E_POINTER; 877 if (!out) return E_POINTER;
840 *out = nullptr; 878 *out = nullptr;
841 if (!hwnd || !desc) return E_INVALIDARG; 879 if (!hwnd || !desc) return E_INVALIDARG;
@@ -875,7 +913,7 @@ public:
875 const HRESULT hr = interop->get_WindowHandle(&hwnd); 913 const HRESULT hr = interop->get_WindowHandle(&hwnd);
876 interop->Release(); 914 interop->Release();
877 if (FAILED(hr) || !hwnd) return DXGI_ERROR_INVALID_CALL; 915 if (FAILED(hr) || !hwnd) return DXGI_ERROR_INVALID_CALL;
878 return CreateSwapChainForHwnd(device, hwnd, desc, nullptr, restrict_to_output, out); 916 return create_swap_chain(device, hwnd, desc, restrict_to_output, out);
879 } 917 }
880 HRESULT STDMETHODCALLTYPE GetSharedResourceAdapterLuid(HANDLE, LUID*) override { return E_NOTIMPL; } 918 HRESULT STDMETHODCALLTYPE GetSharedResourceAdapterLuid(HANDLE, LUID*) override { return E_NOTIMPL; }
881 HRESULT STDMETHODCALLTYPE RegisterStereoStatusWindow(HWND, UINT, DWORD*) override { return E_NOTIMPL; } 919 HRESULT STDMETHODCALLTYPE RegisterStereoStatusWindow(HWND, UINT, DWORD*) override { return E_NOTIMPL; }