Blender V5.3
cache_eviction.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
6
7#include <chrono>
8
9#include "util/math_base.h"
10#include "util/time.h"
11
13
14CacheEvictionManager::CacheEvictionManager(bool background) : background_(background) {}
15
17{
18 render_tile_count_ = 0;
19
20 viewport_last_activity_ = 0.0;
21 viewport_was_navigating_ = false;
22 render_tile_count_ = 0;
23}
24
26{
27 navigating_ = navigating;
28}
29
31{
32 return (background_) ? false : navigating_;
33}
34
35bool CacheEvictionManager::need_eviction(bool idle, bool switched_to_new_tile)
36{
37 /* Final render. */
38 if (background_) {
39 /* Evict before rendering the next tile, except the first one where we
40 * can't determine what was shared with other tiles. */
41 if (idle || !switched_to_new_tile) {
42 return false;
43 }
44
45 render_tile_count_++;
46 return render_tile_count_ >= 2;
47 }
48
49 /* Viewport render. */
50 const bool navigating = navigating_;
51 if (navigating) {
52 /* No eviction while navigating. */
53 viewport_last_activity_ = 0.0;
54 }
55 else if (viewport_was_navigating_) {
56 /* Start eviction timer when navigating stops. */
57 viewport_last_activity_ = time_dt();
58 }
59 viewport_was_navigating_ = navigating;
60
61 if (!idle) {
62 /* Restart eviction timer while not idle. */
63 viewport_last_activity_ = time_dt();
64 return false;
65 }
66
67 if (wait_time(idle) != std::chrono::milliseconds::zero()) {
68 /* Not ready to evict yet. */
69 return false;
70 }
71
72 /* Eviction needed now, clear existing timer. */
73 viewport_last_activity_ = 0.0;
74 return true;
75}
76
77std::chrono::milliseconds CacheEvictionManager::wait_time(bool idle) const
78{
79 if (!idle || background_ || viewport_last_activity_ == 0.0 || viewport_was_navigating_) {
80 /* No eviction pending. */
81 return std::chrono::milliseconds::max();
82 }
83
84 /* Wait for VIEWPORT_EVICTION_DELAY after last activity. */
85 const double elapsed = time_dt() - viewport_last_activity_;
86 const double remaining = VIEWPORT_EVICTION_DELAY - elapsed;
87 return std::chrono::milliseconds(int64_t(max(0.0, remaining) * 1000.0));
88}
89
long long int int64_t
btScalar max
void set_navigating(bool navigating)
std::chrono::milliseconds wait_time(bool idle) const
CacheEvictionManager(bool background)
bool need_eviction(bool idle, bool switched_to_new_tile)
#define CCL_NAMESPACE_END
CCL_NAMESPACE_BEGIN double time_dt()
Definition time.cpp:31