Blender V5.0
GPU_texture_pool.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14#include "BLI_vector.hh"
15
16#include "GPU_texture.hh"
17
18namespace blender::gpu {
19
21 private:
22 /* Defer deallocation enough cycles to avoid interleaved calls to different viewport render
23 * functions (selection / display) causing constant allocation / deallocation (See #113024). */
24 static constexpr int max_unused_cycles_ = 8;
25
26 struct TextureHandle {
28 /* Counts the number of `reset()` call since the last use.
29 * The texture memory is deallocated after a certain number of cycles. */
30 int unused_cycles;
31 };
32
33 /* Pool of texture ready to be reused. */
35 /* List of textures that are currently being used. Tracked to check memory leak. */
37
38 public:
40
41 /* Return the texture pool from the active GPUContext.
42 * Only valid if a context is active. */
43 static TexturePool &get();
44
45 /* Acquire a texture from the pool with the given characteristics. */
47 int height,
49 eGPUTextureUsage usage);
50 /* Release the texture so that its memory can be reused at some other point. */
52
53 /* Transfer ownership of a texture from the pool to the caller. */
55 /* Transfer back ownership to the pool. The texture will become part of the pool. */
57
58 /* Ensure no texture is still acquired and release unused textures.
59 * If `force_free` is true, free all the texture memory inside the pool.
60 * Otherwise, only unused textures will be freed. */
61 void reset(bool force_free = false);
62};
63
64} // namespace blender::gpu
eGPUTextureUsage
void reset()
clear internal cached data and reset random seed
blender::gpu::Texture * acquire_texture(int width, int height, blender::gpu::TextureFormat format, eGPUTextureUsage usage)
void give_texture_ownership(blender::gpu::Texture *tex)
void take_texture_ownership(blender::gpu::Texture *tex)
static TexturePool & get()
void release_texture(blender::gpu::Texture *tmp_tex)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
format