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

151 lines
3.8 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-10-16 12:59:11 +02:00
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create();
inline VkDescriptorSetLayout getHandle() const
{
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;
std::string name;
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:
2021-10-16 12:59:11 +02:00
PipelineLayout(PGraphics graphics)
: graphics(graphics)
, layoutHash(0)
, layoutHandle(VK_NULL_HANDLE)
{
}
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);
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;
}
inline bool isCurrentlyInUse() const
{
return currentlyInUse;
}
void bind()
2021-10-16 12:59:11 +02:00
{
currentlyBound = true;
}
void unbind()
{
currentlyBound = false;
}
void allocate()
{
currentlyInUse = true;
}
void free()
{
currentlyInUse = false;
}
inline VkDescriptorSet getHandle() const
{
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;
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();
virtual void allocateDescriptorSet(Gfx::PDescriptorSet &descriptorSet);
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;
const static int maxSets = 512;
StaticArray<PDescriptorSet, maxSets> cachedHandles;
VkDescriptorPool poolHandle;
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