vsg 1.1.10
VulkanSceneGraph library
 
Loading...
Searching...
No Matches
ResourceRequirements.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/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
26namespace vsg
27{
29 class VSG_DECLSPEC ResourceRequirements
30 {
31 public:
32 ResourceRequirements();
33 ResourceRequirements(const ResourceRequirements& rhs) = default;
34 explicit ResourceRequirements(ref_ptr<ResourceHints> hints);
35
36 ResourceRequirements& operator=(const ResourceRequirements& rhs) = default;
37
38 void apply(const ResourceHints& resourceHints);
39
40 uint32_t computeNumDescriptorSets() const;
41 DescriptorPoolSizes computeDescriptorPoolSizes() const;
42
44 {
45 std::set<int32_t> indices;
46 std::set<const Bin*> bins;
47 std::set<const Light*> lights;
48
49 void add(ViewDetails& vd)
50 {
51 indices.insert(vd.indices.begin(), vd.indices.end());
52 bins.insert(vd.bins.begin(), vd.bins.end());
53 lights.insert(vd.lights.begin(), vd.lights.end());
54 }
55 };
56
57 using Descriptors = std::set<const Descriptor*>;
58 using DescriptorSets = std::set<const DescriptorSet*>;
59 using DescriptorTypeMap = std::map<VkDescriptorType, uint32_t>;
60 using Views = std::map<const View*, ViewDetails>;
61 using ViewDetailStack = std::stack<ViewDetails>;
62
64 {
65 BufferInfoList bufferInfos;
66 ImageInfoList imageInfos;
67
68 explicit operator bool() const noexcept { return !bufferInfos.empty() || !imageInfos.empty(); }
69
70 void clear()
71 {
72 bufferInfos.clear();
73 imageInfos.clear();
74 }
75
76 void add(const DynamicData& dd)
77 {
78 bufferInfos.insert(bufferInfos.end(), dd.bufferInfos.begin(), dd.bufferInfos.end());
79 imageInfos.insert(imageInfos.end(), dd.imageInfos.begin(), dd.imageInfos.end());
80 }
81 };
82
83 DynamicData dynamicData;
84
85 Descriptors descriptors;
86 DescriptorSets descriptorSets;
87 DescriptorTypeMap descriptorTypeMap;
88 Views views;
89 ViewDetailStack viewDetailsStack;
90
91 uint32_t maxSlot = 0;
92 uint32_t externalNumDescriptorSets = 0;
93 bool containsPagedLOD = false;
94
95 VkDeviceSize minimumBufferSize = 16 * 1024 * 1024;
96 VkDeviceSize minimumDeviceMemorySize = 16 * 1024 * 1024;
97
98 VkDeviceSize minimumStagingBufferSize = 16 * 1024 * 1024;
99
100 uivec2 numLightsRange = {8, 1024};
101 uivec2 numShadowMapsRange = {0, 64};
102 uivec2 shadowMapSize = {2048, 2048};
103
104 DataTransferHint dataTransferHint = COMPILE_TRAVERSAL_USE_TRANSFER_TASK;
105 };
106 VSG_type_name(vsg::ResourceRequirements);
107
109 class VSG_DECLSPEC CollectResourceRequirements : public Inherit<ConstVisitor, CollectResourceRequirements>
110 {
111 public:
112 CollectResourceRequirements() { overrideMask = vsg::MASK_ALL; }
113
114 ResourceRequirements requirements;
115
117 ref_ptr<ResourceHints> createResourceHints(uint32_t tileMultiplier = 1) const;
118
119 using ConstVisitor::apply;
120
121 bool checkForResourceHints(const Object& object);
122
123 void apply(const Object& object) override;
124 void apply(const ResourceHints& resourceHints) override;
125 void apply(const Node& node) override;
126 void apply(const StateCommand& stateCommand) override;
127 void apply(const DescriptorSet& descriptorSet) override;
128 void apply(const Descriptor& descriptor) override;
129 void apply(const DescriptorBuffer& descriptorBuffer) override;
130 void apply(const DescriptorImage& descriptorImage) override;
131 void apply(const PagedLOD& plod) override;
132 void apply(const Light& light) override;
133 void apply(const View& view) override;
134 void apply(const DepthSorted& depthSorted) override;
135 void apply(const Layer& layer) override;
136 void apply(const Bin& bin) override;
137 void apply(const Geometry& geometry) override;
138 void apply(const VertexDraw& vid) override;
139 void apply(const VertexIndexDraw& vid) override;
140 void apply(const BindVertexBuffers& bvb) override;
141 void apply(const BindIndexBuffer& bib) override;
142
143 virtual void apply(ref_ptr<BufferInfo> bufferInfo);
144 virtual void apply(ref_ptr<ImageInfo> imageInfo);
145
146 protected:
147 uint32_t _numResourceHintsAbove = 0;
148
149 bool registerDescriptor(const Descriptor& descriptor);
150 };
152
153} // 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:110
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 Descriptor.h:26
Definition DescriptorImage.h:24
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition DescriptorSet.h:26
Definition Geometry.h:30
Layer node is used to control which bin to place the subgraph in and what sort value to assign.
Definition Layer.h:23
Definition Light.h:26
Definition Node.h:24
Definition Object.h:60
Definition PagedLOD.h:36
ResourceHints provides settings that help preallocation of Vulkan resources and memory.
Definition ResourceHints.h:29
ResourceRequirements provides a container for various Vulkan resource requirements that can be used t...
Definition ResourceRequirements.h:30
Definition StateCommand.h:24
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:64
Definition ResourceRequirements.h:44