diff --git a/include/vsg/app/CompileManager.h b/include/vsg/app/CompileManager.h index ee61ac9db..fb9a6d682 100644 --- a/include/vsg/app/CompileManager.h +++ b/include/vsg/app/CompileManager.h @@ -20,6 +20,7 @@ namespace vsg // forward declare class RecordAndSubmitTask; + class Viewer; /// CompileResult struct encapsulates the results of compile traversal. /// Used to help guide further operations done with the compiled subgraph. @@ -36,7 +37,7 @@ namespace vsg void reset(); void add(const CompileResult& cr); - bool requiresViewerUpdate() const; + bool requiresViewerUpdate(const Viewer* viewer = nullptr) const; }; /// ResourceScavenger provides a mechanism for releasing and reusing unused resources when allocation of required GPU memory fails. diff --git a/include/vsg/vk/Slots.h b/include/vsg/vk/Slots.h index 410cfaedb..9f9e5a8f0 100644 --- a/include/vsg/vk/Slots.h +++ b/include/vsg/vk/Slots.h @@ -29,11 +29,18 @@ namespace vsg return view > state ? view : state; } - void merge(const Slots& rhs) + /// update this Slots object to hold the maximum state and view value of this and rhs Slots objects. + void update(const Slots& rhs) { if (rhs.state > state) state = rhs.state; if (rhs.view > view) view = rhs.view; } + + /// return true if this Slots object is less that rhs Slots object and needs to be updated by calling this Slots::merge(rhs). + bool requiresUpdate(const Slots& rhs) const + { + return rhs.state > state || rhs.view > view; + } }; } // namespace vsg diff --git a/src/vsg/app/CompileManager.cpp b/src/vsg/app/CompileManager.cpp index 5799abeec..0a3c14853 100644 --- a/src/vsg/app/CompileManager.cpp +++ b/src/vsg/app/CompileManager.cpp @@ -41,7 +41,7 @@ void CompileResult::add(const CompileResult& cr) result = cr.result; } - maxSlots.merge(cr.maxSlots); + maxSlots.update(cr.maxSlots); if (!containsPagedLOD) containsPagedLOD = cr.containsPagedLOD; @@ -57,7 +57,7 @@ void CompileResult::add(const CompileResult& cr) dynamicData.add(cr.dynamicData); } -bool CompileResult::requiresViewerUpdate() const +bool CompileResult::requiresViewerUpdate(const Viewer* viewer) const { if (result == VK_INCOMPLETE) return false; @@ -67,6 +67,18 @@ bool CompileResult::requiresViewerUpdate() const { if (!binDetails.indices.empty() || !binDetails.bins.empty()) return true; } + + if (viewer) + { + for (const auto& task : viewer->recordAndSubmitTasks) + { + for (const auto& commandGraph : task->commandGraphs) + { + if (commandGraph->maxSlots.requiresUpdate(maxSlots)) return true; + } + } + } + return false; } diff --git a/src/vsg/app/CompileTraversal.cpp b/src/vsg/app/CompileTraversal.cpp index 9eecb7076..4d30a6537 100644 --- a/src/vsg/app/CompileTraversal.cpp +++ b/src/vsg/app/CompileTraversal.cpp @@ -325,7 +325,7 @@ void CompileTraversal::apply(CommandGraph& commandGraph) for (const auto& context : contexts) { - commandGraph.maxSlots.merge(context->resourceRequirements.maxSlots); + commandGraph.maxSlots.update(context->resourceRequirements.maxSlots); } commandGraph.traverse(*this); @@ -339,7 +339,7 @@ void CompileTraversal::apply(SecondaryCommandGraph& secondaryCommandGraph) for (auto& context : contexts) { - secondaryCommandGraph.maxSlots.merge(context->resourceRequirements.maxSlots); + secondaryCommandGraph.maxSlots.update(context->resourceRequirements.maxSlots); // save previous states to be restored after traversal auto previousRenderPass = context->renderPass; diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 8aa2a3053..d61d9685e 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -306,7 +306,7 @@ void vsg::updateTasks(RecordAndSubmitTasks& tasks, ref_ptr compi { for (const auto& commandGraph : task->commandGraphs) { - commandGraph->maxSlots.merge(compileResult.maxSlots); + commandGraph->maxSlots.update(compileResult.maxSlots); } } diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index b091835b9..f1da14018 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -794,17 +794,22 @@ void Viewer::update() { CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer update", COLOR_UPDATE); + CompileResult cr; + // merge any updates from the DatabasePager for (const auto& task : recordAndSubmitTasks) { if (task->databasePager) { - CompileResult cr; task->databasePager->updateSceneGraph(_frameStamp, cr); - if (cr.requiresViewerUpdate()) updateViewer(*this, cr); } } + if (cr.requiresViewerUpdate(this)) + { + updateViewer(*this, cr); + } + // run update operations updateOperations->run(); diff --git a/src/vsg/state/ViewDependentState.cpp b/src/vsg/state/ViewDependentState.cpp index 984664b31..801cd28ff 100644 --- a/src/vsg/state/ViewDependentState.cpp +++ b/src/vsg/state/ViewDependentState.cpp @@ -421,7 +421,7 @@ void ViewDependentState::update(ResourceRequirements& requirements) { if (preRenderCommandGraph) { - preRenderCommandGraph->maxSlots.merge(requirements.maxSlots); + preRenderCommandGraph->maxSlots.update(requirements.maxSlots); } } diff --git a/src/vsg/vk/Context.cpp b/src/vsg/vk/Context.cpp index dc4d9b8b6..38e4c5ef5 100644 --- a/src/vsg/vk/Context.cpp +++ b/src/vsg/vk/Context.cpp @@ -201,7 +201,7 @@ VkResult Context::reserve(ResourceRequirements& requirements) if (deviceMemoryBufferPools->compileTraversalUseReserve) result = deviceMemoryBufferPools->reserve(requirements); - resourceRequirements.maxSlots.merge(requirements.maxSlots); + resourceRequirements.maxSlots.update(requirements.maxSlots); descriptorPools->reserve(requirements); diff --git a/src/vsg/vk/ResourceRequirements.cpp b/src/vsg/vk/ResourceRequirements.cpp index 6a5bb6ae7..9b0229948 100644 --- a/src/vsg/vk/ResourceRequirements.cpp +++ b/src/vsg/vk/ResourceRequirements.cpp @@ -66,7 +66,7 @@ DescriptorPoolSizes ResourceRequirements::computeDescriptorPoolSizes() const void ResourceRequirements::apply(const ResourceHints& resourceHints) { - maxSlots.merge(resourceHints.maxSlots); + maxSlots.update(resourceHints.maxSlots); if (!resourceHints.descriptorPoolSizes.empty() || resourceHints.numDescriptorSets > 0) {