Refactor RHI ResourceView abstraction layer for unified cross-platform interface

- 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
This commit is contained in:
2026-03-24 03:49:13 +08:00
parent 86b6d6b042
commit 0a3fe842b9
32 changed files with 1288 additions and 233 deletions

View File

@@ -12,11 +12,7 @@
#include "XCEngine/RHI/D3D12/D3D12Buffer.h"
#include "XCEngine/RHI/D3D12/D3D12SwapChain.h"
#include "XCEngine/RHI/D3D12/D3D12Shader.h"
#include "XCEngine/RHI/D3D12/D3D12RenderTargetView.h"
#include "XCEngine/RHI/D3D12/D3D12DepthStencilView.h"
#include "XCEngine/RHI/D3D12/D3D12ShaderResourceView.h"
#include "XCEngine/RHI/D3D12/D3D12UnorderedAccessView.h"
#include "XCEngine/RHI/D3D12/D3D12ConstantBufferView.h"
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
#include <stdio.h>
#ifdef _DEBUG
@@ -376,6 +372,109 @@ RHIPipelineState* D3D12Device::CreatePipelineState(const PipelineStateDesc& desc
return nullptr;
}
RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const ResourceViewDesc& desc) {
auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
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);
view->InitializeAsRenderTarget(m_device.Get(), resource, &rtvDesc, heap, 0);
return view;
}
RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const ResourceViewDesc& desc) {
auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
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);
view->InitializeAsDepthStencil(m_device.Get(), resource, &dsvDesc, heap, 0);
return view;
}
RHIResourceView* D3D12Device::CreateShaderResourceView(RHITexture* texture, const ResourceViewDesc& desc) {
auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = static_cast<DXGI_FORMAT>(desc.format);
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = desc.mipLevel > 0 ? desc.mipLevel : 1;
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);
view->InitializeAsShaderResource(m_device.Get(), resource, &srvDesc, heap, 0);
return view;
}
RHIResourceView* D3D12Device::CreateUnorderedAccessView(RHITexture* texture, const ResourceViewDesc& desc) {
auto* view = new D3D12ResourceView();
auto* d3d12Texture = static_cast<D3D12Texture*>(texture);
ID3D12Resource* resource = d3d12Texture->GetResource();
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
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);
view->InitializeAsUnorderedAccess(m_device.Get(), resource, &uavDesc, heap, 0);
return view;
}
D3D12DescriptorHeap* D3D12Device::CreateDescriptorHeap(const DescriptorHeapDesc& desc) {
auto* heap = new D3D12DescriptorHeap();
if (!heap->Initialize(m_device.Get(),
static_cast<DescriptorHeapType>(desc.heapType),
desc.descriptorCount,
desc.shaderVisible)) {
delete heap;
return nullptr;
}
return heap;
}
D3D12QueryHeap* D3D12Device::CreateQueryHeap(const QueryHeapDesc& desc) {
return nullptr;
}
D3D12RootSignature* D3D12Device::CreateRootSignature(const RootSignatureDesc& desc) {
return nullptr;
}
D3D12CommandQueue* D3D12Device::CreateCommandQueueImpl(const CommandQueueDesc& desc) {
return nullptr;
}