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

123 lines
4.7 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 "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"
2025-08-10 19:16:55 +02:00
#include <vulkan/vulkan_core.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
2025-08-10 19:16:55 +02:00
class DescriptorSetHandle : public CommandBoundResource {
public:
DescriptorSetHandle(PGraphics graphics, const std::string& name);
virtual ~DescriptorSetHandle();
constexpr VkDescriptorSet getHandle() const { return handle; }
VkDescriptorSet handle = VK_NULL_HANDLE;
2025-08-14 11:06:43 +02:00
OBufferAllocation constantsBuffer;
bool isUsed = false;
2025-08-10 19:16:55 +02:00
};
DEFINE_REF(DescriptorSetHandle)
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();
2025-08-10 19:16:55 +02:00
virtual Gfx::ODescriptorSet allocateDescriptorSet() override;
2024-06-09 12:20:04 +02:00
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;
2025-08-10 19:16:55 +02:00
StaticArray<ODescriptorSetHandle, maxSets> cachedHandles;
2024-06-09 12:20:04 +02:00
VkDescriptorPool poolHandle;
DescriptorPool* nextAlloc = nullptr;
2020-04-12 15:47:19 +02:00
};
2024-04-13 23:51:38 +02:00
DEFINE_REF(DescriptorPool)
2025-08-10 19:16:55 +02:00
class DescriptorSet : public Gfx::DescriptorSet {
2024-06-09 12:20:04 +02:00
public:
2025-08-10 19:16:55 +02:00
DescriptorSet(PGraphics graphics, PDescriptorPool owner, PDescriptorSetHandle setHandle);
2024-06-09 12:20:04 +02:00
virtual ~DescriptorSet();
2026-04-12 20:49:02 +02:00
DescriptorSet(const DescriptorSet&) = delete;
DescriptorSet(DescriptorSet&&) noexcept;
DescriptorSet& operator=(const DescriptorSet&) = delete;
DescriptorSet& operator=(DescriptorSet&&) noexcept;
2024-06-09 12:20:04 +02:00
virtual void writeChanges() override;
virtual void updateConstants(const std::string& name, uint32 offset, const void* data) override;
2025-02-28 16:56:51 +09:00
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer shaderBuffer) override;
2025-08-08 22:29:54 +02:00
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer vertexBuffer) override;
2025-02-28 16:56:51 +09:00
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer indexBuffer) override;
2025-08-08 22:29:54 +02:00
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PUniformBuffer uniformBuffer) override;
2025-02-28 16:56:51 +09:00
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureView 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
2025-08-10 19:16:55 +02:00
constexpr VkDescriptorSet getHandle() const { return setHandle->getHandle(); }
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;
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;
2026-04-12 20:49:02 +02:00
PDescriptorSetHandle setHandle = nullptr;
2024-06-09 12:20:04 +02:00
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