vsg: include/vsg/state/BindDescriptorSet.h Source File

vsg 1.1.10 VulkanSceneGraph library |

Loading...
Searching...
No Matches
BindDescriptorSet.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 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/DescriptorSet.h>
16#include <vsg/state/PipelineLayout.h>
17#include <vsg/state/StateCommand.h>
18#include <vsg/vk/DescriptorPool.h>
19
20namespace vsg
21{
22
24 class VSG_DECLSPEC BindDescriptorSets : public Inherit<StateCommand, BindDescriptorSets>
25 {
26 public:
27 BindDescriptorSets();
28 BindDescriptorSets(const BindDescriptorSets& rhs, const CopyOp& copyop = {});
29
30 BindDescriptorSets(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_layout, uint32_t in_firstSet, const DescriptorSets& in_descriptorSets) :
31 Inherit(1 + in_firstSet),
32 pipelineBindPoint(in_bindPoint),
33 layout(in_layout),
34 firstSet(in_firstSet),
35 descriptorSets(in_descriptorSets)
36 {
37 }
38
39 BindDescriptorSets(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_layout, const DescriptorSets& in_descriptorSets) :
40 Inherit(1), // slot 1
41 pipelineBindPoint(in_bindPoint),
42 layout(in_layout),
43 firstSet(0),
44 descriptorSets(in_descriptorSets)
45 {
46 }
47
49 VkPipelineBindPoint pipelineBindPoint;
50 ref_ptr<PipelineLayout> layout;
51 uint32_t firstSet;
52 DescriptorSets descriptorSets;
53 std::vector<uint32_t> dynamicOffsets;
54
55 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return BindDescriptorSets::create(*this, copyop); }
56 int compare(const Object& rhs_object) const override;
57
58 template<class N, class V>
59 static void t_traverse(N& bds, V& visitor)
60 {
61 if (bds.layout) bds.layout->accept(visitor);
62 for (auto& ds : bds.descriptorSets) ds->accept(visitor);
63 }
64
65 void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
66 void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
67
68 void read(Input& input) override;
69 void write(Output& output) const override;
70
71 // compile the Vulkan object, context parameter used for Device
72 void compile(Context& context) override;
73
74 void record(CommandBuffer& commandBuffer) const override;
75
76 protected:
77 virtual ~BindDescriptorSets() {}
78
79 struct VulkanData
80 {
81 VkPipelineLayout _vkPipelineLayout = 0;
82 std::vector<VkDescriptorSet> _vkDescriptorSets;
83 };
84
85 vk_buffer<VulkanData> _vulkanData;
86 };
87 VSG_type_name(vsg::BindDescriptorSets);
88
91 class VSG_DECLSPEC BindDescriptorSet : public Inherit<StateCommand, BindDescriptorSet>
92 {
93 public:
94 BindDescriptorSet();
95 BindDescriptorSet(const BindDescriptorSet& rhs, const CopyOp& copyop = {});
96
97 BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, uint32_t in_firstSet, DescriptorSet* in_descriptorSet) :
98 Inherit(1 + in_firstSet),
99 pipelineBindPoint(in_bindPoint),
100 layout(in_pipelineLayout),
101 firstSet(in_firstSet),
102 descriptorSet(in_descriptorSet)
103 {
104 }
105
106 BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, DescriptorSet* in_descriptorSet) :
107 Inherit(1), // slot 1
108 pipelineBindPoint(in_bindPoint),
109 layout(in_pipelineLayout),
110 firstSet(0),
111 descriptorSet(in_descriptorSet)
112 {
113 }
114
116 BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, uint32_t in_firstSet, const vsg::Descriptors& in_descriptors) :
117 Inherit(1 + in_firstSet),
118 pipelineBindPoint(in_bindPoint),
119 layout(in_pipelineLayout),
120 firstSet(in_firstSet),
121 descriptorSet(vsg::DescriptorSet::create(in_pipelineLayout->setLayouts[in_firstSet], in_descriptors))
122 {
123 }
124
125 // vkCmdBindDescriptorSets settings
126 VkPipelineBindPoint pipelineBindPoint;
127 ref_ptr<PipelineLayout> layout;
128 uint32_t firstSet;
129 ref_ptr<DescriptorSet> descriptorSet;
130 std::vector<uint32_t> dynamicOffsets;
131
132 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return BindDescriptorSet::create(*this, copyop); }
133 int compare(const Object& rhs_object) const override;
134
135 template<class N, class V>
136 static void t_traverse(N& bds, V& visitor)
137 {
138 if (bds.layout) bds.layout->accept(visitor);
139 if (bds.descriptorSet) bds.descriptorSet->accept(visitor);
140 }
141
142 void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
143 void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
144
145 void read(Input& input) override;
146 void write(Output& output) const override;
147
148 // compile the Vulkan object, context parameter used for Device
149 void compile(Context& context) override;
150
151 void record(CommandBuffer& commandBuffer) const override;
152
153 protected:
154 virtual ~BindDescriptorSet() {}
155
156 struct VulkanData
157 {
158 VkPipelineLayout _vkPipelineLayout = 0;
159 VkDescriptorSet _vkDescriptorSet = VK_NULL_HANDLE;
160 };
161
162 vk_buffer<VulkanData> _vulkanData;
163 };
164 VSG_type_name(vsg::BindDescriptorSet);
165
166} // namespace vsg
vsg::BindDescriptorSet
Definition BindDescriptorSet.h:92
vsg::BindDescriptorSet::BindDescriptorSet
BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout *in_pipelineLayout, uint32_t in_firstSet, const vsg::Descriptors &in_descriptors)
convenience BindDescriptorSet constructor which creates and assigns the DescriptorSet required for sp...
Definition BindDescriptorSet.h:116
vsg::BindDescriptorSet::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition BindDescriptorSet.h:132
vsg::BindDescriptorSet::compare
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::BindDescriptorSets
BindDescriptorSets state command encapsulates vkCmdBindDescriptorSets call and associated settings fo...
Definition BindDescriptorSet.h:25
vsg::BindDescriptorSets::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition BindDescriptorSet.h:55
vsg::BindDescriptorSets::compare
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::BindDescriptorSets::pipelineBindPoint
VkPipelineBindPoint pipelineBindPoint
vkCmdBindDescriptorSets settings
Definition BindDescriptorSet.h:49
vsg::CopyOp
Definition Object.h:42
vsg::DescriptorSet
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition DescriptorSet.h:26
vsg::Object
Definition Object.h:60
vsg::PipelineLayout
PipelineLayout encapsulates VkPipelineLayout and the VkPipelineLayoutCreateInfo settings used to set ...
Definition PipelineLayout.h:27
vsg::Visitor
Definition Visitor.h:175
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::BindDescriptorSet::VulkanData
Definition BindDescriptorSet.h:157
vsg::BindDescriptorSets::VulkanData
Definition BindDescriptorSet.h:80
vsg::vk_buffer
vk_buffer that manages a single logical device supported.
Definition vk_buffer.h:28