vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
GraphicsPipelineConfigurator.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2022 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/state/BindDescriptorSet.h>
16#include <vsg/state/ColorBlendState.h>
17#include <vsg/state/DepthStencilState.h>
18#include <vsg/state/DescriptorBuffer.h>
19#include <vsg/state/DescriptorImage.h>
20#include <vsg/state/DescriptorSetLayout.h>
21#include <vsg/state/DynamicState.h>
22#include <vsg/state/GraphicsPipeline.h>
23#include <vsg/state/InputAssemblyState.h>
24#include <vsg/state/MultisampleState.h>
25#include <vsg/state/RasterizationState.h>
26#include <vsg/state/TessellationState.h>
27#include <vsg/state/VertexInputState.h>
28#include <vsg/state/ViewportState.h>
29#include <vsg/utils/ShaderSet.h>
30#include <vsg/utils/SharedObjects.h>
31
32namespace vsg
33{
34
36 class VSG_DECLSPEC DescriptorConfigurator : public vsg::Inherit<Object, DescriptorConfigurator>
37 {
38 public:
40
41 ref_ptr<ShaderSet> shaderSet;
42 bool blending = false;
43 bool two_sided = false;
44
45 int compare(const Object& rhs) const override;
46
47 void reset();
48
49 bool enableTexture(const std::string& name);
50 bool assignTexture(const std::string& name, ref_ptr<Data> textureData = {}, ref_ptr<Sampler> sampler = {}, uint32_t dstArrayElement = 0);
51 bool assignTexture(const std::string& name, const ImageInfoList& imageInfoList, uint32_t dstArrayElement = 0);
52
53 bool enableDescriptor(const std::string& name);
54 bool assignDescriptor(const std::string& name, ref_ptr<Data> data = {}, uint32_t dstArrayElement = 0);
55 bool assignDescriptor(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0);
56
57 [[deprecated("use enableDescriptor(..)")]] bool enableUniform(const std::string& name) { return enableDescriptor(name); }
58
59 [[deprecated("use assignDescriptor(..)")]] bool assignUniform(const std::string& name, ref_ptr<Data> data = {}, uint32_t dstArrayElement = 0) { return assignDescriptor(name, data, dstArrayElement); }
60
61 [[deprecated("use assignDescriptor(..)")]] bool assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0) { return assignDescriptor(name, bufferInfoList, dstArrayElement); }
62
63 bool assignDescriptor(uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Descriptor> descriptor);
64
66 bool assignDefaults(const std::set<uint32_t>& inheritedSets = {});
67
68 std::set<std::string> assigned;
69 std::set<std::string> defines;
70 std::vector<ref_ptr<DescriptorSet>> descriptorSets;
71 };
72 VSG_type_name(vsg::DescriptorConfigurator);
73
75 class VSG_DECLSPEC ArrayConfigurator : public vsg::Inherit<Object, ArrayConfigurator>
76 {
77 public:
78 ArrayConfigurator(ref_ptr<ShaderSet> in_shaderSet = {});
79
80 ref_ptr<ShaderSet> shaderSet;
81
82 int compare(const Object& rhs) const override;
83 bool assignArray(const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr<Data> array);
84
85 uint32_t baseAttributeBinding = 0;
86 std::set<std::string> assigned;
87 std::set<std::string> defines;
89 VertexInputState::Bindings vertexBindingDescriptions;
90 VertexInputState::Attributes vertexAttributeDescriptions;
91
92 DataList arrays;
93 };
94 VSG_type_name(vsg::ArrayConfigurator);
95
97 class VSG_DECLSPEC GraphicsPipelineConfigurator : public vsg::Inherit<Object, GraphicsPipelineConfigurator>
98 {
99 public:
101
102 void traverse(Visitor& visitor) override;
103 void traverse(ConstVisitor& visitor) const override;
104
105 // inputs to setup of GraphicsPipeline, the default sets are taken from any provided by ShaderSet::defaultGraphicsPipelineStates
106 GraphicsPipelineStates pipelineStates;
107
108 uint32_t subpass = 0;
109 uint32_t baseAttributeBinding = 0;
110 ref_ptr<ShaderSet> shaderSet;
111
112 void reset();
113
114 bool enableArray(const std::string& name, VkVertexInputRate vertexInputRate, uint32_t stride, VkFormat format = VK_FORMAT_UNDEFINED);
115 bool enableDescriptor(const std::string& name);
116 bool enableTexture(const std::string& name);
117
118 bool assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr<Data> array);
119 bool assignDescriptor(const std::string& name, ref_ptr<Data> data = {}, uint32_t dstArrayElement = 0);
120 bool assignDescriptor(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0);
121 bool assignTexture(const std::string& name, ref_ptr<Data> textureData = {}, ref_ptr<Sampler> sampler = {}, uint32_t dstArrayElement = 0);
122 bool assignTexture(const std::string& name, const ImageInfoList& imageInfoList, uint32_t dstArrayElement = 0);
123
125 void assignInheritedState(const StateCommands& stateCommands);
126
127 [[deprecated("use enableDescriptor(..)")]] bool enableUniform(const std::string& name) { return enableDescriptor(name); }
128
129 [[deprecated("use assignDescriptor(..)")]] bool assignUniform(const std::string& name, ref_ptr<Data> data = {}) { return assignDescriptor(name, data); }
130
131 // setup by assign calls
132 ref_ptr<ShaderCompileSettings> shaderHints;
133 ref_ptr<DescriptorConfigurator> descriptorConfigurator;
134 StateCommands inheritedState;
135
136 int compare(const Object& rhs) const override;
137
139 virtual void init();
140
143
145 virtual bool copyTo(StateCommands& stateCommands, ref_ptr<SharedObjects> sharedObjects = {});
146
148 virtual bool copyTo(ref_ptr<StateGroup> stateGroup, ref_ptr<SharedObjects> sharedObjects = {});
149
150 // setup by init()
151 std::set<uint32_t> inheritedSets;
153 ref_ptr<GraphicsPipeline> graphicsPipeline;
154 ref_ptr<BindGraphicsPipeline> bindGraphicsPipeline;
155
156 protected:
157 void _assignShaderSetSettings();
158 void _assignInheritedSets();
159 };
161
163 using GraphicsPipelineConfig = GraphicsPipelineConfigurator;
164 using DescriptorConfig = DescriptorConfigurator;
165
166} // namespace vsg
ArrayConfigurator utility provides a means of setting up arrays using ShaderSet as a guide for requir...
Definition GraphicsPipelineConfigurator.h:76
VertexInputState::Bindings vertexBindingDescriptions
VkPipelineVertexInputStateCreateInfo settings.
Definition GraphicsPipelineConfigurator.h:89
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 ConstVisitor.h:172
DescriptorConfigurator utility provides a means of setting up descriptors using ShaderSet as a guide ...
Definition GraphicsPipelineConfigurator.h:37
bool assignDefaults(const std::set< uint32_t > &inheritedSets={})
call after all the textures/uniforms have been explictly assigned to add in textures/uniforms descrip...
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,...
GraphicsPipelineConfigurator utility provides a means of setting up state and geometry using ShaderSe...
Definition GraphicsPipelineConfigurator.h:98
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 copyTo(ref_ptr< StateGroup > stateGroup, ref_ptr< SharedObjects > sharedObjects={})
copy state objects to StateGroup, return true if state is added.
virtual ref_ptr< ArrayState > getSuitableArrayState() const
convinience function for calling shaderSet->getSuitableArrayState(shaderHints->defines) to return the...
virtual void init()
initialize state objects
virtual bool copyTo(StateCommands &stateCommands, ref_ptr< SharedObjects > sharedObjects={})
copy state objects to StateCommands list, return true if is add added.
void assignInheritedState(const StateCommands &stateCommands)
set the inherited state which if compatible can hint the the state setup and copying to avoid setting...
Definition Inherit.h:28
Definition Object.h:60
Definition Visitor.h:172
Definition ref_ptr.h:22