From 8a997bcf9e049f46c895e9b399374d3e68427575 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Mon, 10 Jul 2023 15:34:19 +0100 Subject: [PATCH] Render : Improve cache clearing - Only clear caches for whitelisted apps. - Clear per-thread hash caches via `now = true`. --- Changes.md | 1 + src/GafferScene/Render.cpp | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Changes.md b/Changes.md index aabdf43abd7..f0d99bca310 100644 --- a/Changes.md +++ b/Changes.md @@ -51,6 +51,7 @@ Improvements - Ancestors and siblings of locations included in the Visible Set are no longer drawn while their ancestors are collapsed. - Added red wireframe colour to the bounding box of locations excluded from the Visible Set. - HierarchyView : Added support for inclusion and exclusion of leaf level locations to the Visible Set. +- Render : Improved clearing of the compute and hash caches prior to rendering, potentially providing more memory to the renderer. Note that clearing is now only performed in the `execute` and `dispatch` apps. Fixes ----- diff --git a/src/GafferScene/Render.cpp b/src/GafferScene/Render.cpp index f0cbbef311f..4c2908f02af 100644 --- a/src/GafferScene/Render.cpp +++ b/src/GafferScene/Render.cpp @@ -43,6 +43,7 @@ #include "GafferScene/ScenePlug.h" #include "GafferScene/SceneProcessor.h" +#include "Gaffer/ApplicationRoot.h" #include "Gaffer/MonitorAlgo.h" #include "Gaffer/PerformanceMonitor.h" @@ -336,16 +337,21 @@ void Render::executeInternal( bool flushCaches ) const if( flushCaches ) { // Now we have generated the scene, flush Cortex and Gaffer caches to - // provide more memory to the renderer. - /// \todo If executing directly within the gui app flushing the caches - /// is definitely not wanted. Since this scenario is currently uncommon, - /// we prioritise the common case of performing a single render from within - /// `gaffer execute`, but it would be good to do better. - ObjectPool::defaultObjectPool()->clear(); - ValuePlug::clearCache(); - /// \todo This is not as effective as it could be, because it doesn't actually - /// clear the per-thread caches until the next operation on each thread. - ValuePlug::clearHashCache(); + // provide more memory to the renderer. We limit this to the `execute` + // and `dispatch` applications for two reasons : + // + // - In a GUI application, we don't want to clear the caches because + // we'll probably benefit from using them again later. + // - In `execute` and `dispatch` we know we're not executing concurrently + // with anything else, and can therefore pass `now = true` to + // `clearHashCache()` safely. + auto *application = ancestor(); + if( application && ( application->getName() == "execute" || application->getName() == "dispatch" ) ) + { + ObjectPool::defaultObjectPool()->clear(); + ValuePlug::clearCache(); + ValuePlug::clearHashCache( /* now = */ true ); + } } renderer->render();