Files
Seele/src/Engine/Graphics/Vulkan/DescriptorSets.h
T

156 lines
4.1 KiB
C++
Raw Normal View History

2020-08-11 21:23:20 +02:00
#pragma once
2023-10-26 18:37:29 +02:00
#include "Enums.h"
#include "Graphics/Descriptor.h"
#include "Containers/List.h"
#include "Resources.h"
2020-04-12 15:47:19 +02:00
namespace Seele
{
namespace Vulkan
{
2021-04-01 16:40:14 +02:00
DECLARE_REF(Graphics)
2020-04-12 15:47:19 +02:00
class DescriptorLayout : public Gfx::DescriptorLayout
{
public:
2021-10-16 12:59:11 +02:00
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create();
2022-04-15 11:19:30 +02:00
constexpr VkDescriptorSetLayout getHandle() const
2021-10-16 12:59:11 +02:00
{
return layoutHandle;
}
2020-04-12 15:47:19 +02:00
private:
2021-10-16 12:59:11 +02:00
uint32 hash;
PGraphics graphics;
Array<VkDescriptorSetLayoutBinding> bindings;
VkDescriptorSetLayout layoutHandle;
friend class DescriptorAllocator;
2020-04-12 15:47:19 +02:00
};
2021-04-01 16:40:14 +02:00
DEFINE_REF(DescriptorLayout)
2020-04-12 15:47:19 +02:00
class PipelineLayout : public Gfx::PipelineLayout
{
public:
2022-01-12 14:40:26 +01:00
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(baseLayout)
, graphics(graphics)
2021-10-16 12:59:11 +02:00
, layoutHash(0)
, layoutHandle(VK_NULL_HANDLE)
2022-01-12 14:40:26 +01:00
{}
2021-10-16 12:59:11 +02:00
virtual ~PipelineLayout();
virtual void create();
virtual void reset();
inline VkPipelineLayout getHandle() const
{
return layoutHandle;
}
virtual uint32 getHash() const
{
return layoutHash;
}
2020-04-12 15:47:19 +02:00
private:
2021-10-16 12:59:11 +02:00
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
PGraphics graphics;
uint32 layoutHash;
VkPipelineLayout layoutHandle;
2020-04-12 15:47:19 +02:00
};
2021-04-01 16:40:14 +02:00
DEFINE_REF(PipelineLayout)
2020-04-12 15:47:19 +02:00
2021-04-13 23:09:16 +02:00
class DescriptorSet : public Gfx::DescriptorSet
{
public:
2021-10-16 12:59:11 +02:00
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
: setHandle(VK_NULL_HANDLE)
, graphics(graphics)
, owner(owner)
, currentlyBound(false)
, currentlyInUse(false)
{
}
virtual ~DescriptorSet();
virtual void writeChanges();
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer);
2023-08-28 21:23:13 +02:00
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer);
2021-10-16 12:59:11 +02:00
virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState);
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr);
2022-04-15 11:19:30 +02:00
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture);
2021-10-16 12:59:11 +02:00
virtual bool operator<(Gfx::PDescriptorSet other);
2023-11-08 23:27:21 +01:00
constexpr bool isCurrentlyBound() const
2021-10-16 12:59:11 +02:00
{
return currentlyBound;
}
2023-11-08 23:27:21 +01:00
constexpr bool isCurrentlyInUse() const
2021-10-16 12:59:11 +02:00
{
return currentlyInUse;
}
2023-11-08 23:27:21 +01:00
constexpr void bind()
2021-10-16 12:59:11 +02:00
{
currentlyBound = true;
}
2023-11-08 23:27:21 +01:00
constexpr void unbind()
2021-10-16 12:59:11 +02:00
{
currentlyBound = false;
}
2023-11-08 23:27:21 +01:00
constexpr void allocate()
2021-10-16 12:59:11 +02:00
{
currentlyInUse = true;
}
2023-11-08 23:27:21 +01:00
constexpr void free()
2021-10-16 12:59:11 +02:00
{
currentlyInUse = false;
}
2023-11-08 23:27:21 +01:00
constexpr VkDescriptorSet getHandle() const
2021-10-16 12:59:11 +02:00
{
return setHandle;
}
virtual uint32 getSetIndex() const;
2021-04-13 23:09:16 +02:00
private:
2021-10-16 12:59:11 +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;
PDescriptorAllocator owner;
bool currentlyBound;
bool currentlyInUse;
friend class DescriptorAllocator;
friend class CmdBuffer;
2022-04-15 23:45:44 +02:00
friend class RenderCommand;
friend class ComputeCommand;
2021-04-13 23:09:16 +02:00
};
DEFINE_REF(DescriptorSet)
2020-05-05 01:51:13 +02:00
class DescriptorAllocator : public Gfx::DescriptorAllocator
{
public:
2021-10-16 12:59:11 +02:00
DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout);
virtual ~DescriptorAllocator();
2023-11-01 23:12:30 +01:00
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
2021-10-16 12:59:11 +02:00
virtual void reset();
2020-05-05 01:51:13 +02:00
2021-10-16 12:59:11 +02:00
inline VkDescriptorPool getHandle() const
{
return poolHandle;
}
inline DescriptorLayout& getLayout() const
{
return layout;
}
2020-05-05 01:51:13 +02:00
private:
2021-10-16 12:59:11 +02:00
PGraphics graphics;
DescriptorLayout &layout;
2021-12-09 12:38:02 +01:00
const static int maxSets = 64;
2023-11-01 23:12:30 +01:00
StaticArray<ODescriptorSet, maxSets> cachedHandles;
2021-10-16 12:59:11 +02:00
VkDescriptorPool poolHandle;
2021-12-27 15:04:53 +01:00
DescriptorAllocator* nextAlloc = nullptr;
2020-05-05 01:51:13 +02:00
};
2021-04-01 16:40:14 +02:00
DEFINE_REF(DescriptorAllocator)
2020-04-12 15:47:19 +02:00
} // namespace Vulkan
} // namespace Seele