RHI: Implement CreateRenderPass/CreateFramebuffer in D3D12 and OpenGL backends
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ void D3D12Framebuffer::Shutdown() {
|
||||
m_height = 0;
|
||||
}
|
||||
|
||||
bool D3D12Framebuffer::Initialize(D3D12RenderPass* renderPass, uint32_t width, uint32_t height,
|
||||
bool D3D12Framebuffer::Initialize(class RHIRenderPass* renderPass, uint32_t width, uint32_t height,
|
||||
uint32_t colorAttachmentCount, RHIResourceView** colorAttachments,
|
||||
RHIResourceView* depthStencilAttachment) {
|
||||
m_renderPass = renderPass;
|
||||
m_renderPass = static_cast<D3D12RenderPass*>(renderPass);
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ D3D12_RENDER_PASS_ENDING_ACCESS_TYPE D3D12RenderPass::GetEndingAccessType(uint32
|
||||
case StoreAction::Resolve:
|
||||
return D3D12_RENDER_PASS_ENDING_ACCESS_TYPE::D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE;
|
||||
case StoreAction::StoreAndResolve:
|
||||
return D3D12_RENDER_PASS_ENDING_ACCESS_TYPE::D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_STORE_AND_RESOLVE;
|
||||
return D3D12_RENDER_PASS_ENDING_ACCESS_TYPE::D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE;
|
||||
case StoreAction::Undefined:
|
||||
default:
|
||||
return D3D12_RENDER_PASS_ENDING_ACCESS_TYPE::D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLTextureUnitAllocator.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLUniformBufferManager.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLFramebuffer.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLRenderPass.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLResourceView.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorPool.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorSet.h"
|
||||
@@ -418,6 +419,32 @@ RHISampler* OpenGLDevice::CreateSampler(const SamplerDesc& desc) {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
RHIRenderPass* OpenGLDevice::CreateRenderPass(
|
||||
uint32_t colorAttachmentCount,
|
||||
const AttachmentDesc* colorAttachments,
|
||||
const AttachmentDesc* depthStencilAttachment) {
|
||||
auto* renderPass = new OpenGLRenderPass();
|
||||
if (!renderPass->Initialize(colorAttachmentCount, colorAttachments, depthStencilAttachment)) {
|
||||
delete renderPass;
|
||||
return nullptr;
|
||||
}
|
||||
return renderPass;
|
||||
}
|
||||
|
||||
RHIFramebuffer* OpenGLDevice::CreateFramebuffer(
|
||||
class RHIRenderPass* renderPass,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t colorAttachmentCount,
|
||||
RHIResourceView** colorAttachments,
|
||||
RHIResourceView* depthStencilAttachment) {
|
||||
auto* framebuffer = new OpenGLFramebuffer();
|
||||
if (!framebuffer->Initialize(renderPass, width, height, colorAttachmentCount, colorAttachments, depthStencilAttachment)) {
|
||||
delete framebuffer;
|
||||
return nullptr;
|
||||
}
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
RHIDescriptorPool* OpenGLDevice::CreateDescriptorPool(const DescriptorPoolDesc& desc) {
|
||||
auto* pool = new OpenGLDescriptorPool();
|
||||
if (pool->Initialize(desc)) {
|
||||
|
||||
Reference in New Issue
Block a user