2023-10-26 18:37:29 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include "Enums.h"
|
2024-06-09 10:44:24 +02:00
|
|
|
#include "Initializer.h"
|
2024-06-09 12:20:04 +02:00
|
|
|
#include "Resources.h"
|
|
|
|
|
|
2024-04-13 23:51:38 +02:00
|
|
|
namespace Seele {
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
struct DescriptorBinding {
|
2024-06-09 12:20:04 +02:00
|
|
|
uint32 binding = 0;
|
|
|
|
|
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
|
|
|
|
SeImageViewType textureType = SE_IMAGE_VIEW_TYPE_2D;
|
|
|
|
|
uint32 descriptorCount = 1;
|
|
|
|
|
SeDescriptorBindingFlags bindingFlags = 0;
|
|
|
|
|
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
|
|
|
|
|
Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT;
|
2023-10-26 18:37:29 +02:00
|
|
|
};
|
2024-04-13 23:51:38 +02:00
|
|
|
|
|
|
|
|
DECLARE_REF(DescriptorPool)
|
|
|
|
|
DECLARE_REF(DescriptorSet)
|
|
|
|
|
class DescriptorLayout {
|
2024-06-09 12:20:04 +02:00
|
|
|
public:
|
|
|
|
|
DescriptorLayout(const std::string& name);
|
|
|
|
|
DescriptorLayout(const DescriptorLayout& other);
|
|
|
|
|
DescriptorLayout& operator=(const DescriptorLayout& other);
|
|
|
|
|
virtual ~DescriptorLayout();
|
|
|
|
|
void addDescriptorBinding(DescriptorBinding binding);
|
|
|
|
|
void reset();
|
|
|
|
|
PDescriptorSet allocateDescriptorSet();
|
|
|
|
|
virtual void create() = 0;
|
|
|
|
|
constexpr const Array<DescriptorBinding>& getBindings() const { return descriptorBindings; }
|
|
|
|
|
constexpr uint32 getHash() const { return hash; }
|
|
|
|
|
constexpr const std::string& getName() const { return name; }
|
2024-04-13 23:51:38 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
protected:
|
|
|
|
|
Array<DescriptorBinding> descriptorBindings;
|
|
|
|
|
ODescriptorPool pool;
|
|
|
|
|
std::string name;
|
|
|
|
|
uint32 hash = 0;
|
|
|
|
|
friend class PipelineLayout;
|
|
|
|
|
friend class DescriptorPool;
|
2024-04-13 23:51:38 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorLayout)
|
2023-10-26 18:37:29 +02:00
|
|
|
|
|
|
|
|
DECLARE_REF(DescriptorSet)
|
2024-04-13 23:51:38 +02:00
|
|
|
class DescriptorPool {
|
2024-06-09 12:20:04 +02:00
|
|
|
public:
|
|
|
|
|
DescriptorPool();
|
|
|
|
|
virtual ~DescriptorPool();
|
|
|
|
|
virtual PDescriptorSet allocateDescriptorSet() = 0;
|
|
|
|
|
virtual void reset() = 0;
|
2023-10-26 18:37:29 +02:00
|
|
|
};
|
2023-11-15 17:42:57 +01:00
|
|
|
DEFINE_REF(DescriptorPool)
|
2023-10-26 18:37:29 +02:00
|
|
|
DECLARE_REF(UniformBuffer)
|
|
|
|
|
DECLARE_REF(ShaderBuffer)
|
|
|
|
|
DECLARE_REF(Texture)
|
2024-06-20 21:57:26 +02:00
|
|
|
DECLARE_REF(Texture2D)
|
2023-11-15 00:06:00 +01:00
|
|
|
DECLARE_REF(Sampler)
|
2024-07-10 21:07:10 +02:00
|
|
|
DECLARE_REF(TopLevelAS)
|
2024-04-13 23:51:38 +02:00
|
|
|
class DescriptorSet {
|
2024-06-09 12:20:04 +02:00
|
|
|
public:
|
|
|
|
|
DescriptorSet(PDescriptorLayout layout);
|
|
|
|
|
virtual ~DescriptorSet();
|
|
|
|
|
virtual void writeChanges() = 0;
|
|
|
|
|
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
|
2024-07-10 21:07:10 +02:00
|
|
|
virtual void updateBuffer(uint32 binding, PIndexBuffer indexBuffer) = 0;
|
|
|
|
|
virtual void updateBuffer(uint32 binding, PShaderBuffer shaderBuffer) = 0;
|
2024-06-09 12:20:04 +02:00
|
|
|
virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
|
|
|
|
|
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
|
2024-06-20 21:57:26 +02:00
|
|
|
virtual void updateTextureArray(uint32_t binding, Array<PTexture2D> texture) = 0;
|
|
|
|
|
virtual void updateSamplerArray(uint32_t binding, Array<PSampler> samplers) = 0;
|
2024-07-10 21:07:10 +02:00
|
|
|
virtual void updateAccelerationStructure(uint32 binding, PTopLevelAS as) = 0;
|
2024-06-09 12:20:04 +02:00
|
|
|
bool operator<(PDescriptorSet other);
|
2023-10-26 18:37:29 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
constexpr PDescriptorLayout getLayout() const { return layout; }
|
|
|
|
|
constexpr const std::string& getName() const { return layout->getName(); }
|
2024-04-13 23:51:38 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
protected:
|
|
|
|
|
PDescriptorLayout layout;
|
2023-10-26 18:37:29 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorSet)
|
|
|
|
|
|
2024-06-09 10:44:24 +02:00
|
|
|
DECLARE_REF(PipelineLayout)
|
2024-04-13 23:51:38 +02:00
|
|
|
class PipelineLayout {
|
2024-06-09 12:20:04 +02:00
|
|
|
public:
|
|
|
|
|
PipelineLayout(const std::string& name);
|
|
|
|
|
PipelineLayout(const std::string& name, PPipelineLayout baseLayout);
|
|
|
|
|
virtual ~PipelineLayout();
|
|
|
|
|
virtual void create() = 0;
|
|
|
|
|
void addDescriptorLayout(PDescriptorLayout layout);
|
|
|
|
|
void addPushConstants(const SePushConstantRange& pushConstants);
|
|
|
|
|
constexpr uint32 getHash() const { return layoutHash; }
|
|
|
|
|
constexpr const Map<std::string, PDescriptorLayout>& getLayouts() const { return descriptorSetLayouts; }
|
|
|
|
|
constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; }
|
2024-07-10 21:07:10 +02:00
|
|
|
void addMapping(std::string name, uint32 index);
|
2024-06-09 12:20:04 +02:00
|
|
|
constexpr std::string getName() const { return name; };
|
2024-09-16 13:00:53 +02:00
|
|
|
constexpr bool hasPushConstants() const { return !pushConstants.empty(); }
|
|
|
|
|
constexpr uint64 getPushConstantsSize() const { return pushConstants[0].size; }
|
2024-04-20 21:35:43 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
protected:
|
|
|
|
|
uint32 layoutHash = 0;
|
|
|
|
|
Map<std::string, PDescriptorLayout> descriptorSetLayouts;
|
|
|
|
|
Map<std::string, uint32> parameterMapping;
|
|
|
|
|
Array<SePushConstantRange> pushConstants;
|
|
|
|
|
std::string name;
|
2023-10-26 18:37:29 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(PipelineLayout)
|
2024-04-13 23:51:38 +02:00
|
|
|
} // namespace Gfx
|
|
|
|
|
} // namespace Seele
|