Blender
V4.3
source
blender
compositor
realtime_compositor
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
"
10
#include "
BLI_math_vector_types.hh
"
11
#include "
BLI_vector.hh
"
12
13
#include "
GPU_texture.hh
"
14
15
namespace
blender::realtime_compositor
{
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. */
22
class
TexturePoolKey
{
23
public
:
24
int2
size
;
25
eGPUTextureFormat
format
;
26
27
/* Construct a key from the given texture size and format. */
28
TexturePoolKey
(
int2
size,
eGPUTextureFormat
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
36
bool
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. */
50
class
TexturePool
{
51
private
:
52
/* The set of textures in the pool that are available to acquire for each distinct texture
53
* specification. */
54
Map<TexturePoolKey, Vector<GPUTexture *>
> textures_;
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
BLI_map.hh
BLI_math_vector_types.hh
BLI_vector.hh
GPU_texture.hh
eGPUTextureFormat
eGPUTextureFormat
Definition
GPU_texture.hh:399
blender::Map
Definition
BLI_map.hh:129
blender::realtime_compositor::TexturePoolKey
Definition
COM_texture_pool.hh:22
blender::realtime_compositor::TexturePoolKey::format
eGPUTextureFormat format
Definition
COM_texture_pool.hh:25
blender::realtime_compositor::TexturePoolKey::size
int2 size
Definition
COM_texture_pool.hh:24
blender::realtime_compositor::TexturePoolKey::hash
uint64_t hash() const
Definition
texture_pool.cc:30
blender::realtime_compositor::TexturePoolKey::TexturePoolKey
TexturePoolKey(int2 size, eGPUTextureFormat format)
Definition
texture_pool.cc:22
blender::realtime_compositor::TexturePool
Definition
COM_texture_pool.hh:50
blender::realtime_compositor::TexturePool::release
void release(GPUTexture *texture)
Definition
texture_pool.cc:60
blender::realtime_compositor::TexturePool::acquire
GPUTexture * acquire(int2 size, eGPUTextureFormat format)
Definition
texture_pool.cc:46
blender::realtime_compositor::TexturePool::reset
void reset()
Definition
texture_pool.cc:65
b
local_group_size(16, 16) .push_constant(Type b
Definition
compositor_morphological_distance_info.hh:16
format
format
Definition
logImageCore.h:39
blender::realtime_compositor
Definition
BKE_node.hh:80
blender::realtime_compositor::operator==
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
Definition
bokeh_kernel.cc:42
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:90
blender::VecBase< int32_t, 2 >
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0