mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-13 15:43:34 +00:00
fixing descriptor set issue
This commit is contained in:
@@ -14,6 +14,13 @@ namespace Scop
|
||||
{
|
||||
friend Scene;
|
||||
|
||||
public:
|
||||
struct CustomPipeline
|
||||
{
|
||||
std::shared_ptr<Shader> shader;
|
||||
CPUBuffer data;
|
||||
};
|
||||
|
||||
public:
|
||||
Actor();
|
||||
Actor(Model model);
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace Scop
|
||||
~Material() { m_data_buffer.Destroy(); }
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return m_set.IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return m_set.GetSet(frame_index); }
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set->GetSet(frame_index); }
|
||||
|
||||
inline void SetupEventListener()
|
||||
{
|
||||
@@ -49,18 +49,18 @@ namespace Scop
|
||||
EventBus::RegisterListener({ functor, "__ScopMaterial" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });
|
||||
}
|
||||
|
||||
inline void UpdateDescriptorSet(const DescriptorSet& set)
|
||||
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
m_set = set.Duplicate();
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
|
||||
}
|
||||
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
if(m_have_been_updated_this_frame)
|
||||
return;
|
||||
m_set.SetImage(frame_index, 0, *m_textures.albedo);
|
||||
m_set.SetUniformBuffer(frame_index, 1, m_data_buffer.Get(frame_index));
|
||||
m_set.Update(frame_index, cmd);
|
||||
p_set->SetImage(frame_index, 0, *m_textures.albedo);
|
||||
p_set->SetUniformBuffer(frame_index, 1, m_data_buffer.Get(frame_index));
|
||||
p_set->Update(frame_index, cmd);
|
||||
|
||||
static CPUBuffer buffer(sizeof(MaterialData));
|
||||
std::memcpy(buffer.GetData(), &m_data, buffer.GetSize());
|
||||
@@ -73,7 +73,7 @@ namespace Scop
|
||||
UniformBuffer m_data_buffer;
|
||||
MaterialTextures m_textures;
|
||||
MaterialData m_data;
|
||||
DescriptorSet m_set;
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
bool m_have_been_updated_this_frame = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Scop
|
||||
[[nodiscard]] inline Vec3f GetCenter() const noexcept { return m_center; }
|
||||
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||
|
||||
void Draw(VkCommandBuffer cmd, const DescriptorSet& matrices_set, const class GraphicPipeline& pipeline, DescriptorSet& set, std::size_t& drawcalls, std::size_t& polygondrawn, std::size_t frame_index) const;
|
||||
void Draw(VkCommandBuffer cmd, std::shared_ptr<DescriptorSet> matrices_set, const class GraphicPipeline& pipeline, std::shared_ptr<DescriptorSet> set, std::size_t& drawcalls, std::size_t& polygondrawn, std::size_t frame_index) const;
|
||||
|
||||
~Model() = default;
|
||||
|
||||
|
||||
@@ -37,22 +37,22 @@ namespace Scop
|
||||
~Sprite();
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return m_set.IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return m_set.GetSet(frame_index); }
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set->GetSet(frame_index); }
|
||||
|
||||
inline void UpdateDescriptorSet(const DescriptorSet& set)
|
||||
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
m_set = set.Duplicate();
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
|
||||
}
|
||||
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
m_set.SetImage(frame_index, 0, *p_texture);
|
||||
m_set.Update(frame_index, cmd);
|
||||
p_set->SetImage(frame_index, 0, *p_texture);
|
||||
p_set->Update(frame_index, cmd);
|
||||
}
|
||||
|
||||
private:
|
||||
DescriptorSet m_set;
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
std::shared_ptr<Texture> p_texture;
|
||||
std::shared_ptr<class SpriteScript> p_script;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
|
||||
@@ -29,20 +29,20 @@ namespace Scop
|
||||
virtual ~Text() = default;
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return m_set.IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return m_set.GetSet(frame_index); }
|
||||
inline void UpdateDescriptorSet(const DescriptorSet& set)
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set->GetSet(frame_index); }
|
||||
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
m_set = set.Duplicate();
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
|
||||
}
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
m_set.SetImage(frame_index, 0, const_cast<Texture&>(p_font->GetTexture()));
|
||||
m_set.Update(frame_index, cmd);
|
||||
p_set->SetImage(frame_index, 0, const_cast<Texture&>(p_font->GetTexture()));
|
||||
p_set->Update(frame_index, cmd);
|
||||
}
|
||||
|
||||
private:
|
||||
DescriptorSet m_set;
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
std::shared_ptr<Font> p_font;
|
||||
std::string m_text;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include <kvf.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
#include <Renderer/Pipelines/Shader.h>
|
||||
|
||||
namespace Scop
|
||||
@@ -17,34 +17,76 @@ namespace Scop
|
||||
NonOwningPtr<class GPUBuffer> uniform_buffer_ptr;
|
||||
NonOwningPtr<class Image> image_ptr;
|
||||
VkDescriptorType type;
|
||||
ShaderType shader_type;
|
||||
std::uint32_t binding;
|
||||
};
|
||||
|
||||
class DescriptorSet
|
||||
class DescriptorPool
|
||||
{
|
||||
public:
|
||||
DescriptorSet() { m_set.fill(VK_NULL_HANDLE); }
|
||||
DescriptorSet(const ShaderSetLayout& layout, VkDescriptorSetLayout vklayout, ShaderType shader_type);
|
||||
DescriptorPool() = default;
|
||||
|
||||
void Init() noexcept;
|
||||
void Destroy() noexcept;
|
||||
|
||||
std::shared_ptr<class DescriptorSet> RequestDescriptorSet(const ShaderSetLayout& layout, ShaderType shader_type);
|
||||
void ReturnDescriptorSet(std::shared_ptr<class DescriptorSet> set);
|
||||
|
||||
[[nodiscard]] inline VkDescriptorPool Get() const noexcept { return m_pool; }
|
||||
[[nodiscard]] inline std::size_t GetNumberOfSetsAllocated() const noexcept { return m_allocation_count; }
|
||||
|
||||
~DescriptorPool() = default;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<class DescriptorSet>> m_free_sets;
|
||||
std::vector<std::shared_ptr<class DescriptorSet>> m_used_sets;
|
||||
VkDescriptorPool m_pool;
|
||||
std::size_t m_allocation_count = 0;
|
||||
};
|
||||
|
||||
class DescriptorPoolManager
|
||||
{
|
||||
public:
|
||||
DescriptorPoolManager() = default;
|
||||
|
||||
DescriptorPool& GetAvailablePool();
|
||||
void Destroy();
|
||||
|
||||
~DescriptorPoolManager() = default;
|
||||
|
||||
private:
|
||||
std::vector<DescriptorPool> m_pools;
|
||||
};
|
||||
|
||||
class DescriptorSet : public std::enable_shared_from_this<DescriptorSet>
|
||||
{
|
||||
friend DescriptorPool;
|
||||
|
||||
public:
|
||||
void SetImage(std::size_t i, std::uint32_t binding, class Image& image);
|
||||
void SetStorageBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer);
|
||||
void SetUniformBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer);
|
||||
void Update(std::size_t i, VkCommandBuffer cmd = VK_NULL_HANDLE) noexcept;
|
||||
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t i) const noexcept { return m_set[i]; }
|
||||
[[nodiscard]] inline DescriptorSet Duplicate() const { return DescriptorSet{ m_set_layout, m_descriptors }; }
|
||||
[[nodiscard]] inline bool IsInit() const noexcept { return m_set[0] != VK_NULL_HANDLE; }
|
||||
void ReturnDescriptorSetToPool();
|
||||
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t i) const noexcept { return m_sets[i]; }
|
||||
[[nodiscard]] inline bool IsInit() const noexcept { return m_sets[0] != VK_NULL_HANDLE; }
|
||||
[[nodiscard]] inline VkDescriptorSetLayout GetVulkanLayout() const noexcept { return m_set_layout; }
|
||||
[[nodiscard]] inline const ShaderSetLayout& GetShaderLayout() const { return m_shader_layout; }
|
||||
[[nodiscard]] inline ShaderType GetShaderType() const noexcept { return m_shader_type; }
|
||||
|
||||
~DescriptorSet() = default;
|
||||
|
||||
private:
|
||||
DescriptorSet(VkDescriptorSetLayout layout, const std::vector<Descriptor>& descriptors);
|
||||
DescriptorSet(DescriptorPool& pool, VkDescriptorSetLayout vulkan_layout, const ShaderSetLayout& layout, std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> vulkan_sets, ShaderType shader_type);
|
||||
|
||||
private:
|
||||
ShaderSetLayout m_shader_layout;
|
||||
std::vector<Descriptor> m_descriptors;
|
||||
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> m_set;
|
||||
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> m_sets;
|
||||
VkDescriptorSetLayout m_set_layout;
|
||||
ShaderType m_shader_type;
|
||||
DescriptorPool& m_pool;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace Scop
|
||||
std::vector<std::pair<int, VkDescriptorType> > binds;
|
||||
|
||||
ShaderSetLayout(std::vector<std::pair<int, VkDescriptorType> > b) : binds(std::move(b)) {}
|
||||
|
||||
inline bool operator==(const ShaderSetLayout& rhs) const { return binds == rhs.binds; }
|
||||
};
|
||||
|
||||
struct ShaderPushConstantLayout
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace Scop
|
||||
[[nodiscard]] inline VkPhysicalDevice GetPhysicalDevice() const noexcept { return m_physical_device; }
|
||||
[[nodiscard]] inline DeviceAllocator& GetAllocator() noexcept { return m_allocator; }
|
||||
[[nodiscard]] inline bool StackSubmits() const noexcept { return m_stack_submits; }
|
||||
[[nodiscard]] inline class DescriptorPoolManager& GetDescriptorPoolManager() noexcept { return *p_descriptor_pool_manager; }
|
||||
|
||||
[[nodiscard]] inline std::shared_ptr<class Shader> GetDefaultVertexShader() const { return m_internal_shaders[DEFAULT_VERTEX_SHADER_ID]; }
|
||||
[[nodiscard]] inline std::shared_ptr<class Shader> GetBasicFragmentShader() const { return m_internal_shaders[BASIC_FRAGMENT_SHADER_ID]; }
|
||||
@@ -71,6 +72,7 @@ namespace Scop
|
||||
VkInstance m_instance = VK_NULL_HANDLE;
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice m_physical_device = VK_NULL_HANDLE;
|
||||
std::unique_ptr<class DescriptorPoolManager> p_descriptor_pool_manager;
|
||||
bool m_stack_submits = false;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user