From 34216a2b7bd810a8b6b56858ad590639972d0246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 10 Feb 2025 14:06:47 +0100 Subject: [PATCH 1/3] Fix #134234: GPU: Shader Compile Error on with gpu.types.GPUShader The removal of the loose uniform made the shader not compile. This patch adds a new define for these type of shaders and add back the loose uniform. Note that these shaders might no longer work on Metal as the source is not parsed anymore. Pull Request: https://projects.blender.org/blender/blender/pulls/134341 --- source/blender/gpu/intern/gpu_shader.cc | 11 ++++++++++- .../gpu/shaders/gpu_shader_colorspace_lib.glsl | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index b713687492c..8cd6ec9a10b 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -331,9 +331,18 @@ GPUShader *GPU_shader_create_from_python(std::optional vertcode, std::optional fragcode, std::optional geomcode, std::optional libcode, - const std::optional defines, + std::optional defines, const std::optional name) { + std::string defines_cat = "#define GPU_RAW_PYTHON_SHADER\n"; + if (defines) { + defines_cat += defines.value(); + defines = defines_cat; + } + else { + defines = defines_cat; + } + std::string libcodecat; if (!libcode) { diff --git a/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl b/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl index 15168359272..821bfe0eb16 100644 --- a/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl +++ b/source/blender/gpu/shaders/gpu_shader_colorspace_lib.glsl @@ -11,6 +11,13 @@ SHADER_LIBRARY_CREATE_INFO(gpu_srgb_to_framebuffer_space) /* Undefine the macro that avoids compilation errors. */ #undef blender_srgb_to_framebuffer_space +/* Raw python shaders don't have create infos and thus don't generate the needed `srgbTarget` + * uniform automatically. For API compatibility, we sill define this loose uniform, but it will + * not be parsed by the Metal or Vulkan backend. */ +#ifdef GPU_RAW_PYTHON_SHADER +uniform bool srgbTarget = false; +#endif + vec4 blender_srgb_to_framebuffer_space(vec4 in_color) { if (srgbTarget) { From 5437f22faf7449729d77d18ab9b54d0d2a740a22 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 10 Feb 2025 14:13:42 +0100 Subject: [PATCH 2/3] Fix unknown Cycles test device silently pass Prevents situation when requested device is HIPRT (while the expected spelling is HIP-RT). Pull Request: https://projects.blender.org/blender/blender/pulls/134332 --- CMakeLists.txt | 2 +- tests/python/CMakeLists.txt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 537708d0285..aa6950aeb98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -651,7 +651,7 @@ Build Cycles kernels with address sanitizer when WITH_COMPILER_ASAN is on, even OFF ) set(CYCLES_TEST_DEVICES CPU CACHE STRING "\ -Run regression tests on the specified device types (CPU CUDA OPTIX HIP)" +Run regression tests on the specified device types (CPU CUDA OPTIX HIP HIP-RT METAL METAL-RT ONEAPI ONEAPI-RT)" ) option(WITH_CYCLES_TEST_OSL "\ Run additional Cycles test with OSL enabled" diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 8fdc5a729c2..4b7babf5be2 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -613,6 +613,7 @@ if(WITH_CYCLES OR WITH_GPU_RENDER_TESTS) # Cycles if(WITH_CYCLES) set(_cycles_blocklist "") + set(_cycles_known_test_devices CPU CUDA OPTIX HIP HIP-RT METAL METAL-RT ONEAPI ONEAPI-RT) if((NOT WITH_CYCLES_OSL) OR (WITH_CYCLES_TEST_OSL AND WITH_CYCLES_OSL)) # Disable OSL tests if built without OSL or # Disable OSL tests during the "normal" test phase to avoid double @@ -620,6 +621,10 @@ if(WITH_CYCLES OR WITH_GPU_RENDER_TESTS) set(_cycles_blocklist OSL) endif() foreach(_cycles_device ${CYCLES_TEST_DEVICES}) + if(NOT ${_cycles_device} IN_LIST _cycles_known_test_devices) + message(FATAL_ERROR "Unknown Cycles test device ${_cycles_device}." + "Supported devices are: ${_cycles_known_test_devices}") + endif() string(TOLOWER "${_cycles_device}" _cycles_device_lower) set(_cycles_render_tests bake;${render_tests};osl) @@ -662,6 +667,7 @@ if(WITH_CYCLES OR WITH_GPU_RENDER_TESTS) endforeach() endforeach() unset(_cycles_blocklist) + unset(_cycles_known_test_devices) endif() if(WITH_GPU_RENDER_TESTS) From 1586b74262c1d197148c1bd98801800898b33630 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 10 Feb 2025 14:11:19 +0100 Subject: [PATCH 3/3] Fix (unreported) crash when adding new image from UI. The usual issue of non-trivial C++ data being allocated with C-style `alloc` code. Also added more default initializers to some generic RNA-related structs that embded some `PointerRNA` members. --- source/blender/editors/space_image/image_ops.cc | 10 ++++++---- source/blender/makesrna/RNA_types.hh | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/space_image/image_ops.cc b/source/blender/editors/space_image/image_ops.cc index 1cb23342344..1331c5c46d6 100644 --- a/source/blender/editors/space_image/image_ops.cc +++ b/source/blender/editors/space_image/image_ops.cc @@ -2542,7 +2542,7 @@ enum { }; struct ImageNewData { - PropertyPointerRNA pprop; + PropertyPointerRNA pprop = {}; }; static ImageNewData *image_new_init(bContext *C, wmOperator *op) @@ -2551,7 +2551,7 @@ static ImageNewData *image_new_init(bContext *C, wmOperator *op) return static_cast(op->customdata); } - ImageNewData *data = static_cast(MEM_callocN(sizeof(ImageNewData), __func__)); + ImageNewData *data = MEM_new(__func__); UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop); op->customdata = data; return data; @@ -2559,7 +2559,9 @@ static ImageNewData *image_new_init(bContext *C, wmOperator *op) static void image_new_free(wmOperator *op) { - MEM_SAFE_FREE(op->customdata); + if (op->customdata) { + MEM_delete(static_cast(op->customdata)); + } } static int image_new_exec(bContext *C, wmOperator *op) @@ -2655,7 +2657,7 @@ static int image_new_invoke(bContext *C, wmOperator *op, const wmEvent * /*event { /* Get property in advance, it doesn't work after WM_operator_props_dialog_popup. */ ImageNewData *data; - op->customdata = data = static_cast(MEM_callocN(sizeof(ImageNewData), __func__)); + op->customdata = data = MEM_new(__func__); UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop); /* Better for user feedback. */ diff --git a/source/blender/makesrna/RNA_types.hh b/source/blender/makesrna/RNA_types.hh index 94a022d8637..5611e1e1baa 100644 --- a/source/blender/makesrna/RNA_types.hh +++ b/source/blender/makesrna/RNA_types.hh @@ -45,18 +45,18 @@ struct PointerRNA { extern const PointerRNA PointerRNA_NULL; struct PropertyPointerRNA { - PointerRNA ptr; - PropertyRNA *prop; + PointerRNA ptr = {}; + PropertyRNA *prop = nullptr; }; /** * Stored result of a RNA path lookup (as used by anim-system) */ struct PathResolvedRNA { - PointerRNA ptr; - PropertyRNA *prop; + PointerRNA ptr = {}; + PropertyRNA *prop = nullptr; /** -1 for non-array access. */ - int prop_index; + int prop_index = -1; }; /* Property */