From 57281cde5371a7920c59034f90fc6b07d6358489 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 May 2026 16:01:23 +0100 Subject: [PATCH] Refactord how CompileResults::maxSlots is managed to ensure changes from the DatabasePager gets passed on to updateViewer(..) --- include/vsg/app/CompileManager.h | 3 ++- include/vsg/vk/Slots.h | 9 ++++++++- src/vsg/app/CompileManager.cpp | 16 ++++++++++++++-- src/vsg/app/CompileTraversal.cpp | 4 ++-- src/vsg/app/RecordAndSubmitTask.cpp | 2 +- src/vsg/app/Viewer.cpp | 9 +++++++-- src/vsg/state/ViewDependentState.cpp | 2 +- src/vsg/vk/Context.cpp | 2 +- src/vsg/vk/ResourceRequirements.cpp | 2 +- 9 files changed, 37 insertions(+), 12 deletions(-) diff --git a/include/vsg/app/CompileManager.h b/include/vsg/app/CompileManager.h index ee61ac9dbc..fb9a6d6827 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 410cfaedb9..9f9e5a8f09 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 5799abeec8..0a3c148539 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 9eecb70761..4d30a65375 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 8aa2a30531..d61d9685e6 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 b091835b9d..f1da140180 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 984664b316..801cd28ff4 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 dc4d9b8b68..38e4c5ef5b 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 6a5bb6ae76..9b02299488 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) {