30 return texture == other.texture;
54 for (GPUTexture *
tex : pool->tmp_tex_acquired) {
72 "Pool textures must be of usage type attachment.");
75 int user_id = pool->last_user_id;
78 if (pool->users[user_id] != user) {
84 user_id = pool->users.first_index_of_try(user);
88 user_id = pool->users.size();
89 pool->users.append(user);
93 pool->last_user_id = user_id;
98 if (user_bit & handle.users_bits) {
107 handle.users_bits |= user_bit;
108 return handle.texture;
112 char name[16] =
"DRW_tex_pool";
114 int texture_id = pool->handles.size();
115 SNPRINTF(name,
"DRW_tex_pool_%d", texture_id);
120 handle.orphan_cycles = 0;
122 pool->handles.append(handle);
129 return handle.texture;
135 GPUTexture *tmp_tex =
nullptr;
138 auto texture_match = [&](GPUTexture *
tex) ->
bool {
145 for (
auto i : pool->tmp_tex_released.index_range()) {
146 if (texture_match(pool->tmp_tex_released[i].texture)) {
147 tmp_tex = pool->tmp_tex_released[i].texture;
154 pool->tmp_tex_released.remove_and_reorder(found_index);
158 char name[16] =
"DRW_tex_pool";
160 int texture_id = pool->handles.size();
161 SNPRINTF(name,
"DRW_tex_pool_%d", texture_id);
166 pool->tmp_tex_acquired.append(tmp_tex);
173 pool->tmp_tex_acquired.remove_first_occurrence_and_reorder(tmp_tex);
174 pool->tmp_tex_released.append({tmp_tex, 0});
179 pool->tmp_tex_acquired.remove_first_occurrence_and_reorder(
tex);
184 pool->tmp_tex_acquired.append(
tex);
191 const int max_orphan_cycles = 8;
193 pool->last_user_id = -1;
195 for (
auto it = pool->handles.rbegin(); it != pool->handles.rend(); ++it) {
197 if (handle.users_bits == 0) {
199 if (handle.texture && handle.orphan_cycles >= max_orphan_cycles) {
201 handle.texture =
nullptr;
205 handle.users_bits = 0;
206 handle.orphan_cycles = 0;
211 for (
int i = pool->handles.size() - 1; i >= 0; i--) {
212 if (!pool->handles[i].texture) {
213 pool->handles.remove_and_reorder(i);
218 "Missing a TextureFromPool.release() before end of draw.");
220 for (
int i = pool->tmp_tex_released.size() - 1; i >= 0; i--) {
222 if (
tex.orphan_cycles >= max_orphan_cycles) {
224 pool->tmp_tex_released.remove_and_reorder(i);
#define BLI_assert_msg(a, msg)
#define SNPRINTF(dst, format,...)
int GPU_texture_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
int GPU_texture_width(const GPUTexture *texture)
bool GPU_texture_has_integer_format(const GPUTexture *texture)
@ GPU_TEXTURE_USAGE_ATTACHMENT
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
#define GPU_TEXTURE_FREE_SAFE(texture)
eGPUTextureUsage GPU_texture_usage(const GPUTexture *texture)
bool GPU_texture_has_depth_format(const GPUTexture *texture)
eGPUTextureFormat GPU_texture_format(const GPUTexture *texture)
void DRW_texture_pool_free(DRWTexturePool *pool)
GPUTexture * DRW_texture_pool_texture_acquire(DRWTexturePool *pool, int width, int height, eGPUTextureFormat format, eGPUTextureUsage usage)
DRWTexturePool * DRW_texture_pool_create()
GPUTexture * DRW_texture_pool_query(DRWTexturePool *pool, int width, int height, eGPUTextureFormat format, eGPUTextureUsage usage, void *user)
void DRW_texture_pool_reset(DRWTexturePool *pool)
void DRW_texture_pool_texture_release(DRWTexturePool *pool, GPUTexture *tmp_tex)
void DRW_texture_pool_take_texture_ownership(DRWTexturePool *pool, GPUTexture *tex)
void DRW_texture_pool_give_texture_ownership(DRWTexturePool *pool, GPUTexture *tex)
unsigned __int64 uint64_t
Vector< void *, 16 > users
Vector< DRWTexturePoolHandle > handles
Vector< ReleasedTexture > tmp_tex_released
Vector< GPUTexture * > tmp_tex_acquired
bool operator==(const ReleasedTexture &other)