vsg  1.1.0
VulkanSceneGraph library
DescriptorSet.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/Descriptor.h>
16 #include <vsg/state/DescriptorSetLayout.h>
17 
18 namespace vsg
19 {
20 
21  // forward declare
22  class DescriptorPool;
23 
25  class VSG_DECLSPEC DescriptorSet : public Inherit<Object, DescriptorSet>
26  {
27  public:
28  DescriptorSet();
29  DescriptorSet(ref_ptr<DescriptorSetLayout> in_descriptorSetLayout, const Descriptors& in_descriptors);
30 
33  Descriptors descriptors;
34 
35  int compare(const Object& rhs_object) const override;
36 
37  template<class N, class V>
38  static void t_traverse(N& ds, V& visitor)
39  {
40  if (ds.setLayout) ds.setLayout->accept(visitor);
41  for (auto& descriptor : ds.descriptors) descriptor->accept(visitor);
42  }
43 
44  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
45  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
46 
47  void read(Input& input) override;
48  void write(Output& output) const override;
49 
50  // compile the Vulkan object, context parameter used for Device
51  void compile(Context& context);
52 
53  // remove the local reference to the Vulkan implementation
54  void release(uint32_t deviceID);
55  void release();
56 
58  VkDescriptorSet vk(uint32_t deviceID) const;
59 
60  public:
64  class VSG_DECLSPEC Implementation : public Inherit<Object, Implementation>
65  {
66  public:
67  Implementation(DescriptorPool* descriptorPool, DescriptorSetLayout* descriptorSetLayout);
68 
69  void assign(Context& context, const Descriptors& descriptors);
70 
71  VkDescriptorSet _descriptorSet;
72 
73  static void recycle(ref_ptr<DescriptorSet::Implementation>& dsi);
74 
75  protected:
76  virtual ~Implementation();
77 
78  friend DescriptorPool;
79 
80  ref_ptr<DescriptorPool> _descriptorPool;
81  ref_ptr<DescriptorSetLayout> _descriptorSetLayout;
82  };
83 
84  protected:
85  virtual ~DescriptorSet();
86 
87  vk_buffer<ref_ptr<Implementation>> _implementation;
88  };
89  VSG_type_name(vsg::DescriptorSet);
91 
92  using DescriptorSets = std::vector<ref_ptr<DescriptorSet>>;
93 
94 } // namespace vsg
Definition: Context.h:67
DescriptorPool encapsulates management of VkDescriptorPool.
Definition: DescriptorPool.h:22
DescriptorSetLayout encapsulates VkDescriptorSetLayout and VkDescriptorSetLayoutCreateInfo settings u...
Definition: DescriptorSetLayout.h:28
Definition: DescriptorSet.h:65
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition: DescriptorSet.h:26
VkDescriptorSet vk(uint32_t deviceID) const
get the Vulkan handle to the descriptor set for specified device
ref_ptr< DescriptorSetLayout > setLayout
VkDescriptorSetAllocateInfo settings.
Definition: DescriptorSet.h:32
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,...
Definition: Inherit.h:28
Definition: Object.h:42
Definition: Visitor.h:147
Definition: ref_ptr.h:22
vk_buffer that manages a single logical device supported.
Definition: vk_buffer.h:28