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

@@ -273,12 +273,6 @@ RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& 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();
D3D12_RESOURCE_DESC d3d12Desc = {};
@@ -302,24 +296,14 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
}
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)) {
FILE* f = fopen("D:\\Xuanchi\\Main\\XCEngine\\debug_rhi.log", "a");
if (f) { fprintf(f, "[CreateTexture] Initialize succeeded\n"); fclose(f); }
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;
return nullptr;
}
RHIShader* D3D12Device::CompileShader(const ShaderCompileDesc& desc) {
RHIShader* D3D12Device::CreateShader(const ShaderCompileDesc& desc) {
auto* shader = new D3D12Shader();
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());
@@ -426,32 +410,21 @@ RHISwapChain* D3D12Device::CreateSwapChain(const SwapChainDesc& 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) {
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))) {
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())) {
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;
}
@@ -486,12 +459,7 @@ 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;
}
@@ -500,8 +468,6 @@ RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const
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;
}
@@ -510,39 +476,19 @@ RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const
rtvDesc.Format = ToD3D12(static_cast<Format>(desc.format));
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>();
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;
}
{
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->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;
}
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* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
@@ -563,9 +509,6 @@ RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const
}
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* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
@@ -579,8 +522,6 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
auto heap = std::make_unique<D3D12DescriptorHeap>();
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;
return nullptr;
}
@@ -588,8 +529,6 @@ RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, cons
view->InitializeAsShaderResource(m_device.Get(), resource, &srvDesc, heap.get(), 0);
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;
}