diff --git a/new_editor/app/Host/D3D12WindowSwapChainPresenter.cpp b/new_editor/app/Host/D3D12WindowSwapChainPresenter.cpp index 39db7cf8..dac7bb25 100644 --- a/new_editor/app/Host/D3D12WindowSwapChainPresenter.cpp +++ b/new_editor/app/Host/D3D12WindowSwapChainPresenter.cpp @@ -63,6 +63,8 @@ bool D3D12WindowSwapChainPresenter::CreateSwapChain(int width, int height) { return false; } + ConfigureFrameLatency(); + if (!RecreateBackBufferViews()) { m_lastError = "Failed to create swap chain back buffer views."; return false; @@ -73,6 +75,21 @@ bool D3D12WindowSwapChainPresenter::CreateSwapChain(int width, int height) { return true; } +void D3D12WindowSwapChainPresenter::ConfigureFrameLatency() { + D3D12SwapChain* d3d12SwapChain = GetD3D12SwapChain(); + if (d3d12SwapChain == nullptr) { + return; + } + + auto* nativeSwapChain = + static_cast(d3d12SwapChain->GetNativeHandle()); + if (nativeSwapChain == nullptr) { + return; + } + + nativeSwapChain->SetMaximumFrameLatency(1u); +} + void D3D12WindowSwapChainPresenter::DestroySwapChain() { ReleaseBackBufferViews(); diff --git a/new_editor/app/Host/D3D12WindowSwapChainPresenter.h b/new_editor/app/Host/D3D12WindowSwapChainPresenter.h index 8164ea3c..49ced76c 100644 --- a/new_editor/app/Host/D3D12WindowSwapChainPresenter.h +++ b/new_editor/app/Host/D3D12WindowSwapChainPresenter.h @@ -23,7 +23,7 @@ namespace XCEngine::UI::Editor::Host { class D3D12WindowSwapChainPresenter { public: - static constexpr std::uint32_t kSwapChainBufferCount = 3u; + static constexpr std::uint32_t kSwapChainBufferCount = 2u; bool Initialize(D3D12HostDevice& hostDevice, HWND hwnd, int width, int height); void Shutdown(); @@ -41,6 +41,7 @@ public: private: bool CreateSwapChain(int width, int height); + void ConfigureFrameLatency(); void DestroySwapChain(); bool RecreateSwapChain(int width, int height); ::XCEngine::RHI::D3D12SwapChain* GetD3D12SwapChain() const;