vsg  1.1.0
VulkanSceneGraph library
BindDescriptorSet.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission 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 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE 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 
20 namespace vsg
21 {
22 
24  class VSG_DECLSPEC BindDescriptorSets : public Inherit<StateCommand, BindDescriptorSets>
25  {
26  public:
28 
29  BindDescriptorSets(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_layout, uint32_t in_firstSet, const DescriptorSets& in_descriptorSets) :
30  Inherit(1 + in_firstSet),
31  pipelineBindPoint(in_bindPoint),
32  layout(in_layout),
33  firstSet(in_firstSet),
34  descriptorSets(in_descriptorSets)
35  {
36  }
37 
38  BindDescriptorSets(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_layout, const DescriptorSets& in_descriptorSets) :
39  Inherit(1), // slot 1
40  pipelineBindPoint(in_bindPoint),
41  layout(in_layout),
42  firstSet(0),
43  descriptorSets(in_descriptorSets)
44  {
45  }
46 
48  VkPipelineBindPoint pipelineBindPoint;
50  uint32_t firstSet;
51  DescriptorSets descriptorSets;
52  std::vector<uint32_t> dynamicOffsets;
53 
54  int compare(const Object& rhs_object) const override;
55 
56  template<class N, class V>
57  static void t_traverse(N& bds, V& visitor)
58  {
59  if (bds.layout) bds.layout->accept(visitor);
60  for (auto& ds : bds.descriptorSets) ds->accept(visitor);
61  }
62 
63  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
64  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
65 
66  void read(Input& input) override;
67  void write(Output& output) const override;
68 
69  // compile the Vulkan object, context parameter used for Device
70  void compile(Context& context) override;
71 
72  void record(CommandBuffer& commandBuffer) const override;
73 
74  protected:
75  virtual ~BindDescriptorSets() {}
76 
77  struct VulkanData
78  {
79  VkPipelineLayout _vkPipelineLayout = 0;
80  std::vector<VkDescriptorSet> _vkDescriptorSets;
81  };
82 
83  vk_buffer<VulkanData> _vulkanData;
84  };
85  VSG_type_name(vsg::BindDescriptorSets);
86 
89  class VSG_DECLSPEC BindDescriptorSet : public Inherit<StateCommand, BindDescriptorSet>
90  {
91  public:
93 
94  BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, uint32_t in_firstSet, DescriptorSet* in_descriptorSet) :
95  Inherit(1 + in_firstSet),
96  pipelineBindPoint(in_bindPoint),
97  layout(in_pipelineLayout),
98  firstSet(in_firstSet),
99  descriptorSet(in_descriptorSet)
100  {
101  }
102 
103  BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, DescriptorSet* in_descriptorSet) :
104  Inherit(1), // slot 1
105  pipelineBindPoint(in_bindPoint),
106  layout(in_pipelineLayout),
107  firstSet(0),
108  descriptorSet(in_descriptorSet)
109  {
110  }
111 
113  BindDescriptorSet(VkPipelineBindPoint in_bindPoint, PipelineLayout* in_pipelineLayout, uint32_t in_firstSet, const vsg::Descriptors& in_descriptors) :
114  Inherit(1 + in_firstSet),
115  pipelineBindPoint(in_bindPoint),
116  layout(in_pipelineLayout),
117  firstSet(in_firstSet),
118  descriptorSet(vsg::DescriptorSet::create(in_pipelineLayout->setLayouts[in_firstSet], in_descriptors))
119  {
120  }
121 
122  // vkCmdBindDescriptorSets settings
123  VkPipelineBindPoint pipelineBindPoint;
125  uint32_t firstSet;
126  ref_ptr<DescriptorSet> descriptorSet;
127  std::vector<uint32_t> dynamicOffsets;
128 
129  int compare(const Object& rhs_object) const override;
130 
131  template<class N, class V>
132  static void t_traverse(N& bds, V& visitor)
133  {
134  if (bds.layout) bds.layout->accept(visitor);
135  if (bds.descriptorSet) bds.descriptorSet->accept(visitor);
136  }
137 
138  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
139  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
140 
141  void read(Input& input) override;
142  void write(Output& output) const override;
143 
144  // compile the Vulkan object, context parameter used for Device
145  void compile(Context& context) override;
146 
147  void record(CommandBuffer& commandBuffer) const override;
148 
149  protected:
150  virtual ~BindDescriptorSet() {}
151 
152  struct VulkanData
153  {
154  VkPipelineLayout _vkPipelineLayout = 0;
155  VkDescriptorSet _vkDescriptorSet;
156  };
157 
158  vk_buffer<VulkanData> _vulkanData;
159  };
160  VSG_type_name(vsg::BindDescriptorSet);
161 
162 } // namespace vsg
Definition: BindDescriptorSet.h:90
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:113
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,...
BindDescriptorSets state command encapsulates vkCmdBindDescriptorSets call and associated settings fo...
Definition: BindDescriptorSet.h:25
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,...
VkPipelineBindPoint pipelineBindPoint
vkCmdBindDescriptorSets settings
Definition: BindDescriptorSet.h:48
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition: DescriptorSet.h:26
Definition: Inherit.h:28
Definition: Object.h:42
PipelineLayout encapsulates VkPipelineLayout and the VkPipelineLayoutCreateInfo settings used to set ...
Definition: PipelineLayout.h:27
Definition: Visitor.h:147
Definition: ref_ptr.h:22
Definition: BindDescriptorSet.h:153
Definition: BindDescriptorSet.h:78
vk_buffer that manages a single logical device supported.
Definition: vk_buffer.h:28