80 lines
3.1 KiB
C++
80 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <d3d12.h>
|
|
#include <wrl/client.h>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include "../RHIPipelineLayout.h"
|
|
#include "D3D12RootSignature.h"
|
|
|
|
using Microsoft::WRL::ComPtr;
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
class D3D12Device;
|
|
|
|
class D3D12PipelineLayout : public RHIPipelineLayout {
|
|
public:
|
|
struct SetRootParameterMapping {
|
|
std::unordered_map<uint32_t, uint32_t> constantBufferRootIndices;
|
|
uint32_t shaderResourceTableRootIndex = UINT32_MAX;
|
|
uint32_t unorderedAccessTableRootIndex = UINT32_MAX;
|
|
uint32_t samplerTableRootIndex = UINT32_MAX;
|
|
};
|
|
|
|
D3D12PipelineLayout();
|
|
~D3D12PipelineLayout() override;
|
|
|
|
bool InitializeWithDevice(D3D12Device* device, const RHIPipelineLayoutDesc& desc);
|
|
void Shutdown() override;
|
|
bool Initialize(const RHIPipelineLayoutDesc& desc) override { return false; }
|
|
|
|
void* GetNativeHandle() override { return m_rootSignature.Get(); }
|
|
ID3D12RootSignature* GetRootSignature() const { return m_rootSignature.Get(); }
|
|
|
|
bool UsesSetLayouts() const { return m_desc.setLayoutCount > 0 && m_desc.setLayouts != nullptr; }
|
|
uint32_t GetSetLayoutCount() const { return m_desc.setLayoutCount; }
|
|
|
|
bool HasConstantBufferBinding(uint32_t binding) const;
|
|
uint32_t GetConstantBufferRootParameterIndex(uint32_t binding) const;
|
|
bool HasShaderResourceTable() const;
|
|
uint32_t GetShaderResourceTableRootParameterIndex() const;
|
|
bool HasUnorderedAccessTable() const;
|
|
uint32_t GetUnorderedAccessTableRootParameterIndex() const;
|
|
bool HasSamplerTable() const;
|
|
uint32_t GetSamplerTableRootParameterIndex() const;
|
|
|
|
bool HasConstantBufferBinding(uint32_t setIndex, uint32_t binding) const;
|
|
uint32_t GetConstantBufferRootParameterIndex(uint32_t setIndex, uint32_t binding) const;
|
|
bool HasShaderResourceTable(uint32_t setIndex) const;
|
|
uint32_t GetShaderResourceTableRootParameterIndex(uint32_t setIndex) const;
|
|
bool HasUnorderedAccessTable(uint32_t setIndex) const;
|
|
uint32_t GetUnorderedAccessTableRootParameterIndex(uint32_t setIndex) const;
|
|
bool HasSamplerTable(uint32_t setIndex) const;
|
|
uint32_t GetSamplerTableRootParameterIndex(uint32_t setIndex) const;
|
|
const RHIPipelineLayoutDesc& GetDesc() const { return m_desc; }
|
|
|
|
private:
|
|
bool InitializeInternal(D3D12Device* device, const RHIPipelineLayoutDesc& desc);
|
|
bool InitializeSetAwareRootSignature();
|
|
bool InitializeFlatRootSignature();
|
|
|
|
ComPtr<ID3D12RootSignature> m_rootSignature;
|
|
D3D12Device* m_device;
|
|
RHIPipelineLayoutDesc m_desc = {};
|
|
std::unordered_map<uint32_t, uint32_t> m_constantBufferRootIndices;
|
|
uint32_t m_shaderResourceTableRootIndex = UINT32_MAX;
|
|
uint32_t m_unorderedAccessTableRootIndex = UINT32_MAX;
|
|
uint32_t m_samplerTableRootIndex = UINT32_MAX;
|
|
std::vector<SetRootParameterMapping> m_setRootParameterMappings;
|
|
std::vector<DescriptorSetLayoutDesc> m_setLayouts;
|
|
std::vector<std::vector<DescriptorSetLayoutBinding>> m_setLayoutBindings;
|
|
std::vector<D3D12_ROOT_PARAMETER> m_rootParameters;
|
|
std::vector<D3D12_DESCRIPTOR_RANGE> m_descriptorRanges;
|
|
};
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|