mirror of
https://github.com/blender/blender
synced 2026-11-22 03:45:13 +03:00
Evict unused texture cache tiles in viewport rendering. The heuristic is to do this least 2 seconds after the last viewport navigation, and after rendering has completed. When using many render samples this is not ideal, as renders might rarely complete. On the other hand, doing it too early would evict tiles that are used by later render samples. So there is room improve this later, but it's better than not evicting at all.. Pull Request: https://projects.blender.org/blender/blender/pulls/157244
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
/* SPDX-FileCopyrightText: 2026 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
|
|
#include "util/types.h"
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
/* CacheEvictionManager has decides when texture cache eviction should
|
|
* happen in a render session. Different policies are used for viewport
|
|
* and final rendering. */
|
|
class CacheEvictionManager {
|
|
public:
|
|
explicit CacheEvictionManager(bool background);
|
|
|
|
/* Reset state when starting a new render. */
|
|
void reset();
|
|
|
|
/* Set and query if viewport navigation is happening. */
|
|
void set_navigating(bool navigating);
|
|
bool is_navigating() const;
|
|
|
|
/* For a render iteration, check if cache eviction is needed. */
|
|
bool need_eviction(bool idle, bool switched_to_new_tile);
|
|
|
|
/* Wait time until cache eviction needs to be performed. */
|
|
std::chrono::milliseconds wait_time(bool idle) const;
|
|
|
|
private:
|
|
const bool background_;
|
|
|
|
bool navigating_ = false;
|
|
|
|
double viewport_last_activity_ = 0.0;
|
|
bool viewport_was_navigating_ = false;
|
|
int render_tile_count_ = 0;
|
|
|
|
static constexpr double VIEWPORT_EVICTION_DELAY = 2.0;
|
|
};
|
|
|
|
CCL_NAMESPACE_END
|