Skip to content

Commit 87ac6b6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into new-ref_ptr
2 parents 2179962 + 2594b01 commit 87ac6b6

37 files changed

Lines changed: 715 additions & 300 deletions

.github/workflows/ci.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
os: [ubuntu-latest, macos-latest, windows-latest]
13-
vulkan-version: [1.3.268.0]
12+
# os: [ubuntu-latest, macos-latest, windows-latest]
13+
os: [ubuntu-latest]
14+
vulkan-version: [1.4.341.1]
1415
build-shared: [OFF]
15-
include:
16-
- build-shared: ON
17-
os: windows-latest
18-
vulkan-version: 1.3.268.0
16+
# include:
17+
# - build-shared: ON
18+
# os: windows-latest
19+
# vulkan-version: 1.4.341.1
20+
1921
continue-on-error: ${{ matrix.vulkan-version == 'latest' }}
2022

2123
steps:
22-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2325
- name: Setup cmake
24-
uses: jwlawson/actions-setup-cmake@v1.12
26+
uses: jwlawson/actions-setup-cmake@v2.2.0
2527
with:
2628
cmake-version: ${{ env.CMakeVersion }}
2729
- name: Install Vulkan SDK
@@ -30,7 +32,7 @@ jobs:
3032
version: ${{ matrix.vulkan-version }}
3133
cache: true
3234
- name: Add MSBuild to PATH
33-
uses: microsoft/setup-msbuild@v2
35+
uses: microsoft/setup-msbuild@v3
3436
if: startsWith(matrix.os, 'windows')
3537
- name: Build and Install VSG
3638
shell: bash

include/vsg/app/CompileManager.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ namespace vsg
3939
bool requiresViewerUpdate() const;
4040
};
4141

42+
/// ResourceScavenger provides a mechanism for releasing and reusing unused resources when allocation of required GPU memory fails.
43+
class VSG_DECLSPEC ResourceScavenger : public Inherit<Object, ResourceScavenger>
44+
{
45+
public:
46+
explicit ResourceScavenger(ref_ptr<DatabasePager> in_databasePager);
47+
48+
virtual bool scavenge(ResourceRequirements& resourceRequirements);
49+
50+
uint64_t sleepDuration = 16 * 5; /// milliseconds sleep to make after adjusting load targets to allow other threads to free up space, default to 5 frames at 60fps
51+
observer_ptr<DatabasePager> databasePager;
52+
};
53+
4254
/// CompileManager is a helper class that compiles subgraphs for the windows/framebuffers associated with the CompileManager.
4355
class VSG_DECLSPEC CompileManager : public Inherit<Object, CompileManager>
4456
{
@@ -71,7 +83,15 @@ namespace vsg
7183
/// compile all the command graphs in a task
7284
CompileResult compileTask(ref_ptr<RecordAndSubmitTask> task, const ResourceRequirements& resourceRequirements = {});
7385

86+
/// mechanism for releasing and reusing used resources
87+
ref_ptr<ResourceScavenger> resourceScavenger;
88+
89+
std::atomic_uint successfulCompileCount{0};
90+
std::atomic_uint failedCompileCount{0};
91+
7492
protected:
93+
~CompileManager();
94+
7595
using CompileTraversals = ThreadSafeQueue<ref_ptr<CompileTraversal>>;
7696
size_t numCompileTraversals = 0;
7797
ref_ptr<CompileTraversals> compileTraversals;

include/vsg/core/Exception.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
1212
1313
</editor-fold> */
1414

15+
#include <vsg/core/Export.h>
16+
1517
#include <string>
1618

1719
namespace vsg
1820
{
1921

2022
/// Exception object that can be thrown from VSG code, such as failed Vulkan calls where the result value will be the VkResult value
2123
/// returned from failed Vulkan call.
22-
struct Exception
24+
struct VSG_DECLSPEC Exception
2325
{
2426
std::string message;
2527
int result = 0;

include/vsg/core/MemorySlots.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace vsg
3131
MEMORY_TRACKING_DEFAULT = MEMORY_TRACKING_NO_CHECKS
3232
};
3333

34+
// forward declare
35+
struct LogOutput;
36+
3437
/** class used internally by vsg::Allocator, vsg::DeviceMemory and vsg::Buffer to manage suballocation within a block of CPU or GPU memory.*/
3538
class VSG_DECLSPEC MemorySlots
3639
{
@@ -52,7 +55,8 @@ namespace vsg
5255
size_t totalMemorySize() const { return _totalMemorySize; }
5356

5457
// debug facilities
55-
void report(std::ostream& out) const;
58+
void report(LogOutput& log) const;
59+
5660
bool check() const;
5761

5862
mutable int memoryTracking = MEMORY_TRACKING_DEFAULT;

include/vsg/core/observer_ptr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ namespace vsg
223223
}
224224
}
225225

226+
/// We strongly recommend access via ref_ptr<> rather than get(). Only use get() to get access to the raw C pointer when it's know that the object pointed to will remain in memory through use of that raw C pointer.
227+
T* get() const noexcept { return _ptr; }
228+
226229
protected:
227230
template<class R>
228231
friend class observer_ptr;

include/vsg/core/type_name.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace vsg
4949
template<> constexpr const char* vsg::type_name<T>() noexcept { return #T; } \
5050
template<> constexpr const char* vsg::type_name<const T>() noexcept { return "const "#T; }
5151

52-
/// convinience function for adding a space in front of the type_name string.
52+
/// convenience function for adding a space in front of the type_name string.
5353
template<typename T>
5454
std::string space_type_name(const T&) { return std::string(" ") + type_name<T>(); }
5555

include/vsg/io/DatabasePager.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ namespace vsg
104104

105105
void add(ref_ptr<PagedLOD> plod, const CompileResult& cr);
106106

107-
ref_ptr<PagedLOD> take_when_available();
107+
/// prune entries older than specified frameCount
108+
uint32_t prune(uint64_t frameCount);
109+
110+
ref_ptr<PagedLOD> take_when_available(uint64_t frameCount);
108111

109112
Nodes take_all(CompileResult& result);
110113

@@ -138,13 +141,16 @@ namespace vsg
138141
ref_ptr<CompileManager> compileManager;
139142

140143
std::atomic_uint numActiveRequests{0};
141-
std::atomic_uint64_t frameCount;
144+
std::atomic_uint64_t frameCount{0};
142145

143146
ref_ptr<CulledPagedLODs> culledPagedLODs;
144147

145148
/// for systems with smaller GPU memory limits you may need to reduce the targetMaxNumPagedLODWithHighResSubgraphs to keep memory usage within available limits.
146149
uint32_t targetMaxNumPagedLODWithHighResSubgraphs = 1500;
147150

151+
/// number of frames before a PagedLOD with a failed load/compile is attempted to be loaded/compiled again.
152+
uint64_t delayBeforeNextLoadAttempt = 60;
153+
148154
std::mutex pendingPagedLODMutex;
149155

150156
ref_ptr<PagedLODContainer> pagedLODContainer;
@@ -158,16 +164,16 @@ namespace vsg
158164
/// read and delete threads created by start()
159165
std::list<std::thread> threads;
160166

167+
ref_ptr<ActivityStatus> status;
168+
ref_ptr<DeleteQueue> deleteQueue;
169+
161170
protected:
162171
virtual ~DatabasePager();
163172

164173
void requestDiscarded(PagedLOD* plod);
165174

166-
ref_ptr<ActivityStatus> _status;
167-
168175
ref_ptr<DatabaseQueue> _requestQueue;
169176
ref_ptr<DatabaseQueue> _toMergeQueue;
170-
ref_ptr<DeleteQueue> _deleteQueue;
171177
};
172178
VSG_type_name(vsg::DatabasePager);
173179

include/vsg/io/stream.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2929

3030
#include <istream>
3131
#include <ostream>
32+
#include <set>
3233
#include <sstream>
3334

3435
namespace vsg
@@ -333,4 +334,29 @@ namespace vsg
333334
return output;
334335
}
335336

337+
template<typename T>
338+
std::ostream& operator<<(std::ostream& output, const std::set<T>& values)
339+
{
340+
if (values.empty())
341+
output << "{}";
342+
else
343+
{
344+
output << "{ ";
345+
346+
bool first = true;
347+
for (const auto& v : values)
348+
{
349+
if (!first)
350+
output << ", ";
351+
else
352+
first = false;
353+
354+
output << v;
355+
}
356+
357+
output << " }";
358+
}
359+
return output;
360+
}
361+
336362
} // namespace vsg

include/vsg/nodes/InstanceNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ namespace vsg
2121
{
2222

2323
/// InstanceNode provides a mechanism for specifying the translations, rotations and scales (transform arrays) of subgraph
24-
/// that contains InstanceDraw leaf node(s) that utlize the InstanceNode's per instance transform arrays combined with the
24+
/// that contains InstanceDraw leaf node(s) that utilize the InstanceNode's per instance transform arrays combined with the
2525
/// InstanceDraw nodes per vertex arrays.
2626
///
27-
/// InstanceNode only work correctly when the child subgraphs that obey these contraints:
27+
/// InstanceNode only work correctly when the child subgraphs that obey these constraints:
2828
/// 1. Do not contain any Transform nodes
2929
/// 2. Do not contain any Culling nodes
3030
/// 3. Do not contain any InstanceNode nodes

include/vsg/nodes/PagedLOD.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ namespace vsg
8989
mutable std::atomic_uint64_t frameHighResLastUsed{0};
9090
mutable std::atomic_uint requestCount{0};
9191

92+
mutable std::atomic_uint64_t frameNextLoadAttempt{0};
93+
mutable std::atomic_uint64_t loadAttempts{0};
94+
9295
enum RequestStatus : unsigned int
9396
{
9497
NoRequest = 0,

0 commit comments

Comments
 (0)