vsg: include/vsg/vk/ResourceRequirements.h Source File

vsg 1.1.3 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(ref_ptr<ResourceHints> hints = {});
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 void add(ViewDetails& vd)
49 {
50 indices.insert(vd.indices.begin(), vd.indices.end());
51 bins.insert(vd.bins.begin(), vd.bins.end());
52 lights.insert(vd.lights.begin(), vd.lights.end());
53 }
54 };
55
56 using Descriptors = std::set<const Descriptor*>;
57 using DescriptorSets = std::set<const DescriptorSet*>;
58 using DescriptorTypeMap = std::map<VkDescriptorType, uint32_t>;
59 using Views = std::map<const View*, ViewDetails>;
60 using ViewDetailStack = std::stack<ViewDetails>;
61
62 struct DynamicData
63 {
64 BufferInfoList bufferInfos;
65 ImageInfoList imageInfos;
66
67 explicit operator bool() const noexcept { return !bufferInfos.empty() || !imageInfos.empty(); }
68
69 void clear()
70 {
71 bufferInfos.clear();
72 imageInfos.clear();
73 }
74
75 void add(const DynamicData& dd)
76 {
77 bufferInfos.insert(bufferInfos.end(), dd.bufferInfos.begin(), dd.bufferInfos.end());
78 imageInfos.insert(imageInfos.end(), dd.imageInfos.begin(), dd.imageInfos.end());
79 }
80 };
81
82 DynamicData earlyDynamicData;
83 DynamicData lateDynamicData;
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 uivec2 numLightsRange = {8, 1024};
99 uivec2 numShadowMapsRange = {0, 64};
100 uivec2 shadowMapSize = {2048, 2048};
101 };
102 VSG_type_name(vsg::ResourceRequirements);
103
105 class VSG_DECLSPEC CollectResourceRequirements : public Inherit<ConstVisitor, CollectResourceRequirements>
106 {
107 public:
108 CollectResourceRequirements() { overrideMask = vsg::MASK_ALL; }
109
110 ResourceRequirements requirements;
111
113 ref_ptr<ResourceHints> createResourceHints(uint32_t tileMultiplier = 1) const;
114
115 using ConstVisitor::apply;
116
117 bool checkForResourceHints(const Object& object);
118
119 void apply(const Object& object) override;
120 void apply(const ResourceHints& resourceHints) override;
121 void apply(const Node& node) override;
122 void apply(const StateCommand& stateCommand) override;
123 void apply(const DescriptorSet& descriptorSet) override;
124 void apply(const Descriptor& descriptor) override;
125 void apply(const DescriptorBuffer& descriptorBuffer) override;
126 void apply(const DescriptorImage& descriptorImage) override;
127 void apply(const PagedLOD& plod) override;
128 void apply(const Light& light) override;
129 void apply(const View& view) override;
130 void apply(const DepthSorted& depthSorted) override;
131 void apply(const Layer& layer) override;
132 void apply(const Bin& bin) override;
133 void apply(const Geometry& geometry) override;
134 void apply(const VertexDraw& vid) override;
135 void apply(const VertexIndexDraw& vid) override;
136 void apply(const BindVertexBuffers& bvb) override;
137 void apply(const BindIndexBuffer& bib) override;
138
139 virtual void apply(ref_ptr<BufferInfo> bufferInfo);
140 virtual void apply(ref_ptr<ImageInfo> imageInfo);
141
142 protected:
143 uint32_t _numResourceHintsAbove = 0;
144
145 bool registerDescriptor(const Descriptor& descriptor);
146 };
147 VSG_type_name(vsg::CollectResourceRequirements);
148
149} // namespace vsg
vsg::Bin
Definition Bin.h:24
vsg::BindIndexBuffer
BindIndexBuffer command encapsulates vkCmdBindIndexBuffer call and associated settings.
Definition BindIndexBuffer.h:28
vsg::BindVertexBuffers
BindVertexBuffers command encapsulates vkCmdBindVertexBuffers call and associated settings.
Definition BindVertexBuffers.h:25
vsg::CollectResourceRequirements
CollectResourceRequirements is a visitor class that collects the ResourceRequirements of a scene grap...
Definition ResourceRequirements.h:106
vsg::CollectResourceRequirements::createResourceHints
ref_ptr< ResourceHints > createResourceHints(uint32_t tileMultiplier=1) const
create ResouceHints that capture the collected ResourceRequirements. Note, call after the CollectReso...
vsg::DepthSorted
Definition DepthSorted.h:27
vsg::DescriptorBuffer
Definition DescriptorBuffer.h:24
vsg::Descriptor
Definition Descriptor.h:26
vsg::DescriptorImage
Definition DescriptorImage.h:24
vsg::DescriptorSet
DescriptorSet encapsulates VkDescriptorSet and VkDescriptorSetAllocateInfo settings used to describe ...
Definition DescriptorSet.h:26
vsg::Geometry
Definition Geometry.h:30
vsg::Inherit
Definition Inherit.h:28
vsg::Layer
Layer node is used to control which bin to place the subgraph in and what sort value to assign.
Definition Layer.h:23
vsg::Light
Definition Light.h:26
vsg::Node
Definition Node.h:24
vsg::Object
Definition Object.h:60
vsg::PagedLOD
Definition PagedLOD.h:36
vsg::ResourceHints
ResourceHints provides settings that help preallocation of Vulkan resources and memory.
Definition ResourceHints.h:23
vsg::ResourceRequirements
ResourceRequirements provides a container for various Vulkan resource requirements that can be used t...
Definition ResourceRequirements.h:30
vsg::StateCommand
Definition StateCommand.h:24
vsg::VertexDraw
Definition VertexDraw.h:25
vsg::VertexIndexDraw
Definition VertexIndexDraw.h:25
vsg::View
View is a Group class that pairs a Camera that defines the view with a subgraph that defines the scen...
Definition View.h:36
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::ResourceRequirements::DynamicData
Definition ResourceRequirements.h:63
vsg::ResourceRequirements::ViewDetails
Definition ResourceRequirements.h:43
vsg::t_vec2< uint32_t >