- Create unified RHIResourceView base interface with type-specific Initialize methods - Implement D3D12ResourceView with RTV/DSV/SRV/UAV/CBV support - Implement OpenGL ResourceView simulation layer using FBO, texture units, and UBO - Add OpenGLTextureUnitAllocator for managing texture unit bindings - Add OpenGLUniformBufferManager for UBO binding points - Add OpenGLFramebuffer for FBO management - Remove deprecated D3D12 view classes (RenderTargetView, DepthStencilView, etc.) - Fix ExecuteCommandLists type confusion bug by adding GetNativeHandle to RHICommandList - Fix test bug where Close() was called before ExecuteCommandLists - Update all integration tests to use new D3D12ResourceView class - All tests pass: 144 unit tests + 8 integration tests
143 lines
5.1 KiB
C++
143 lines
5.1 KiB
C++
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
|
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
D3D12ResourceView::D3D12ResourceView()
|
|
: m_viewType(ResourceViewType::ShaderResource)
|
|
, m_handle({0})
|
|
, m_resource(nullptr)
|
|
, m_heap(nullptr)
|
|
, m_slotIndex(0) {
|
|
}
|
|
|
|
D3D12ResourceView::~D3D12ResourceView() {
|
|
Shutdown();
|
|
}
|
|
|
|
void D3D12ResourceView::Shutdown() {
|
|
m_handle = {};
|
|
m_resource = nullptr;
|
|
m_heap = nullptr;
|
|
m_slotIndex = 0;
|
|
}
|
|
|
|
void* D3D12ResourceView::GetNativeHandle() {
|
|
return this;
|
|
}
|
|
|
|
bool D3D12ResourceView::IsValid() const {
|
|
return m_handle.ptr != 0 && m_resource != nullptr;
|
|
}
|
|
|
|
void D3D12ResourceView::InitializeAsRenderTarget(ID3D12Device* device, ID3D12Resource* resource,
|
|
const D3D12_RENDER_TARGET_VIEW_DESC* desc,
|
|
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
|
m_viewType = ResourceViewType::RenderTarget;
|
|
m_resource = resource;
|
|
m_heap = heap;
|
|
m_slotIndex = slotIndex;
|
|
|
|
m_handle = heap->GetCPUDescriptorHandleForHeapStart();
|
|
m_handle.ptr += slotIndex * heap->GetDescriptorSize();
|
|
device->CreateRenderTargetView(resource, desc, m_handle);
|
|
}
|
|
|
|
void D3D12ResourceView::InitializeAsDepthStencil(ID3D12Device* device, ID3D12Resource* resource,
|
|
const D3D12_DEPTH_STENCIL_VIEW_DESC* desc,
|
|
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
|
m_viewType = ResourceViewType::DepthStencil;
|
|
m_resource = resource;
|
|
m_heap = heap;
|
|
m_slotIndex = slotIndex;
|
|
|
|
m_handle = heap->GetCPUDescriptorHandleForHeapStart();
|
|
m_handle.ptr += slotIndex * heap->GetDescriptorSize();
|
|
device->CreateDepthStencilView(resource, desc, m_handle);
|
|
}
|
|
|
|
void D3D12ResourceView::InitializeAsShaderResource(ID3D12Device* device, ID3D12Resource* resource,
|
|
const D3D12_SHADER_RESOURCE_VIEW_DESC* desc,
|
|
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
|
m_viewType = ResourceViewType::ShaderResource;
|
|
m_resource = resource;
|
|
m_heap = heap;
|
|
m_slotIndex = slotIndex;
|
|
|
|
m_handle = heap->GetCPUDescriptorHandleForHeapStart();
|
|
m_handle.ptr += slotIndex * heap->GetDescriptorSize();
|
|
device->CreateShaderResourceView(resource, desc, m_handle);
|
|
}
|
|
|
|
void D3D12ResourceView::InitializeAsUnorderedAccess(ID3D12Device* device, ID3D12Resource* resource,
|
|
const D3D12_UNORDERED_ACCESS_VIEW_DESC* desc,
|
|
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
|
m_viewType = ResourceViewType::UnorderedAccess;
|
|
m_resource = resource;
|
|
m_heap = heap;
|
|
m_slotIndex = slotIndex;
|
|
|
|
m_handle = heap->GetCPUDescriptorHandleForHeapStart();
|
|
m_handle.ptr += slotIndex * heap->GetDescriptorSize();
|
|
device->CreateUnorderedAccessView(resource, nullptr, desc, m_handle);
|
|
}
|
|
|
|
void D3D12ResourceView::InitializeAsConstantBuffer(ID3D12Device* device, ID3D12Resource* resource,
|
|
const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc,
|
|
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
|
m_viewType = ResourceViewType::ConstantBuffer;
|
|
m_resource = resource;
|
|
m_heap = heap;
|
|
m_slotIndex = slotIndex;
|
|
|
|
m_handle = heap->GetCPUDescriptorHandleForHeapStart();
|
|
m_handle.ptr += slotIndex * heap->GetDescriptorSize();
|
|
device->CreateConstantBufferView(desc, m_handle);
|
|
}
|
|
|
|
GPUDescriptorHandle D3D12ResourceView::GetGPUHandle() const {
|
|
if (m_heap) {
|
|
return m_heap->GetGPUDescriptorHandle(m_slotIndex);
|
|
}
|
|
return {};
|
|
}
|
|
|
|
D3D12_RENDER_TARGET_VIEW_DESC D3D12ResourceView::CreateRenderTargetDesc(Format format, D3D12_RTV_DIMENSION dimension) {
|
|
D3D12_RENDER_TARGET_VIEW_DESC desc = {};
|
|
desc.Format = ToD3D12(format);
|
|
desc.ViewDimension = dimension;
|
|
return desc;
|
|
}
|
|
|
|
D3D12_DEPTH_STENCIL_VIEW_DESC D3D12ResourceView::CreateDepthStencilDesc(Format format, D3D12_DSV_DIMENSION dimension) {
|
|
D3D12_DEPTH_STENCIL_VIEW_DESC desc = {};
|
|
desc.Format = ToD3D12(format);
|
|
desc.ViewDimension = dimension;
|
|
return desc;
|
|
}
|
|
|
|
D3D12_SHADER_RESOURCE_VIEW_DESC D3D12ResourceView::CreateShaderResourceDesc(Format format, D3D12_SRV_DIMENSION dimension, uint32_t mipLevels) {
|
|
D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};
|
|
desc.Format = ToD3D12(format);
|
|
desc.ViewDimension = dimension;
|
|
if (mipLevels == 0) {
|
|
desc.Texture2D.MostDetailedMip = 0;
|
|
desc.Texture2D.MipLevels = 1;
|
|
} else {
|
|
desc.Texture2D.MostDetailedMip = 0;
|
|
desc.Texture2D.MipLevels = mipLevels;
|
|
}
|
|
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
|
return desc;
|
|
}
|
|
|
|
D3D12_UNORDERED_ACCESS_VIEW_DESC D3D12ResourceView::CreateUnorderedAccessDesc(Format format, D3D12_UAV_DIMENSION dimension) {
|
|
D3D12_UNORDERED_ACCESS_VIEW_DESC desc = {};
|
|
desc.Format = ToD3D12(format);
|
|
desc.ViewDimension = dimension;
|
|
return desc;
|
|
}
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|