refactor: Clean up RHI interface and implement descriptor set pooling
- Remove unnecessary inline keywords from RHICommandList - Add TextureType enum for proper texture type classification - Update DescriptorSet API to support binding with pipeline layout - Simplify D3D12CommandList implementation - Implement descriptor set binding with pipeline layout for both D3D12 and OpenGL
This commit is contained in:
@@ -37,12 +37,6 @@ public:
|
||||
|
||||
void SetShader(RHIShader* shader) override;
|
||||
|
||||
void SetUniformInt(const char* name, int value) override;
|
||||
void SetUniformFloat(const char* name, float value) override;
|
||||
void SetUniformVec3(const char* name, float x, float y, float z) override;
|
||||
void SetUniformVec4(const char* name, float x, float y, float z, float w) override;
|
||||
void SetUniformMat4(const char* name, const float* value) override;
|
||||
|
||||
void TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
||||
void TransitionBarrier(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter);
|
||||
void TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <wrl/client.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../RHIEnums.h"
|
||||
#include "../RHITypes.h"
|
||||
@@ -21,13 +22,21 @@ public:
|
||||
bool Initialize(D3D12DescriptorHeap* heap, uint32_t offset, uint32_t count, const DescriptorSetLayoutDesc& layout);
|
||||
void Shutdown() override;
|
||||
|
||||
void Bind() override;
|
||||
void Unbind() override;
|
||||
|
||||
void Update(uint32_t offset, RHIResourceView* view) override;
|
||||
void UpdateSampler(uint32_t offset, RHISampler* sampler) override;
|
||||
void* GetNativeHandle() override;
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUHandle(uint32_t index = 0) const;
|
||||
uint32_t GetOffset() const { return m_offset; }
|
||||
uint32_t GetCount() const { return m_count; }
|
||||
@@ -39,6 +48,8 @@ private:
|
||||
uint32_t m_count;
|
||||
uint32_t m_bindingCount;
|
||||
DescriptorSetLayoutBinding* m_bindings;
|
||||
std::vector<uint8_t> m_constantBufferData;
|
||||
bool m_constantBufferDirty = false;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -54,11 +54,11 @@ public:
|
||||
|
||||
void SetShader(RHIShader* shader) override;
|
||||
|
||||
void SetUniformInt(const char* name, int value) override;
|
||||
void SetUniformFloat(const char* name, float value) override;
|
||||
void SetUniformVec3(const char* name, float x, float y, float z) override;
|
||||
void SetUniformVec4(const char* name, float x, float y, float z, float w) override;
|
||||
void SetUniformMat4(const char* name, const float* value) override;
|
||||
void SetUniformInt(const char* name, int value);
|
||||
void SetUniformFloat(const char* name, float value);
|
||||
void SetUniformVec3(const char* name, float x, float y, float z);
|
||||
void SetUniformVec4(const char* name, float x, float y, float z, float w);
|
||||
void SetUniformMat4(const char* name, const float* value);
|
||||
|
||||
void SetPipelineState(RHIPipelineState* pipelineState) override;
|
||||
void SetGraphicsDescriptorSets(
|
||||
|
||||
@@ -28,14 +28,21 @@ public:
|
||||
bool Initialize(OpenGLTextureUnitAllocator* allocator, uint32_t count, const DescriptorSetLayoutDesc& layout);
|
||||
void Shutdown() override;
|
||||
|
||||
void Bind() override;
|
||||
void Unbind() override;
|
||||
|
||||
void Update(uint32_t offset, RHIResourceView* view) override;
|
||||
void UpdateSampler(uint32_t offset, RHISampler* sampler) override;
|
||||
void* GetNativeHandle() override { return this; }
|
||||
void WriteConstant(uint32_t binding, const void* data, size_t size, size_t offset = 0) override;
|
||||
|
||||
uint32_t GetBindingCount() const override { return static_cast<uint32_t>(m_bindings.size()); }
|
||||
const DescriptorSetLayoutBinding* GetBindings() const override { return m_layoutBindings; }
|
||||
|
||||
void Bind();
|
||||
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; }
|
||||
|
||||
uint32_t GetBindingPoint(uint32_t binding) const;
|
||||
|
||||
private:
|
||||
@@ -44,6 +51,9 @@ private:
|
||||
DescriptorSetLayoutBinding* m_layoutBindings;
|
||||
uint32_t m_bindingCount;
|
||||
bool m_bound;
|
||||
std::vector<uint8_t> m_constantBufferData;
|
||||
bool m_constantBufferDirty = false;
|
||||
uint32_t m_constantBuffer = 0;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -64,12 +64,6 @@ public:
|
||||
|
||||
virtual void SetShader(RHIShader* shader) = 0;
|
||||
|
||||
virtual void SetUniformInt(const char* name, int value) = 0;
|
||||
virtual void SetUniformFloat(const char* name, float value) = 0;
|
||||
virtual void SetUniformVec3(const char* name, float x, float y, float z) = 0;
|
||||
virtual void SetUniformVec4(const char* name, float x, float y, float z, float w) = 0;
|
||||
virtual void SetUniformMat4(const char* name, const float* value) = 0;
|
||||
|
||||
virtual void SetPipelineState(RHIPipelineState* pso) = 0;
|
||||
virtual void SetGraphicsDescriptorSets(
|
||||
uint32_t firstSet,
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "RHIEnums.h"
|
||||
#include <cstdint>
|
||||
#include "RHITypes.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class RHIDescriptorSet;
|
||||
struct DescriptorSetLayoutDesc;
|
||||
|
||||
struct DescriptorPoolDesc {
|
||||
void* device;
|
||||
DescriptorHeapType type;
|
||||
uint32_t descriptorCount;
|
||||
bool shaderVisible;
|
||||
};
|
||||
|
||||
class RHIDescriptorPool {
|
||||
public:
|
||||
|
||||
@@ -10,34 +10,30 @@ class RHIDescriptorPool;
|
||||
class RHIResourceView;
|
||||
class RHISampler;
|
||||
|
||||
struct DescriptorSetLayoutBinding {
|
||||
uint32_t binding;
|
||||
DescriptorType type;
|
||||
uint32_t count;
|
||||
ShaderVisibility visibility = ShaderVisibility::All;
|
||||
};
|
||||
|
||||
struct DescriptorSetLayoutDesc {
|
||||
DescriptorSetLayoutBinding* bindings = nullptr;
|
||||
uint32_t bindingCount = 0;
|
||||
};
|
||||
|
||||
class RHIDescriptorSet {
|
||||
public:
|
||||
virtual ~RHIDescriptorSet() = default;
|
||||
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void Bind() = 0;
|
||||
virtual void Unbind() = 0;
|
||||
|
||||
virtual void Update(uint32_t offset, RHIResourceView* view) = 0;
|
||||
virtual void UpdateSampler(uint32_t offset, RHISampler* sampler) = 0;
|
||||
|
||||
virtual void* GetNativeHandle() = 0;
|
||||
virtual void WriteConstant(uint32_t binding, const void* data, size_t size, size_t offset = 0) = 0;
|
||||
|
||||
virtual uint32_t GetBindingCount() const = 0;
|
||||
virtual const DescriptorSetLayoutBinding* GetBindings() const = 0;
|
||||
|
||||
virtual void* GetConstantBufferData() = 0;
|
||||
virtual size_t GetConstantBufferSize() const = 0;
|
||||
virtual bool IsConstantDirty() const = 0;
|
||||
virtual void MarkConstantClean() = 0;
|
||||
|
||||
protected:
|
||||
RHIDescriptorSet() = default;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
@@ -377,5 +377,24 @@ struct ResourceViewDesc {
|
||||
uint32_t structureByteStride = 0;
|
||||
};
|
||||
|
||||
struct DescriptorSetLayoutBinding {
|
||||
uint32_t binding = 0;
|
||||
uint32_t type = 0;
|
||||
uint32_t count = 0;
|
||||
uint32_t visibility = 0;
|
||||
};
|
||||
|
||||
struct DescriptorSetLayoutDesc {
|
||||
DescriptorSetLayoutBinding* bindings = nullptr;
|
||||
uint32_t bindingCount = 0;
|
||||
};
|
||||
|
||||
struct DescriptorPoolDesc {
|
||||
void* device = nullptr;
|
||||
DescriptorHeapType type = DescriptorHeapType::CBV_SRV_UAV;
|
||||
uint32_t descriptorCount = 0;
|
||||
bool shaderVisible = false;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
|
||||
Reference in New Issue
Block a user