diff options
author | Omar Emara <mail@OmarEmara.dev> | 2022-11-04 17:14:22 +0300 |
---|---|---|
committer | Omar Emara <mail@OmarEmara.dev> | 2022-11-04 17:14:22 +0300 |
commit | 85ce4882981943b5a306090f03482bd5397c503d (patch) | |
tree | ee5c20f6a58d7688a304f4958d5466a4c707c375 /source/blender/compositor/realtime_compositor/intern/static_cache_manager.cc | |
parent | 943d574185d784c8e4c30b50e52e11f54b11ec50 (diff) |
Realtime Compositor: Implement static cache manager
This patch introduces the concept of a Cached Resource that can be
cached across compositor evaluations as well as used by multiple
operations in the same evaluation. Additionally, this patch implements a
new structure for the realtime compositor, the Static Cache Manager,
that manages all the cached resources and deletes them when they are no
longer needed.
This improves responsiveness while adjusting compositor node trees and
also conserves memory usage.
Differential Revision: https://developer.blender.org/D16357
Reviewed By: Clement Foucault
Diffstat (limited to 'source/blender/compositor/realtime_compositor/intern/static_cache_manager.cc')
-rw-r--r-- | source/blender/compositor/realtime_compositor/intern/static_cache_manager.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/blender/compositor/realtime_compositor/intern/static_cache_manager.cc b/source/blender/compositor/realtime_compositor/intern/static_cache_manager.cc new file mode 100644 index 00000000000..da78412a815 --- /dev/null +++ b/source/blender/compositor/realtime_compositor/intern/static_cache_manager.cc @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <memory> + +#include "BLI_math_vec_types.hh" + +#include "COM_morphological_distance_feather_weights.hh" +#include "COM_symmetric_blur_weights.hh" +#include "COM_symmetric_separable_blur_weights.hh" + +#include "COM_static_cache_manager.hh" + +namespace blender::realtime_compositor { + +/* -------------------------------------------------------------------- + * Static Cache Manager. + */ + +void StaticCacheManager::reset() +{ + /* First, delete all resources that are no longer needed. */ + symmetric_blur_weights_.remove_if([](auto item) { return !item.value->needed; }); + symmetric_separable_blur_weights_.remove_if([](auto item) { return !item.value->needed; }); + morphological_distance_feather_weights_.remove_if([](auto item) { return !item.value->needed; }); + + /* Second, reset the needed status of the remaining resources to false to ready them to track + * their needed status for the next evaluation. */ + for (auto &value : symmetric_blur_weights_.values()) { + value->needed = false; + } + for (auto &value : symmetric_separable_blur_weights_.values()) { + value->needed = false; + } + for (auto &value : morphological_distance_feather_weights_.values()) { + value->needed = false; + } +} + +SymmetricBlurWeights &StaticCacheManager::get_symmetric_blur_weights(int type, float2 radius) +{ + const SymmetricBlurWeightsKey key(type, radius); + + auto &weights = *symmetric_blur_weights_.lookup_or_add_cb( + key, [&]() { return std::make_unique<SymmetricBlurWeights>(type, radius); }); + + weights.needed = true; + return weights; +} + +SymmetricSeparableBlurWeights &StaticCacheManager::get_symmetric_separable_blur_weights( + int type, float radius) +{ + const SymmetricSeparableBlurWeightsKey key(type, radius); + + auto &weights = *symmetric_separable_blur_weights_.lookup_or_add_cb( + key, [&]() { return std::make_unique<SymmetricSeparableBlurWeights>(type, radius); }); + + weights.needed = true; + return weights; +} + +MorphologicalDistanceFeatherWeights &StaticCacheManager:: + get_morphological_distance_feather_weights(int type, int radius) +{ + const MorphologicalDistanceFeatherWeightsKey key(type, radius); + + auto &weights = *morphological_distance_feather_weights_.lookup_or_add_cb( + key, [&]() { return std::make_unique<MorphologicalDistanceFeatherWeights>(type, radius); }); + + weights.needed = true; + return weights; +} + +} // namespace blender::realtime_compositor |