vsg  1.1.0
VulkanSceneGraph library
DatabasePager.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/core/Inherit.h>
16 #include <vsg/core/observer_ptr.h>
17 #include <vsg/io/FileSystem.h>
18 #include <vsg/io/Options.h>
19 
20 #include <vsg/nodes/PagedLOD.h>
21 
22 #include <vsg/threading/ActivityStatus.h>
23 
24 #include <vsg/app/CompileManager.h>
25 
26 #include <condition_variable>
27 #include <list>
28 #include <thread>
29 
30 namespace vsg
31 {
32 
34  class CulledPagedLODs : public Inherit<Object, CulledPagedLODs>
35  {
36  public:
38  {
39  highresCulled.reserve(512);
40  newHighresRequired.reserve(8);
41  }
42 
43  void clear()
44  {
45  highresCulled.clear();
46  newHighresRequired.clear();
47  }
48 
49  std::vector<const PagedLOD*> highresCulled;
50  std::vector<const PagedLOD*> newHighresRequired;
51  };
52 
54  class VSG_DECLSPEC DatabaseQueue : public Inherit<Object, DatabaseQueue>
55  {
56  public:
57  explicit DatabaseQueue(ref_ptr<ActivityStatus> status);
58 
59  using Nodes = std::list<ref_ptr<PagedLOD>>;
60 
61  ActivityStatus* getStatus() { return _status; }
62  const ActivityStatus* getStatus() const { return _status; }
63 
64  void add(ref_ptr<PagedLOD> plod);
65 
66  void add(ref_ptr<PagedLOD> plod, const CompileResult& cr);
67 
68  ref_ptr<PagedLOD> take_when_available();
69 
70  Nodes take_all(CompileResult& result);
71 
72  protected:
73  virtual ~DatabaseQueue();
74 
75  std::mutex _mutex;
76  std::condition_variable _cv;
77  Nodes _queue;
78  CompileResult _compileResult;
80  };
81  VSG_type_name(vsg::DatabaseQueue);
82 
85  class VSG_DECLSPEC DatabasePager : public Inherit<Object, DatabasePager>
86  {
87  public:
88  DatabasePager();
89 
90  DatabasePager(const DatabasePager&) = delete;
91  DatabasePager& operator=(const DatabasePager& rhs) = delete;
92 
93  virtual void start();
94 
95  virtual void request(ref_ptr<PagedLOD> plod);
96 
97  virtual void updateSceneGraph(FrameStamp* frameStamp, CompileResult& cr);
98 
99  ref_ptr<const Options> options;
100 
101  ref_ptr<CompileManager> compileManager;
102 
103  std::atomic_uint numActiveRequests{0};
104  std::atomic_uint64_t frameCount;
105 
106  ref_ptr<CulledPagedLODs> culledPagedLODs;
107 
109  uint32_t targetMaxNumPagedLODWithHighResSubgraphs = 1500;
110 
111  std::mutex pendingPagedLODMutex;
112 
113  ref_ptr<PagedLODContainer> pagedLODContainer;
114 
115  protected:
116  virtual ~DatabasePager();
117 
118  void requestDiscarded(PagedLOD* plod);
119 
120  ref_ptr<ActivityStatus> _status;
121 
122  ref_ptr<DatabaseQueue> _requestQueue;
123  ref_ptr<DatabaseQueue> _toMergeQueue;
124 
125  std::list<std::thread> _readThreads;
126  };
127  VSG_type_name(vsg::DatabasePager);
128 
129 } // namespace vsg
ActivityStatus provides atomic management of whether threads watching this ActivityStatus object shou...
Definition: ActivityStatus.h:22
Class used by the DatabasePager to keep track of PagedLOD nodes.
Definition: DatabasePager.h:35
Definition: DatabasePager.h:86
Thread safe queue for tracking PagedLOD that needs to be loaded, compiled or merged by the DatabasePa...
Definition: DatabasePager.h:55
FrameStamp represents the time and frame count of a specific frame.
Definition: FrameStamp.h:22
Definition: Inherit.h:28
Definition: PagedLOD.h:36
Definition: ref_ptr.h:22
Definition: CompileManager.h:24