From c4790309ec46ae2f4f7c49eb50699a950ee7a9a4 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 20 Feb 2022 14:37:41 -0800 Subject: gfx: defer downstream shader compilation until draw/dispatch. (#2139) Co-authored-by: Yong He --- tools/gfx/d3d/d3d-swapchain.h | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'tools/gfx/d3d') diff --git a/tools/gfx/d3d/d3d-swapchain.h b/tools/gfx/d3d/d3d-swapchain.h index 99343aaf4..1c29b2039 100644 --- a/tools/gfx/d3d/d3d-swapchain.h +++ b/tools/gfx/d3d/d3d-swapchain.h @@ -48,17 +48,44 @@ public: swapChainDesc.OutputWindow = (HWND)window.handleValues[0]; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.Windowed = TRUE; - if (!desc.enableVSync) { swapChainDesc.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; } // Swap chain needs the queue so that it can force a flush on it. - ComPtr swapChain; - SLANG_RETURN_ON_FAIL( - getDXGIFactory()->CreateSwapChain(getOwningDevice(), &swapChainDesc, swapChain.writeRef())); - SLANG_RETURN_ON_FAIL(swapChain->QueryInterface(m_swapChain.writeRef())); + ComPtr dxgiFactory2; + getDXGIFactory()->QueryInterface(IID_PPV_ARGS(dxgiFactory2.writeRef())); + if (!dxgiFactory2) + { + ComPtr swapChain; + SLANG_RETURN_ON_FAIL(getDXGIFactory()->CreateSwapChain( + getOwningDevice(), &swapChainDesc, swapChain.writeRef())); + SLANG_RETURN_ON_FAIL(getDXGIFactory()->MakeWindowAssociation( + (HWND)window.handleValues[0], DXGI_MWA_NO_ALT_ENTER)); + SLANG_RETURN_ON_FAIL(swapChain->QueryInterface(m_swapChain.writeRef())); + } + else + { + DXGI_SWAP_CHAIN_DESC1 desc1 = {}; + desc1.BufferCount = swapChainDesc.BufferCount; + desc1.BufferUsage = swapChainDesc.BufferUsage; + desc1.Flags = swapChainDesc.Flags; + desc1.Format = swapChainDesc.BufferDesc.Format; + desc1.Height = swapChainDesc.BufferDesc.Height; + desc1.Width = swapChainDesc.BufferDesc.Width; + desc1.SampleDesc = swapChainDesc.SampleDesc; + desc1.SwapEffect = swapChainDesc.SwapEffect; + ComPtr swapChain1; + SLANG_RETURN_ON_FAIL(dxgiFactory2->CreateSwapChainForHwnd( + getOwningDevice(), + (HWND)window.handleValues[0], + &desc1, + nullptr, + nullptr, + swapChain1.writeRef())); + SLANG_RETURN_ON_FAIL(swapChain1->QueryInterface(m_swapChain.writeRef())); + } if (!desc.enableVSync) { @@ -74,9 +101,6 @@ public: m_swapChain->SetMaximumFrameLatency(maxLatency); } - SLANG_RETURN_ON_FAIL(getDXGIFactory()->MakeWindowAssociation( - (HWND)window.handleValues[0], DXGI_MWA_NO_ALT_ENTER)); - createSwapchainBufferImages(); return SLANG_OK; } -- cgit v1.2.3