Blender V4.3
texture_pool.cc
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#include <cstdint>
6
7#include "BLI_hash.hh"
8#include "BLI_map.hh"
10#include "BLI_vector.hh"
11
12#include "GPU_texture.hh"
13
14#include "COM_texture_pool.hh"
15
17
18/* -------------------------------------------------------------------- */
23
24TexturePoolKey::TexturePoolKey(const GPUTexture *texture)
25{
26 size = int2(GPU_texture_width(texture), GPU_texture_height(texture));
27 format = GPU_texture_format(texture);
28}
29
31{
32 return get_default_hash(size.x, size.y, format);
33}
34
36{
37 return a.size == b.size && a.format == b.format;
38}
39
42/* -------------------------------------------------------------------- */
47{
48 /* Check if there is an available texture with the required specification, and if one exists,
49 * return it. */
50 const TexturePoolKey key = TexturePoolKey(size, format);
51 Vector<GPUTexture *> &available_textures = textures_.lookup_or_add_default(key);
52 if (!available_textures.is_empty()) {
53 return available_textures.pop_last();
54 }
55
56 /* Otherwise, allocate a new texture. */
57 return allocate_texture(size, format);
58}
59
60void TexturePool::release(GPUTexture *texture)
61{
62 textures_.lookup(TexturePoolKey(texture)).append(texture);
63}
64
66{
67 textures_.clear();
68}
69
72} // namespace blender::realtime_compositor
int GPU_texture_height(const GPUTexture *texture)
int GPU_texture_width(const GPUTexture *texture)
eGPUTextureFormat
eGPUTextureFormat GPU_texture_format(const GPUTexture *texture)
bool is_empty() const
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)
VecBase< int32_t, 2 > int2
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
unsigned __int64 uint64_t
Definition stdint.h:90