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

vsg 1.1.13 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
43 struct ViewDetails
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
63 struct DynamicData
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 Slots maxSlots;
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 uint32_t viewportStateHint = DYNAMIC_VIEWPORTSTATE;
106 };
107 VSG_type_name(vsg::ResourceRequirements);
108
110 class VSG_DECLSPEC CollectResourceRequirements : public Inherit<ConstVisitor, CollectResourceRequirements>
111 {
112 public:
113 CollectResourceRequirements() { overrideMask = vsg::MASK_ALL; }
114
115 ResourceRequirements requirements;
116
118 ref_ptr<ResourceHints> createResourceHints(uint32_t tileMultiplier = 1) const;
119
120 using ConstVisitor::apply;
121
122 bool checkForResourceHints(const Object& object);
123
124 void apply(const Object& object) override;
125 void apply(const ResourceHints& resourceHints) override;
126 void apply(const Node& node) override;
127 void apply(const StateCommand& stateCommand) override;
128 void apply(const DescriptorSet& descriptorSet) override;
129 void apply(const Descriptor& descriptor) override;
130 void apply(const DescriptorBuffer& descriptorBuffer) override;
131 void apply(const DescriptorImage& descriptorImage) override;
132 void apply(const PagedLOD& plod) override;
133 void apply(const Light& light) override;
134 void apply(const RenderGraph& rg) override;
135 void apply(const View& view) override;
136 void apply(const DepthSorted& depthSorted) override;
137 void apply(const Layer& layer) override;
138 void apply(const Bin& bin) override;
139 void apply(const Geometry& geometry) override;
140 void apply(const VertexDraw& vid) override;
141 void apply(const VertexIndexDraw& vid) override;
142 void apply(const BindVertexBuffers& bvb) override;
143 void apply(const BindIndexBuffer& bib) override;
144
145 virtual void apply(ref_ptr<BufferInfo> bufferInfo);
146 virtual void apply(ref_ptr<ImageInfo> imageInfo);
147
148 protected:
149 uint32_t _numResourceHintsAbove = 0;
150
151 bool registerDescriptor(const Descriptor& descriptor);
152 };
153 VSG_type_name(vsg::CollectResourceRequirements);
154
155} // 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:111
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::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::RenderGraph
Definition RenderGraph.h:29
vsg::ResourceHints
ResourceHints provides settings that help preallocation of Vulkan resources and memory.
Definition ResourceHints.h:35
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:64
vsg::ResourceRequirements::ViewDetails
Definition ResourceRequirements.h:44
vsg::Slots
max slot values used for general state and view state related State::stateStacks
Definition Slots.h:22