From cfca7ac952022834bc99696b998df3a4960c0b4e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 7 Feb 2025 21:23:48 +0100 Subject: [PATCH 1/4] Fix #133943: Unnecessary image full update mark on file open This would be done when the frame, layer, pass or view changes compared to the previous value. But for cases like old files without these members or loading the image datablock into a different scene, this considered the image to be always be changed on file load. Now always reset this state on file load, and don't consider the initial state as an image update. This could also happen in the middle of GPU rendering, causing the GPU texture to be freed while still in use. Pull Request: https://projects.blender.org/blender/blender/pulls/134198 --- source/blender/blenkernel/intern/image.cc | 22 ++++++++++++++----- source/blender/blenkernel/intern/image_gpu.cc | 7 +++--- source/blender/makesdna/DNA_image_defaults.h | 7 +++--- source/blender/makesdna/DNA_image_types.h | 6 +++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index c2a085e4c67..b0c4cc1eab1 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -49,6 +49,7 @@ #include "DNA_brush_types.h" #include "DNA_camera_types.h" #include "DNA_defaults.h" +#include "DNA_image_types.h" #include "DNA_light_types.h" #include "DNA_material_types.h" #include "DNA_object_types.h" @@ -156,6 +157,16 @@ static void image_runtime_free_data(Image *image) BKE_image_partial_update_register_free(image); } +static void image_gpu_runtime_reset(Image *ima) +{ + ima->lastused = 0; + ima->gpuflag = 0; + ima->gpuframenr = IMAGE_GPU_FRAME_NONE; + ima->gpu_pass = IMAGE_GPU_PASS_NONE; + ima->gpu_layer = IMAGE_GPU_LAYER_NONE; + ima->gpu_view = IMAGE_GPU_VIEW_NONE; +} + static void image_init_data(ID *id) { Image *image = (Image *)id; @@ -348,9 +359,8 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres /* Clear all data that isn't read to reduce false detection of changed image during memfile undo. */ - ima->lastused = 0; ima->cache = nullptr; - ima->gpuflag = 0; + image_gpu_runtime_reset(ima); BLI_listbase_clear(&ima->anims); ima->runtime.partial_update_register = nullptr; ima->runtime.partial_update_user = nullptr; @@ -433,9 +443,7 @@ static void image_blend_read_data(BlendDataReader *reader, ID *id) BKE_previewimg_blend_read(reader, ima->preview); BLO_read_struct(reader, Stereo3dFormat, &ima->stereo3d_format); - ima->lastused = 0; - ima->gpuflag = 0; - + image_gpu_runtime_reset(ima); image_runtime_reset(ima); } @@ -5224,7 +5232,9 @@ void BKE_image_user_frame_calc(Image *ima, ImageUser *iuser, int cfra) /* NOTE: a single texture and refresh doesn't really work when * multiple image users may use different frames, this is to * be improved with perhaps a GPU texture cache. */ - BKE_image_partial_update_mark_full_update(ima); + if (ima->gpuframenr != IMAGE_GPU_FRAME_NONE) { + BKE_image_partial_update_mark_full_update(ima); + } ima->gpuframenr = iuser->framenr; } diff --git a/source/blender/blenkernel/intern/image_gpu.cc b/source/blender/blenkernel/intern/image_gpu.cc index 9ea33c1dc76..ebfcf96320b 100644 --- a/source/blender/blenkernel/intern/image_gpu.cc +++ b/source/blender/blenkernel/intern/image_gpu.cc @@ -335,7 +335,7 @@ static void image_gpu_texture_try_partial_update(Image *image, ImageUser *iuser) } } -void BKE_image_ensure_gpu_texture(Image *image, ImageUser *image_user) +void BKE_image_ensure_gpu_texture(Image *image, ImageUser *iuser) { if (!image) { return; @@ -343,8 +343,9 @@ void BKE_image_ensure_gpu_texture(Image *image, ImageUser *image_user) /* Note that the image can cache both stereo views, so we only invalidate the cache if the view * index is more than 2. */ - if (image->gpu_pass != image_user->pass || image->gpu_layer != image_user->layer || - (image->gpu_view != image_user->multi_index && image_user->multi_index >= 2)) + if (!ELEM(image->gpu_pass, IMAGE_GPU_PASS_NONE, iuser->pass) || + !ELEM(image->gpu_layer, IMAGE_GPU_LAYER_NONE, iuser->layer) || + (!ELEM(image->gpu_view, IMAGE_GPU_VIEW_NONE, iuser->multi_index) && iuser->multi_index >= 2)) { BKE_image_partial_update_mark_full_update(image); } diff --git a/source/blender/makesdna/DNA_image_defaults.h b/source/blender/makesdna/DNA_image_defaults.h index 9e7b4bf696a..99eea9984eb 100644 --- a/source/blender/makesdna/DNA_image_defaults.h +++ b/source/blender/makesdna/DNA_image_defaults.h @@ -22,9 +22,10 @@ .gen_y = 1024, \ .gen_type = IMA_GENTYPE_GRID, \ \ - .gpuframenr = INT_MAX, \ - .gpu_pass = SHRT_MAX, \ - .gpu_layer = SHRT_MAX, \ + .gpuframenr = IMAGE_GPU_FRAME_NONE, \ + .gpu_pass = IMAGE_GPU_PASS_NONE, \ + .gpu_layer = IMAGE_GPU_LAYER_NONE, \ + .gpu_view = IMAGE_GPU_VIEW_NONE, \ .seam_margin = 8, \ } diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h index dc40faec838..023639b0a96 100644 --- a/source/blender/makesdna/DNA_image_types.h +++ b/source/blender/makesdna/DNA_image_types.h @@ -293,3 +293,9 @@ enum { IMA_ALPHA_CHANNEL_PACKED = 2, IMA_ALPHA_IGNORE = 3, }; + +/* Image gpu runtime defaults */ +#define IMAGE_GPU_FRAME_NONE INT_MAX +#define IMAGE_GPU_PASS_NONE SHRT_MAX +#define IMAGE_GPU_LAYER_NONE SHRT_MAX +#define IMAGE_GPU_VIEW_NONE SHRT_MAX From d568867c80c3b60b78f3a26841a85ecd8d9ba4db Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 7 Feb 2025 20:08:55 +0100 Subject: [PATCH 2/4] Fix: SYCL library not found after recent library update Pull Request: https://projects.blender.org/blender/blender/pulls/134244 --- build_files/cmake/Modules/FindSYCL.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build_files/cmake/Modules/FindSYCL.cmake b/build_files/cmake/Modules/FindSYCL.cmake index c361cb511d5..b2bfe16fd69 100644 --- a/build_files/cmake/Modules/FindSYCL.cmake +++ b/build_files/cmake/Modules/FindSYCL.cmake @@ -64,6 +64,9 @@ endif() find_library(SYCL_LIBRARY NAMES + sycl10 + sycl9 + sycl8 sycl7 sycl6 sycl @@ -76,6 +79,9 @@ find_library(SYCL_LIBRARY if(WIN32) find_library(SYCL_LIBRARY_DEBUG NAMES + sycl10d + sycl9d + sycl8d sycl7d sycl6d sycld From fcc770390dd33b95cda081b35cc60886e97dd965 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 7 Feb 2025 20:21:20 +0100 Subject: [PATCH 3/4] Fix: Disable zlib in dpcpp to avoid linking to system library Matching build options for regular LLVM. Pull Request: https://projects.blender.org/blender/blender/pulls/134244 --- build_files/build_environment/cmake/dpcpp.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/build_files/build_environment/cmake/dpcpp.cmake b/build_files/build_environment/cmake/dpcpp.cmake index d42f49fb218..6f5e644c234 100644 --- a/build_files/build_environment/cmake/dpcpp.cmake +++ b/build_files/build_environment/cmake/dpcpp.cmake @@ -82,6 +82,7 @@ set(DPCPP_EXTRA_ARGS -DPYTHON_EXECUTABLE=${PYTHON_BINARY} -DLLDB_ENABLE_CURSES=OFF -DLLVM_ENABLE_TERMINFO=OFF + -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=FORCE_ON -DLLVM_USE_STATIC_ZSTD=ON -Dzstd_INCLUDE_DIR=${LIBDIR}/zstd/include From f9c4ad1477ff347cfb133cc4ae216ee3c955641c Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 7 Feb 2025 20:52:24 +0100 Subject: [PATCH 4/4] Build: Auto clear CMake cache variables for 4.4 library update And remove some old checks that are no longer relevant. Pull Request: https://projects.blender.org/blender/blender/pulls/134244 --- .../platform/platform_old_libs_update.cmake | 85 +++++-------------- 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/build_files/cmake/platform/platform_old_libs_update.cmake b/build_files/cmake/platform/platform_old_libs_update.cmake index b83cc89df42..7027949e504 100644 --- a/build_files/cmake/platform/platform_old_libs_update.cmake +++ b/build_files/cmake/platform/platform_old_libs_update.cmake @@ -43,68 +43,6 @@ function(unset_cached_varables_containting contents msg) endif() endfunction() -# Detect update from 3.1 to 3.2 libs. -if(UNIX AND - DEFINED OPENEXR_VERSION AND - OPENEXR_VERSION VERSION_LESS "3.0.0" AND - EXISTS ${LIBDIR}/imath) - message(STATUS "Auto updating CMake configuration for Blender 3.2 libraries") - - unset_cache_variables("^OPENIMAGEIO") - unset_cache_variables("^OPENEXR") - unset_cache_variables("^IMATH") - unset_cache_variables("^PNG") - unset_cache_variables("^USD") - unset_cache_variables("^WEBP") - unset_cache_variables("^NANOVDB") -endif() - -# Automatically set WebP on/off depending if libraries are available. -if(EXISTS ${LIBDIR}/webp) - if(WITH_OPENIMAGEIO) - set(WITH_IMAGE_WEBP ON CACHE BOOL "" FORCE) - endif() -else() - set(WITH_IMAGE_WEBP OFF) -endif() - -# NanoVDB moved into openvdb. -if(UNIX AND DEFINED NANOVDB_INCLUDE_DIR) - if(NOT EXISTS ${NANOVDB_INCLUDE_DIR} AND - EXISTS ${LIBDIR}/openvdb/include/nanovdb) - unset_cache_variables("^NANOVDB") - endif() -endif() - -# Detect update to 3.5 libs with shared libraries. -if(UNIX AND - DEFINED TBB_LIBRARY AND - TBB_LIBRARY MATCHES "libtbb.a$" AND - EXISTS ${LIBDIR}/usd/include/pxr/base/tf/pyModule.h) - message(STATUS "Auto updating CMake configuration for Blender 3.5 libraries") - unset_cache_variables("^BLOSC") - unset_cache_variables("^BOOST") - unset_cache_variables("^Boost") - unset_cache_variables("^IMATH") - unset_cache_variables("^OPENCOLORIO") - unset_cache_variables("^OPENEXR") - unset_cache_variables("^OPENIMAGEIO") - unset_cache_variables("^OPENSUBDIV") - unset_cache_variables("^OPENVDB") - unset_cache_variables("^TBB") - unset_cache_variables("^USD") -endif() - -if(UNIX AND (NOT APPLE) AND LIBDIR AND (EXISTS ${LIBDIR})) - # Only search for the path if it's found on the system. - set(_libdir_stale "/lib/linux_centos7_x86_64/") - unset_cached_varables_containting( - "${_libdir_stale}" - "Auto clearing old ${_libdir_stale} paths from CMake configuration" - ) - unset(_libdir_stale) -endif() - # Detect update in 4.1 to shared library OpenImageDenoise and OSL. if(UNIX AND DEFINED OPENIMAGEDENOISE_LIBRARY AND @@ -135,3 +73,26 @@ if(UNIX AND message(STATUS "Auto updating CMake configuration for Python 3.11") unset_cache_variables("^PYTHON_") endif() + +# Detect update to 4.4 libs. +if(LIBDIR AND + EXISTS ${LIBDIR}/tbb/include/oneapi AND + ((DEFINED Boost_INCLUDE_DIR) OR (SYCL_LIBRARY MATCHES "sycl7"))) + message(STATUS "Auto updating CMake configuration for Blender 4.4 libraries") + unset_cache_variables("^BOOST") + unset_cache_variables("^Boost") + unset_cache_variables("^EMBREE") + unset_cache_variables("^IMATH") + unset_cache_variables("^MATERIALX") + unset_cache_variables("^NANOVDB") + unset_cache_variables("^OPENCOLORIO") + unset_cache_variables("^OPENEXR") + unset_cache_variables("^OPENIMAGEDENOISE") + unset_cache_variables("^OPENIMAGEIO") + unset_cache_variables("^OPENVDB") + unset_cache_variables("^OSL_") + unset_cache_variables("^PYTHON") + unset_cache_variables("^SYCL") + unset_cache_variables("^TBB") + unset_cache_variables("^USD") +endif()