refactor: Clean up D3D12 debug logging and rename CompileShader

- Remove debug OutputDebugStringA and file logging from D3D12Device
- Rename CompileShader to CreateShader for API consistency
This commit is contained in:
2026-03-25 19:01:47 +08:00
parent 712e975610
commit 5ade399df2
6 changed files with 3 additions and 79 deletions

View File

@@ -68,7 +68,7 @@ public:
RHISwapChain* CreateSwapChain(const SwapChainDesc& desc) override; RHISwapChain* CreateSwapChain(const SwapChainDesc& desc) override;
RHICommandList* CreateCommandList(const CommandListDesc& desc) override; RHICommandList* CreateCommandList(const CommandListDesc& desc) override;
RHICommandQueue* CreateCommandQueue(const CommandQueueDesc& desc) override; RHICommandQueue* CreateCommandQueue(const CommandQueueDesc& desc) override;
RHIShader* CompileShader(const ShaderCompileDesc& desc) override; RHIShader* CreateShader(const ShaderCompileDesc& desc) override;
RHIPipelineState* CreatePipelineState(const GraphicsPipelineDesc& desc) override; RHIPipelineState* CreatePipelineState(const GraphicsPipelineDesc& desc) override;
RHIPipelineLayout* CreatePipelineLayout(const RHIPipelineLayoutDesc& desc) override; RHIPipelineLayout* CreatePipelineLayout(const RHIPipelineLayoutDesc& desc) override;
RHIFence* CreateFence(const FenceDesc& desc) override; RHIFence* CreateFence(const FenceDesc& desc) override;

View File

@@ -27,6 +27,7 @@ public:
RHITexture* GetCurrentBackBuffer() override; RHITexture* GetCurrentBackBuffer() override;
D3D12Texture& GetBackBuffer(uint32_t index); D3D12Texture& GetBackBuffer(uint32_t index);
const D3D12Texture& GetBackBuffer(uint32_t index) const; const D3D12Texture& GetBackBuffer(uint32_t index) const;
ID3D12CommandQueue* GetNativeCommandQueue() const { return m_commandQueue.Get(); }
void Present(uint32_t syncInterval = 1, uint32_t flags = 0) override; void Present(uint32_t syncInterval = 1, uint32_t flags = 0) override;
void Resize(uint32_t width, uint32_t height) override; void Resize(uint32_t width, uint32_t height) override;
void* GetNativeHandle() override; void* GetNativeHandle() override;

View File

@@ -1,6 +1,5 @@
#include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h" #include "XCEngine/RHI/D3D12/D3D12CommandAllocator.h"
#include "XCEngine/RHI/D3D12/D3D12Enums.h" #include "XCEngine/RHI/D3D12/D3D12Enums.h"
#include <stdio.h>
namespace XCEngine { namespace XCEngine {
namespace RHI { namespace RHI {
@@ -18,14 +17,6 @@ bool D3D12CommandAllocator::Initialize(ID3D12Device* device, CommandQueueType ty
HRESULT hResult = device->CreateCommandAllocator( HRESULT hResult = device->CreateCommandAllocator(
ToD3D12(type), ToD3D12(type),
IID_PPV_ARGS(&m_commandAllocator)); IID_PPV_ARGS(&m_commandAllocator));
if (FAILED(hResult)) {
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[D3D12CommandAllocator] CreateCommandAllocator failed: hr=0x%08X\n", hResult); fclose(f); }
if (hResult == DXGI_ERROR_DEVICE_REMOVED) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[D3D12CommandAllocator] Device removed reason: %d\n", device->GetDeviceRemovedReason()); fclose(f2); }
}
}
return SUCCEEDED(hResult); return SUCCEEDED(hResult);
} }

View File

@@ -273,12 +273,6 @@ RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& desc) {
} }
RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) { RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
OutputDebugStringA("[CreateTexture] Start\n");
{
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateTexture] Start, m_device=%p\n", m_device.Get()); fclose(f); }
}
auto* texture = new D3D12Texture(); auto* texture = new D3D12Texture();
D3D12_RESOURCE_DESC d3d12Desc = {}; D3D12_RESOURCE_DESC d3d12Desc = {};
@@ -302,24 +296,14 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
} }
d3d12Desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; d3d12Desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
{
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateTexture] Calling Initialize, device=%p, format=%d, flags=0x%X\n", m_device.Get(), (int)d3d12Desc.Format, d3d12Desc.Flags); fclose(f); }
}
if (texture->Initialize(m_device.Get(), d3d12Desc)) { if (texture->Initialize(m_device.Get(), d3d12Desc)) {
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateTexture] Initialize succeeded\n"); fclose(f); }
return texture; return texture;
} }
{
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateTexture] Initialize FAILED\n"); fclose(f); }
}
delete texture; delete texture;
return nullptr; return nullptr;
} }
RHIShader* D3D12Device::CompileShader(const ShaderCompileDesc& desc) { RHIShader* D3D12Device::CreateShader(const ShaderCompileDesc& desc) {
auto* shader = new D3D12Shader(); auto* shader = new D3D12Shader();
const char* entryPoint = desc.entryPoint.empty() ? nullptr : reinterpret_cast<const char*>(desc.entryPoint.c_str()); const char* entryPoint = desc.entryPoint.empty() ? nullptr : reinterpret_cast<const char*>(desc.entryPoint.c_str());
const char* profile = desc.profile.empty() ? nullptr : reinterpret_cast<const char*>(desc.profile.c_str()); const char* profile = desc.profile.empty() ? nullptr : reinterpret_cast<const char*>(desc.profile.c_str());
@@ -426,32 +410,21 @@ RHISwapChain* D3D12Device::CreateSwapChain(const SwapChainDesc& desc) {
} }
RHICommandList* D3D12Device::CreateCommandList(const CommandListDesc& desc) { RHICommandList* D3D12Device::CreateCommandList(const CommandListDesc& desc) {
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) { 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; return nullptr;
} }
auto allocator = std::make_unique<D3D12CommandAllocator>(); auto allocator = std::make_unique<D3D12CommandAllocator>();
if (!allocator->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType))) { if (!allocator->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType))) {
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; return nullptr;
} }
auto* cmdList = new D3D12CommandList(); auto* cmdList = new D3D12CommandList();
if (!cmdList->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType), allocator->GetCommandAllocator())) { if (!cmdList->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType), allocator->GetCommandAllocator())) {
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; delete cmdList;
return nullptr; return nullptr;
} }
FILE* f3 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f3) { fprintf(f3, "[CreateCommandList] Success\n"); fclose(f3); }
return cmdList; return cmdList;
} }
@@ -486,12 +459,7 @@ RHIPipelineLayout* D3D12Device::CreatePipelineLayout(const RHIPipelineLayoutDesc
} }
RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const ResourceViewDesc& desc) { 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) { 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; return nullptr;
} }
@@ -500,8 +468,6 @@ RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const
ID3D12Resource* resource = d3d12Texture->GetResource(); ID3D12Resource* resource = d3d12Texture->GetResource();
if (!resource) { 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; delete view;
return nullptr; return nullptr;
} }
@@ -510,39 +476,19 @@ RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const
rtvDesc.Format = ToD3D12(static_cast<Format>(desc.format)); rtvDesc.Format = ToD3D12(static_cast<Format>(desc.format));
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
{
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateRenderTargetView] Creating RTV heap...\n"); fclose(f2); }
}
auto heap = std::make_unique<D3D12DescriptorHeap>(); auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::RTV, 1, false)) { 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; delete view;
return nullptr; return nullptr;
} }
{
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateRenderTargetView] RTV heap created, calling CreateRenderTargetView...\n"); fclose(f2); }
}
view->InitializeAsRenderTarget(m_device.Get(), resource, &rtvDesc, heap.get(), 0); view->InitializeAsRenderTarget(m_device.Get(), resource, &rtvDesc, heap.get(), 0);
view->SetOwnedHeap(std::move(heap)); view->SetOwnedHeap(std::move(heap));
{
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateRenderTargetView] Success\n"); fclose(f2); }
}
return view; return view;
} }
RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const ResourceViewDesc& desc) { RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const ResourceViewDesc& desc) {
{
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateDepthStencilView] Start, desc.format=%d\n", desc.format); fclose(f); }
}
auto* view = new D3D12ResourceView(); auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture); auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource(); ID3D12Resource* resource = d3d12Texture->GetResource();
@@ -563,9 +509,6 @@ RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const
} }
RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, const ResourceViewDesc& desc) { RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, const ResourceViewDesc& desc) {
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateShaderResourceView] Start\n"); fclose(f); }
auto* view = new D3D12ResourceView(); auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture); auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource(); ID3D12Resource* resource = d3d12Texture->GetResource();
@@ -579,8 +522,6 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
auto heap = std::make_unique<D3D12DescriptorHeap>(); auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, true)) { if (!heap->Initialize(m_device.Get(), DescriptorHeapType::CBV_SRV_UAV, 1, true)) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[CreateShaderResourceView] heap Initialize failed\n"); fclose(f2); }
delete view; delete view;
return nullptr; return nullptr;
} }
@@ -588,8 +529,6 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
view->InitializeAsShaderResource(m_device.Get(), resource, &srvDesc, heap.get(), 0); view->InitializeAsShaderResource(m_device.Get(), resource, &srvDesc, heap.get(), 0);
view->SetOwnedHeap(std::move(heap)); view->SetOwnedHeap(std::move(heap));
FILE* f3 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f3) { fprintf(f3, "[CreateShaderResourceView] Success\n"); fclose(f3); }
return view; return view;
} }

View File

@@ -151,7 +151,6 @@ bool D3D12Screenshot::CopyToReadbackAndSave(ID3D12Device* device,
cmdList->Close(); cmdList->Close();
ID3D12CommandList* ppCmdLists[] = { cmdList }; ID3D12CommandList* ppCmdLists[] = { cmdList };
commandQueue->ExecuteCommandLists(1, ppCmdLists); commandQueue->ExecuteCommandLists(1, ppCmdLists);
XCEngine::Debug::Logger::Get().Info(XCEngine::Debug::LogCategory::Rendering, "Screenshot: ExecuteCommandLists done, waiting for fence...");
HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); HANDLE fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
ID3D12Fence* fence = nullptr; ID3D12Fence* fence = nullptr;
@@ -164,7 +163,6 @@ bool D3D12Screenshot::CopyToReadbackAndSave(ID3D12Device* device,
CloseHandle(fenceEvent); CloseHandle(fenceEvent);
return false; return false;
} }
XCEngine::Debug::Logger::Get().Info(XCEngine::Debug::LogCategory::Rendering, "Screenshot: Fence created, waiting...");
{ {
UINT64 fenceValue = 1; UINT64 fenceValue = 1;
commandQueue->Signal(fence, fenceValue); commandQueue->Signal(fence, fenceValue);

View File

@@ -11,9 +11,6 @@ D3D12Texture::~D3D12Texture() {
} }
bool D3D12Texture::Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES initialState) { bool D3D12Texture::Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES initialState) {
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[D3D12Texture::Initialize] Start, device=%p\n", device); fclose(f); }
D3D12_HEAP_PROPERTIES heapProperties = {}; D3D12_HEAP_PROPERTIES heapProperties = {};
heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT; heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
@@ -33,8 +30,6 @@ bool D3D12Texture::Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& d
); );
if (FAILED(hResult)) { if (FAILED(hResult)) {
FILE* f2 = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f2) { fprintf(f2, "[D3D12Texture::Initialize] CreateCommittedResource failed: hr=0x%08X\n", hResult); fclose(f2); }
return false; return false;
} }