Blender V5.3
gl_texture_pool.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "gl_texture.hh"
13
14namespace blender::gpu {
15
17 /* Defer deallocation enough cycles to avoid interleaved calls to different viewport render
18 * functions (selection / display) causing constant allocation / deallocation (See #113024). */
19 static constexpr int max_unused_cycles_ = 8;
20
21 struct AllocationHandle {
22 GLTexture *texture = nullptr;
23
24 /* Counter to track the number of unused cycles before deallocation in `pool_`. */
25 int unused_cycles_count = 0;
26 };
27
28 struct TextureHandle {
29 GLTexture *view = nullptr;
30 GLTexture *texture = nullptr;
31
32 /* Counter to track texture acquire/retain mismatches in `acquire_`. */
33 int users_count = 1;
34
35 /* We use the pointer as hash/comparator, as a texture cannot be acquired twice. */
36 uint64_t hash() const
37 {
38 return get_default_hash(view);
39 }
40
41 bool operator==(const TextureHandle &o) const
42 {
43 return view == o.view;
44 }
45 };
46
48 Set<TextureHandle> acquired_;
49
50 /* Debug storage to log memory usage. Log is only output
51 * if values have changed since the last `::reset()`. */
52 struct LogUsageData {
53 int64_t usage_count = 0;
54 int64_t usage_count_max = 0;
55
56 bool operator==(const LogUsageData &o) const
57 {
58 return std::tie(usage_count, usage_count_max) == std::tie(o.usage_count, o.usage_count_max);
59 }
60 };
61 LogUsageData previous_usage_data_ = {};
62 LogUsageData current_usage_data_ = {};
63
64 /* Output usage data to debug log. Called on `--debug-gpu` */
65 void log_usage_data() const;
66
67 protected:
69 int mip_len,
70 GPUTextureType type,
71 TextureFormat format,
73 const char *name = nullptr) override;
74
75 public:
77
78 void release_texture(Texture *tex) override;
79
80 void reset(bool force_free = false) override;
81
82 void offset_users_count(Texture *tex, int offset) override;
83};
84
85} // namespace blender::gpu
Texture * acquire_texture_impl(int3 extent, int mip_len, GPUTextureType type, TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const char *name=nullptr) override
void offset_users_count(Texture *tex, int offset) override
void release_texture(Texture *tex) override
void reset(bool force_free=false) override
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
bool operator==(const GPUState &a, const GPUState &b)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_GENERAL
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
#define hash
Definition noise_c.cc:156