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:
@@ -18,13 +18,11 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12SwapChain.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Buffer.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Texture.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12RenderTargetView.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12DepthStencilView.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Shader.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12RootSignature.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12PipelineState.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Screenshot.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ShaderResourceView.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
||||
#include "XCEngine/Debug/Logger.h"
|
||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||
#include "XCEngine/Debug/FileLogSink.h"
|
||||
@@ -51,8 +49,8 @@ D3D12Texture gDepthStencil;
|
||||
D3D12DescriptorHeap gRTVHeap;
|
||||
D3D12DescriptorHeap gDSVHeap;
|
||||
D3D12DescriptorHeap gSRVHeap;
|
||||
D3D12RenderTargetView gRTVs[2];
|
||||
D3D12DepthStencilView gDSV;
|
||||
D3D12ResourceView gRTVs[2];
|
||||
D3D12ResourceView gDSV;
|
||||
|
||||
D3D12Shader gVertexShader;
|
||||
D3D12Shader gPixelShader;
|
||||
@@ -60,7 +58,7 @@ D3D12RootSignature gRootSignature;
|
||||
D3D12PipelineState gPipelineState;
|
||||
D3D12Buffer gVertexBuffer;
|
||||
D3D12Texture gDiffuseTexture;
|
||||
D3D12ShaderResourceView gDiffuseSRV;
|
||||
D3D12ResourceView gDiffuseSRV;
|
||||
|
||||
UINT gRTVDescriptorSize = 0;
|
||||
UINT gDSVDescriptorSize = 0;
|
||||
@@ -88,7 +86,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
bool LoadTexture(const char* filename, D3D12Texture& texture, D3D12ShaderResourceView& srv, ID3D12Device* device, D3D12DescriptorHeap& srvHeap, ID3D12GraphicsCommandList* commandList, D3D12CommandAllocator& allocator, D3D12CommandQueue& queue) {
|
||||
bool LoadTexture(const char* filename, D3D12Texture& texture, D3D12ResourceView& srv, ID3D12Device* device, D3D12DescriptorHeap& srvHeap, ID3D12GraphicsCommandList* commandList, D3D12CommandAllocator& allocator, D3D12CommandQueue& queue) {
|
||||
int width, height, channels;
|
||||
stbi_uc* pixels = stbi_load(filename, &width, &height, &channels, STBI_rgb_alpha);
|
||||
if (!pixels) {
|
||||
@@ -113,8 +111,8 @@ bool LoadTexture(const char* filename, D3D12Texture& texture, D3D12ShaderResourc
|
||||
texture.SetName(filename);
|
||||
|
||||
srvHeap.Initialize(device, DescriptorHeapType::CBV_SRV_UAV, 1, true);
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = D3D12ShaderResourceView::CreateDesc(Format::R8G8B8A8_UNorm, D3D12_SRV_DIMENSION_TEXTURE2D);
|
||||
srv.InitializeAt(device, texture.GetResource(), srvHeap.GetCPUDescriptorHandleForHeapStart(), &srvDesc);
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = D3D12ResourceView::CreateShaderResourceDesc(Format::R8G8B8A8_UNorm, D3D12_SRV_DIMENSION_TEXTURE2D);
|
||||
srv.InitializeAsShaderResource(device, texture.GetResource(), &srvDesc, &srvHeap, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -156,15 +154,12 @@ bool InitD3D12() {
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
D3D12Texture& backBuffer = gSwapChain.GetBackBuffer(i);
|
||||
CPUDescriptorHandle rtvCpuHandle = gRTVHeap.GetCPUDescriptorHandle(i);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = { rtvCpuHandle.ptr };
|
||||
gRTVs[i].InitializeAt(device, backBuffer.GetResource(), rtvHandle, nullptr);
|
||||
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = D3D12ResourceView::CreateRenderTargetDesc(Format::R8G8B8A8_UNorm, D3D12_RTV_DIMENSION_TEXTURE2D);
|
||||
gRTVs[i].InitializeAsRenderTarget(device, backBuffer.GetResource(), &rtvDesc, &gRTVHeap, i);
|
||||
}
|
||||
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = D3D12DepthStencilView::CreateDesc(Format::D24_UNorm_S8_UInt);
|
||||
CPUDescriptorHandle dsvCpuHandle = gDSVHeap.GetCPUDescriptorHandle(0);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = { dsvCpuHandle.ptr };
|
||||
gDSV.InitializeAt(device, gDepthStencil.GetResource(), dsvHandle, &dsvDesc);
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = D3D12ResourceView::CreateDepthStencilDesc(Format::D24_UNorm_S8_UInt, D3D12_DSV_DIMENSION_TEXTURE2D);
|
||||
gDSV.InitializeAsDepthStencil(device, gDepthStencil.GetResource(), &dsvDesc, &gDSVHeap, 0);
|
||||
|
||||
gCommandAllocator.Initialize(device, CommandQueueType::Direct);
|
||||
gCommandList.Initialize(device, CommandQueueType::Direct, gCommandAllocator.GetCommandAllocator());
|
||||
|
||||
Reference in New Issue
Block a user