68 bool exact_format_match =
false;
69 for (
uint64_t i : pool_.index_range()) {
70 const AllocationHandle &handle = pool_[i];
72 if (
int3(handle.texture->
w_, handle.texture->
h_, handle.texture->
d_) != extent) {
76 if (handle.texture->
mip_count() != mip_len) {
86 if ((handle.texture->
usage_get() & usage_flag) != usage_flag) {
90 exact_format_match = (format == handle.texture->
format_get());
93 bool writable_texture = usage &
100 if (!exact_format_match && writable_texture) {
109 TextureHandle texture_handle;
112 if (match_index != -1) {
113 texture_handle.texture = pool_[match_index].texture;
114 pool_.remove_and_reorder(match_index);
118 std::string texture_name_str;
120 texture_name_str = fmt::format(
"TexFromPool_{}", pool_.size());
125 bool texture_result =
false;
130 texture_result =
texture->init_1D(extent.x, extent.y, mip_len, format);
134 texture_result =
texture->init_2D(extent.x, extent.y, extent.z, mip_len, format);
137 texture_result =
texture->init_3D(extent.x, extent.y, extent.z, mip_len, format);
141 texture_result =
texture->init_cubemap(extent.x, extent.y, mip_len, format);
150 exact_format_match =
true;
169 if (exact_format_match) {
172 texture_handle.view = texture_handle.texture;
176 std::string view_name_str;
178 view_name_str = name ? name : texture_handle.texture->
name_;
183 bool view_result =
false;
191 texture_handle.texture, format, type, 0, mip_len, 0, 1,
false,
false);
195 texture_handle.texture, format, type, 0, mip_len, 0, extent.y,
false,
false);
200 texture_handle.texture, format, type, 0, mip_len, 0, extent.z,
false,
false);
208 texture_handle.view =
unwrap(view);
212 current_usage_data_.usage_count++;
213 current_usage_data_.usage_count_max = std::max(current_usage_data_.usage_count,
214 current_usage_data_.usage_count_max);
217 acquired_.add(texture_handle);
218 return wrap(texture_handle.view);
224 "Unacquired texture passed to TexturePool::release_texture()");
225 TextureHandle texture_handle = acquired_.lookup_key({
unwrap(tex), {}, 1});
228 current_usage_data_.usage_count--;
232 AllocationHandle allocation_handle;
233 allocation_handle.texture = texture_handle.texture;
234 pool_.append(allocation_handle);
237 if (texture_handle.view && texture_handle.view != texture_handle.texture) {
240 acquired_.remove(texture_handle);
257 for (
const TextureHandle &tex : acquired_) {
259 "Missing texture release/retain. Likely TextureFromPool::release(), "
260 "TextureFromPool::retain() or TexturePool::release_texture().");
265 for (
int i = pool_.size() - 1; i >= 0; i--) {
266 AllocationHandle &handle = pool_[i];
267 if (handle.unused_cycles_count >= max_unused_cycles_ || force_free) {
269 pool_.remove_and_reorder(i);
272 handle.unused_cycles_count++;
278 if (!(previous_usage_data_ == current_usage_data_)) {
283 previous_usage_data_ = current_usage_data_;
284 current_usage_data_ = {};
285 current_usage_data_.usage_count = acquired_.size();
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 reset(bool force_free=false) override
void release_texture(Texture *tex) override
eGPUTextureUsage usage_get() const
bool init_view(Texture *src, TextureFormat format, GPUTextureType type, int mip_start, int mip_len, int layer_start, int layer_len, bool cube_as_array, bool use_stencil)
TextureFormat format_get() const