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

150 lines
3.4 KiB
C++
Raw Normal View History

2020-08-11 21:23:20 +02:00
#pragma once
2020-04-12 15:47:19 +02:00
#include "VulkanGraphicsResources.h"
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-05-06 17:02:10 +02:00
DescriptorLayout(PGraphics graphics, const std::string& name);
2020-04-12 15:47:19 +02:00
virtual ~DescriptorLayout();
virtual void create();
inline VkDescriptorSetLayout getHandle() const
{
return layoutHandle;
}
private:
2020-10-03 11:00:10 +02:00
uint32 hash;
2020-04-12 15:47:19 +02:00
PGraphics graphics;
Array<VkDescriptorSetLayoutBinding> bindings;
VkDescriptorSetLayout layoutHandle;
2021-05-06 17:02:10 +02:00
std::string name;
2020-10-03 11:00:10 +02:00
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:
PipelineLayout(PGraphics graphics)
2021-04-01 16:40:14 +02:00
: graphics(graphics)
, layoutHash(0)
, layoutHandle(VK_NULL_HANDLE)
2020-04-12 15:47:19 +02:00
{
}
virtual ~PipelineLayout();
virtual void create();
2020-06-02 11:46:18 +02:00
virtual void reset();
2020-04-12 15:47:19 +02:00
inline VkPipelineLayout getHandle() const
{
return layoutHandle;
}
virtual uint32 getHash() const
{
return layoutHash;
}
private:
Array<VkDescriptorSetLayout> vulkanDescriptorLayouts;
2021-04-01 16:40:14 +02:00
PGraphics graphics;
2020-04-12 15:47:19 +02:00
uint32 layoutHash;
VkPipelineLayout layoutHandle;
};
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:
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
2021-05-10 23:57:55 +02:00
: setHandle(VK_NULL_HANDLE)
, graphics(graphics)
, owner(owner)
, currentlyInUse(false)
, currentlyBound(false)
2021-04-13 23:09:16 +02:00
{
}
virtual ~DescriptorSet();
virtual void writeChanges();
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer);
virtual void updateBuffer(uint32_t binding, Gfx::PStructuredBuffer uniformBuffer);
virtual void updateSampler(uint32_t binding, Gfx::PSamplerState samplerState);
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSamplerState sampler = nullptr);
virtual bool operator<(Gfx::PDescriptorSet other);
inline bool isCurrentlyBound() const
{
return currentlyBound;
2021-04-13 23:09:16 +02:00
}
inline bool isCurrentlyInUse() const
{
return currentlyInUse;
}
void bind()
{
currentlyBound = true;
}
void unbind()
{
currentlyBound = false;
}
2021-04-13 23:09:16 +02:00
void free()
{
currentlyInUse = false;
}
inline VkDescriptorSet getHandle() const
{
2021-05-10 23:57:55 +02:00
return setHandle;
2021-04-13 23:09:16 +02:00
}
virtual uint32 getSetIndex() const;
private:
2021-04-25 23:43:40 +02:00
List<VkDescriptorImageInfo> imageInfos;
List<VkDescriptorBufferInfo> bufferInfos;
2021-04-13 23:09:16 +02:00
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
2021-05-10 23:57:55 +02:00
Array<void*> cachedData;
VkDescriptorSet setHandle;
2021-04-13 23:09:16 +02:00
PGraphics graphics;
PDescriptorAllocator owner;
//PCmdBuffer currentlyBound;
bool currentlyBound;
2021-04-13 23:09:16 +02:00
bool currentlyInUse;
friend class DescriptorAllocator;
friend class CmdBuffer;
friend class SecondaryCmdBuffer;
};
DEFINE_REF(DescriptorSet)
2020-05-05 01:51:13 +02:00
class DescriptorAllocator : public Gfx::DescriptorAllocator
{
public:
DescriptorAllocator(PGraphics graphics, DescriptorLayout &layout);
virtual ~DescriptorAllocator();
virtual void allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet);
2020-10-03 11:00:10 +02:00
virtual void reset();
2020-05-05 01:51:13 +02:00
inline VkDescriptorPool getHandle() const
{
return poolHandle;
}
2020-10-14 01:49:43 +02:00
inline DescriptorLayout& getLayout() const
2020-05-05 01:51:13 +02:00
{
return layout;
}
private:
PGraphics graphics;
2021-04-01 16:40:14 +02:00
DescriptorLayout &layout;
2020-10-03 11:00:10 +02:00
const static int maxSets = 512;
2021-04-13 23:09:16 +02:00
StaticArray<PDescriptorSet, maxSets> cachedHandles;
2020-05-05 01:51:13 +02:00
VkDescriptorPool poolHandle;
};
2021-04-01 16:40:14 +02:00
DEFINE_REF(DescriptorAllocator)
2020-04-12 15:47:19 +02:00
} // namespace Vulkan
} // namespace Seele