vsg  1.1.0
VulkanSceneGraph library
ResourceRequirements.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/nodes/Bin.h>
16 #include <vsg/state/BufferInfo.h>
17 #include <vsg/state/Descriptor.h>
18 #include <vsg/state/ImageInfo.h>
19 #include <vsg/state/ResourceHints.h>
20 #include <vsg/vk/DescriptorPool.h>
21 
22 #include <map>
23 #include <set>
24 #include <stack>
25 
26 namespace vsg
27 {
29  class VSG_DECLSPEC ResourceRequirements
30  {
31  public:
33  ResourceRequirements(const ResourceRequirements& rhs) = default;
34 
35  ResourceRequirements& operator=(const ResourceRequirements& rhs) = default;
36 
37  void apply(const ResourceHints& resourceHints);
38 
39  uint32_t computeNumDescriptorSets() const;
40  DescriptorPoolSizes computeDescriptorPoolSizes() const;
41 
42  struct ViewDetails
43  {
44  std::set<int32_t> indices;
45  std::set<const Bin*> bins;
46  std::set<const Light*> lights;
47  };
48 
49  using Descriptors = std::set<const Descriptor*>;
50  using DescriptorSets = std::set<const DescriptorSet*>;
51  using DescriptorTypeMap = std::map<VkDescriptorType, uint32_t>;
52  using Views = std::map<const View*, ViewDetails>;
53  using ViewDetailStack = std::stack<ViewDetails>;
54 
55  struct DynamicData
56  {
57  BufferInfoList bufferInfos;
58  ImageInfoList imageInfos;
59 
60  explicit operator bool() const noexcept { return !bufferInfos.empty() || !imageInfos.empty(); }
61 
62  void clear()
63  {
64  bufferInfos.clear();
65  imageInfos.clear();
66  }
67 
68  void add(const DynamicData& dd)
69  {
70  bufferInfos.insert(bufferInfos.end(), dd.bufferInfos.begin(), dd.bufferInfos.end());
71  imageInfos.insert(imageInfos.end(), dd.imageInfos.begin(), dd.imageInfos.end());
72  }
73  };
74 
75  DynamicData earlyDynamicData;
76  DynamicData lateDynamicData;
77 
78  Descriptors descriptors;
79  DescriptorSets descriptorSets;
80  DescriptorTypeMap descriptorTypeMap;
81  Views views;
82  ViewDetailStack viewDetailsStack;
83 
84  uint32_t maxSlot = 0;
85  uint32_t externalNumDescriptorSets = 0;
86  bool containsPagedLOD = false;
87 
88  VkDeviceSize minimumBufferSize = 16 * 1024 * 1024;
89  VkDeviceSize minimumDeviceMemorySize = 16 * 1024 * 1024;
90 
91  uivec2 numLightsRange = {8, 1024};
92  uivec2 numShadowMapsRange = {0, 64};
93  uivec2 shadowMapSize = {2048, 2048};
94  };
95  VSG_type_name(vsg::ResourceRequirements);
96 
98  class VSG_DECLSPEC CollectResourceRequirements : public Inherit<ConstVisitor, CollectResourceRequirements>
99  {
100  public:
101  CollectResourceRequirements() { overrideMask = vsg::MASK_ALL; }
102 
103  ResourceRequirements requirements;
104 
106  ref_ptr<ResourceHints> createResourceHints(uint32_t tileMultiplier = 1) const;
107 
108  using ConstVisitor::apply;
109 
110  bool checkForResourceHints(const Object& object);
111 
112  void apply(const Object& object) override;
113  void apply(const ResourceHints& resourceHints) override;
114  void apply(const Node& node) override;
115  void apply(const StateGroup& stategroup) override;
116  void apply(const StateCommand& stateCommand) override;
117  void apply(const DescriptorSet& descriptorSet) override;
118  void apply(const Descriptor& descriptor) override;
119  void apply(const DescriptorBuffer& descriptorBuffer) override;
120  void apply(const DescriptorImage& descriptorImage) override;
121  void apply(const PagedLOD& plod) override;
122  void apply(const Light& light) override;
123  void apply(const View& view) override;
124  void apply(const DepthSorted& depthSorted) override;
125  void apply(const Bin& bin) override;
126  void apply(const Geometry& geometry) override;
127  void apply(const VertexDraw& vid) override;
128  void apply(const VertexIndexDraw& vid) override;
129  void apply(const BindVertexBuffers& bvb) override;
130  void apply(const BindIndexBuffer& bib) override;
131 
132  virtual void apply(ref_ptr<BufferInfo> bufferInfo);
133  virtual void apply(ref_ptr<ImageInfo> imageInfo);
134 
135  protected:
136  uint32_t _numResourceHintsAbove = 0;
137 
138  bool registerDescriptor(const Descriptor& descriptor);
139  };
140  VSG_type_name(vsg::CollectResourceRequirements);
141 
142 } // namespace vsg
Definition: Bin.h:24
BindIndexBuffer command encapsulates vkCmdBindIndexBuffer call and associated settings.
Definition: BindIndexBuffer.h:28
BindVertexBuffers command encapsulates vkCmdBindVertexBuffers call and associated settings.
Definition: BindVertexBuffers.h:25
CollectResourceRequirements is a visitor class that collects the ResourceRequirements of a scene grap...
Definition: ResourceRequirements.h:99
ref_ptr< ResourceHints > createResourceHints(uint32_t tileMultiplier=1) const
create ResouceHints that capture the collected ResourceRequirements. Note, call after the CollectReso...
Definition: DepthSorted.h:27
Definition: DescriptorBuffer.h:24
Definition: DescriptorImage.h:24
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition: DescriptorSet.h:26
Definition: Descriptor.h:26
Definition: Geometry.h:30
Definition: Inherit.h:28
Definition: Light.h:25
Definition: Node.h:24
Definition: Object.h:42
Definition: PagedLOD.h:36
ResourceHints provides settings that help preallocation of Vulkan resources and memory.
Definition: ResourceHints.h:23
ResourceRequirements provides a container for various Vulkan resource requirements that can be used t...
Definition: ResourceRequirements.h:30
Definition: StateCommand.h:24
Definition: StateGroup.h:32
Definition: VertexDraw.h:25
Definition: VertexIndexDraw.h:25
View is a Group class that pairs a Camera that defines the view with a subgraph that defines the scen...
Definition: View.h:36
Definition: ref_ptr.h:22
Definition: ResourceRequirements.h:56
Definition: ResourceRequirements.h:43