Tighten XCUI compositor texture registration

This commit is contained in:
2026-04-05 06:43:51 +08:00
parent a1b98abfbb
commit edf434aa03
7 changed files with 54 additions and 41 deletions

View File

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

View File

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

View File

@@ -1,12 +1,11 @@
#pragma once
#include "Platform/D3D12WindowRenderer.h"
#include "XCUIBackend/UITextureRegistration.h"
#include <XCEngine/RHI/RHIDevice.h>
#include <XCEngine/RHI/RHITexture.h>
#include <imgui.h>
#include <functional>
#include <memory>
#include <windows.h>
@@ -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<IEditorHostCompositor> CreateImGuiHostCompositor();

View File

@@ -1,12 +1,11 @@
#pragma once
#include "Platform/D3D12WindowRenderer.h"
#include "XCUIBackend/UITextureRegistration.h"
#include <XCEngine/RHI/RHIDevice.h>
#include <XCEngine/RHI/RHITexture.h>
#include <imgui.h>
#include <functional>
#include <memory>
#include <windows.h>
@@ -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<IWindowUICompositor> CreateImGuiWindowUICompositor();

View File

@@ -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;
}
void FreeTextureDescriptor(
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle,
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle) override {
m_backend.FreeTextureDescriptor(cpuHandle, gpuHandle);
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(const UITextureRegistration& registration) override {
m_backend.FreeTextureDescriptor(registration.cpuHandle, registration.gpuHandle);
}
private:

View File

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

View File

@@ -0,0 +1,23 @@
#pragma once
#include <XCEngine/UI/Types.h>
#include <d3d12.h>
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