Add pipeline layout support for graphics PSOs
This commit is contained in:
@@ -156,6 +156,7 @@ add_library(XCEngine STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/OpenGL/OpenGLResourceView.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/OpenGL/OpenGLDescriptorPool.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/OpenGL/OpenGLDescriptorSet.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/OpenGL/OpenGLPipelineLayout.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLBuffer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLTexture.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLSampler.cpp
|
||||
@@ -177,6 +178,7 @@ add_library(XCEngine STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLResourceView.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLDescriptorPool.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLDescriptorSet.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RHI/OpenGL/OpenGLPipelineLayout.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../tests/opengl/package/src/glad.c
|
||||
|
||||
# RHI Factory
|
||||
@@ -327,4 +329,4 @@ else()
|
||||
target_compile_options(XCEngine PRIVATE -Wall)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(XCEngine PRIVATE XCENGINE_SUPPORT_OPENGL)
|
||||
target_compile_definitions(XCEngine PRIVATE XCENGINE_SUPPORT_OPENGL)
|
||||
|
||||
25
engine/include/XCEngine/RHI/OpenGL/OpenGLPipelineLayout.h
Normal file
25
engine/include/XCEngine/RHI/OpenGL/OpenGLPipelineLayout.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "../RHIPipelineLayout.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class OpenGLPipelineLayout : public RHIPipelineLayout {
|
||||
public:
|
||||
OpenGLPipelineLayout() = default;
|
||||
~OpenGLPipelineLayout() override = default;
|
||||
|
||||
bool Initialize(const RHIPipelineLayoutDesc& desc) override;
|
||||
void Shutdown() override;
|
||||
|
||||
void* GetNativeHandle() override { return m_initialized ? this : nullptr; }
|
||||
const RHIPipelineLayoutDesc& GetDesc() const { return m_desc; }
|
||||
|
||||
private:
|
||||
RHIPipelineLayoutDesc m_desc = {};
|
||||
bool m_initialized = false;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
@@ -9,6 +9,8 @@
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class RHIPipelineLayout;
|
||||
|
||||
struct Viewport {
|
||||
float topLeftX;
|
||||
float topLeftY;
|
||||
@@ -310,6 +312,7 @@ struct GraphicsPipelineDesc {
|
||||
ShaderCompileDesc vertexShader;
|
||||
ShaderCompileDesc fragmentShader;
|
||||
ShaderCompileDesc geometryShader;
|
||||
RHIPipelineLayout* pipelineLayout = nullptr;
|
||||
InputLayoutDesc inputLayout;
|
||||
RasterizerDesc rasterizerState;
|
||||
BlendDesc blendState;
|
||||
|
||||
@@ -523,14 +523,19 @@ RHIPipelineState* D3D12Device::CreatePipelineState(const GraphicsPipelineDesc& d
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* rootSignature = CreateRootSignature({});
|
||||
if (rootSignature == nullptr) {
|
||||
delete pso;
|
||||
return nullptr;
|
||||
D3D12RootSignature* rootSignature = nullptr;
|
||||
if (desc.pipelineLayout != nullptr) {
|
||||
auto* pipelineLayout = static_cast<D3D12PipelineLayout*>(desc.pipelineLayout);
|
||||
pso->SetRootSignature(pipelineLayout->GetRootSignature());
|
||||
} else {
|
||||
rootSignature = CreateRootSignature({});
|
||||
if (rootSignature == nullptr) {
|
||||
delete pso;
|
||||
return nullptr;
|
||||
}
|
||||
pso->SetRootSignature(rootSignature->GetRootSignature());
|
||||
}
|
||||
|
||||
pso->SetRootSignature(rootSignature->GetRootSignature());
|
||||
|
||||
D3D12Shader vertexShader;
|
||||
D3D12Shader fragmentShader;
|
||||
D3D12Shader geometryShader;
|
||||
@@ -539,8 +544,10 @@ RHIPipelineState* D3D12Device::CreatePipelineState(const GraphicsPipelineDesc& d
|
||||
const bool geometryCompiled = !hasGeometryShader || CompileD3D12Shader(desc.geometryShader, geometryShader);
|
||||
|
||||
if (!vertexCompiled || !fragmentCompiled || !geometryCompiled) {
|
||||
rootSignature->Shutdown();
|
||||
delete rootSignature;
|
||||
if (rootSignature != nullptr) {
|
||||
rootSignature->Shutdown();
|
||||
delete rootSignature;
|
||||
}
|
||||
delete pso;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -551,8 +558,10 @@ RHIPipelineState* D3D12Device::CreatePipelineState(const GraphicsPipelineDesc& d
|
||||
hasGeometryShader ? geometryShader.GetD3D12Bytecode() : D3D12_SHADER_BYTECODE{});
|
||||
pso->EnsureValid();
|
||||
|
||||
rootSignature->Shutdown();
|
||||
delete rootSignature;
|
||||
if (rootSignature != nullptr) {
|
||||
rootSignature->Shutdown();
|
||||
delete rootSignature;
|
||||
}
|
||||
|
||||
if (!pso->IsValid()) {
|
||||
delete pso;
|
||||
|
||||
@@ -22,9 +22,6 @@ bool OpenGLDescriptorPool::Initialize(const DescriptorPoolDesc& desc) {
|
||||
}
|
||||
|
||||
void OpenGLDescriptorPool::Shutdown() {
|
||||
for (auto* set : m_allocatedSets) {
|
||||
delete set;
|
||||
}
|
||||
m_allocatedSets.clear();
|
||||
m_textureUnitAllocator = nullptr;
|
||||
}
|
||||
@@ -59,4 +56,4 @@ void OpenGLDescriptorPool::FreeSet(RHIDescriptorSet* set) {
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLResourceView.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorPool.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorSet.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLPipelineLayout.h"
|
||||
#include "XCEngine/Debug/Logger.h"
|
||||
|
||||
typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc);
|
||||
@@ -476,7 +477,12 @@ RHIPipelineState* OpenGLDevice::CreatePipelineState(const GraphicsPipelineDesc&
|
||||
}
|
||||
|
||||
RHIPipelineLayout* OpenGLDevice::CreatePipelineLayout(const RHIPipelineLayoutDesc& desc) {
|
||||
return nullptr;
|
||||
auto* layout = new OpenGLPipelineLayout();
|
||||
if (!layout->Initialize(desc)) {
|
||||
delete layout;
|
||||
return nullptr;
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
RHIFence* OpenGLDevice::CreateFence(const FenceDesc& desc) {
|
||||
|
||||
18
engine/src/RHI/OpenGL/OpenGLPipelineLayout.cpp
Normal file
18
engine/src/RHI/OpenGL/OpenGLPipelineLayout.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLPipelineLayout.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
bool OpenGLPipelineLayout::Initialize(const RHIPipelineLayoutDesc& desc) {
|
||||
m_desc = desc;
|
||||
m_initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenGLPipelineLayout::Shutdown() {
|
||||
m_desc = {};
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user