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

121 lines
3.0 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
{
DECLARE_REF(Graphics);
class DescriptorLayout : public Gfx::DescriptorLayout
{
public:
2020-10-03 11:00:10 +02:00
DescriptorLayout(PGraphics graphics);
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;
2020-10-03 11:00:10 +02:00
friend class DescriptorAllocator;
2020-04-12 15:47:19 +02:00
};
DEFINE_REF(DescriptorLayout);
class PipelineLayout : public Gfx::PipelineLayout
{
public:
PipelineLayout(PGraphics graphics)
: graphics(graphics), layoutHash(0), layoutHandle(VK_NULL_HANDLE)
{
}
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;
uint32 layoutHash;
VkPipelineLayout layoutHandle;
PGraphics graphics;
};
DEFINE_REF(PipelineLayout);
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;
2020-10-03 11:00:10 +02:00
const static int maxSets = 512;
VkDescriptorSet cachedHandles[maxSets];
uint32 currentCachedIndex;
2020-05-05 01:51:13 +02:00
VkDescriptorPool poolHandle;
DescriptorLayout &layout;
};
DEFINE_REF(DescriptorAllocator);
2020-04-12 15:47:19 +02:00
class DescriptorSet : public Gfx::DescriptorSet
{
public:
DescriptorSet(PGraphics graphics, PDescriptorAllocator owner)
2020-10-14 01:49:43 +02:00
: graphics(graphics), owner(owner)
2020-04-12 15:47:19 +02:00
{
}
virtual ~DescriptorSet();
2020-10-03 11:00:10 +02:00
virtual void writeChanges();
2020-04-12 15:47:19 +02:00
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 VkDescriptorSet getHandle() const
{
2020-10-14 01:49:43 +02:00
return setHandle[Gfx::currentFrameIndex];
2020-04-12 15:47:19 +02:00
}
2020-05-05 01:51:13 +02:00
virtual uint32 getSetIndex() const
{
return owner->getLayout().getSetIndex();
}
2020-04-12 15:47:19 +02:00
private:
Array<VkDescriptorImageInfo> imageInfos;
Array<VkDescriptorBufferInfo> bufferInfos;
Array<VkWriteDescriptorSet> writeDescriptors;
2020-10-03 11:00:10 +02:00
// 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[Gfx::numFramesBuffered];
VkDescriptorSet setHandle[Gfx::numFramesBuffered];
2020-04-12 15:47:19 +02:00
PDescriptorAllocator owner;
PGraphics graphics;
friend class DescriptorAllocator;
};
DEFINE_REF(DescriptorSet);
} // namespace Vulkan
} // namespace Seele