15#include <vsg/core/compare.h>
16#include <vsg/state/ArrayState.h>
17#include <vsg/state/GraphicsPipeline.h>
18#include <vsg/state/Sampler.h>
19#include <vsg/state/ShaderStage.h>
20#include <vsg/utils/CoordinateSpace.h>
29 uint32_t location = 0;
30 VkFormat format = VK_FORMAT_UNDEFINED;
31 CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE;
36 explicit operator bool()
const noexcept {
return !name.empty(); }
46 VkDescriptorType descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
47 uint32_t descriptorCount = 0;
48 VkShaderStageFlags stageFlags = 0;
49 CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE;
54 explicit operator bool()
const noexcept {
return !name.empty(); }
62 VkPushConstantRange range;
70 std::set<std::string> defines;
78 struct VSG_DECLSPEC CustomDescriptorSetBinding :
public Inherit<Object, CustomDescriptorSetBinding>
80 explicit CustomDescriptorSetBinding(uint32_t in_set = 0);
86 void read(
Input& input)
override;
87 void write(
Output& output)
const override;
96 struct VSG_DECLSPEC ViewDependentStateBinding :
public Inherit<CustomDescriptorSetBinding, ViewDependentStateBinding>
98 explicit ViewDependentStateBinding(uint32_t in_set = 0);
102 void read(
Input& input)
override;
103 void write(
Output& output)
const override;
114 class VSG_DECLSPEC ShaderSet :
public Inherit<Object, ShaderSet>
123 std::vector<AttributeBinding> attributeBindings;
124 std::vector<DescriptorBinding> descriptorBindings;
125 std::vector<PushConstantRange> pushConstantRanges;
126 std::vector<DefinesArrayState> definesArrayStates;
127 std::set<std::string> optionalDefines;
128 GraphicsPipelineStates defaultGraphicsPipelineStates;
129 std::vector<ref_ptr<CustomDescriptorSetBinding>> customDescriptorSetBindings;
139 void addAttributeBinding(
const std::string& name,
const std::string& define, uint32_t location, VkFormat format,
ref_ptr<Data> data, CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE);
142 void addDescriptorBinding(
const std::string& name,
const std::string& define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags,
ref_ptr<Data> data, CoordinateSpace coordinateSpace = CoordinateSpace::NO_PREFERENCE);
144 [[deprecated(
"use addDescriptorBinding(..)")]]
void addUniformBinding(
const std::string& name,
const std::string& define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags,
ref_ptr<Data> data) {
addDescriptorBinding(name, define, set, binding, descriptorType, descriptorCount, stageFlags, data); }
147 void addPushConstantRange(
const std::string& name,
const std::string& define, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size);
163 [[deprecated(
"use getDescriptorBinding(..)")]]
const DescriptorBinding& getUnifomrBinding(
const std::string& name)
const {
return getDescriptorBinding(name); }
195 void read(
Input& input)
override;
196 void write(
Output& output)
const override;
199 virtual ~ShaderSet();
210 extern VSG_DECLSPEC ref_ptr<ShaderSet> createPhongShaderSet(ref_ptr<const Options> options = {});
DescriptorSetLayout encapsulates VkDescriptorSetLayout and VkDescriptorSetLayoutCreateInfo settings u...
Definition DescriptorSetLayout.h:28
PipelineLayout encapsulates VkPipelineLayout and the VkPipelineLayoutCreateInfo settings used to set ...
Definition PipelineLayout.h:27
ShaderSet provides a collection of shader related settings to provide a form of shader introspection.
Definition ShaderSet.h:115
std::mutex mutex
mutex used by getShaderStages(..) to ensure the variants map can be used from multiple threads.
Definition ShaderSet.h:136
ref_ptr< ArrayState > getSuitableArrayState(const std::set< std::string > &defines) const
get the first ArrayState that has matches with defines in the specified list of defines.
void addAttributeBinding(const std::string &name, const std::string &define, uint32_t location, VkFormat format, ref_ptr< Data > data, CoordinateSpace coordinateSpace=CoordinateSpace::NO_PREFERENCE)
add an attribute binding, Not thread safe, should only be called when initially setting up the Shader...
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
virtual bool compatibleDescriptorSetLayout(const DescriptorSetLayout &dsl, const std::set< std::string > &defines, uint32_t set) const
return true of specified descriptor set layout is compatible with what is required for this ShaderSet
const AttributeBinding & getAttributeBinding(const std::string &name) const
get the const AttributeBinding associated with name
void addPushConstantRange(const std::string &name, const std::string &define, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size)
add a push constant range. Not thread safe, should only be called when initially setting up the Shade...
const DescriptorBinding & getDescriptorBinding(const std::string &name) const
get the const DescriptorBinding associated with name
virtual ref_ptr< DescriptorSetLayout > createDescriptorSetLayout(const std::set< std::string > &defines, uint32_t set) const
create the descriptor set layout.
AttributeBinding & getAttributeBinding(const std::string &name)
get the AttributeBinding associated with name
ShaderStages getShaderStages(ref_ptr< ShaderCompileSettings > scs={})
get the ShaderStages variant that uses specified ShaderCompileSettings.
std::pair< uint32_t, uint32_t > descriptorSetRange() const
return the <minimum_set, maximum_set+1> range of set numbers encompassing DescriptorBindings
ShaderStages stages
base ShaderStages that other variants are based on.
Definition ShaderSet.h:121
DescriptorBinding & getDescriptorBinding(const std::string &name)
get the DescriptorBinding associated with name
virtual ref_ptr< PipelineLayout > createPipelineLayout(const std::set< std::string > &defines, std::pair< uint32_t, uint32_t > range) const
std::map< ref_ptr< ShaderCompileSettings >, ShaderStages, DereferenceLess > variants
variants of the rootShaderModule compiled for different combinations of ShaderCompileSettings
Definition ShaderSet.h:133
virtual bool compatiblePipelineLayout(const PipelineLayout &layout, const std::set< std::string > &defines) const
return true of specified pipline layout is compatible with what is required for this ShaderSet
void addDescriptorBinding(const std::string &name, const std::string &define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr< Data > data, CoordinateSpace coordinateSpace=CoordinateSpace::NO_PREFERENCE)
add an uniform binding. Not thread safe, should only be called when initially setting up the ShaderSe...
ref_ptr< PipelineLayout > createPipelineLayout(const std::set< std::string > &defines)
create the pipeline layout for all descriptor sets enabled by specified defines or required by defaul...
Definition ShaderSet.h:184
Definition ShaderSet.h:26
Base class for specifying custom DescriptorSetLayout and StateCommand.
Definition ShaderSet.h:79
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition ShaderSet.h:69
less functor for comparing ref_ptr<Object> typically used with std::set<> etc.
Definition compare.h:107
Definition ShaderSet.h:41
Definition ShaderSet.h:59
Custom state binding class for providing the DescriptorSetLayout and StateCommand required to pass vi...
Definition ShaderSet.h:97
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...