Refactor RHI swapchain present policy
This commit is contained in:
@@ -12,6 +12,7 @@ using ::XCEngine::RHI::ResourceStates;
|
||||
using ::XCEngine::RHI::ResourceViewDesc;
|
||||
using ::XCEngine::RHI::ResourceViewDimension;
|
||||
using ::XCEngine::RHI::SwapChainDesc;
|
||||
using ::XCEngine::RHI::SwapChainPresentMode;
|
||||
|
||||
bool D3D12WindowSwapChainPresenter::Initialize(
|
||||
D3D12HostDevice& hostDevice,
|
||||
@@ -57,6 +58,8 @@ bool D3D12WindowSwapChainPresenter::CreateSwapChain(int width, int height) {
|
||||
swapChainDesc.width = static_cast<std::uint32_t>(width);
|
||||
swapChainDesc.height = static_cast<std::uint32_t>(height);
|
||||
swapChainDesc.bufferCount = kSwapChainBufferCount;
|
||||
swapChainDesc.presentPolicy.preferredMode = SwapChainPresentMode::Immediate;
|
||||
swapChainDesc.presentPolicy.maxFrameLatency = 1u;
|
||||
m_swapChain = m_hostDevice->GetRHIDevice()->CreateSwapChain(
|
||||
swapChainDesc,
|
||||
m_hostDevice->GetRHICommandQueue());
|
||||
@@ -65,8 +68,6 @@ bool D3D12WindowSwapChainPresenter::CreateSwapChain(int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigureFrameLatency();
|
||||
|
||||
if (!RecreateBackBufferViews()) {
|
||||
m_lastError = "Failed to create swap chain back buffer views.";
|
||||
return false;
|
||||
@@ -77,21 +78,6 @@ 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(kSwapChainBufferCount);
|
||||
}
|
||||
|
||||
void D3D12WindowSwapChainPresenter::DestroySwapChain() {
|
||||
ReleaseBackBufferViews();
|
||||
|
||||
@@ -292,7 +278,7 @@ bool D3D12WindowSwapChainPresenter::PresentFrame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_swapChain->Present(0, 0);
|
||||
m_swapChain->Present();
|
||||
m_lastError.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user