vsg: include/vsg/io/DatabasePager.h Source File

vsg 1.1.9 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/DeleteQueue.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:
35 CulledPagedLODs()
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:
55 explicit DatabaseQueue(ref_ptr<ActivityStatus> status);
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;
77 ref_ptr<ActivityStatus> _status;
78 };
79 VSG_type_name(vsg::DatabaseQueue);
80
83 class VSG_DECLSPEC DatabasePager : public Inherit<Object, DatabasePager>
84 {
85 public:
86 DatabasePager();
87
88 DatabasePager(const DatabasePager&) = delete;
89 DatabasePager& operator=(const DatabasePager& rhs) = delete;
90
91 virtual void start(uint32_t numReadThreads = 4);
92
93 virtual void request(ref_ptr<PagedLOD> plod);
94
95 virtual void updateSceneGraph(ref_ptr<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
112 ref_ptr<Instrumentation> instrumentation;
113
115 void assignInstrumentation(ref_ptr<Instrumentation> in_instrumentation);
116
118 std::list<std::thread> threads;
119
120 protected:
121 virtual ~DatabasePager();
122
123 void requestDiscarded(PagedLOD* plod);
124
125 ref_ptr<ActivityStatus> _status;
126
127 ref_ptr<DatabaseQueue> _requestQueue;
128 ref_ptr<DatabaseQueue> _toMergeQueue;
129 ref_ptr<DeleteQueue> _deleteQueue;
130 };
131 VSG_type_name(vsg::DatabasePager);
132
133} // namespace vsg
vsg::ActivityStatus
ActivityStatus provides atomic management of whether threads watching this ActivityStatus object shou...
Definition ActivityStatus.h:22
vsg::DatabasePager
Definition DatabasePager.h:84
vsg::DatabasePager::targetMaxNumPagedLODWithHighResSubgraphs
uint32_t targetMaxNumPagedLODWithHighResSubgraphs
for systems with smaller GPU memory limits you may need to reduce the targetMaxNumPagedLODWithHighRes...
Definition DatabasePager.h:105
vsg::DatabasePager::assignInstrumentation
void assignInstrumentation(ref_ptr< Instrumentation > in_instrumentation)
assign Instrumentation to all CompileTraversal and their associated Context
vsg::DatabasePager::threads
std::list< std::thread > threads
read and delete threads created by start()
Definition DatabasePager.h:118
vsg::DatabasePager::instrumentation
ref_ptr< Instrumentation > instrumentation
Hook for assigning Instrumentation to enable profiling.
Definition DatabasePager.h:112
vsg::DatabaseQueue
Thread safe queue for tracking PagedLOD that needs to be loaded, compiled or merged by the DatabasePa...
Definition DatabasePager.h:53
vsg::PagedLOD
Definition PagedLOD.h:36
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::CompileResult
Definition CompileManager.h:27