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

102 lines
3.5 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#pragma once
#include "Enums.h"
#include "Resources.h"
2024-04-13 23:51:38 +02:00
#include <compare>
2023-10-26 18:37:29 +02:00
2024-04-13 23:51:38 +02:00
namespace Seele {
namespace Gfx {
struct DescriptorBinding {
uint32 binding = 0;
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2024-04-23 19:11:06 +02:00
SeImageViewType textureType = SE_IMAGE_VIEW_TYPE_2D;
uint32 descriptorCount = 1;
2024-04-13 23:51:38 +02:00
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 {
public:
DescriptorLayout(const std::string& name);
DescriptorLayout(const DescriptorLayout& other);
DescriptorLayout& operator=(const DescriptorLayout& other);
virtual ~DescriptorLayout();
2024-04-19 22:44:00 +02:00
void addDescriptorBinding(DescriptorBinding binding);
2024-04-13 23:51:38 +02:00
void reset();
PDescriptorSet allocateDescriptorSet();
virtual void create() = 0;
constexpr const Array<DescriptorBinding>& getBindings() const { return descriptorBindings; }
constexpr uint32 getHash() const { return hash; }
2024-04-19 18:23:36 +02:00
constexpr const std::string& getName() const { return name; }
2024-04-13 23:51:38 +02:00
protected:
Array<DescriptorBinding> descriptorBindings;
ODescriptorPool pool;
std::string name;
uint32 hash = 0;
friend class PipelineLayout;
friend class DescriptorPool;
};
DEFINE_REF(DescriptorLayout)
2023-10-26 18:37:29 +02:00
DECLARE_REF(DescriptorSet)
2024-04-13 23:51:38 +02:00
class DescriptorPool {
2023-10-26 18:37:29 +02:00
public:
2024-04-13 23:51:38 +02:00
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)
2023-11-15 00:06:00 +01:00
DECLARE_REF(Sampler)
2024-04-13 23:51:38 +02:00
class DescriptorSet {
2023-10-26 18:37:29 +02:00
public:
2024-04-13 23:51:38 +02:00
DescriptorSet(PDescriptorLayout layout);
virtual ~DescriptorSet();
virtual void writeChanges() = 0;
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
virtual void updateBuffer(uint32 binding, PShaderBuffer ShaderBuffer) = 0;
2024-05-06 18:36:16 +02:00
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0;
2024-04-13 23:51:38 +02:00
virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
virtual void updateTextureArray(uint32_t binding, Array<PTexture> texture) = 0;
bool operator<(PDescriptorSet other);
2023-10-26 18:37:29 +02:00
2024-04-19 18:23:36 +02:00
constexpr PDescriptorLayout getLayout() const { return layout; }
2024-04-23 08:11:44 +02:00
constexpr const std::string& getName() const { return layout->getName(); }
2024-04-13 23:51:38 +02:00
protected:
PDescriptorLayout layout;
2023-10-26 18:37:29 +02:00
};
DEFINE_REF(DescriptorSet)
2024-04-13 23:51:38 +02:00
class PipelineLayout {
2023-10-26 18:37:29 +02:00
public:
2024-04-20 21:35:43 +02:00
PipelineLayout(const std::string& name);
PipelineLayout(const std::string& name, PPipelineLayout baseLayout);
2024-04-13 23:51:38 +02:00
virtual ~PipelineLayout();
virtual void create() = 0;
2024-04-19 18:23:36 +02:00
void addDescriptorLayout(PDescriptorLayout layout);
2024-04-13 23:51:38 +02:00
void addPushConstants(const SePushConstantRange& pushConstants);
constexpr uint32 getHash() const { return layoutHash; }
2024-04-19 18:23:36 +02:00
constexpr const Map<std::string, PDescriptorLayout>& getLayouts() const { return descriptorSetLayouts; }
2024-04-23 08:11:44 +02:00
constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; }
2024-04-19 18:23:36 +02:00
void addMapping(Map<std::string, uint32> mapping);
2024-04-20 21:35:43 +02:00
constexpr std::string getName() const {return name;};
2023-10-26 18:37:29 +02:00
protected:
2024-04-13 23:51:38 +02:00
uint32 layoutHash = 0;
2024-04-19 18:23:36 +02:00
Map<std::string, PDescriptorLayout> descriptorSetLayouts;
Map<std::string, uint32> parameterMapping;
2024-04-13 23:51:38 +02:00
Array<SePushConstantRange> pushConstants;
2024-04-20 21:35:43 +02:00
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