Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_descriptorset.hpp
Go to the documentation of this file.
1#pragma once
5#include <unordered_map>
6
7namespace foray::core {
8
14 class DescriptorSet : public VulkanResource<VkObjectType::VK_OBJECT_TYPE_DESCRIPTOR_SET>
15 {
16 public:
22 void Create(Context* context,
23 std::string debugName,
24 VkDescriptorSetLayout predefinedLayout = VK_NULL_HANDLE,
25 VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags = 0);
27 void Update();
29 virtual void Destroy() override;
31
35 void SetDescriptorAt(uint32_t binding, const std::vector<const ManagedBuffer*>& buffers, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
39 void SetDescriptorAt(uint32_t binding, const ManagedBuffer& buffer, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
43 void SetDescriptorAt(uint32_t binding, const ManagedBuffer* buffer, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
44
50 void SetDescriptorAt(uint32_t binding,
51 const std::vector<const ManagedImage*>& images,
52 VkImageLayout layout,
53 VkSampler sampler,
54 VkDescriptorType descriptorType,
55 VkShaderStageFlags shaderStageFlags);
61 uint32_t binding, const ManagedImage* image, VkImageLayout layout, VkSampler sampler, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
67 uint32_t binding, const ManagedImage& image, VkImageLayout layout, VkSampler sampler, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
68
71 void SetDescriptorAt(uint32_t binding, const std::vector<VkDescriptorImageInfo>& imageInfos, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
74 void SetDescriptorAt(uint32_t binding, const std::vector<VkDescriptorBufferInfo>& bufferInfos, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
77 void SetDescriptorAt(uint32_t binding, const VkDescriptorImageInfo& imageInfo, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
80 void SetDescriptorAt(uint32_t binding, const VkDescriptorBufferInfo& bufferInfo, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
84 void SetDescriptorAt(uint32_t binding, void* pNext, uint32_t DescriptorCount, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
89 void SetDescriptorAt(uint32_t binding, const CombinedImageSampler& sampledImage, VkImageLayout layout, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
94 void SetDescriptorAt(uint32_t binding, const CombinedImageSampler* sampledImage, VkImageLayout layout, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
99 void SetDescriptorAt(uint32_t binding, const std::vector<const CombinedImageSampler*>& sampledImages, VkImageLayout layout, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags);
100
101 bool Exists() const override { return mDescriptorSet != VK_NULL_HANDLE; }
102
104 FORAY_GETTER_V(DescriptorSetLayout)
105
106 protected:
108 {
109 std::vector<VkDescriptorBufferInfo> BufferInfos;
110 std::vector<VkDescriptorImageInfo> ImageInfos;
111 void* pNext{nullptr};
112 VkDescriptorType DescriptorType;
114 VkShaderStageFlags ShaderStageFlags;
115 };
116
117 std::unordered_map<uint32_t, DescriptorInfo> mMapBindingToDescriptorInfo;
119 VkDescriptorPool mDescriptorPool{};
120 VkDescriptorSetLayout mDescriptorSetLayout{};
121 bool mExternalLayout = false;
122 VkDescriptorSet mDescriptorSet{};
123
125 void CreateDescriptorSetLayout(VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags);
126
127 void AssertBindingInUse(uint32_t binding);
128 void AssertHandleNotNull(void* handle, uint32_t binding);
129 };
130} // namespace foray::core
Wraps an image + sampler combination.
Definition foray_samplercollection.hpp:61
Helps with the creation of a VkDescriptorSetLayout and VkDescriptorSet.
Definition foray_descriptorset.hpp:15
void SetDescriptorAt(uint32_t binding, const std::vector< VkDescriptorBufferInfo > &bufferInfos, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (buffer info array)
void SetDescriptorAt(uint32_t binding, const CombinedImageSampler &sampledImage, VkImageLayout layout, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (CombinedImageSampler)
bool mExternalLayout
Definition foray_descriptorset.hpp:121
void SetDescriptorAt(uint32_t binding, const ManagedBuffer &buffer, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (buffer)
VkDescriptorPool mDescriptorPool
Definition foray_descriptorset.hpp:119
void SetDescriptorAt(uint32_t binding, const VkDescriptorImageInfo &imageInfo, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (image info)
Context * mContext
Definition foray_descriptorset.hpp:118
bool Exists() const override
Return true, if the managed resource is allocated.
Definition foray_descriptorset.hpp:101
void CreateDescriptorSetLayout(VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags)
void Create(Context *context, std::string debugName, VkDescriptorSetLayout predefinedLayout=VK_NULL_HANDLE, VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags=0)
Creates the VkDescriptorSet.
void AssertHandleNotNull(void *handle, uint32_t binding)
void SetDescriptorAt(uint32_t binding, const std::vector< const ManagedImage * > &images, VkImageLayout layout, VkSampler sampler, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (image array)
void SetDescriptorAt(uint32_t binding, const std::vector< const ManagedBuffer * > &buffers, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (buffer array)
void SetDescriptorAt(uint32_t binding, const VkDescriptorBufferInfo &bufferInfo, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (buffer info)
void SetDescriptorAt(uint32_t binding, const ManagedImage &image, VkImageLayout layout, VkSampler sampler, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (image)
virtual void Destroy() override
Destroys descriptorset and layout (latter only if also allocated by this object)
void SetDescriptorAt(uint32_t binding, void *pNext, uint32_t DescriptorCount, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (custom / .pNext)
void SetDescriptorAt(uint32_t binding, const std::vector< VkDescriptorImageInfo > &imageInfos, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (image info array)
void SetDescriptorAt(uint32_t binding, const std::vector< const CombinedImageSampler * > &sampledImages, VkImageLayout layout, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (CombinedImageSampler)
void Update()
Rather than reallocating the descriptorset, rewrites all bindings to the descriptor set.
VkDescriptorSetLayout mDescriptorSetLayout
Definition foray_descriptorset.hpp:120
void SetDescriptorAt(uint32_t binding, const ManagedImage *image, VkImageLayout layout, VkSampler sampler, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (image)
void SetDescriptorAt(uint32_t binding, const CombinedImageSampler *sampledImage, VkImageLayout layout, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (CombinedImageSampler)
VkDescriptorSet mDescriptorSet
Definition foray_descriptorset.hpp:122
void SetDescriptorAt(uint32_t binding, const ManagedBuffer *buffer, VkDescriptorType descriptorType, VkShaderStageFlags shaderStageFlags)
Set a binding (buffer)
void AssertBindingInUse(uint32_t binding)
std::unordered_map< uint32_t, DescriptorInfo > mMapBindingToDescriptorInfo
Definition foray_descriptorset.hpp:117
~DescriptorSet()
Definition foray_descriptorset.hpp:30
Wraps allocation and lifetime functionality of a VkBuffer.
Definition foray_managedbuffer.hpp:12
Wraps allocation and lifetime functionality of VkImage.
Definition foray_managedimage.hpp:13
ManagedResource variant which automates GetTypeName() overloading by returning a stringified version ...
Definition foray_managedresource.hpp:59
#define FORAY_GETTER_V(member)
Return value.
Definition foray_basics.hpp:39
Definition foray_commandbuffer.hpp:6
Non owning context object.
Definition foray_context.hpp:16
Definition foray_descriptorset.hpp:108
std::vector< VkDescriptorImageInfo > ImageInfos
Definition foray_descriptorset.hpp:110
void * pNext
Definition foray_descriptorset.hpp:111
uint32_t DescriptorCount
Definition foray_descriptorset.hpp:113
VkShaderStageFlags ShaderStageFlags
Definition foray_descriptorset.hpp:114
std::vector< VkDescriptorBufferInfo > BufferInfos
Definition foray_descriptorset.hpp:109
VkDescriptorType DescriptorType
Definition foray_descriptorset.hpp:112