vsg  1.1.0
VulkanSceneGraph library
CompileTraversal.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/app/Window.h>
16 #include <vsg/core/Object.h>
17 #include <vsg/nodes/Bin.h>
18 #include <vsg/nodes/Group.h>
19 #include <vsg/state/BufferInfo.h>
20 #include <vsg/state/Descriptor.h>
21 #include <vsg/state/ResourceHints.h>
22 #include <vsg/vk/CommandPool.h>
23 #include <vsg/vk/Context.h>
24 #include <vsg/vk/DescriptorPool.h>
25 #include <vsg/vk/Fence.h>
26 #include <vsg/vk/ResourceRequirements.h>
27 
28 namespace vsg
29 {
30 
32  class VSG_DECLSPEC CompileTraversal : public Inherit<Visitor, CompileTraversal>
33  {
34  public:
35  CompileTraversal() { overrideMask = vsg::MASK_ALL; }
37  explicit CompileTraversal(ref_ptr<Device> device, const ResourceRequirements& resourceRequirements = {});
38  explicit CompileTraversal(Window& window, ref_ptr<ViewportState> viewport = {}, const ResourceRequirements& resourceRequirements = {});
39  explicit CompileTraversal(const Viewer& viewer, const ResourceRequirements& resourceRequirements = {});
40 
42  VkQueueFlags queueFlags = VK_QUEUE_GRAPHICS_BIT;
43  uint32_t queueFamilyIndex = 1;
44 
46  std::list<ref_ptr<Context>> contexts;
47 
49  void add(ref_ptr<Device> device, const ResourceRequirements& resourceRequirements = {});
50 
52  void add(Window& window, ref_ptr<ViewportState> viewport = {}, const ResourceRequirements& resourceRequirements = {});
53 
55  void add(Framebuffer& framebuffer, ref_ptr<View> view, const ResourceRequirements& resourceRequirements = {});
56 
58  void add(Window& window, ref_ptr<View> view, const ResourceRequirements& resourceRequirements = {});
59 
61  void add(const Viewer& viewer, const ResourceRequirements& resourceRequirements = {});
62 
63  virtual bool record();
64  virtual void waitForCompletion();
65 
67  template<typename T>
68  void compile(T object, bool wait = true)
69  {
70  object->accept(*this);
71  if (record() && wait) waitForCompletion();
72  }
73 
74  // implement compile of relevant nodes in the scene graph
75  void apply(Object& object) override;
76  void apply(Compilable& node) override;
77  void apply(Commands& commands) override;
78  void apply(StateGroup& stateGroup) override;
79  void apply(Geometry& geometry) override;
80  void apply(CommandGraph& commandGraph) override;
81  void apply(RenderGraph& renderGraph) override;
82  void apply(View& view) override;
83 
84  protected:
86 
87  void addViewDependentState(ViewDependentState& viewDependentState, const ResourceRequirements& resourceRequirements);
88  };
89  VSG_type_name(vsg::CompileTraversal);
90 
91 } // namespace vsg
CommandGraph is a group node that sits at the top of the scene graph and manages the recording of its...
Definition: CommandGraph.h:27
Definition: Commands.h:29
Base class for encapsulating nodes that have Vulkan objects associated with them that will need compi...
Definition: Compilable.h:23
CompileTraversal traverses a scene graph and invokes all the StateCommand/Command::compile(....
Definition: CompileTraversal.h:33
void add(Framebuffer &framebuffer, ref_ptr< View > view, const ResourceRequirements &resourceRequirements={})
add a compile Context for Framebuffer and associated View
void compile(T object, bool wait=true)
convenience method that compiles an object/subgraph
Definition: CompileTraversal.h:68
void add(const Viewer &viewer, const ResourceRequirements &resourceRequirements={})
add a compile Context for all the Views assigned to a Viewer
std::list< ref_ptr< Context > > contexts
list of Context that Vulkan objects should be compiled for.
Definition: CompileTraversal.h:46
void add(Window &window, ref_ptr< ViewportState > viewport={}, const ResourceRequirements &resourceRequirements={})
add a compile Context for Window and associated viewport.
void add(Window &window, ref_ptr< View > view, const ResourceRequirements &resourceRequirements={})
add a compile Context for Window and associated View
void add(ref_ptr< Device > device, const ResourceRequirements &resourceRequirements={})
add a compile Context for device
Framebuffer encapsulates VkFramebuffer, used as a rendering target associated with a Window or for re...
Definition: Framebuffer.h:23
Definition: Geometry.h:30
Definition: Inherit.h:28
Definition: Object.h:42
Definition: RenderGraph.h:28
ResourceRequirements provides a container for various Vulkan resource requirements that can be used t...
Definition: ResourceRequirements.h:30
Definition: StateGroup.h:32
Definition: ViewDependentState.h:105
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: Viewer.h:31
Definition: Window.h:31
Definition: ref_ptr.h:22