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

109 lines
4.0 KiB
C++
Raw Normal View History

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"
2025-02-28 16:56:51 +09:00
#include "Graphics/Vulkan/Buffer.h"
2023-10-26 18:37:29 +02:00
#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)
2025-03-07 21:48:27 +01:00
struct DescriptorMapping {
2025-02-28 16:56:51 +09:00
uint32 binding;
uint32 constantOffset;
uint32 constantSize;
2025-03-07 21:48:27 +01:00
VkDescriptorType type;
2025-02-28 16:56:51 +09:00
};
2024-04-13 23:51:38 +02:00
class DescriptorLayout : public Gfx::DescriptorLayout {
2024-06-09 12:20:04 +02:00
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create() override;
constexpr VkDescriptorSetLayout getHandle() const { return layoutHandle; }
2024-04-13 23:51:38 +02:00
2024-06-09 12:20:04 +02:00
private:
PGraphics graphics;
2025-03-07 21:48:27 +01:00
uint32 constantsSize = 0;
2025-03-26 13:38:48 +01:00
VkShaderStageFlags constantsStages = 0;
2024-06-09 12:20:04 +02:00
Array<VkDescriptorSetLayoutBinding> bindings;
2025-02-28 16:56:51 +09:00
Map<std::string, DescriptorMapping> mappings;
2024-06-09 12:20:04 +02:00
VkDescriptorSetLayout layoutHandle;
friend class DescriptorPool;
2025-02-28 16:56:51 +09:00
friend class DescriptorSet;
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)
2024-05-15 15:27:13 +02:00
class DescriptorPool : public Gfx::DescriptorPool, public CommandBoundResource {
2024-06-09 12:20:04 +02:00
public:
DescriptorPool(PGraphics graphics, PDescriptorLayout layout);
virtual ~DescriptorPool();
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
virtual void reset() override;
2024-04-13 23:51:38 +02:00
2024-06-09 12:20:04 +02:00
constexpr VkDescriptorPool getHandle() const { return poolHandle; }
constexpr PDescriptorLayout getLayout() const { return layout; }
2020-04-12 15:47:19 +02:00
2024-06-09 12:20:04 +02:00
private:
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-05-15 15:27:13 +02:00
class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
2024-06-09 12:20:04 +02:00
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet();
virtual void writeChanges() override;
2025-02-28 16:56:51 +09:00
virtual void updateConstants(const std::string& name, uint32 offset, void* data) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer shaderBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer indexBuffer) override;
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) override;
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
2025-04-04 14:44:53 +02:00
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture texture) override;
2025-02-28 16:56:51 +09:00
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
2024-04-13 23:51:38 +02:00
2024-06-09 12:20:04 +02:00
constexpr VkDescriptorSet getHandle() const { return setHandle; }
2021-04-13 23:09:16 +02:00
2024-06-09 12:20:04 +02:00
private:
2025-02-28 16:56:51 +09:00
std::vector<uint8> constantData;
2025-03-07 21:48:27 +01:00
OBufferAllocation constantsBuffer;
2024-06-09 12:20:04 +02:00
List<VkDescriptorImageInfo> imageInfos;
List<VkDescriptorBufferInfo> bufferInfos;
2024-07-10 21:07:10 +02:00
List<VkWriteDescriptorSetAccelerationStructureKHR> accelerationInfos;
2024-06-09 12:20:04 +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
// Array<void*> cachedData;
2024-09-27 15:57:37 +02:00
Array<Array<PCommandBoundResource>> boundResources;
2024-06-09 12:20:04 +02:00
VkDescriptorSet setHandle;
PGraphics graphics;
PDescriptorPool owner;
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 {
2024-06-09 12:20:04 +02:00
public:
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout);
virtual ~PipelineLayout();
virtual void create();
constexpr VkPipelineLayout getHandle() const { return layoutHandle; }
2020-05-05 01:51:13 +02:00
2024-06-09 12:20:04 +02:00
private:
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