78 lines
3.1 KiB
C++
78 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include "XCEngine/RHI/RHIPipelineState.h"
|
|
#include "XCEngine/RHI/Vulkan/VulkanCommon.h"
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
class VulkanDevice;
|
|
class VulkanShader;
|
|
|
|
class VulkanPipelineState : public RHIPipelineState {
|
|
public:
|
|
VulkanPipelineState() = default;
|
|
~VulkanPipelineState() override;
|
|
|
|
bool Initialize(VulkanDevice* device, const GraphicsPipelineDesc& desc);
|
|
|
|
void SetInputLayout(const InputLayoutDesc& layout) override;
|
|
void SetRasterizerState(const RasterizerDesc& state) override;
|
|
void SetBlendState(const BlendDesc& state) override;
|
|
void SetDepthStencilState(const DepthStencilStateDesc& state) override;
|
|
void SetTopology(uint32_t topologyType) override;
|
|
void SetRenderTargetFormats(uint32_t count, const uint32_t* formats, uint32_t depthFormat) override;
|
|
void SetSampleCount(uint32_t count) override;
|
|
void SetComputeShader(RHIShader* shader) override;
|
|
|
|
const RasterizerDesc& GetRasterizerState() const override { return m_rasterizerDesc; }
|
|
const BlendDesc& GetBlendState() const override { return m_blendDesc; }
|
|
const DepthStencilStateDesc& GetDepthStencilState() const override { return m_depthStencilDesc; }
|
|
const InputLayoutDesc& GetInputLayout() const override { return m_inputLayoutDesc; }
|
|
PipelineStateHash GetHash() const override;
|
|
RHIShader* GetComputeShader() const override { return m_computeShader; }
|
|
bool HasComputeShader() const override { return m_computeShader != nullptr; }
|
|
|
|
bool IsValid() const override { return m_isConfigured; }
|
|
void EnsureValid() override;
|
|
|
|
void Shutdown() override;
|
|
void Bind() override {}
|
|
void Unbind() override {}
|
|
void* GetNativeHandle() override { return m_pipeline; }
|
|
PipelineType GetType() const override { return HasComputeShader() ? PipelineType::Compute : PipelineType::Graphics; }
|
|
|
|
VkPipeline GetPipeline() const { return m_pipeline; }
|
|
VkPipelineLayout GetPipelineLayout() const { return m_pipelineLayout; }
|
|
VkRenderPass GetRenderPass() const { return m_renderPass; }
|
|
bool HasDepthStencilAttachment() const {
|
|
return m_depthStencilFormat != 0 && static_cast<Format>(m_depthStencilFormat) != Format::Unknown;
|
|
}
|
|
|
|
private:
|
|
bool EnsurePipelineLayout(const GraphicsPipelineDesc& desc);
|
|
bool CreateGraphicsPipeline(const GraphicsPipelineDesc& desc);
|
|
bool CreateComputePipeline();
|
|
|
|
VulkanDevice* m_deviceOwner = nullptr;
|
|
VkDevice m_device = VK_NULL_HANDLE;
|
|
VkPipeline m_pipeline = VK_NULL_HANDLE;
|
|
VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
|
|
VkRenderPass m_renderPass = VK_NULL_HANDLE;
|
|
bool m_ownsPipelineLayout = false;
|
|
InputLayoutDesc m_inputLayoutDesc = {};
|
|
RasterizerDesc m_rasterizerDesc = {};
|
|
BlendDesc m_blendDesc = {};
|
|
DepthStencilStateDesc m_depthStencilDesc = {};
|
|
uint32_t m_topologyType = static_cast<uint32_t>(PrimitiveTopologyType::Triangle);
|
|
uint32_t m_renderTargetCount = 1;
|
|
uint32_t m_renderTargetFormats[8] = { 0 };
|
|
uint32_t m_depthStencilFormat = 0;
|
|
uint32_t m_sampleCount = 1;
|
|
RHIShader* m_computeShader = nullptr;
|
|
bool m_isConfigured = false;
|
|
};
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|