Blender V4.3
COM_texture_pool.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
9#include "BLI_map.hh"
11#include "BLI_vector.hh"
12
13#include "GPU_texture.hh"
14
16
17/* ------------------------------------------------------------------------------------------------
18 * Texture Pool Key
19 *
20 * A key used to identify a texture specification in a texture pool. Defines a hash and an equality
21 * operator for use in a hash map. */
23 public:
26
27 /* Construct a key from the given texture size and format. */
29
30 /* Construct a key from the size and format of the given texture. */
31 TexturePoolKey(const GPUTexture *texture);
32
33 uint64_t hash() const;
34};
35
36bool operator==(const TexturePoolKey &a, const TexturePoolKey &b);
37
38/* ------------------------------------------------------------------------------------------------
39 * Texture Pool
40 *
41 * A texture pool allows the allocation and reuse of textures throughout the execution of the
42 * compositor to avoid memory fragmentation and texture allocation overheads. The texture pool
43 * delegates the actual texture allocation to an allocate_texture method that should be implemented
44 * by the caller of the compositor evaluator, allowing a more agnostic and flexible execution that
45 * can be controlled by the caller. If the compositor is expected to execute frequently, like on
46 * every redraw, then the allocation method should use a persistent texture pool to allow
47 * cross-evaluation texture pooling, for instance, by using the DRWTexturePool. But if the
48 * evaluator is expected to execute infrequently, the allocated textures can just be freed when the
49 * evaluator is done, that is, when the pool is destructed. */
51 private:
52 /* The set of textures in the pool that are available to acquire for each distinct texture
53 * specification. */
55
56 public:
57 /* Check if there is an available texture with the given specification in the pool, if such
58 * texture exists, return it, otherwise, return a newly allocated texture. Expect the texture to
59 * be uncleared and possibly contains garbage data. */
60 GPUTexture *acquire(int2 size, eGPUTextureFormat format);
61
62 /* Put the texture back into the pool, potentially to be acquired later by another user. Expects
63 * the texture to be one that was acquired using the same texture pool. */
64 void release(GPUTexture *texture);
65
66 /* Reset the texture pool by clearing all available textures without freeing the textures. If the
67 * textures will no longer be needed, they should be freed in the destructor. This should be
68 * called after the compositor is done evaluating. */
69 void reset();
70
71 private:
72 /* Returns a newly allocated texture with the given specification. This method should be
73 * implemented by the caller of the compositor evaluator. See the class description for more
74 * information. */
75 virtual GPUTexture *allocate_texture(int2 size, eGPUTextureFormat format) = 0;
76};
77
78} // namespace blender::realtime_compositor
eGPUTextureFormat
TexturePoolKey(int2 size, eGPUTextureFormat format)
GPUTexture * acquire(int2 size, eGPUTextureFormat format)
local_group_size(16, 16) .push_constant(Type b
format
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
unsigned __int64 uint64_t
Definition stdint.h:90