Execute viewport offscreen frames through D3D12 host

This commit is contained in:
2026-04-12 23:21:59 +08:00
parent 941034b387
commit dd3731ba66
7 changed files with 69 additions and 6 deletions

View File

@@ -464,8 +464,18 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
LogRuntimeTrace("app", "renderer initialization failed");
return false;
}
RECT clientRect = {};
GetClientRect(m_hwnd, &clientRect);
const int clientWidth = (std::max)(clientRect.right - clientRect.left, 1L);
const int clientHeight = (std::max)(clientRect.bottom - clientRect.top, 1L);
if (!m_windowRenderer.Initialize(m_hwnd, clientWidth, clientHeight)) {
LogRuntimeTrace("app", "d3d12 window renderer initialization failed");
return false;
}
m_editorContext.AttachTextMeasurer(m_renderer);
m_editorWorkspace.Initialize(repoRoot, m_renderer);
m_editorWorkspace.AttachViewportWindowRenderer(m_windowRenderer);
m_editorWorkspace.SetViewportSurfacePresentationEnabled(false);
if (!m_editorWorkspace.GetBuiltInIconError().empty()) {
LogRuntimeTrace("icons", m_editorWorkspace.GetBuiltInIconError());
}
@@ -494,6 +504,7 @@ void Application::Shutdown() {
m_autoScreenshot.Shutdown();
m_editorWorkspace.Shutdown();
m_windowRenderer.Shutdown();
m_renderer.Shutdown();
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
@@ -541,11 +552,22 @@ void Application::RenderFrame() {
m_editorWorkspace.GetShellInteractionState()));
}
const bool d3d12FrameBegun = m_windowRenderer.BeginFrame();
if (!d3d12FrameBegun) {
LogRuntimeTrace("viewport", "d3d12 frame begin failed");
}
m_editorWorkspace.Update(
m_editorContext,
UIRect(0.0f, 0.0f, width, height),
frameEvents,
BuildCaptureStatusText());
if (d3d12FrameBegun) {
m_editorWorkspace.RenderRequestedViewports(m_windowRenderer.GetRenderContext());
if (!m_windowRenderer.SubmitFrame(false)) {
LogRuntimeTrace("viewport", "d3d12 offscreen frame submit failed");
}
}
const UIEditorShellInteractionFrame& shellFrame =
m_editorWorkspace.GetShellFrame();
if (!frameEvents.empty() ||
@@ -710,6 +732,7 @@ void Application::OnResize(UINT width, UINT height) {
}
m_renderer.Resize(width, height);
m_windowRenderer.Resize(static_cast<int>(width), static_cast<int>(height));
}
void Application::OnDpiChanged(UINT dpi, const RECT& suggestedRect) {