Refactor new editor boundaries and test ownership

This commit is contained in:
2026-04-19 15:52:28 +08:00
parent dc13b56cf3
commit 93f06e84ed
279 changed files with 6349 additions and 3238 deletions

View File

@@ -25,11 +25,21 @@ bool D3D12WindowRenderer::Initialize(HWND hwnd, int width, int height) {
return false;
}
auto* device = m_hostDevice.GetRHIDevice();
if (device == nullptr ||
!m_viewportTextureAllocator.Initialize(*device)) {
m_lastError = "Failed to initialize the viewport texture allocator.";
Shutdown();
return false;
}
m_lastError.clear();
return true;
}
void D3D12WindowRenderer::Shutdown() {
m_viewportTextureCpuHandles.clear();
m_viewportTextureAllocator.Shutdown();
m_presenter.Shutdown();
m_hostDevice.Shutdown();
m_activeBackBufferIndex = 0u;
@@ -132,6 +142,56 @@ RHIDevice* D3D12WindowRenderer::GetRHIDevice() const {
return m_hostDevice.GetRHIDevice();
}
bool D3D12WindowRenderer::CreateViewportTextureHandle(
::XCEngine::RHI::RHITexture& texture,
std::uint32_t width,
std::uint32_t height,
::XCEngine::UI::UITextureHandle& outTexture) {
outTexture = {};
if (width == 0u ||
height == 0u ||
!m_viewportTextureAllocator.IsInitialized()) {
return false;
}
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = {};
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = {};
if (!m_viewportTextureAllocator.CreateTextureDescriptor(
&texture,
&cpuHandle,
&gpuHandle) ||
cpuHandle.ptr == 0u ||
gpuHandle.ptr == 0u) {
return false;
}
outTexture.nativeHandle = static_cast<std::uintptr_t>(gpuHandle.ptr);
outTexture.width = width;
outTexture.height = height;
outTexture.kind = ::XCEngine::UI::UITextureHandleKind::ShaderResourceView;
outTexture.resourceHandle = reinterpret_cast<std::uintptr_t>(&texture);
m_viewportTextureCpuHandles[outTexture.nativeHandle] = cpuHandle;
return true;
}
void D3D12WindowRenderer::ReleaseViewportTextureHandle(
::XCEngine::UI::UITextureHandle& texture) {
if (!texture.IsValid()) {
texture = {};
return;
}
const auto found = m_viewportTextureCpuHandles.find(texture.nativeHandle);
if (found != m_viewportTextureCpuHandles.end()) {
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = {};
gpuHandle.ptr = static_cast<UINT64>(texture.nativeHandle);
m_viewportTextureAllocator.Free(found->second, gpuHandle);
m_viewportTextureCpuHandles.erase(found);
}
texture = {};
}
RHISwapChain* D3D12WindowRenderer::GetSwapChain() const {
return m_presenter.GetSwapChain();
}