File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,16 @@ bool DriverImpl::init()
101101 _AXASSERT_HR (
102102 hr = _device->QueryInterface (__uuidof (IDXGIDevice), reinterpret_cast <void **>(dxgiDevice.GetAddressOf ())));
103103 _AXASSERT_HR (hr = dxgiDevice->GetAdapter (&_dxgiAdapter));
104+
105+ // Refresh factory pointer from adapter to ensure consistency.
106+ // Using the factory obtained via GetParent guarantees it matches the adapter
107+ // bound to the device. Without this, creating a swapchain may fail with
108+ // DXGI_ERROR_INVALID_CALL(0x887A0001) if the factory and adapter come from different DXGI instances.
109+ _AXASSERT_HR (
110+ hr = _dxgiAdapter->GetParent (__uuidof (IDXGIFactory1), (void **)_dxgiFactory.ReleaseAndGetAddressOf ()));
111+
112+ // Optionally query for DXGI 1.2+ factory (IDXGIFactory2) to enable modern features
113+ _dxgiFactory->QueryInterface (IID_PPV_ARGS (_dxgiFactory2.ReleaseAndGetAddressOf ()));
104114 }
105115
106116 LARGE_INTEGER version;
@@ -151,12 +161,12 @@ void DriverImpl::initializeDevice()
151161
152162 const bool isDebugLayer = Application::getContextAttrs ().debugLayerEnabled ;
153163
154- HRESULT hr = _dxgiFactory->QueryInterface (IID_PPV_ARGS (&_dxgiFactory2));
155-
156164 constexpr D3D_FEATURE_LEVEL DEFAULT_FEATURE_LEVELS[] = {D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
157165 D3D_FEATURE_LEVEL_10_1};
158166 std::span<const D3D_FEATURE_LEVEL> featureLevels (DEFAULT_FEATURE_LEVELS);
159167
168+ // It's ok to check whether DXGI 1.2 is supported at here
169+ HRESULT hr = _dxgiFactory->QueryInterface (IID_PPV_ARGS (&_dxgiFactory2));
160170 if (!_dxgiFactory2)
161171 {
162172 // On Windows 7 RTM or Windows 7 SP1 without the Platform Update (KB2670838),
You can’t perform that action at this time.
0 commit comments