RHI: Implement CreateRenderPass/CreateFramebuffer in D3D12 and OpenGL backends

This commit is contained in:
2026-03-25 13:03:02 +08:00
parent 2313124cc5
commit 41cea4d1a2
4 changed files with 75 additions and 3 deletions

View File

@@ -15,6 +15,8 @@
#include "XCEngine/RHI/D3D12/D3D12SwapChain.h"
#include "XCEngine/RHI/D3D12/D3D12Shader.h"
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
#include "XCEngine/RHI/D3D12/D3D12RenderPass.h"
#include "XCEngine/RHI/D3D12/D3D12Framebuffer.h"
#include <stdio.h>
#ifdef _DEBUG
@@ -283,6 +285,13 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
d3d12Desc.SampleDesc.Count = desc.sampleCount > 0 ? desc.sampleCount : 1;
d3d12Desc.SampleDesc.Quality = desc.sampleQuality;
d3d12Desc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(desc.flags);
Format format = static_cast<Format>(desc.format);
if (format == Format::D24_UNorm_S8_UInt || format == Format::D32_Float ||
format == Format::D16_UNorm) {
d3d12Desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
}
d3d12Desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
if (texture->Initialize(m_device.Get(), d3d12Desc)) {
return texture;
@@ -344,6 +353,32 @@ RHIDescriptorPool* D3D12Device::CreateDescriptorPool(const DescriptorPoolDesc& d
return nullptr;
}
RHIRenderPass* D3D12Device::CreateRenderPass(
uint32_t colorAttachmentCount,
const AttachmentDesc* colorAttachments,
const AttachmentDesc* depthStencilAttachment) {
auto* renderPass = new D3D12RenderPass();
if (!renderPass->Initialize(colorAttachmentCount, colorAttachments, depthStencilAttachment)) {
delete renderPass;
return nullptr;
}
return renderPass;
}
RHIFramebuffer* D3D12Device::CreateFramebuffer(
class RHIRenderPass* renderPass,
uint32_t width, uint32_t height,
uint32_t colorAttachmentCount,
RHIResourceView** colorAttachments,
RHIResourceView* depthStencilAttachment) {
auto* framebuffer = new D3D12Framebuffer();
if (!framebuffer->Initialize(renderPass, width, height, colorAttachmentCount, colorAttachments, depthStencilAttachment)) {
delete framebuffer;
return nullptr;
}
return framebuffer;
}
RHIDescriptorSet* D3D12Device::CreateDescriptorSet(RHIDescriptorPool* pool, const DescriptorSetLayoutDesc& layout) {
if (pool == nullptr) {
return nullptr;
@@ -433,6 +468,11 @@ RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const
auto* heapPool = CreateDescriptorHeap(heapDesc);
auto* heap = static_cast<D3D12DescriptorHeap*>(heapPool);
if (heap == nullptr) {
delete view;
return nullptr;
}
view->InitializeAsRenderTarget(m_device.Get(), resource, &rtvDesc, heap, 0);
return view;
}
@@ -453,6 +493,11 @@ RHIResourceView* D3D12Device::CreateDepthStencilView(RHITexture* texture, const
auto* heapPool = CreateDescriptorHeap(heapDesc);
auto* heap = static_cast<D3D12DescriptorHeap*>(heapPool);
if (heap == nullptr) {
delete view;
return nullptr;
}
view->InitializeAsDepthStencil(m_device.Get(), resource, &dsvDesc, heap, 0);
return view;
}