|
Blender V4.3
|
#include "MEM_guardedalloc.h"#include "BLI_boxpack_2d.h"#include "BLI_linklist.h"#include "BLI_listbase.h"#include "BLI_threads.h"#include "BLI_time.h"#include "DNA_image_types.h"#include "DNA_userdef_types.h"#include "IMB_colormanagement.hh"#include "IMB_imbuf.hh"#include "IMB_imbuf_types.hh"#include "BKE_global.hh"#include "BKE_image.hh"#include "BKE_image_partial_update.hh"#include "BKE_main.hh"#include "GPU_capabilities.hh"#include "GPU_state.hh"#include "GPU_texture.hh"Go to the source code of this file.
Classes | |
| struct | PackTile |
Functions | |
| bool | BKE_image_has_gpu_texture_premultiplied_alpha (Image *image, ImBuf *ibuf) |
Deletion | |
| static void | image_free_gpu (Image *ima, const bool immediate) |
| void | BKE_image_free_gputextures (Image *ima) |
| void | BKE_image_free_all_gputextures (Main *bmain) |
| void | BKE_image_free_anim_gputextures (Main *bmain) |
| void | BKE_image_free_old_gputextures (Main *bmain) |
Paint Update | |
| static void | image_update_gputexture_ex (Image *ima, ImageTile *tile, ImBuf *ibuf, int x, int y, int w, int h) |
| static ImBuf * | update_do_scale (const uchar *rect, const float *rect_float, int *x, int *y, int *w, int *h, int limit_w, int limit_h, int full_w, int full_h) |
| static void | gpu_texture_update_scaled (GPUTexture *tex, const uchar *rect, const float *rect_float, int full_w, int full_h, int x, int y, int layer, const int *tile_offset, const int *tile_size, int w, int h) |
| static void | gpu_texture_update_unscaled (GPUTexture *tex, uchar *rect, float *rect_float, int x, int y, int layer, const int tile_offset[2], int w, int h, int tex_stride, int tex_offset) |
| static void | gpu_texture_update_from_ibuf (GPUTexture *tex, Image *ima, ImBuf *ibuf, ImageTile *tile, int x, int y, int w, int h) |
| void | BKE_image_update_gputexture (Image *ima, ImageUser *iuser, int x, int y, int w, int h) |
| void | BKE_image_update_gputexture_delayed (Image *ima, ImageTile *image_tile, ImBuf *ibuf, int x, int y, int w, int h) |
| void | BKE_image_paint_set_mipmap (Main *bmain, bool mipmap) |
UDIM GPU Texture | |
| static bool | is_over_resolution_limit (int w, int h) |
| static int | smaller_power_of_2_limit (int num) |
| static GPUTexture * | gpu_texture_create_tile_mapping (Image *ima, const int multiview_eye) |
| static int | compare_packtile (const void *a, const void *b) |
| static GPUTexture * | gpu_texture_create_tile_array (Image *ima, ImBuf *main_ibuf) |
Regular gpu texture | |
| static GPUTexture ** | get_image_gpu_texture_ptr (Image *ima, eGPUTextureTarget textarget, const int multiview_eye) |
| static GPUTexture * | image_gpu_texture_error_create (eGPUTextureTarget textarget) |
| static void | image_gpu_texture_partial_update_changes_available (Image *image, PartialUpdateChecker< ImageTileData >::CollectResult &changes) |
| static void | image_gpu_texture_try_partial_update (Image *image, ImageUser *iuser) |
| void | BKE_image_ensure_gpu_texture (Image *image, ImageUser *image_user) |
| static ImageGPUTextures | image_get_gpu_texture (Image *ima, ImageUser *iuser, const bool use_viewers, const bool use_tile_mapping) |
| GPUTexture * | BKE_image_get_gpu_texture (Image *image, ImageUser *iuser) |
| GPUTexture * | BKE_image_get_gpu_viewer_texture (Image *image, ImageUser *iuser) |
| ImageGPUTextures | BKE_image_get_gpu_material_texture (Image *image, ImageUser *iuser, const bool use_tile_mapping) |
Delayed GPU texture free | |
Image datablocks can be deleted by any thread, but there may not be any active OpenGL context. In that case we push them into a queue and free the buffers later. | |
| static LinkNode * | gpu_texture_free_queue = nullptr |
| static ThreadMutex | gpu_texture_queue_mutex = BLI_MUTEX_INITIALIZER |
| static void | gpu_free_unused_buffers () |
| void | BKE_image_free_unused_gpu_textures () |
Ensure that the cached GPU texture inside the image matches the pass, layer, and view of the given image user, if not, invalidate the cache such that the next call to the GPU texture retrieval functions such as BKE_image_get_gpu_texture updates the cache with an image that matches the give image user.
This is provided as a separate function and not implemented as part of the GPU texture retrieval functions because the current cache system only allows a single pass, layer, and stereo view to be cached, so possible frequent cache invalidation can have performance implications, and making invalidation explicit by calling this function will help make that clear and pave the way for a more complete cache system in the future.
Definition at line 336 of file image_gpu.cc.
References BKE_image_partial_update_mark_full_update(), ImageUser::layer, ImageUser::multi_index, and ImageUser::pass.
| void BKE_image_free_all_gputextures | ( | Main * | bmain | ) |
Definition at line 561 of file image_gpu.cc.
References BKE_image_free_gputextures(), Main::images, and LISTBASE_FOREACH.
Referenced by ED_object_texture_paint_mode_enter_ex(), and ED_object_texture_paint_mode_exit_ex().
| void BKE_image_free_anim_gputextures | ( | Main * | bmain | ) |
Same as BKE_image_free_all_gputextures but only free animated images.
Definition at line 570 of file image_gpu.cc.
References BKE_image_free_gputextures(), BKE_image_is_animated(), Main::images, and LISTBASE_FOREACH.
Referenced by ED_view3d_draw_offscreen().
| void BKE_image_free_gputextures | ( | Image * | ima | ) |
Definition at line 556 of file image_gpu.cc.
References BLI_thread_is_main(), and image_free_gpu().
Referenced by blender::ed::object::bake_targets_refresh(), BKE_image_free_all_gputextures(), BKE_image_free_anim_gputextures(), BKE_image_free_buffers_ex(), BKE_image_free_old_gputextures(), BKE_image_paint_set_mipmap(), paint_2d_redraw(), ptile_restore_runtime_map(), and texture_paint_camera_project_exec().
| void BKE_image_free_old_gputextures | ( | Main * | bmain | ) |
Definition at line 581 of file image_gpu.cc.
References BKE_image_free_buffers, BKE_image_free_gputextures(), BKE_image_has_opengl_texture(), BLI_time_now_seconds(), G, IMA_NOCOLLECT, Main::images, int, and LISTBASE_FOREACH.
Referenced by view3d_main_region_draw().
| void BKE_image_free_unused_gpu_textures | ( | void | ) |
Delayed free of OpenGL buffers by main thread.
Definition at line 521 of file image_gpu.cc.
References BLI_thread_is_main(), and gpu_free_unused_buffers().
Referenced by wm_draw_update(), and WM_exit_ex().
| ImageGPUTextures BKE_image_get_gpu_material_texture | ( | Image * | image, |
| ImageUser * | iuser, | ||
| const bool | use_tile_mapping ) |
Definition at line 486 of file image_gpu.cc.
References image_get_gpu_texture().
Referenced by DRW_shgroup_add_material_resources(), blender::draw::detail::PassBase< DrawCommandBufType >::material_set(), blender::workbench::MaterialTexture::MaterialTexture(), and blender::workbench::MaterialTexture::MaterialTexture().
Get the #GPUTexture for a given Image.
The requested GPU texture will be cached for subsequent calls, but only a single layer, pass, and view can be cached at a time, so the cache should be invalidated in operators and RNA callbacks that change the layer, pass, or view of the image to maintain a correct cache state. However, in some cases, multiple layers, passes, or views might be needed at the same time, like is the case for the realtime compositor. This is currently not supported, so the caller should ensure that the requested layer is indeed the cached one and invalidated the cached otherwise by calling BKE_image_ensure_gpu_texture. This is a workaround until image can support a more complete caching system.
Definition at line 476 of file image_gpu.cc.
References image_get_gpu_texture(), and ImageGPUTextures::texture.
Referenced by blender::draw::overlay::Paints::begin_sync(), blender::draw::overlay::MeshUVs::end_sync(), gpencil_image_texture_get(), blender::eevee::LookdevWorld::LookdevWorld(), OVERLAY_edit_uv_cache_init(), OVERLAY_image_empty_cache_populate(), OVERLAY_paint_cache_init(), and pygpu_texture_from_image().
Definition at line 481 of file image_gpu.cc.
References image_get_gpu_texture(), and ImageGPUTextures::texture.
Referenced by image_camera_background_texture_get().
Is the alpha of the GPUTexture for a given image/ibuf premultiplied.
Definition at line 41 of file image_gpu.cc.
References ImBufFloatBuffer::data, ELEM, ImBuf::float_buffer, IMA_ALPHA_PREMUL, IMA_ALPHA_STRAIGHT, IMA_TYPE_COMPOSITE, IMA_TYPE_R_RESULT, and IMA_TYPE_UV_TEST.
Referenced by gpu_texture_create_tile_array(), gpu_texture_update_from_ibuf(), image_get_gpu_texture(), and blender::draw::image_engine::ShaderParameters::update().
| void BKE_image_paint_set_mipmap | ( | Main * | bmain, |
| bool | mipmap ) |
Called on entering and exiting texture paint mode, temporary disabling/enabling mipmapping on all images for quick texture updates with glTexSubImage2D. images that didn't change don't have to be re-uploaded to OpenGL.
Definition at line 906 of file image_gpu.cc.
References BKE_image_free_gputextures(), BKE_image_has_opengl_texture(), ELEM, GPU_texture_mipmap_mode(), IMA_GPU_MIPMAP_COMPLETE, Main::images, LISTBASE_FOREACH, tex, TEXTARGET_2D, TEXTARGET_2D_ARRAY, and TEXTARGET_COUNT.
Referenced by ED_object_texture_paint_mode_enter_ex(), and ED_object_texture_paint_mode_exit_ex().
Partial update of texture for texture painting. This is often much quicker than fully updating the texture for high resolution images.
Definition at line 882 of file image_gpu.cc.
References BKE_image_acquire_ibuf(), BKE_image_get_tile_from_iuser, BKE_image_release_ibuf(), BKE_image_update_gputexture_delayed(), and w().
Referenced by imapaint_image_update().
| void BKE_image_update_gputexture_delayed | ( | Image * | ima, |
| ImageTile * | image_tile, | ||
| ImBuf * | ibuf, | ||
| int | x, | ||
| int | y, | ||
| int | w, | ||
| int | h ) |
Mark areas on the #GPUTexture that needs to be updated. The areas are marked in chunks. The next time the #GPUTexture is used these tiles will be refreshes. This saves time when writing to the same place multiple times This happens for during foreground rendering.
Definition at line 890 of file image_gpu.cc.
References BKE_image_partial_update_mark_full_update(), BKE_image_partial_update_mark_region(), BLI_rcti_init(), IMA_SRC_TILED, Image::source, w(), ImBuf::x, and ImBuf::y.
Referenced by BKE_image_update_gputexture(), and image_rect_update().
|
static |
Definition at line 126 of file image_gpu.cc.
References b, and PackTile::pack_score.
Referenced by gpu_texture_create_tile_array().
|
static |
Definition at line 260 of file image_gpu.cc.
References BLI_assert, ELEM, Image::gputexture, int, and TEXTARGET_COUNT.
Referenced by image_get_gpu_texture().
|
static |
Definition at line 505 of file image_gpu.cc.
References BLI_linklist_pop(), BLI_mutex_lock(), BLI_mutex_unlock(), GPU_texture_free(), gpu_texture_free_queue, gpu_texture_queue_mutex, and tex.
Referenced by BKE_image_free_unused_gpu_textures(), and image_get_gpu_texture().
Definition at line 134 of file image_gpu.cc.
References BKE_image_acquire_ibuf(), BKE_image_has_gpu_texture_premultiplied_alpha(), BKE_image_release_ibuf(), BKE_imageuser_default(), BLI_addtail(), BLI_assert, BLI_box_pack_2d_fixedarea(), BLI_freelistN(), BLI_listbase_sort(), PackTile::boxpack, compare_packtile(), ListBase::first, Image::flag, GPU_mipmap_enabled(), GPU_texture_mipmap_mode(), GPU_texture_update_mipmap_chain(), Image::gpuflag, FixedSizeBoxPack::h, Image::id, IMA_GPU_MIPMAP_COMPLETE, IMA_HIGH_BITDEPTH, IMB_touch_gpu_texture(), IMB_update_gpu_texture_sub(), is_over_resolution_limit(), LISTBASE_FOREACH, max_ff(), max_ii(), min_ff(), ID::name, PackTile::pack_score, ImBuf::planes, smaller_power_of_2_limit(), tex, ImageUser::tile, PackTile::tile, tile, ImageTile_Runtime::tilearray_layer, ImageTile_Runtime::tilearray_offset, ImageTile_Runtime::tilearray_size, Image::tiles, UNPACK2, FixedSizeBoxPack::w, w(), ImBuf::x, and ImBuf::y.
Referenced by image_get_gpu_texture().
Definition at line 77 of file image_gpu.cc.
References BKE_image_sort_tiles(), GPU_RGBA32F, GPU_texture_create_1d_array(), GPU_texture_height(), GPU_texture_mipmap_mode(), GPU_TEXTURE_USAGE_SHADER_READ, GPU_texture_width(), Image::gputexture, Image::id, ListBase::last, LISTBASE_FOREACH, MEM_callocN, MEM_freeN(), ID::name, tex, TEXTARGET_2D_ARRAY, tile, ImageTile::tile_number, ImageTile_Runtime::tilearray_layer, ImageTile_Runtime::tilearray_offset, ImageTile_Runtime::tilearray_size, and Image::tiles.
Referenced by image_get_gpu_texture().
|
static |
Definition at line 731 of file image_gpu.cc.
References BKE_image_has_gpu_texture_premultiplied_alpha(), ImBuf::byte_buffer, ImBuf::channels, ImBufByteBuffer::colorspace, ImBufByteBuffer::data, ImBufFloatBuffer::data, ImBuf::float_buffer, GPU_mipmap_enabled(), GPU_texture_height(), GPU_texture_unbind(), GPU_texture_update_mipmap_chain(), gpu_texture_update_scaled(), gpu_texture_update_unscaled(), GPU_texture_width(), Image::gpuflag, IMB_colormanagement_imbuf_to_byte_texture(), IMB_colormanagement_imbuf_to_float_texture(), IMB_colormanagement_space_is_data(), IMB_colormanagement_space_is_scene_linear(), IMB_colormanagement_space_is_srgb(), max_ii(), MEM_freeN(), MEM_mallocN, min_ii(), padding(), scaled(), tex, tile, ImageTile_Runtime::tilearray_layer, ImageTile_Runtime::tilearray_offset, ImageTile_Runtime::tilearray_size, w(), ImBuf::x, x, ImBuf::y, and y.
Referenced by image_update_gputexture_ex().
|
static |
Definition at line 662 of file image_gpu.cc.
References ImBuf::byte_buffer, ImBufByteBuffer::data, ImBufFloatBuffer::data, ImBuf::float_buffer, GPU_DATA_FLOAT, GPU_DATA_UBYTE, GPU_texture_height(), GPU_texture_update_sub(), GPU_texture_width(), IMB_freeImBuf(), tex, update_do_scale(), and w().
Referenced by gpu_texture_update_from_ibuf().
|
static |
Definition at line 701 of file image_gpu.cc.
References GPU_DATA_FLOAT, GPU_DATA_UBYTE, GPU_texture_update_sub(), GPU_unpack_row_length_set(), tex, and w().
Referenced by gpu_texture_update_from_ibuf().
|
static |
Definition at line 534 of file image_gpu.cc.
References BLI_linklist_prepend(), BLI_mutex_lock(), BLI_mutex_unlock(), GPU_texture_free(), gpu_texture_free_queue, gpu_texture_queue_mutex, Image::gpuflag, Image::gputexture, and TEXTARGET_COUNT.
Referenced by BKE_image_free_gputextures(), and image_gpu_texture_try_partial_update().
|
static |
Definition at line 351 of file image_gpu.cc.
References BKE_image_acquire_ibuf(), BKE_image_get_tile, BKE_image_has_gpu_texture_premultiplied_alpha(), BKE_image_partial_update_create(), BKE_image_release_ibuf(), BKE_image_tag_time(), Image::flag, get_image_gpu_texture_ptr(), gpu_free_unused_buffers(), Image::gpu_layer, GPU_mipmap_enabled(), Image::gpu_pass, GPU_SAMPLER_EXTEND_MODE_REPEAT, gpu_texture_create_tile_array(), gpu_texture_create_tile_mapping(), GPU_texture_extend_mode(), GPU_texture_mipmap_mode(), GPU_texture_original_size_set(), GPU_texture_update_mipmap_chain(), Image::gpu_view, Image::gpuflag, Image::id, IMA_GPU_MIPMAP_COMPLETE, IMA_HIGH_BITDEPTH, IMA_SRC_TILED, image_gpu_texture_error_create(), image_gpu_texture_try_partial_update(), IMB_create_gpu_texture(), ImageUser::layer, lock, ImageUser::multi_index, ImageUser::multiview_eye, ID::name, Image_Runtime::partial_update_user, ImageUser::pass, result, Image::runtime, Image::source, tex, TEXTARGET_2D, TEXTARGET_2D_ARRAY, TEXTARGET_TILE_MAPPING, tile, ImBuf::x, and ImBuf::y.
Referenced by BKE_image_get_gpu_material_texture(), BKE_image_get_gpu_texture(), and BKE_image_get_gpu_viewer_texture().
|
static |
Definition at line 274 of file image_gpu.cc.
References GPU_texture_create_error(), TEXTARGET_2D, TEXTARGET_2D_ARRAY, and TEXTARGET_TILE_MAPPING.
Referenced by image_get_gpu_texture().
|
static |
Definition at line 288 of file image_gpu.cc.
References BLI_rcti_init(), BLI_rcti_isect(), BLI_rcti_size_x(), BLI_rcti_size_y(), image_update_gputexture_ex(), rcti::xmin, and rcti::ymin.
Referenced by image_gpu_texture_try_partial_update().
Definition at line 314 of file image_gpu.cc.
References blender::bke::image::partial_update::PartialUpdateChecker< TileData >::collect_changes(), image_free_gpu(), and image_gpu_texture_partial_update_changes_available().
Referenced by image_get_gpu_texture().
|
static |
Definition at line 865 of file image_gpu.cc.
References ListBase::first, gpu_texture_update_from_ibuf(), Image::gputexture, tex, TEXTARGET_2D, TEXTARGET_2D_ARRAY, tile, Image::tiles, and w().
Referenced by image_gpu_texture_partial_update_changes_available().
Definition at line 67 of file image_gpu.cc.
References GPU_texture_size_with_limit(), and w().
Referenced by gpu_texture_create_tile_array().
Definition at line 72 of file image_gpu.cc.
References GPU_texture_size_with_limit(), and power_of_2_min_i().
Referenced by gpu_texture_create_tile_array().
|
static |
Definition at line 623 of file image_gpu.cc.
References Box, ceil(), float, IMB_allocFromBuffer(), IMB_scale(), int, and w().
Referenced by gpu_texture_update_scaled().
|
static |
Definition at line 502 of file image_gpu.cc.
Referenced by gpu_free_unused_buffers(), and image_free_gpu().
|
static |
Definition at line 503 of file image_gpu.cc.
Referenced by gpu_free_unused_buffers(), and image_free_gpu().