Blender V5.3
COM_cached_image.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
7#include <cstdint>
8#include <memory>
9#include <string>
10
11#include "BLI_map.hh"
12
13#include "GPU_texture.hh"
14
15#include "DNA_image_types.h"
16
17#include "RE_pipeline.h"
18
20#include "COM_result.hh"
21
22namespace blender::compositor {
23
24class Context;
25
26/* ------------------------------------------------------------------------------------------------
27 * Cached Image Key.
28 */
30 public:
31 const int layer_index;
32 const std::string pass_name;
33 const std::string view_name;
34 const int frame;
35
37 const std::string pass_name,
38 const std::string view_name,
39 const int frame);
40
41 uint64_t hash() const;
42};
43
44bool operator==(const CachedImageKey &a, const CachedImageKey &b);
45
46/* -------------------------------------------------------------------------------------------------
47 * Cached Image.
48 *
49 * A cached resource that computes and caches a result containing the contents of the image with
50 * the given image user. */
52 public:
54
55 private:
56 /* For GPU, the result wraps an external GPU texture that is generated by the IMB module and
57 * stored in this member to be freed when the cached resource is deleted. */
58 gpu::Texture *texture_ = nullptr;
59
60 public:
61 CachedImage(Context &context, Image &image, ImageUser &image_user, const char *pass_name);
62
64
65 private:
66 /* Populates the Cryptomatte meta data of the image. */
67 void populate_cryptomatte_meta_data(const RenderResult *render_result,
68 const ImageUser &image_user);
69
70 /* Populates the meta data of the image. */
71 void populate_meta_data(const ImBuf *image_buffer);
72};
73
74/* ------------------------------------------------------------------------------------------------
75 * Cached Image Container.
76 */
78 private:
80
81 /* A map that stores the update counts of the images at the moment they were cached. */
82 Map<std::string, uint64_t> update_counts_;
83
84 public:
85 void reset() override;
86
87 /* Check if the given image has changed since it was cached, and if so, invalidate its cache
88 * entry. Then, check if there is an available CachedImage cached resource with the given image
89 * user and pass_name in the container, if one exists, return it, otherwise, return a newly
90 * created one and add it to the container. In both cases, tag the cached resource as needed to
91 * keep it cached for the next evaluation. */
92 Result &get(Context &context, Image &image, const ImageUser &image_user, const char *pass_name);
93};
94
95} // namespace blender::compositor
Result & get(Context &context, Image &image, const ImageUser &image_user, const char *pass_name)
CachedImageKey(const int layer_index, const std::string pass_name, const std::string view_name, const int frame)
CachedImage(Context &context, Image &image, ImageUser &image_user, const char *pass_name)
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
unsigned __int64 uint64_t
Definition BKE_text.h:91