Unified logging: Replace LogSystem with EditorConsoleSink

- Created EditorConsoleSink (implements ILogSink interface)
- EditorConsoleSink stores logs in memory buffer (max 1000 entries)
- Added to Debug::Logger in Application::Initialize()
- ConsolePanel now reads from EditorConsoleSink via static GetInstance()
- Removed separate LogSystem singleton
- Removed editor/src/Core/LogEntry.h (no longer needed)

Now Editor and Engine share the same Debug::Logger, with ConsolePanel
displaying logs via EditorConsoleSink.
This commit is contained in:
2026-03-25 16:13:02 +08:00
parent b08f682e5c
commit 16e2065c6c
28 changed files with 355 additions and 121 deletions

View File

@@ -1,5 +1,6 @@
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
#include "XCEngine/RHI/D3D12/D3D12Enums.h"
#include <stdio.h>
namespace XCEngine {
namespace RHI {
@@ -17,6 +18,11 @@ bool D3D12CommandAllocator::Initialize(ID3D12Device* device, CommandQueueType ty
HRESULT hResult = device->CreateCommandAllocator(
ToD3D12(type),
IID_PPV_ARGS(&m_commandAllocator));
if (FAILED(hResult)) {
char buf[256];
sprintf(buf, "[D3D12CommandAllocator] CreateCommandAllocator failed: hr=0x%08X\n", hResult);
OutputDebugStringA(buf);
}
return SUCCEEDED(hResult);
}

View File

@@ -30,6 +30,10 @@ bool D3D12CommandList::Initialize(ID3D12Device* device, CommandQueueType type, I
m_commandAllocator = allocator;
m_device = device;
char buf[512];
sprintf(buf, "[D3D12CommandList::Initialize] device=%p, allocator=%p, type=%d\n", device, allocator, (int)type);
OutputDebugStringA(buf);
HRESULT hResult = device->CreateCommandList(
0,
listType,
@@ -39,6 +43,8 @@ bool D3D12CommandList::Initialize(ID3D12Device* device, CommandQueueType type, I
);
if (FAILED(hResult)) {
sprintf(buf, "[D3D12CommandList::Initialize] CreateCommandList failed: hr=0x%08X\n", hResult);
OutputDebugStringA(buf);
return false;
}

View File

@@ -18,6 +18,7 @@
#include "XCEngine/RHI/D3D12/D3D12RenderPass.h"
#include "XCEngine/RHI/D3D12/D3D12Framebuffer.h"
#include <stdio.h>
#include <memory>
#ifdef _DEBUG
#include <dxgidebug.h>
@@ -407,18 +408,32 @@ RHISwapChain* D3D12Device::CreateSwapChain(const SwapChainDesc& desc) {
}
RHICommandList* D3D12Device::CreateCommandList(const CommandListDesc& desc) {
auto* allocator = new D3D12CommandAllocator();
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateCommandList] Start, m_device=%p, m_initialized=%d\n", m_device.Get(), m_initialized); fclose(f); }
if (!m_device) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateCommandList] Error: m_device is null\n"); fclose(f2); }
return nullptr;
}
auto allocator = std::make_unique<D3D12CommandAllocator>();
if (!allocator->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType))) {
delete allocator;
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateCommandList] Error: allocator Initialize failed\n"); fclose(f2); }
return nullptr;
}
auto* cmdList = new D3D12CommandList();
if (!cmdList->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType), allocator->GetCommandAllocator())) {
delete allocator;
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateCommandList] Error: cmdList Initialize failed\n"); fclose(f2); }
delete cmdList;
return nullptr;
}
FILE* f3 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f3) { fprintf(f3, "[CreateCommandList] Success\n"); fclose(f3); }
return cmdList;
}
@@ -453,27 +468,42 @@ RHIPipelineLayout* D3D12Device::CreatePipelineLayout(const RHIPipelineLayoutDesc
}
RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const ResourceViewDesc& desc) {
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateRenderTargetView] Start\n"); fclose(f); }
if (!texture) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateRenderTargetView] Error: texture is null\n"); fclose(f2); }
return nullptr;
}
auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
if (!resource) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateRenderTargetView] Error: resource is null\n"); fclose(f2); }
delete view;
return nullptr;
}
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = {};
rtvDesc.Format = static_cast<DXGI_FORMAT>(desc.format);
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
DescriptorHeapDesc heapDesc = {};
heapDesc.descriptorCount = 1;
heapDesc.heapType = static_cast<uint32_t>(DescriptorHeapType::RTV);
heapDesc.shaderVisible = false;
auto* heapPool = CreateDescriptorHeap(heapDesc);
auto* heap = static_cast<D3D12DescriptorHeap*>(heapPool);
if (heap == nullptr) {
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::RTV, 1, false)) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateRenderTargetView] Error: heap Initialize failed\n"); fclose(f2); }
delete view;
return nullptr;
}
view->InitializeAsRenderTarget(m_device.Get(), resource, &rtvDesc, heap, 0);
view->InitializeAsRenderTarget(m_device.Get(), resource, &rtvDesc, heap.get(), 0);
view->SetOwnedHeap(std::move(heap));
FILE* f3 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f3) { fprintf(f3, "[CreateRenderTargetView] Success\n"); fclose(f3); }
return view;
}
@@ -486,19 +516,14 @@ RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const
dsvDesc.Format = static_cast<DXGI_FORMAT>(desc.format);
dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
DescriptorHeapDesc heapDesc = {};
heapDesc.descriptorCount = 1;
heapDesc.heapType = static_cast<uint32_t>(DescriptorHeapType::DSV);
heapDesc.shaderVisible = false;
auto* heapPool = CreateDescriptorHeap(heapDesc);
auto* heap = static_cast<D3D12DescriptorHeap*>(heapPool);
if (heap == nullptr) {
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::DSV, 1, false)) {
delete view;
return nullptr;
}
view->InitializeAsDepthStencil(m_device.Get(), resource, &dsvDesc, heap, 0);
view->InitializeAsDepthStencil(m_device.Get(), resource, &dsvDesc, heap.get(), 0);
view->SetOwnedHeap(std::move(heap));
return view;
}
@@ -514,14 +539,14 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
DescriptorHeapDesc heapDesc = {};
heapDesc.descriptorCount = 1;
heapDesc.heapType = static_cast<uint32_t>(DescriptorHeapType::CBV_SRV_UAV);
heapDesc.shaderVisible = true;
auto* heapPool = CreateDescriptorHeap(heapDesc);
auto* heap = static_cast<D3D12DescriptorHeap*>(heapPool);
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, true)) {
delete view;
return nullptr;
}
view->InitializeAsShaderResource(m_device.Get(), resource, &srvDesc, heap, 0);
view->InitializeAsShaderResource(m_device.Get(), resource, &srvDesc, heap.get(), 0);
view->SetOwnedHeap(std::move(heap));
return view;
}
@@ -534,14 +559,14 @@ RHIResourceView* D3D12Device::CreateUnorderedAccessView(RHITexture* texture, con
uavDesc.Format = static_cast<DXGI_FORMAT>(desc.format);
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
DescriptorHeapDesc heapDesc = {};
heapDesc.descriptorCount = 1;
heapDesc.heapType = static_cast<uint32_t>(DescriptorHeapType::CBV_SRV_UAV);
heapDesc.shaderVisible = true;
auto* heapPool = CreateDescriptorHeap(heapDesc);
auto* heap = static_cast<D3D12DescriptorHeap*>(heapPool);
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, true)) {
delete view;
return nullptr;
}
view->InitializeAsUnorderedAccess(m_device.Get(), resource, &uavDesc, heap, 0);
view->InitializeAsUnorderedAccess(m_device.Get(), resource, &uavDesc, heap.get(), 0);
view->SetOwnedHeap(std::move(heap));
return view;
}

View File

@@ -11,7 +11,8 @@ D3D12ResourceView::D3D12ResourceView()
, m_handle({0})
, m_resource(nullptr)
, m_heap(nullptr)
, m_slotIndex(0) {
, m_slotIndex(0)
, m_ownedHeap(nullptr) {
}
D3D12ResourceView::~D3D12ResourceView() {
@@ -21,6 +22,10 @@ D3D12ResourceView::~D3D12ResourceView() {
void D3D12ResourceView::Shutdown() {
m_handle = {};
m_resource = nullptr;
if (m_ownedHeap) {
m_ownedHeap->Shutdown();
m_ownedHeap.reset();
}
m_heap = nullptr;
m_slotIndex = 0;
}
@@ -151,5 +156,10 @@ D3D12_UNORDERED_ACCESS_VIEW_DESC D3D12ResourceView::CreateUnorderedAccessDesc(Fo
return desc;
}
void D3D12ResourceView::SetOwnedHeap(std::unique_ptr<D3D12DescriptorHeap> heap) {
m_ownedHeap = std::move(heap);
m_heap = m_ownedHeap.get();
}
} // namespace RHI
} // namespace XCEngine