vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
DatabasePager.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/app/CompileManager.h>
16#include <vsg/core/Inherit.h>
17#include <vsg/core/observer_ptr.h>
18#include <vsg/io/FileSystem.h>
19#include <vsg/io/Options.h>
20#include <vsg/nodes/PagedLOD.h>
21#include <vsg/threading/ActivityStatus.h>
22#include <vsg/utils/Instrumentation.h>
23
24#include <condition_variable>
25#include <list>
26#include <thread>
27
28namespace vsg
29{
30
32 class CulledPagedLODs : public Inherit<Object, CulledPagedLODs>
33 {
34 public:
36 {
37 highresCulled.reserve(512);
38 newHighresRequired.reserve(8);
39 }
40
41 void clear()
42 {
43 highresCulled.clear();
44 newHighresRequired.clear();
45 }
46
47 std::vector<const PagedLOD*> highresCulled;
48 std::vector<const PagedLOD*> newHighresRequired;
49 };
50
52 class VSG_DECLSPEC DatabaseQueue : public Inherit<Object, DatabaseQueue>
53 {
54 public:
56
57 using Nodes = std::list<ref_ptr<PagedLOD>>;
58
59 ActivityStatus* getStatus() { return _status; }
60 const ActivityStatus* getStatus() const { return _status; }
61
62 void add(ref_ptr<PagedLOD> plod);
63
64 void add(ref_ptr<PagedLOD> plod, const CompileResult& cr);
65
66 ref_ptr<PagedLOD> take_when_available();
67
68 Nodes take_all(CompileResult& result);
69
70 protected:
71 virtual ~DatabaseQueue();
72
73 std::mutex _mutex;
74 std::condition_variable _cv;
75 Nodes _queue;
76 CompileResult _compileResult;
78 };
79 VSG_type_name(vsg::DatabaseQueue);
80
83 class VSG_DECLSPEC DatabasePager : public Inherit<Object, DatabasePager>
84 {
85 public:
87
88 DatabasePager(const DatabasePager&) = delete;
89 DatabasePager& operator=(const DatabasePager& rhs) = delete;
90
91 virtual void start();
92
93 virtual void request(ref_ptr<PagedLOD> plod);
94
95 virtual void updateSceneGraph(FrameStamp* frameStamp, CompileResult& cr);
96
97 ref_ptr<CompileManager> compileManager;
98
99 std::atomic_uint numActiveRequests{0};
100 std::atomic_uint64_t frameCount;
101
102 ref_ptr<CulledPagedLODs> culledPagedLODs;
103
105 uint32_t targetMaxNumPagedLODWithHighResSubgraphs = 1500;
106
107 std::mutex pendingPagedLODMutex;
108
109 ref_ptr<PagedLODContainer> pagedLODContainer;
110
113
116
117 protected:
118 virtual ~DatabasePager();
119
120 void requestDiscarded(PagedLOD* plod);
121
123
124 ref_ptr<DatabaseQueue> _requestQueue;
125 ref_ptr<DatabaseQueue> _toMergeQueue;
126
127 std::list<std::thread> _readThreads;
128 };
129 VSG_type_name(vsg::DatabasePager);
130
131} // 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:33
Definition DatabasePager.h:84
void assignInstrumentation(ref_ptr< Instrumentation > in_instrumentation)
assign Instrumentation to all CompileTraversal and their associated Context
ref_ptr< Instrumentation > instrumentation
Hook for assigning Instrumentation to enable profiling.
Definition DatabasePager.h:112
Thread safe queue for tracking PagedLOD that needs to be loaded, compiled or merged by the DatabasePa...
Definition DatabasePager.h:53
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