2020-08-11 21:23:20 +02:00
|
|
|
#pragma once
|
2024-04-13 23:51:38 +02:00
|
|
|
#include "Containers/List.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Enums.h"
|
|
|
|
|
#include "Graphics/Descriptor.h"
|
|
|
|
|
#include "Resources.h"
|
2020-04-12 15:47:19 +02:00
|
|
|
|
2024-04-13 23:51:38 +02:00
|
|
|
namespace Seele {
|
|
|
|
|
namespace Vulkan {
|
2021-04-01 16:40:14 +02:00
|
|
|
DECLARE_REF(Graphics)
|
2024-04-13 23:51:38 +02:00
|
|
|
class DescriptorLayout : public Gfx::DescriptorLayout {
|
2020-04-12 15:47:19 +02:00
|
|
|
public:
|
2024-04-13 23:51:38 +02:00
|
|
|
DescriptorLayout(PGraphics graphics, const std::string& name);
|
|
|
|
|
virtual ~DescriptorLayout();
|
|
|
|
|
virtual void create() override;
|
|
|
|
|
constexpr VkDescriptorSetLayout getHandle() const { return layoutHandle; }
|
|
|
|
|
|
2020-04-12 15:47:19 +02:00
|
|
|
private:
|
2024-04-13 23:51:38 +02:00
|
|
|
PGraphics graphics;
|
|
|
|
|
Array<VkDescriptorSetLayoutBinding> bindings;
|
|
|
|
|
VkDescriptorSetLayout layoutHandle;
|
|
|
|
|
friend class DescriptorPool;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
2021-04-01 16:40:14 +02:00
|
|
|
DEFINE_REF(DescriptorLayout)
|
2024-04-13 23:51:38 +02:00
|
|
|
|
|
|
|
|
DECLARE_REF(DescriptorSet)
|
|
|
|
|
class DescriptorPool : public Gfx::DescriptorPool {
|
2020-04-12 15:47:19 +02:00
|
|
|
public:
|
2024-04-13 23:51:38 +02:00
|
|
|
DescriptorPool(PGraphics graphics, PDescriptorLayout layout);
|
|
|
|
|
virtual ~DescriptorPool();
|
|
|
|
|
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
|
|
|
|
|
virtual void reset() override;
|
|
|
|
|
|
|
|
|
|
constexpr VkDescriptorPool getHandle() const { return poolHandle; }
|
|
|
|
|
constexpr PDescriptorLayout getLayout() const { return layout; }
|
2020-04-12 15:47:19 +02:00
|
|
|
|
|
|
|
|
private:
|
2024-04-13 23:51:38 +02:00
|
|
|
PGraphics graphics;
|
|
|
|
|
PDescriptorLayout layout;
|
|
|
|
|
const static int maxSets = 64;
|
|
|
|
|
StaticArray<ODescriptorSet, maxSets> cachedHandles;
|
|
|
|
|
VkDescriptorPool poolHandle;
|
|
|
|
|
DescriptorPool* nextAlloc = nullptr;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
2024-04-13 23:51:38 +02:00
|
|
|
DEFINE_REF(DescriptorPool)
|
2020-04-12 15:47:19 +02:00
|
|
|
|
2024-04-13 23:51:38 +02:00
|
|
|
class DescriptorSet : public Gfx::DescriptorSet {
|
2021-04-13 23:09:16 +02:00
|
|
|
public:
|
2024-04-13 23:51:38 +02:00
|
|
|
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
|
|
|
|
|
virtual ~DescriptorSet();
|
|
|
|
|
virtual void writeChanges() override;
|
|
|
|
|
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) override;
|
|
|
|
|
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) override;
|
|
|
|
|
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState) override;
|
|
|
|
|
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
|
|
|
|
|
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture) override;
|
|
|
|
|
|
|
|
|
|
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
|
|
|
|
|
constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
|
|
|
|
|
constexpr void bind() { bindCount++; }
|
|
|
|
|
constexpr void unbind() { bindCount--; }
|
|
|
|
|
constexpr void allocate() { currentlyInUse = true; }
|
|
|
|
|
constexpr void free() { currentlyInUse = false; }
|
|
|
|
|
constexpr VkDescriptorSet getHandle() const { return setHandle; }
|
2021-04-13 23:09:16 +02:00
|
|
|
|
|
|
|
|
private:
|
2024-04-13 23:51:38 +02:00
|
|
|
List<VkDescriptorImageInfo> imageInfos;
|
|
|
|
|
List<VkDescriptorBufferInfo> bufferInfos;
|
|
|
|
|
Array<VkWriteDescriptorSet> writeDescriptors;
|
|
|
|
|
// contains the previously bound resources at every binding
|
|
|
|
|
// since the layout is fixed, trying to bind a texture to a buffer
|
|
|
|
|
// would not work anyways, so casts should be safe
|
|
|
|
|
Array<void*> cachedData;
|
|
|
|
|
VkDescriptorSet setHandle;
|
|
|
|
|
PGraphics graphics;
|
|
|
|
|
PDescriptorPool owner;
|
|
|
|
|
uint32 bindCount;
|
|
|
|
|
bool currentlyInUse;
|
|
|
|
|
friend class DescriptorPool;
|
|
|
|
|
friend class Command;
|
|
|
|
|
friend class RenderCommand;
|
|
|
|
|
friend class ComputeCommand;
|
2021-04-13 23:09:16 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorSet)
|
|
|
|
|
|
2024-04-13 23:51:38 +02:00
|
|
|
class PipelineLayout : public Gfx::PipelineLayout {
|
2020-05-05 01:51:13 +02:00
|
|
|
public:
|
2024-04-13 23:51:38 +02:00
|
|
|
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout);
|
|
|
|
|
virtual ~PipelineLayout();
|
|
|
|
|
virtual void create();
|
|
|
|
|
constexpr VkPipelineLayout getHandle() const { return layoutHandle; }
|
2020-05-05 01:51:13 +02:00
|
|
|
|
|
|
|
|
private:
|
2024-04-13 23:51:38 +02:00
|
|
|
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
|
|
|
|
|
PGraphics graphics;
|
|
|
|
|
VkPipelineLayout layoutHandle;
|
2020-05-05 01:51:13 +02:00
|
|
|
};
|
2024-04-13 23:51:38 +02:00
|
|
|
DEFINE_REF(PipelineLayout)
|
|
|
|
|
|
2020-04-12 15:47:19 +02:00
|
|
|
} // namespace Vulkan
|
|
|
|
|
} // namespace Seele
|