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