From edf434aa037df92904b246ca9d020f595c2cce26 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sun, 5 Apr 2026 06:43:51 +0800 Subject: [PATCH] Tighten XCUI compositor texture registration --- docs/plan/XCUI_Phase_Status_2026-04-05.md | 2 ++ new_editor/src/Application.h | 6 ++-- .../src/XCUIBackend/IEditorHostCompositor.h | 11 ++------ .../src/XCUIBackend/IWindowUICompositor.h | 11 ++------ .../src/XCUIBackend/ImGuiHostCompositor.cpp | 28 +++++++++++-------- .../src/XCUIBackend/ImGuiWindowUICompositor.h | 14 +++------- .../src/XCUIBackend/UITextureRegistration.h | 23 +++++++++++++++ 7 files changed, 54 insertions(+), 41 deletions(-) create mode 100644 new_editor/src/XCUIBackend/UITextureRegistration.h diff --git a/docs/plan/XCUI_Phase_Status_2026-04-05.md b/docs/plan/XCUI_Phase_Status_2026-04-05.md index e8f150f5..85e1ac78 100644 --- a/docs/plan/XCUI_Phase_Status_2026-04-05.md +++ b/docs/plan/XCUI_Phase_Status_2026-04-05.md @@ -68,6 +68,7 @@ Current gap: - Panel diagnostics were expanded to clearly separate preview/runtime/input state and native vs legacy paths. - The editor bridge layer now has smoke coverage for swapchain after-UI rendering hooks and SRV-backed ImGui texture descriptor registration. - `Application` no longer owns the ImGui backend directly; window presentation now routes through `IWindowUICompositor` with an `ImGuiWindowUICompositor` implementation, which currently delegates to `IEditorHostCompositor` / `ImGuiHostCompositor`. +- Hosted preview offscreen surfaces now keep compositor-returned `UITextureRegistration` / `UITextureHandle` data inside `Application` instead of storing `ImTextureID` directly. - The generic hosted-preview presenter contract no longer owns `ImGuiTransitionBackend`; the ImGui presenter now sits in a separate `ImGuiXCUIHostedPreviewPresenter` header while the native queue/surface registry remains XCUI-generic. - The generic hosted-preview frame contract no longer carries an ImGui draw-list pointer; the legacy ImGui presenter resolves its inline draw target from the active ImGui window context instead of pushing that type through the XCUI contract. - `XCNewEditor` builds successfully to `build/new_editor/bin/Debug/XCNewEditor.exe`. @@ -139,6 +140,7 @@ Current gap: - `IEditorHostCompositor` - `ImGuiHostCompositor` - `Application` frame/present flow routed through the compositor instead of direct `m_imguiBackend` ownership +- Window compositor texture registration now also flows back into `Application` as XCUI-owned `UITextureRegistration` / `UITextureHandle` data instead of exposing raw `ImTextureID` there. - Hosted preview contracts were tightened again: - generic preview surface metadata stays on XCUI-owned value types - `ImGuiTransitionBackend` moved behind `ImGuiXCUIHostedPreviewPresenter` diff --git a/new_editor/src/Application.h b/new_editor/src/Application.h index 2663bc34..62db8bdd 100644 --- a/new_editor/src/Application.h +++ b/new_editor/src/Application.h @@ -57,16 +57,14 @@ private: std::uint32_t height = 0; ::XCEngine::RHI::RHITexture* colorTexture = nullptr; ::XCEngine::RHI::RHIResourceView* colorView = nullptr; - D3D12_CPU_DESCRIPTOR_HANDLE imguiCpuHandle = {}; - D3D12_GPU_DESCRIPTOR_HANDLE imguiGpuHandle = {}; - ImTextureID imguiTextureId = {}; + ::XCEngine::Editor::XCUIBackend::UITextureRegistration textureRegistration = {}; ::XCEngine::RHI::ResourceStates colorState = ::XCEngine::RHI::ResourceStates::Common; bool IsReady() const { return !debugName.empty() && colorTexture != nullptr && colorView != nullptr && - imguiTextureId != ImTextureID{} && + textureRegistration.IsValid() && width > 0u && height > 0u; } diff --git a/new_editor/src/XCUIBackend/IEditorHostCompositor.h b/new_editor/src/XCUIBackend/IEditorHostCompositor.h index 4256f734..712312ce 100644 --- a/new_editor/src/XCUIBackend/IEditorHostCompositor.h +++ b/new_editor/src/XCUIBackend/IEditorHostCompositor.h @@ -1,12 +1,11 @@ #pragma once #include "Platform/D3D12WindowRenderer.h" +#include "XCUIBackend/UITextureRegistration.h" #include #include -#include - #include #include #include @@ -37,12 +36,8 @@ public: virtual bool CreateTextureDescriptor( ::XCEngine::RHI::RHIDevice* device, ::XCEngine::RHI::RHITexture* texture, - D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle, - ImTextureID* outTextureId) = 0; - virtual void FreeTextureDescriptor( - D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) = 0; + UITextureRegistration& outRegistration) = 0; + virtual void FreeTextureDescriptor(const UITextureRegistration& registration) = 0; }; std::unique_ptr CreateImGuiHostCompositor(); diff --git a/new_editor/src/XCUIBackend/IWindowUICompositor.h b/new_editor/src/XCUIBackend/IWindowUICompositor.h index 8172882e..45738c11 100644 --- a/new_editor/src/XCUIBackend/IWindowUICompositor.h +++ b/new_editor/src/XCUIBackend/IWindowUICompositor.h @@ -1,12 +1,11 @@ #pragma once #include "Platform/D3D12WindowRenderer.h" +#include "XCUIBackend/UITextureRegistration.h" #include #include -#include - #include #include #include @@ -37,12 +36,8 @@ public: virtual bool CreateTextureDescriptor( ::XCEngine::RHI::RHIDevice* device, ::XCEngine::RHI::RHITexture* texture, - D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle, - ImTextureID* outTextureId) = 0; - virtual void FreeTextureDescriptor( - D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) = 0; + UITextureRegistration& outRegistration) = 0; + virtual void FreeTextureDescriptor(const UITextureRegistration& registration) = 0; }; std::unique_ptr CreateImGuiWindowUICompositor(); diff --git a/new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp b/new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp index 18727ab4..8e079152 100644 --- a/new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp +++ b/new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp @@ -67,21 +67,27 @@ public: bool CreateTextureDescriptor( ::XCEngine::RHI::RHIDevice* device, ::XCEngine::RHI::RHITexture* texture, - D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle, - ImTextureID* outTextureId) override { - return m_backend.CreateTextureDescriptor( + UITextureRegistration& outRegistration) override { + ImTextureID textureId = {}; + if (!m_backend.CreateTextureDescriptor( device, texture, - outCpuHandle, - outGpuHandle, - outTextureId); + &outRegistration.cpuHandle, + &outRegistration.gpuHandle, + &textureId)) { + outRegistration = {}; + return false; + } + + outRegistration.texture.nativeHandle = (std::uintptr_t)textureId; + outRegistration.texture.width = texture != nullptr ? texture->GetWidth() : 0u; + outRegistration.texture.height = texture != nullptr ? texture->GetHeight() : 0u; + outRegistration.texture.kind = ::XCEngine::UI::UITextureHandleKind::ImGuiDescriptor; + return outRegistration.IsValid(); } - void FreeTextureDescriptor( - D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) override { - m_backend.FreeTextureDescriptor(cpuHandle, gpuHandle); + void FreeTextureDescriptor(const UITextureRegistration& registration) override { + m_backend.FreeTextureDescriptor(registration.cpuHandle, registration.gpuHandle); } private: diff --git a/new_editor/src/XCUIBackend/ImGuiWindowUICompositor.h b/new_editor/src/XCUIBackend/ImGuiWindowUICompositor.h index d89fdec9..47f66f37 100644 --- a/new_editor/src/XCUIBackend/ImGuiWindowUICompositor.h +++ b/new_editor/src/XCUIBackend/ImGuiWindowUICompositor.h @@ -60,23 +60,17 @@ public: bool CreateTextureDescriptor( ::XCEngine::RHI::RHIDevice* device, ::XCEngine::RHI::RHITexture* texture, - D3D12_CPU_DESCRIPTOR_HANDLE* outCpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE* outGpuHandle, - ImTextureID* outTextureId) override { + UITextureRegistration& outRegistration) override { return m_hostCompositor != nullptr && m_hostCompositor->CreateTextureDescriptor( device, texture, - outCpuHandle, - outGpuHandle, - outTextureId); + outRegistration); } - void FreeTextureDescriptor( - D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle, - D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) override { + void FreeTextureDescriptor(const UITextureRegistration& registration) override { if (m_hostCompositor != nullptr) { - m_hostCompositor->FreeTextureDescriptor(cpuHandle, gpuHandle); + m_hostCompositor->FreeTextureDescriptor(registration); } } diff --git a/new_editor/src/XCUIBackend/UITextureRegistration.h b/new_editor/src/XCUIBackend/UITextureRegistration.h new file mode 100644 index 00000000..392f285c --- /dev/null +++ b/new_editor/src/XCUIBackend/UITextureRegistration.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include + +namespace XCEngine { +namespace Editor { +namespace XCUIBackend { + +struct UITextureRegistration { + D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = {}; + D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = {}; + ::XCEngine::UI::UITextureHandle texture = {}; + + bool IsValid() const { + return cpuHandle.ptr != 0u && gpuHandle.ptr != 0u && texture.IsValid(); + } +}; + +} // namespace XCUIBackend +} // namespace Editor +} // namespace XCEngine