Skip to content

Commit 78f0618

Browse files
Merge pull request #1705 from vsg-dev/DatabasePager_CompileResult_fix
Refactord how CompileResults::maxSlots is managed to ensure changes from the DatabasePager gets passed on to updateViewer(..)
2 parents 30f8c34 + 57281cd commit 78f0618

9 files changed

Lines changed: 37 additions & 12 deletions

File tree

include/vsg/app/CompileManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace vsg
2020

2121
// forward declare
2222
class RecordAndSubmitTask;
23+
class Viewer;
2324

2425
/// CompileResult struct encapsulates the results of compile traversal.
2526
/// Used to help guide further operations done with the compiled subgraph.
@@ -36,7 +37,7 @@ namespace vsg
3637

3738
void reset();
3839
void add(const CompileResult& cr);
39-
bool requiresViewerUpdate() const;
40+
bool requiresViewerUpdate(const Viewer* viewer = nullptr) const;
4041
};
4142

4243
/// ResourceScavenger provides a mechanism for releasing and reusing unused resources when allocation of required GPU memory fails.

include/vsg/vk/Slots.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ namespace vsg
2929
return view > state ? view : state;
3030
}
3131

32-
void merge(const Slots& rhs)
32+
/// update this Slots object to hold the maximum state and view value of this and rhs Slots objects.
33+
void update(const Slots& rhs)
3334
{
3435
if (rhs.state > state) state = rhs.state;
3536
if (rhs.view > view) view = rhs.view;
3637
}
38+
39+
/// return true if this Slots object is less that rhs Slots object and needs to be updated by calling this Slots::merge(rhs).
40+
bool requiresUpdate(const Slots& rhs) const
41+
{
42+
return rhs.state > state || rhs.view > view;
43+
}
3744
};
3845

3946
} // namespace vsg

src/vsg/app/CompileManager.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void CompileResult::add(const CompileResult& cr)
4141
result = cr.result;
4242
}
4343

44-
maxSlots.merge(cr.maxSlots);
44+
maxSlots.update(cr.maxSlots);
4545

4646
if (!containsPagedLOD) containsPagedLOD = cr.containsPagedLOD;
4747

@@ -57,7 +57,7 @@ void CompileResult::add(const CompileResult& cr)
5757
dynamicData.add(cr.dynamicData);
5858
}
5959

60-
bool CompileResult::requiresViewerUpdate() const
60+
bool CompileResult::requiresViewerUpdate(const Viewer* viewer) const
6161
{
6262
if (result == VK_INCOMPLETE) return false;
6363

@@ -67,6 +67,18 @@ bool CompileResult::requiresViewerUpdate() const
6767
{
6868
if (!binDetails.indices.empty() || !binDetails.bins.empty()) return true;
6969
}
70+
71+
if (viewer)
72+
{
73+
for (const auto& task : viewer->recordAndSubmitTasks)
74+
{
75+
for (const auto& commandGraph : task->commandGraphs)
76+
{
77+
if (commandGraph->maxSlots.requiresUpdate(maxSlots)) return true;
78+
}
79+
}
80+
}
81+
7082
return false;
7183
}
7284

src/vsg/app/CompileTraversal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void CompileTraversal::apply(CommandGraph& commandGraph)
325325

326326
for (const auto& context : contexts)
327327
{
328-
commandGraph.maxSlots.merge(context->resourceRequirements.maxSlots);
328+
commandGraph.maxSlots.update(context->resourceRequirements.maxSlots);
329329
}
330330

331331
commandGraph.traverse(*this);
@@ -339,7 +339,7 @@ void CompileTraversal::apply(SecondaryCommandGraph& secondaryCommandGraph)
339339

340340
for (auto& context : contexts)
341341
{
342-
secondaryCommandGraph.maxSlots.merge(context->resourceRequirements.maxSlots);
342+
secondaryCommandGraph.maxSlots.update(context->resourceRequirements.maxSlots);
343343

344344
// save previous states to be restored after traversal
345345
auto previousRenderPass = context->renderPass;

src/vsg/app/RecordAndSubmitTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void vsg::updateTasks(RecordAndSubmitTasks& tasks, ref_ptr<CompileManager> compi
306306
{
307307
for (const auto& commandGraph : task->commandGraphs)
308308
{
309-
commandGraph->maxSlots.merge(compileResult.maxSlots);
309+
commandGraph->maxSlots.update(compileResult.maxSlots);
310310
}
311311
}
312312

src/vsg/app/Viewer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,17 +794,22 @@ void Viewer::update()
794794
{
795795
CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer update", COLOR_UPDATE);
796796

797+
CompileResult cr;
798+
797799
// merge any updates from the DatabasePager
798800
for (const auto& task : recordAndSubmitTasks)
799801
{
800802
if (task->databasePager)
801803
{
802-
CompileResult cr;
803804
task->databasePager->updateSceneGraph(_frameStamp, cr);
804-
if (cr.requiresViewerUpdate()) updateViewer(*this, cr);
805805
}
806806
}
807807

808+
if (cr.requiresViewerUpdate(this))
809+
{
810+
updateViewer(*this, cr);
811+
}
812+
808813
// run update operations
809814
updateOperations->run();
810815

src/vsg/state/ViewDependentState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ void ViewDependentState::update(ResourceRequirements& requirements)
421421
{
422422
if (preRenderCommandGraph)
423423
{
424-
preRenderCommandGraph->maxSlots.merge(requirements.maxSlots);
424+
preRenderCommandGraph->maxSlots.update(requirements.maxSlots);
425425
}
426426
}
427427

src/vsg/vk/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ VkResult Context::reserve(ResourceRequirements& requirements)
201201

202202
if (deviceMemoryBufferPools->compileTraversalUseReserve) result = deviceMemoryBufferPools->reserve(requirements);
203203

204-
resourceRequirements.maxSlots.merge(requirements.maxSlots);
204+
resourceRequirements.maxSlots.update(requirements.maxSlots);
205205

206206
descriptorPools->reserve(requirements);
207207

src/vsg/vk/ResourceRequirements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ DescriptorPoolSizes ResourceRequirements::computeDescriptorPoolSizes() const
6666

6767
void ResourceRequirements::apply(const ResourceHints& resourceHints)
6868
{
69-
maxSlots.merge(resourceHints.maxSlots);
69+
maxSlots.update(resourceHints.maxSlots);
7070

7171
if (!resourceHints.descriptorPoolSizes.empty() || resourceHints.numDescriptorSets > 0)
7272
{

0 commit comments

Comments
 (0)