refactor(rhi): untangle d3d12 descriptor bindings
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <wrl/client.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -32,32 +33,46 @@ public:
|
||||
void WriteConstant(uint32_t binding, const void* data, size_t size, size_t offset = 0) override;
|
||||
|
||||
uint32_t GetBindingCount() const override { return m_bindingCount; }
|
||||
const DescriptorSetLayoutBinding* GetBindings() const override { return m_bindings; }
|
||||
const DescriptorSetLayoutBinding* GetBindings() const override { return m_bindings.empty() ? nullptr : m_bindings.data(); }
|
||||
|
||||
void* GetConstantBufferData() override { return m_constantBufferData.data(); }
|
||||
size_t GetConstantBufferSize() const override { return m_constantBufferData.size(); }
|
||||
bool IsConstantDirty() const override { return m_constantBufferDirty; }
|
||||
void MarkConstantClean() override { m_constantBufferDirty = false; }
|
||||
void* GetConstantBufferData() override;
|
||||
size_t GetConstantBufferSize() const override;
|
||||
bool IsConstantDirty() const override;
|
||||
void MarkConstantClean() override;
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUHandle(uint32_t index = 0) const;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUHandleForBinding(uint32_t binding) const;
|
||||
uint32_t GetOffset() const { return m_offset; }
|
||||
uint32_t GetCount() const { return m_count; }
|
||||
D3D12DescriptorHeap* GetHeap() const { return m_heap; }
|
||||
bool HasBindingType(DescriptorType type) const;
|
||||
uint32_t GetFirstBindingOfType(DescriptorType type) const;
|
||||
bool UploadConstantBuffer();
|
||||
D3D12_GPU_VIRTUAL_ADDRESS GetConstantBufferGPUAddress() const;
|
||||
uint32_t GetDescriptorIndexForBinding(uint32_t binding) const;
|
||||
bool UploadConstantBuffer(uint32_t binding);
|
||||
D3D12_GPU_VIRTUAL_ADDRESS GetConstantBufferGPUAddress(uint32_t binding) const;
|
||||
|
||||
private:
|
||||
struct BindingRecord {
|
||||
DescriptorSetLayoutBinding layout = {};
|
||||
uint32_t descriptorIndex = UINT32_MAX;
|
||||
std::vector<uint8_t> constantBufferData;
|
||||
bool constantBufferDirty = false;
|
||||
std::unique_ptr<D3D12Buffer> constantBuffer;
|
||||
uint64_t constantBufferCapacity = 0;
|
||||
};
|
||||
|
||||
BindingRecord* FindBindingRecord(uint32_t binding);
|
||||
const BindingRecord* FindBindingRecord(uint32_t binding) const;
|
||||
BindingRecord* FindFirstBindingRecordOfType(DescriptorType type);
|
||||
const BindingRecord* FindFirstBindingRecordOfType(DescriptorType type) const;
|
||||
|
||||
D3D12DescriptorHeap* m_heap;
|
||||
uint32_t m_offset;
|
||||
uint32_t m_count;
|
||||
uint32_t m_bindingCount;
|
||||
DescriptorSetLayoutBinding* m_bindings;
|
||||
std::vector<uint8_t> m_constantBufferData;
|
||||
bool m_constantBufferDirty = false;
|
||||
std::unique_ptr<D3D12Buffer> m_constantBuffer;
|
||||
uint64_t m_constantBufferCapacity = 0;
|
||||
std::vector<DescriptorSetLayoutBinding> m_bindings;
|
||||
std::vector<BindingRecord> m_bindingRecords;
|
||||
std::unordered_map<uint32_t, uint32_t> m_bindingToRecordIndex;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -27,8 +27,14 @@ public:
|
||||
void* GetNativeHandle() override { return m_rootSignature.Get(); }
|
||||
ID3D12RootSignature* GetRootSignature() const { return m_rootSignature.Get(); }
|
||||
|
||||
uint32_t GetRootParameterIndex(uint32_t shaderRegister) const;
|
||||
bool HasRootParameter(uint32_t shaderRegister) const;
|
||||
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;
|
||||
const RHIPipelineLayoutDesc& GetDesc() const { return m_desc; }
|
||||
|
||||
private:
|
||||
@@ -37,7 +43,10 @@ private:
|
||||
ComPtr<ID3D12RootSignature> m_rootSignature;
|
||||
D3D12Device* m_device;
|
||||
RHIPipelineLayoutDesc m_desc = {};
|
||||
std::unordered_map<uint32_t, uint32_t> m_registerToRootIndex;
|
||||
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<D3D12_ROOT_PARAMETER> m_rootParameters;
|
||||
std::vector<D3D12_DESCRIPTOR_RANGE> m_descriptorRanges;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user