54 if (
image->runtime->cache ==
nullptr) {
58 if (ibuf !=
nullptr) {
73 if (ibuf ==
nullptr) {
82 if (ima->runtime->cache ==
nullptr) {
97 if (ima->runtime->cache ==
nullptr) {
101 std::scoped_lock
lock(ima->runtime->cache_mutex);
106 if (ibuf !=
nullptr && ibuf->
gpu.
texture !=
nullptr) {
156 if (tilearray ==
nullptr) {
165 ImageTile *last_tile = ima->tiles.last();
169 int width = max_tile + 1;
171 for (
int i = 0; i < width; i++) {
175 int i =
tile.tile_number - 1001;
179 float *tile_info = &
data[4 * width + 4 * i];
190 gpu::TextureFormat::SFLOAT_32_32_32_32,
193 if (tex !=
nullptr) {
218 int arraywidth = 0, arrayheight = 0;
219 ListBaseT<FixedSizeBoxPack> boxes = {
nullptr};
221 bool all_grayscale =
true;
250 all_grayscale =
false;
255 BLI_assert(arraywidth > 0 && arrayheight > 0);
260 while (boxes.first() !=
nullptr) {
261 ListBaseT<FixedSizeBoxPack> packed = {
nullptr};
272 tileoffset[0] = packtile->
boxpack.
x;
273 tileoffset[1] = packtile->
boxpack.
y;
279 packed.free_no_destruct();
284 const bool use_grayscale = all_grayscale;
305 if (tilesize[0] == 0 || tilesize[1] == 0) {
322 store_premultiplied);
351 std::scoped_lock
lock(ima->runtime->cache_mutex);
354 const int current_frame = current_ibuf->
fileframe;
401 if (ima->runtime->gpu_load_error_logged) {
404 ima->runtime->gpu_load_error_logged =
true;
418 STRNCPY(filepath, ima->id.name + 2);
426 CLOG_ERROR(&
LOG,
"Image file \"%s\" does not exist", filepath);
429 CLOG_ERROR(&
LOG,
"Failed to create texture for \"%s\"", filepath);
436 ima->runtime->gpu_load_error_logged =
false;
464 if (atlas_ibuf ==
nullptr) {
470 bool need_full_rebuild =
false;
473 if (iuser !=
nullptr) {
488 if (ibuf !=
nullptr) {
490 switch (changes.
kind) {
491 case Changes::Kind::Resized:
492 need_full_rebuild =
true;
494 case Changes::Kind::Full:
497 case Changes::Kind::Partial:
498 if (atlas_tex !=
nullptr) {
505 tile.runtime.tilearray_layer,
506 int2(
tile.runtime.tilearray_offset),
510 case Changes::Kind::None:
516 if (need_full_rebuild) {
524 if (need_full_rebuild) {
534 result.need_tile_mapping =
true;
537 ImBuf *atlas_ibuf, *mapping_ibuf;
539 std::scoped_lock
lock(ima->runtime->cache_mutex);
555 if (try_only || (
result.texture !=
nullptr &&
result.tile_mapping !=
nullptr)) {
566 if (
result.tile_mapping) {
568 result.tile_mapping =
nullptr;
579 if (ibuf ==
nullptr) {
588 if (atlas_tex && mapping_tex) {
597 if (atlas_tex ==
nullptr || mapping_tex ==
nullptr) {
618 result.texture = atlas_tex;
619 result.tile_mapping = mapping_tex;
645 const bool use_viewers,
646 const bool only_full_resolution,
652 void *
lock =
nullptr;
653 bool cpu_load_failed =
false;
655 ima, iuser, use_viewers ? &
lock :
nullptr, &cpu_load_failed, try_only);
657 bool gpu_load_failed =
false;
670 ima->id.name + 2, ibuf, texture_create_flags, try_only);
675 else if (!try_only) {
690 if (
result.texture ==
nullptr && (!try_only || cpu_load_failed || gpu_load_failed) &&
691 !only_full_resolution)
715 const bool use_viewers,
716 const bool only_full_resolution,
717 const bool use_tile_mapping,
720 if (ima ==
nullptr) {
726 const bool tiled = (use_tile_mapping && ima->source ==
IMA_SRC_TILED);
743 if (ibuf !=
nullptr) {
751 const bool only_full_resolution)
764 const bool use_tile_mapping,
772 const bool use_tile_mapping)
774 const bool try_only =
true;
776 image, iuser,
false,
false, use_tile_mapping, try_only);
777 const bool has_texture =
result.texture !=
nullptr;
783 if (
result.tile_mapping) {
792 const bool use_tile_mapping)
795 image, iuser,
false,
false, use_tile_mapping,
false);
801 if (
result.tile_mapping) {
828 if (ima->runtime->cache) {
829 std::scoped_lock
lock(ima->runtime->cache_mutex);
836 if (ibuf !=
nullptr) {
871 if (iuser !=
nullptr) {
879 if (ibuf !=
nullptr) {
File and directory operations.
Platform independent time functions.
#define CLOG_ERROR(clg_ref,...)
Read Blender memory allocation and freeing.
#define IMA_INDEX_UDIM_ATLAS
#define IMA_INDEX_UDIM_TILE_MAPPING
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
const ccl_global KernelWorkTile * tile
MINLINE float min_ff(float a, float b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void IMB_cacheIter_step(ImBufCacheIter *iter)
void BLI_box_pack_2d_fixedarea(ListBaseT< FixedSizeBoxPack > *boxes, int width, int height, ListBaseT< FixedSizeBoxPack > *packed)
static void image_gpu_log_load_error_once(Image *ima, ImageUser *iuser, ImageLoadError error)
bool BKE_image_is_animated(Image *image)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_image_sort_tiles(Image *ima)
void IMB_assign_gpu_texture(ImBuf *ibuf, gpu::Texture *texture)
int64_t BLI_time_now_seconds_i()
void BKE_image_ensure_gpu_material_texture(Image *image, ImageUser *iuser, const bool use_tile_mapping)
MINLINE int power_of_2_min_i(int n)
void BKE_image_free_gpu_texture_caches(Image *ima)
static void image_udim_gpu_ibuf_remove(Image *ima, const int udim_index)
void GPU_texture_update_mipmap_chain(gpu::Texture *texture)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_image_free_gpu_fallback()
bool BKE_image_has_filepath(const Image *ima)
ImageGPUTextures BKE_image_acquire_gpu_material_texture(Image *image, ImageUser *iuser, const bool use_tile_mapping, const bool try_only)
void BKE_image_assign_gpu_texture(Image *image, gpu::Texture *texture)
ImBuf * IMB_cacheIter_getImBuf(ImBufCacheIter *iter)
void BKE_image_user_file_path(const ImageUser *iuser, const Image *ima, char *filepath)
MINLINE int max_ii(int a, int b)
static gpu::Texture * gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
imbuf::ChangesetID IMB_partial_update_changeset_id_current()
void BKE_image_free_all_gpu_texture_caches(Main *bmain)
static int smaller_power_of_2_limit(int num)
ImBuf * IMB_cache_get(ImBufCache *cache, void *userkey, bool *r_is_cached_empty)
static bool is_over_resolution_limit(int w, int h)
void GPU_texture_mipmap_mode(gpu::Texture *texture, bool use_mipmap, bool use_filter)
ImBuf * BKE_image_acquire_ibuf_gpu(Image *ima, ImageUser *iuser, void **r_lock, bool *r_load_failed=nullptr, bool cached_only=false)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
ImBufCacheIter * IMB_cacheIter_new(ImBufCache *cache)
@ GPU_TEXTURE_USAGE_SHADER_READ
void imagecache_put(Image *image, ImageCacheKey key, ImBuf *ibuf)
BMesh const char void * data
gpu::Texture * BKE_image_acquire_gpu_viewer_texture(Image *image, ImageUser *iuser, bool only_full_resolution=false)
static ImBuf * image_udim_gpu_ibuf_ensure(Image *ima, const int udim_index)
void GPU_texture_original_size_set(gpu::Texture *texture, int width, int height)
int GPU_texture_width(const gpu::Texture *texture)
bool BKE_image_has_gpu_texture(Image *ima)
void IMB_gpu_texture_apply_partial_update(gpu::Texture *tex, ImBuf *ibuf, bool store_premultiplied, const imbuf::partial_update::Changes &changes, int layer=-1, int2 tile_offset=int2(0), int2 tile_size=int2(0))
static ImageGPUTextures image_get_gpu_texture_single(Image *ima, ImageUser *iuser, const bool use_viewers, const bool only_full_resolution, const bool try_only)
ATTR_WARN_UNUSED_RESULT const size_t num
bool IMB_cacheIter_done(ImBufCacheIter *iter)
bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf)
void BKE_image_free_gpu_udim_textures(Image *ima)
static int compare_packtile(const void *a, const void *b)
void void BLI_listbase_sort(ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
int64_t BKE_image_partial_update_flush(Image *ima, const ImageUser *iuser)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
static ImageGPUTextures image_get_gpu_texture(Image *ima, ImageUser *iuser, const bool use_viewers, const bool only_full_resolution, const bool use_tile_mapping, const bool try_only)
void IMB_update_gpu_texture_sub(gpu::Texture *tex, ImBuf *ibuf, int x, int y, int z, int w, int h, bool use_grayscale, bool use_premult)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static ImBuf * image_udim_gpu_ibuf_get(Image *ima, const int udim_index)
gpu::Texture * IMB_acquire_gpu_texture(const char *name, ImBuf *ibuf, GPUTextureCreateFlags texture_create_flags, bool try_only=false)
static void image_cache_free_inactive_frame_gpu_textures(Image *ima, const ImBuf *current_ibuf)
static gpu::Texture * gpu_texture_create_tile_mapping(Image *ima, gpu::Texture *tilearray)
int GPU_texture_height(const gpu::Texture *texture)
bool GPU_is_safe_texture_size(int width, int height)
MINLINE float max_ff(float a, float b)
void GPU_texture_free(gpu::Texture *texture)
bool BKE_image_has_gpu_material_texture(Image *image, ImageUser *iuser, const bool use_tile_mapping)
static ImBuf * image_udim_gpu_cache_get(Image *image, ImageCacheKey key)
void IMB_free_gpu_textures(ImBuf *ibuf)
void BKE_image_free_anim_gpu_texture_caches(Main *bmain)
static bool image_gpu_texture_fits_full_resolution(const ImBuf *ibuf)
static void image_gpu_atlas_try_partial_update(Image *image, ImageUser *iuser)
imbuf::partial_update::Changes IMB_partial_update_collect(ImBuf *ibuf, imbuf::ChangesetID last_changeset_id)
bool BKE_image_source_is_file(const Image *ima)
gpu::Texture * GPU_texture_create_error(int dimension, bool array)
void IMB_partial_update_flush(ImBuf *ibuf)
gpu::Texture * BKE_image_acquire_gpu_texture(Image *image, ImageUser *iuser)
bool BKE_image_has_packedfile(const Image *image)
static ImBuf * g_error_imbuf
void IMB_cache_remove(ImBufCache *cache, void *userkey)
void BKE_imageuser_default(ImageUser *iuser)
static ImageGPUTextures image_get_gpu_texture_tiled(Image *ima, ImageUser *iuser, const bool try_only)
void IMB_cacheIter_free(ImBufCacheIter *iter)
static ImBuf * image_gpu_error_imbuf_ensure()
static void image_gpu_clear_load_error(Image *ima)
gpu::Texture * IMB_touch_gpu_texture(const char *name, ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth, bool use_grayscale)
int GPU_texture_size_with_limit(int res)
gpu::Texture * GPU_texture_create_1d_array(const char *name, int width, int layer_len, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void GPU_texture_ref(gpu::Texture *texture)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
std::atomic< imbuf::ChangesetID > partial_update_changeset_id
std::atomic< gpu::Texture * > texture
const uint8_t * byte_data() const
const float * float_data() const
ListBaseT< Image > images
void set_all_chunks_modified()