Blender V4.3
COM_cached_resource.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9/* -------------------------------------------------------------------------------------------------
10 * Cached Resource.
11 *
12 * A cached resource is any resource that can be cached across compositor evaluations and across
13 * multiple operations. Cached resources are managed by an instance of a StaticCacheManager, stored
14 * in an instance of a CachedResourceContainer, and are freed when they are no longer needed, a
15 * state which is represented by the `needed` member in the class. For more information on the
16 * caching mechanism, see the StaticCacheManager class.
17 *
18 * To add a new cached resource:
19 *
20 * - Create a key class that can be used to identify the resource in a Map if needed.
21 * - Create a derived class from CachedResource to represent the resource.
22 * - Create a derived class from CachedResourceContainer to store the resources.
23 * - Add an instance of the container to StaticCacheManager and call its reset method.
24 *
25 * See the existing cached resources for reference. */
27 public:
28 /* A flag that represents the needed status of the cached resource. See the StaticCacheManager
29 * class for more information on how this member is utilized in the caching mechanism. */
30 bool needed = true;
31};
32
33/* -------------------------------------------------------------------------------------------------
34 * Cached Resource Container.
35 *
36 * A cached resource container stores all the cached resources for a specific cached resource type.
37 * The cached resources are typically stored in a map identified by a key type. The reset method
38 * should be implemented as described in StaticCacheManager::reset. An appropriate getter method
39 * should be provided that properly sets the CachedResource::needed flag as described in the
40 * description of the StaticCacheManager class.
41 *
42 * See the existing cached resources for reference. */
44 public:
45 /* Reset the container by deleting the cached resources that are no longer needed because they
46 * weren't used in the last evaluation and prepare the remaining cached resources to track their
47 * needed status in the next evaluation. See the description of the StaticCacheManager class for
48 * more information. This should be called in StaticCacheManager::reset. */
49 virtual void reset() = 0;
50};
51
52} // namespace blender::realtime_compositor