new_editor: stabilize resize lifecycle groundwork
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <XCEditor/Foundation/UIEditorRuntimeTrace.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
|
||||
@@ -17,6 +18,15 @@ using ::XCEngine::RHI::ResourceViewDimension;
|
||||
using ::XCEngine::RHI::SwapChainDesc;
|
||||
using ::XCEngine::RHI::SwapChainPresentMode;
|
||||
|
||||
bool IsVerboseResizeTraceEnabled() {
|
||||
wchar_t buffer[8] = {};
|
||||
const DWORD length = GetEnvironmentVariableW(
|
||||
L"XCUIEDITOR_VERBOSE_TRACE",
|
||||
buffer,
|
||||
static_cast<DWORD>(sizeof(buffer) / sizeof(buffer[0])));
|
||||
return length > 0u && buffer[0] != L'0';
|
||||
}
|
||||
|
||||
bool D3D12WindowSwapChainPresenter::Initialize(
|
||||
D3D12HostDevice& hostDevice,
|
||||
HWND hwnd,
|
||||
@@ -339,7 +349,9 @@ bool D3D12WindowSwapChainPresenter::Resize(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
m_hostDevice->WaitForSubmittedFrames();
|
||||
const auto waitBegin = std::chrono::steady_clock::now();
|
||||
m_hostDevice->WaitForTrackedFrameRetirement();
|
||||
const auto waitEnd = std::chrono::steady_clock::now();
|
||||
ReleaseBackBufferCommandReferences();
|
||||
ReleaseBackBufferViews();
|
||||
|
||||
@@ -349,10 +361,28 @@ bool D3D12WindowSwapChainPresenter::Resize(int width, int height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto resizeBuffersBegin = std::chrono::steady_clock::now();
|
||||
d3d12SwapChain->Resize(
|
||||
static_cast<std::uint32_t>(width),
|
||||
static_cast<std::uint32_t>(height));
|
||||
const auto resizeBuffersEnd = std::chrono::steady_clock::now();
|
||||
const HRESULT resizeHr = d3d12SwapChain->GetLastResizeResult();
|
||||
if (IsVerboseResizeTraceEnabled()) {
|
||||
const auto waitMs =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(waitEnd - waitBegin).count();
|
||||
const auto resizeBuffersMs =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
resizeBuffersEnd - resizeBuffersBegin).count();
|
||||
std::ostringstream trace = {};
|
||||
trace << "swapchain resize requested="
|
||||
<< width << 'x' << height
|
||||
<< " waitForTrackedRetirementMs=" << waitMs
|
||||
<< " resizeBuffersMs=" << resizeBuffersMs
|
||||
<< " hr=0x"
|
||||
<< std::hex << std::uppercase
|
||||
<< static_cast<unsigned long>(resizeHr);
|
||||
AppendUIEditorRuntimeTrace("resize", trace.str());
|
||||
}
|
||||
if (FAILED(resizeHr)) {
|
||||
if (RecreateSwapChain(width, height)) {
|
||||
m_lastError.clear();
|
||||
|
||||
Reference in New Issue
Block a user