Reduce host swap chain latency

This commit is contained in:
2026-04-14 00:25:57 +08:00
parent d705cc839b
commit c3d443eb85
2 changed files with 19 additions and 1 deletions

View File

@@ -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<IDXGISwapChain3*>(d3d12SwapChain->GetNativeHandle());
if (nativeSwapChain == nullptr) {
return;
}
nativeSwapChain->SetMaximumFrameLatency(1u);
}
void D3D12WindowSwapChainPresenter::DestroySwapChain() {
ReleaseBackBufferViews();

View File

@@ -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;