diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 6040c5f938b..30842f32441 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -55,8 +55,7 @@ if(WITH_LZMA) add_subdirectory(lzma) endif() -if(WITH_CYCLES OR WITH_COMPOSITOR_CPU OR WITH_OPENSUBDIV) - add_subdirectory(clew) +if(WITH_CYCLES OR WITH_OPENSUBDIV) if((WITH_CYCLES_DEVICE_CUDA OR WITH_CYCLES_DEVICE_OPTIX) AND WITH_CUDA_DYNLOAD) add_subdirectory(cuew) endif() diff --git a/extern/clew/CMakeLists.txt b/extern/clew/CMakeLists.txt deleted file mode 100644 index a9d64f286ed..00000000000 --- a/extern/clew/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-FileCopyrightText: 2006 Blender Foundation -# -# SPDX-License-Identifier: GPL-2.0-or-later - -set(INC - . - include -) - -set(INC_SYS - -) - -set(SRC - include/clew.h - src/clew.c -) - -set(LIB -) - -add_definitions(-DCL_USE_DEPRECATED_OPENCL_1_1_APIS) - -blender_add_lib(extern_clew "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/extern/clew/README.blender b/extern/clew/README.blender deleted file mode 100644 index 127b6bdac63..00000000000 --- a/extern/clew/README.blender +++ /dev/null @@ -1,5 +0,0 @@ -Project: OpenCL Wrangler -URL: https://github.com/OpenCLWrangler/clew -License: Apache 2.0 -Upstream version: 27a6867 -Local modifications: None diff --git a/extern/clew/include/clew.h b/extern/clew/include/clew.h deleted file mode 100644 index 0bbb95b9839..00000000000 --- a/extern/clew/include/clew.h +++ /dev/null @@ -1,2822 +0,0 @@ -#ifndef CLEW_HPP_INCLUDED -#define CLEW_HPP_INCLUDED - -////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2009-2011 Organic Vectory B.V., KindDragon -// Written by George van Venrooij -// -// Distributed under the MIT License. -////////////////////////////////////////////////////////////////////////// - -//! \file clew.h -//! \brief OpenCL run-time loader header -//! -//! This file contains a copy of the contents of CL.H and CL_PLATFORM.H from the -//! official OpenCL spec. The purpose of this code is to load the OpenCL dynamic -//! library at run-time and thus allow the executable to function on many -//! platforms regardless of the vendor of the OpenCL driver actually installed. -//! Some of the techniques used here were inspired by work done in the GLEW -//! library (http://glew.sourceforge.net/) - -// Run-time dynamic linking functionality based on concepts used in GLEW -#ifdef __OPENCL_CL_H -#error cl.h included before clew.h -#endif - -#ifdef __OPENCL_CL_PLATFORM_H -#error cl_platform.h included before clew.h -#endif - -// Prevent cl.h inclusion -#define __OPENCL_CL_H -// Prevent cl_platform.h inclusion -#define __CL_PLATFORM_H - -/******************************************************************************* -* Copyright (c) 2008-2010 The Khronos Group Inc. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and/or associated documentation files (the -* "Materials"), to deal in the Materials without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Materials, and to -* permit persons to whom the Materials are furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Materials. -* -* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -******************************************************************************/ -#ifdef __APPLE__ - /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ - #include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WIN32) - #define CL_API_ENTRY - #define CL_API_CALL __stdcall - #define CL_CALLBACK __stdcall -#else - #define CL_API_ENTRY - #define CL_API_CALL - #define CL_CALLBACK -#endif - -#ifdef __APPLE__ - #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) - #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_API_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK - #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_API_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK -#else - #define CL_EXTENSION_WEAK_LINK - #define CL_API_SUFFIX__VERSION_1_0 - #define CL_EXT_SUFFIX__VERSION_1_0 - #define CL_API_SUFFIX__VERSION_1_1 - #define CL_EXT_SUFFIX__VERSION_1_1 - #define CL_API_SUFFIX__VERSION_1_2 - #define CL_EXT_SUFFIX__VERSION_1_2 - - #if defined(__GNUC__) - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif - #elif defined(_WIN32) - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) - #endif - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif -#endif - -#if (defined (_WIN32) && defined(_MSC_VER)) - -/* scalar types */ -typedef signed __int8 cl_char; -typedef unsigned __int8 cl_uchar; -typedef signed __int16 cl_short; -typedef unsigned __int16 cl_ushort; -typedef signed __int32 cl_int; -typedef unsigned __int32 cl_uint; -typedef signed __int64 cl_long; -typedef unsigned __int64 cl_ulong; - -typedef unsigned __int16 cl_half; -typedef float cl_float; -typedef double cl_double; - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 340282346638528859811704183484516925440.0f -#define CL_FLT_MIN 1.175494350822287507969e-38f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 -#define CL_DBL_MIN 2.225073858507201383090e-308 -#define CL_DBL_EPSILON 2.220446049250313080847e-16 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#define CL_NAN (CL_INFINITY - CL_INFINITY) -#define CL_HUGE_VALF ((cl_float) 1e50) -#define CL_HUGE_VAL ((cl_double) 1e500) -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#else - -#include - -/* scalar types */ -typedef int8_t cl_char; -typedef uint8_t cl_uchar; -typedef int16_t cl_short __attribute__((aligned(2))); -typedef uint16_t cl_ushort __attribute__((aligned(2))); -typedef int32_t cl_int __attribute__((aligned(4))); -typedef uint32_t cl_uint __attribute__((aligned(4))); -typedef int64_t cl_long __attribute__((aligned(8))); -typedef uint64_t cl_ulong __attribute__((aligned(8))); - -typedef uint16_t cl_half __attribute__((aligned(2))); -typedef float cl_float __attribute__((aligned(4))); -typedef double cl_double __attribute__((aligned(8))); - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 0x1.fffffep127f -#define CL_FLT_MIN 0x1.0p-126f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 0x1.fffffffffffffp1023 -#define CL_DBL_MIN 0x1.0p-1022 -#define CL_DBL_EPSILON 0x1.0p-52 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#if defined( __GNUC__ ) - #define CL_HUGE_VALF __builtin_huge_valf() - #define CL_HUGE_VAL __builtin_huge_val() - #define CL_NAN __builtin_nanf( "" ) -#else - #define CL_HUGE_VALF ((cl_float) 1e50) - #define CL_HUGE_VAL ((cl_double) 1e500) - float nanf( const char * ); - #define CL_NAN nanf( "" ) -#endif -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#endif - -#include - -/* Mirror types to GL types. Mirror types allow us to avoid deciding which headers to load based on whether we are using GL or GLES here. */ -typedef unsigned int cl_GLuint; -typedef int cl_GLint; -typedef unsigned int cl_GLenum; - -/* - * Vector types - * - * Note: OpenCL requires that all types be naturally aligned. - * This means that vector types must be naturally aligned. - * For example, a vector of four floats must be aligned to - * a 16 byte boundary (calculated as 4 * the natural 4-byte - * alignment of the float). The alignment qualifiers here - * will only function properly if your compiler supports them - * and if you don't actively work to defeat them. For example, - * in order for a cl_float4 to be 16 byte aligned in a struct, - * the start of the struct must itself be 16-byte aligned. - * - * Maintaining proper alignment is the user's responsibility. - */ - - -#ifdef _MSC_VER -#if defined(_M_IX86) -#if _M_IX86_FP >= 0 && !defined(__SSE__) -#define __SSE__ -#endif -#if _M_IX86_FP >= 1 -# ifndef __SSE2__ -# define __SSE2__ -# endif -#endif -#elif defined(_M_X64) -# ifndef __SSE__ -# define __SSE__ -# endif -# ifndef __SSE2__ -# define __SSE2__ -# endif -#endif -#endif - -/* Define basic vector types */ -/* Workaround for ppc64el platform: conflicts with bool from C++. */ -#if defined( __VEC__ ) && !(defined(__PPC64__) && defined(__LITTLE_ENDIAN__)) - #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ - typedef vector unsigned char __cl_uchar16; - typedef vector signed char __cl_char16; - typedef vector unsigned short __cl_ushort8; - typedef vector signed short __cl_short8; - typedef vector unsigned int __cl_uint4; - typedef vector signed int __cl_int4; - typedef vector float __cl_float4; - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_UINT4__ 1 - #define __CL_INT4__ 1 - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) && !defined( __ICC ) - typedef float __cl_float4 __attribute__((vector_size(16))); - #else - typedef __m128 __cl_float4; - #endif - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE2__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) && !defined( __ICC ) - typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); - typedef cl_char __cl_char16 __attribute__((vector_size(16))); - typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); - typedef cl_short __cl_short8 __attribute__((vector_size(16))); - typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); - typedef cl_int __cl_int4 __attribute__((vector_size(16))); - typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); - typedef cl_long __cl_long2 __attribute__((vector_size(16))); - typedef cl_double __cl_double2 __attribute__((vector_size(16))); - #else - typedef __m128i __cl_uchar16; - typedef __m128i __cl_char16; - typedef __m128i __cl_ushort8; - typedef __m128i __cl_short8; - typedef __m128i __cl_uint4; - typedef __m128i __cl_int4; - typedef __m128i __cl_ulong2; - typedef __m128i __cl_long2; - typedef __m128d __cl_double2; - #endif - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_INT4__ 1 - #define __CL_UINT4__ 1 - #define __CL_ULONG2__ 1 - #define __CL_LONG2__ 1 - #define __CL_DOUBLE2__ 1 -#endif - -#if defined( __MMX__ ) - #include - #if defined( __GNUC__ ) && !defined( __ICC ) - typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); - typedef cl_char __cl_char8 __attribute__((vector_size(8))); - typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); - typedef cl_short __cl_short4 __attribute__((vector_size(8))); - typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); - typedef cl_int __cl_int2 __attribute__((vector_size(8))); - typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); - typedef cl_long __cl_long1 __attribute__((vector_size(8))); - typedef cl_float __cl_float2 __attribute__((vector_size(8))); - #else - typedef __m64 __cl_uchar8; - typedef __m64 __cl_char8; - typedef __m64 __cl_ushort4; - typedef __m64 __cl_short4; - typedef __m64 __cl_uint2; - typedef __m64 __cl_int2; - typedef __m64 __cl_ulong1; - typedef __m64 __cl_long1; - typedef __m64 __cl_float2; - #endif - #define __CL_UCHAR8__ 1 - #define __CL_CHAR8__ 1 - #define __CL_USHORT4__ 1 - #define __CL_SHORT4__ 1 - #define __CL_INT2__ 1 - #define __CL_UINT2__ 1 - #define __CL_ULONG1__ 1 - #define __CL_LONG1__ 1 - #define __CL_FLOAT2__ 1 -#endif - -#if defined( __AVX__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) && !defined( __ICC ) - typedef cl_float __cl_float8 __attribute__((vector_size(32))); - typedef cl_double __cl_double4 __attribute__((vector_size(32))); - #else - typedef __m256 __cl_float8; - typedef __m256d __cl_double4; - #endif - #define __CL_FLOAT8__ 1 - #define __CL_DOUBLE4__ 1 -#endif - -/* Define alignment keys */ -#if defined( __GNUC__ ) - #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) -#elif defined( _WIN32) && (_MSC_VER) - /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ - /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ - /* #include */ - /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ - #define CL_ALIGNED(_x) -#else - #warning Need to implement some method to align data here - #define CL_ALIGNED(_x) -#endif - -/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ -#if (defined( __GNUC__) && ! defined( __STRICT_ANSI__ )) || (defined( _MSC_VER ) && ! defined( __STDC__ )) - /* .xyzw and .s0123...{f|F} are supported */ - #define CL_HAS_NAMED_VECTOR_FIELDS 1 - /* .hi and .lo are supported */ - #define CL_HAS_HI_LO_VECTOR_FIELDS 1 - - #define CL_NAMED_STRUCT_SUPPORTED -#endif - -#if defined( CL_NAMED_STRUCT_SUPPORTED) && defined( _MSC_VER ) -#define __extension__ __pragma(warning(suppress:4201)) -#endif - -/* Define cl_vector types */ - -/* ---- cl_charn ---- */ -typedef union -{ - cl_char CL_ALIGNED(2) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_char x, y; }; - __extension__ struct{ cl_char s0, s1; }; - __extension__ struct{ cl_char lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2; -#endif -}cl_char2; - -typedef union -{ - cl_char CL_ALIGNED(4) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_char x, y, z, w; }; - __extension__ struct{ cl_char s0, s1, s2, s3; }; - __extension__ struct{ cl_char2 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[2]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4; -#endif -}cl_char4; - -/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ -typedef cl_char4 cl_char3; - -typedef union -{ - cl_char CL_ALIGNED(8) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_char x, y, z, w; }; - __extension__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_char4 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[4]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[2]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8; -#endif -}cl_char8; - -typedef union -{ - cl_char CL_ALIGNED(16) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_char8 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[8]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[4]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8[2]; -#endif -#if defined( __CL_CHAR16__ ) - __cl_char16 v16; -#endif -}cl_char16; - - -/* ---- cl_ucharn ---- */ -typedef union -{ - cl_uchar CL_ALIGNED(2) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uchar x, y; }; - __extension__ struct{ cl_uchar s0, s1; }; - __extension__ struct{ cl_uchar lo, hi; }; -#endif -#if defined( __cl_uchar2__) - __cl_uchar2 v2; -#endif -}cl_uchar2; - -typedef union -{ - cl_uchar CL_ALIGNED(4) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uchar x, y, z, w; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3; }; - __extension__ struct{ cl_uchar2 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[2]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4; -#endif -}cl_uchar4; - -/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ -typedef cl_uchar4 cl_uchar3; - -typedef union -{ - cl_uchar CL_ALIGNED(8) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uchar x, y, z, w; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_uchar4 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[4]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[2]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8; -#endif -}cl_uchar8; - -typedef union -{ - cl_uchar CL_ALIGNED(16) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_uchar8 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[8]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[4]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8[2]; -#endif -#if defined( __CL_UCHAR16__ ) - __cl_uchar16 v16; -#endif -}cl_uchar16; - - -/* ---- cl_shortn ---- */ -typedef union -{ - cl_short CL_ALIGNED(4) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_short x, y; }; - __extension__ struct{ cl_short s0, s1; }; - __extension__ struct{ cl_short lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2; -#endif -}cl_short2; - -typedef union -{ - cl_short CL_ALIGNED(8) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_short x, y, z, w; }; - __extension__ struct{ cl_short s0, s1, s2, s3; }; - __extension__ struct{ cl_short2 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[2]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4; -#endif -}cl_short4; - -/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ -typedef cl_short4 cl_short3; - -typedef union -{ - cl_short CL_ALIGNED(16) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_short x, y, z, w; }; - __extension__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_short4 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[4]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[2]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8; -#endif -}cl_short8; - -typedef union -{ - cl_short CL_ALIGNED(32) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_short8 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[8]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[4]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8[2]; -#endif -#if defined( __CL_SHORT16__ ) - __cl_short16 v16; -#endif -}cl_short16; - - -/* ---- cl_ushortn ---- */ -typedef union -{ - cl_ushort CL_ALIGNED(4) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ushort x, y; }; - __extension__ struct{ cl_ushort s0, s1; }; - __extension__ struct{ cl_ushort lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2; -#endif -}cl_ushort2; - -typedef union -{ - cl_ushort CL_ALIGNED(8) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ushort x, y, z, w; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3; }; - __extension__ struct{ cl_ushort2 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[2]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4; -#endif -}cl_ushort4; - -/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ -typedef cl_ushort4 cl_ushort3; - -typedef union -{ - cl_ushort CL_ALIGNED(16) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ushort x, y, z, w; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_ushort4 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[4]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[2]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8; -#endif -}cl_ushort8; - -typedef union -{ - cl_ushort CL_ALIGNED(32) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_ushort8 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[8]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[4]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8[2]; -#endif -#if defined( __CL_USHORT16__ ) - __cl_ushort16 v16; -#endif -}cl_ushort16; - -/* ---- cl_intn ---- */ -typedef union -{ - cl_int CL_ALIGNED(8) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_int x, y; }; - __extension__ struct{ cl_int s0, s1; }; - __extension__ struct{ cl_int lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2; -#endif -}cl_int2; - -typedef union -{ - cl_int CL_ALIGNED(16) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_int x, y, z, w; }; - __extension__ struct{ cl_int s0, s1, s2, s3; }; - __extension__ struct{ cl_int2 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[2]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4; -#endif -}cl_int4; - -/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ -typedef cl_int4 cl_int3; - -typedef union -{ - cl_int CL_ALIGNED(32) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_int x, y, z, w; }; - __extension__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_int4 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[4]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[2]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8; -#endif -}cl_int8; - -typedef union -{ - cl_int CL_ALIGNED(64) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_int8 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[8]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[4]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8[2]; -#endif -#if defined( __CL_INT16__ ) - __cl_int16 v16; -#endif -}cl_int16; - - -/* ---- cl_uintn ---- */ -typedef union -{ - cl_uint CL_ALIGNED(8) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uint x, y; }; - __extension__ struct{ cl_uint s0, s1; }; - __extension__ struct{ cl_uint lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2; -#endif -}cl_uint2; - -typedef union -{ - cl_uint CL_ALIGNED(16) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uint x, y, z, w; }; - __extension__ struct{ cl_uint s0, s1, s2, s3; }; - __extension__ struct{ cl_uint2 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[2]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4; -#endif -}cl_uint4; - -/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ -typedef cl_uint4 cl_uint3; - -typedef union -{ - cl_uint CL_ALIGNED(32) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uint x, y, z, w; }; - __extension__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_uint4 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[4]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[2]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8; -#endif -}cl_uint8; - -typedef union -{ - cl_uint CL_ALIGNED(64) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_uint8 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[8]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[4]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8[2]; -#endif -#if defined( __CL_UINT16__ ) - __cl_uint16 v16; -#endif -}cl_uint16; - -/* ---- cl_longn ---- */ -typedef union -{ - cl_long CL_ALIGNED(16) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_long x, y; }; - __extension__ struct{ cl_long s0, s1; }; - __extension__ struct{ cl_long lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2; -#endif -}cl_long2; - -typedef union -{ - cl_long CL_ALIGNED(32) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_long x, y, z, w; }; - __extension__ struct{ cl_long s0, s1, s2, s3; }; - __extension__ struct{ cl_long2 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[2]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4; -#endif -}cl_long4; - -/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ -typedef cl_long4 cl_long3; - -typedef union -{ - cl_long CL_ALIGNED(64) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_long x, y, z, w; }; - __extension__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_long4 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[4]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[2]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8; -#endif -}cl_long8; - -typedef union -{ - cl_long CL_ALIGNED(128) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_long8 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[8]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[4]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8[2]; -#endif -#if defined( __CL_LONG16__ ) - __cl_long16 v16; -#endif -}cl_long16; - - -/* ---- cl_ulongn ---- */ -typedef union -{ - cl_ulong CL_ALIGNED(16) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ulong x, y; }; - __extension__ struct{ cl_ulong s0, s1; }; - __extension__ struct{ cl_ulong lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2; -#endif -}cl_ulong2; - -typedef union -{ - cl_ulong CL_ALIGNED(32) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ulong x, y, z, w; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3; }; - __extension__ struct{ cl_ulong2 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[2]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4; -#endif -}cl_ulong4; - -/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ -typedef cl_ulong4 cl_ulong3; - -typedef union -{ - cl_ulong CL_ALIGNED(64) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ulong x, y, z, w; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_ulong4 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[4]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[2]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8; -#endif -}cl_ulong8; - -typedef union -{ - cl_ulong CL_ALIGNED(128) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_ulong8 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[8]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[4]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8[2]; -#endif -#if defined( __CL_ULONG16__ ) - __cl_ulong16 v16; -#endif -}cl_ulong16; - - -/* --- cl_floatn ---- */ - -typedef union -{ - cl_float CL_ALIGNED(8) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_float x, y; }; - __extension__ struct{ cl_float s0, s1; }; - __extension__ struct{ cl_float lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2; -#endif -}cl_float2; - -typedef union -{ - cl_float CL_ALIGNED(16) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_float x, y, z, w; }; - __extension__ struct{ cl_float s0, s1, s2, s3; }; - __extension__ struct{ cl_float2 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[2]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4; -#endif -}cl_float4; - -/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ -typedef cl_float4 cl_float3; - -typedef union -{ - cl_float CL_ALIGNED(32) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_float x, y, z, w; }; - __extension__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_float4 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[4]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[2]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8; -#endif -}cl_float8; - -typedef union -{ - cl_float CL_ALIGNED(64) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_float8 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[8]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[4]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8[2]; -#endif -#if defined( __CL_FLOAT16__ ) - __cl_float16 v16; -#endif -}cl_float16; - -/* --- cl_doublen ---- */ - -typedef union -{ - cl_double CL_ALIGNED(16) s[2]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_double x, y; }; - __extension__ struct{ cl_double s0, s1; }; - __extension__ struct{ cl_double lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2; -#endif -}cl_double2; - -typedef union -{ - cl_double CL_ALIGNED(32) s[4]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_double x, y, z, w; }; - __extension__ struct{ cl_double s0, s1, s2, s3; }; - __extension__ struct{ cl_double2 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[2]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4; -#endif -}cl_double4; - -/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ -typedef cl_double4 cl_double3; - -typedef union -{ - cl_double CL_ALIGNED(64) s[8]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_double x, y, z, w; }; - __extension__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_double4 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[4]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[2]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8; -#endif -}cl_double8; - -typedef union -{ - cl_double CL_ALIGNED(128) s[16]; -#if defined( CL_NAMED_STRUCT_SUPPORTED ) - __extension__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_double8 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[8]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[4]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8[2]; -#endif -#if defined( __CL_DOUBLE16__ ) - __cl_double16 v16; -#endif -}cl_double16; - -/* Macro to facilitate debugging - * Usage: - * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. - * The first line ends with: CL_PROGRAM_STRING_BEGIN \" - * Each line thereafter of OpenCL C source must end with: \n\ - * The last line ends in "; - * - * Example: - * - * const char *my_program = CL_PROGRAM_STRING_BEGIN "\ - * kernel void foo( int a, float * b ) \n\ - * { \n\ - * // my comment \n\ - * *b[ get_global_id(0)] = a; \n\ - * } \n\ - * "; - * - * This should correctly set up the line, (column) and file information for your source - * string so you can do source level debugging. - */ -#define __CL_STRINGIFY( _x ) # _x -#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) -#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" - -// CL.h contents -/******************************************************************************/ - -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; - -typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ -typedef cl_ulong cl_bitfield; -typedef cl_bitfield cl_device_type; -typedef cl_uint cl_platform_info; -typedef cl_uint cl_device_info; -typedef cl_bitfield cl_device_fp_config; -typedef cl_uint cl_device_mem_cache_type; -typedef cl_uint cl_device_local_mem_type; -typedef cl_bitfield cl_device_exec_capabilities; -typedef cl_bitfield cl_command_queue_properties; -typedef intptr_t cl_device_partition_property; -typedef cl_bitfield cl_device_affinity_domain; - -typedef intptr_t cl_context_properties; -typedef cl_uint cl_context_info; -typedef cl_uint cl_command_queue_info; -typedef cl_uint cl_channel_order; -typedef cl_uint cl_channel_type; -typedef cl_bitfield cl_mem_flags; -typedef cl_uint cl_mem_object_type; -typedef cl_uint cl_mem_info; -typedef cl_uint cl_image_info; -typedef cl_uint cl_buffer_create_type; -typedef cl_uint cl_addressing_mode; -typedef cl_uint cl_filter_mode; -typedef cl_uint cl_sampler_info; -typedef cl_bitfield cl_map_flags; -typedef cl_uint cl_program_info; -typedef cl_uint cl_program_build_info; -typedef cl_int cl_build_status; -typedef cl_uint cl_kernel_info; -typedef cl_uint cl_kernel_work_group_info; -typedef cl_uint cl_event_info; -typedef cl_uint cl_command_type; -typedef cl_uint cl_profiling_info; - -typedef struct _cl_image_format { - cl_channel_order image_channel_order; - cl_channel_type image_channel_data_type; -} cl_image_format; - -typedef struct _cl_image_desc { - cl_mem_object_type image_type; - size_t image_width; - size_t image_height; - size_t image_depth; - size_t image_array_size; - size_t image_row_pitch; - size_t image_slice_pitch; - cl_uint num_mip_levels; - cl_uint num_samples; - cl_mem buffer; - } cl_image_desc; - -typedef struct _cl_buffer_region { - size_t origin; - size_t size; -} cl_buffer_region; - -/******************************************************************************/ - -/* Error Codes */ -#define CL_SUCCESS 0 -#define CL_DEVICE_NOT_FOUND -1 -#define CL_DEVICE_NOT_AVAILABLE -2 -#define CL_COMPILER_NOT_AVAILABLE -3 -#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 -#define CL_OUT_OF_RESOURCES -5 -#define CL_OUT_OF_HOST_MEMORY -6 -#define CL_PROFILING_INFO_NOT_AVAILABLE -7 -#define CL_MEM_COPY_OVERLAP -8 -#define CL_IMAGE_FORMAT_MISMATCH -9 -#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 -#define CL_BUILD_PROGRAM_FAILURE -11 -#define CL_MAP_FAILURE -12 -#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 -#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 -#define CL_COMPILE_PROGRAM_FAILURE -15 -#define CL_LINKER_NOT_AVAILABLE -16 -#define CL_LINK_PROGRAM_FAILURE -17 -#define CL_DEVICE_PARTITION_FAILED -18 -#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 - -#define CL_INVALID_VALUE -30 -#define CL_INVALID_DEVICE_TYPE -31 -#define CL_INVALID_PLATFORM -32 -#define CL_INVALID_DEVICE -33 -#define CL_INVALID_CONTEXT -34 -#define CL_INVALID_QUEUE_PROPERTIES -35 -#define CL_INVALID_COMMAND_QUEUE -36 -#define CL_INVALID_HOST_PTR -37 -#define CL_INVALID_MEM_OBJECT -38 -#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 -#define CL_INVALID_IMAGE_SIZE -40 -#define CL_INVALID_SAMPLER -41 -#define CL_INVALID_BINARY -42 -#define CL_INVALID_BUILD_OPTIONS -43 -#define CL_INVALID_PROGRAM -44 -#define CL_INVALID_PROGRAM_EXECUTABLE -45 -#define CL_INVALID_KERNEL_NAME -46 -#define CL_INVALID_KERNEL_DEFINITION -47 -#define CL_INVALID_KERNEL -48 -#define CL_INVALID_ARG_INDEX -49 -#define CL_INVALID_ARG_VALUE -50 -#define CL_INVALID_ARG_SIZE -51 -#define CL_INVALID_KERNEL_ARGS -52 -#define CL_INVALID_WORK_DIMENSION -53 -#define CL_INVALID_WORK_GROUP_SIZE -54 -#define CL_INVALID_WORK_ITEM_SIZE -55 -#define CL_INVALID_GLOBAL_OFFSET -56 -#define CL_INVALID_EVENT_WAIT_LIST -57 -#define CL_INVALID_EVENT -58 -#define CL_INVALID_OPERATION -59 -#define CL_INVALID_GL_OBJECT -60 -#define CL_INVALID_BUFFER_SIZE -61 -#define CL_INVALID_MIP_LEVEL -62 -#define CL_INVALID_GLOBAL_WORK_SIZE -63 -#define CL_INVALID_PROPERTY -64 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#define CL_INVALID_COMPILER_OPTIONS -66 -#define CL_INVALID_LINKER_OPTIONS -67 -#define CL_INVALID_DEVICE_PARTITION_COUNT -68 - -/* OpenCL Version */ -#define CL_VERSION_1_0 1 -#define CL_VERSION_1_1 1 -#define CL_VERSION_1_2 1 - -/* cl_bool */ -#define CL_FALSE 0 -#define CL_TRUE 1 -#define CL_BLOCKING CL_TRUE -#define CL_NON_BLOCKING CL_FALSE - -/* cl_platform_info */ -#define CL_PLATFORM_PROFILE 0x0900 -#define CL_PLATFORM_VERSION 0x0901 -#define CL_PLATFORM_NAME 0x0902 -#define CL_PLATFORM_VENDOR 0x0903 -#define CL_PLATFORM_EXTENSIONS 0x0904 - -/* cl_device_type - bitfield */ -#define CL_DEVICE_TYPE_DEFAULT (1 << 0) -#define CL_DEVICE_TYPE_CPU (1 << 1) -#define CL_DEVICE_TYPE_GPU (1 << 2) -#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) -#define CL_DEVICE_TYPE_CUSTOM (1 << 4) -#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF - -/* cl_device_info */ -#define CL_DEVICE_TYPE 0x1000 -#define CL_DEVICE_VENDOR_ID 0x1001 -#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 -#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 -#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 -#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B -#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C -#define CL_DEVICE_ADDRESS_BITS 0x100D -#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E -#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F -#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 -#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 -#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 -#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 -#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 -#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 -#define CL_DEVICE_IMAGE_SUPPORT 0x1016 -#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 -#define CL_DEVICE_MAX_SAMPLERS 0x1018 -#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 -#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A -#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B -#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C -#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D -#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E -#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F -#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 -#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 -#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 -#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 -#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 -#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 -#define CL_DEVICE_ENDIAN_LITTLE 0x1026 -#define CL_DEVICE_AVAILABLE 0x1027 -#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 -#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 -#define CL_DEVICE_QUEUE_PROPERTIES 0x102A -#define CL_DEVICE_NAME 0x102B -#define CL_DEVICE_VENDOR 0x102C -#define CL_DRIVER_VERSION 0x102D -#define CL_DEVICE_PROFILE 0x102E -#define CL_DEVICE_VERSION 0x102F -#define CL_DEVICE_EXTENSIONS 0x1030 -#define CL_DEVICE_PLATFORM 0x1031 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */ -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 -#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C -#define CL_DEVICE_OPENCL_C_VERSION 0x103D -#define CL_DEVICE_LINKER_AVAILABLE 0x103E -#define CL_DEVICE_BUILT_IN_KERNELS 0x103F -#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 -#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 -#define CL_DEVICE_PARENT_DEVICE 0x1042 -#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 -#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 -#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 -#define CL_DEVICE_PARTITION_TYPE 0x1046 -#define CL_DEVICE_REFERENCE_COUNT 0x1047 -#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 -#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B - -/* cl_device_fp_config - bitfield */ -#define CL_FP_DENORM (1 << 0) -#define CL_FP_INF_NAN (1 << 1) -#define CL_FP_ROUND_TO_NEAREST (1 << 2) -#define CL_FP_ROUND_TO_ZERO (1 << 3) -#define CL_FP_ROUND_TO_INF (1 << 4) -#define CL_FP_FMA (1 << 5) -#define CL_FP_SOFT_FLOAT (1 << 6) -#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) - -/* cl_device_mem_cache_type */ -#define CL_NONE 0x0 -#define CL_READ_ONLY_CACHE 0x1 -#define CL_READ_WRITE_CACHE 0x2 - -/* cl_device_local_mem_type */ -#define CL_LOCAL 0x1 -#define CL_GLOBAL 0x2 - -/* cl_device_exec_capabilities - bitfield */ -#define CL_EXEC_KERNEL (1 << 0) -#define CL_EXEC_NATIVE_KERNEL (1 << 1) - -/* cl_command_queue_properties - bitfield */ -#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) -#define CL_QUEUE_PROFILING_ENABLE (1 << 1) - -/* cl_context_info */ -#define CL_CONTEXT_REFERENCE_COUNT 0x1080 -#define CL_CONTEXT_DEVICES 0x1081 -#define CL_CONTEXT_PROPERTIES 0x1082 -#define CL_CONTEXT_NUM_DEVICES 0x1083 - -/* cl_context_info + cl_context_properties */ -#define CL_CONTEXT_PLATFORM 0x1084 -#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 - -/* cl_device_partition_property */ -#define CL_DEVICE_PARTITION_EQUALLY 0x1086 -#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 -#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 - -/* cl_device_affinity_domain */ -#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) -#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) -#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) -#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) -#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) -#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) - -/* cl_command_queue_info */ -#define CL_QUEUE_CONTEXT 0x1090 -#define CL_QUEUE_DEVICE 0x1091 -#define CL_QUEUE_REFERENCE_COUNT 0x1092 -#define CL_QUEUE_PROPERTIES 0x1093 - -/* cl_mem_flags - bitfield */ -#define CL_MEM_READ_WRITE (1 << 0) -#define CL_MEM_WRITE_ONLY (1 << 1) -#define CL_MEM_READ_ONLY (1 << 2) -#define CL_MEM_USE_HOST_PTR (1 << 3) -#define CL_MEM_ALLOC_HOST_PTR (1 << 4) -#define CL_MEM_COPY_HOST_PTR (1 << 5) -// reserved (1 << 6) -#define CL_MEM_HOST_WRITE_ONLY (1 << 7) -#define CL_MEM_HOST_READ_ONLY (1 << 8) -#define CL_MEM_HOST_NO_ACCESS (1 << 9) - -/* cl_mem_migration_flags - bitfield */ -#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) -#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) - -/* cl_channel_order */ -#define CL_R 0x10B0 -#define CL_A 0x10B1 -#define CL_RG 0x10B2 -#define CL_RA 0x10B3 -#define CL_RGB 0x10B4 -#define CL_RGBA 0x10B5 -#define CL_BGRA 0x10B6 -#define CL_ARGB 0x10B7 -#define CL_INTENSITY 0x10B8 -#define CL_LUMINANCE 0x10B9 -#define CL_Rx 0x10BA -#define CL_RGx 0x10BB -#define CL_RGBx 0x10BC -#define CL_DEPTH 0x10BD -#define CL_DEPTH_STENCIL 0x10BE - -/* cl_channel_type */ -#define CL_SNORM_INT8 0x10D0 -#define CL_SNORM_INT16 0x10D1 -#define CL_UNORM_INT8 0x10D2 -#define CL_UNORM_INT16 0x10D3 -#define CL_UNORM_SHORT_565 0x10D4 -#define CL_UNORM_SHORT_555 0x10D5 -#define CL_UNORM_INT_101010 0x10D6 -#define CL_SIGNED_INT8 0x10D7 -#define CL_SIGNED_INT16 0x10D8 -#define CL_SIGNED_INT32 0x10D9 -#define CL_UNSIGNED_INT8 0x10DA -#define CL_UNSIGNED_INT16 0x10DB -#define CL_UNSIGNED_INT32 0x10DC -#define CL_HALF_FLOAT 0x10DD -#define CL_FLOAT 0x10DE -#define CL_UNORM_INT24 0x10DF - -/* cl_mem_object_type */ -#define CL_MEM_OBJECT_BUFFER 0x10F0 -#define CL_MEM_OBJECT_IMAGE2D 0x10F1 -#define CL_MEM_OBJECT_IMAGE3D 0x10F2 -#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 -#define CL_MEM_OBJECT_IMAGE1D 0x10F4 -#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 -#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 - -/* cl_mem_info */ -#define CL_MEM_TYPE 0x1100 -#define CL_MEM_FLAGS 0x1101 -#define CL_MEM_SIZE 0x1102 -#define CL_MEM_HOST_PTR 0x1103 -#define CL_MEM_MAP_COUNT 0x1104 -#define CL_MEM_REFERENCE_COUNT 0x1105 -#define CL_MEM_CONTEXT 0x1106 -#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 -#define CL_MEM_OFFSET 0x1108 - -/* cl_image_info */ -#define CL_IMAGE_FORMAT 0x1110 -#define CL_IMAGE_ELEMENT_SIZE 0x1111 -#define CL_IMAGE_ROW_PITCH 0x1112 -#define CL_IMAGE_SLICE_PITCH 0x1113 -#define CL_IMAGE_WIDTH 0x1114 -#define CL_IMAGE_HEIGHT 0x1115 -#define CL_IMAGE_DEPTH 0x1116 -#define CL_IMAGE_ARRAY_SIZE 0x1117 -#define CL_IMAGE_BUFFER 0x1118 -#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 -#define CL_IMAGE_NUM_SAMPLES 0x111A - -/* cl_addressing_mode */ -#define CL_ADDRESS_NONE 0x1130 -#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 -#define CL_ADDRESS_CLAMP 0x1132 -#define CL_ADDRESS_REPEAT 0x1133 -#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 - -/* cl_filter_mode */ -#define CL_FILTER_NEAREST 0x1140 -#define CL_FILTER_LINEAR 0x1141 - -/* cl_sampler_info */ -#define CL_SAMPLER_REFERENCE_COUNT 0x1150 -#define CL_SAMPLER_CONTEXT 0x1151 -#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 -#define CL_SAMPLER_ADDRESSING_MODE 0x1153 -#define CL_SAMPLER_FILTER_MODE 0x1154 - -/* cl_map_flags - bitfield */ -#define CL_MAP_READ (1 << 0) -#define CL_MAP_WRITE (1 << 1) -#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) - -/* cl_program_info */ -#define CL_PROGRAM_REFERENCE_COUNT 0x1160 -#define CL_PROGRAM_CONTEXT 0x1161 -#define CL_PROGRAM_NUM_DEVICES 0x1162 -#define CL_PROGRAM_DEVICES 0x1163 -#define CL_PROGRAM_SOURCE 0x1164 -#define CL_PROGRAM_BINARY_SIZES 0x1165 -#define CL_PROGRAM_BINARIES 0x1166 -#define CL_PROGRAM_NUM_KERNELS 0x1167 -#define CL_PROGRAM_KERNEL_NAMES 0x1168 - -/* cl_program_build_info */ -#define CL_PROGRAM_BUILD_STATUS 0x1181 -#define CL_PROGRAM_BUILD_OPTIONS 0x1182 -#define CL_PROGRAM_BUILD_LOG 0x1183 -#define CL_PROGRAM_BINARY_TYPE 0x1184 - -/* cl_build_status */ -#define CL_BUILD_SUCCESS 0 -#define CL_BUILD_NONE -1 -#define CL_BUILD_ERROR -2 -#define CL_BUILD_IN_PROGRESS -3 - -/* cl_kernel_info */ -#define CL_KERNEL_FUNCTION_NAME 0x1190 -#define CL_KERNEL_NUM_ARGS 0x1191 -#define CL_KERNEL_REFERENCE_COUNT 0x1192 -#define CL_KERNEL_CONTEXT 0x1193 -#define CL_KERNEL_PROGRAM 0x1194 -#define CL_KERNEL_ATTRIBUTES 0x1195 - -/* cl_kernel_arg_info */ -#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 -#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 -#define CL_KERNEL_ARG_TYPE_NAME 0x1198 -#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 -#define CL_KERNEL_ARG_NAME 0x119A - -/* cl_kernel_arg_address_qualifier */ -#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B -#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C -#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D -#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E - -/* cl_kernel_arg_access_qualifier */ -#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 -#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 -#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 -#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 - -/* cl_kernel_arg_type_qualifer */ -#define CL_KERNEL_ARG_TYPE_NONE 0 -#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) -#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) -#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) - -/* cl_kernel_work_group_info */ -#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 -#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 -#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 -#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 -#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 -#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 - -/* cl_event_info */ -#define CL_EVENT_COMMAND_QUEUE 0x11D0 -#define CL_EVENT_COMMAND_TYPE 0x11D1 -#define CL_EVENT_REFERENCE_COUNT 0x11D2 -#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 -#define CL_EVENT_CONTEXT 0x11D4 - -/* cl_command_type */ -#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 -#define CL_COMMAND_TASK 0x11F1 -#define CL_COMMAND_NATIVE_KERNEL 0x11F2 -#define CL_COMMAND_READ_BUFFER 0x11F3 -#define CL_COMMAND_WRITE_BUFFER 0x11F4 -#define CL_COMMAND_COPY_BUFFER 0x11F5 -#define CL_COMMAND_READ_IMAGE 0x11F6 -#define CL_COMMAND_WRITE_IMAGE 0x11F7 -#define CL_COMMAND_COPY_IMAGE 0x11F8 -#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 -#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA -#define CL_COMMAND_MAP_BUFFER 0x11FB -#define CL_COMMAND_MAP_IMAGE 0x11FC -#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD -#define CL_COMMAND_MARKER 0x11FE -#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF -#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 -#define CL_COMMAND_READ_BUFFER_RECT 0x1201 -#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 -#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 -#define CL_COMMAND_USER 0x1204 -#define CL_COMMAND_BARRIER 0x1205 -#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 -#define CL_COMMAND_FILL_BUFFER 0x1207 -#define CL_COMMAND_FILL_IMAGE 0x1208 - -/* command execution status */ -#define CL_COMPLETE 0x0 -#define CL_RUNNING 0x1 -#define CL_SUBMITTED 0x2 -#define CL_QUEUED 0x3 - -/* cl_buffer_create_type */ -#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 - -/* cl_profiling_info */ -#define CL_PROFILING_COMMAND_QUEUED 0x1280 -#define CL_PROFILING_COMMAND_SUBMIT 0x1281 -#define CL_PROFILING_COMMAND_START 0x1282 -#define CL_PROFILING_COMMAND_END 0x1283 - -/********************************************************************************************************/ - -/********************************************************************************************************/ - -/* Function signature typedef's */ - -#ifdef __APPLE__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wignored-attributes" -#endif - -/* Platform API */ -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETPLATFORMIDS)(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETPLATFORMINFO)(cl_platform_id /* platform */, - cl_platform_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Device APIs */ -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETDEVICEIDS)(cl_platform_id /* platform */, - cl_device_type /* device_type */, - cl_uint /* num_entries */, - cl_device_id * /* devices */, - cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETDEVICEINFO)(cl_device_id /* device */, - cl_device_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLCREATESUBDEVICES)(cl_device_id /* in_device */, - const cl_device_partition_property * /* properties */, - cl_uint /* num_devices */, - cl_device_id * /* out_devices */, - cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINDEVICE)(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASEDEVICE)(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -// Context APIs -typedef CL_API_ENTRY cl_context (CL_API_CALL * -PFNCLCREATECONTEXT)(const cl_context_properties * /* properties */, - cl_uint /* num_devices */, - const cl_device_id * /* devices */, - void (CL_CALLBACK * /* pfn_notify */)(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_context (CL_API_CALL * -PFNCLCREATECONTEXTFROMTYPE)(const cl_context_properties * /* properties */, - cl_device_type /* device_type */, - void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINCONTEXT)(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASECONTEXT)(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETCONTEXTINFO)(cl_context /* context */, - cl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Command Queue APIs */ -typedef CL_API_ENTRY cl_command_queue (CL_API_CALL * -PFNCLCREATECOMMANDQUEUE)(cl_context /* context */, - cl_device_id /* device */, - cl_command_queue_properties /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINCOMMANDQUEUE)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASECOMMANDQUEUE)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETCOMMANDQUEUEINFO)(cl_command_queue /* command_queue */, - cl_command_queue_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLSETCOMMANDQUEUEPROPERTY)(cl_command_queue /* command_queue */, - cl_command_queue_properties /* properties */, - cl_bool /* enable */, - cl_command_queue_properties * /* old_properties */) CL_API_SUFFIX__VERSION_1_0; - -/* Memory Object APIs */ -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -PFNCLCREATEBUFFER)(cl_context /* context */, - cl_mem_flags /* flags */, - size_t /* size */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -PFNCLCREATESUBBUFFER)(cl_mem /* buffer */, - cl_mem_flags /* flags */, - cl_buffer_create_type /* buffer_create_type */, - const void * /* buffer_create_info */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -PFNCLCREATEIMAGE)(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - const cl_image_desc * /* image_desc */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINMEMOBJECT)(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASEMEMOBJECT)(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETSUPPORTEDIMAGEFORMATS)(cl_context /* context */, - cl_mem_flags /* flags */, - cl_mem_object_type /* image_type */, - cl_uint /* num_entries */, - cl_image_format * /* image_formats */, - cl_uint * /* num_image_formats */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETMEMOBJECTINFO)(cl_mem /* memobj */, - cl_mem_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETIMAGEINFO)(cl_mem /* image */, - cl_image_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLSETMEMOBJECTDESTRUCTORCALLBACK)( cl_mem /* memobj */, - void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; - -/* Sampler APIs */ -typedef CL_API_ENTRY cl_sampler (CL_API_CALL * -PFNCLCREATESAMPLER)(cl_context /* context */, - cl_bool /* normalized_coords */, - cl_addressing_mode /* addressing_mode */, - cl_filter_mode /* filter_mode */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINSAMPLER)(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASESAMPLER)(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETSAMPLERINFO)(cl_sampler /* sampler */, - cl_sampler_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Program Object APIs */ -typedef CL_API_ENTRY cl_program (CL_API_CALL * -PFNCLCREATEPROGRAMWITHSOURCE)(cl_context /* context */, - cl_uint /* count */, - const char ** /* strings */, - const size_t * /* lengths */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_program (CL_API_CALL * -PFNCLCREATEPROGRAMWITHBINARY)(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const size_t * /* lengths */, - const unsigned char ** /* binaries */, - cl_int * /* binary_status */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_program (CL_API_CALL * -PFNCLCREATEPROGRAMWITHBUILTINKERNELS)(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* kernel_names */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINPROGRAM)(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASEPROGRAM)(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLBUILDPROGRAM)(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETPROGRAMINFO)(cl_program /* program */, - cl_program_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETPROGRAMBUILDINFO)(cl_program /* program */, - cl_device_id /* device */, - cl_program_build_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Kernel Object APIs */ -typedef CL_API_ENTRY cl_kernel (CL_API_CALL * -PFNCLCREATEKERNEL)(cl_program /* program */, - const char * /* kernel_name */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLCREATEKERNELSINPROGRAM)(cl_program /* program */, - cl_uint /* num_kernels */, - cl_kernel * /* kernels */, - cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINKERNEL)(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASEKERNEL)(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLSETKERNELARG)(cl_kernel /* kernel */, - cl_uint /* arg_index */, - size_t /* arg_size */, - const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETKERNELINFO)(cl_kernel /* kernel */, - cl_kernel_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETKERNELWORKGROUPINFO)(cl_kernel /* kernel */, - cl_device_id /* device */, - cl_kernel_work_group_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -// Event Object APIs -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLWAITFOREVENTS)(cl_uint /* num_events */, - const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETEVENTINFO)(cl_event /* event */, - cl_event_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_event (CL_API_CALL * -PFNCLCREATEUSEREVENT)(cl_context /* context */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRETAINEVENT)(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLRELEASEEVENT)(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLSETUSEREVENTSTATUS)(cl_event /* event */, - cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLSETEVENTCALLBACK)( cl_event /* event */, - cl_int /* command_exec_callback_type */, - void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; - -/* Profiling APIs */ -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETEVENTPROFILINGINFO)(cl_event /* event */, - cl_profiling_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -// Flush and Finish APIs -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLFLUSH)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLFINISH)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -/* Enqueued Commands APIs */ -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEREADBUFFER)(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - size_t /* offset */, - size_t /* cb */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEREADBUFFERRECT)(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - const size_t * /* buffer_origin */, - const size_t * /* host_origin */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEWRITEBUFFER)(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - size_t /* offset */, - size_t /* cb */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEWRITEBUFFERRECT)(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - const size_t * /* buffer_origin */, - const size_t * /* host_origin */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUECOPYBUFFER)(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - size_t /* src_offset */, - size_t /* dst_offset */, - size_t /* cb */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUECOPYBUFFERRECT)(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin */, - const size_t * /* dst_origin */, - const size_t * /* region */, - size_t /* src_row_pitch */, - size_t /* src_slice_pitch */, - size_t /* dst_row_pitch */, - size_t /* dst_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEREADIMAGE)(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_read */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* row_pitch */, - size_t /* slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEWRITEIMAGE)(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_write */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* input_row_pitch */, - size_t /* input_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUECOPYIMAGE)(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_image */, - const size_t * /* src_origin[3] */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUECOPYIMAGETOBUFFER)(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin[3] */, - const size_t * /* region[3] */, - size_t /* dst_offset */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUECOPYBUFFERTOIMAGE)(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_image */, - size_t /* src_offset */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY void * (CL_API_CALL * -PFNCLENQUEUEMAPBUFFER)(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - size_t /* offset */, - size_t /* cb */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY void * (CL_API_CALL * -PFNCLENQUEUEMAPIMAGE)(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t * /* image_row_pitch */, - size_t * /* image_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEUNMAPMEMOBJECT)(cl_command_queue /* command_queue */, - cl_mem /* memobj */, - void * /* mapped_ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUENDRANGEKERNEL)(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* work_dim */, - const size_t * /* global_work_offset */, - const size_t * /* global_work_size */, - const size_t * /* local_work_size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUETASK)(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUENATIVEKERNEL)(cl_command_queue /* command_queue */, - void (*user_func)(void *), - void * /* args */, - size_t /* cb_args */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_list */, - const void ** /* args_mem_loc */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -/* Extension function access -* -* Returns the extension function address for the given function name, -* or NULL if a valid function can not be found. The client must -* check to make sure the address is not NULL, before using or -* calling the returned function address. -*/ -typedef CL_API_ENTRY void * (CL_API_CALL * -PFNCLGETEXTENSIONFUNCTIONADDRESSFORPLATFORM)(cl_platform_id /* platform */, - const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -// Deprecated OpenCL 1.1 APIs -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem (CL_API_CALL * -PFNCLCREATEIMAGE2D)(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_row_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem (CL_API_CALL * -PFNCLCREATEIMAGE3D)(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_depth */, - size_t /* image_row_pitch */, - size_t /* image_slice_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int (CL_API_CALL * -PFNCLENQUEUEMARKER)(cl_command_queue /* command_queue */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int (CL_API_CALL * -PFNCLENQUEUEWAITFOREVENTS)(cl_command_queue /* command_queue */, - cl_uint /* num_events */, - const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int (CL_API_CALL * -PFNCLENQUEUEBARRIER)(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int (CL_API_CALL * -PFNCLUNLOADCOMPILER)(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * (CL_API_CALL * -PFNCLGETEXTENSIONFUNCTIONADDRESS)(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -#endif - - -/* cl_gl */ - -typedef cl_uint cl_gl_object_type; -typedef cl_uint cl_gl_texture_info; -typedef cl_uint cl_gl_platform_info; -typedef struct __GLsync *cl_GLsync; - -/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ -#define CL_GL_OBJECT_BUFFER 0x2000 -#define CL_GL_OBJECT_TEXTURE2D 0x2001 -#define CL_GL_OBJECT_TEXTURE3D 0x2002 -#define CL_GL_OBJECT_RENDERBUFFER 0x2003 -#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E -#define CL_GL_OBJECT_TEXTURE1D 0x200F -#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 -#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 - -/* cl_gl_texture_info */ -#define CL_GL_TEXTURE_TARGET 0x2004 -#define CL_GL_MIPMAP_LEVEL 0x2005 -#define CL_GL_NUM_SAMPLES 0x2012 - - -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -PFNCLCREATEFROMGLBUFFER)(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* bufobj */, - int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -PFNCLCREATEFROMGLTEXTURE)(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL * -PFNCLCREATEFROMGLRENDERBUFFER)(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* renderbuffer */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETGLOBJECTINFO)(cl_mem /* memobj */, - cl_gl_object_type * /* gl_object_type */, - cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETGLTEXTUREINFO)(cl_mem /* memobj */, - cl_gl_texture_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUEACQUIREGLOBJECTS)(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLENQUEUERELEASEGLOBJECTS)(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - - -// Deprecated OpenCL 1.1 APIs -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem (CL_API_CALL * -PFNCLCREATEFROMGLTEXTURE2D)(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -typedef CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem (CL_API_CALL * -PFNCLCREATEFROMGLTEXTURE3D)(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -#endif - -#ifdef __APPLE__ -# pragma GCC diagnostic pop // ignored "-Wignored-attributes" -#endif - -/* cl_khr_gl_sharing extension */ - -#define cl_khr_gl_sharing 1 - -typedef cl_uint cl_gl_context_info; - -/* Additional Error Codes */ -#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 - -/* cl_gl_context_info */ -#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 -#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 - -/* Additional cl_context_properties */ -#define CL_GL_CONTEXT_KHR 0x2008 -#define CL_EGL_DISPLAY_KHR 0x2009 -#define CL_GLX_DISPLAY_KHR 0x200A -#define CL_WGL_HDC_KHR 0x200B -#define CL_CGL_SHAREGROUP_KHR 0x200C - -typedef CL_API_ENTRY cl_int (CL_API_CALL * -PFNCLGETGLCONTEXTINFOKHR)(const cl_context_properties * /* properties */, - cl_gl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( - const cl_context_properties * properties, - cl_gl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret); - -#define CLEW_STATIC - -#ifdef CLEW_STATIC -# define CLEWAPI extern -#else -# ifdef CLEW_BUILD -# define CLEWAPI extern __declspec(dllexport) -# else -# define CLEWAPI extern __declspec(dllimport) -# endif -#endif - -#if defined(_WIN32) -#define CLEW_FUN_EXPORT extern -#else -#define CLEW_FUN_EXPORT CLEWAPI -#endif - -#define CLEW_GET_FUN(x) x - - -// Variables holding function entry points -CLEW_FUN_EXPORT PFNCLGETPLATFORMIDS __clewGetPlatformIDs ; -CLEW_FUN_EXPORT PFNCLGETPLATFORMINFO __clewGetPlatformInfo ; -CLEW_FUN_EXPORT PFNCLGETDEVICEIDS __clewGetDeviceIDs ; -CLEW_FUN_EXPORT PFNCLGETDEVICEINFO __clewGetDeviceInfo ; -CLEW_FUN_EXPORT PFNCLCREATESUBDEVICES __clewCreateSubDevices ; -CLEW_FUN_EXPORT PFNCLRETAINDEVICE __clewRetainDevice ; -CLEW_FUN_EXPORT PFNCLRELEASEDEVICE __clewReleaseDevice ; -CLEW_FUN_EXPORT PFNCLCREATECONTEXT __clewCreateContext ; -CLEW_FUN_EXPORT PFNCLCREATECONTEXTFROMTYPE __clewCreateContextFromType ; -CLEW_FUN_EXPORT PFNCLRETAINCONTEXT __clewRetainContext ; -CLEW_FUN_EXPORT PFNCLRELEASECONTEXT __clewReleaseContext ; -CLEW_FUN_EXPORT PFNCLGETCONTEXTINFO __clewGetContextInfo ; -CLEW_FUN_EXPORT PFNCLCREATECOMMANDQUEUE __clewCreateCommandQueue ; -CLEW_FUN_EXPORT PFNCLRETAINCOMMANDQUEUE __clewRetainCommandQueue ; -CLEW_FUN_EXPORT PFNCLRELEASECOMMANDQUEUE __clewReleaseCommandQueue ; -CLEW_FUN_EXPORT PFNCLGETCOMMANDQUEUEINFO __clewGetCommandQueueInfo ; -CLEW_FUN_EXPORT PFNCLCREATEBUFFER __clewCreateBuffer ; -CLEW_FUN_EXPORT PFNCLCREATESUBBUFFER __clewCreateSubBuffer ; -CLEW_FUN_EXPORT PFNCLCREATEIMAGE __clewCreateImage ; -CLEW_FUN_EXPORT PFNCLRETAINMEMOBJECT __clewRetainMemObject ; -CLEW_FUN_EXPORT PFNCLRELEASEMEMOBJECT __clewReleaseMemObject ; -CLEW_FUN_EXPORT PFNCLGETSUPPORTEDIMAGEFORMATS __clewGetSupportedImageFormats ; -CLEW_FUN_EXPORT PFNCLGETMEMOBJECTINFO __clewGetMemObjectInfo ; -CLEW_FUN_EXPORT PFNCLGETIMAGEINFO __clewGetImageInfo ; -CLEW_FUN_EXPORT PFNCLSETMEMOBJECTDESTRUCTORCALLBACK __clewSetMemObjectDestructorCallback; -CLEW_FUN_EXPORT PFNCLCREATESAMPLER __clewCreateSampler ; -CLEW_FUN_EXPORT PFNCLRETAINSAMPLER __clewRetainSampler ; -CLEW_FUN_EXPORT PFNCLRELEASESAMPLER __clewReleaseSampler ; -CLEW_FUN_EXPORT PFNCLGETSAMPLERINFO __clewGetSamplerInfo ; -CLEW_FUN_EXPORT PFNCLCREATEPROGRAMWITHSOURCE __clewCreateProgramWithSource ; -CLEW_FUN_EXPORT PFNCLCREATEPROGRAMWITHBINARY __clewCreateProgramWithBinary ; -CLEW_FUN_EXPORT PFNCLCREATEPROGRAMWITHBUILTINKERNELS __clewCreateProgramWithBuiltInKernels; -CLEW_FUN_EXPORT PFNCLRETAINPROGRAM __clewRetainProgram ; -CLEW_FUN_EXPORT PFNCLRELEASEPROGRAM __clewReleaseProgram ; -CLEW_FUN_EXPORT PFNCLBUILDPROGRAM __clewBuildProgram ; -CLEW_FUN_EXPORT PFNCLGETPROGRAMINFO __clewGetProgramInfo ; -CLEW_FUN_EXPORT PFNCLGETPROGRAMBUILDINFO __clewGetProgramBuildInfo ; -CLEW_FUN_EXPORT PFNCLCREATEKERNEL __clewCreateKernel ; -CLEW_FUN_EXPORT PFNCLCREATEKERNELSINPROGRAM __clewCreateKernelsInProgram ; -CLEW_FUN_EXPORT PFNCLRETAINKERNEL __clewRetainKernel ; -CLEW_FUN_EXPORT PFNCLRELEASEKERNEL __clewReleaseKernel ; -CLEW_FUN_EXPORT PFNCLSETKERNELARG __clewSetKernelArg ; -CLEW_FUN_EXPORT PFNCLGETKERNELINFO __clewGetKernelInfo ; -CLEW_FUN_EXPORT PFNCLGETKERNELWORKGROUPINFO __clewGetKernelWorkGroupInfo ; -CLEW_FUN_EXPORT PFNCLWAITFOREVENTS __clewWaitForEvents ; -CLEW_FUN_EXPORT PFNCLGETEVENTINFO __clewGetEventInfo ; -CLEW_FUN_EXPORT PFNCLCREATEUSEREVENT __clewCreateUserEvent ; -CLEW_FUN_EXPORT PFNCLRETAINEVENT __clewRetainEvent ; -CLEW_FUN_EXPORT PFNCLRELEASEEVENT __clewReleaseEvent ; -CLEW_FUN_EXPORT PFNCLSETUSEREVENTSTATUS __clewSetUserEventStatus ; -CLEW_FUN_EXPORT PFNCLSETEVENTCALLBACK __clewSetEventCallback ; -CLEW_FUN_EXPORT PFNCLGETEVENTPROFILINGINFO __clewGetEventProfilingInfo ; -CLEW_FUN_EXPORT PFNCLFLUSH __clewFlush ; -CLEW_FUN_EXPORT PFNCLFINISH __clewFinish ; -CLEW_FUN_EXPORT PFNCLENQUEUEREADBUFFER __clewEnqueueReadBuffer ; -CLEW_FUN_EXPORT PFNCLENQUEUEREADBUFFERRECT __clewEnqueueReadBufferRect ; -CLEW_FUN_EXPORT PFNCLENQUEUEWRITEBUFFER __clewEnqueueWriteBuffer ; -CLEW_FUN_EXPORT PFNCLENQUEUEWRITEBUFFERRECT __clewEnqueueWriteBufferRect ; -CLEW_FUN_EXPORT PFNCLENQUEUECOPYBUFFER __clewEnqueueCopyBuffer ; -CLEW_FUN_EXPORT PFNCLENQUEUECOPYBUFFERRECT __clewEnqueueCopyBufferRect ; -CLEW_FUN_EXPORT PFNCLENQUEUEREADIMAGE __clewEnqueueReadImage ; -CLEW_FUN_EXPORT PFNCLENQUEUEWRITEIMAGE __clewEnqueueWriteImage ; -CLEW_FUN_EXPORT PFNCLENQUEUECOPYIMAGE __clewEnqueueCopyImage ; -CLEW_FUN_EXPORT PFNCLENQUEUECOPYIMAGETOBUFFER __clewEnqueueCopyImageToBuffer ; -CLEW_FUN_EXPORT PFNCLENQUEUECOPYBUFFERTOIMAGE __clewEnqueueCopyBufferToImage ; -CLEW_FUN_EXPORT PFNCLENQUEUEMAPBUFFER __clewEnqueueMapBuffer ; -CLEW_FUN_EXPORT PFNCLENQUEUEMAPIMAGE __clewEnqueueMapImage ; -CLEW_FUN_EXPORT PFNCLENQUEUEUNMAPMEMOBJECT __clewEnqueueUnmapMemObject ; -CLEW_FUN_EXPORT PFNCLENQUEUENDRANGEKERNEL __clewEnqueueNDRangeKernel ; -CLEW_FUN_EXPORT PFNCLENQUEUETASK __clewEnqueueTask ; -CLEW_FUN_EXPORT PFNCLENQUEUENATIVEKERNEL __clewEnqueueNativeKernel ; -CLEW_FUN_EXPORT PFNCLGETEXTENSIONFUNCTIONADDRESSFORPLATFORM __clewGetExtensionFunctionAddressForPlatform; - -#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS -CLEW_FUN_EXPORT PFNCLSETCOMMANDQUEUEPROPERTY __clewSetCommandQueueProperty ; -#endif - -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -CLEW_FUN_EXPORT PFNCLCREATEIMAGE2D __clewCreateImage2D ; -CLEW_FUN_EXPORT PFNCLCREATEIMAGE3D __clewCreateImage3D ; -CLEW_FUN_EXPORT PFNCLGETEXTENSIONFUNCTIONADDRESS __clewGetExtensionFunctionAddress ; -CLEW_FUN_EXPORT PFNCLUNLOADCOMPILER __clewUnloadCompiler ; -CLEW_FUN_EXPORT PFNCLENQUEUEMARKER __clewEnqueueMarker ; -CLEW_FUN_EXPORT PFNCLENQUEUEWAITFOREVENTS __clewEnqueueWaitForEvents ; -CLEW_FUN_EXPORT PFNCLENQUEUEBARRIER __clewEnqueueBarrier ; -#endif - -/* cl_gl */ -CLEW_FUN_EXPORT PFNCLCREATEFROMGLBUFFER __clewCreateFromGLBuffer ; -CLEW_FUN_EXPORT PFNCLCREATEFROMGLTEXTURE __clewCreateFromGLTexture ; -CLEW_FUN_EXPORT PFNCLCREATEFROMGLRENDERBUFFER __clewCreateFromGLRenderbuffer ; -CLEW_FUN_EXPORT PFNCLGETGLOBJECTINFO __clewGetGLObjectInfo ; -CLEW_FUN_EXPORT PFNCLGETGLTEXTUREINFO __clewGetGLTextureInfo ; -CLEW_FUN_EXPORT PFNCLENQUEUEACQUIREGLOBJECTS __clewEnqueueAcquireGLObjects ; -CLEW_FUN_EXPORT PFNCLENQUEUERELEASEGLOBJECTS __clewEnqueueReleaseGLObjects ; -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -CLEW_FUN_EXPORT PFNCLCREATEFROMGLTEXTURE2D __clewCreateFromGLTexture2D ; -CLEW_FUN_EXPORT PFNCLCREATEFROMGLTEXTURE3D __clewCreateFromGLTexture3D ; -#endif -CLEW_FUN_EXPORT PFNCLGETGLCONTEXTINFOKHR __clewGetGLContextInfoKHR ; - -#define clGetPlatformIDs CLEW_GET_FUN(__clewGetPlatformIDs ) -#define clGetPlatformInfo CLEW_GET_FUN(__clewGetPlatformInfo ) -#define clGetDeviceIDs CLEW_GET_FUN(__clewGetDeviceIDs ) -#define clGetDeviceInfo CLEW_GET_FUN(__clewGetDeviceInfo ) -#define clCreateContext CLEW_GET_FUN(__clewCreateContext ) -#define clCreateContextFromType CLEW_GET_FUN(__clewCreateContextFromType ) -#define clRetainContext CLEW_GET_FUN(__clewRetainContext ) -#define clReleaseContext CLEW_GET_FUN(__clewReleaseContext ) -#define clGetContextInfo CLEW_GET_FUN(__clewGetContextInfo ) -#define clCreateCommandQueue CLEW_GET_FUN(__clewCreateCommandQueue ) -#define clRetainCommandQueue CLEW_GET_FUN(__clewRetainCommandQueue ) -#define clReleaseCommandQueue CLEW_GET_FUN(__clewReleaseCommandQueue ) -#define clGetCommandQueueInfo CLEW_GET_FUN(__clewGetCommandQueueInfo ) -#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS -#warning CL_USE_DEPRECATED_OPENCL_1_0_APIS is defined. These APIs are unsupported and untested in OpenCL 1.1! -/* - * WARNING: - * This API introduces mutable state into the OpenCL implementation. It has been REMOVED - * to better facilitate thread safety. The 1.0 API is not thread safe. It is not tested by the - * OpenCL 1.1 conformance test, and consequently may not work or may not work dependably. - * It is likely to be non-performant. Use of this API is not advised. Use at your own risk. - * - * Software developers previously relying on this API are instructed to set the command queue - * properties when creating the queue, instead. - */ -#define clSetCommandQueueProperty CLEW_GET_FUN(__clewSetCommandQueueProperty ) -#endif /* CL_USE_DEPRECATED_OPENCL_1_0_APIS */ -#define clCreateBuffer CLEW_GET_FUN(__clewCreateBuffer ) -#define clCreateSubBuffer CLEW_GET_FUN(__clewCreateSubBuffer ) -#define clCreateImage CLEW_GET_FUN(__clewCreateImage ) -#define clRetainMemObject CLEW_GET_FUN(__clewRetainMemObject ) -#define clReleaseMemObject CLEW_GET_FUN(__clewReleaseMemObject ) -#define clGetSupportedImageFormats CLEW_GET_FUN(__clewGetSupportedImageFormats ) -#define clGetMemObjectInfo CLEW_GET_FUN(__clewGetMemObjectInfo ) -#define clGetImageInfo CLEW_GET_FUN(__clewGetImageInfo ) -#define clSetMemObjectDestructorCallback CLEW_GET_FUN(__clewSetMemObjectDestructorCallback) -#define clCreateSampler CLEW_GET_FUN(__clewCreateSampler ) -#define clRetainSampler CLEW_GET_FUN(__clewRetainSampler ) -#define clReleaseSampler CLEW_GET_FUN(__clewReleaseSampler ) -#define clGetSamplerInfo CLEW_GET_FUN(__clewGetSamplerInfo ) -#define clCreateProgramWithSource CLEW_GET_FUN(__clewCreateProgramWithSource ) -#define clCreateProgramWithBinary CLEW_GET_FUN(__clewCreateProgramWithBinary ) -#define clCreateProgramWithBuiltInKernels CLEW_GET_FUN(__clewCreateProgramWithBuiltInKernels) -#define clRetainProgram CLEW_GET_FUN(__clewRetainProgram ) -#define clReleaseProgram CLEW_GET_FUN(__clewReleaseProgram ) -#define clBuildProgram CLEW_GET_FUN(__clewBuildProgram ) -#define clGetProgramInfo CLEW_GET_FUN(__clewGetProgramInfo ) -#define clGetProgramBuildInfo CLEW_GET_FUN(__clewGetProgramBuildInfo ) -#define clCreateKernel CLEW_GET_FUN(__clewCreateKernel ) -#define clCreateKernelsInProgram CLEW_GET_FUN(__clewCreateKernelsInProgram ) -#define clRetainKernel CLEW_GET_FUN(__clewRetainKernel ) -#define clReleaseKernel CLEW_GET_FUN(__clewReleaseKernel ) -#define clSetKernelArg CLEW_GET_FUN(__clewSetKernelArg ) -#define clGetKernelInfo CLEW_GET_FUN(__clewGetKernelInfo ) -#define clGetKernelWorkGroupInfo CLEW_GET_FUN(__clewGetKernelWorkGroupInfo ) -#define clWaitForEvents CLEW_GET_FUN(__clewWaitForEvents ) -#define clGetEventInfo CLEW_GET_FUN(__clewGetEventInfo ) -#define clCreateUserEvent CLEW_GET_FUN(__clewCreateUserEvent ) -#define clRetainEvent CLEW_GET_FUN(__clewRetainEvent ) -#define clReleaseEvent CLEW_GET_FUN(__clewReleaseEvent ) -#define clSetUserEventStatus CLEW_GET_FUN(__clewSetUserEventStatus ) -#define clSetEventCallback CLEW_GET_FUN(__clewSetEventCallback ) -#define clGetEventProfilingInfo CLEW_GET_FUN(__clewGetEventProfilingInfo ) -#define clFlush CLEW_GET_FUN(__clewFlush ) -#define clFinish CLEW_GET_FUN(__clewFinish ) -#define clEnqueueReadBuffer CLEW_GET_FUN(__clewEnqueueReadBuffer ) -#define clEnqueueReadBufferRect CLEW_GET_FUN(__clewEnqueueReadBufferRect ) -#define clEnqueueWriteBuffer CLEW_GET_FUN(__clewEnqueueWriteBuffer ) -#define clEnqueueWriteBufferRect CLEW_GET_FUN(__clewEnqueueWriteBufferRect ) -#define clEnqueueCopyBuffer CLEW_GET_FUN(__clewEnqueueCopyBuffer ) -#define clEnqueueCopyBufferRect CLEW_GET_FUN(__clewEnqueueCopyBufferRect ) -#define clEnqueueReadImage CLEW_GET_FUN(__clewEnqueueReadImage ) -#define clEnqueueWriteImage CLEW_GET_FUN(__clewEnqueueWriteImage ) -#define clEnqueueCopyImage CLEW_GET_FUN(__clewEnqueueCopyImage ) -#define clEnqueueCopyImageToBuffer CLEW_GET_FUN(__clewEnqueueCopyImageToBuffer ) -#define clEnqueueCopyBufferToImage CLEW_GET_FUN(__clewEnqueueCopyBufferToImage ) -#define clEnqueueMapBuffer CLEW_GET_FUN(__clewEnqueueMapBuffer ) -#define clEnqueueMapImage CLEW_GET_FUN(__clewEnqueueMapImage ) -#define clEnqueueUnmapMemObject CLEW_GET_FUN(__clewEnqueueUnmapMemObject ) -#define clEnqueueNDRangeKernel CLEW_GET_FUN(__clewEnqueueNDRangeKernel ) -#define clEnqueueTask CLEW_GET_FUN(__clewEnqueueTask ) -#define clEnqueueNativeKernel CLEW_GET_FUN(__clewEnqueueNativeKernel ) - -#define clGetExtensionFunctionAddressForPlatform CLEW_GET_FUN(__clewGetExtensionFunctionAddressForPlatform) - -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -#define clCreateImage2D CLEW_GET_FUN(__clewCreateImage2D ) -#define clCreateImage3D CLEW_GET_FUN(__clewCreateImage3D ) -#define clGetExtensionFunctionAddress CLEW_GET_FUN(__clewGetExtensionFunctionAddress ) -#define clEnqueueMarker CLEW_GET_FUN(__clewEnqueueMarker ) -#define clEnqueueWaitForEvents CLEW_GET_FUN(__clewEnqueueWaitForEvents ) -#define clEnqueueBarrier CLEW_GET_FUN(__clewEnqueueBarrier ) -#define clUnloadCompiler CLEW_GET_FUN(__clewUnloadCompiler ) -#endif - -/* cl_gl */ -#define clCreateFromGLBuffer CLEW_GET_FUN(__clewCreateFromGLBuffer ) -#define clCreateFromGLTexture CLEW_GET_FUN(__clewCreateFromGLTexture ) -#define clCreateFromGLRenderbuffer CLEW_GET_FUN(__clewCreateFromGLRenderbuffer ) -#define clGetGLObjectInfo CLEW_GET_FUN(__clewGetGLObjectInfo ) -#define clGetGLTextureInfo CLEW_GET_FUN(__clGetGLTextureInfo ) -#define clEnqueueAcquireGLObjects CLEW_GET_FUN(__clewEnqueueAcquireGLObjects ) -#define clEnqueueReleaseGLObjects CLEW_GET_FUN(__clewEnqueueReleaseGLObjects ) -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -#define clCreateFromGLTexture2D CLEW_GET_FUN(__clewCreateFromGLTexture2D ) -#define clCreateFromGLTexture3D CLEW_GET_FUN(__clewCreateFromGLTexture3D ) -#endif -#define clGetGLContextInfoKHR CLEW_GET_FUN(__clewGetGLContextInfoKHR ) - -/* cl_ext */ - -/****************************************** - * cl_nv_device_attribute_query extension * - ******************************************/ -/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ -#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 -#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 -#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 -#define CL_DEVICE_WARP_SIZE_NV 0x4003 -#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 -#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 -#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 -#define CL_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT_NV 0x4007 -#define CL_DEVICE_PCI_BUS_ID_NV 0x4008 -#define CL_DEVICE_PCI_SLOT_ID_NV 0x4009 - -/********************************* - * cl_amd_device_attribute_query * - *********************************/ -#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 -#define CL_DEVICE_TOPOLOGY_AMD 0x4037 -#define CL_DEVICE_BOARD_NAME_AMD 0x4038 -#define CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 0x4039 -#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 -#define CL_DEVICE_SIMD_WIDTH_AMD 0x4041 -#define CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 0x4042 -#define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043 -#define CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 0x4044 -#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 0x4045 -#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 0x4046 -#define CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 0x4047 -#define CL_DEVICE_LOCAL_MEM_BANKS_AMD 0x4048 -#define CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD 0x4049 -#define CL_DEVICE_GFXIP_MAJOR_AMD 0x404A -#define CL_DEVICE_GFXIP_MINOR_AMD 0x404B -#define CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD 0x404C - -#ifndef CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD -#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 - -typedef union -{ - struct { cl_uint type; cl_uint data[5]; } raw; - struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char function; } pcie; -} cl_device_topology_amd; -#endif - -/********************************* - * cl_arm_printf extension - *********************************/ -#define CL_PRINTF_CALLBACK_ARM 0x40B0 -#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 - -#define CLEW_SUCCESS 0 //!< Success error code -#define CLEW_ERROR_OPEN_FAILED -1 //!< Error code for failing to open the dynamic library -#define CLEW_ERROR_ATEXIT_FAILED -2 //!< Error code for failing to queue the closing of the dynamic library to atexit() - -//! \brief Load OpenCL dynamic library and set function entry points -int clewInit (void); -//! \brief Convert an OpenCL error code to its string equivalent -const char* clewErrorString (cl_int error); - -#ifdef __cplusplus -} -#endif - -#endif // CLEW_HPP_INCLUDED diff --git a/extern/clew/src/clew.c b/extern/clew/src/clew.c deleted file mode 100644 index dbdddfc0332..00000000000 --- a/extern/clew/src/clew.c +++ /dev/null @@ -1,407 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2009 Organic Vectory B.V. -// Written by George van Venrooij -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file license.txt) -////////////////////////////////////////////////////////////////////////// - -#include "clew.h" - -#ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #define VC_EXTRALEAN - #include - - typedef HMODULE CLEW_DYNLIB_HANDLE; - - #define CLEW_DYNLIB_OPEN LoadLibraryA - #define CLEW_DYNLIB_CLOSE FreeLibrary - #define CLEW_DYNLIB_IMPORT GetProcAddress -#else - #include - - typedef void* CLEW_DYNLIB_HANDLE; - - #define CLEW_DYNLIB_OPEN(path) dlopen(path, RTLD_NOW | RTLD_GLOBAL) - #define CLEW_DYNLIB_CLOSE dlclose - #define CLEW_DYNLIB_IMPORT dlsym -#endif - -#include - -//! \brief module handle -static CLEW_DYNLIB_HANDLE module = NULL; - -// Variables holding function entry points -PFNCLGETPLATFORMIDS __clewGetPlatformIDs = NULL; -PFNCLGETPLATFORMINFO __clewGetPlatformInfo = NULL; -PFNCLGETDEVICEIDS __clewGetDeviceIDs = NULL; -PFNCLGETDEVICEINFO __clewGetDeviceInfo = NULL; -PFNCLCREATESUBDEVICES __clewCreateSubDevices = NULL; -PFNCLRETAINDEVICE __clewRetainDevice = NULL; -PFNCLRELEASEDEVICE __clewReleaseDevice = NULL; -PFNCLCREATECONTEXT __clewCreateContext = NULL; -PFNCLCREATECONTEXTFROMTYPE __clewCreateContextFromType = NULL; -PFNCLRETAINCONTEXT __clewRetainContext = NULL; -PFNCLRELEASECONTEXT __clewReleaseContext = NULL; -PFNCLGETCONTEXTINFO __clewGetContextInfo = NULL; -PFNCLCREATECOMMANDQUEUE __clewCreateCommandQueue = NULL; -PFNCLRETAINCOMMANDQUEUE __clewRetainCommandQueue = NULL; -PFNCLRELEASECOMMANDQUEUE __clewReleaseCommandQueue = NULL; -PFNCLGETCOMMANDQUEUEINFO __clewGetCommandQueueInfo = NULL; -#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS -PFNCLSETCOMMANDQUEUEPROPERTY __clewSetCommandQueueProperty = NULL; -#endif -PFNCLCREATEBUFFER __clewCreateBuffer = NULL; -PFNCLCREATESUBBUFFER __clewCreateSubBuffer = NULL; -PFNCLCREATEIMAGE __clewCreateImage = NULL; -PFNCLRETAINMEMOBJECT __clewRetainMemObject = NULL; -PFNCLRELEASEMEMOBJECT __clewReleaseMemObject = NULL; -PFNCLGETSUPPORTEDIMAGEFORMATS __clewGetSupportedImageFormats = NULL; -PFNCLGETMEMOBJECTINFO __clewGetMemObjectInfo = NULL; -PFNCLGETIMAGEINFO __clewGetImageInfo = NULL; -PFNCLSETMEMOBJECTDESTRUCTORCALLBACK __clewSetMemObjectDestructorCallback = NULL; -PFNCLCREATESAMPLER __clewCreateSampler = NULL; -PFNCLRETAINSAMPLER __clewRetainSampler = NULL; -PFNCLRELEASESAMPLER __clewReleaseSampler = NULL; -PFNCLGETSAMPLERINFO __clewGetSamplerInfo = NULL; -PFNCLCREATEPROGRAMWITHSOURCE __clewCreateProgramWithSource = NULL; -PFNCLCREATEPROGRAMWITHBINARY __clewCreateProgramWithBinary = NULL; -PFNCLCREATEPROGRAMWITHBUILTINKERNELS __clewCreateProgramWithBuiltInKernels = NULL; -PFNCLRETAINPROGRAM __clewRetainProgram = NULL; -PFNCLRELEASEPROGRAM __clewReleaseProgram = NULL; -PFNCLBUILDPROGRAM __clewBuildProgram = NULL; -PFNCLGETPROGRAMINFO __clewGetProgramInfo = NULL; -PFNCLGETPROGRAMBUILDINFO __clewGetProgramBuildInfo = NULL; -PFNCLCREATEKERNEL __clewCreateKernel = NULL; -PFNCLCREATEKERNELSINPROGRAM __clewCreateKernelsInProgram = NULL; -PFNCLRETAINKERNEL __clewRetainKernel = NULL; -PFNCLRELEASEKERNEL __clewReleaseKernel = NULL; -PFNCLSETKERNELARG __clewSetKernelArg = NULL; -PFNCLGETKERNELINFO __clewGetKernelInfo = NULL; -PFNCLGETKERNELWORKGROUPINFO __clewGetKernelWorkGroupInfo = NULL; -PFNCLWAITFOREVENTS __clewWaitForEvents = NULL; -PFNCLGETEVENTINFO __clewGetEventInfo = NULL; -PFNCLCREATEUSEREVENT __clewCreateUserEvent = NULL; -PFNCLRETAINEVENT __clewRetainEvent = NULL; -PFNCLRELEASEEVENT __clewReleaseEvent = NULL; -PFNCLSETUSEREVENTSTATUS __clewSetUserEventStatus = NULL; -PFNCLSETEVENTCALLBACK __clewSetEventCallback = NULL; -PFNCLGETEVENTPROFILINGINFO __clewGetEventProfilingInfo = NULL; -PFNCLFLUSH __clewFlush = NULL; -PFNCLFINISH __clewFinish = NULL; -PFNCLENQUEUEREADBUFFER __clewEnqueueReadBuffer = NULL; -PFNCLENQUEUEREADBUFFERRECT __clewEnqueueReadBufferRect = NULL; -PFNCLENQUEUEWRITEBUFFER __clewEnqueueWriteBuffer = NULL; -PFNCLENQUEUEWRITEBUFFERRECT __clewEnqueueWriteBufferRect = NULL; -PFNCLENQUEUECOPYBUFFER __clewEnqueueCopyBuffer = NULL; -PFNCLENQUEUEREADIMAGE __clewEnqueueReadImage = NULL; -PFNCLENQUEUEWRITEIMAGE __clewEnqueueWriteImage = NULL; -PFNCLENQUEUECOPYIMAGE __clewEnqueueCopyImage = NULL; -PFNCLENQUEUECOPYBUFFERRECT __clewEnqueueCopyBufferRect = NULL; -PFNCLENQUEUECOPYIMAGETOBUFFER __clewEnqueueCopyImageToBuffer = NULL; -PFNCLENQUEUECOPYBUFFERTOIMAGE __clewEnqueueCopyBufferToImage = NULL; -PFNCLENQUEUEMAPBUFFER __clewEnqueueMapBuffer = NULL; -PFNCLENQUEUEMAPIMAGE __clewEnqueueMapImage = NULL; -PFNCLENQUEUEUNMAPMEMOBJECT __clewEnqueueUnmapMemObject = NULL; -PFNCLENQUEUENDRANGEKERNEL __clewEnqueueNDRangeKernel = NULL; -PFNCLENQUEUETASK __clewEnqueueTask = NULL; -PFNCLENQUEUENATIVEKERNEL __clewEnqueueNativeKernel = NULL; - - - -PFNCLGETEXTENSIONFUNCTIONADDRESSFORPLATFORM __clewGetExtensionFunctionAddressForPlatform = NULL; - -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -PFNCLCREATEIMAGE2D __clewCreateImage2D = NULL; -PFNCLCREATEIMAGE3D __clewCreateImage3D = NULL; -PFNCLENQUEUEMARKER __clewEnqueueMarker = NULL; -PFNCLENQUEUEWAITFOREVENTS __clewEnqueueWaitForEvents = NULL; -PFNCLENQUEUEBARRIER __clewEnqueueBarrier = NULL; -PFNCLUNLOADCOMPILER __clewUnloadCompiler = NULL; -PFNCLGETEXTENSIONFUNCTIONADDRESS __clewGetExtensionFunctionAddress = NULL; -#endif - -/* cl_gl */ -PFNCLCREATEFROMGLBUFFER __clewCreateFromGLBuffer = NULL; -PFNCLCREATEFROMGLTEXTURE __clewCreateFromGLTexture = NULL; -PFNCLCREATEFROMGLRENDERBUFFER __clewCreateFromGLRenderbuffer = NULL; -PFNCLGETGLOBJECTINFO __clewGetGLObjectInfo = NULL; -PFNCLGETGLTEXTUREINFO __clewGetGLTextureInfo = NULL; -PFNCLENQUEUEACQUIREGLOBJECTS __clewEnqueueAcquireGLObjects = NULL; -PFNCLENQUEUERELEASEGLOBJECTS __clewEnqueueReleaseGLObjects = NULL; -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS -PFNCLCREATEFROMGLTEXTURE2D __clewCreateFromGLTexture2D = NULL; -PFNCLCREATEFROMGLTEXTURE3D __clewCreateFromGLTexture3D = NULL; -#endif -PFNCLGETGLCONTEXTINFOKHR __clewGetGLContextInfoKHR = NULL; - -static CLEW_DYNLIB_HANDLE dynamic_library_open_find(const char **paths) { - int i = 0; - while (paths[i] != NULL) { - CLEW_DYNLIB_HANDLE lib = CLEW_DYNLIB_OPEN(paths[i]); - if (lib != NULL) { - return lib; - } - ++i; - } - return NULL; -} - -static void clewExit(void) -{ - if (module != NULL) - { - // Ignore errors - CLEW_DYNLIB_CLOSE(module); - module = NULL; - } -} - -int clewInit() -{ -#ifdef _WIN32 - const char *paths[] = {"OpenCL.dll", NULL}; -#elif defined(__APPLE__) - const char *paths[] = {"/Library/Frameworks/OpenCL.framework/OpenCL", NULL}; -#else - const char *paths[] = {"libOpenCL.so", - "libOpenCL.so.0", - "libOpenCL.so.1", - "libOpenCL.so.2", - NULL}; -#endif - - int error = 0; - - // Check if already initialized - if (module != NULL) - { - return CLEW_SUCCESS; - } - - // Load library - module = dynamic_library_open_find(paths); - - // Check for errors - if (module == NULL) - { - return CLEW_ERROR_OPEN_FAILED; - } - - // Set unloading - error = atexit(clewExit); - - if (error) - { - // Failure queuing atexit, shutdown with error - CLEW_DYNLIB_CLOSE(module); - module = NULL; - - return CLEW_ERROR_ATEXIT_FAILED; - } - - // Determine function entry-points - __clewGetPlatformIDs = (PFNCLGETPLATFORMIDS )CLEW_DYNLIB_IMPORT(module, "clGetPlatformIDs"); - __clewGetPlatformInfo = (PFNCLGETPLATFORMINFO )CLEW_DYNLIB_IMPORT(module, "clGetPlatformInfo"); - __clewGetDeviceIDs = (PFNCLGETDEVICEIDS )CLEW_DYNLIB_IMPORT(module, "clGetDeviceIDs"); - __clewGetDeviceInfo = (PFNCLGETDEVICEINFO )CLEW_DYNLIB_IMPORT(module, "clGetDeviceInfo"); - __clewCreateSubDevices = (PFNCLCREATESUBDEVICES )CLEW_DYNLIB_IMPORT(module, "clCreateSubDevices"); - __clewRetainDevice = (PFNCLRETAINDEVICE )CLEW_DYNLIB_IMPORT(module, "clRetainDevice"); - __clewReleaseDevice = (PFNCLRELEASEDEVICE )CLEW_DYNLIB_IMPORT(module, "clReleaseDevice"); - __clewCreateContext = (PFNCLCREATECONTEXT )CLEW_DYNLIB_IMPORT(module, "clCreateContext"); - __clewCreateContextFromType = (PFNCLCREATECONTEXTFROMTYPE )CLEW_DYNLIB_IMPORT(module, "clCreateContextFromType"); - __clewRetainContext = (PFNCLRETAINCONTEXT )CLEW_DYNLIB_IMPORT(module, "clRetainContext"); - __clewReleaseContext = (PFNCLRELEASECONTEXT )CLEW_DYNLIB_IMPORT(module, "clReleaseContext"); - __clewGetContextInfo = (PFNCLGETCONTEXTINFO )CLEW_DYNLIB_IMPORT(module, "clGetContextInfo"); - __clewCreateCommandQueue = (PFNCLCREATECOMMANDQUEUE )CLEW_DYNLIB_IMPORT(module, "clCreateCommandQueue"); - __clewRetainCommandQueue = (PFNCLRETAINCOMMANDQUEUE )CLEW_DYNLIB_IMPORT(module, "clRetainCommandQueue"); - __clewReleaseCommandQueue = (PFNCLRELEASECOMMANDQUEUE )CLEW_DYNLIB_IMPORT(module, "clReleaseCommandQueue"); - __clewGetCommandQueueInfo = (PFNCLGETCOMMANDQUEUEINFO )CLEW_DYNLIB_IMPORT(module, "clGetCommandQueueInfo"); -#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - __clewSetCommandQueueProperty = (PFNCLSETCOMMANDQUEUEPROPERTY )CLEW_DYNLIB_IMPORT(module, "clSetCommandQueueProperty"); -#endif - __clewCreateBuffer = (PFNCLCREATEBUFFER )CLEW_DYNLIB_IMPORT(module, "clCreateBuffer"); - __clewCreateSubBuffer = (PFNCLCREATESUBBUFFER )CLEW_DYNLIB_IMPORT(module, "clCreateSubBuffer"); - __clewCreateImage = (PFNCLCREATEIMAGE )CLEW_DYNLIB_IMPORT(module, "clCreateImage"); - __clewRetainMemObject = (PFNCLRETAINMEMOBJECT )CLEW_DYNLIB_IMPORT(module, "clRetainMemObject"); - __clewReleaseMemObject = (PFNCLRELEASEMEMOBJECT )CLEW_DYNLIB_IMPORT(module, "clReleaseMemObject"); - __clewGetSupportedImageFormats = (PFNCLGETSUPPORTEDIMAGEFORMATS )CLEW_DYNLIB_IMPORT(module, "clGetSupportedImageFormats"); - __clewGetMemObjectInfo = (PFNCLGETMEMOBJECTINFO )CLEW_DYNLIB_IMPORT(module, "clGetMemObjectInfo"); - __clewGetImageInfo = (PFNCLGETIMAGEINFO )CLEW_DYNLIB_IMPORT(module, "clGetImageInfo"); - __clewSetMemObjectDestructorCallback = (PFNCLSETMEMOBJECTDESTRUCTORCALLBACK)CLEW_DYNLIB_IMPORT(module, "clSetMemObjectDestructorCallback"); - __clewCreateSampler = (PFNCLCREATESAMPLER )CLEW_DYNLIB_IMPORT(module, "clCreateSampler"); - __clewRetainSampler = (PFNCLRETAINSAMPLER )CLEW_DYNLIB_IMPORT(module, "clRetainSampler"); - __clewReleaseSampler = (PFNCLRELEASESAMPLER )CLEW_DYNLIB_IMPORT(module, "clReleaseSampler"); - __clewGetSamplerInfo = (PFNCLGETSAMPLERINFO )CLEW_DYNLIB_IMPORT(module, "clGetSamplerInfo"); - __clewCreateProgramWithSource = (PFNCLCREATEPROGRAMWITHSOURCE )CLEW_DYNLIB_IMPORT(module, "clCreateProgramWithSource"); - __clewCreateProgramWithBinary = (PFNCLCREATEPROGRAMWITHBINARY )CLEW_DYNLIB_IMPORT(module, "clCreateProgramWithBinary"); - __clewCreateProgramWithBuiltInKernels =(PFNCLCREATEPROGRAMWITHBUILTINKERNELS)CLEW_DYNLIB_IMPORT(module, "clCreateProgramWithBuiltInKernels"); - __clewRetainProgram = (PFNCLRETAINPROGRAM )CLEW_DYNLIB_IMPORT(module, "clRetainProgram"); - __clewReleaseProgram = (PFNCLRELEASEPROGRAM )CLEW_DYNLIB_IMPORT(module, "clReleaseProgram"); - __clewBuildProgram = (PFNCLBUILDPROGRAM )CLEW_DYNLIB_IMPORT(module, "clBuildProgram"); - - __clewGetProgramInfo = (PFNCLGETPROGRAMINFO )CLEW_DYNLIB_IMPORT(module, "clGetProgramInfo"); - __clewGetProgramBuildInfo = (PFNCLGETPROGRAMBUILDINFO )CLEW_DYNLIB_IMPORT(module, "clGetProgramBuildInfo"); - __clewCreateKernel = (PFNCLCREATEKERNEL )CLEW_DYNLIB_IMPORT(module, "clCreateKernel"); - __clewCreateKernelsInProgram = (PFNCLCREATEKERNELSINPROGRAM )CLEW_DYNLIB_IMPORT(module, "clCreateKernelsInProgram"); - __clewRetainKernel = (PFNCLRETAINKERNEL )CLEW_DYNLIB_IMPORT(module, "clRetainKernel"); - __clewReleaseKernel = (PFNCLRELEASEKERNEL )CLEW_DYNLIB_IMPORT(module, "clReleaseKernel"); - __clewSetKernelArg = (PFNCLSETKERNELARG )CLEW_DYNLIB_IMPORT(module, "clSetKernelArg"); - __clewGetKernelInfo = (PFNCLGETKERNELINFO )CLEW_DYNLIB_IMPORT(module, "clGetKernelInfo"); - __clewGetKernelWorkGroupInfo = (PFNCLGETKERNELWORKGROUPINFO )CLEW_DYNLIB_IMPORT(module, "clGetKernelWorkGroupInfo"); - __clewWaitForEvents = (PFNCLWAITFOREVENTS )CLEW_DYNLIB_IMPORT(module, "clWaitForEvents"); - __clewGetEventInfo = (PFNCLGETEVENTINFO )CLEW_DYNLIB_IMPORT(module, "clGetEventInfo"); - __clewCreateUserEvent = (PFNCLCREATEUSEREVENT )CLEW_DYNLIB_IMPORT(module, "clCreateUserEvent"); - __clewRetainEvent = (PFNCLRETAINEVENT )CLEW_DYNLIB_IMPORT(module, "clRetainEvent"); - __clewReleaseEvent = (PFNCLRELEASEEVENT )CLEW_DYNLIB_IMPORT(module, "clReleaseEvent"); - __clewSetUserEventStatus = (PFNCLSETUSEREVENTSTATUS )CLEW_DYNLIB_IMPORT(module, "clSetUserEventStatus"); - __clewSetEventCallback = (PFNCLSETEVENTCALLBACK )CLEW_DYNLIB_IMPORT(module, "clSetEventCallback"); - __clewGetEventProfilingInfo = (PFNCLGETEVENTPROFILINGINFO )CLEW_DYNLIB_IMPORT(module, "clGetEventProfilingInfo"); - __clewFlush = (PFNCLFLUSH )CLEW_DYNLIB_IMPORT(module, "clFlush"); - __clewFinish = (PFNCLFINISH )CLEW_DYNLIB_IMPORT(module, "clFinish"); - __clewEnqueueReadBuffer = (PFNCLENQUEUEREADBUFFER )CLEW_DYNLIB_IMPORT(module, "clEnqueueReadBuffer"); - __clewEnqueueReadBufferRect = (PFNCLENQUEUEREADBUFFERRECT )CLEW_DYNLIB_IMPORT(module, "clEnqueueReadBufferRect"); - __clewEnqueueWriteBuffer = (PFNCLENQUEUEWRITEBUFFER )CLEW_DYNLIB_IMPORT(module, "clEnqueueWriteBuffer"); - __clewEnqueueWriteBufferRect = (PFNCLENQUEUEWRITEBUFFERRECT )CLEW_DYNLIB_IMPORT(module, "clEnqueueWriteBufferRect"); - __clewEnqueueCopyBuffer = (PFNCLENQUEUECOPYBUFFER )CLEW_DYNLIB_IMPORT(module, "clEnqueueCopyBuffer"); - __clewEnqueueCopyBufferRect = (PFNCLENQUEUECOPYBUFFERRECT )CLEW_DYNLIB_IMPORT(module, "clEnqueueCopyBufferRect"); - __clewEnqueueReadImage = (PFNCLENQUEUEREADIMAGE )CLEW_DYNLIB_IMPORT(module, "clEnqueueReadImage"); - __clewEnqueueWriteImage = (PFNCLENQUEUEWRITEIMAGE )CLEW_DYNLIB_IMPORT(module, "clEnqueueWriteImage"); - __clewEnqueueCopyImage = (PFNCLENQUEUECOPYIMAGE )CLEW_DYNLIB_IMPORT(module, "clEnqueueCopyImage"); - __clewEnqueueCopyImageToBuffer = (PFNCLENQUEUECOPYIMAGETOBUFFER )CLEW_DYNLIB_IMPORT(module, "clEnqueueCopyImageToBuffer"); - __clewEnqueueCopyBufferToImage = (PFNCLENQUEUECOPYBUFFERTOIMAGE )CLEW_DYNLIB_IMPORT(module, "clEnqueueCopyBufferToImage"); - __clewEnqueueMapBuffer = (PFNCLENQUEUEMAPBUFFER )CLEW_DYNLIB_IMPORT(module, "clEnqueueMapBuffer"); - __clewEnqueueMapImage = (PFNCLENQUEUEMAPIMAGE )CLEW_DYNLIB_IMPORT(module, "clEnqueueMapImage"); - __clewEnqueueUnmapMemObject = (PFNCLENQUEUEUNMAPMEMOBJECT )CLEW_DYNLIB_IMPORT(module, "clEnqueueUnmapMemObject"); - __clewEnqueueNDRangeKernel = (PFNCLENQUEUENDRANGEKERNEL )CLEW_DYNLIB_IMPORT(module, "clEnqueueNDRangeKernel"); - __clewEnqueueTask = (PFNCLENQUEUETASK )CLEW_DYNLIB_IMPORT(module, "clEnqueueTask"); - __clewEnqueueNativeKernel = (PFNCLENQUEUENATIVEKERNEL )CLEW_DYNLIB_IMPORT(module, "clEnqueueNativeKernel"); - - - __clewGetExtensionFunctionAddressForPlatform = (PFNCLGETEXTENSIONFUNCTIONADDRESSFORPLATFORM)CLEW_DYNLIB_IMPORT(module, "clGetExtensionFunctionAddressForPlatform"); -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - __clewCreateImage2D = (PFNCLCREATEIMAGE2D )CLEW_DYNLIB_IMPORT(module, "clCreateImage2D"); - __clewCreateImage3D = (PFNCLCREATEIMAGE3D )CLEW_DYNLIB_IMPORT(module, "clCreateImage3D"); - __clewEnqueueMarker = (PFNCLENQUEUEMARKER )CLEW_DYNLIB_IMPORT(module, "clEnqueueMarker"); - __clewEnqueueWaitForEvents = (PFNCLENQUEUEWAITFOREVENTS )CLEW_DYNLIB_IMPORT(module, "clEnqueueWaitForEvents"); - __clewEnqueueBarrier = (PFNCLENQUEUEBARRIER )CLEW_DYNLIB_IMPORT(module, "clEnqueueBarrier"); - __clewUnloadCompiler = (PFNCLUNLOADCOMPILER )CLEW_DYNLIB_IMPORT(module, "clUnloadCompiler"); - __clewGetExtensionFunctionAddress = (PFNCLGETEXTENSIONFUNCTIONADDRESS )CLEW_DYNLIB_IMPORT(module, "clGetExtensionFunctionAddress"); -#endif - - - /* cl_gl */ - __clewCreateFromGLBuffer = (PFNCLCREATEFROMGLBUFFER )CLEW_DYNLIB_IMPORT(module, "clCreateFromGLBuffer"); - __clewCreateFromGLTexture = (PFNCLCREATEFROMGLTEXTURE )CLEW_DYNLIB_IMPORT(module, "clCreateFromGLTexture"); - __clewCreateFromGLRenderbuffer = (PFNCLCREATEFROMGLRENDERBUFFER )CLEW_DYNLIB_IMPORT(module, "clCreateFromGLRenderbuffer"); - __clewGetGLObjectInfo = (PFNCLGETGLOBJECTINFO )CLEW_DYNLIB_IMPORT(module, "clGetGLObjectInfo"); - __clewGetGLTextureInfo = (PFNCLGETGLTEXTUREINFO )CLEW_DYNLIB_IMPORT(module, "clGetGLTextureInfo"); - __clewEnqueueAcquireGLObjects = (PFNCLENQUEUEACQUIREGLOBJECTS )CLEW_DYNLIB_IMPORT(module, "clEnqueueAcquireGLObjects"); - __clewEnqueueReleaseGLObjects = (PFNCLENQUEUERELEASEGLOBJECTS )CLEW_DYNLIB_IMPORT(module, "clEnqueueReleaseGLObjects"); - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - __clewCreateFromGLTexture2D = (PFNCLCREATEFROMGLTEXTURE2D )CLEW_DYNLIB_IMPORT(module, "clCreateFromGLTexture2D"); - __clewCreateFromGLTexture3D = (PFNCLCREATEFROMGLTEXTURE3D )CLEW_DYNLIB_IMPORT(module, "clCreateFromGLTexture3D"); - #endif - __clewGetGLContextInfoKHR = (PFNCLGETGLCONTEXTINFOKHR )CLEW_DYNLIB_IMPORT(module, "clGetGLContextInfoKHR"); - - - if(__clewGetPlatformIDs == NULL) return 0; - if(__clewGetPlatformInfo == NULL) return 0; - if(__clewGetDeviceIDs == NULL) return 0; - if(__clewGetDeviceInfo == NULL) return 0; - - return CLEW_SUCCESS; -} - -const char* clewErrorString(cl_int error) -{ - static const char* strings[] = - { - // Error Codes - "CL_SUCCESS" // 0 - , "CL_DEVICE_NOT_FOUND" // -1 - , "CL_DEVICE_NOT_AVAILABLE" // -2 - , "CL_COMPILER_NOT_AVAILABLE" // -3 - , "CL_MEM_OBJECT_ALLOCATION_FAILURE" // -4 - , "CL_OUT_OF_RESOURCES" // -5 - , "CL_OUT_OF_HOST_MEMORY" // -6 - , "CL_PROFILING_INFO_NOT_AVAILABLE" // -7 - , "CL_MEM_COPY_OVERLAP" // -8 - , "CL_IMAGE_FORMAT_MISMATCH" // -9 - , "CL_IMAGE_FORMAT_NOT_SUPPORTED" // -10 - , "CL_BUILD_PROGRAM_FAILURE" // -11 - , "CL_MAP_FAILURE" // -12 - , "CL_MISALIGNED_SUB_BUFFER_OFFSET" // -13 - , "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST"// -14 - , "CL_COMPILE_PROGRAM_FAILURE" // -15 - , "CL_LINKER_NOT_AVAILABLE" // -16 - , "CL_LINK_PROGRAM_FAILURE" // -17 - , "CL_DEVICE_PARTITION_FAILED" // -18 - , "CL_KERNEL_ARG_INFO_NOT_AVAILABLE" // -19 - - , "" // -20 - , "" // -21 - , "" // -22 - , "" // -23 - , "" // -24 - , "" // -25 - , "" // -26 - , "" // -27 - , "" // -28 - , "" // -29 - - , "CL_INVALID_VALUE" // -30 - , "CL_INVALID_DEVICE_TYPE" // -31 - , "CL_INVALID_PLATFORM" // -32 - , "CL_INVALID_DEVICE" // -33 - , "CL_INVALID_CONTEXT" // -34 - , "CL_INVALID_QUEUE_PROPERTIES" // -35 - , "CL_INVALID_COMMAND_QUEUE" // -36 - , "CL_INVALID_HOST_PTR" // -37 - , "CL_INVALID_MEM_OBJECT" // -38 - , "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR" // -39 - , "CL_INVALID_IMAGE_SIZE" // -40 - , "CL_INVALID_SAMPLER" // -41 - , "CL_INVALID_BINARY" // -42 - , "CL_INVALID_BUILD_OPTIONS" // -43 - , "CL_INVALID_PROGRAM" // -44 - , "CL_INVALID_PROGRAM_EXECUTABLE" // -45 - , "CL_INVALID_KERNEL_NAME" // -46 - , "CL_INVALID_KERNEL_DEFINITION" // -47 - , "CL_INVALID_KERNEL" // -48 - , "CL_INVALID_ARG_INDEX" // -49 - , "CL_INVALID_ARG_VALUE" // -50 - , "CL_INVALID_ARG_SIZE" // -51 - , "CL_INVALID_KERNEL_ARGS" // -52 - , "CL_INVALID_WORK_DIMENSION" // -53 - , "CL_INVALID_WORK_GROUP_SIZE" // -54 - , "CL_INVALID_WORK_ITEM_SIZE" // -55 - , "CL_INVALID_GLOBAL_OFFSET" // -56 - , "CL_INVALID_EVENT_WAIT_LIST" // -57 - , "CL_INVALID_EVENT" // -58 - , "CL_INVALID_OPERATION" // -59 - , "CL_INVALID_GL_OBJECT" // -60 - , "CL_INVALID_BUFFER_SIZE" // -61 - , "CL_INVALID_MIP_LEVEL" // -62 - , "CL_INVALID_GLOBAL_WORK_SIZE" // -63 - , "CL_INVALID_PROPERTY" // -64 - , "CL_INVALID_IMAGE_DESCRIPTOR" // -65 - , "CL_INVALID_COMPILER_OPTIONS" // -66 - , "CL_INVALID_LINKER_OPTIONS" // -67 - , "CL_INVALID_DEVICE_PARTITION_COUNT" // -68 - }; - - static const int num_errors = sizeof(strings) / sizeof(strings[0]); - - if (error == -1001) { - return "CL_PLATFORM_NOT_FOUND_KHR"; - } - - if (error > 0 || -error >= num_errors) { - return "Unknown OpenCL error"; - } - - return strings[-error]; -} diff --git a/release/license/THIRD-PARTY-LICENSES.txt b/release/license/THIRD-PARTY-LICENSES.txt index 669fb7bfec2..ef00fc9d31a 100644 --- a/release/license/THIRD-PARTY-LICENSES.txt +++ b/release/license/THIRD-PARTY-LICENSES.txt @@ -32,7 +32,6 @@ https://github.com/AcademySoftwareFoundation/MaterialX ** meson; version 0.63 -- https://github.com/mesonbuild/meson ** oneAPI Threading Building Block; version 2020_U3 -- https://software.intel.com/en-us/oneapi/onetbb -** OpenCL Wrangler; version 27a6867 -- https://github.com/OpenCLWrangler/clew ** OpenImageDenoise; version 1.4.3 -- https://www.openimagedenoise.org/ ** OpenImageIO; version 2.4.15.0 -- http://www.openimageio.org ** OpenSSL; version 3.1.2 -- https://www.openssl.org/ diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index c2c22f141bc..8425ca8848f 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -22,7 +22,6 @@ if(WITH_COMPOSITOR_CPU) ../nodes/intern ../render ../render/intern - ../../../extern/clew/include # RNA_prototypes.h ${CMAKE_BINARY_DIR}/source/blender/makesrna @@ -38,16 +37,10 @@ if(WITH_COMPOSITOR_CPU) COM_profile.hh intern/COM_BufferArea.h - intern/COM_BufferOperation.cc - intern/COM_BufferOperation.h intern/COM_BufferRange.h intern/COM_BuffersIterator.h intern/COM_CPUDevice.cc intern/COM_CPUDevice.h - intern/COM_ChunkOrder.cc - intern/COM_ChunkOrder.h - intern/COM_ChunkOrderHotspot.cc - intern/COM_ChunkOrderHotspot.h intern/COM_CompositorContext.cc intern/COM_CompositorContext.h intern/COM_ConstantFolder.cc @@ -60,8 +53,6 @@ if(WITH_COMPOSITOR_CPU) intern/COM_Device.h intern/COM_Enums.cc intern/COM_Enums.h - intern/COM_ExecutionGroup.cc - intern/COM_ExecutionGroup.h intern/COM_ExecutionModel.cc intern/COM_ExecutionModel.h intern/COM_ExecutionSystem.cc @@ -70,8 +61,6 @@ if(WITH_COMPOSITOR_CPU) intern/COM_FullFrameExecutionModel.h intern/COM_MemoryBuffer.cc intern/COM_MemoryBuffer.h - intern/COM_MemoryProxy.cc - intern/COM_MemoryProxy.h intern/COM_MetaData.cc intern/COM_MetaData.h intern/COM_MultiThreadedOperation.cc @@ -88,15 +77,8 @@ if(WITH_COMPOSITOR_CPU) intern/COM_NodeOperation.h intern/COM_NodeOperationBuilder.cc intern/COM_NodeOperationBuilder.h - intern/COM_OpenCLDevice.cc - intern/COM_OpenCLDevice.h intern/COM_SharedOperationBuffers.cc intern/COM_SharedOperationBuffers.h - intern/COM_SingleThreadedOperation.cc - intern/COM_SingleThreadedOperation.h - intern/COM_TiledExecutionModel.cc - intern/COM_TiledExecutionModel.h - intern/COM_WorkPackage.cc intern/COM_WorkPackage.h intern/COM_WorkScheduler.cc intern/COM_WorkScheduler.h @@ -335,18 +317,10 @@ if(WITH_COMPOSITOR_CPU) operations/COM_GammaCorrectOperation.h operations/COM_GaussianAlphaBlurBaseOperation.cc operations/COM_GaussianAlphaBlurBaseOperation.h - operations/COM_GaussianAlphaXBlurOperation.cc - operations/COM_GaussianAlphaXBlurOperation.h - operations/COM_GaussianAlphaYBlurOperation.cc - operations/COM_GaussianAlphaYBlurOperation.h operations/COM_GaussianBlurBaseOperation.cc operations/COM_GaussianBlurBaseOperation.h operations/COM_GaussianBokehBlurOperation.cc operations/COM_GaussianBokehBlurOperation.h - operations/COM_GaussianXBlurOperation.cc - operations/COM_GaussianXBlurOperation.h - operations/COM_GaussianYBlurOperation.cc - operations/COM_GaussianYBlurOperation.h operations/COM_KuwaharaAnisotropicOperation.cc operations/COM_KuwaharaAnisotropicOperation.h operations/COM_KuwaharaAnisotropicStructureTensorOperation.cc @@ -473,16 +447,12 @@ if(WITH_COMPOSITOR_CPU) operations/COM_GammaOperation.h operations/COM_MixOperation.cc operations/COM_MixOperation.h - operations/COM_ReadBufferOperation.cc - operations/COM_ReadBufferOperation.h operations/COM_SetColorOperation.cc operations/COM_SetColorOperation.h operations/COM_SetValueOperation.cc operations/COM_SetValueOperation.h operations/COM_SetVectorOperation.cc operations/COM_SetVectorOperation.h - operations/COM_WriteBufferOperation.cc - operations/COM_WriteBufferOperation.h operations/COM_MathBaseOperation.cc operations/COM_MathBaseOperation.h @@ -536,8 +506,6 @@ if(WITH_COMPOSITOR_CPU) operations/COM_TransformOperation.h operations/COM_TranslateOperation.cc operations/COM_TranslateOperation.h - operations/COM_WrapOperation.cc - operations/COM_WrapOperation.h # Filter operations operations/COM_ConvolutionEdgeFilterOperation.cc @@ -607,7 +575,6 @@ if(WITH_COMPOSITOR_CPU) PRIVATE bf::intern::clog PRIVATE bf::intern::guardedalloc bf_realtime_compositor - extern_clew PRIVATE bf::intern::atomic ) @@ -615,15 +582,6 @@ if(WITH_COMPOSITOR_CPU) ${CMAKE_CURRENT_BINARY_DIR}/operations ) - data_to_c( - ${CMAKE_CURRENT_SOURCE_DIR}/operations/COM_OpenCLKernels.cl - ${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h - SRC - STRIP_LEADING_C_COMMENTS - ) - - add_definitions(-DCL_USE_DEPRECATED_OPENCL_1_1_APIS) - set(GENSRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/operations) set(GENSRC ${GENSRC_DIR}/COM_SMAAAreaTexture.h) add_custom_command( diff --git a/source/blender/compositor/COM_compositor.hh b/source/blender/compositor/COM_compositor.hh index a70edbb5d02..a061e0a9bdd 100644 --- a/source/blender/compositor/COM_compositor.hh +++ b/source/blender/compositor/COM_compositor.hh @@ -33,49 +33,6 @@ struct Render; * \defgroup Operation All operations of the compositor * \ingroup compositor * - * \page Introduction of the Blender Compositor - * - * \section bcomp Blender compositor - * This project redesigns the internals of Blender's compositor. - * The project has been executed in 2011 by At Mind. - * At Mind is a technology company located in Amsterdam, The Netherlands. - * The project has been crowd-funded. This code has been released under GPL2 to be used in Blender. - * - * \section goals The goals of the project - * the new compositor has 2 goals. - * - Make a faster compositor (speed of calculation) - * - Make the compositor work faster for you (workflow) - * - * \section speed Faster compositor - * The speedup has been done by making better use of the hardware Blenders is working on. - * The previous compositor only used a single threaded model to calculate a node. - * The only exception to this is the Defocus node. - * Only when it is possible to calculate two full nodes in parallel a second thread was used. - * Current workstations have 8-16 threads available, and most of the time these are idle. - * - * In the new compositor we want to use as much of threads as possible. - * Even new OpenCL capable GPU-hardware can be used for calculation. - * - * \section workflow Work faster - * The previous compositor only showed the final image. - * The compositor could wait a long time before seeing the result of his work. - * The new compositor will work in a way that it will focus on - * getting information back to the user. It will prioritize its work to get earlier user feedback. - * - * \page memory Memory model - * The main issue is the type of memory model to use. - * Blender is used by consumers and professionals. - * Ranging from low-end machines to very high-end machines. - * The system should work on high-end machines and on low-end machines. - * \page executing Executing - * \section prepare Prepare execution - * - * during the preparation of the execution All ReadBufferOperation will receive an offset. - * This offset is used during execution as an optimization trick - * Next all operations will be initialized for execution \see NodeOperation.init_execution - * Next all ExecutionGroup's will be initialized for execution \see ExecutionGroup.init_execution - * this all is controlled from \see ExecutionSystem.execute - * * \section priority Render priority * Render priority is an priority of an output node. * A user has a different need of Render priorities of output nodes @@ -85,152 +42,6 @@ struct Render; * All NodeOperation has a setting for their render-priority, * but only for output NodeOperation these have effect. * In ExecutionSystem.execute all priorities are checked. - * For every priority the ExecutionGroup's are check if the - * priority do match. - * When match the ExecutionGroup will be executed (this happens in serial) - * - * \see ExecutionSystem.execute control of the Render priority - * \see NodeOperation.get_render_priority receive the render priority - * \see ExecutionGroup.execute the main loop to execute a whole ExecutionGroup - * - * \section order Chunk order - * - * When a ExecutionGroup is executed, first the order of chunks are determined. - * The settings are stored in the ViewerNode inside the ExecutionGroup. - * ExecutionGroups that have no viewer-node, - * will use a default one. - * There are several possible chunk orders - * - [@ref ChunkOrdering.CenterOut]: - * Start calculating from a configurable point and order by nearest chunk. - * - [@ref ChunkOrdering.Random]: - * Randomize all chunks. - * - [@ref ChunkOrdering.TopDown]: - * Start calculation from the bottom to the top of the image. - * - [@ref ChunkOrdering.RuleOfThirds]: - * Experimental order based on 9 hot-spots in the image. - * - * When the chunk-order is determined, the first few chunks will be checked if they can be scheduled. - * Chunks can have three states: - * - [@ref eWorkPackageState.NotScheduled]: - * Chunk is not yet scheduled, or dependencies are not met. - * - [@ref eWorkPackageState.Scheduled]: - * All dependencies are met, chunk is scheduled, but not finished. - * - [@ref eWorkPackageState.Executed]: - * Chunk is finished. - * - * \see ExecutionGroup.execute - * \see ViewerOperation.get_chunk_order - * \see ChunkOrdering - * - * \section interest Area of interest - * An ExecutionGroup can have dependencies to other ExecutionGroup's. - * Data passing from one ExecutionGroup to another one are stored in 'chunks'. - * If not all input chunks are available the chunk execution will not be scheduled. - *
- * +-------------------------------------+              +--------------------------------------+
- * | ExecutionGroup A                    |              | ExecutionGroup B                     |
- * | +----------------+  +-------------+ |              | +------------+   +-----------------+ |
- * | | NodeOperation a|  | WriteBuffer | |              | | ReadBuffer |   | ViewerOperation | |
- * | |                *==* Operation   | |              | | Operation  *===*                 | |
- * | |                |  |             | |              | |            |   |                 | |
- * | +----------------+  +-------------+ |              | +------------+   +-----------------+ |
- * |                                |    |              |   |                                  |
- * +--------------------------------|----+              +---|----------------------------------+
- *                                  |                       |
- *                                  |                       |
- *                                +---------------------------+
- *                                | MemoryProxy               |
- *                                | +----------+  +---------+ |
- *                                | | Chunk a  |  | Chunk b | |
- *                                | |          |  |         | |
- *                                | +----------+  +---------+ |
- *                                |                           |
- *                                +---------------------------+
- * 
- * - * In the above example ExecutionGroup B has an outputoperation (ViewerOperation) - * and is being executed. - * The first chunk is evaluated [@ref ExecutionGroup.schedule_chunk_when_possible], - * but not all input chunks are available. - * The relevant ExecutionGroup (that can calculate the missing chunks; ExecutionGroup A) - * is asked to calculate the area ExecutionGroup B is missing. - * [@ref ExecutionGroup.schedule_area_when_possible] - * ExecutionGroup B checks what chunks the area spans, and tries to schedule these chunks. - * If all input data is available these chunks are scheduled [@ref ExecutionGroup.schedule_chunk] - * - *
- *
- * +-------------------------+        +----------------+                           +----------------+
- * | ExecutionSystem.execute |        | ExecutionGroup |                           | ExecutionGroup |
- * +-------------------------+        | (B)            |                           | (A)            |
- *            O                       +----------------+                           +----------------+
- *            O                                |                                            |
- *            O       ExecutionGroup.execute   |                                            |
- *            O------------------------------->O                                            |
- *            .                                O                                            |
- *            .                                O-------\                                    |
- *            .                                .       | ExecutionGroup.schedule_chunk_when_possible
- *            .                                .  O----/ (*)                                |
- *            .                                .  O                                         |
- *            .                                .  O                                         |
- *            .                                .  O  ExecutionGroup.schedule_area_when_possible|
- *            .                                .  O---------------------------------------->O
- *            .                                .  .                                         O----------\ ExecutionGroup.schedule_chunk_when_possible
- *            .                                .  .                                         .          | (*)
- *            .                                .  .                                         .  O-------/
- *            .                                .  .                                         .  O
- *            .                                .  .                                         .  O
- *            .                                .  .                                         .  O-------\ ExecutionGroup.schedule_chunk
- *            .                                .  .                                         .  .       |
- *            .                                .  .                                         .  .  O----/
- *            .                                .  .                                         .  O<=O
- *            .                                .  .                                         O<=O
- *            .                                .  .                                         O
- *            .                                .  O<========================================O
- *            .                                .  O                                         |
- *            .                                O<=O                                         |
- *            .                                O                                            |
- *            .                                O                                            |
- * 
- * - * This happens until all chunks of (ExecutionGroup B) are finished executing or the user break's the process. - * - * NodeOperation like the ScaleOperation can influence the area of interest by reimplementing the - * [@ref NodeOperation.determine_area_of_interest] method - * - *
- *
- * +--------------------------+                             +---------------------------------+
- * | ExecutionGroup A         |                             | ExecutionGroup B                |
- * |                          |                             |                                 |
- * +--------------------------+                             +---------------------------------+
- *           Needed chunks from ExecutionGroup A               |   Chunk of ExecutionGroup B (to be evaluated)
- *            +-------+ +-------+                              |                  +--------+
- *            |Chunk 1| |Chunk 2|               +----------------+                |Chunk 1 |
- *            |       | |       |               | ScaleOperation |                |        |
- *            +-------+ +-------+               +----------------+                +--------+
- *
- *            +-------+ +-------+
- *            |Chunk 3| |Chunk 4|
- *            |       | |       |
- *            +-------+ +-------+
- *
- * 
- * - * \see ExecutionGroup.execute Execute a complete ExecutionGroup. - * Halts until finished or breaked by user - * \see ExecutionGroup.schedule_chunk_when_possible Tries to schedule a single chunk, - * checks if all input data is available. Can trigger dependent chunks to be calculated - * \see ExecutionGroup.schedule_area_when_possible - * Tries to schedule an area. This can be multiple chunks - * (is called from [@ref ExecutionGroup.schedule_chunk_when_possible]) - * \see ExecutionGroup.schedule_chunk Schedule a chunk on the WorkScheduler - * \see NodeOperation.determine_depending_area_of_interest Influence the area of interest of a chunk. - * \see WriteBufferOperation Operation to write to a MemoryProxy/MemoryBuffer - * \see ReadBufferOperation Operation to read from a MemoryProxy/MemoryBuffer - * \see MemoryProxy proxy for information about memory image - * (a image consist out of multiple chunks) - * \see MemoryBuffer Allocated memory for a single chunk * * \section workscheduler WorkScheduler * the WorkScheduler is implemented as a static class. the responsibility of the WorkScheduler @@ -251,47 +62,6 @@ struct Render; * This is done by changing the `COM_threading_model` * to `ThreadingModel::SingleThreaded`. When compiling the work-scheduler * will be changes to support no threading and run everything on the CPU. - * - * \section devices Devices - * A Device within the compositor context is a Hardware component that can used to calculate chunks. - * This chunk is encapsulated in a WorkPackage. - * the WorkScheduler controls the devices and selects the device where a - * WorkPackage will be calculated. - * - * \subsection WS_Devices Work-scheduler - * The WorkScheduler controls all Devices. - * When initializing the compositor the WorkScheduler selects all - * devices that will be used during compositor. - * There are two types of Devices, CPUDevice and OpenCLDevice. - * When an ExecutionGroup schedules a Chunk the schedule method of the WorkScheduler - * The Workscheduler determines if the chunk can be run on an OpenCLDevice - * (and that there are available OpenCLDevice). - * If this is the case the chunk will be added to the work-list for OpenCLDevice's - * otherwise the chunk will be added to the work-list of CPUDevices. - * - * A thread will read the work-list and sends a work-package to its device. - * - * \see WorkScheduler.schedule method that is called to schedule a chunk - * \see Device.execute method called to execute a chunk - * - * \subsection CPUDevice CPUDevice - * When a CPUDevice gets a WorkPackage the Device will get the input-buffer that is needed to - * calculate the chunk. Allocation is already done by the ExecutionGroup. - * The output-buffer of the chunk is being created. - * The OutputOperation of the ExecutionGroup is called to execute the area of the output-buffer. - * - * \see ExecutionGroup - * \see NodeOperation.execute_region executes a single chunk of a NodeOperation - * \see CPUDevice.execute - * - * \subsection GPUDevice OpenCLDevice - * - * To be completed! - * \see NodeOperation.execute_opencl_region - * \see OpenCLDevice.execute - * - * \section execute_pixel executing a pixel - * Finally the last step, the node functionality :) */ /** diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index 66f3a878144..d5ae44317f8 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -12,16 +12,6 @@ namespace blender::compositor { using Size2f = float2; -enum class eExecutionModel { - /** - * Operations are executed from outputs to inputs grouped in execution groups and rendered - * in tiles. - */ - Tiled, - /** Operations are fully rendered in order from inputs to outputs. */ - FullFrame -}; - enum class eDimension { X, Y }; /** @@ -84,28 +74,6 @@ constexpr DataType COM_num_channels_data_type(const int num_channels) } } -/* Configurable items. - * - * Chunk size determination. - * - * Chunk order. */ -/** - * \brief The order of chunks to be scheduled - * \ingroup Execution - */ -enum class ChunkOrdering { - /** \brief order from a distance to centerX/centerY */ - CenterOut = 0, - /** \brief order randomly */ - Random = 1, - /** \brief no ordering */ - TopDown = 2, - /** \brief experimental ordering with 9 hot-spots. */ - RuleOfThirds = 3, - - Default = ChunkOrdering::CenterOut, -}; - constexpr float COM_PREVIEW_SIZE = 140.f; constexpr float COM_RULE_OF_THIRDS_DIVIDER = 100.0f; constexpr float COM_BLUR_BOKEH_PIXELS = 512; diff --git a/source/blender/compositor/COM_precomp.h b/source/blender/compositor/COM_precomp.h index a45c771eb6b..e557346d3ae 100644 --- a/source/blender/compositor/COM_precomp.h +++ b/source/blender/compositor/COM_precomp.h @@ -23,12 +23,10 @@ #include "COM_ConvertOperation.h" #include "COM_Debug.h" #include "COM_Enums.h" -#include "COM_ExecutionGroup.h" #include "COM_ExecutionSystem.h" #include "COM_MultiThreadedOperation.h" #include "COM_Node.h" #include "COM_NodeOperation.h" -#include "COM_OpenCLDevice.h" #include "COM_SetAlphaMultiplyOperation.h" #include "COM_SetColorOperation.h" #include "COM_SetSamplerOperation.h" diff --git a/source/blender/compositor/intern/COM_BufferOperation.cc b/source/blender/compositor/intern/COM_BufferOperation.cc deleted file mode 100644 index ac2dfbc0fb8..00000000000 --- a/source/blender/compositor/intern/COM_BufferOperation.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* SPDX-FileCopyrightText: 2021 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_BufferOperation.h" - -namespace blender::compositor { - -BufferOperation::BufferOperation(MemoryBuffer *buffer, DataType data_type) -{ - buffer_ = buffer; - inflated_buffer_ = nullptr; - set_canvas(buffer->get_rect()); - add_output_socket(data_type); - flags_.is_constant_operation = buffer_->is_a_single_elem(); - flags_.is_fullframe_operation = false; -} - -const float *BufferOperation::get_constant_elem() -{ - BLI_assert(buffer_->is_a_single_elem()); - return buffer_->get_buffer(); -} - -void BufferOperation::init_execution() -{ - if (buffer_->is_a_single_elem()) { - init_mutex(); - } -} - -void *BufferOperation::initialize_tile_data(rcti * /*rect*/) -{ - if (buffer_->is_a_single_elem() == false) { - return buffer_; - } - - lock_mutex(); - if (!inflated_buffer_) { - inflated_buffer_ = buffer_->inflate(); - } - unlock_mutex(); - return inflated_buffer_; -} - -void BufferOperation::deinit_execution() -{ - if (buffer_->is_a_single_elem()) { - deinit_mutex(); - } - delete inflated_buffer_; -} - -void BufferOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - switch (sampler) { - case PixelSampler::Nearest: - buffer_->read(output, x, y); - break; - case PixelSampler::Bilinear: - default: - buffer_->read_bilinear(output, x, y); - break; - case PixelSampler::Bicubic: - /* No bicubic. Same implementation as ReadBufferOperation. */ - buffer_->read_bilinear(output, x, y); - break; - } -} - -void BufferOperation::execute_pixel_filtered( - float output[4], float x, float y, float dx[2], float dy[2]) -{ - const float uv[2] = {x, y}; - const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}}; - buffer_->readEWA(output, uv, deriv); -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_BufferOperation.h b/source/blender/compositor/intern/COM_BufferOperation.h deleted file mode 100644 index dcbb4360730..00000000000 --- a/source/blender/compositor/intern/COM_BufferOperation.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-FileCopyrightText: 2021 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_ConstantOperation.h" - -namespace blender::compositor { - -class BufferOperation : public ConstantOperation { - private: - MemoryBuffer *buffer_; - MemoryBuffer *inflated_buffer_; - - public: - BufferOperation(MemoryBuffer *buffer, DataType data_type); - - const float *get_constant_elem() override; - void *initialize_tile_data(rcti *rect) override; - void init_execution() override; - void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void execute_pixel_filtered( - float output[4], float x, float y, float dx[2], float dy[2]) override; -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_CPUDevice.cc b/source/blender/compositor/intern/COM_CPUDevice.cc index d24a62d7feb..6896d68c473 100644 --- a/source/blender/compositor/intern/COM_CPUDevice.cc +++ b/source/blender/compositor/intern/COM_CPUDevice.cc @@ -4,8 +4,7 @@ #include "COM_CPUDevice.h" -#include "COM_ExecutionGroup.h" -#include "COM_NodeOperation.h" +#include "COM_WorkPackage.h" namespace blender::compositor { @@ -13,21 +12,7 @@ CPUDevice::CPUDevice(int thread_id) : thread_id_(thread_id) {} void CPUDevice::execute(WorkPackage *work_package) { - switch (work_package->type) { - case eWorkPackageType::Tile: { - const uint chunk_number = work_package->chunk_number; - ExecutionGroup *execution_group = work_package->execution_group; - - execution_group->get_output_operation()->execute_region(&work_package->rect, chunk_number); - execution_group->finalize_chunk_execution(chunk_number, nullptr); - break; - } - case eWorkPackageType::CustomFunction: { - work_package->execute_fn(); - break; - } - } - + work_package->execute_fn(); if (work_package->executed_fn) { work_package->executed_fn(); } diff --git a/source/blender/compositor/intern/COM_ChunkOrder.cc b/source/blender/compositor/intern/COM_ChunkOrder.cc deleted file mode 100644 index 9fbf3eac235..00000000000 --- a/source/blender/compositor/intern/COM_ChunkOrder.cc +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include - -#include "COM_ChunkOrder.h" - -namespace blender::compositor { - -void ChunkOrder::update_distance(ChunkOrderHotspot *hotspots, uint len_hotspots) -{ - double new_distance = DBL_MAX; - for (int index = 0; index < len_hotspots; index++) { - double distance_to_hotspot = hotspots[index].calc_distance(x, y); - if (distance_to_hotspot < new_distance) { - new_distance = distance_to_hotspot; - } - } - this->distance = new_distance; -} - -bool operator<(const ChunkOrder &a, const ChunkOrder &b) -{ - return a.distance < b.distance; -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ChunkOrder.h b/source/blender/compositor/intern/COM_ChunkOrder.h deleted file mode 100644 index 3eb63c559bb..00000000000 --- a/source/blender/compositor/intern/COM_ChunkOrder.h +++ /dev/null @@ -1,33 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -#include "BLI_sys_types.h" - -#include "COM_ChunkOrderHotspot.h" - -namespace blender::compositor { - -/** Helper to determine the order how chunks are prioritized during execution. */ -struct ChunkOrder { - uint index = 0; - int x = 0; - int y = 0; - double distance = 0.0; - - friend bool operator<(const ChunkOrder &a, const ChunkOrder &b); - - void update_distance(ChunkOrderHotspot *hotspots, uint len_hotspots); - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:ChunkOrderHotspot") -#endif -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ChunkOrderHotspot.cc b/source/blender/compositor/intern/COM_ChunkOrderHotspot.cc deleted file mode 100644 index 5fc7b146ea3..00000000000 --- a/source/blender/compositor/intern/COM_ChunkOrderHotspot.cc +++ /dev/null @@ -1,19 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_ChunkOrderHotspot.h" -#include - -namespace blender::compositor { - -double ChunkOrderHotspot::calc_distance(int x, int y) -{ - int dx = this->x - x; - int dy = this->y - y; - double result = sqrt(double(dx * dx + dy * dy)); - result += double(this->addition); - return result; -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ChunkOrderHotspot.h b/source/blender/compositor/intern/COM_ChunkOrderHotspot.h deleted file mode 100644 index ede28058859..00000000000 --- a/source/blender/compositor/intern/COM_ChunkOrderHotspot.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -namespace blender::compositor { - -struct ChunkOrderHotspot { - int x; - int y; - float addition; - - ChunkOrderHotspot(int x, int y, float addition) : x(x), y(y), addition(addition) {} - - double calc_distance(int x, int y); - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:ChunkOrderHotspot") -#endif -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_CompositorContext.cc b/source/blender/compositor/intern/COM_CompositorContext.cc index cd8d83c727f..786af4e983f 100644 --- a/source/blender/compositor/intern/COM_CompositorContext.cc +++ b/source/blender/compositor/intern/COM_CompositorContext.cc @@ -11,7 +11,6 @@ CompositorContext::CompositorContext() scene_ = nullptr; rd_ = nullptr; quality_ = eCompositorQuality::High; - hasActiveOpenCLDevices_ = false; fast_calculation_ = false; bnodetree_ = nullptr; } @@ -28,9 +27,4 @@ Size2f CompositorContext::get_render_size() const get_render_data()->ysch * get_render_percentage_as_factor()}; } -eExecutionModel CompositorContext::get_execution_model() const -{ - return eExecutionModel::FullFrame; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_CompositorContext.h b/source/blender/compositor/intern/COM_CompositorContext.h index acc4af1d23d..e61d0eb8dbb 100644 --- a/source/blender/compositor/intern/COM_CompositorContext.h +++ b/source/blender/compositor/intern/COM_CompositorContext.h @@ -59,11 +59,6 @@ class CompositorContext { */ bNodeInstanceHash *previews_; - /** - * \brief does this system have active opencl devices? - */ - bool hasActiveOpenCLDevices_; - /** * \brief Skip slow nodes */ @@ -180,22 +175,6 @@ class CompositorContext { */ int get_framenumber() const; - /** - * \brief has this system active opencl_devices? - */ - bool get_has_active_opencl_devices() const - { - return hasActiveOpenCLDevices_; - } - - /** - * \brief set has this system active opencl_devices? - */ - void setHasActiveOpenCLDevices(bool hasAvtiveOpenCLDevices) - { - hasActiveOpenCLDevices_ = hasAvtiveOpenCLDevices; - } - /** Whether it has a view with a specific name and not the default one. */ bool has_explicit_view() const { @@ -234,11 +213,6 @@ class CompositorContext { view_name_ = view_name; } - int get_chunksize() const - { - return 256; - } - void set_fast_calculation(bool fast_calculation) { fast_calculation_ = fast_calculation; @@ -247,10 +221,6 @@ class CompositorContext { { return fast_calculation_; } - bool is_groupnode_buffer_enabled() const - { - return false; - } /** * \brief Get the render percentage as a factor. @@ -262,11 +232,6 @@ class CompositorContext { } Size2f get_render_size() const; - - /** - * Get active execution model. - */ - eExecutionModel get_execution_model() const; }; } // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ConstantFolder.cc b/source/blender/compositor/intern/COM_ConstantFolder.cc index 817fab1660b..6e16d6ea720 100644 --- a/source/blender/compositor/intern/COM_ConstantFolder.cc +++ b/source/blender/compositor/intern/COM_ConstantFolder.cc @@ -133,7 +133,7 @@ Vector ConstantFolder::try_fold_operations(Span last_folds = try_fold_operations( operations_builder_.get_operations()); int folds_count = last_folds.size(); diff --git a/source/blender/compositor/intern/COM_Converter.cc b/source/blender/compositor/intern/COM_Converter.cc index 57f03db7e40..0f3d71564da 100644 --- a/source/blender/compositor/intern/COM_Converter.cc +++ b/source/blender/compositor/intern/COM_Converter.cc @@ -550,13 +550,11 @@ void COM_convert_canvas(NodeOperationBuilder &builder, builder.add_operation(syop); rcti scale_canvas = from_operation->get_canvas(); - if (builder.context().get_execution_model() == eExecutionModel::FullFrame) { - ScaleOperation::scale_area(scale_canvas, scaleX, scaleY); - scale_canvas.xmax = scale_canvas.xmin + to_operation->get_width(); - scale_canvas.ymax = scale_canvas.ymin + to_operation->get_height(); - addX = 0; - addY = 0; - } + ScaleOperation::scale_area(scale_canvas, scaleX, scaleY); + scale_canvas.xmax = scale_canvas.xmin + to_operation->get_width(); + scale_canvas.ymax = scale_canvas.ymin + to_operation->get_height(); + addX = 0; + addY = 0; scale_operation->set_canvas(scale_canvas); sxop->set_canvas(scale_canvas); syop->set_canvas(scale_canvas); diff --git a/source/blender/compositor/intern/COM_Debug.cc b/source/blender/compositor/intern/COM_Debug.cc index 1203e8e3337..5bd27617247 100644 --- a/source/blender/compositor/intern/COM_Debug.cc +++ b/source/blender/compositor/intern/COM_Debug.cc @@ -12,11 +12,8 @@ #include "IMB_imbuf.hh" #include "IMB_imbuf_types.hh" -#include "COM_ExecutionGroup.h" -#include "COM_ReadBufferOperation.h" #include "COM_SetValueOperation.h" #include "COM_ViewerOperation.h" -#include "COM_WriteBufferOperation.h" namespace blender::compositor { @@ -25,7 +22,6 @@ DebugInfo::NodeNameMap DebugInfo::node_names_; DebugInfo::OpNameMap DebugInfo::op_names_; std::string DebugInfo::current_node_name_; std::string DebugInfo::current_op_name_; -DebugInfo::GroupStateMap DebugInfo::group_states_; static std::string operation_class_name(const NodeOperation *op) { @@ -56,7 +52,6 @@ std::string DebugInfo::operation_name(const NodeOperation *op) int DebugInfo::graphviz_operation(const ExecutionSystem *system, NodeOperation *operation, - const ExecutionGroup *group, char *str, int maxlen) { @@ -78,20 +73,9 @@ int DebugInfo::graphviz_operation(const ExecutionSystem *system, else if (operation->get_flags().is_set_operation) { fillcolor = "khaki1"; } - else if (operation->get_flags().is_read_buffer_operation) { - fillcolor = "darkolivegreen3"; - } - else if (operation->get_flags().is_write_buffer_operation) { - fillcolor = "darkorange"; - } len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "// OPERATION: %p\r\n", operation); - if (group) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "\"O_%p_%p\"", operation, group); - } - else { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "\"O_%p\"", operation); - } + len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "\"O_%p\"", operation); len += snprintf(str + len, maxlen > len ? maxlen - len : 0, " [fillcolor=%s,style=filled,shape=record,label=\"{", @@ -220,14 +204,11 @@ int DebugInfo::graphviz_legend_group( return len; } -int DebugInfo::graphviz_legend(char *str, int maxlen, const bool has_execution_groups) +int DebugInfo::graphviz_legend(char *str, int maxlen) { int len = 0; len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "{\r\n"); - if (has_execution_groups) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "rank = sink;\r\n"); - } len += snprintf( str + len, maxlen > len ? maxlen - len : 0, "Legend [shape=none, margin=0, label=<\r\n"); @@ -247,25 +228,9 @@ int DebugInfo::graphviz_legend(char *str, int maxlen, const bool has_execution_g "Viewer", "lightskyblue3", str + len, maxlen > len ? maxlen - len : 0); len += graphviz_legend_color( "Active Viewer", "lightskyblue1", str + len, maxlen > len ? maxlen - len : 0); - if (has_execution_groups) { - len += graphviz_legend_color( - "Write Buffer", "darkorange", str + len, maxlen > len ? maxlen - len : 0); - len += graphviz_legend_color( - "Read Buffer", "darkolivegreen3", str + len, maxlen > len ? maxlen - len : 0); - } len += graphviz_legend_color( "Input Value", "khaki1", str + len, maxlen > len ? maxlen - len : 0); - if (has_execution_groups) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "\r\n"); - len += graphviz_legend_group( - "Group Waiting", "white", "dashed", str + len, maxlen > len ? maxlen - len : 0); - len += graphviz_legend_group( - "Group Running", "firebrick1", "solid", str + len, maxlen > len ? maxlen - len : 0); - len += graphviz_legend_group( - "Group Finished", "chartreuse4", "solid", str + len, maxlen > len ? maxlen - len : 0); - } - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "\r\n"); len += snprintf(str + len, maxlen > len ? maxlen - len : 0, ">];\r\n"); len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "}\r\n"); @@ -275,7 +240,6 @@ int DebugInfo::graphviz_legend(char *str, int maxlen, const bool has_execution_g bool DebugInfo::graphviz_system(const ExecutionSystem *system, char *str, int maxlen) { - char strbuf[64]; int len = 0; len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "digraph compositorexecution {\r\n"); @@ -284,39 +248,7 @@ bool DebugInfo::graphviz_system(const ExecutionSystem *system, char *str, int ma len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "splines=false\r\n"); std::map> op_groups; - int index = 0; - for (const ExecutionGroup *group : system->groups_) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "// GROUP: %d\r\n", index); - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "subgraph cluster_%d{\r\n", index); - /* used as a check for executing group */ - if (group_states_[group] == EG_WAIT) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "style=dashed\r\n"); - } - else if (group_states_[group] == EG_RUNNING) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "style=filled\r\n"); - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "color=black\r\n"); - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "fillcolor=firebrick1\r\n"); - } - else if (group_states_[group] == EG_FINISHED) { - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "style=filled\r\n"); - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "color=black\r\n"); - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "fillcolor=chartreuse4\r\n"); - } - for (NodeOperation *operation : group->operations_) { - - SNPRINTF(strbuf, "_%p", group); - op_groups[operation].push_back(std::string(strbuf)); - - len += graphviz_operation( - system, operation, group, str + len, maxlen > len ? maxlen - len : 0); - } - - len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "}\r\n"); - index++; - } - - /* operations not included in any group */ for (NodeOperation *operation : system->operations_) { if (op_groups.find(operation) != op_groups.end()) { continue; @@ -324,29 +256,7 @@ bool DebugInfo::graphviz_system(const ExecutionSystem *system, char *str, int ma op_groups[operation].push_back(std::string("")); - len += graphviz_operation( - system, operation, nullptr, str + len, maxlen > len ? maxlen - len : 0); - } - - for (NodeOperation *operation : system->operations_) { - if (operation->get_flags().is_read_buffer_operation) { - ReadBufferOperation *read = (ReadBufferOperation *)operation; - WriteBufferOperation *write = read->get_memory_proxy()->get_write_buffer_operation(); - std::vector &read_groups = op_groups[read]; - std::vector &write_groups = op_groups[write]; - - for (int k = 0; k < write_groups.size(); k++) { - for (int l = 0; l < read_groups.size(); l++) { - len += snprintf(str + len, - maxlen > len ? maxlen - len : 0, - "\"O_%p%s\" -> \"O_%p%s\" [style=dotted]\r\n", - write, - write_groups[k].c_str(), - read, - read_groups[l].c_str()); - } - } - } + len += graphviz_operation(system, operation, str + len, maxlen > len ? maxlen - len : 0); } for (NodeOperation *op : system->operations_) { @@ -401,10 +311,7 @@ bool DebugInfo::graphviz_system(const ExecutionSystem *system, char *str, int ma } } - const bool has_execution_groups = system->get_context().get_execution_model() == - eExecutionModel::Tiled && - system->groups_.size() > 0; - len += graphviz_legend(str + len, maxlen > len ? maxlen - len : 0, has_execution_groups); + len += graphviz_legend(str + len, maxlen > len ? maxlen - len : 0); len += snprintf(str + len, maxlen > len ? maxlen - len : 0, "}\r\n"); diff --git a/source/blender/compositor/intern/COM_Debug.h b/source/blender/compositor/intern/COM_Debug.h index 608fe9f0af0..871ae393b08 100644 --- a/source/blender/compositor/intern/COM_Debug.h +++ b/source/blender/compositor/intern/COM_Debug.h @@ -24,15 +24,11 @@ static constexpr bool COM_EXPORT_OPERATION_BUFFERS = false; class Node; class NodeOperation; class ExecutionSystem; -class ExecutionGroup; class DebugInfo { public: - typedef enum { EG_WAIT, EG_RUNNING, EG_FINISHED } GroupState; - typedef std::map NodeNameMap; typedef std::map OpNameMap; - typedef std::map GroupStateMap; static std::string node_name(const Node *node); static std::string operation_name(const NodeOperation *op); @@ -47,8 +43,6 @@ class DebugInfo { static std::string current_node_name_; /** Base name for automatic sub-operations. */ static std::string current_op_name_; - /** For visualizing group states. */ - static GroupStateMap group_states_; public: static void convert_started() @@ -58,14 +52,10 @@ class DebugInfo { } } - static void execute_started(const ExecutionSystem *system) + static void execute_started() { if (COM_EXPORT_GRAPHVIZ) { file_index_ = 1; - group_states_.clear(); - for (ExecutionGroup *execution_group : system->groups_) { - group_states_[execution_group] = EG_WAIT; - } } if (COM_EXPORT_OPERATION_BUFFERS) { delete_operation_exports(); @@ -100,19 +90,6 @@ class DebugInfo { } }; - static void execution_group_started(const ExecutionGroup *group) - { - if (COM_EXPORT_GRAPHVIZ) { - group_states_[group] = EG_RUNNING; - } - }; - static void execution_group_finished(const ExecutionGroup *group) - { - if (COM_EXPORT_GRAPHVIZ) { - group_states_[group] = EG_FINISHED; - } - }; - static void operation_rendered(const NodeOperation *op, MemoryBuffer *render) { /* Don't export constant operations as there are too many and it's rarely useful. */ @@ -126,7 +103,6 @@ class DebugInfo { protected: static int graphviz_operation(const ExecutionSystem *system, NodeOperation *operation, - const ExecutionGroup *group, char *str, int maxlen); static int graphviz_legend_color(const char *name, const char *color, char *str, int maxlen); @@ -134,7 +110,7 @@ class DebugInfo { const char *name, const char *color, const char *style, char *str, int maxlen); static int graphviz_legend_group( const char *name, const char *color, const char *style, char *str, int maxlen); - static int graphviz_legend(char *str, int maxlen, bool has_execution_groups); + static int graphviz_legend(char *str, int maxlen); static bool graphviz_system(const ExecutionSystem *system, char *str, int maxlen); static void export_operation(const NodeOperation *op, MemoryBuffer *render); diff --git a/source/blender/compositor/intern/COM_Enums.cc b/source/blender/compositor/intern/COM_Enums.cc index 9f8f65b47b9..04d3805da65 100644 --- a/source/blender/compositor/intern/COM_Enums.cc +++ b/source/blender/compositor/intern/COM_Enums.cc @@ -43,23 +43,4 @@ std::ostream &operator<<(std::ostream &os, const eCompositorPriority &priority) return os; } -std::ostream &operator<<(std::ostream &os, const eWorkPackageState &execution_state) -{ - switch (execution_state) { - case eWorkPackageState::NotScheduled: { - os << "ExecutionState::NotScheduled"; - break; - } - case eWorkPackageState::Scheduled: { - os << "ExecutionState::Scheduled"; - break; - } - case eWorkPackageState::Executed: { - os << "ExecutionState::Executed"; - break; - } - } - return os; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_Enums.h b/source/blender/compositor/intern/COM_Enums.h index d062553bb4f..a35e49541b4 100644 --- a/source/blender/compositor/intern/COM_Enums.h +++ b/source/blender/compositor/intern/COM_Enums.h @@ -31,48 +31,11 @@ enum class eCompositorQuality { * \ingroup Execution */ enum class eCompositorPriority { - /** \brief High quality setting */ High = 2, - /** \brief Medium quality setting */ Medium = 1, - /** \brief Low quality setting */ Low = 0, }; -/** - * \brief the execution state of a chunk in an ExecutionGroup - * \ingroup Execution - */ -enum class eWorkPackageState { - /** - * \brief chunk is not yet scheduled - */ - NotScheduled = 0, - /** - * \brief chunk is scheduled, but not yet executed - */ - Scheduled = 1, - /** - * \brief chunk is executed. - */ - Executed = 2, -}; - -/** - * \brief Work type to execute. - * \ingroup Execution - */ -enum class eWorkPackageType { - /** - * \brief Executes an execution group tile. - */ - Tile = 0, - /** - * \brief Executes a custom function. - */ - CustomFunction = 1 -}; - enum class PixelSampler { Nearest = 0, Bilinear = 1, @@ -81,6 +44,5 @@ enum class PixelSampler { void expand_area_for_sampler(rcti &area, PixelSampler sampler); std::ostream &operator<<(std::ostream &os, const eCompositorPriority &priority); -std::ostream &operator<<(std::ostream &os, const eWorkPackageState &execution_state); } // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cc b/source/blender/compositor/intern/COM_ExecutionGroup.cc deleted file mode 100644 index d4535a95dc1..00000000000 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cc +++ /dev/null @@ -1,583 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_ExecutionGroup.h" -#include "COM_ChunkOrder.h" -#include "COM_Debug.h" -#include "COM_ReadBufferOperation.h" -#include "COM_ViewerOperation.h" -#include "COM_WorkScheduler.h" -#include "COM_WriteBufferOperation.h" -#include "COM_defines.h" - -#include "BLI_rand.hh" -#include "BLI_string.h" -#include "BLI_time.h" - -#include "BLT_translation.hh" - -namespace blender::compositor { - -std::ostream &operator<<(std::ostream &os, const ExecutionGroupFlags &flags) -{ - if (flags.initialized) { - os << "init,"; - } - if (flags.is_output) { - os << "output,"; - } - if (flags.complex) { - os << "complex,"; - } - if (flags.open_cl) { - os << "open_cl,"; - } - if (flags.single_threaded) { - os << "single_threaded,"; - } - return os; -} - -ExecutionGroup::ExecutionGroup(int id) -{ - id_ = id; - bTree_ = nullptr; - height_ = 0; - width_ = 0; - max_read_buffer_offset_ = 0; - x_chunks_len_ = 0; - y_chunks_len_ = 0; - chunks_len_ = 0; - chunks_finished_ = 0; - BLI_rcti_init(&viewer_border_, 0, 0, 0, 0); - execution_start_time_ = 0; -} - -std::ostream &operator<<(std::ostream &os, const ExecutionGroup &execution_group) -{ - os << "ExecutionGroup(id=" << execution_group.get_id(); - os << ",flags={" << execution_group.get_flags() << "}"; - os << ",operation=" << *execution_group.get_output_operation() << ""; - os << ")"; - return os; -} - -eCompositorPriority ExecutionGroup::get_render_priority() -{ - return this->get_output_operation()->get_render_priority(); -} - -bool ExecutionGroup::can_contain(NodeOperation &operation) -{ - if (!flags_.initialized) { - return true; - } - - if (operation.get_flags().is_read_buffer_operation) { - return true; - } - if (operation.get_flags().is_write_buffer_operation) { - return false; - } - if (operation.get_flags().is_set_operation) { - return true; - } - - /* complex groups don't allow further ops (except read buffer and values, see above) */ - if (flags_.complex) { - return false; - } - /* complex ops can't be added to other groups (except their own, which they initialize, see - * above) */ - if (operation.get_flags().complex) { - return false; - } - - return true; -} - -bool ExecutionGroup::add_operation(NodeOperation *operation) -{ - if (!can_contain(*operation)) { - return false; - } - - if (!operation->get_flags().is_read_buffer_operation && - !operation->get_flags().is_write_buffer_operation) - { - flags_.complex = operation->get_flags().complex; - flags_.open_cl = operation->get_flags().open_cl; - flags_.single_threaded = operation->get_flags().single_threaded; - flags_.initialized = true; - } - - operations_.append(operation); - - return true; -} - -NodeOperation *ExecutionGroup::get_output_operation() const -{ - /* The first operation of the group is always the output operation. */ - return this->operations_[0]; -} - -void ExecutionGroup::init_work_packages() -{ - work_packages_.clear(); - if (chunks_len_ != 0) { - work_packages_.resize(chunks_len_); - for (uint index = 0; index < chunks_len_; index++) { - work_packages_[index].type = eWorkPackageType::Tile; - work_packages_[index].state = eWorkPackageState::NotScheduled; - work_packages_[index].execution_group = this; - work_packages_[index].chunk_number = index; - determine_chunk_rect(&work_packages_[index].rect, index); - } - } -} - -void ExecutionGroup::init_read_buffer_operations() -{ - uint max_offset = 0; - for (NodeOperation *operation : operations_) { - if (operation->get_flags().is_read_buffer_operation) { - ReadBufferOperation *read_operation = static_cast(operation); - read_operations_.append(read_operation); - max_offset = std::max(max_offset, read_operation->get_offset()); - } - } - max_offset++; - max_read_buffer_offset_ = max_offset; -} - -void ExecutionGroup::init_execution() -{ - init_number_of_chunks(); - init_work_packages(); - init_read_buffer_operations(); -} - -void ExecutionGroup::deinit_execution() -{ - work_packages_.clear(); - chunks_len_ = 0; - x_chunks_len_ = 0; - y_chunks_len_ = 0; - read_operations_.clear(); - bTree_ = nullptr; -} - -void ExecutionGroup::determine_resolution(uint resolution[2]) -{ - NodeOperation *operation = this->get_output_operation(); - resolution[0] = operation->get_width(); - resolution[1] = operation->get_height(); - this->set_resolution(resolution); - BLI_rcti_init(&viewer_border_, 0, width_, 0, height_); -} - -void ExecutionGroup::init_number_of_chunks() -{ - if (flags_.single_threaded) { - x_chunks_len_ = 1; - y_chunks_len_ = 1; - chunks_len_ = 1; - } - else { - const float chunk_sizef = chunk_size_; - const int border_width = BLI_rcti_size_x(&viewer_border_); - const int border_height = BLI_rcti_size_y(&viewer_border_); - x_chunks_len_ = ceil(border_width / chunk_sizef); - y_chunks_len_ = ceil(border_height / chunk_sizef); - chunks_len_ = x_chunks_len_ * y_chunks_len_; - } -} - -blender::Array ExecutionGroup::get_execution_order() const -{ - blender::Array chunk_order(chunks_len_); - for (int chunk_index = 0; chunk_index < chunks_len_; chunk_index++) { - chunk_order[chunk_index] = chunk_index; - } - - NodeOperation *operation = this->get_output_operation(); - float centerX = 0.5f; - float centerY = 0.5f; - ChunkOrdering order_type = ChunkOrdering::Default; - - if (operation->get_flags().is_viewer_operation) { - ViewerOperation *viewer = (ViewerOperation *)operation; - centerX = viewer->getCenterX(); - centerY = viewer->getCenterY(); - order_type = viewer->get_chunk_order(); - } - - const int border_width = BLI_rcti_size_x(&viewer_border_); - const int border_height = BLI_rcti_size_y(&viewer_border_); - int index; - switch (order_type) { - case ChunkOrdering::Random: { - static blender::RandomNumberGenerator rng; - blender::MutableSpan span = chunk_order.as_mutable_span(); - /* Shuffle twice to make it more random. */ - rng.shuffle(span); - rng.shuffle(span); - break; - } - case ChunkOrdering::CenterOut: { - ChunkOrderHotspot hotspot(border_width * centerX, border_height * centerY, 0.0f); - blender::Array chunk_orders(chunks_len_); - for (index = 0; index < chunks_len_; index++) { - const WorkPackage &work_package = work_packages_[index]; - chunk_orders[index].index = index; - chunk_orders[index].x = work_package.rect.xmin - viewer_border_.xmin; - chunk_orders[index].y = work_package.rect.ymin - viewer_border_.ymin; - chunk_orders[index].update_distance(&hotspot, 1); - } - - std::sort(&chunk_orders[0], &chunk_orders[chunks_len_ - 1]); - for (index = 0; index < chunks_len_; index++) { - chunk_order[index] = chunk_orders[index].index; - } - - break; - } - case ChunkOrdering::RuleOfThirds: { - uint tx = border_width / 6; - uint ty = border_height / 6; - uint mx = border_width / 2; - uint my = border_height / 2; - uint bx = mx + 2 * tx; - uint by = my + 2 * ty; - float addition = chunks_len_ / COM_RULE_OF_THIRDS_DIVIDER; - - ChunkOrderHotspot hotspots[9] = { - ChunkOrderHotspot(mx, my, addition * 0), - ChunkOrderHotspot(tx, my, addition * 1), - ChunkOrderHotspot(bx, my, addition * 2), - ChunkOrderHotspot(bx, by, addition * 3), - ChunkOrderHotspot(tx, ty, addition * 4), - ChunkOrderHotspot(bx, ty, addition * 5), - ChunkOrderHotspot(tx, by, addition * 6), - ChunkOrderHotspot(mx, ty, addition * 7), - ChunkOrderHotspot(mx, by, addition * 8), - }; - - blender::Array chunk_orders(chunks_len_); - for (index = 0; index < chunks_len_; index++) { - const WorkPackage &work_package = work_packages_[index]; - chunk_orders[index].index = index; - chunk_orders[index].x = work_package.rect.xmin - viewer_border_.xmin; - chunk_orders[index].y = work_package.rect.ymin - viewer_border_.ymin; - chunk_orders[index].update_distance(hotspots, 9); - } - - std::sort(&chunk_orders[0], &chunk_orders[chunks_len_]); - - for (index = 0; index < chunks_len_; index++) { - chunk_order[index] = chunk_orders[index].index; - } - - break; - } - case ChunkOrdering::TopDown: - default: - break; - } - return chunk_order; -} - -void ExecutionGroup::execute(ExecutionSystem *graph) -{ - const CompositorContext &context = graph->get_context(); - const bNodeTree *bTree = context.get_bnodetree(); - if (width_ == 0 || height_ == 0) { - return; - } /** \note Break out... no pixels to calculate. */ - if (bTree->runtime->test_break && bTree->runtime->test_break(bTree->runtime->tbh)) { - return; - } /** \note Early break out for blur and preview nodes. */ - if (chunks_len_ == 0) { - return; - } /** \note Early break out. */ - uint chunk_index; - - execution_start_time_ = BLI_time_now_seconds(); - - chunks_finished_ = 0; - bTree_ = bTree; - - blender::Array chunk_order = get_execution_order(); - - DebugInfo::execution_group_started(this); - DebugInfo::graphviz(graph); - - bool breaked = false; - bool finished = false; - uint start_index = 0; - const int max_number_evaluated = BLI_system_thread_count() * 2; - - while (!finished && !breaked) { - bool start_evaluated = false; - finished = true; - int number_evaluated = 0; - - for (int index = start_index; index < chunks_len_ && number_evaluated < max_number_evaluated; - index++) - { - chunk_index = chunk_order[index]; - int y_chunk = chunk_index / x_chunks_len_; - int x_chunk = chunk_index - (y_chunk * x_chunks_len_); - const WorkPackage &work_package = work_packages_[chunk_index]; - switch (work_package.state) { - case eWorkPackageState::NotScheduled: { - schedule_chunk_when_possible(graph, x_chunk, y_chunk); - finished = false; - start_evaluated = true; - number_evaluated++; - - if (bTree->runtime->update_draw) { - bTree->runtime->update_draw(bTree->runtime->udh); - } - break; - } - case eWorkPackageState::Scheduled: { - finished = false; - start_evaluated = true; - number_evaluated++; - break; - } - case eWorkPackageState::Executed: { - if (!start_evaluated) { - start_index = index + 1; - } - } - }; - } - - WorkScheduler::finish(); - - if (bTree->runtime->test_break && bTree->runtime->test_break(bTree->runtime->tbh)) { - breaked = true; - } - } - DebugInfo::execution_group_finished(this); - DebugInfo::graphviz(graph); -} - -MemoryBuffer **ExecutionGroup::get_input_buffers_opencl(int chunk_number) -{ - WorkPackage &work_package = work_packages_[chunk_number]; - - MemoryBuffer **memory_buffers = (MemoryBuffer **)MEM_callocN( - sizeof(MemoryBuffer *) * max_read_buffer_offset_, __func__); - rcti output; - for (ReadBufferOperation *read_operation : read_operations_) { - MemoryProxy *memory_proxy = read_operation->get_memory_proxy(); - this->determine_depending_area_of_interest(&work_package.rect, read_operation, &output); - MemoryBuffer *memory_buffer = - memory_proxy->get_executor()->construct_consolidated_memory_buffer(*memory_proxy, output); - memory_buffers[read_operation->get_offset()] = memory_buffer; - } - return memory_buffers; -} - -MemoryBuffer *ExecutionGroup::construct_consolidated_memory_buffer(MemoryProxy &memory_proxy, - rcti &rect) -{ - MemoryBuffer *image_buffer = memory_proxy.get_buffer(); - MemoryBuffer *result = new MemoryBuffer(&memory_proxy, rect, MemoryBufferState::Temporary); - result->fill_from(*image_buffer); - return result; -} - -void ExecutionGroup::finalize_chunk_execution(int chunk_number, MemoryBuffer **memory_buffers) -{ - WorkPackage &work_package = work_packages_[chunk_number]; - if (work_package.state == eWorkPackageState::Scheduled) { - work_package.state = eWorkPackageState::Executed; - } - - atomic_add_and_fetch_u(&chunks_finished_, 1); - if (memory_buffers) { - for (uint index = 0; index < max_read_buffer_offset_; index++) { - MemoryBuffer *buffer = memory_buffers[index]; - if (buffer) { - if (buffer->is_temporarily()) { - memory_buffers[index] = nullptr; - delete buffer; - } - } - } - MEM_freeN(memory_buffers); - } - if (bTree_) { - /* Status report is only performed for top level Execution Groups. */ - float progress = chunks_finished_; - progress /= chunks_len_; - bTree_->runtime->progress(bTree_->runtime->prh, progress); - - char buf[128]; - SNPRINTF(buf, RPT_("Compositing | Tile %u-%u"), chunks_finished_, chunks_len_); - bTree_->runtime->stats_draw(bTree_->runtime->sdh, buf); - } -} - -inline void ExecutionGroup::determine_chunk_rect(rcti *r_rect, - const uint x_chunk, - const uint y_chunk) const -{ - const int border_width = BLI_rcti_size_x(&viewer_border_); - const int border_height = BLI_rcti_size_y(&viewer_border_); - - if (flags_.single_threaded) { - BLI_rcti_init(r_rect, viewer_border_.xmin, border_width, viewer_border_.ymin, border_height); - } - else { - const uint minx = x_chunk * chunk_size_ + viewer_border_.xmin; - const uint miny = y_chunk * chunk_size_ + viewer_border_.ymin; - const uint width = std::min(uint(viewer_border_.xmax), width_); - const uint height = std::min(uint(viewer_border_.ymax), height_); - BLI_rcti_init(r_rect, - std::min(minx, width_), - std::min(minx + chunk_size_, width), - std::min(miny, height_), - std::min(miny + chunk_size_, height)); - } -} - -void ExecutionGroup::determine_chunk_rect(rcti *r_rect, const uint chunk_number) const -{ - const uint y_chunk = chunk_number / x_chunks_len_; - const uint x_chunk = chunk_number - (y_chunk * x_chunks_len_); - determine_chunk_rect(r_rect, x_chunk, y_chunk); -} - -MemoryBuffer *ExecutionGroup::allocate_output_buffer(rcti &rect) -{ - /* We assume that this method is only called from complex execution groups. */ - NodeOperation *operation = this->get_output_operation(); - if (operation->get_flags().is_write_buffer_operation) { - WriteBufferOperation *write_operation = (WriteBufferOperation *)operation; - MemoryBuffer *buffer = new MemoryBuffer( - write_operation->get_memory_proxy(), rect, MemoryBufferState::Temporary); - return buffer; - } - return nullptr; -} - -bool ExecutionGroup::schedule_area_when_possible(ExecutionSystem *graph, rcti *area) -{ - if (flags_.single_threaded) { - return schedule_chunk_when_possible(graph, 0, 0); - } - /* Find all chunks inside the rect - * determine `minxchunk`, `minychunk`, `maxxchunk`, `maxychunk` - * where x and y are chunk-numbers. */ - - int indexx, indexy; - int minx = max_ii(area->xmin - viewer_border_.xmin, 0); - int maxx = min_ii(area->xmax - viewer_border_.xmin, viewer_border_.xmax - viewer_border_.xmin); - int miny = max_ii(area->ymin - viewer_border_.ymin, 0); - int maxy = min_ii(area->ymax - viewer_border_.ymin, viewer_border_.ymax - viewer_border_.ymin); - int minxchunk = minx / int(chunk_size_); - int maxxchunk = (maxx + int(chunk_size_) - 1) / int(chunk_size_); - int minychunk = miny / int(chunk_size_); - int maxychunk = (maxy + int(chunk_size_) - 1) / int(chunk_size_); - minxchunk = max_ii(minxchunk, 0); - minychunk = max_ii(minychunk, 0); - maxxchunk = min_ii(maxxchunk, int(x_chunks_len_)); - maxychunk = min_ii(maxychunk, int(y_chunks_len_)); - - bool result = true; - for (indexx = minxchunk; indexx < maxxchunk; indexx++) { - for (indexy = minychunk; indexy < maxychunk; indexy++) { - if (!schedule_chunk_when_possible(graph, indexx, indexy)) { - result = false; - } - } - } - - return result; -} - -bool ExecutionGroup::schedule_chunk(uint chunk_number) -{ - WorkPackage &work_package = work_packages_[chunk_number]; - if (work_package.state == eWorkPackageState::NotScheduled) { - work_package.state = eWorkPackageState::Scheduled; - WorkScheduler::schedule(&work_package); - return true; - } - return false; -} - -bool ExecutionGroup::schedule_chunk_when_possible(ExecutionSystem *graph, - const int chunk_x, - const int chunk_y) -{ - if (chunk_x < 0 || chunk_x >= int(x_chunks_len_)) { - return true; - } - if (chunk_y < 0 || chunk_y >= int(y_chunks_len_)) { - return true; - } - - /* Check if chunk is already executed or scheduled and not yet executed. */ - const int chunk_index = chunk_y * x_chunks_len_ + chunk_x; - WorkPackage &work_package = work_packages_[chunk_index]; - if (work_package.state == eWorkPackageState::Executed) { - return true; - } - if (work_package.state == eWorkPackageState::Scheduled) { - return false; - } - - bool can_be_executed = true; - rcti area; - - for (ReadBufferOperation *read_operation : read_operations_) { - BLI_rcti_init(&area, 0, 0, 0, 0); - MemoryProxy *memory_proxy = read_operation->get_memory_proxy(); - determine_depending_area_of_interest(&work_package.rect, read_operation, &area); - ExecutionGroup *group = memory_proxy->get_executor(); - - if (!group->schedule_area_when_possible(graph, &area)) { - can_be_executed = false; - } - } - - if (can_be_executed) { - schedule_chunk(chunk_index); - } - - return false; -} - -void ExecutionGroup::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - this->get_output_operation()->determine_depending_area_of_interest( - input, read_operation, output); -} - -void ExecutionGroup::set_viewer_border(float xmin, float xmax, float ymin, float ymax) -{ - const NodeOperation &operation = *this->get_output_operation(); - if (operation.get_flags().use_viewer_border) { - BLI_rcti_init(&viewer_border_, xmin * width_, xmax * width_, ymin * height_, ymax * height_); - } -} - -void ExecutionGroup::set_render_border(float xmin, float xmax, float ymin, float ymax) -{ - const NodeOperation &operation = *this->get_output_operation(); - if (operation.is_output_operation(true) && operation.get_flags().use_render_border) { - BLI_rcti_init(&viewer_border_, xmin * width_, xmax * width_, ymin * height_, ymax * height_); - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.h b/source/blender/compositor/intern/COM_ExecutionGroup.h deleted file mode 100644 index 27c1c22fe19..00000000000 --- a/source/blender/compositor/intern/COM_ExecutionGroup.h +++ /dev/null @@ -1,392 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -#include - -#include "BLI_array.hh" -#include "BLI_vector.hh" - -#include "COM_Enums.h" -#include "COM_WorkPackage.h" - -#include "DNA_node_types.h" -#include "DNA_vec_types.h" - -namespace blender::compositor { - -class ExecutionSystem; -class NodeOperation; -class MemoryProxy; -class MemoryBuffer; -class ReadBufferOperation; - -struct ExecutionGroupFlags { - bool initialized : 1; - /** - * Is this ExecutionGroup an output ExecutionGroup - * An OutputExecution group are groups containing a - * ViewerOperation, CompositeOperation, PreviewOperation. - */ - bool is_output : 1; - bool complex : 1; - - /** - * Can this ExecutionGroup be scheduled on an OpenCLDevice. - */ - bool open_cl : 1; - - /** - * Schedule this execution group as a single chunk. This - * chunk will be executed by a single thread. - */ - bool single_threaded : 1; - - ExecutionGroupFlags() - { - initialized = false; - is_output = false; - complex = false; - open_cl = false; - single_threaded = false; - } -}; - -std::ostream &operator<<(std::ostream &os, const ExecutionGroupFlags &flags); - -/** - * \brief Class ExecutionGroup is a group of Operations that are executed as one. - * This grouping is used to combine Operations that can be executed as one whole when - * multi-processing. - * \ingroup Execution - */ -class ExecutionGroup { - private: - // fields - /** - * Id of the execution group. For debugging purposes. - */ - int id_; - - /** - * \brief list of operations in this ExecutionGroup - */ - Vector operations_; - - ExecutionGroupFlags flags_; - - /** - * \brief Width of the output - */ - unsigned int width_; - - /** - * \brief Height of the output - */ - unsigned int height_; - - /** - * \brief size of a single chunk, being Width or of height - * a chunk is always a square, except at the edges of the MemoryBuffer - */ - unsigned int chunk_size_; - - /** - * \brief number of chunks in the x-axis - */ - unsigned int x_chunks_len_; - - /** - * \brief number of chunks in the y-axis - */ - unsigned int y_chunks_len_; - - /** - * \brief total number of chunks - */ - unsigned int chunks_len_; - - /** - * \brief what is the maximum number field of all ReadBufferOperation in this ExecutionGroup. - * \note this is used to construct the MemoryBuffers that will be passed during execution. - */ - unsigned int max_read_buffer_offset_; - - /** - * \brief All read operations of this execution group. - */ - Vector read_operations_; - - /** - * \brief reference to the original bNodeTree, - * this field is only set for the 'top' execution group. - * \note can only be used to call the callbacks for progress, status and break. - */ - const bNodeTree *bTree_; - - /** - * \brief total number of chunks that have been calculated for this ExecutionGroup - */ - unsigned int chunks_finished_; - - /** - * \brief work_packages_ holds all unit of work. - */ - Vector work_packages_; - - /** - * \brief denotes boundary for border compositing - * \note measured in pixel space - */ - rcti viewer_border_; - - /** - * \brief start time of execution - */ - double execution_start_time_; - - // methods - /** - * \brief check whether parameter operation can be added to the execution group - * \param operation: the operation to be added - */ - bool can_contain(NodeOperation &operation); - - /** - * \brief Determine the rect (minx, maxx, miny, maxy) of a chunk at a position. - */ - void determine_chunk_rect(rcti *r_rect, unsigned int x_chunk, unsigned int y_chunk) const; - - /** - * \brief determine the number of chunks, based on the chunk_size, width and height. - * \note The result are stored in the fields number_of_chunks, number_of_xchunks, - * number_of_ychunks - */ - void init_number_of_chunks(); - - /** - * \brief try to schedule a specific chunk. - * \note scheduling succeeds when all input requirements are met and the chunks hasn't been - * scheduled yet. - * \param graph: - * \param x_chunk: - * \param y_chunk: - * \return [true:false] - * true: package(s) are scheduled - * false: scheduling is deferred (depending workpackages are scheduled) - */ - bool schedule_chunk_when_possible(ExecutionSystem *graph, int chunk_x, int chunk_y); - - /** - * \brief try to schedule a specific area. - * \note Check if a certain area is available, when not available this are will be checked. - * \note This method is called from other ExecutionGroup's. - * \param graph: - * \param area: - * \return [true:false] - * true: package(s) are scheduled - * false: scheduling is deferred (depending workpackages are scheduled) - */ - bool schedule_area_when_possible(ExecutionSystem *graph, rcti *area); - - /** - * \brief add a chunk to the WorkScheduler. - * \param chunknumber: - */ - bool schedule_chunk(unsigned int chunk_number); - - /** - * \brief determine the area of interest of a certain input area - * \note This method only evaluates a single ReadBufferOperation - * \param input: the input area - * \param read_operation: The ReadBufferOperation where the area needs to be evaluated - * \param output: the area needed of the ReadBufferOperation. Result - */ - void determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output); - - /** - * Return the execution order of the user visible chunks. - */ - blender::Array get_execution_order() const; - - void init_read_buffer_operations(); - void init_work_packages(); - - public: - // constructors - ExecutionGroup(int id); - - int get_id() const - { - return id_; - } - - const ExecutionGroupFlags get_flags() const - { - return flags_; - } - - // methods - /** - * \brief add an operation to this ExecutionGroup - * \note this method will add input of the operations recursively - * \note this method can create multiple ExecutionGroup's - * \param system: - * \param operation: - * \return True if the operation was successfully added - */ - bool add_operation(NodeOperation *operation); - - /** - * \brief set whether this ExecutionGroup is an output - * \param is_output: - */ - void set_output_execution_group(bool is_output) - { - flags_.is_output = is_output; - } - - /** - * \brief determine the resolution of this ExecutionGroup - * \param resolution: - */ - void determine_resolution(unsigned int resolution[2]); - - /** - * \brief set the resolution of this executiongroup - * \param resolution: - */ - void set_resolution(unsigned int resolution[2]) - { - width_ = resolution[0]; - height_ = resolution[1]; - } - - /** - * \brief get the width of this execution group - */ - unsigned int get_width() const - { - return width_; - } - - /** - * \brief get the height of this execution group - */ - unsigned int get_height() const - { - return height_; - } - - /** - * \brief get the output operation of this ExecutionGroup - * \return NodeOperation *output operation - */ - NodeOperation *get_output_operation() const; - - /** - * \brief compose multiple chunks into a single chunk - * \return `(Memorybuffer *)` consolidated chunk - */ - MemoryBuffer *construct_consolidated_memory_buffer(MemoryProxy &memory_proxy, rcti &rect); - - /** - * \brief init_execution is called just before the execution of the whole graph will be done. - * \note The implementation will calculate the chunk_size of this execution group. - */ - void init_execution(); - - /** - * \brief get all input-buffers needed to calculate an chunk - * \note all input-buffers must be executed - * \param chunk_number: the chunk to be calculated - * \return `(MemoryBuffer **)` the input-buffers. - */ - MemoryBuffer **get_input_buffers_opencl(int chunk_number); - - /** - * \brief allocate the output-buffer of a chunk - * \param chunk_number: the number of the chunk in the ExecutionGroup - * \param rect: the rect of that chunk - * \see determine_chunk_rect - */ - MemoryBuffer *allocate_output_buffer(rcti &rect); - - /** - * \brief after a chunk is executed the needed resources can be freed or unlocked. - * \param chunknumber: - * \param memorybuffers: - */ - void finalize_chunk_execution(int chunk_number, MemoryBuffer **memory_buffers); - - /** - * \brief deinit_execution is called just after execution the whole graph. - * \note It will release all needed resources - */ - void deinit_execution(); - - /** - * \brief schedule an ExecutionGroup - * \note this method will return when all chunks have been calculated, or the execution has - * breaked (by user) - * - * first the order of the chunks will be determined. This is determined by finding the - * ViewerOperation and get the relevant information from it. - * - ChunkOrdering - * - CenterX - * - CenterY - * - * After determining the order of the chunks the chunks will be scheduled - * - * \see ViewerOperation - * \param graph: - */ - /** - * This method is called for the top execution groups. containing the compositor node or the - * preview node or the viewer node). - */ - void execute(ExecutionSystem *graph); - - /** - * \brief Determine the rect (minx, maxx, miny, maxy) of a chunk. - */ - void determine_chunk_rect(rcti *r_rect, unsigned int chunk_number) const; - - void set_chunksize(int chunksize) - { - chunk_size_ = chunksize; - } - - /** - * \brief get the Render priority of this ExecutionGroup - * \see ExecutionSystem.execute - */ - eCompositorPriority get_render_priority(); - - /** - * \brief set border for viewer operation - * \note all the coordinates are assumed to be in normalized space - */ - void set_viewer_border(float xmin, float xmax, float ymin, float ymax); - - void set_render_border(float xmin, float xmax, float ymin, float ymax); - - /* allow the DebugInfo class to look at internals */ - friend class DebugInfo; - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:ExecutionGroup") -#endif -}; - -std::ostream &operator<<(std::ostream &os, const ExecutionGroup &execution_group); - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.cc b/source/blender/compositor/intern/COM_ExecutionSystem.cc index dc334b85c3c..88117f89891 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.cc +++ b/source/blender/compositor/intern/COM_ExecutionSystem.cc @@ -5,11 +5,9 @@ #include "COM_ExecutionSystem.h" #include "COM_Debug.h" -#include "COM_ExecutionGroup.h" #include "COM_FullFrameExecutionModel.h" #include "COM_NodeOperation.h" #include "COM_NodeOperationBuilder.h" -#include "COM_TiledExecutionModel.h" #include "COM_WorkPackage.h" #include "COM_WorkScheduler.h" @@ -44,7 +42,6 @@ ExecutionSystem::ExecutionSystem(RenderData *rd, context_.set_quality((eCompositorQuality)editingtree->edit_quality); } context_.set_rendering(rendering); - context_.setHasActiveOpenCLDevices(WorkScheduler::has_gpu_devices() && false); context_.set_render_data(rd); @@ -56,17 +53,7 @@ ExecutionSystem::ExecutionSystem(RenderData *rd, builder.convert_to_operations(this); } - switch (context_.get_execution_model()) { - case eExecutionModel::Tiled: - execution_model_ = new TiledExecutionModel(context_, operations_, groups_); - break; - case eExecutionModel::FullFrame: - execution_model_ = new FullFrameExecutionModel(context_, active_buffers_, operations_); - break; - default: - BLI_assert_msg(0, "Non implemented execution model"); - break; - } + execution_model_ = new FullFrameExecutionModel(context_, active_buffers_, operations_); } ExecutionSystem::~ExecutionSystem() @@ -80,23 +67,16 @@ ExecutionSystem::~ExecutionSystem() delete operation; } operations_.clear(); - - for (ExecutionGroup *group : groups_) { - delete group; - } - groups_.clear(); } -void ExecutionSystem::set_operations(const Span operations, - const Span groups) +void ExecutionSystem::set_operations(const Span operations) { operations_ = operations; - groups_ = groups; } void ExecutionSystem::execute() { - DebugInfo::execute_started(this); + DebugInfo::execute_started(); for (NodeOperation *op : operations_) { op->init_data(); } @@ -131,7 +111,6 @@ void ExecutionSystem::execute_work(const rcti &work_rect, } WorkPackage &sub_work = sub_works[i]; - sub_work.type = eWorkPackageType::CustomFunction; sub_work.execute_fn = [=, &work_func, &work_rect]() { if (is_breaked()) { return; diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.h b/source/blender/compositor/intern/COM_ExecutionSystem.h index 3c3c8b63aa0..8080302d5e3 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.h +++ b/source/blender/compositor/intern/COM_ExecutionSystem.h @@ -82,36 +82,9 @@ class ProfilerData; * * \see COM_convert_data_type Datatype conversions * \see Converter.convert_resolution Image size conversions - * - * \section EM_Step4 Step4: group operations in executions groups - * ExecutionGroup are groups of operations that are calculated as being one bigger operation. - * All operations will be part of an ExecutionGroup. - * Complex nodes will be added to separate groups. Between ExecutionGroup's the data will be stored - * in MemoryBuffers. ReadBufferOperations and WriteBufferOperations are added where needed. - * - *
- *
- *        +------------------------------+      +----------------+
- *        | ExecutionGroup A             |      |ExecutionGroup B|   ExecutionGroup
- *        | +----------+     +----------+|      |+----------+    |
- *   /----->| Operation|---->| Operation|-\ /--->| Operation|-\  |   NodeOperation
- *   |    | | A        |     | B        ||| |   || C        | |  |
- *   |    | | cFFA     |  /->| cFFA     ||| |   || cFFA     | |  |
- *   |    | +----------+  |  +----------+|| |   |+----------+ |  |
- *   |    +---------------|--------------+v |   +-------------v--+
- * +-*----+           +---*--+         +--*-*--+           +--*----+
- * |inputA|           |inputB|         |outputA|           |outputB| MemoryBuffer
- * |cFAA  |           |cFAA  |         |cFAA   |           |cFAA   |
- * +------+           +------+         +-------+           +-------+
- * 
- * \see ExecutionSystem.group_operations method doing this step - * \see ExecutionSystem.add_read_write_buffer_operations - * \see NodeOperation.is_complex - * \see ExecutionGroup class representing the ExecutionGroup */ /* Forward declarations. */ -class ExecutionGroup; class ExecutionModel; class NodeOperation; @@ -136,11 +109,6 @@ class ExecutionSystem { */ Vector operations_; - /** - * \brief vector of groups - */ - Vector groups_; - /** * Active execution model implementation. */ @@ -178,13 +146,13 @@ class ExecutionSystem { */ ~ExecutionSystem(); - void set_operations(Span operations, Span groups); + void set_operations(Span operations); /** * \brief execute this system - * - initialize the NodeOperation's and ExecutionGroup's - * - schedule the output ExecutionGroup's based on their priority - * - deinitialize the ExecutionGroup's and NodeOperation's + * - initialize the NodeOperation's + * - schedule the outputs based on their priority + * - deinitialize the NodeOperation's */ void execute(); @@ -196,11 +164,6 @@ class ExecutionSystem { return context_; } - SharedOperationBuffers &get_active_buffers() - { - return active_buffers_; - } - /** * Multi-threadedly execute given work function passing work_rect splits as argument. */ diff --git a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc index 0f5af05d28f..ed571da57df 100644 --- a/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc +++ b/source/blender/compositor/intern/COM_FullFrameExecutionModel.cc @@ -134,7 +134,7 @@ void FullFrameExecutionModel::render_operations() { const bool is_rendering = context_.is_rendering(); - WorkScheduler::start(this->context_); + WorkScheduler::start(); for (eCompositorPriority priority : priorities_) { for (NodeOperation *op : operations_) { const bool has_size = op->get_width() > 0 && op->get_height() > 0; diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cc b/source/blender/compositor/intern/COM_MemoryBuffer.cc index db6940f062a..463590ba011 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cc +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cc @@ -4,8 +4,6 @@ #include "COM_MemoryBuffer.h" -#include "COM_MemoryProxy.h" - #include "IMB_colormanagement.hh" #include "IMB_imbuf_types.hh" @@ -30,31 +28,14 @@ static rcti create_rect(const int width, const int height) return rect; } -MemoryBuffer::MemoryBuffer(MemoryProxy *memory_proxy, const rcti &rect, MemoryBufferState state) -{ - rect_ = rect; - is_a_single_elem_ = false; - memory_proxy_ = memory_proxy; - num_channels_ = COM_data_type_num_channels(memory_proxy->get_data_type()); - buffer_ = (float *)MEM_mallocN_aligned( - sizeof(float) * buffer_len() * num_channels_, 16, "COM_MemoryBuffer"); - owns_data_ = true; - state_ = state; - datatype_ = memory_proxy->get_data_type(); - - set_strides(); -} - MemoryBuffer::MemoryBuffer(DataType data_type, const rcti &rect, bool is_a_single_elem) { rect_ = rect; is_a_single_elem_ = is_a_single_elem; - memory_proxy_ = nullptr; num_channels_ = COM_data_type_num_channels(data_type); buffer_ = (float *)MEM_mallocN_aligned( sizeof(float) * buffer_len() * num_channels_, 16, "COM_MemoryBuffer"); owns_data_ = true; - state_ = MemoryBufferState::Temporary; datatype_ = data_type; set_strides(); @@ -73,19 +54,16 @@ MemoryBuffer::MemoryBuffer(float *buffer, { rect_ = rect; is_a_single_elem_ = is_a_single_elem; - memory_proxy_ = nullptr; num_channels_ = num_channels; datatype_ = COM_num_channels_data_type(num_channels); buffer_ = buffer; owns_data_ = false; - state_ = MemoryBufferState::Temporary; set_strides(); } MemoryBuffer::MemoryBuffer(const MemoryBuffer &src) : MemoryBuffer(src.datatype_, src.rect_, false) { - memory_proxy_ = src.memory_proxy_; /* src may be single elem buffer */ fill_from(src); } @@ -468,44 +446,6 @@ void MemoryBuffer::read_elem_filtered( out); } -/* TODO(manzanilla): to be removed with tiled implementation. */ -static void read_ewa_pixel_sampled(void *userdata, int x, int y, float result[4]) -{ - MemoryBuffer *buffer = (MemoryBuffer *)userdata; - buffer->read(result, x, y); -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void MemoryBuffer::readEWA(float *result, const float uv[2], const float derivatives[2][2]) -{ - if (is_a_single_elem_) { - memcpy(result, buffer_, sizeof(float) * num_channels_); - } - else { - BLI_assert(datatype_ == DataType::Color); - float inv_width = 1.0f / float(this->get_width()), - inv_height = 1.0f / float(this->get_height()); - /* TODO(sergey): Render pipeline uses normalized coordinates and derivatives, - * but compositor uses pixel space. For now let's just divide the values and - * switch compositor to normalized space for EWA later. - */ - float uv_normal[2] = {uv[0] * inv_width, uv[1] * inv_height}; - float du_normal[2] = {derivatives[0][0] * inv_width, derivatives[0][1] * inv_height}; - float dv_normal[2] = {derivatives[1][0] * inv_width, derivatives[1][1] * inv_height}; - - BLI_ewa_filter(this->get_width(), - this->get_height(), - false, - true, - uv_normal, - du_normal, - dv_normal, - read_ewa_pixel_sampled, - this, - result); - } -} - void MemoryBuffer::copy_single_elem_from(const MemoryBuffer *src, const int channel_offset, const int elem_size, diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index 177ea614d2e..2ad308a3d92 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -21,28 +21,14 @@ struct ImBuf; namespace blender::compositor { -/** - * \brief state of a memory buffer - * \ingroup Memory - */ -enum class MemoryBufferState { - /** \brief memory has been allocated on creator device and CPU machine, - * but kernel has not been executed */ - Default = 0, - /** \brief chunk is consolidated from other chunks. special state. */ - Temporary = 6, -}; - enum class MemoryBufferExtend { Clip, Extend, Repeat, }; -class MemoryProxy; - /** - * \brief a MemoryBuffer contains access to the data of a chunk + * \brief a MemoryBuffer contains access to the data */ class MemoryBuffer { public: @@ -65,26 +51,16 @@ class MemoryBuffer { int row_stride; private: - /** - * \brief proxy of the memory (same for all chunks in the same buffer) - */ - MemoryProxy *memory_proxy_; - /** * \brief the type of buffer DataType::Value, DataType::Vector, DataType::Color */ DataType datatype_; /** - * \brief region of this buffer inside relative to the MemoryProxy + * \brief region of this buffer inside */ rcti rect_; - /** - * \brief state of the buffer - */ - MemoryBufferState state_; - /** * \brief the actual float buffer/data */ @@ -113,11 +89,6 @@ class MemoryBuffer { int to_positive_y_stride_; public: - /** - * \brief construct new temporarily MemoryBuffer for an area - */ - MemoryBuffer(MemoryProxy *memory_proxy, const rcti &rect, MemoryBufferState state); - /** * \brief construct new temporarily MemoryBuffer for an area */ @@ -384,12 +355,6 @@ class MemoryBuffer { return buffer_; } - float *release_ownership_buffer() - { - owns_data_ = false; - return buffer_; - } - /** * Converts a single elem buffer to a full size buffer (allocates memory for all * elements in resolution). @@ -491,8 +456,6 @@ class MemoryBuffer { y = y + rect_.ymin; } - /* TODO(manzanilla): to be removed with tiled implementation. For applying #MemoryBufferExtend - * use #wrap_pixel. */ inline void read(float *result, int x, int y, @@ -514,28 +477,6 @@ class MemoryBuffer { memcpy(result, buffer, sizeof(float) * num_channels_); } } - - /* TODO(manzanilla): to be removed with tiled implementation. */ - inline void read_no_check(float *result, - int x, - int y, - MemoryBufferExtend extend_x = MemoryBufferExtend::Clip, - MemoryBufferExtend extend_y = MemoryBufferExtend::Clip) - { - int u = x; - int v = y; - - this->wrap_pixel(u, v, extend_x, extend_y); - const int offset = get_coords_offset(u, v); - - BLI_assert(offset >= 0); - BLI_assert(offset < this->buffer_len() * num_channels_); - BLI_assert(!(extend_x == MemoryBufferExtend::Clip && (u < rect_.xmin || u >= rect_.xmax)) && - !(extend_y == MemoryBufferExtend::Clip && (v < rect_.ymin || v >= rect_.ymax))); - float *buffer = &buffer_[offset]; - memcpy(result, buffer, sizeof(float) * num_channels_); - } - void write_pixel(int x, int y, const float color[4]); void add_pixel(int x, int y, const float color[4]); inline void read_bilinear(float *result, @@ -569,16 +510,6 @@ class MemoryBuffer { } } - void readEWA(float *result, const float uv[2], const float derivatives[2][2]); - - /** - * \brief is this MemoryBuffer a temporarily buffer (based on an area, not on a chunk) - */ - inline bool is_temporarily() const - { - return state_ == MemoryBufferState::Temporary; - } - /** * \brief Apply a color processor on the given area. */ diff --git a/source/blender/compositor/intern/COM_MemoryProxy.cc b/source/blender/compositor/intern/COM_MemoryProxy.cc deleted file mode 100644 index 2388cf69645..00000000000 --- a/source/blender/compositor/intern/COM_MemoryProxy.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_MemoryProxy.h" -#include "COM_MemoryBuffer.h" - -namespace blender::compositor { - -MemoryProxy::MemoryProxy(DataType datatype) -{ - write_buffer_operation_ = nullptr; - executor_ = nullptr; - buffer_ = nullptr; - datatype_ = datatype; -} - -void MemoryProxy::allocate(uint width, uint height) -{ - rcti result; - result.xmin = 0; - result.xmax = width; - result.ymin = 0; - result.ymax = height; - - buffer_ = new MemoryBuffer(this, result, MemoryBufferState::Default); -} - -void MemoryProxy::free() -{ - if (buffer_) { - delete buffer_; - buffer_ = nullptr; - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_MemoryProxy.h b/source/blender/compositor/intern/COM_MemoryProxy.h deleted file mode 100644 index ca531eb66dc..00000000000 --- a/source/blender/compositor/intern/COM_MemoryProxy.h +++ /dev/null @@ -1,114 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -#include "COM_defines.h" - -namespace blender::compositor { - -/* Forward declarations. */ -class MemoryBuffer; -class ExecutionGroup; -class WriteBufferOperation; - -/** - * \brief A MemoryProxy is a unique identifier for a memory buffer. - * A single MemoryProxy is used among all chunks of the same buffer, - * the MemoryBuffer only stores the data of a single chunk. - * \ingroup Memory - */ -class MemoryProxy { - private: - /** - * \brief reference to the output operation of the executiongroup - */ - WriteBufferOperation *write_buffer_operation_; - - /** - * \brief reference to the executor. the Execution group that can fill a chunk - */ - ExecutionGroup *executor_; - - /** - * \brief the allocated memory - */ - MemoryBuffer *buffer_; - - /** - * \brief datatype of this MemoryProxy - */ - DataType datatype_; - - public: - MemoryProxy(DataType type); - - /** - * \brief set the ExecutionGroup that can be scheduled to calculate a certain chunk. - * \param group: the ExecutionGroup to set - */ - void set_executor(ExecutionGroup *executor) - { - executor_ = executor; - } - - /** - * \brief get the ExecutionGroup that can be scheduled to calculate a certain chunk. - */ - ExecutionGroup *get_executor() const - { - return executor_; - } - - /** - * \brief set the WriteBufferOperation that is responsible for writing to this MemoryProxy - * \param operation: - */ - void set_write_buffer_operation(WriteBufferOperation *operation) - { - write_buffer_operation_ = operation; - } - - /** - * \brief get the WriteBufferOperation that is responsible for writing to this MemoryProxy - * \return WriteBufferOperation - */ - WriteBufferOperation *get_write_buffer_operation() const - { - return write_buffer_operation_; - } - - /** - * \brief allocate memory of size width x height - */ - void allocate(unsigned int width, unsigned int height); - - /** - * \brief free the allocated memory - */ - void free(); - - /** - * \brief get the allocated memory - */ - inline MemoryBuffer *get_buffer() - { - return buffer_; - } - - inline DataType get_data_type() - { - return datatype_; - } - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:MemoryProxy") -#endif -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_MultiThreadedOperation.cc b/source/blender/compositor/intern/COM_MultiThreadedOperation.cc index cfb65c9376f..695e83e8cf8 100644 --- a/source/blender/compositor/intern/COM_MultiThreadedOperation.cc +++ b/source/blender/compositor/intern/COM_MultiThreadedOperation.cc @@ -11,7 +11,6 @@ MultiThreadedOperation::MultiThreadedOperation() { num_passes_ = 1; current_pass_ = 0; - flags_.is_fullframe_operation = true; } void MultiThreadedOperation::update_memory_buffer(MemoryBuffer *output, diff --git a/source/blender/compositor/intern/COM_NodeGraph.cc b/source/blender/compositor/intern/COM_NodeGraph.cc index 013d55d1845..3059ebbc296 100644 --- a/source/blender/compositor/intern/COM_NodeGraph.cc +++ b/source/blender/compositor/intern/COM_NodeGraph.cc @@ -231,7 +231,7 @@ void NodeGraph::add_proxies_group_inputs(bNode *b_node, bNode *b_node_io) } } -void NodeGraph::add_proxies_group_outputs(const CompositorContext &context, +void NodeGraph::add_proxies_group_outputs(const CompositorContext & /*context*/, bNode *b_node, bNode *b_node_io) { @@ -247,16 +247,8 @@ void NodeGraph::add_proxies_group_outputs(const CompositorContext &context, { bNodeSocket *b_sock_group = find_b_node_output(b_node, b_sock_io->identifier); if (b_sock_group) { - if (context.is_groupnode_buffer_enabled() && - context.get_execution_model() == eExecutionModel::Tiled) - { - SocketBufferNode *buffer = new SocketBufferNode(b_node_io, b_sock_io, b_sock_group); - add_node(buffer, b_group_tree, key, is_active_group); - } - else { - SocketProxyNode *proxy = new SocketProxyNode(b_node_io, b_sock_io, b_sock_group, true); - add_node(proxy, b_group_tree, key, is_active_group); - } + SocketProxyNode *proxy = new SocketProxyNode(b_node_io, b_sock_io, b_sock_group, true); + add_node(proxy, b_group_tree, key, is_active_group); } } } diff --git a/source/blender/compositor/intern/COM_NodeOperation.cc b/source/blender/compositor/intern/COM_NodeOperation.cc index 0cc71829c33..4187ec1180c 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cc +++ b/source/blender/compositor/intern/COM_NodeOperation.cc @@ -4,9 +4,7 @@ #include -#include "COM_BufferOperation.h" #include "COM_ExecutionSystem.h" -#include "COM_ReadBufferOperation.h" #include "COM_NodeOperation.h" /* own include */ @@ -156,26 +154,6 @@ void NodeOperation::init_execution() /* pass */ } -void NodeOperation::init_mutex() -{ - BLI_mutex_init(&mutex_); -} - -void NodeOperation::lock_mutex() -{ - BLI_mutex_lock(&mutex_); -} - -void NodeOperation::unlock_mutex() -{ - BLI_mutex_unlock(&mutex_); -} - -void NodeOperation::deinit_mutex() -{ - BLI_mutex_end(&mutex_); -} - void NodeOperation::deinit_execution() { /* pass */ @@ -213,57 +191,15 @@ NodeOperation *NodeOperation::get_input_operation(int index) return nullptr; } -bool NodeOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - if (inputs_.is_empty()) { - BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax); - return false; - } - - rcti temp_output; - bool first = true; - for (int i = 0; i < get_number_of_input_sockets(); i++) { - NodeOperation *input_operation = this->get_input_operation(i); - if (input_operation && - input_operation->determine_depending_area_of_interest(input, read_operation, &temp_output)) - { - if (first) { - output->xmin = temp_output.xmin; - output->ymin = temp_output.ymin; - output->xmax = temp_output.xmax; - output->ymax = temp_output.ymax; - first = false; - } - else { - output->xmin = std::min(output->xmin, temp_output.xmin); - output->ymin = std::min(output->ymin, temp_output.ymin); - output->xmax = std::max(output->xmax, temp_output.xmax); - output->ymax = std::max(output->ymax, temp_output.ymax); - } - } - } - return !first; -} - /* -------------------------------------------------------------------- */ /** \name Full Frame Methods * \{ */ -void NodeOperation::get_area_of_interest(const int input_idx, +void NodeOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) { - if (get_flags().is_fullframe_operation) { - r_input_area = output_area; - } - else { - /* Non full-frame operations never implement this method. To ensure correctness assume - * whole area is used. */ - NodeOperation *input_op = get_input_operation(input_idx); - r_input_area = input_op->get_canvas(); - } + r_input_area = output_area; } void NodeOperation::get_area_of_interest(NodeOperation *input_op, @@ -283,12 +219,7 @@ void NodeOperation::render(MemoryBuffer *output_buf, Span areas, Span inputs_bufs) { - if (get_flags().is_fullframe_operation) { - render_full_frame(output_buf, areas, inputs_bufs); - } - else { - render_full_frame_fallback(output_buf, areas, inputs_bufs); - } + render_full_frame(output_buf, areas, inputs_bufs); } void NodeOperation::render_full_frame(MemoryBuffer *output_buf, @@ -302,92 +233,6 @@ void NodeOperation::render_full_frame(MemoryBuffer *output_buf, deinit_execution(); } -void NodeOperation::render_full_frame_fallback(MemoryBuffer *output_buf, - Span areas, - Span inputs_bufs) -{ - Vector orig_input_links = replace_inputs_with_buffers(inputs_bufs); - - init_execution(); - const bool is_output_operation = get_number_of_output_sockets() == 0; - if (!is_output_operation && output_buf->is_a_single_elem()) { - float *output_elem = output_buf->get_elem(0, 0); - read_sampled(output_elem, 0, 0, PixelSampler::Nearest); - } - else { - for (const rcti &rect : areas) { - exec_system_->execute_work(rect, [=](const rcti &split_rect) { - rcti tile_rect = split_rect; - if (is_output_operation) { - execute_region(&tile_rect, 0); - } - else { - render_tile(output_buf, &tile_rect); - } - }); - } - } - deinit_execution(); - - remove_buffers_and_restore_original_inputs(orig_input_links); -} - -void NodeOperation::render_tile(MemoryBuffer *output_buf, rcti *tile_rect) -{ - const bool is_complex = get_flags().complex; - void *tile_data = is_complex ? initialize_tile_data(tile_rect) : nullptr; - const int elem_stride = output_buf->elem_stride; - for (int y = tile_rect->ymin; y < tile_rect->ymax; y++) { - float *output_elem = output_buf->get_elem(tile_rect->xmin, y); - if (is_complex) { - for (int x = tile_rect->xmin; x < tile_rect->xmax; x++) { - read(output_elem, x, y, tile_data); - output_elem += elem_stride; - } - } - else { - for (int x = tile_rect->xmin; x < tile_rect->xmax; x++) { - read_sampled(output_elem, x, y, PixelSampler::Nearest); - output_elem += elem_stride; - } - } - } - if (tile_data) { - deinitialize_tile_data(tile_rect, tile_data); - } -} - -Vector NodeOperation::replace_inputs_with_buffers( - Span inputs_bufs) -{ - BLI_assert(inputs_bufs.size() == get_number_of_input_sockets()); - Vector orig_links(inputs_bufs.size()); - for (int i = 0; i < inputs_bufs.size(); i++) { - NodeOperationInput *input_socket = get_input_socket(i); - BufferOperation *buffer_op = new BufferOperation(inputs_bufs[i], - input_socket->get_data_type()); - orig_links[i] = input_socket->get_link(); - input_socket->set_link(buffer_op->get_output_socket()); - buffer_op->init_execution(); - } - return orig_links; -} - -void NodeOperation::remove_buffers_and_restore_original_inputs( - Span original_inputs_links) -{ - BLI_assert(original_inputs_links.size() == get_number_of_input_sockets()); - for (int i = 0; i < original_inputs_links.size(); i++) { - NodeOperation *buffer_op = get_input_operation(i); - BLI_assert(buffer_op != nullptr); - BLI_assert(typeid(*buffer_op) == typeid(BufferOperation)); - buffer_op->deinit_execution(); - NodeOperationInput *input_socket = get_input_socket(i); - input_socket->set_link(original_inputs_links[i]); - delete buffer_op; - } -} - /** \} */ /***************** @@ -444,15 +289,6 @@ void NodeOperationOutput::determine_canvas(const rcti &preferred_area, rcti &r_a std::ostream &operator<<(std::ostream &os, const NodeOperationFlags &node_operation_flags) { - if (node_operation_flags.complex) { - os << "complex,"; - } - if (node_operation_flags.open_cl) { - os << "open_cl,"; - } - if (node_operation_flags.single_threaded) { - os << "single_threaded,"; - } if (node_operation_flags.use_render_border) { os << "render_border,"; } @@ -465,12 +301,6 @@ std::ostream &operator<<(std::ostream &os, const NodeOperationFlags &node_operat if (node_operation_flags.is_set_operation) { os << "set_operation,"; } - if (node_operation_flags.is_write_buffer_operation) { - os << "write_buffer,"; - } - if (node_operation_flags.is_read_buffer_operation) { - os << "read_buffer,"; - } if (node_operation_flags.is_proxy_operation) { os << "proxy,"; } @@ -483,9 +313,6 @@ std::ostream &operator<<(std::ostream &os, const NodeOperationFlags &node_operat if (!node_operation_flags.use_datatype_conversion) { os << "no_conversion,"; } - if (node_operation_flags.is_fullframe_operation) { - os << "full_frame,"; - } if (node_operation_flags.is_constant_operation) { os << "contant_operation,"; } @@ -505,16 +332,6 @@ std::ostream &operator<<(std::ostream &os, const NodeOperation &node_operation) os << ",name=" << node_operation.get_name(); } os << ",flags={" << flags << "}"; - if (flags.is_read_buffer_operation) { - const ReadBufferOperation *read_operation = (const ReadBufferOperation *)&node_operation; - const MemoryProxy *proxy = read_operation->get_memory_proxy(); - if (proxy) { - const WriteBufferOperation *write_operation = proxy->get_write_buffer_operation(); - if (write_operation) { - os << ",write=" << (NodeOperation &)*write_operation; - } - } - } os << ")"; return os; diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h index 9062602c32e..b68b4d67bd1 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.h +++ b/source/blender/compositor/intern/COM_NodeOperation.h @@ -22,14 +22,10 @@ #include "BKE_node.hh" #include "BKE_node_runtime.hh" -#include "clew.h" - #include "DNA_node_types.h" namespace blender::compositor { -class OpenCLDevice; -class ReadBufferOperation; class ExecutionSystem; class NodeOperation; class NodeOperationOutput; @@ -165,28 +161,6 @@ class NodeOperationOutput { }; struct NodeOperationFlags { - /** - * Is this an complex operation. - * - * The input and output buffers of Complex operations are stored in buffers. It allows - * sequential and read/write. - * - * Complex operations are typically doing many reads to calculate the output of a single pixel. - * Mostly Filter types (Blurs, Convolution, Defocus etc) need this to be set to true. - */ - bool complex : 1; - - /** - * Does this operation support OpenCL. - */ - bool open_cl : 1; - - /** - * TODO: Remove this flag and #SingleThreadedOperation if tiled implementation is removed. - * Full-frame implementation doesn't need it. - */ - bool single_threaded : 1; - /** * Does the operation needs a viewer border. * Basically, setting border need to happen for only operations @@ -214,8 +188,6 @@ struct NodeOperationFlags { * TODO: To be replaced by is_constant_operation flag once tiled implementation is removed. */ bool is_set_operation : 1; - bool is_write_buffer_operation : 1; - bool is_read_buffer_operation : 1; bool is_proxy_operation : 1; bool is_viewer_operation : 1; bool is_preview_operation : 1; @@ -228,11 +200,6 @@ struct NodeOperationFlags { */ bool use_datatype_conversion : 1; - /** - * Has this operation fullframe implementation. - */ - bool is_fullframe_operation : 1; - /** * Whether operation is a primitive constant operation (Color/Vector/Value). */ @@ -246,20 +213,14 @@ struct NodeOperationFlags { NodeOperationFlags() { - complex = false; - single_threaded = false; - open_cl = false; use_render_border = false; use_viewer_border = false; is_canvas_set = false; is_set_operation = false; - is_read_buffer_operation = false; - is_write_buffer_operation = false; is_proxy_operation = false; is_viewer_operation = false; is_preview_operation = false; use_datatype_conversion = true; - is_fullframe_operation = false; is_constant_operation = false; can_be_constant = false; } @@ -326,28 +287,12 @@ class NodeOperation { std::function modify_determined_canvas_fn_; - /** - * \brief mutex reference for very special node initializations - * \note only use when you really know what you are doing. - * this mutex is used to share data among chunks in the same operation - * \see TonemapOperation for an example of usage - * \see NodeOperation.init_mutex initializes this mutex - * \see NodeOperation.deinit_mutex deinitializes this mutex - * \see NodeOperation.get_mutex retrieve a pointer to this mutex. - */ - ThreadMutex mutex_; - /** * \brief reference to the editing bNodeTree, used for break and update callback */ const bNodeTree *btree_; protected: - /** - * Compositor execution model. - */ - eExecutionModel execution_model_; - rcti canvas_ = COM_AREA_NONE; /** @@ -441,11 +386,6 @@ class NodeOperation { return false; } - void set_execution_model(const eExecutionModel model) - { - execution_model_ = model; - } - void set_bnodetree(const bNodeTree *tree) { btree_ = tree; @@ -464,58 +404,6 @@ class NodeOperation { virtual void init_execution(); - /** - * \brief when a chunk is executed by a CPUDevice, this method is called - * \ingroup execution - * \param rect: the rectangle of the chunk (location and size) - * \param chunk_number: the chunk_number to be calculated - * \param memory_buffers: all input MemoryBuffer's needed - */ - virtual void execute_region(rcti * /*rect*/, unsigned int /*chunk_number*/) {} - - /** - * \brief when a chunk is executed by an OpenCLDevice, this method is called - * \ingroup execution - * \note this method is only implemented in WriteBufferOperation - * \param context: the OpenCL context - * \param program: the OpenCL program containing all compositor kernels - * \param queue: the OpenCL command queue of the device the chunk is executed on - * \param rect: the rectangle of the chunk (location and size) - * \param chunk_number: the chunk_number to be calculated - * \param memory_buffers: all input MemoryBuffer's needed - * \param output_buffer: the output-buffer to write to - */ - virtual void execute_opencl_region(OpenCLDevice * /*device*/, - rcti * /*rect*/, - unsigned int /*chunk_number*/, - MemoryBuffer ** /*memory_buffers*/, - MemoryBuffer * /*output_buffer*/) - { - } - - /** - * \brief custom handle to add new tasks to the OpenCL command queue - * in order to execute a chunk on an GPUDevice. - * \ingroup execution - * \param context: the OpenCL context - * \param program: the OpenCL program containing all compositor kernels - * \param queue: the OpenCL command queue of the device the chunk is executed on - * \param output_memory_buffer: the allocated memory buffer in main CPU memory - * \param cl_output_buffer: the allocated memory buffer in OpenCLDevice memory - * \param input_memory_buffers: all input MemoryBuffer's needed - * \param cl_mem_to_clean_up: all created cl_mem references must be added to this list. - * Framework will clean this after execution - * \param cl_kernels_to_clean_up: all created cl_kernel references must be added to this list. - * Framework will clean this after execution - */ - virtual void execute_opencl(OpenCLDevice * /*device*/, - MemoryBuffer * /*output_memory_buffer*/, - cl_mem /*cl_output_buffer*/, - MemoryBuffer ** /*input_memory_buffers*/, - std::list * /*cl_mem_to_clean_up*/, - std::list * /*cl_kernels_to_clean_up*/) - { - } virtual void deinit_execution(); void set_canvas(const rcti &canvas_area); @@ -538,10 +426,6 @@ class NodeOperation { return false; } - virtual bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output); - /** * \brief set the index of the input socket that will determine the canvas of this * operation \param index: the index to set @@ -589,36 +473,6 @@ class NodeOperation { return BLI_rcti_size_y(&get_canvas()); } - inline void read_sampled(float result[4], float x, float y, PixelSampler sampler) - { - execute_pixel_sampled(result, x, y, sampler); - } - - inline void read_filtered(float result[4], float x, float y, float dx[2], float dy[2]) - { - execute_pixel_filtered(result, x, y, dx, dy); - } - - inline void read(float result[4], int x, int y, void *chunk_data) - { - execute_pixel(result, x, y, chunk_data); - } - - inline void read_clamped(float result[4], int x, int y, void *chunk_data) - { - execute_pixel(result, - math::clamp(x, 0, int(this->get_width()) - 1), - math::clamp(y, 0, int(this->get_height()) - 1), - chunk_data); - } - - virtual void *initialize_tile_data(rcti * /*rect*/) - { - return 0; - } - - virtual void deinitialize_tile_data(rcti * /*rect*/, void * /*data*/) {} - virtual MemoryBuffer *get_input_memory_buffer(MemoryBuffer ** /*memory_buffers*/) { return 0; @@ -704,85 +558,9 @@ class NodeOperation { void add_input_socket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center); void add_output_socket(DataType datatype); - /* TODO(manzanilla): to be removed with tiled implementation. */ - void set_width(unsigned int width) - { - canvas_.xmax = canvas_.xmin + width; - flags_.is_canvas_set = true; - } - void set_height(unsigned int height) - { - canvas_.ymax = canvas_.ymin + height; - flags_.is_canvas_set = true; - } - SocketReader *get_input_socket_reader(unsigned int index); - void deinit_mutex(); - void init_mutex(); - void lock_mutex(); - void unlock_mutex(); - - /** - * \brief set whether this operation is complex - * - * Complex operations are typically doing many reads to calculate the output of a single pixel. - * Mostly Filter types (Blurs, Convolution, Defocus etc) need this to be set to true. - */ - void set_complex(bool complex) - { - flags_.complex = complex; - } - - /** - * \brief calculate a single pixel - * \note this method is called for non-complex - * \param result: is a float[4] array to store the result - * \param x: the x-coordinate of the pixel to calculate in image space - * \param y: the y-coordinate of the pixel to calculate in image space - * \param input_buffers: chunks that can be read by their ReadBufferOperation. - */ - virtual void execute_pixel_sampled(float /*output*/[4], - float /*x*/, - float /*y*/, - PixelSampler /*sampler*/) - { - } - - /** - * \brief calculate a single pixel - * \note this method is called for complex - * \param result: is a float[4] array to store the result - * \param x: the x-coordinate of the pixel to calculate in image space - * \param y: the y-coordinate of the pixel to calculate in image space - * \param input_buffers: chunks that can be read by their ReadBufferOperation. - * \param chunk_data: chunk specific data a during execution time. - */ - virtual void execute_pixel(float output[4], int x, int y, void * /*chunk_data*/) - { - execute_pixel_sampled(output, x, y, PixelSampler::Nearest); - } - - /** - * \brief calculate a single pixel using an EWA filter - * \note this method is called for complex - * \param result: is a float[4] array to store the result - * \param x: the x-coordinate of the pixel to calculate in image space - * \param y: the y-coordinate of the pixel to calculate in image space - * \param dx: - * \param dy: - * \param input_buffers: chunks that can be read by their ReadBufferOperation. - */ - virtual void execute_pixel_filtered( - float /*output*/[4], float /*x*/, float /*y*/, float /*dx*/[2], float /*dy*/[2]) - { - } - private: - /* -------------------------------------------------------------------- */ - /** \name Full Frame Methods - * \{ */ - /** * Renders given areas using operations full frame implementation. */ @@ -790,22 +568,6 @@ class NodeOperation { Span areas, Span inputs_bufs); - /** - * Renders given areas using operations tiled implementation. - */ - void render_full_frame_fallback(MemoryBuffer *output_buf, - Span areas, - Span inputs); - void render_tile(MemoryBuffer *output_buf, rcti *tile_rect); - /** - * \return Replaced inputs links. - */ - Vector replace_inputs_with_buffers(Span inputs_bufs); - void remove_buffers_and_restore_original_inputs( - Span original_inputs_links); - - /** \} */ - /* allow the DebugInfo class to look at internals */ friend class DebugInfo; diff --git a/source/blender/compositor/intern/COM_NodeOperationBuilder.cc b/source/blender/compositor/intern/COM_NodeOperationBuilder.cc index c3174c351eb..6afac170ba1 100644 --- a/source/blender/compositor/intern/COM_NodeOperationBuilder.cc +++ b/source/blender/compositor/intern/COM_NodeOperationBuilder.cc @@ -11,14 +11,11 @@ #include "COM_Converter.h" #include "COM_Debug.h" -#include "COM_ExecutionGroup.h" #include "COM_PreviewOperation.h" -#include "COM_ReadBufferOperation.h" #include "COM_SetColorOperation.h" #include "COM_SetValueOperation.h" #include "COM_SetVectorOperation.h" #include "COM_ViewerOperation.h" -#include "COM_WriteBufferOperation.h" #include "COM_ConstantFolder.h" #include "COM_NodeOperationBuilder.h" /* own include */ @@ -84,22 +81,15 @@ void NodeOperationBuilder::convert_to_operations(ExecutionSystem *system) add_datatype_conversions(); - if (context_->get_execution_model() == eExecutionModel::FullFrame) { - save_graphviz("compositor_prior_folding"); - ConstantFolder folder(*this); - folder.fold_operations(); - } + save_graphviz("compositor_prior_folding"); + ConstantFolder folder(*this); + folder.fold_operations(); determine_canvases(); save_graphviz("compositor_prior_merging"); merge_equal_operations(); - if (context_->get_execution_model() == eExecutionModel::Tiled) { - /* surround complex ops with read/write buffer */ - add_complex_operation_buffers(); - } - /* links not available from here on */ /* XXX make links_ a local variable to avoid confusion! */ links_.clear(); @@ -109,13 +99,8 @@ void NodeOperationBuilder::convert_to_operations(ExecutionSystem *system) /* ensure topological (link-based) order of nodes */ // sort_operations(); /* not needed yet. */ - if (context_->get_execution_model() == eExecutionModel::Tiled) { - /* create execution groups */ - group_operations(); - } - /* transfer resulting operations to the system */ - system->set_operations(operations_, groups_); + system->set_operations(operations_); } void NodeOperationBuilder::add_operation(NodeOperation *operation) @@ -126,7 +111,6 @@ void NodeOperationBuilder::add_operation(NodeOperation *operation) operation->set_name(current_node_->get_bnode()->name); operation->set_node_instance_key(current_node_->get_instance_key()); } - operation->set_execution_model(context_->get_execution_model()); operation->set_execution_system(exec_system_); } @@ -517,133 +501,6 @@ Vector NodeOperationBuilder::cache_output_links( return inputs; } -WriteBufferOperation *NodeOperationBuilder::find_attached_write_buffer_operation( - NodeOperationOutput *output) const -{ - for (const Link &link : links_) { - if (link.from() == output) { - NodeOperation &op = link.to()->get_operation(); - if (op.get_flags().is_write_buffer_operation) { - return (WriteBufferOperation *)(&op); - } - } - } - return nullptr; -} - -void NodeOperationBuilder::add_input_buffers(NodeOperation * /*operation*/, - NodeOperationInput *input) -{ - if (!input->is_connected()) { - return; - } - - NodeOperationOutput *output = input->get_link(); - if (output->get_operation().get_flags().is_read_buffer_operation) { - /* input is already buffered, no need to add another */ - return; - } - - /* this link will be replaced below */ - remove_input_link(input); - - /* check of other end already has write operation, otherwise add a new one */ - WriteBufferOperation *writeoperation = find_attached_write_buffer_operation(output); - if (!writeoperation) { - writeoperation = new WriteBufferOperation(output->get_data_type()); - writeoperation->set_bnodetree(context_->get_bnodetree()); - add_operation(writeoperation); - - add_link(output, writeoperation->get_input_socket(0)); - - writeoperation->read_resolution_from_input_socket(); - } - - /* add readbuffer op for the input */ - ReadBufferOperation *readoperation = new ReadBufferOperation(output->get_data_type()); - readoperation->set_memory_proxy(writeoperation->get_memory_proxy()); - this->add_operation(readoperation); - - add_link(readoperation->get_output_socket(), input); - - readoperation->read_resolution_from_write_buffer(); -} - -void NodeOperationBuilder::add_output_buffers(NodeOperation *operation, - NodeOperationOutput *output) -{ - /* cache connected sockets, so we can safely remove links first before replacing them */ - Vector targets = cache_output_links(output); - if (targets.is_empty()) { - return; - } - - WriteBufferOperation *write_operation = nullptr; - for (NodeOperationInput *target : targets) { - /* try to find existing write buffer operation */ - if (target->get_operation().get_flags().is_write_buffer_operation) { - BLI_assert(write_operation == nullptr); /* there should only be one write op connected */ - write_operation = (WriteBufferOperation *)&target->get_operation(); - } - else { - /* remove all links to other nodes */ - remove_input_link(target); - } - } - - /* if no write buffer operation exists yet, create a new one */ - if (!write_operation) { - write_operation = new WriteBufferOperation(operation->get_output_socket()->get_data_type()); - write_operation->set_bnodetree(context_->get_bnodetree()); - add_operation(write_operation); - - add_link(output, write_operation->get_input_socket(0)); - } - - write_operation->read_resolution_from_input_socket(); - - /* add readbuffer op for every former connected input */ - for (NodeOperationInput *target : targets) { - if (&target->get_operation() == write_operation) { - continue; /* skip existing write op links */ - } - - ReadBufferOperation *readoperation = new ReadBufferOperation( - operation->get_output_socket()->get_data_type()); - readoperation->set_memory_proxy(write_operation->get_memory_proxy()); - add_operation(readoperation); - - add_link(readoperation->get_output_socket(), target); - - readoperation->read_resolution_from_write_buffer(); - } -} - -void NodeOperationBuilder::add_complex_operation_buffers() -{ - /* NOTE: complex ops and get cached here first, since adding operations - * will invalidate iterators over the main operations_ - */ - Vector complex_ops; - for (NodeOperation *operation : operations_) { - if (operation->get_flags().complex) { - complex_ops.append(operation); - } - } - - for (NodeOperation *op : complex_ops) { - DebugInfo::operation_read_write_buffer(op); - - for (int index = 0; index < op->get_number_of_input_sockets(); index++) { - add_input_buffers(op, op->get_input_socket(index)); - } - - for (int index = 0; index < op->get_number_of_output_sockets(); index++) { - add_output_buffers(op, op->get_output_socket(index)); - } - } -} - using Tags = std::set; static void find_reachable_operations_recursive(Tags &reachable, NodeOperation *op) @@ -659,13 +516,6 @@ static void find_reachable_operations_recursive(Tags &reachable, NodeOperation * find_reachable_operations_recursive(reachable, &input->get_link()->get_operation()); } } - - /* associated write-buffer operations are executed as well */ - if (op->get_flags().is_read_buffer_operation) { - ReadBufferOperation *read_op = (ReadBufferOperation *)op; - MemoryProxy *memproxy = read_op->get_memory_proxy(); - find_reachable_operations_recursive(reachable, memproxy->get_write_buffer_operation()); - } } void NodeOperationBuilder::prune_operations() @@ -725,62 +575,10 @@ void NodeOperationBuilder::sort_operations() operations_ = sorted; } -static void add_group_operations_recursive(Tags &visited, NodeOperation *op, ExecutionGroup *group) -{ - if (visited.find(op) != visited.end()) { - return; - } - visited.insert(op); - - if (!group->add_operation(op)) { - return; - } - - /* add all eligible input ops to the group */ - for (int i = 0; i < op->get_number_of_input_sockets(); i++) { - NodeOperationInput *input = op->get_input_socket(i); - if (input->is_connected()) { - add_group_operations_recursive(visited, &input->get_link()->get_operation(), group); - } - } -} - -ExecutionGroup *NodeOperationBuilder::make_group(NodeOperation *op) -{ - ExecutionGroup *group = new ExecutionGroup(groups_.size()); - groups_.append(group); - - Tags visited; - add_group_operations_recursive(visited, op, group); - - return group; -} - -void NodeOperationBuilder::group_operations() -{ - for (NodeOperation *op : operations_) { - if (op->is_output_operation(context_->is_rendering())) { - ExecutionGroup *group = make_group(op); - group->set_output_execution_group(true); - } - - /* add new groups for associated memory proxies where needed */ - if (op->get_flags().is_read_buffer_operation) { - ReadBufferOperation *read_op = (ReadBufferOperation *)op; - MemoryProxy *memproxy = read_op->get_memory_proxy(); - - if (memproxy->get_executor() == nullptr) { - ExecutionGroup *group = make_group(memproxy->get_write_buffer_operation()); - memproxy->set_executor(group); - } - } - } -} - void NodeOperationBuilder::save_graphviz(StringRefNull name) { if (COM_EXPORT_GRAPHVIZ) { - exec_system_->set_operations(operations_, groups_); + exec_system_->set_operations(operations_); DebugInfo::graphviz(exec_system_, name); } } @@ -800,15 +598,6 @@ std::ostream &operator<<(std::ostream &os, const NodeOperationBuilder &builder) os << " op" << link.from()->get_operation().get_id() << " -> op" << link.to()->get_operation().get_id() << ";\n"; } - for (const NodeOperation *operation : builder.get_operations()) { - if (operation->get_flags().is_read_buffer_operation) { - const ReadBufferOperation &read_operation = static_cast( - *operation); - const WriteBufferOperation &write_operation = - *read_operation.get_memory_proxy()->get_write_buffer_operation(); - os << " op" << write_operation.get_id() << " -> op" << read_operation.get_id() << ";\n"; - } - } os << "}\n"; os << "# Builder end\n"; diff --git a/source/blender/compositor/intern/COM_NodeOperationBuilder.h b/source/blender/compositor/intern/COM_NodeOperationBuilder.h index 2d9f4a2ce4e..4d2d652ca54 100644 --- a/source/blender/compositor/intern/COM_NodeOperationBuilder.h +++ b/source/blender/compositor/intern/COM_NodeOperationBuilder.h @@ -18,13 +18,11 @@ class NodeInput; class NodeOutput; class ExecutionSystem; -class ExecutionGroup; class NodeOperation; class NodeOperationInput; class NodeOperationOutput; class PreviewOperation; -class WriteBufferOperation; class ViewerOperation; class ConstantOperation; @@ -55,7 +53,6 @@ class NodeOperationBuilder { Vector operations_; Vector links_; - Vector groups_; /** Maps operation inputs to node inputs */ Map input_map_; @@ -133,12 +130,6 @@ class NodeOperationBuilder { /** Helper function to store connected inputs for replacement */ Vector cache_output_links(NodeOperationOutput *output) const; - /** Find a connected write buffer operation to an OpOutput */ - WriteBufferOperation *find_attached_write_buffer_operation(NodeOperationOutput *output) const; - /** Add read/write buffer operations around complex operations */ - void add_complex_operation_buffers(); - void add_input_buffers(NodeOperation *operation, NodeOperationInput *input); - void add_output_buffers(NodeOperation *operation, NodeOperationOutput *output); /** Remove unreachable operations */ void prune_operations(); @@ -146,10 +137,6 @@ class NodeOperationBuilder { /** Sort operations by link dependencies */ void sort_operations(); - /** Create execution groups */ - void group_operations(); - ExecutionGroup *make_group(NodeOperation *op); - private: PreviewOperation *make_preview_operation() const; void unlink_inputs_and_relink_outputs(NodeOperation *unlinked_op, NodeOperation *linked_op); diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cc b/source/blender/compositor/intern/COM_OpenCLDevice.cc deleted file mode 100644 index c2f6de56dfc..00000000000 --- a/source/blender/compositor/intern/COM_OpenCLDevice.cc +++ /dev/null @@ -1,271 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_OpenCLDevice.h" - -#include "COM_ExecutionGroup.h" -#include "COM_ReadBufferOperation.h" - -namespace blender::compositor { - -enum COM_VendorID { NVIDIA = 0x10DE, AMD = 0x1002 }; -const cl_image_format IMAGE_FORMAT_COLOR = { - CL_RGBA, - CL_FLOAT, -}; -const cl_image_format IMAGE_FORMAT_VECTOR = { - CL_RGB, - CL_FLOAT, -}; -const cl_image_format IMAGE_FORMAT_VALUE = { - CL_R, - CL_FLOAT, -}; - -OpenCLDevice::OpenCLDevice(cl_context context, - cl_device_id device, - cl_program program, - cl_int vendor_id) -{ - device_ = device; - context_ = context; - program_ = program; - queue_ = nullptr; - vendor_id_ = vendor_id; - - cl_int error; - queue_ = clCreateCommandQueue(context_, device_, 0, &error); -} - -OpenCLDevice::OpenCLDevice(OpenCLDevice &&other) noexcept - : context_(other.context_), - device_(other.device_), - program_(other.program_), - queue_(other.queue_), - vendor_id_(other.vendor_id_) -{ - other.queue_ = nullptr; -} - -OpenCLDevice::~OpenCLDevice() -{ - if (queue_) { - clReleaseCommandQueue(queue_); - } -} - -void OpenCLDevice::execute(WorkPackage *work_package) -{ - const uint chunk_number = work_package->chunk_number; - ExecutionGroup *execution_group = work_package->execution_group; - - MemoryBuffer **input_buffers = execution_group->get_input_buffers_opencl(chunk_number); - MemoryBuffer *output_buffer = execution_group->allocate_output_buffer(work_package->rect); - - execution_group->get_output_operation()->execute_opencl_region( - this, &work_package->rect, chunk_number, input_buffers, output_buffer); - - delete output_buffer; - - execution_group->finalize_chunk_execution(chunk_number, input_buffers); -} -cl_mem OpenCLDevice::COM_cl_attach_memory_buffer_to_kernel_parameter( - cl_kernel kernel, - int parameter_index, - int offset_index, - std::list *cleanup, - MemoryBuffer **input_memory_buffers, - SocketReader *reader) -{ - return COM_cl_attach_memory_buffer_to_kernel_parameter(kernel, - parameter_index, - offset_index, - cleanup, - input_memory_buffers, - (ReadBufferOperation *)reader); -} - -const cl_image_format *OpenCLDevice::determine_image_format(MemoryBuffer *memory_buffer) -{ - switch (memory_buffer->get_num_channels()) { - case 1: - return &IMAGE_FORMAT_VALUE; - break; - case 3: - return &IMAGE_FORMAT_VECTOR; - break; - case 4: - return &IMAGE_FORMAT_COLOR; - break; - default: - BLI_assert_msg(0, "Unsupported num_channels."); - } - - return &IMAGE_FORMAT_COLOR; -} - -cl_mem OpenCLDevice::COM_cl_attach_memory_buffer_to_kernel_parameter( - cl_kernel kernel, - int parameter_index, - int offset_index, - std::list *cleanup, - MemoryBuffer **input_memory_buffers, - ReadBufferOperation *reader) -{ - cl_int error; - - MemoryBuffer *result = reader->get_input_memory_buffer(input_memory_buffers); - - const cl_image_format *image_format = determine_image_format(result); - - cl_mem cl_buffer = clCreateImage2D(context_, - CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, - image_format, - result->get_width(), - result->get_height(), - 0, - result->get_buffer(), - &error); - - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - if (error == CL_SUCCESS) { - cleanup->push_back(cl_buffer); - } - - error = clSetKernelArg(kernel, parameter_index, sizeof(cl_mem), &cl_buffer); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - - COM_cl_attach_memory_buffer_offset_to_kernel_parameter(kernel, offset_index, result); - return cl_buffer; -} - -void OpenCLDevice::COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - cl_kernel kernel, int offset_index, MemoryBuffer *memory_buffer) -{ - if (offset_index != -1) { - cl_int error; - const rcti &rect = memory_buffer->get_rect(); - cl_int2 offset = {{rect.xmin, rect.ymin}}; - - error = clSetKernelArg(kernel, offset_index, sizeof(cl_int2), &offset); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - } -} - -void OpenCLDevice::COM_cl_attach_size_to_kernel_parameter(cl_kernel kernel, - int offset_index, - NodeOperation *operation) -{ - if (offset_index != -1) { - cl_int error; - cl_int2 offset = {{(cl_int)operation->get_width(), (cl_int)operation->get_height()}}; - - error = clSetKernelArg(kernel, offset_index, sizeof(cl_int2), &offset); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - } -} - -void OpenCLDevice::COM_cl_attach_output_memory_buffer_to_kernel_parameter( - cl_kernel kernel, int parameter_index, cl_mem cl_output_memory_buffer) -{ - cl_int error; - error = clSetKernelArg(kernel, parameter_index, sizeof(cl_mem), &cl_output_memory_buffer); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } -} - -void OpenCLDevice::COM_cl_enqueue_range(cl_kernel kernel, MemoryBuffer *output_memory_buffer) -{ - cl_int error; - const size_t size[] = { - size_t(output_memory_buffer->get_width()), - size_t(output_memory_buffer->get_height()), - }; - - error = clEnqueueNDRangeKernel(queue_, kernel, 2, nullptr, size, nullptr, 0, nullptr, nullptr); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } -} - -void OpenCLDevice::COM_cl_enqueue_range(cl_kernel kernel, - MemoryBuffer *output_memory_buffer, - int offset_index, - NodeOperation *operation) -{ - cl_int error; - const int width = output_memory_buffer->get_width(); - const int height = output_memory_buffer->get_height(); - int offsetx; - int offsety; - int local_size = 1024; - size_t size[2]; - cl_int2 offset; - - if (vendor_id_ == NVIDIA) { - local_size = 32; - } - - bool breaked = false; - for (offsety = 0; offsety < height && (!breaked); offsety += local_size) { - offset.s[1] = offsety; - if (offsety + local_size < height) { - size[1] = local_size; - } - else { - size[1] = height - offsety; - } - - for (offsetx = 0; offsetx < width && (!breaked); offsetx += local_size) { - if (offsetx + local_size < width) { - size[0] = local_size; - } - else { - size[0] = width - offsetx; - } - offset.s[0] = offsetx; - - error = clSetKernelArg(kernel, offset_index, sizeof(cl_int2), &offset); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - error = clEnqueueNDRangeKernel( - queue_, kernel, 2, nullptr, size, nullptr, 0, nullptr, nullptr); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - clFlush(queue_); - if (operation->is_braked()) { - breaked = false; - } - } - } -} - -cl_kernel OpenCLDevice::COM_cl_create_kernel(const char *kernelname, - std::list *cl_kernels_to_clean_up) -{ - cl_int error; - cl_kernel kernel = clCreateKernel(program_, kernelname, &error); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - else { - if (cl_kernels_to_clean_up) { - cl_kernels_to_clean_up->push_back(kernel); - } - } - return kernel; -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.h b/source/blender/compositor/intern/COM_OpenCLDevice.h deleted file mode 100644 index 89acd9fcd84..00000000000 --- a/source/blender/compositor/intern/COM_OpenCLDevice.h +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -class OpenCLDevice; - -#pragma once - -#include - -#include "COM_Device.h" - -#include "clew.h" - -namespace blender::compositor { - -class NodeOperation; -class MemoryBuffer; -class ReadBufferOperation; - -typedef NodeOperation SocketReader; - -/** - * \brief device representing an GPU OpenCL device. - * an instance of this class represents a single cl_device - */ -class OpenCLDevice : public Device { - private: - /** - * \brief OPENCL context - */ - cl_context context_; - - /** - * \brief OPENCL device - */ - cl_device_id device_; - - /** - * \brief OPENCL program - */ - cl_program program_; - - /** - * \brief OPENCL command queue - */ - cl_command_queue queue_; - - /** - * \brief OPENCL vendor ID - */ - cl_int vendor_id_; - - public: - /** - * \brief constructor with OPENCL device - * \param context: - * \param device: - * \param program: - * \param vendorID: - */ - OpenCLDevice(cl_context context, cl_device_id device, cl_program program, cl_int vendor_id); - - OpenCLDevice(OpenCLDevice &&other) noexcept; - - ~OpenCLDevice(); - - /** - * \brief execute a WorkPackage - * \param work: the WorkPackage to execute - */ - void execute(WorkPackage *work) override; - - /** - * \brief determine an image format - * \param memorybuffer: - */ - static const cl_image_format *determine_image_format(MemoryBuffer *memory_buffer); - - cl_context get_context() - { - return context_; - } - - cl_command_queue get_queue() - { - return queue_; - } - - cl_mem COM_cl_attach_memory_buffer_to_kernel_parameter(cl_kernel kernel, - int parameter_index, - int offset_index, - std::list *cleanup, - MemoryBuffer **input_memory_buffers, - SocketReader *reader); - cl_mem COM_cl_attach_memory_buffer_to_kernel_parameter(cl_kernel kernel, - int parameter_index, - int offset_index, - std::list *cleanup, - MemoryBuffer **input_memory_buffers, - ReadBufferOperation *reader); - void COM_cl_attach_memory_buffer_offset_to_kernel_parameter(cl_kernel kernel, - int offset_index, - MemoryBuffer *memory_buffers); - void COM_cl_attach_output_memory_buffer_to_kernel_parameter(cl_kernel kernel, - int parameter_index, - cl_mem cl_output_memory_buffer); - void COM_cl_attach_size_to_kernel_parameter(cl_kernel kernel, - int offset_index, - NodeOperation *operation); - void COM_cl_enqueue_range(cl_kernel kernel, MemoryBuffer *output_memory_buffer); - void COM_cl_enqueue_range(cl_kernel kernel, - MemoryBuffer *output_memory_buffer, - int offset_index, - NodeOperation *operation); - cl_kernel COM_cl_create_kernel(const char *kernelname, - std::list *cl_kernels_to_clean_up); -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_SingleThreadedOperation.cc b/source/blender/compositor/intern/COM_SingleThreadedOperation.cc deleted file mode 100644 index 22b6224434f..00000000000 --- a/source/blender/compositor/intern/COM_SingleThreadedOperation.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_SingleThreadedOperation.h" - -namespace blender::compositor { - -SingleThreadedOperation::SingleThreadedOperation() -{ - cached_instance_ = nullptr; - flags_.complex = true; - flags_.single_threaded = true; -} - -void SingleThreadedOperation::init_execution() -{ - init_mutex(); -} - -void SingleThreadedOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - cached_instance_->read_no_check(output, x, y); -} - -void SingleThreadedOperation::deinit_execution() -{ - deinit_mutex(); - if (cached_instance_) { - delete cached_instance_; - cached_instance_ = nullptr; - } -} -void *SingleThreadedOperation::initialize_tile_data(rcti *rect) -{ - if (cached_instance_) { - return cached_instance_; - } - - lock_mutex(); - if (cached_instance_ == nullptr) { - // - cached_instance_ = create_memory_buffer(rect); - } - unlock_mutex(); - return cached_instance_; -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_SingleThreadedOperation.h b/source/blender/compositor/intern/COM_SingleThreadedOperation.h deleted file mode 100644 index 1cdbcd931b6..00000000000 --- a/source/blender/compositor/intern/COM_SingleThreadedOperation.h +++ /dev/null @@ -1,44 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_NodeOperation.h" - -namespace blender::compositor { - -class SingleThreadedOperation : public NodeOperation { - private: - MemoryBuffer *cached_instance_; - - protected: - inline bool is_cached() - { - return cached_instance_ != nullptr; - } - - public: - SingleThreadedOperation(); - - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - - virtual MemoryBuffer *create_memory_buffer(rcti *rect) = 0; -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_TiledExecutionModel.cc b/source/blender/compositor/intern/COM_TiledExecutionModel.cc deleted file mode 100644 index 024673af965..00000000000 --- a/source/blender/compositor/intern/COM_TiledExecutionModel.cc +++ /dev/null @@ -1,148 +0,0 @@ -/* SPDX-FileCopyrightText: 2021 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_TiledExecutionModel.h" -#include "COM_Debug.h" -#include "COM_ExecutionGroup.h" -#include "COM_ReadBufferOperation.h" -#include "COM_WorkScheduler.h" - -#include "BLT_translation.hh" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -namespace blender::compositor { - -TiledExecutionModel::TiledExecutionModel(CompositorContext &context, - Span operations, - Span groups) - : ExecutionModel(context, operations), groups_(groups) -{ - const bNodeTree *node_tree = context.get_bnodetree(); - node_tree->runtime->stats_draw(node_tree->runtime->sdh, - RPT_("Compositing | Determining resolution")); - - uint resolution[2]; - for (ExecutionGroup *group : groups_) { - resolution[0] = 0; - resolution[1] = 0; - group->determine_resolution(resolution); - - if (border_.use_render_border) { - const rctf *render_border = border_.render_border; - group->set_render_border( - render_border->xmin, render_border->xmax, render_border->ymin, render_border->ymax); - } - - if (border_.use_viewer_border) { - const rctf *viewer_border = border_.viewer_border; - group->set_viewer_border( - viewer_border->xmin, viewer_border->xmax, viewer_border->ymin, viewer_border->ymax); - } - } -} - -static void update_read_buffer_offset(Span operations) -{ - uint order = 0; - for (NodeOperation *operation : operations) { - if (operation->get_flags().is_read_buffer_operation) { - ReadBufferOperation *read_operation = (ReadBufferOperation *)operation; - read_operation->set_offset(order); - order++; - } - } -} - -static void init_write_operations_for_execution(Span operations, - const bNodeTree *bTree) -{ - for (NodeOperation *operation : operations) { - if (operation->get_flags().is_write_buffer_operation) { - operation->set_bnodetree(bTree); - operation->init_execution(); - } - } -} - -static void link_write_buffers(Span operations) -{ - for (NodeOperation *operation : operations) { - if (operation->get_flags().is_read_buffer_operation) { - ReadBufferOperation *read_operation = static_cast(operation); - read_operation->update_memory_buffer(); - } - } -} - -static void init_non_write_operations_for_execution(Span operations, - const bNodeTree *bTree) -{ - for (NodeOperation *operation : operations) { - if (!operation->get_flags().is_write_buffer_operation) { - operation->set_bnodetree(bTree); - operation->init_execution(); - } - } -} - -static void init_execution_groups_for_execution(Span groups, - const int chunk_size) -{ - for (ExecutionGroup *execution_group : groups) { - execution_group->set_chunksize(chunk_size); - execution_group->init_execution(); - } -} - -void TiledExecutionModel::execute(ExecutionSystem &exec_system) -{ - const bNodeTree *editingtree = this->context_.get_bnodetree(); - - editingtree->runtime->stats_draw(editingtree->runtime->sdh, - RPT_("Compositing | Initializing execution")); - - update_read_buffer_offset(operations_); - - init_write_operations_for_execution(operations_, context_.get_bnodetree()); - link_write_buffers(operations_); - init_non_write_operations_for_execution(operations_, context_.get_bnodetree()); - init_execution_groups_for_execution(groups_, context_.get_chunksize()); - - WorkScheduler::start(context_); - execute_groups(eCompositorPriority::High, exec_system); - if (!context_.is_fast_calculation()) { - execute_groups(eCompositorPriority::Medium, exec_system); - execute_groups(eCompositorPriority::Low, exec_system); - } - WorkScheduler::finish(); - WorkScheduler::stop(); - - editingtree->runtime->stats_draw(editingtree->runtime->sdh, - RPT_("Compositing | De-initializing execution")); - - for (NodeOperation *operation : operations_) { - operation->deinit_execution(); - } - - for (ExecutionGroup *execution_group : groups_) { - execution_group->deinit_execution(); - } -} - -void TiledExecutionModel::execute_groups(eCompositorPriority priority, - ExecutionSystem &exec_system) -{ - for (ExecutionGroup *execution_group : groups_) { - if (execution_group->get_flags().is_output && - execution_group->get_render_priority() == priority) - { - execution_group->execute(&exec_system); - } - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_TiledExecutionModel.h b/source/blender/compositor/intern/COM_TiledExecutionModel.h deleted file mode 100644 index d65acf3490a..00000000000 --- a/source/blender/compositor/intern/COM_TiledExecutionModel.h +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-FileCopyrightText: 2021 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_Enums.h" -#include "COM_ExecutionModel.h" - -#ifdef WITH_CXX_GUARDEDALLOC -# include "MEM_guardedalloc.h" -#endif - -namespace blender::compositor { - -class ExecutionGroup; - -/** - * Operations are executed from outputs to inputs grouped in execution groups and rendered in - * tiles. - */ -class TiledExecutionModel : public ExecutionModel { - private: - Span groups_; - - public: - TiledExecutionModel(CompositorContext &context, - Span operations, - Span groups); - - void execute(ExecutionSystem &exec_system) override; - - private: - void execute_groups(eCompositorPriority priority, ExecutionSystem &exec_system); - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:TiledExecutionModel") -#endif -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_WorkPackage.cc b/source/blender/compositor/intern/COM_WorkPackage.cc deleted file mode 100644 index cad3aa75e58..00000000000 --- a/source/blender/compositor/intern/COM_WorkPackage.cc +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_WorkPackage.h" - -#include "COM_ExecutionGroup.h" - -namespace blender::compositor { - -std::ostream &operator<<(std::ostream &os, const WorkPackage &work_package) -{ - os << "WorkPackage(execution_group=" << *work_package.execution_group; - os << ",chunk=" << work_package.chunk_number; - os << ",state=" << work_package.state; - os << ",rect=(" << work_package.rect.xmin << "," << work_package.rect.ymin << ")-(" - << work_package.rect.xmax << "," << work_package.rect.ymax << ")"; - os << ")"; - return os; -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_WorkPackage.h b/source/blender/compositor/intern/COM_WorkPackage.h index bf7824d778c..951eb981977 100644 --- a/source/blender/compositor/intern/COM_WorkPackage.h +++ b/source/blender/compositor/intern/COM_WorkPackage.h @@ -8,43 +8,17 @@ # include "MEM_guardedalloc.h" #endif -#include "COM_Enums.h" - -#include "DNA_vec_types.h" - #include -#include namespace blender::compositor { -/* Forward Declarations. */ -class ExecutionGroup; /** * \brief contains data about work that can be scheduled * \see WorkScheduler */ struct WorkPackage { - eWorkPackageType type; - - eWorkPackageState state = eWorkPackageState::NotScheduled; - /** - * \brief execution_group with the operations-setup to be evaluated - */ - ExecutionGroup *execution_group; - - /** - * \brief number of the chunk to be executed - */ - unsigned int chunk_number; - - /** - * Area of the execution group that the work package calculates. - */ - rcti rect; - - /** - * Custom function to execute when work package type is CustomFunction. + * Called to execute work. */ std::function execute_fn; @@ -58,6 +32,4 @@ struct WorkPackage { #endif }; -std::ostream &operator<<(std::ostream &os, const WorkPackage &work_package); - } // namespace blender::compositor diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cc b/source/blender/compositor/intern/COM_WorkScheduler.cc index 7661fe9938a..af7b9e7509e 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cc +++ b/source/blender/compositor/intern/COM_WorkScheduler.cc @@ -5,13 +5,6 @@ #include "COM_WorkScheduler.h" #include "COM_CPUDevice.h" -#include "COM_CompositorContext.h" -#include "COM_ExecutionGroup.h" -#include "COM_OpenCLDevice.h" -#include "COM_OpenCLKernels.cl.h" -#include "COM_WriteBufferOperation.h" - -#include "clew.h" #include "MEM_guardedalloc.h" @@ -42,14 +35,6 @@ constexpr ThreadingModel COM_threading_model() return ThreadingModel::Queue; } -/** - * Does the active threading model support opencl? - */ -constexpr bool COM_is_opencl_enabled() -{ - return COM_threading_model() != ThreadingModel::SingleThreaded; -} - static ThreadLocal(CPUDevice *) g_thread_device; static struct { struct { @@ -69,222 +54,9 @@ static struct { TaskPool *pool; } task; - struct { - ThreadQueue *queue; - cl_context context; - cl_program program; - /** \brief list of all OpenCLDevices. for every OpenCL GPU device an instance of OpenCLDevice - * is created. */ - Vector devices; - /** \brief list of all thread for every GPUDevice in cpudevices a thread exists. */ - ListBase threads; - /** \brief all scheduled work for the GPU. */ - bool active = false; - bool initialized = false; - } opencl; - int num_cpu_threads; } g_work_scheduler; -/* -------------------------------------------------------------------- */ -/** \name OpenCL Scheduling - * \{ */ - -static void CL_CALLBACK cl_context_error(const char *errinfo, - const void * /*private_info*/, - size_t /*cb*/, - void * /*user_data*/) -{ - printf("OPENCL error: %s\n", errinfo); -} - -static void *thread_execute_gpu(void *data) -{ - Device *device = (Device *)data; - WorkPackage *work; - - while ((work = (WorkPackage *)BLI_thread_queue_pop(g_work_scheduler.opencl.queue))) { - device->execute(work); - } - - return nullptr; -} - -static void opencl_start(const CompositorContext &context) -{ - if (context.get_has_active_opencl_devices()) { - g_work_scheduler.opencl.queue = BLI_thread_queue_init(); - BLI_threadpool_init(&g_work_scheduler.opencl.threads, - thread_execute_gpu, - g_work_scheduler.opencl.devices.size()); - for (Device &device : g_work_scheduler.opencl.devices) { - BLI_threadpool_insert(&g_work_scheduler.opencl.threads, &device); - } - g_work_scheduler.opencl.active = true; - } - else { - g_work_scheduler.opencl.active = false; - } -} - -static bool opencl_schedule(WorkPackage *package) -{ - if (package->type == eWorkPackageType::Tile && package->execution_group->get_flags().open_cl && - g_work_scheduler.opencl.active) - { - BLI_thread_queue_push(g_work_scheduler.opencl.queue, package); - return true; - } - return false; -} - -static void opencl_finish() -{ - if (g_work_scheduler.opencl.active) { - BLI_thread_queue_wait_finish(g_work_scheduler.opencl.queue); - } -} - -static void opencl_stop() -{ - if (g_work_scheduler.opencl.active) { - BLI_thread_queue_nowait(g_work_scheduler.opencl.queue); - BLI_threadpool_end(&g_work_scheduler.opencl.threads); - BLI_thread_queue_free(g_work_scheduler.opencl.queue); - g_work_scheduler.opencl.queue = nullptr; - } -} - -static bool opencl_has_gpu_devices() -{ - return !g_work_scheduler.opencl.devices.is_empty(); -} - -static void opencl_initialize(const bool use_opencl) -{ - /* deinitialize OpenCL GPU's */ - if (use_opencl && !g_work_scheduler.opencl.initialized) { - g_work_scheduler.opencl.context = nullptr; - g_work_scheduler.opencl.program = nullptr; - - /* This will check for errors and skip if already initialized. */ - if (clewInit() != CLEW_SUCCESS) { - return; - } - - if (clCreateContextFromType) { - cl_uint number_of_platforms = 0; - cl_int error; - error = clGetPlatformIDs(0, nullptr, &number_of_platforms); - if (error == -1001) { - } /* GPU not supported */ - else if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - if (G.f & G_DEBUG) { - printf("%u number of platforms\n", number_of_platforms); - } - cl_platform_id *platforms = (cl_platform_id *)MEM_mallocN( - sizeof(cl_platform_id) * number_of_platforms, __func__); - error = clGetPlatformIDs(number_of_platforms, platforms, nullptr); - uint index_platform; - for (index_platform = 0; index_platform < number_of_platforms; index_platform++) { - cl_platform_id platform = platforms[index_platform]; - cl_uint number_of_devices = 0; - clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 0, nullptr, &number_of_devices); - if (number_of_devices <= 0) { - continue; - } - - cl_device_id *cldevices = (cl_device_id *)MEM_mallocN( - sizeof(cl_device_id) * number_of_devices, __func__); - clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, number_of_devices, cldevices, nullptr); - - g_work_scheduler.opencl.context = clCreateContext( - nullptr, number_of_devices, cldevices, cl_context_error, nullptr, &error); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - const char *cl_str[2] = {datatoc_COM_OpenCLKernels_cl, nullptr}; - g_work_scheduler.opencl.program = clCreateProgramWithSource( - g_work_scheduler.opencl.context, 1, cl_str, nullptr, &error); - error = clBuildProgram(g_work_scheduler.opencl.program, - number_of_devices, - cldevices, - nullptr, - nullptr, - nullptr); - if (error != CL_SUCCESS) { - cl_int error2; - size_t ret_val_size = 0; - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - error2 = clGetProgramBuildInfo(g_work_scheduler.opencl.program, - cldevices[0], - CL_PROGRAM_BUILD_LOG, - 0, - nullptr, - &ret_val_size); - if (error2 != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - char *build_log = (char *)MEM_mallocN(sizeof(char) * ret_val_size + 1, __func__); - error2 = clGetProgramBuildInfo(g_work_scheduler.opencl.program, - cldevices[0], - CL_PROGRAM_BUILD_LOG, - ret_val_size, - build_log, - nullptr); - if (error2 != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - build_log[ret_val_size] = '\0'; - printf("%s", build_log); - MEM_freeN(build_log); - } - else { - uint index_devices; - for (index_devices = 0; index_devices < number_of_devices; index_devices++) { - cl_device_id device = cldevices[index_devices]; - cl_int vendorID = 0; - cl_int error2 = clGetDeviceInfo( - device, CL_DEVICE_VENDOR_ID, sizeof(cl_int), &vendorID, nullptr); - if (error2 != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error2, clewErrorString(error2)); - } - g_work_scheduler.opencl.devices.append_as(g_work_scheduler.opencl.context, - device, - g_work_scheduler.opencl.program, - vendorID); - } - } - MEM_freeN(cldevices); - } - MEM_freeN(platforms); - } - - g_work_scheduler.opencl.initialized = true; - } -} - -static void opencl_deinitialize() -{ - g_work_scheduler.opencl.devices.clear_and_shrink(); - - if (g_work_scheduler.opencl.program) { - clReleaseProgram(g_work_scheduler.opencl.program); - g_work_scheduler.opencl.program = nullptr; - } - - if (g_work_scheduler.opencl.context) { - clReleaseContext(g_work_scheduler.opencl.context); - g_work_scheduler.opencl.context = nullptr; - } - - g_work_scheduler.opencl.initialized = false; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Single threaded Scheduling * \{ */ @@ -419,12 +191,6 @@ static void threading_model_task_stop() void WorkScheduler::schedule(WorkPackage *package) { - if (COM_is_opencl_enabled()) { - if (opencl_schedule(package)) { - return; - } - } - switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: { threading_model_single_thread_execute(package); @@ -443,12 +209,8 @@ void WorkScheduler::schedule(WorkPackage *package) } } -void WorkScheduler::start(const CompositorContext &context) +void WorkScheduler::start() { - if (COM_is_opencl_enabled()) { - opencl_start(context); - } - switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: /* Nothing to do. */ @@ -466,10 +228,6 @@ void WorkScheduler::start(const CompositorContext &context) void WorkScheduler::finish() { - if (COM_is_opencl_enabled()) { - opencl_finish(); - } - switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: /* Nothing to do. */ @@ -487,10 +245,6 @@ void WorkScheduler::finish() void WorkScheduler::stop() { - if (COM_is_opencl_enabled()) { - opencl_stop(); - } - switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: /* Nothing to do. */ @@ -506,20 +260,8 @@ void WorkScheduler::stop() } } -bool WorkScheduler::has_gpu_devices() +void WorkScheduler::initialize(int num_cpu_threads) { - if (COM_is_opencl_enabled()) { - return opencl_has_gpu_devices(); - } - return false; -} - -void WorkScheduler::initialize(bool use_opencl, int num_cpu_threads) -{ - if (COM_is_opencl_enabled()) { - opencl_initialize(use_opencl); - } - g_work_scheduler.num_cpu_threads = num_cpu_threads; switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: @@ -538,10 +280,6 @@ void WorkScheduler::initialize(bool use_opencl, int num_cpu_threads) void WorkScheduler::deinitialize() { - if (COM_is_opencl_enabled()) { - opencl_deinitialize(); - } - switch (COM_threading_model()) { case ThreadingModel::SingleThreaded: /* Nothing to do. */ diff --git a/source/blender/compositor/intern/COM_WorkScheduler.h b/source/blender/compositor/intern/COM_WorkScheduler.h index fb1a4c83e00..4a1ac60a983 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.h +++ b/source/blender/compositor/intern/COM_WorkScheduler.h @@ -12,8 +12,6 @@ namespace blender::compositor { struct WorkPackage; -class CompositorContext; - /** \brief the workscheduler * \ingroup execution */ @@ -21,9 +19,6 @@ struct WorkScheduler { /** * \brief schedule a chunk of a group to be calculated. * An execution group schedules a chunk in the WorkScheduler - * when ExecutionGroup.get_flags().open_cl is set the work will be handled by a OpenCLDevice - * otherwise the work is scheduled for an CPUDevice - * \see ExecutionGroup.execute */ static void schedule(WorkPackage *package); @@ -33,13 +28,9 @@ struct WorkScheduler { * during initialization the mutexes are initialized. * there are two mutexes (for every device type one) * After mutex initialization the system is queried in order to count the number of CPUDevices - * and GPUDevices to be created. For every hardware thread a CPUDevice and for every OpenCL GPU - * device a OpenCLDevice is created. these devices are stored in a separate list (cpudevices & - * gpudevices) - * - * This function can be called multiple times to lazily initialize OpenCL. + * to be created. For every hardware thread a CPUDevice is created. */ - static void initialize(bool use_opencl, int num_cpu_threads); + static void initialize(int num_cpu_threads); /** * \brief deinitialize the WorkScheduler @@ -53,7 +44,7 @@ struct WorkScheduler { * for every device a thread is created. * \see initialize Initialization and query of the number of devices */ - static void start(const CompositorContext &context); + static void start(); /** * \brief stop the execution @@ -67,14 +58,6 @@ struct WorkScheduler { */ static void finish(); - /** - * \brief Are there OpenCL capable GPU devices initialized? - * the result of this method is stored in the CompositorContext - * A node can generate a different operation tree when OpenCLDevices exists. - * \see CompositorContext.get_has_active_opencl_devices - */ - static bool has_gpu_devices(); - static int get_num_cpu_threads(); static int current_thread_id(); diff --git a/source/blender/compositor/intern/COM_compositor.cc b/source/blender/compositor/intern/COM_compositor.cc index 48659aad115..01d201df31b 100644 --- a/source/blender/compositor/intern/COM_compositor.cc +++ b/source/blender/compositor/intern/COM_compositor.cc @@ -89,7 +89,7 @@ void COM_execute(Render *render, /* CPU compositor. */ /* Initialize workscheduler. */ - blender::compositor::WorkScheduler::initialize(false, BKE_render_num_threads(render_data)); + blender::compositor::WorkScheduler::initialize(BKE_render_num_threads(render_data)); /* Execute. */ const bool twopass = (node_tree->flag & NTREE_TWO_PASS) && !rendering; diff --git a/source/blender/compositor/nodes/COM_BlurNode.cc b/source/blender/compositor/nodes/COM_BlurNode.cc index f7f6156ba59..4efbdc86364 100644 --- a/source/blender/compositor/nodes/COM_BlurNode.cc +++ b/source/blender/compositor/nodes/COM_BlurNode.cc @@ -5,11 +5,9 @@ #include "COM_BlurNode.h" #include "COM_FastGaussianBlurOperation.h" #include "COM_GammaCorrectOperation.h" -#include "COM_GaussianAlphaXBlurOperation.h" -#include "COM_GaussianAlphaYBlurOperation.h" +#include "COM_GaussianAlphaBlurBaseOperation.h" +#include "COM_GaussianBlurBaseOperation.h" #include "COM_GaussianBokehBlurOperation.h" -#include "COM_GaussianXBlurOperation.h" -#include "COM_GaussianYBlurOperation.h" #include "COM_MathBaseOperation.h" #include "COM_SetValueOperation.h" @@ -93,7 +91,6 @@ void BlurNode::convert_to_operations(NodeConverter &converter, GaussianXBlurOperation *operationx = new GaussianXBlurOperation(); operationx->set_data(data); operationx->set_quality(quality); - operationx->check_opencl(); operationx->set_extend_bounds(extend_bounds); converter.add_operation(operationx); @@ -102,7 +99,6 @@ void BlurNode::convert_to_operations(NodeConverter &converter, GaussianYBlurOperation *operationy = new GaussianYBlurOperation(); operationy->set_data(data); operationy->set_quality(quality); - operationy->check_opencl(); operationy->set_extend_bounds(extend_bounds); converter.add_operation(operationy); diff --git a/source/blender/compositor/nodes/COM_DilateErodeNode.cc b/source/blender/compositor/nodes/COM_DilateErodeNode.cc index 33f770ec1cf..f087b42e507 100644 --- a/source/blender/compositor/nodes/COM_DilateErodeNode.cc +++ b/source/blender/compositor/nodes/COM_DilateErodeNode.cc @@ -4,8 +4,7 @@ #include "COM_DilateErodeNode.h" #include "COM_DilateErodeOperation.h" -#include "COM_GaussianAlphaXBlurOperation.h" -#include "COM_GaussianAlphaYBlurOperation.h" +#include "COM_GaussianAlphaBlurBaseOperation.h" #include "COM_SMAAOperation.h" namespace blender::compositor { diff --git a/source/blender/compositor/nodes/COM_KeyingNode.cc b/source/blender/compositor/nodes/COM_KeyingNode.cc index 9ea2642d361..87e451b8cd8 100644 --- a/source/blender/compositor/nodes/COM_KeyingNode.cc +++ b/source/blender/compositor/nodes/COM_KeyingNode.cc @@ -18,8 +18,7 @@ #include "COM_SetAlphaMultiplyOperation.h" -#include "COM_GaussianAlphaXBlurOperation.h" -#include "COM_GaussianAlphaYBlurOperation.h" +#include "COM_GaussianAlphaBlurBaseOperation.h" #include "BLI_math_color.h" diff --git a/source/blender/compositor/nodes/COM_KuwaharaNode.cc b/source/blender/compositor/nodes/COM_KuwaharaNode.cc index bf21e75865a..fa4171f49d8 100644 --- a/source/blender/compositor/nodes/COM_KuwaharaNode.cc +++ b/source/blender/compositor/nodes/COM_KuwaharaNode.cc @@ -9,8 +9,7 @@ #include "COM_KuwaharaNode.h" -#include "COM_GaussianXBlurOperation.h" -#include "COM_GaussianYBlurOperation.h" +#include "COM_GaussianBlurBaseOperation.h" #include "COM_KuwaharaAnisotropicOperation.h" #include "COM_KuwaharaAnisotropicStructureTensorOperation.h" #include "COM_KuwaharaClassicOperation.h" diff --git a/source/blender/compositor/nodes/COM_RotateNode.cc b/source/blender/compositor/nodes/COM_RotateNode.cc index 1879ce49500..fe0a0ea40a0 100644 --- a/source/blender/compositor/nodes/COM_RotateNode.cc +++ b/source/blender/compositor/nodes/COM_RotateNode.cc @@ -15,7 +15,7 @@ RotateNode::RotateNode(bNode *editor_node) : Node(editor_node) } void RotateNode::convert_to_operations(NodeConverter &converter, - const CompositorContext &context) const + const CompositorContext & /*context*/) const { NodeInput *input_socket = this->get_input_socket(0); NodeInput *input_degree_socket = this->get_input_socket(1); @@ -24,21 +24,8 @@ void RotateNode::convert_to_operations(NodeConverter &converter, converter.add_operation(operation); PixelSampler sampler = (PixelSampler)this->get_bnode()->custom1; - switch (context.get_execution_model()) { - case eExecutionModel::Tiled: { - SetSamplerOperation *sampler_op = new SetSamplerOperation(); - sampler_op->set_sampler(sampler); - converter.add_operation(sampler_op); - converter.add_link(sampler_op->get_output_socket(), operation->get_input_socket(0)); - converter.map_input_socket(input_socket, sampler_op->get_input_socket(0)); - break; - } - case eExecutionModel::FullFrame: { - operation->set_sampler(sampler); - converter.map_input_socket(input_socket, operation->get_input_socket(0)); - break; - } - } + operation->set_sampler(sampler); + converter.map_input_socket(input_socket, operation->get_input_socket(0)); converter.map_input_socket(input_degree_socket, operation->get_input_socket(1)); converter.map_output_socket(output_socket, operation->get_output_socket(0)); diff --git a/source/blender/compositor/nodes/COM_SocketProxyNode.cc b/source/blender/compositor/nodes/COM_SocketProxyNode.cc index be6947651ea..33731fb28d7 100644 --- a/source/blender/compositor/nodes/COM_SocketProxyNode.cc +++ b/source/blender/compositor/nodes/COM_SocketProxyNode.cc @@ -3,8 +3,6 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "COM_SocketProxyNode.h" -#include "COM_ReadBufferOperation.h" -#include "COM_WriteBufferOperation.h" namespace blender::compositor { @@ -43,47 +41,4 @@ void SocketProxyNode::convert_to_operations(NodeConverter &converter, converter.map_output_socket(get_output_socket(), proxy_output); } -SocketBufferNode::SocketBufferNode(bNode *editor_node, - bNodeSocket *editor_input, - bNodeSocket *editor_output) - : Node(editor_node, false) -{ - DataType dt; - - dt = DataType::Value; - if (editor_input->type == SOCK_RGBA) { - dt = DataType::Color; - } - if (editor_input->type == SOCK_VECTOR) { - dt = DataType::Vector; - } - this->add_input_socket(dt, editor_input); - - dt = DataType::Value; - if (editor_output->type == SOCK_RGBA) { - dt = DataType::Color; - } - if (editor_output->type == SOCK_VECTOR) { - dt = DataType::Vector; - } - this->add_output_socket(dt, editor_output); -} - -void SocketBufferNode::convert_to_operations(NodeConverter &converter, - const CompositorContext & /*context*/) const -{ - NodeOutput *output = this->get_output_socket(0); - NodeInput *input = this->get_input_socket(0); - - DataType datatype = output->get_data_type(); - WriteBufferOperation *write_operation = new WriteBufferOperation(datatype); - ReadBufferOperation *read_operation = new ReadBufferOperation(datatype); - read_operation->set_memory_proxy(write_operation->get_memory_proxy()); - converter.add_operation(write_operation); - converter.add_operation(read_operation); - - converter.map_input_socket(input, write_operation->get_input_socket(0)); - converter.map_output_socket(output, read_operation->get_output_socket()); -} - } // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_SocketProxyNode.h b/source/blender/compositor/nodes/COM_SocketProxyNode.h index 76530b070e3..61bdd17a550 100644 --- a/source/blender/compositor/nodes/COM_SocketProxyNode.h +++ b/source/blender/compositor/nodes/COM_SocketProxyNode.h @@ -35,11 +35,4 @@ class SocketProxyNode : public Node { bool use_conversion_; }; -class SocketBufferNode : public Node { - public: - SocketBufferNode(bNode *editor_node, bNodeSocket *editor_input, bNodeSocket *editor_output); - void convert_to_operations(NodeConverter &converter, - const CompositorContext &context) const override; -}; - } // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_Stabilize2dNode.cc b/source/blender/compositor/nodes/COM_Stabilize2dNode.cc index 1c38f23a177..e5ac119a216 100644 --- a/source/blender/compositor/nodes/COM_Stabilize2dNode.cc +++ b/source/blender/compositor/nodes/COM_Stabilize2dNode.cc @@ -55,119 +55,55 @@ void Stabilize2dNode::convert_to_operations(NodeConverter &converter, converter.add_operation(x_attribute); converter.add_operation(y_attribute); - switch (context.get_execution_model()) { - case eExecutionModel::Tiled: { - ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation(); - scale_operation->set_sampler(sampler); - RotateOperation *rotate_operation = new RotateOperation(); - rotate_operation->set_do_degree2_rad_conversion(false); - TranslateOperation *translate_operation = new TranslateOperation(); - SetSamplerOperation *psoperation = new SetSamplerOperation(); - psoperation->set_sampler(sampler); + ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation(); + scale_operation->set_sampler(sampler); + RotateOperation *rotate_operation = new RotateOperation(); + rotate_operation->set_do_degree2_rad_conversion(false); + rotate_operation->set_sampler(sampler); + TranslateOperation *translate_operation = new TranslateCanvasOperation(); - converter.add_operation(scale_operation); - converter.add_operation(translate_operation); - converter.add_operation(rotate_operation); - converter.add_operation(psoperation); + converter.add_operation(scale_operation); + converter.add_operation(translate_operation); + converter.add_operation(rotate_operation); - converter.add_link(scale_attribute->get_output_socket(), - scale_operation->get_input_socket(1)); - converter.add_link(scale_attribute->get_output_socket(), - scale_operation->get_input_socket(2)); + converter.add_link(scale_attribute->get_output_socket(), scale_operation->get_input_socket(1)); + converter.add_link(scale_attribute->get_output_socket(), scale_operation->get_input_socket(2)); - converter.add_link(angle_attribute->get_output_socket(), - rotate_operation->get_input_socket(1)); + converter.add_link(angle_attribute->get_output_socket(), rotate_operation->get_input_socket(1)); - converter.add_link(x_attribute->get_output_socket(), - translate_operation->get_input_socket(1)); - converter.add_link(y_attribute->get_output_socket(), - translate_operation->get_input_socket(2)); + converter.add_link(x_attribute->get_output_socket(), translate_operation->get_input_socket(1)); + converter.add_link(y_attribute->get_output_socket(), translate_operation->get_input_socket(2)); - converter.map_output_socket(get_output_socket(), psoperation->get_output_socket()); + NodeOperationInput *stabilization_socket = nullptr; + if (invert) { + /* Translate -> Rotate -> Scale. */ + stabilization_socket = translate_operation->get_input_socket(0); + converter.map_input_socket(image_input, translate_operation->get_input_socket(0)); - if (invert) { - /* Translate -> Rotate -> Scale. */ - converter.map_input_socket(image_input, translate_operation->get_input_socket(0)); + converter.add_link(translate_operation->get_output_socket(), + rotate_operation->get_input_socket(0)); + converter.add_link(rotate_operation->get_output_socket(), + scale_operation->get_input_socket(0)); - converter.add_link(translate_operation->get_output_socket(), - rotate_operation->get_input_socket(0)); - converter.add_link(rotate_operation->get_output_socket(), - scale_operation->get_input_socket(0)); - - converter.add_link(scale_operation->get_output_socket(), psoperation->get_input_socket(0)); - } - else { - /* Scale -> Rotate -> Translate. */ - converter.map_input_socket(image_input, scale_operation->get_input_socket(0)); - - converter.add_link(scale_operation->get_output_socket(), - rotate_operation->get_input_socket(0)); - converter.add_link(rotate_operation->get_output_socket(), - translate_operation->get_input_socket(0)); - - converter.add_link(translate_operation->get_output_socket(), - psoperation->get_input_socket(0)); - } - break; - } - case eExecutionModel::FullFrame: { - ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation(); - scale_operation->set_sampler(sampler); - RotateOperation *rotate_operation = new RotateOperation(); - rotate_operation->set_do_degree2_rad_conversion(false); - rotate_operation->set_sampler(sampler); - TranslateOperation *translate_operation = new TranslateCanvasOperation(); - - converter.add_operation(scale_operation); - converter.add_operation(translate_operation); - converter.add_operation(rotate_operation); - - converter.add_link(scale_attribute->get_output_socket(), - scale_operation->get_input_socket(1)); - converter.add_link(scale_attribute->get_output_socket(), - scale_operation->get_input_socket(2)); - - converter.add_link(angle_attribute->get_output_socket(), - rotate_operation->get_input_socket(1)); - - converter.add_link(x_attribute->get_output_socket(), - translate_operation->get_input_socket(1)); - converter.add_link(y_attribute->get_output_socket(), - translate_operation->get_input_socket(2)); - - NodeOperationInput *stabilization_socket = nullptr; - if (invert) { - /* Translate -> Rotate -> Scale. */ - stabilization_socket = translate_operation->get_input_socket(0); - converter.map_input_socket(image_input, translate_operation->get_input_socket(0)); - - converter.add_link(translate_operation->get_output_socket(), - rotate_operation->get_input_socket(0)); - converter.add_link(rotate_operation->get_output_socket(), - scale_operation->get_input_socket(0)); - - converter.map_output_socket(get_output_socket(), scale_operation->get_output_socket()); - } - else { - /* Scale -> Rotate -> Translate. */ - stabilization_socket = scale_operation->get_input_socket(0); - converter.map_input_socket(image_input, scale_operation->get_input_socket(0)); - - converter.add_link(scale_operation->get_output_socket(), - rotate_operation->get_input_socket(0)); - converter.add_link(rotate_operation->get_output_socket(), - translate_operation->get_input_socket(0)); - - converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket()); - } - - x_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); - y_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); - scale_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); - angle_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); - break; - } + converter.map_output_socket(get_output_socket(), scale_operation->get_output_socket()); } + else { + /* Scale -> Rotate -> Translate. */ + stabilization_socket = scale_operation->get_input_socket(0); + converter.map_input_socket(image_input, scale_operation->get_input_socket(0)); + + converter.add_link(scale_operation->get_output_socket(), + rotate_operation->get_input_socket(0)); + converter.add_link(rotate_operation->get_output_socket(), + translate_operation->get_input_socket(0)); + + converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket()); + } + + x_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); + y_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); + scale_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); + angle_attribute->set_socket_input_resolution_for_stabilization(stabilization_socket); } } // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_TransformNode.cc b/source/blender/compositor/nodes/COM_TransformNode.cc index f07442e7591..a598fd9dc4d 100644 --- a/source/blender/compositor/nodes/COM_TransformNode.cc +++ b/source/blender/compositor/nodes/COM_TransformNode.cc @@ -16,7 +16,7 @@ TransformNode::TransformNode(bNode *editor_node) : Node(editor_node) } void TransformNode::convert_to_operations(NodeConverter &converter, - const CompositorContext &context) const + const CompositorContext & /*context*/) const { NodeInput *image_input = this->get_input_socket(0); NodeInput *x_input = this->get_input_socket(1); @@ -24,73 +24,34 @@ void TransformNode::convert_to_operations(NodeConverter &converter, NodeInput *angle_input = this->get_input_socket(3); NodeInput *scale_input = this->get_input_socket(4); - switch (context.get_execution_model()) { - case eExecutionModel::Tiled: { - ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation(); - converter.add_operation(scale_operation); + ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation(); + converter.add_operation(scale_operation); - RotateOperation *rotate_operation = new RotateOperation(); - rotate_operation->set_do_degree2_rad_conversion(false); - converter.add_operation(rotate_operation); + RotateOperation *rotate_operation = new RotateOperation(); + rotate_operation->set_do_degree2_rad_conversion(false); + converter.add_operation(rotate_operation); - TranslateOperation *translate_operation = new TranslateOperation(); - converter.add_operation(translate_operation); + TranslateOperation *translate_operation = new TranslateCanvasOperation(); + converter.add_operation(translate_operation); - SetSamplerOperation *sampler = new SetSamplerOperation(); - sampler->set_sampler((PixelSampler)this->get_bnode()->custom1); - converter.add_operation(sampler); + PixelSampler sampler = (PixelSampler)this->get_bnode()->custom1; + scale_operation->set_sampler(sampler); + rotate_operation->set_sampler(sampler); - converter.map_input_socket(image_input, sampler->get_input_socket(0)); - converter.add_link(sampler->get_output_socket(), scale_operation->get_input_socket(0)); - converter.map_input_socket(scale_input, scale_operation->get_input_socket(1)); - converter.map_input_socket(scale_input, - scale_operation->get_input_socket(2)); // xscale = yscale + converter.map_input_socket(image_input, scale_operation->get_input_socket(0)); + converter.map_input_socket(scale_input, scale_operation->get_input_socket(1)); + converter.map_input_socket(scale_input, + scale_operation->get_input_socket(2)); // xscale = yscale - converter.add_link(scale_operation->get_output_socket(), - rotate_operation->get_input_socket(0)); - converter.map_input_socket(angle_input, rotate_operation->get_input_socket(1)); + converter.add_link(scale_operation->get_output_socket(), rotate_operation->get_input_socket(0)); + converter.map_input_socket(angle_input, rotate_operation->get_input_socket(1)); - converter.add_link(rotate_operation->get_output_socket(), - translate_operation->get_input_socket(0)); - converter.map_input_socket(x_input, translate_operation->get_input_socket(1)); - converter.map_input_socket(y_input, translate_operation->get_input_socket(2)); + converter.add_link(rotate_operation->get_output_socket(), + translate_operation->get_input_socket(0)); + converter.map_input_socket(x_input, translate_operation->get_input_socket(1)); + converter.map_input_socket(y_input, translate_operation->get_input_socket(2)); - converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket()); - break; - } - case eExecutionModel::FullFrame: { - ScaleRelativeOperation *scale_operation = new ScaleRelativeOperation(); - converter.add_operation(scale_operation); - - RotateOperation *rotate_operation = new RotateOperation(); - rotate_operation->set_do_degree2_rad_conversion(false); - converter.add_operation(rotate_operation); - - TranslateOperation *translate_operation = new TranslateCanvasOperation(); - converter.add_operation(translate_operation); - - PixelSampler sampler = (PixelSampler)this->get_bnode()->custom1; - scale_operation->set_sampler(sampler); - rotate_operation->set_sampler(sampler); - - converter.map_input_socket(image_input, scale_operation->get_input_socket(0)); - converter.map_input_socket(scale_input, scale_operation->get_input_socket(1)); - converter.map_input_socket(scale_input, - scale_operation->get_input_socket(2)); // xscale = yscale - - converter.add_link(scale_operation->get_output_socket(), - rotate_operation->get_input_socket(0)); - converter.map_input_socket(angle_input, rotate_operation->get_input_socket(1)); - - converter.add_link(rotate_operation->get_output_socket(), - translate_operation->get_input_socket(0)); - converter.map_input_socket(x_input, translate_operation->get_input_socket(1)); - converter.map_input_socket(y_input, translate_operation->get_input_socket(2)); - - converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket()); - break; - } - } + converter.map_output_socket(get_output_socket(), translate_operation->get_output_socket()); } } // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_TranslateNode.cc b/source/blender/compositor/nodes/COM_TranslateNode.cc index 8ba403d62b5..ad3f17f5c49 100644 --- a/source/blender/compositor/nodes/COM_TranslateNode.cc +++ b/source/blender/compositor/nodes/COM_TranslateNode.cc @@ -5,8 +5,6 @@ #include "COM_TranslateNode.h" #include "COM_TranslateOperation.h" -#include "COM_WrapOperation.h" -#include "COM_WriteBufferOperation.h" namespace blender::compositor { @@ -16,7 +14,7 @@ TranslateNode::TranslateNode(bNode *editor_node) : Node(editor_node) } void TranslateNode::convert_to_operations(NodeConverter &converter, - const CompositorContext &context) const + const CompositorContext & /*context*/) const { const bNode *bnode = this->get_bnode(); const NodeTranslateData *data = (const NodeTranslateData *)bnode->storage; @@ -26,9 +24,7 @@ void TranslateNode::convert_to_operations(NodeConverter &converter, NodeInput *input_ysocket = this->get_input_socket(2); NodeOutput *output_socket = this->get_output_socket(0); - TranslateOperation *operation = context.get_execution_model() == eExecutionModel::Tiled ? - new TranslateOperation() : - new TranslateCanvasOperation(); + TranslateOperation *operation = new TranslateCanvasOperation(); operation->set_wrapping(data->wrap_axis); operation->set_is_relative(data->relative); @@ -36,21 +32,7 @@ void TranslateNode::convert_to_operations(NodeConverter &converter, converter.map_input_socket(input_xsocket, operation->get_input_socket(1)); converter.map_input_socket(input_ysocket, operation->get_input_socket(2)); converter.map_output_socket(output_socket, operation->get_output_socket(0)); - if (data->wrap_axis && context.get_execution_model() != eExecutionModel::FullFrame) { - /* TODO: To be removed with tiled implementation. */ - WriteBufferOperation *write_operation = new WriteBufferOperation(DataType::Color); - WrapOperation *wrap_operation = new WrapOperation(DataType::Color); - wrap_operation->set_memory_proxy(write_operation->get_memory_proxy()); - wrap_operation->set_wrapping(data->wrap_axis); - - converter.add_operation(write_operation); - converter.add_operation(wrap_operation); - converter.map_input_socket(input_socket, write_operation->get_input_socket(0)); - converter.add_link(wrap_operation->get_output_socket(), operation->get_input_socket(0)); - } - else { - converter.map_input_socket(input_socket, operation->get_input_socket(0)); - } + converter.map_input_socket(input_socket, operation->get_input_socket(0)); } } // namespace blender::compositor diff --git a/source/blender/compositor/nodes/COM_ViewerNode.cc b/source/blender/compositor/nodes/COM_ViewerNode.cc index 1260b1966ca..0be56d248d4 100644 --- a/source/blender/compositor/nodes/COM_ViewerNode.cc +++ b/source/blender/compositor/nodes/COM_ViewerNode.cc @@ -29,7 +29,6 @@ void ViewerNode::convert_to_operations(NodeConverter &converter, viewer_operation->set_bnodetree(context.get_bnodetree()); viewer_operation->set_image(image); viewer_operation->set_image_user(image_user); - viewer_operation->set_chunk_order((ChunkOrdering)editor_node->custom1); viewer_operation->setCenterX(editor_node->custom3); viewer_operation->setCenterY(editor_node->custom4); /* alpha socket gives either 1 or a custom alpha value if "use alpha" is enabled */ diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc index 61ed9bf6f86..73377835370 100644 --- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc +++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cc @@ -11,36 +11,6 @@ AlphaOverKeyOperation::AlphaOverKeyOperation() flags_.can_be_constant = true; } -void AlphaOverKeyOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_over_color[4]; - float value[4]; - - input_value_operation_->read_sampled(value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_over_color, x, y, sampler); - - if (input_over_color[3] <= 0.0f) { - copy_v4_v4(output, input_color1); - } - else if (value[0] == 1.0f && input_over_color[3] >= 1.0f) { - copy_v4_v4(output, input_over_color); - } - else { - float premul = value[0] * input_over_color[3]; - float mul = 1.0f - premul; - - output[0] = (mul * input_color1[0]) + premul * input_over_color[0]; - output[1] = (mul * input_color1[1]) + premul * input_over_color[1]; - output[2] = (mul * input_color1[2]) + premul * input_over_color[2]; - output[3] = (mul * input_color1[3]) + value[0] * input_over_color[3]; - } -} - void AlphaOverKeyOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h index 8fda605e61d..2dd87f33963 100644 --- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h @@ -16,11 +16,6 @@ class AlphaOverKeyOperation : public MixBaseOperation { public: AlphaOverKeyOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_row(PixelCursor &p) override; }; diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc index 8e6d59d05e7..8d9e8b94bea 100644 --- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc +++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cc @@ -12,37 +12,6 @@ AlphaOverMixedOperation::AlphaOverMixedOperation() flags_.can_be_constant = true; } -void AlphaOverMixedOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_over_color[4]; - float value[4]; - - input_value_operation_->read_sampled(value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_over_color, x, y, sampler); - - if (input_over_color[3] <= 0.0f) { - copy_v4_v4(output, input_color1); - } - else if (value[0] == 1.0f && input_over_color[3] >= 1.0f) { - copy_v4_v4(output, input_over_color); - } - else { - float addfac = 1.0f - x_ + input_over_color[3] * x_; - float premul = value[0] * addfac; - float mul = 1.0f - value[0] * input_over_color[3]; - - output[0] = (mul * input_color1[0]) + premul * input_over_color[0]; - output[1] = (mul * input_color1[1]) + premul * input_over_color[1]; - output[2] = (mul * input_color1[2]) + premul * input_over_color[2]; - output[3] = (mul * input_color1[3]) + value[0] * input_over_color[3]; - } -} - void AlphaOverMixedOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h index 65ef10d56f8..d03c42eb305 100644 --- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h @@ -22,11 +22,6 @@ class AlphaOverMixedOperation : public MixBaseOperation { */ AlphaOverMixedOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void setX(float x) { x_ = x; diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc index be20630fa6a..f7169f68b09 100644 --- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc +++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cc @@ -11,36 +11,6 @@ AlphaOverPremultiplyOperation::AlphaOverPremultiplyOperation() flags_.can_be_constant = true; } -void AlphaOverPremultiplyOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_over_color[4]; - float value[4]; - - input_value_operation_->read_sampled(value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_over_color, x, y, sampler); - - /* Zero alpha values should still permit an add of RGB data */ - if (input_over_color[3] < 0.0f) { - copy_v4_v4(output, input_color1); - } - else if (value[0] == 1.0f && input_over_color[3] >= 1.0f) { - copy_v4_v4(output, input_over_color); - } - else { - float mul = 1.0f - value[0] * input_over_color[3]; - - output[0] = (mul * input_color1[0]) + value[0] * input_over_color[0]; - output[1] = (mul * input_color1[1]) + value[0] * input_over_color[1]; - output[2] = (mul * input_color1[2]) + value[0] * input_over_color[2]; - output[3] = (mul * input_color1[3]) + value[0] * input_over_color[3]; - } -} - void AlphaOverPremultiplyOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h index 644e54db6af..f55207394c5 100644 --- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h @@ -16,11 +16,6 @@ class AlphaOverPremultiplyOperation : public MixBaseOperation { public: AlphaOverPremultiplyOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_row(PixelCursor &p) override; }; diff --git a/source/blender/compositor/operations/COM_BilateralBlurOperation.cc b/source/blender/compositor/operations/COM_BilateralBlurOperation.cc index 43313de77a0..0435b190e6f 100644 --- a/source/blender/compositor/operations/COM_BilateralBlurOperation.cc +++ b/source/blender/compositor/operations/COM_BilateralBlurOperation.cc @@ -11,87 +11,14 @@ BilateralBlurOperation::BilateralBlurOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - - input_color_program_ = nullptr; - input_determinator_program_ = nullptr; } void BilateralBlurOperation::init_execution() { - input_color_program_ = get_input_socket_reader(0); - input_determinator_program_ = get_input_socket_reader(1); QualityStepHelper::init_execution(COM_QH_INCREASE); } -void BilateralBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - /* Read the determinator color at x, y, - * this will be used as the reference color for the determinator. */ - float determinator_reference_color[4]; - float determinator[4]; - float temp_color[4]; - float blur_color[4]; - float blur_divider; - float sigmacolor = data_->sigma_color; - float delta_color; - input_determinator_program_->read(determinator_reference_color, x, y, data); - - zero_v4(blur_color); - blur_divider = 0.0f; - /* TODO(sergey): This isn't really good bilateral filter, it should be - * using gaussian bell for weights. Also sigma_color doesn't seem to be - * used correct at all. - */ - for (int yi = -radius_; yi <= radius_; yi += QualityStepHelper::get_step()) { - for (int xi = -radius_; xi <= radius_; xi += QualityStepHelper::get_step()) { - /* Read determinator. */ - input_determinator_program_->read_clamped(determinator, x + xi, y + yi, data); - delta_color = (fabsf(determinator_reference_color[0] - determinator[0]) + - fabsf(determinator_reference_color[1] - determinator[1]) + - /* Do not take the alpha channel into account. */ - fabsf(determinator_reference_color[2] - determinator[2])); - if (delta_color < sigmacolor) { - /* Add this to the blur. */ - input_color_program_->read_clamped(temp_color, x + xi, y + yi, data); - add_v4_v4(blur_color, temp_color); - blur_divider += 1.0f; - } - } - } - - if (blur_divider > 0.0f) { - mul_v4_v4fl(output, blur_color, 1.0f / blur_divider); - } - else { - output[0] = 0.0f; - output[1] = 0.0f; - output[2] = 0.0f; - output[3] = 1.0f; - } -} - -void BilateralBlurOperation::deinit_execution() -{ - input_color_program_ = nullptr; - input_determinator_program_ = nullptr; -} - -bool BilateralBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - int add = radius_ + 1; - - new_input.xmax = input->xmax + (add); - new_input.xmin = input->xmin - (add); - new_input.ymax = input->ymax + (add); - new_input.ymin = input->ymin - (add); - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void BilateralBlurOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_BilateralBlurOperation.h b/source/blender/compositor/operations/COM_BilateralBlurOperation.h index 4661d07444b..0920fc6fb52 100644 --- a/source/blender/compositor/operations/COM_BilateralBlurOperation.h +++ b/source/blender/compositor/operations/COM_BilateralBlurOperation.h @@ -13,33 +13,14 @@ namespace blender::compositor { class BilateralBlurOperation : public MultiThreadedOperation, public QualityStepHelper { private: - SocketReader *input_color_program_; - SocketReader *input_determinator_program_; NodeBilateralBlurData *data_; int radius_; public: BilateralBlurOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void set_data(NodeBilateralBlurData *data) { data_ = data; diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.cc b/source/blender/compositor/operations/COM_BlurBaseOperation.cc index 2d4399c2250..6403e89c11a 100644 --- a/source/blender/compositor/operations/COM_BlurBaseOperation.cc +++ b/source/blender/compositor/operations/COM_BlurBaseOperation.cc @@ -15,9 +15,7 @@ BlurBaseOperation::BlurBaseOperation(DataType data_type) this->add_input_socket(data_type); this->add_input_socket(DataType::Value); this->add_output_socket(data_type); - flags_.complex = true; flags_.can_be_constant = true; - input_program_ = nullptr; memset(&data_, 0, sizeof(NodeBlurData)); size_ = 1.0f; sizeavailable_ = false; @@ -27,9 +25,7 @@ BlurBaseOperation::BlurBaseOperation(DataType data_type) void BlurBaseOperation::init_data() { - if (execution_model_ == eExecutionModel::FullFrame) { - update_size(); - } + update_size(); data_.image_in_width = this->get_width(); data_.image_in_height = this->get_height(); @@ -55,9 +51,6 @@ void BlurBaseOperation::init_data() void BlurBaseOperation::init_execution() { - input_program_ = this->get_input_socket_reader(0); - input_size_ = this->get_input_socket_reader(1); - QualityStepHelper::init_execution(COM_QH_MULTIPLY); } @@ -148,12 +141,6 @@ float *BlurBaseOperation::make_dist_fac_inverse(float rad, int size, int falloff return dist_fac_invert; } -void BlurBaseOperation::deinit_execution() -{ - input_program_ = nullptr; - input_size_ = nullptr; -} - void BlurBaseOperation::set_data(const NodeBlurData *data) { memcpy(&data_, data, sizeof(NodeBlurData)); @@ -176,21 +163,10 @@ void BlurBaseOperation::update_size() return; } - switch (execution_model_) { - case eExecutionModel::Tiled: { - float result[4]; - this->get_input_socket_reader(1)->read_sampled(result, 0, 0, PixelSampler::Nearest); - size_ = result[0]; - break; - } - case eExecutionModel::FullFrame: { - NodeOperation *size_input = get_input_operation(SIZE_INPUT_INDEX); - if (size_input->get_flags().is_constant_operation) { - size_ = *static_cast(size_input)->get_constant_elem(); - } /* Else use default. */ - break; - } - } + NodeOperation *size_input = get_input_operation(SIZE_INPUT_INDEX); + if (size_input->get_flags().is_constant_operation) { + size_ = *static_cast(size_input)->get_constant_elem(); + } /* Else use default. */ sizeavailable_ = true; } @@ -201,26 +177,15 @@ void BlurBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_are return; } - switch (execution_model_) { - case eExecutionModel::Tiled: { - NodeOperation::determine_canvas(preferred_area, r_area); - r_area.xmax += 2 * size_ * data_.sizex; - r_area.ymax += 2 * size_ * data_.sizey; - break; - } - case eExecutionModel::FullFrame: { - /* Setting a modifier ensures all non main inputs have extended bounds as preferred - * canvas, avoiding unnecessary canvas conversions that would hide constant - * operations. */ - set_determined_canvas_modifier([=](rcti &canvas) { - /* Rounding to even prevents jiggling in backdrop while switching size values. */ - canvas.xmax += round_to_even(2 * size_ * data_.sizex); - canvas.ymax += round_to_even(2 * size_ * data_.sizey); - }); - NodeOperation::determine_canvas(preferred_area, r_area); - break; - } - } + /* Setting a modifier ensures all non main inputs have extended bounds as preferred + * canvas, avoiding unnecessary canvas conversions that would hide constant + * operations. */ + set_determined_canvas_modifier([=](rcti &canvas) { + /* Rounding to even prevents jiggling in backdrop while switching size values. */ + canvas.xmax += round_to_even(2 * size_ * data_.sizex); + canvas.ymax += round_to_even(2 * size_ * data_.sizey); + }); + NodeOperation::determine_canvas(preferred_area, r_area); } void BlurBaseOperation::get_area_of_interest(const int input_idx, diff --git a/source/blender/compositor/operations/COM_BlurBaseOperation.h b/source/blender/compositor/operations/COM_BlurBaseOperation.h index 9f7ac9fec81..ab293bbd292 100644 --- a/source/blender/compositor/operations/COM_BlurBaseOperation.h +++ b/source/blender/compositor/operations/COM_BlurBaseOperation.h @@ -35,11 +35,6 @@ class BlurBaseOperation : public MultiThreadedOperation, public QualityStepHelpe void update_size(); - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - SocketReader *input_size_; NodeBlurData data_; float size_; @@ -50,16 +45,8 @@ class BlurBaseOperation : public MultiThreadedOperation, public QualityStepHelpe public: virtual void init_data() override; - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_data(const NodeBlurData *data); void set_size(float size) diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cc b/source/blender/compositor/operations/COM_BokehBlurOperation.cc index bd4b9eab927..1686af6dfc6 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.cc +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cc @@ -8,8 +8,6 @@ #include "COM_BokehBlurOperation.h" #include "COM_ConstantOperation.h" -#include "COM_OpenCLDevice.h" - namespace blender::compositor { constexpr int IMAGE_INPUT_INDEX = 0; @@ -25,195 +23,35 @@ BokehBlurOperation::BokehBlurOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - flags_.complex = true; - flags_.open_cl = true; flags_.can_be_constant = true; size_ = 1.0f; sizeavailable_ = false; - input_program_ = nullptr; - input_bokeh_program_ = nullptr; - input_bounding_box_reader_ = nullptr; extend_bounds_ = false; } void BokehBlurOperation::init_data() { - if (execution_model_ == eExecutionModel::FullFrame) { - update_size(); - } -} - -void *BokehBlurOperation::initialize_tile_data(rcti * /*rect*/) -{ - lock_mutex(); - if (!sizeavailable_) { - update_size(); - } - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - unlock_mutex(); - return buffer; + update_size(); } void BokehBlurOperation::init_execution() { - init_mutex(); - - input_program_ = get_input_socket_reader(0); - input_bokeh_program_ = get_input_socket_reader(1); - input_bounding_box_reader_ = get_input_socket_reader(2); - QualityStepHelper::init_execution(COM_QH_INCREASE); } -void BokehBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - - float temp_bounding_box[4]; - input_bounding_box_reader_->read_sampled(temp_bounding_box, x, y, PixelSampler::Nearest); - if (temp_bounding_box[0] <= 0.0f) { - copy_v4_v4(output, input_buffer->get_elem(x, y)); - return; - } - - const float max_dim = std::max(this->get_width(), this->get_height()); - int radius = size_ * max_dim / 100.0f; - const int2 bokeh_size = int2(input_bokeh_program_->get_width(), - input_bokeh_program_->get_height()); - - float4 accumulated_color = float4(0.0f); - float4 accumulated_weight = float4(0.0f); - int step = get_step(); - for (int yi = -radius; yi <= radius; yi += step) { - for (int xi = -radius; xi <= radius; xi += step) { - const float2 normalized_texel = (float2(xi, yi) + radius + 0.5f) / (radius * 2.0f + 1.0f); - const float2 weight_texel = (1.0f - normalized_texel) * float2(bokeh_size - 1); - float4 weight; - input_bokeh_program_->read(weight, int(weight_texel.x), int(weight_texel.y), nullptr); - const float4 color = float4(input_buffer->get_elem_clamped(x + xi, y + yi)) * weight; - accumulated_color += color; - accumulated_weight += weight; - } - } - - const float4 final_color = math::safe_divide(accumulated_color, accumulated_weight); - copy_v4_v4(output, final_color); -} - -void BokehBlurOperation::deinit_execution() -{ - deinit_mutex(); - input_program_ = nullptr; - input_bokeh_program_ = nullptr; - input_bounding_box_reader_ = nullptr; -} - -bool BokehBlurOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - rcti bokeh_input; - const float max_dim = std::max(this->get_width(), this->get_height()); - - if (sizeavailable_) { - new_input.xmax = input->xmax + (size_ * max_dim / 100.0f); - new_input.xmin = input->xmin - (size_ * max_dim / 100.0f); - new_input.ymax = input->ymax + (size_ * max_dim / 100.0f); - new_input.ymin = input->ymin - (size_ * max_dim / 100.0f); - } - else { - new_input.xmax = input->xmax + (10.0f * max_dim / 100.0f); - new_input.xmin = input->xmin - (10.0f * max_dim / 100.0f); - new_input.ymax = input->ymax + (10.0f * max_dim / 100.0f); - new_input.ymin = input->ymin - (10.0f * max_dim / 100.0f); - } - - NodeOperation *operation = get_input_operation(1); - bokeh_input.xmax = operation->get_width(); - bokeh_input.xmin = 0; - bokeh_input.ymax = operation->get_height(); - bokeh_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&bokeh_input, read_operation, output)) { - return true; - } - operation = get_input_operation(0); - if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { - return true; - } - operation = get_input_operation(2); - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - if (!sizeavailable_) { - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - operation = get_input_operation(3); - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - } - return false; -} - -void BokehBlurOperation::execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel kernel = device->COM_cl_create_kernel("bokeh_blur_kernel", nullptr); - if (!sizeavailable_) { - update_size(); - } - const float max_dim = std::max(this->get_width(), this->get_height()); - cl_int radius = size_ * max_dim / 100.0f; - cl_int step = this->get_step(); - - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - kernel, 0, -1, cl_mem_to_clean_up, input_memory_buffers, input_bounding_box_reader_); - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - kernel, 1, 4, cl_mem_to_clean_up, input_memory_buffers, input_program_); - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - kernel, 2, -1, cl_mem_to_clean_up, input_memory_buffers, input_bokeh_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter(kernel, 3, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter(kernel, 5, output_memory_buffer); - clSetKernelArg(kernel, 6, sizeof(cl_int), &radius); - clSetKernelArg(kernel, 7, sizeof(cl_int), &step); - device->COM_cl_attach_size_to_kernel_parameter(kernel, 8, this); - - device->COM_cl_enqueue_range(kernel, output_memory_buffer, 9, this); -} - void BokehBlurOperation::update_size() { if (sizeavailable_) { return; } - switch (execution_model_) { - case eExecutionModel::Tiled: { - float result[4]; - this->get_input_socket_reader(3)->read_sampled(result, 0, 0, PixelSampler::Nearest); - size_ = result[0]; - CLAMP(size_, 0.0f, 10.0f); - break; - } - case eExecutionModel::FullFrame: { - NodeOperation *size_input = get_input_operation(SIZE_INPUT_INDEX); - if (size_input->get_flags().is_constant_operation) { - size_ = *static_cast(size_input)->get_constant_elem(); - CLAMP(size_, 0.0f, 10.0f); - } /* Else use default. */ - break; - } - } + NodeOperation *size_input = get_input_operation(SIZE_INPUT_INDEX); + if (size_input->get_flags().is_constant_operation) { + size_ = *static_cast(size_input)->get_constant_elem(); + CLAMP(size_, 0.0f, 10.0f); + } /* Else use default. */ sizeavailable_ = true; } @@ -224,27 +62,14 @@ void BokehBlurOperation::determine_canvas(const rcti &preferred_area, rcti &r_ar return; } - switch (execution_model_) { - case eExecutionModel::Tiled: { - NodeOperation::determine_canvas(preferred_area, r_area); - const float max_dim = std::max(BLI_rcti_size_x(&r_area), BLI_rcti_size_y(&r_area)); - float add_size = round_to_even(2 * size_ * max_dim / 100.0f); - r_area.xmax += add_size; - r_area.ymax += add_size; - break; - } - case eExecutionModel::FullFrame: { - set_determined_canvas_modifier([=](rcti &canvas) { - const float max_dim = std::max(BLI_rcti_size_x(&canvas), BLI_rcti_size_y(&canvas)); - /* Rounding to even prevents image jiggling in backdrop while switching size values. */ - float add_size = round_to_even(2 * size_ * max_dim / 100.0f); - canvas.xmax += add_size; - canvas.ymax += add_size; - }); - NodeOperation::determine_canvas(preferred_area, r_area); - break; - } - } + set_determined_canvas_modifier([=](rcti &canvas) { + const float max_dim = std::max(BLI_rcti_size_x(&canvas), BLI_rcti_size_y(&canvas)); + /* Rounding to even prevents image jiggling in backdrop while switching size values. */ + float add_size = round_to_even(2 * size_ * max_dim / 100.0f); + canvas.xmax += add_size; + canvas.ymax += add_size; + }); + NodeOperation::determine_canvas(preferred_area, r_area); } void BokehBlurOperation::get_area_of_interest(const int input_idx, diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.h b/source/blender/compositor/operations/COM_BokehBlurOperation.h index 24278327c29..ad967d83932 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.h @@ -11,9 +11,6 @@ namespace blender::compositor { class BokehBlurOperation : public MultiThreadedOperation, public QualityStepHelper { private: - SocketReader *input_program_; - SocketReader *input_bokeh_program_; - SocketReader *input_bounding_box_reader_; void update_size(); float size_; bool sizeavailable_; @@ -25,39 +22,14 @@ class BokehBlurOperation : public MultiThreadedOperation, public QualityStepHelp void init_data() override; - void *initialize_tile_data(rcti *rect) override; - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void set_size(float size) { size_ = size; sizeavailable_ = true; } - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - void set_extend_bounds(bool extend_bounds) { extend_bounds_ = extend_bounds; diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.cc b/source/blender/compositor/operations/COM_BokehImageOperation.cc index 3aff7f00d27..0b2668b617f 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.cc +++ b/source/blender/compositor/operations/COM_BokehImageOperation.cc @@ -75,30 +75,6 @@ float BokehImageOperation::is_inside_bokeh(float distance, float x, float y) } return inside_bokeh; } -void BokehImageOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - float shift = data_->lensshift; - float shift2 = shift / 2.0f; - float distance = circular_distance_; - float inside_bokeh_max = is_inside_bokeh(distance, x, y); - float inside_bokeh_med = is_inside_bokeh(distance - fabsf(shift2 * distance), x, y); - float inside_bokeh_min = is_inside_bokeh(distance - fabsf(shift * distance), x, y); - if (shift < 0) { - output[0] = inside_bokeh_max; - output[1] = inside_bokeh_med; - output[2] = inside_bokeh_min; - } - else { - output[0] = inside_bokeh_min; - output[1] = inside_bokeh_med; - output[2] = inside_bokeh_max; - } - output[3] = (inside_bokeh_max + inside_bokeh_med + inside_bokeh_min) / 3.0f; -} - void BokehImageOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.h b/source/blender/compositor/operations/COM_BokehImageOperation.h index db6c83fdb5e..c73a2a1f994 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.h +++ b/source/blender/compositor/operations/COM_BokehImageOperation.h @@ -95,19 +95,7 @@ class BokehImageOperation : public MultiThreadedOperation { public: BokehImageOperation(); - /** - * \brief The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * \brief Initialize the execution - */ void init_execution() override; - - /** - * \brief De-initialize the execution - */ void deinit_execution() override; /** diff --git a/source/blender/compositor/operations/COM_BoxMaskOperation.cc b/source/blender/compositor/operations/COM_BoxMaskOperation.cc index 23f89d5545c..523e02a4c4d 100644 --- a/source/blender/compositor/operations/COM_BoxMaskOperation.cc +++ b/source/blender/compositor/operations/COM_BoxMaskOperation.cc @@ -11,87 +11,17 @@ BoxMaskOperation::BoxMaskOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_mask_ = nullptr; - input_value_ = nullptr; cosine_ = 0.0f; sine_ = 0.0f; } void BoxMaskOperation::init_execution() { - input_mask_ = this->get_input_socket_reader(0); - input_value_ = this->get_input_socket_reader(1); const double rad = double(data_->rotation); cosine_ = cos(rad); sine_ = sin(rad); aspect_ratio_ = float(this->get_width()) / this->get_height(); } -void BoxMaskOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_mask[4]; - float input_value[4]; - - float rx = x / std::max(this->get_width() - 1.0f, FLT_EPSILON); - float ry = y / std::max(this->get_height() - 1.0f, FLT_EPSILON); - - const float dy = (ry - data_->y) / aspect_ratio_; - const float dx = rx - data_->x; - rx = data_->x + (cosine_ * dx + sine_ * dy); - ry = data_->y + (-sine_ * dx + cosine_ * dy); - - input_mask_->read_sampled(input_mask, x, y, sampler); - input_value_->read_sampled(input_value, x, y, sampler); - - float half_height = data_->height / 2.0f + FLT_EPSILON; - float half_width = data_->width / 2.0f + FLT_EPSILON; - bool inside = (rx >= data_->x - half_width && rx <= data_->x + half_width && - ry >= data_->y - half_height && ry <= data_->y + half_height); - - switch (mask_type_) { - case CMP_NODE_MASKTYPE_ADD: - if (inside) { - output[0] = std::max(input_mask[0], input_value[0]); - } - else { - output[0] = input_mask[0]; - } - break; - case CMP_NODE_MASKTYPE_SUBTRACT: - if (inside) { - output[0] = input_mask[0] - input_value[0]; - CLAMP(output[0], 0, 1); - } - else { - output[0] = input_mask[0]; - } - break; - case CMP_NODE_MASKTYPE_MULTIPLY: - if (inside) { - output[0] = input_mask[0] * input_value[0]; - } - else { - output[0] = 0; - } - break; - case CMP_NODE_MASKTYPE_NOT: - if (inside) { - if (input_mask[0] > 0.0f) { - output[0] = 0; - } - else { - output[0] = input_value[0]; - } - } - else { - output[0] = input_mask[0]; - } - break; - } -} - void BoxMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -150,10 +80,4 @@ void BoxMaskOperation::apply_mask(MemoryBuffer *output, } } -void BoxMaskOperation::deinit_execution() -{ - input_mask_ = nullptr; - input_value_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_BoxMaskOperation.h b/source/blender/compositor/operations/COM_BoxMaskOperation.h index 2f4527128a9..48adb764a9c 100644 --- a/source/blender/compositor/operations/COM_BoxMaskOperation.h +++ b/source/blender/compositor/operations/COM_BoxMaskOperation.h @@ -12,12 +12,6 @@ class BoxMaskOperation : public MultiThreadedOperation { private: using MaskFunc = std::function; - /** - * Cached reference to the input_program - */ - SocketReader *input_mask_; - SocketReader *input_value_; - float sine_; float cosine_; float aspect_ratio_; @@ -28,21 +22,8 @@ class BoxMaskOperation : public MultiThreadedOperation { public: BoxMaskOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_data(const NodeBoxMask *data) { data_ = data; diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.cc b/source/blender/compositor/operations/COM_BrightnessOperation.cc index cc69d58b7bc..738dda2fc35 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.cc +++ b/source/blender/compositor/operations/COM_BrightnessOperation.cc @@ -14,7 +14,6 @@ BrightnessOperation::BrightnessOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_program_ = nullptr; use_premultiply_ = false; flags_.can_be_constant = true; } @@ -24,56 +23,6 @@ void BrightnessOperation::set_use_premultiply(bool use_premultiply) use_premultiply_ = use_premultiply; } -void BrightnessOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); - input_brightness_program_ = this->get_input_socket_reader(1); - input_contrast_program_ = this->get_input_socket_reader(2); -} - -void BrightnessOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value[4]; - float a, b; - float input_brightness[4]; - float input_contrast[4]; - input_program_->read_sampled(input_value, x, y, sampler); - input_brightness_program_->read_sampled(input_brightness, x, y, sampler); - input_contrast_program_->read_sampled(input_contrast, x, y, sampler); - float brightness = input_brightness[0]; - float contrast = input_contrast[0]; - brightness /= 100.0f; - float delta = contrast / 200.0f; - /* - * The algorithm is by Werner D. Streidt - * (http://visca.com/ffactory/archives/5-99/msg00021.html) - * Extracted of OpenCV `demhist.c`. - */ - if (contrast > 0) { - a = 1.0f - delta * 2.0f; - a = 1.0f / max_ff(a, FLT_EPSILON); - b = a * (brightness - delta); - } - else { - delta *= -1; - a = max_ff(1.0f - delta * 2.0f, 0.0f); - b = a * brightness + delta; - } - if (use_premultiply_) { - premul_to_straight_v4(input_value); - } - output[0] = a * input_value[0] + b; - output[1] = a * input_value[1] + b; - output[2] = a * input_value[2] + b; - output[3] = input_value[3]; - if (use_premultiply_) { - straight_to_premul_v4(output); - } -} - void BrightnessOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -118,11 +67,4 @@ void BrightnessOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void BrightnessOperation::deinit_execution() -{ - input_program_ = nullptr; - input_brightness_program_ = nullptr; - input_contrast_program_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.h b/source/blender/compositor/operations/COM_BrightnessOperation.h index 644f9b1571a..2f3d921c67d 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.h +++ b/source/blender/compositor/operations/COM_BrightnessOperation.h @@ -10,33 +10,11 @@ namespace blender::compositor { class BrightnessOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - SocketReader *input_brightness_program_; - SocketReader *input_contrast_program_; - bool use_premultiply_; public: BrightnessOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_use_premultiply(bool use_premultiply); void update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_CalculateMeanOperation.cc b/source/blender/compositor/operations/COM_CalculateMeanOperation.cc index 23450b20246..1c851c31897 100644 --- a/source/blender/compositor/operations/COM_CalculateMeanOperation.cc +++ b/source/blender/compositor/operations/COM_CalculateMeanOperation.cc @@ -14,10 +14,8 @@ CalculateMeanOperation::CalculateMeanOperation() { this->add_input_socket(DataType::Color, ResizeMode::Align); this->add_output_socket(DataType::Value); - image_reader_ = nullptr; is_calculated_ = false; setting_ = 1; - flags_.complex = true; flags_.is_constant_operation = true; needs_canvas_to_get_constant_ = true; @@ -25,95 +23,7 @@ CalculateMeanOperation::CalculateMeanOperation() void CalculateMeanOperation::init_execution() { - image_reader_ = this->get_input_socket_reader(0); is_calculated_ = false; - NodeOperation::init_mutex(); -} - -void CalculateMeanOperation::execute_pixel(float output[4], int /*x*/, int /*y*/, void * /*data*/) -{ - output[0] = constant_value_; -} - -void CalculateMeanOperation::deinit_execution() -{ - image_reader_ = nullptr; - NodeOperation::deinit_mutex(); -} - -bool CalculateMeanOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - rcti image_input; - if (is_calculated_) { - return false; - } - NodeOperation *operation = get_input_operation(0); - image_input.xmax = operation->get_width(); - image_input.xmin = 0; - image_input.ymax = operation->get_height(); - image_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&image_input, read_operation, output)) { - return true; - } - return false; -} - -void *CalculateMeanOperation::initialize_tile_data(rcti *rect) -{ - lock_mutex(); - if (!is_calculated_) { - MemoryBuffer *tile = (MemoryBuffer *)image_reader_->initialize_tile_data(rect); - constant_value_ = calculate_mean_tile(tile); - is_calculated_ = true; - } - unlock_mutex(); - return nullptr; -} - -float CalculateMeanOperation::calculate_mean_tile(MemoryBuffer *tile) const -{ - float *buffer = tile->get_buffer(); - int size = tile->get_width() * tile->get_height(); - int pixels = 0; - float sum = 0.0f; - for (int i = 0, offset = 0; i < size; i++, offset += 4) { - if (buffer[offset + 3] > 0) { - pixels++; - - switch (setting_) { - case 1: { - sum += IMB_colormanagement_get_luminance(&buffer[offset]); - break; - } - case 2: { - sum += buffer[offset]; - break; - } - case 3: { - sum += buffer[offset + 1]; - break; - } - case 4: { - sum += buffer[offset + 2]; - break; - } - case 5: { - float yuv[3]; - rgb_to_yuv(buffer[offset], - buffer[offset + 1], - buffer[offset + 2], - &yuv[0], - &yuv[1], - &yuv[2], - BLI_YUV_ITU_BT709); - sum += yuv[0]; - break; - } - } - } - } - return sum / pixels; } void CalculateMeanOperation::set_setting(int setting) diff --git a/source/blender/compositor/operations/COM_CalculateMeanOperation.h b/source/blender/compositor/operations/COM_CalculateMeanOperation.h index 4649e7f3c53..b4a4ab729fb 100644 --- a/source/blender/compositor/operations/COM_CalculateMeanOperation.h +++ b/source/blender/compositor/operations/COM_CalculateMeanOperation.h @@ -22,11 +22,6 @@ class CalculateMeanOperation : public ConstantOperation { }; protected: - /** - * \brief Cached reference to the reader - */ - SocketReader *image_reader_; - bool is_calculated_; float constant_value_; int setting_; @@ -35,26 +30,8 @@ class CalculateMeanOperation : public ConstantOperation { public: CalculateMeanOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void set_setting(int setting); void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; @@ -71,7 +48,6 @@ class CalculateMeanOperation : public ConstantOperation { * The caller takes care of checking the value is only calculated once. */ virtual float calculate_value(const MemoryBuffer *input) const; - float calculate_mean_tile(MemoryBuffer *tile) const; float calculate_mean(const MemoryBuffer *input) const; private: diff --git a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cc b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cc index b67b890bc77..31013cea35c 100644 --- a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cc +++ b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cc @@ -10,77 +10,6 @@ namespace blender::compositor { -void CalculateStandardDeviationOperation::execute_pixel(float output[4], - int /*x*/, - int /*y*/, - void * /*data*/) -{ - output[0] = standard_deviation_; -} - -void *CalculateStandardDeviationOperation::initialize_tile_data(rcti *rect) -{ - lock_mutex(); - if (!is_calculated_) { - MemoryBuffer *tile = (MemoryBuffer *)image_reader_->initialize_tile_data(rect); - standard_deviation_ = 0.0f; - float *buffer = tile->get_buffer(); - int size = tile->get_width() * tile->get_height(); - int pixels = 0; - float sum = 0.0f; - const float mean = this->calculate_mean_tile(tile); - for (int i = 0, offset = 0; i < size; i++, offset += 4) { - if (buffer[offset + 3] > 0) { - pixels++; - - switch (setting_) { - case 1: /* rgb combined */ - { - float value = IMB_colormanagement_get_luminance(&buffer[offset]); - sum += (value - mean) * (value - mean); - break; - } - case 2: /* red */ - { - float value = buffer[offset]; - sum += (value - mean) * (value - mean); - break; - } - case 3: /* green */ - { - float value = buffer[offset + 1]; - sum += (value - mean) * (value - mean); - break; - } - case 4: /* blue */ - { - float value = buffer[offset + 2]; - sum += (value - mean) * (value - mean); - break; - } - case 5: /* luminance */ - { - float yuv[3]; - rgb_to_yuv(buffer[offset], - buffer[offset + 1], - buffer[offset + 2], - &yuv[0], - &yuv[1], - &yuv[2], - BLI_YUV_ITU_BT709); - sum += (yuv[0] - mean) * (yuv[0] - mean); - break; - } - } - } - } - standard_deviation_ = sqrt(sum / float(pixels - 1)); - is_calculated_ = true; - } - unlock_mutex(); - return nullptr; -} - float CalculateStandardDeviationOperation::calculate_value(const MemoryBuffer *input) const { const float mean = this->calculate_mean(input); diff --git a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h index 1ba42786e5a..88a951cc535 100644 --- a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h +++ b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h @@ -19,15 +19,6 @@ class CalculateStandardDeviationOperation : public CalculateMeanOperation { protected: float standard_deviation_; - public: - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - void *initialize_tile_data(rcti *rect) override; - - protected: float calculate_value(const MemoryBuffer *input) const override; private: diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.cc b/source/blender/compositor/operations/COM_ChangeHSVOperation.cc index 0a6451efda6..16d51cced48 100644 --- a/source/blender/compositor/operations/COM_ChangeHSVOperation.cc +++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.cc @@ -13,51 +13,9 @@ ChangeHSVOperation::ChangeHSVOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_operation_ = nullptr; flags_.can_be_constant = true; } -void ChangeHSVOperation::init_execution() -{ - input_operation_ = get_input_socket_reader(0); - hue_operation_ = get_input_socket_reader(1); - saturation_operation_ = get_input_socket_reader(2); - value_operation_ = get_input_socket_reader(3); -} - -void ChangeHSVOperation::deinit_execution() -{ - input_operation_ = nullptr; - hue_operation_ = nullptr; - saturation_operation_ = nullptr; - value_operation_ = nullptr; -} - -void ChangeHSVOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float hue[4], saturation[4], value[4]; - - input_operation_->read_sampled(input_color1, x, y, sampler); - hue_operation_->read_sampled(hue, x, y, sampler); - saturation_operation_->read_sampled(saturation, x, y, sampler); - value_operation_->read_sampled(value, x, y, sampler); - - output[0] = input_color1[0] + (hue[0] - 0.5f); - if (output[0] > 1.0f) { - output[0] -= 1.0f; - } - else if (output[0] < 0.0f) { - output[0] += 1.0f; - } - output[1] = input_color1[1] * saturation[0]; - output[2] = input_color1[2] * value[0]; - output[3] = input_color1[3]; -} - void ChangeHSVOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.h b/source/blender/compositor/operations/COM_ChangeHSVOperation.h index 4e903c79325..b2b81586fa3 100644 --- a/source/blender/compositor/operations/COM_ChangeHSVOperation.h +++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.h @@ -13,26 +13,9 @@ namespace blender::compositor { * it assumes we are in sRGB color space. */ class ChangeHSVOperation : public MultiThreadedOperation { - private: - SocketReader *input_operation_; - SocketReader *hue_operation_; - SocketReader *saturation_operation_; - SocketReader *value_operation_; - public: - /** - * Default constructor - */ ChangeHSVOperation(); - void init_execution() override; - void deinit_execution() override; - - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc index eb256c4d4ea..4d17442fcc5 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cc +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cc @@ -11,14 +11,11 @@ ChannelMatteOperation::ChannelMatteOperation() add_input_socket(DataType::Color); add_output_socket(DataType::Value); - input_image_program_ = nullptr; flags_.can_be_constant = true; } void ChannelMatteOperation::init_execution() { - input_image_program_ = this->get_input_socket_reader(0); - limit_range_ = limit_max_ - limit_min_; switch (limit_method_) { @@ -63,50 +60,6 @@ void ChannelMatteOperation::init_execution() } } -void ChannelMatteOperation::deinit_execution() -{ - input_image_program_ = nullptr; -} - -void ChannelMatteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_color[4]; - float alpha; - - const float limit_max = limit_max_; - const float limit_min = limit_min_; - const float limit_range = limit_range_; - - input_image_program_->read_sampled(in_color, x, y, sampler); - - /* matte operation */ - alpha = in_color[ids_[0]] - std::max(in_color[ids_[1]], in_color[ids_[2]]); - - /* flip because 0.0 is transparent, not 1.0 */ - alpha = 1.0f - alpha; - - /* test range */ - if (alpha > limit_max) { - alpha = in_color[3]; /* Whatever it was prior. */ - } - else if (alpha < limit_min) { - alpha = 0.0f; - } - else { /* Blend. */ - alpha = (alpha - limit_min) / limit_range; - } - - /* Store matte(alpha) value in [0] to go with - * COM_SetAlphaMultiplyOperation and the Value output. - */ - - /* Don't make something that was more transparent less transparent. */ - output[0] = std::min(alpha, in_color[3]); -} - void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.h b/source/blender/compositor/operations/COM_ChannelMatteOperation.h index 1274004f3e8..5c7d05b6a53 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.h +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.h @@ -14,8 +14,6 @@ namespace blender::compositor { */ class ChannelMatteOperation : public MultiThreadedOperation { private: - SocketReader *input_image_program_; - // int color_space_; /* node->custom1 */ /* UNUSED */ /* TODO? */ int matte_channel_; /* node->custom2 */ int limit_method_; /* node->algorithm */ @@ -37,18 +35,9 @@ class ChannelMatteOperation : public MultiThreadedOperation { int ids_[3]; public: - /** - * Default constructor - */ ChannelMatteOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void init_execution() override; - void deinit_execution() override; void set_settings(NodeChroma *node_chroma, const int custom2) { diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.cc b/source/blender/compositor/operations/COM_ChromaMatteOperation.cc index 71df80a88be..81ce18ac4f3 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.cc +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.cc @@ -12,90 +12,9 @@ ChromaMatteOperation::ChromaMatteOperation() add_input_socket(DataType::Color); add_output_socket(DataType::Value); - input_image_program_ = nullptr; - input_key_program_ = nullptr; flags_.can_be_constant = true; } -void ChromaMatteOperation::init_execution() -{ - input_image_program_ = this->get_input_socket_reader(0); - input_key_program_ = this->get_input_socket_reader(1); -} - -void ChromaMatteOperation::deinit_execution() -{ - input_image_program_ = nullptr; - input_key_program_ = nullptr; -} - -void ChromaMatteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_key[4]; - float in_image[4]; - - const float acceptance = settings_->t1; /* in radians */ - const float cutoff = settings_->t2; /* in radians */ - const float gain = settings_->fstrength; - - float x_angle, z_angle, alpha; - float theta, beta; - float kfg; - - input_key_program_->read_sampled(in_key, x, y, sampler); - input_image_program_->read_sampled(in_image, x, y, sampler); - - /* Store matte(alpha) value in [0] to go with - * #COM_SetAlphaMultiplyOperation and the Value output. */ - - /* Algorithm from book "Video Demystified", does not include the spill reduction part. */ - /* Find theta, the angle that the color space should be rotated based on key. */ - - /* rescale to -1.0..1.0 */ - // in_image[0] = (in_image[0] * 2.0f) - 1.0f; // UNUSED - in_image[1] = (in_image[1] * 2.0f) - 1.0f; - in_image[2] = (in_image[2] * 2.0f) - 1.0f; - - // in_key[0] = (in_key[0] * 2.0f) - 1.0f; // UNUSED - in_key[1] = (in_key[1] * 2.0f) - 1.0f; - in_key[2] = (in_key[2] * 2.0f) - 1.0f; - - theta = atan2(in_key[2], in_key[1]); - - /* Rotate the cb and cr into x/z space. */ - x_angle = in_image[1] * cosf(theta) + in_image[2] * sinf(theta); - z_angle = in_image[2] * cosf(theta) - in_image[1] * sinf(theta); - - /* If within the acceptance angle. */ - /* If kfg is <0 then the pixel is outside of the key color. */ - kfg = x_angle - (fabsf(z_angle) / tanf(acceptance / 2.0f)); - - if (kfg > 0.0f) { /* found a pixel that is within key color */ - alpha = 1.0f - (kfg / gain); - - beta = atan2(z_angle, x_angle); - - /* if beta is within the cutoff angle */ - if (fabsf(beta) < (cutoff / 2.0f)) { - alpha = 0.0f; - } - - /* don't make something that was more transparent less transparent */ - if (alpha < in_image[3]) { - output[0] = alpha; - } - else { - output[0] = in_image[3]; - } - } - else { /* Pixel is outside key color. */ - output[0] = in_image[3]; /* Make pixel just as transparent as it was before. */ - } -} - void ChromaMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.h b/source/blender/compositor/operations/COM_ChromaMatteOperation.h index 47762ac3e65..72ceb3d9160 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.h +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.h @@ -15,23 +15,10 @@ namespace blender::compositor { class ChromaMatteOperation : public MultiThreadedOperation { private: NodeChroma *settings_; - SocketReader *input_image_program_; - SocketReader *input_key_program_; public: - /** - * Default constructor - */ ChromaMatteOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void set_settings(NodeChroma *node_chroma) { settings_ = node_chroma; diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc index 8968b009ce0..c3911ef10be 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc +++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cc @@ -23,42 +23,10 @@ ColorBalanceASCCDLOperation::ColorBalanceASCCDLOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_value_operation_ = nullptr; - input_color_operation_ = nullptr; this->set_canvas_input_index(1); flags_.can_be_constant = true; } -void ColorBalanceASCCDLOperation::init_execution() -{ - input_value_operation_ = this->get_input_socket_reader(0); - input_color_operation_ = this->get_input_socket_reader(1); -} - -void ColorBalanceASCCDLOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - float value[4]; - - input_value_operation_->read_sampled(value, x, y, sampler); - input_color_operation_->read_sampled(input_color, x, y, sampler); - - float fac = value[0]; - fac = std::min(1.0f, fac); - const float mfac = 1.0f - fac; - - output[0] = mfac * input_color[0] + - fac * colorbalance_cdl(input_color[0], offset_[0], power_[0], slope_[0]); - output[1] = mfac * input_color[1] + - fac * colorbalance_cdl(input_color[1], offset_[1], power_[1], slope_[1]); - output[2] = mfac * input_color[2] + - fac * colorbalance_cdl(input_color[2], offset_[2], power_[2], slope_[2]); - output[3] = input_color[3]; -} - void ColorBalanceASCCDLOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { @@ -76,10 +44,4 @@ void ColorBalanceASCCDLOperation::update_memory_buffer_row(PixelCursor &p) } } -void ColorBalanceASCCDLOperation::deinit_execution() -{ - input_value_operation_ = nullptr; - input_color_operation_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h index 88be57ff91d..75772678802 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h +++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h @@ -14,37 +14,13 @@ namespace blender::compositor { */ class ColorBalanceASCCDLOperation : public MultiThreadedRowOperation { protected: - /** - * Prefetched reference to the input_program - */ - SocketReader *input_value_operation_; - SocketReader *input_color_operation_; - float offset_[3]; float power_[3]; float slope_[3]; public: - /** - * Default constructor - */ ColorBalanceASCCDLOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_offset(float offset[3]) { copy_v3_v3(offset_, offset); diff --git a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc index 9b0e4466bba..0ebad370beb 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc +++ b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cc @@ -30,42 +30,10 @@ ColorBalanceLGGOperation::ColorBalanceLGGOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_value_operation_ = nullptr; - input_color_operation_ = nullptr; this->set_canvas_input_index(1); flags_.can_be_constant = true; } -void ColorBalanceLGGOperation::init_execution() -{ - input_value_operation_ = this->get_input_socket_reader(0); - input_color_operation_ = this->get_input_socket_reader(1); -} - -void ColorBalanceLGGOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - float value[4]; - - input_value_operation_->read_sampled(value, x, y, sampler); - input_color_operation_->read_sampled(input_color, x, y, sampler); - - float fac = value[0]; - fac = std::min(1.0f, fac); - const float mfac = 1.0f - fac; - - output[0] = mfac * input_color[0] + - fac * colorbalance_lgg(input_color[0], lift_[0], gamma_inv_[0], gain_[0]); - output[1] = mfac * input_color[1] + - fac * colorbalance_lgg(input_color[1], lift_[1], gamma_inv_[1], gain_[1]); - output[2] = mfac * input_color[2] + - fac * colorbalance_lgg(input_color[2], lift_[2], gamma_inv_[2], gain_[2]); - output[3] = input_color[3]; -} - void ColorBalanceLGGOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { @@ -83,10 +51,4 @@ void ColorBalanceLGGOperation::update_memory_buffer_row(PixelCursor &p) } } -void ColorBalanceLGGOperation::deinit_execution() -{ - input_value_operation_ = nullptr; - input_color_operation_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h index deb829c8a73..9d25bb1d1dc 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h +++ b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h @@ -14,37 +14,13 @@ namespace blender::compositor { */ class ColorBalanceLGGOperation : public MultiThreadedRowOperation { protected: - /** - * Prefetched reference to the input_program - */ - SocketReader *input_value_operation_; - SocketReader *input_color_operation_; - float gain_[3]; float lift_[3]; float gamma_inv_[3]; public: - /** - * Default constructor - */ ColorBalanceLGGOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_gain(const float gain[3]) { copy_v3_v3(gain_, gain); diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc index 08b350c9d6c..157ed2b94b2 100644 --- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc +++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cc @@ -13,18 +13,11 @@ ColorCorrectionOperation::ColorCorrectionOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_image_ = nullptr; - input_mask_ = nullptr; red_channel_enabled_ = true; green_channel_enabled_ = true; blue_channel_enabled_ = true; flags_.can_be_constant = true; } -void ColorCorrectionOperation::init_execution() -{ - input_image_ = this->get_input_socket_reader(0); - input_mask_ = this->get_input_socket_reader(1); -} /* Calculate x^y if the function is defined. Otherwise return the given fallback value. */ BLI_INLINE float color_correct_powf_safe(const float x, const float y, const float fallback_value) @@ -35,111 +28,6 @@ BLI_INLINE float color_correct_powf_safe(const float x, const float y, const flo return powf(x, y); } -void ColorCorrectionOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_image_color[4]; - float input_mask[4]; - input_image_->read_sampled(input_image_color, x, y, sampler); - input_mask_->read_sampled(input_mask, x, y, sampler); - - float level = (input_image_color[0] + input_image_color[1] + input_image_color[2]) / 3.0f; - float contrast = data_->master.contrast; - float saturation = data_->master.saturation; - float gamma = data_->master.gamma; - float gain = data_->master.gain; - float lift = data_->master.lift; - float r, g, b; - - float value = input_mask[0]; - value = std::min(1.0f, value); - const float mvalue = 1.0f - value; - - float level_shadows = 0.0; - float level_midtones = 0.0; - float level_highlights = 0.0; -#define MARGIN 0.10f -#define MARGIN_DIV (0.5f / MARGIN) - if (level < data_->startmidtones - MARGIN) { - level_shadows = 1.0f; - } - else if (level < data_->startmidtones + MARGIN) { - level_midtones = ((level - data_->startmidtones) * MARGIN_DIV) + 0.5f; - level_shadows = 1.0f - level_midtones; - } - else if (level < data_->endmidtones - MARGIN) { - level_midtones = 1.0f; - } - else if (level < data_->endmidtones + MARGIN) { - level_highlights = ((level - data_->endmidtones) * MARGIN_DIV) + 0.5f; - level_midtones = 1.0f - level_highlights; - } - else { - level_highlights = 1.0f; - } -#undef MARGIN -#undef MARGIN_DIV - contrast *= (level_shadows * data_->shadows.contrast) + - (level_midtones * data_->midtones.contrast) + - (level_highlights * data_->highlights.contrast); - saturation *= (level_shadows * data_->shadows.saturation) + - (level_midtones * data_->midtones.saturation) + - (level_highlights * data_->highlights.saturation); - gamma *= (level_shadows * data_->shadows.gamma) + (level_midtones * data_->midtones.gamma) + - (level_highlights * data_->highlights.gamma); - gain *= (level_shadows * data_->shadows.gain) + (level_midtones * data_->midtones.gain) + - (level_highlights * data_->highlights.gain); - lift += (level_shadows * data_->shadows.lift) + (level_midtones * data_->midtones.lift) + - (level_highlights * data_->highlights.lift); - - float invgamma = 1.0f / gamma; - float luma = IMB_colormanagement_get_luminance(input_image_color); - - r = input_image_color[0]; - g = input_image_color[1]; - b = input_image_color[2]; - - r = (luma + saturation * (r - luma)); - g = (luma + saturation * (g - luma)); - b = (luma + saturation * (b - luma)); - - r = 0.5f + ((r - 0.5f) * contrast); - g = 0.5f + ((g - 0.5f) * contrast); - b = 0.5f + ((b - 0.5f) * contrast); - - /* Check for negative values to avoid nan. */ - r = color_correct_powf_safe(r * gain + lift, invgamma, r); - g = color_correct_powf_safe(g * gain + lift, invgamma, g); - b = color_correct_powf_safe(b * gain + lift, invgamma, b); - - /* Mix with mask. */ - r = mvalue * input_image_color[0] + value * r; - g = mvalue * input_image_color[1] + value * g; - b = mvalue * input_image_color[2] + value * b; - - if (red_channel_enabled_) { - output[0] = r; - } - else { - output[0] = input_image_color[0]; - } - if (green_channel_enabled_) { - output[1] = g; - } - else { - output[1] = input_image_color[1]; - } - if (blue_channel_enabled_) { - output[2] = b; - } - else { - output[2] = input_image_color[2]; - } - output[3] = input_image_color[3]; -} - void ColorCorrectionOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { @@ -217,10 +105,4 @@ void ColorCorrectionOperation::update_memory_buffer_row(PixelCursor &p) } } -void ColorCorrectionOperation::deinit_execution() -{ - input_image_ = nullptr; - input_mask_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.h b/source/blender/compositor/operations/COM_ColorCorrectionOperation.h index f90875a43f5..a386f956e19 100644 --- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.h +++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.h @@ -10,11 +10,6 @@ namespace blender::compositor { class ColorCorrectionOperation : public MultiThreadedRowOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_image_; - SocketReader *input_mask_; NodeColorCorrection *data_; bool red_channel_enabled_; @@ -24,21 +19,6 @@ class ColorCorrectionOperation : public MultiThreadedRowOperation { public: ColorCorrectionOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_data(NodeColorCorrection *data) { data_ = data; diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.cc b/source/blender/compositor/operations/COM_ColorCurveOperation.cc index 2d573e50a34..420cd8b5346 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.cc +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.cc @@ -16,72 +16,15 @@ ColorCurveOperation::ColorCurveOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_fac_program_ = nullptr; - input_image_program_ = nullptr; - input_black_program_ = nullptr; - input_white_program_ = nullptr; - this->set_canvas_input_index(1); } void ColorCurveOperation::init_execution() { CurveBaseOperation::init_execution(); - input_fac_program_ = this->get_input_socket_reader(0); - input_image_program_ = this->get_input_socket_reader(1); - input_black_program_ = this->get_input_socket_reader(2); - input_white_program_ = this->get_input_socket_reader(3); BKE_curvemapping_premultiply(curve_mapping_, false); } -void ColorCurveOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - CurveMapping *cumap = curve_mapping_; - - float fac[4]; - float image[4]; - - /* local versions of cumap->black, cumap->white, cumap->bwmul */ - float black[4]; - float white[4]; - float bwmul[3]; - - input_black_program_->read_sampled(black, x, y, sampler); - input_white_program_->read_sampled(white, x, y, sampler); - - /* get our own local bwmul value, - * since we can't be threadsafe and use cumap->bwmul & friends */ - BKE_curvemapping_set_black_white_ex(black, white, bwmul); - - input_fac_program_->read_sampled(fac, x, y, sampler); - input_image_program_->read_sampled(image, x, y, sampler); - - if (*fac >= 1.0f) { - BKE_curvemapping_evaluate_premulRGBF_ex(cumap, output, image, black, bwmul); - } - else if (*fac <= 0.0f) { - copy_v3_v3(output, image); - } - else { - float col[4]; - BKE_curvemapping_evaluate_premulRGBF_ex(cumap, col, image, black, bwmul); - interp_v3_v3v3(output, image, col, *fac); - } - output[3] = image[3]; -} - -void ColorCurveOperation::deinit_execution() -{ - CurveBaseOperation::deinit_execution(); - input_fac_program_ = nullptr; - input_image_program_ = nullptr; - input_black_program_ = nullptr; - input_white_program_ = nullptr; -} - void ColorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -120,54 +63,17 @@ ConstantLevelColorCurveOperation::ConstantLevelColorCurveOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_fac_program_ = nullptr; - input_image_program_ = nullptr; - this->set_canvas_input_index(1); } void ConstantLevelColorCurveOperation::init_execution() { CurveBaseOperation::init_execution(); - input_fac_program_ = this->get_input_socket_reader(0); - input_image_program_ = this->get_input_socket_reader(1); BKE_curvemapping_premultiply(curve_mapping_, false); BKE_curvemapping_set_black_white(curve_mapping_, black_, white_); } -void ConstantLevelColorCurveOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float fac[4]; - float image[4]; - - input_fac_program_->read_sampled(fac, x, y, sampler); - input_image_program_->read_sampled(image, x, y, sampler); - - if (*fac >= 1.0f) { - BKE_curvemapping_evaluate_premulRGBF(curve_mapping_, output, image); - } - else if (*fac <= 0.0f) { - copy_v3_v3(output, image); - } - else { - float col[4]; - BKE_curvemapping_evaluate_premulRGBF(curve_mapping_, col, image); - interp_v3_v3v3(output, image, col, *fac); - } - output[3] = image[3]; -} - -void ConstantLevelColorCurveOperation::deinit_execution() -{ - CurveBaseOperation::deinit_execution(); - input_fac_program_ = nullptr; - input_image_program_ = nullptr; -} - void ConstantLevelColorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.h b/source/blender/compositor/operations/COM_ColorCurveOperation.h index 7d69f9d0149..072075c6396 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.h +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.h @@ -9,33 +9,11 @@ namespace blender::compositor { class ColorCurveOperation : public CurveBaseOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_fac_program_; - SocketReader *input_image_program_; - SocketReader *input_black_program_; - SocketReader *input_white_program_; - public: ColorCurveOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; @@ -43,32 +21,14 @@ class ColorCurveOperation : public CurveBaseOperation { class ConstantLevelColorCurveOperation : public CurveBaseOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_fac_program_; - SocketReader *input_image_program_; float black_[3]; float white_[3]; public: ConstantLevelColorCurveOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_black_level(float black[3]) { copy_v3_v3(black_, black); diff --git a/source/blender/compositor/operations/COM_ColorExposureOperation.cc b/source/blender/compositor/operations/COM_ColorExposureOperation.cc index 69ac6028fb3..4346a89be09 100644 --- a/source/blender/compositor/operations/COM_ColorExposureOperation.cc +++ b/source/blender/compositor/operations/COM_ColorExposureOperation.cc @@ -11,34 +11,9 @@ ExposureOperation::ExposureOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_program_ = nullptr; flags_.can_be_constant = true; } -void ExposureOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); - input_exposure_program_ = this->get_input_socket_reader(1); -} - -void ExposureOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value[4]; - float input_exposure[4]; - input_program_->read_sampled(input_value, x, y, sampler); - input_exposure_program_->read_sampled(input_exposure, x, y, sampler); - const float exposure = pow(2, input_exposure[0]); - - output[0] = input_value[0] * exposure; - output[1] = input_value[1] * exposure; - output[2] = input_value[2] * exposure; - - output[3] = input_value[3]; -} - void ExposureOperation::update_memory_buffer_row(PixelCursor &p) { for (; p.out < p.row_end; p.next()) { @@ -52,10 +27,4 @@ void ExposureOperation::update_memory_buffer_row(PixelCursor &p) } } -void ExposureOperation::deinit_execution() -{ - input_program_ = nullptr; - input_exposure_program_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ColorExposureOperation.h b/source/blender/compositor/operations/COM_ColorExposureOperation.h index 93695b30016..8f75a238b8c 100644 --- a/source/blender/compositor/operations/COM_ColorExposureOperation.h +++ b/source/blender/compositor/operations/COM_ColorExposureOperation.h @@ -9,31 +9,9 @@ namespace blender::compositor { class ExposureOperation : public MultiThreadedRowOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - SocketReader *input_exposure_program_; - public: ExposureOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_row(PixelCursor &p) override; }; diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.cc b/source/blender/compositor/operations/COM_ColorMatteOperation.cc index f959f06b170..7afa92c7c36 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.cc +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.cc @@ -12,64 +12,9 @@ ColorMatteOperation::ColorMatteOperation() add_input_socket(DataType::Color); add_output_socket(DataType::Value); - input_image_program_ = nullptr; - input_key_program_ = nullptr; flags_.can_be_constant = true; } -void ColorMatteOperation::init_execution() -{ - input_image_program_ = this->get_input_socket_reader(0); - input_key_program_ = this->get_input_socket_reader(1); -} - -void ColorMatteOperation::deinit_execution() -{ - input_image_program_ = nullptr; - input_key_program_ = nullptr; -} - -void ColorMatteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_color[4]; - float in_key[4]; - - const float hue = settings_->t1; - const float sat = settings_->t2; - const float val = settings_->t3; - - float h_wrap; - - input_image_program_->read_sampled(in_color, x, y, sampler); - input_key_program_->read_sampled(in_key, x, y, sampler); - - /* Store matte(alpha) value in [0] to go with - * COM_SetAlphaMultiplyOperation and the Value output. - */ - - if ( - /* Do hue last because it needs to wrap, and does some more checks. */ - - /* sat */ (fabsf(in_color[1] - in_key[1]) < sat) && - /* val */ (fabsf(in_color[2] - in_key[2]) < val) && - - /* multiply by 2 because it wraps on both sides of the hue, - * otherwise 0.5 would key all hue's */ - - /* hue */ - ((h_wrap = 2.0f * fabsf(in_color[0] - in_key[0])) < hue || (2.0f - h_wrap) < hue)) - { - output[0] = 0.0f; /* make transparent */ - } - - else { /* Pixel is outside key color. */ - output[0] = in_color[3]; /* Make pixel just as transparent as it was before. */ - } -} - void ColorMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.h b/source/blender/compositor/operations/COM_ColorMatteOperation.h index 1edec85076e..2c02eda0bca 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.h +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.h @@ -15,23 +15,10 @@ namespace blender::compositor { class ColorMatteOperation : public MultiThreadedOperation { private: NodeChroma *settings_; - SocketReader *input_image_program_; - SocketReader *input_key_program_; public: - /** - * Default constructor - */ ColorMatteOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void set_settings(NodeChroma *node_chroma) { settings_ = node_chroma; diff --git a/source/blender/compositor/operations/COM_ColorRampOperation.cc b/source/blender/compositor/operations/COM_ColorRampOperation.cc index 2d966570c76..bc7342e249f 100644 --- a/source/blender/compositor/operations/COM_ColorRampOperation.cc +++ b/source/blender/compositor/operations/COM_ColorRampOperation.cc @@ -13,30 +13,9 @@ ColorRampOperation::ColorRampOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_program_ = nullptr; color_band_ = nullptr; flags_.can_be_constant = true; } -void ColorRampOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void ColorRampOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float values[4]; - - input_program_->read_sampled(values, x, y, sampler); - BKE_colorband_evaluate(color_band_, values[0], output); -} - -void ColorRampOperation::deinit_execution() -{ - input_program_ = nullptr; -} void ColorRampOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_ColorRampOperation.h b/source/blender/compositor/operations/COM_ColorRampOperation.h index 304b720a545..8d16d5419d7 100644 --- a/source/blender/compositor/operations/COM_ColorRampOperation.h +++ b/source/blender/compositor/operations/COM_ColorRampOperation.h @@ -11,30 +11,11 @@ namespace blender::compositor { class ColorRampOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; ColorBand *color_band_; public: ColorRampOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_color_band(ColorBand *color_band) { color_band_ = color_band; diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.cc b/source/blender/compositor/operations/COM_ColorSpillOperation.cc index d6b7fcba26e..a206ed2f637 100644 --- a/source/blender/compositor/operations/COM_ColorSpillOperation.cc +++ b/source/blender/compositor/operations/COM_ColorSpillOperation.cc @@ -13,8 +13,6 @@ ColorSpillOperation::ColorSpillOperation() add_input_socket(DataType::Value); add_output_socket(DataType::Color); - input_image_reader_ = nullptr; - input_fac_reader_ = nullptr; spill_channel_ = 1; /* GREEN */ spill_method_ = 0; flags_.can_be_constant = true; @@ -22,8 +20,6 @@ ColorSpillOperation::ColorSpillOperation() void ColorSpillOperation::init_execution() { - input_image_reader_ = this->get_input_socket_reader(0); - input_fac_reader_ = this->get_input_socket_reader(1); if (spill_channel_ == 0) { rmut_ = -1.0f; gmut_ = 1.0f; @@ -63,45 +59,6 @@ void ColorSpillOperation::init_execution() } } -void ColorSpillOperation::deinit_execution() -{ - input_image_reader_ = nullptr; - input_fac_reader_ = nullptr; -} - -void ColorSpillOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float fac[4]; - float input[4]; - input_fac_reader_->read_sampled(fac, x, y, sampler); - input_image_reader_->read_sampled(input, x, y, sampler); - float rfac = std::min(1.0f, fac[0]); - float map; - - switch (spill_method_) { - case 0: /* simple */ - map = rfac * (input[spill_channel_] - (settings_->limscale * input[settings_->limchan])); - break; - default: /* average */ - map = rfac * (input[spill_channel_] - - (settings_->limscale * AVG(input[channel2_], input[channel3_]))); - break; - } - - if (map > 0.0f) { - output[0] = input[0] + rmut_ * (settings_->uspillr * map); - output[1] = input[1] + gmut_ * (settings_->uspillg * map); - output[2] = input[2] + bmut_ * (settings_->uspillb * map); - output[3] = input[3]; - } - else { - copy_v4_v4(output, input); - } -} - void ColorSpillOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.h b/source/blender/compositor/operations/COM_ColorSpillOperation.h index cfc157bd313..2c18104e567 100644 --- a/source/blender/compositor/operations/COM_ColorSpillOperation.h +++ b/source/blender/compositor/operations/COM_ColorSpillOperation.h @@ -15,8 +15,6 @@ namespace blender::compositor { class ColorSpillOperation : public MultiThreadedOperation { protected: NodeColorspill *settings_; - SocketReader *input_image_reader_; - SocketReader *input_fac_reader_; int spill_channel_; int spill_method_; int channel2_; @@ -24,18 +22,9 @@ class ColorSpillOperation : public MultiThreadedOperation { float rmut_, gmut_, bmut_; public: - /** - * Default constructor - */ ColorSpillOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void init_execution() override; - void deinit_execution() override; void set_settings(NodeColorspill *node_color_spill) { diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cc b/source/blender/compositor/operations/COM_CompositorOperation.cc index 496a3307754..e69e184f124 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cc +++ b/source/blender/compositor/operations/COM_CompositorOperation.cc @@ -23,8 +23,6 @@ CompositorOperation::CompositorOperation() this->set_render_data(nullptr); output_buffer_ = nullptr; - image_input_ = nullptr; - alpha_input_ = nullptr; use_alpha_input_ = false; active_ = false; @@ -43,8 +41,6 @@ void CompositorOperation::init_execution() } /* When initializing the tree during initial load the width and height can be zero. */ - image_input_ = get_input_socket_reader(0); - alpha_input_ = get_input_socket_reader(1); if (this->get_width() * this->get_height() != 0) { output_buffer_ = (float *)MEM_callocN( sizeof(float[4]) * this->get_width() * this->get_height(), "CompositorOperation"); @@ -93,89 +89,6 @@ void CompositorOperation::deinit_execution() } output_buffer_ = nullptr; - image_input_ = nullptr; - alpha_input_ = nullptr; -} - -void CompositorOperation::execute_region(rcti *rect, uint /*tile_number*/) -{ - float color[8]; /* 7 is enough. */ - float *buffer = output_buffer_; - - if (!buffer) { - return; - } - int x1 = rect->xmin; - int y1 = rect->ymin; - int x2 = rect->xmax; - int y2 = rect->ymax; - int offset = (y1 * this->get_width() + x1); - int add = (this->get_width() - (x2 - x1)); - int offset4 = offset * COM_DATA_TYPE_COLOR_CHANNELS; - int x; - int y; - bool breaked = false; - int dx = 0, dy = 0; - -#if 0 - const RenderData *rd = rd_; - - if (rd->mode & R_BORDER && rd->mode & R_CROP) { - /** - * When using cropped render result, need to re-position area of interest, - * so it'll match bounds of render border within frame. By default, canvas - * will be centered between full frame and cropped frame, so we use such - * scheme to map cropped coordinates to full-frame coordinates - * - * ^ Y - * | Width - * +------------------------------------------------+ - * | | - * | | - * | Centered canvas, we map coordinate from it | - * | +------------------+ | - * | | | | H - * | | | | e - * | +------------------+ . Center | | i - * | | | | | | g - * | | | | | | h - * | |....dx.... +------|-----------+ | t - * | | . dy | | - * | +------------------+ | - * | Render border, we map coordinates to it | - * | | X - * +------------------------------------------------+----> - * Full frame - */ - - int full_width, full_height; - BKE_render_resolution(rd, false, &full_width, &full_height); - - dx = rd->border.xmin * full_width - (full_width - this->get_width()) / 2.0f; - dy = rd->border.ymin * full_height - (full_height - this->get_height()) / 2.0f; - } -#endif - - for (y = y1; y < y2 && (!breaked); y++) { - for (x = x1; x < x2 && (!breaked); x++) { - int input_x = x + dx, input_y = y + dy; - - image_input_->read_sampled(color, input_x, input_y, PixelSampler::Nearest); - if (use_alpha_input_) { - alpha_input_->read_sampled(&(color[3]), input_x, input_y, PixelSampler::Nearest); - } - - copy_v4_v4(buffer + offset4, color); - - offset4 += COM_DATA_TYPE_COLOR_CHANNELS; - offset++; - if (is_braked()) { - breaked = true; - } - } - offset += add; - offset4 += add * COM_DATA_TYPE_COLOR_CHANNELS; - } } void CompositorOperation::set_scene_name(const char *scene_name) @@ -217,16 +130,8 @@ void CompositorOperation::determine_canvas(const rcti & /*preferred_area*/, rcti rcti local_preferred; BLI_rcti_init(&local_preferred, 0, width, 0, height); - switch (execution_model_) { - case eExecutionModel::Tiled: - NodeOperation::determine_canvas(local_preferred, r_area); - r_area = local_preferred; - break; - case eExecutionModel::FullFrame: - set_determined_canvas_modifier([&](rcti &canvas) { canvas = local_preferred; }); - NodeOperation::determine_canvas(local_preferred, r_area); - break; - } + set_determined_canvas_modifier([&](rcti &canvas) { canvas = local_preferred; }); + NodeOperation::determine_canvas(local_preferred, r_area); } } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index f0115c84852..a0eebe9c471 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -31,16 +31,6 @@ class CompositorOperation : public MultiThreadedOperation { */ float *output_buffer_; - /** - * \brief local reference to the input image operation - */ - SocketReader *image_input_; - - /** - * \brief local reference to the input alpha operation - */ - SocketReader *alpha_input_; - /** * \brief Ignore any alpha input */ @@ -62,7 +52,6 @@ class CompositorOperation : public MultiThreadedOperation { { return active_; } - void execute_region(rcti *rect, unsigned int tile_number) override; void set_scene(const struct Scene *scene) { scene_ = scene; diff --git a/source/blender/compositor/operations/COM_ConstantOperation.cc b/source/blender/compositor/operations/COM_ConstantOperation.cc index 6b6d599401f..527a9b2a449 100644 --- a/source/blender/compositor/operations/COM_ConstantOperation.cc +++ b/source/blender/compositor/operations/COM_ConstantOperation.cc @@ -10,7 +10,6 @@ ConstantOperation::ConstantOperation() { needs_canvas_to_get_constant_ = false; flags_.is_constant_operation = true; - flags_.is_fullframe_operation = true; } bool ConstantOperation::can_get_constant_elem() const diff --git a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cc b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cc index eeba7a681e7..95464a14940 100644 --- a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cc +++ b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cc @@ -12,29 +12,7 @@ ConvertColorProfileOperation::ConvertColorProfileOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_operation_ = nullptr; predivided_ = false; } -void ConvertColorProfileOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void ConvertColorProfileOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float color[4]; - input_operation_->read_sampled(color, x, y, sampler); - IMB_buffer_float_from_float( - output, color, 4, to_profile_, from_profile_, predivided_, 1, 1, 0, 0); -} - -void ConvertColorProfileOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h index b92c8dcbeb1..09cf3e528de 100644 --- a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h @@ -14,11 +14,6 @@ namespace blender::compositor { */ class ConvertColorProfileOperation : public NodeOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_operation_; - /** * \brief color profile where to convert from */ @@ -40,21 +35,6 @@ class ConvertColorProfileOperation : public NodeOperation { */ ConvertColorProfileOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_from_color_profile(int color_profile) { from_profile_ = color_profile; diff --git a/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc index f06bca284e3..89af6187112 100644 --- a/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc +++ b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.cc @@ -12,7 +12,6 @@ ConvertColorSpaceOperation::ConvertColorSpaceOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - this->input_program_ = nullptr; color_processor_ = nullptr; } @@ -38,23 +37,10 @@ void ConvertColorSpaceOperation::init_execution() return; } - this->input_program_ = this->get_input_socket_reader(0); - color_processor_ = IMB_colormanagement_colorspace_processor_new(settings_->from_color_space, settings_->to_color_space); } -void ConvertColorSpaceOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - this->input_program_->read_sampled(output, x, y, sampler); - if (color_processor_ != nullptr) { - IMB_colormanagement_processor_apply_pixel(color_processor_, output, 3); - } -} - void ConvertColorSpaceOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -73,7 +59,6 @@ void ConvertColorSpaceOperation::deinit_execution() if (color_processor_ != nullptr) { IMB_colormanagement_processor_free(color_processor_); } - this->input_program_ = nullptr; this->color_processor_ = nullptr; } diff --git a/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h index e8e3b8067cc..d60d0336dfb 100644 --- a/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorSpaceOperation.h @@ -12,7 +12,6 @@ namespace blender::compositor { class ConvertColorSpaceOperation : public MultiThreadedOperation { private: - SocketReader *input_program_; NodeConvertColorSpace *settings_; ColormanageProcessor *color_processor_; @@ -20,19 +19,8 @@ class ConvertColorSpaceOperation : public MultiThreadedOperation { ConvertColorSpaceOperation(); void set_settings(NodeConvertColorSpace *node_color_space); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - /** - * Initialize the execution - */ void init_execution() override; - - /** - * Deinitialize the execution - */ void deinit_execution() override; void update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc index c23ba17da3e..4ecf27c4a09 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cc @@ -46,40 +46,6 @@ void ConvertDepthToRadiusOperation::init_execution() blur_y_operation_->set_size(1.0f); } -/* Given a depth texture, compute the radius of the circle of confusion in pixels based on equation - * (8) of the paper: - * - * Potmesil, Michael, and Indranil Chakravarty. "A lens and aperture camera model for synthetic - * image generation." ACM SIGGRAPH Computer Graphics 15.3 (1981): 297-305. */ -void ConvertDepthToRadiusOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value[4]; - depth_input_operation_->read_sampled(input_value, x, y, sampler); - const float depth = input_value[0]; - - /* Compute `Vu` in equation (7). */ - const float distance_to_image_of_object = (focal_length * depth) / (depth - focal_length); - - /* Compute C in equation (8). Notice that the last multiplier was included in the absolute since - * it is negative when the object distance is less than the focal length, as noted in equation - * (7). */ - float diameter = abs((distance_to_image_of_object - distance_to_image_of_focus) * - (focal_length / (f_stop * distance_to_image_of_object))); - - /* The diameter is in meters, so multiply by the pixels per meter. */ - float radius = (diameter / 2.0f) * pixels_per_meter; - - output[0] = math::min(max_radius, radius); -} - -void ConvertDepthToRadiusOperation::deinit_execution() -{ - depth_input_operation_ = nullptr; -} - /* Given a depth texture, compute the radius of the circle of confusion in pixels based on equation * (8) of the paper: * diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h index 32eacf5a617..e8ef8592999 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h @@ -4,8 +4,7 @@ #pragma once -#include "COM_GaussianXBlurOperation.h" -#include "COM_GaussianYBlurOperation.h" +#include "COM_GaussianBlurBaseOperation.h" #include "COM_MultiThreadedOperation.h" namespace blender::compositor { @@ -30,12 +29,8 @@ class ConvertDepthToRadiusOperation : public MultiThreadedOperation { public: ConvertDepthToRadiusOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void init_execution() override; - void deinit_execution() override; - void set_data(const NodeDefocus *data) { data_ = data; diff --git a/source/blender/compositor/operations/COM_ConvertOperation.cc b/source/blender/compositor/operations/COM_ConvertOperation.cc index f14dcab1396..d4b15bea1ef 100644 --- a/source/blender/compositor/operations/COM_ConvertOperation.cc +++ b/source/blender/compositor/operations/COM_ConvertOperation.cc @@ -12,20 +12,9 @@ namespace blender::compositor { ConvertBaseOperation::ConvertBaseOperation() { - input_operation_ = nullptr; flags_.can_be_constant = true; } -void ConvertBaseOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void ConvertBaseOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - void ConvertBaseOperation::hash_output_params() {} void ConvertBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, @@ -44,17 +33,6 @@ ConvertValueToColorOperation::ConvertValueToColorOperation() : ConvertBaseOperat this->add_output_socket(DataType::Color); } -void ConvertValueToColorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float value; - input_operation_->read_sampled(&value, x, y, sampler); - output[0] = output[1] = output[2] = value; - output[3] = 1.0f; -} - void ConvertValueToColorOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -71,16 +49,6 @@ ConvertColorToValueOperation::ConvertColorToValueOperation() : ConvertBaseOperat this->add_output_socket(DataType::Value); } -void ConvertColorToValueOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - output[0] = (input_color[0] + input_color[1] + input_color[2]) / 3.0f; -} - void ConvertColorToValueOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -97,16 +65,6 @@ ConvertColorToBWOperation::ConvertColorToBWOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Value); } -void ConvertColorToBWOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - output[0] = IMB_colormanagement_get_luminance(input_color); -} - void ConvertColorToBWOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -122,16 +80,6 @@ ConvertColorToVectorOperation::ConvertColorToVectorOperation() : ConvertBaseOper this->add_output_socket(DataType::Vector); } -void ConvertColorToVectorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float color[4]; - input_operation_->read_sampled(color, x, y, sampler); - copy_v3_v3(output, color); -} - void ConvertColorToVectorOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -147,16 +95,6 @@ ConvertValueToVectorOperation::ConvertValueToVectorOperation() : ConvertBaseOper this->add_output_socket(DataType::Vector); } -void ConvertValueToVectorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float value; - input_operation_->read_sampled(&value, x, y, sampler); - output[0] = output[1] = output[2] = value; -} - void ConvertValueToVectorOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -172,15 +110,6 @@ ConvertVectorToColorOperation::ConvertVectorToColorOperation() : ConvertBaseOper this->add_output_socket(DataType::Color); } -void ConvertVectorToColorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - input_operation_->read_sampled(output, x, y, sampler); - output[3] = 1.0f; -} - void ConvertVectorToColorOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -197,16 +126,6 @@ ConvertVectorToValueOperation::ConvertVectorToValueOperation() : ConvertBaseOper this->add_output_socket(DataType::Value); } -void ConvertVectorToValueOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input[4]; - input_operation_->read_sampled(input, x, y, sampler); - output[0] = (input[0] + input[1] + input[2]) / 3.0f; -} - void ConvertVectorToValueOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -239,24 +158,6 @@ void ConvertRGBToYCCOperation::set_mode(int mode) } } -void ConvertRGBToYCCOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - float color[3]; - - input_operation_->read_sampled(input_color, x, y, sampler); - rgb_to_ycc( - input_color[0], input_color[1], input_color[2], &color[0], &color[1], &color[2], mode_); - - /* divided by 255 to normalize for viewing in */ - /* R,G,B --> Y,Cb,Cr */ - mul_v3_v3fl(output, color, 1.0f / 255.0f); - output[3] = input_color[3]; -} - void ConvertRGBToYCCOperation::hash_output_params() { ConvertBaseOperation::hash_output_params(); @@ -299,23 +200,6 @@ void ConvertYCCToRGBOperation::set_mode(int mode) } } -void ConvertYCCToRGBOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - - /* need to un-normalize the data */ - /* R,G,B --> Y,Cb,Cr */ - mul_v3_fl(input_color, 255.0f); - - ycc_to_rgb( - input_color[0], input_color[1], input_color[2], &output[0], &output[1], &output[2], mode_); - output[3] = input_color[3]; -} - void ConvertYCCToRGBOperation::hash_output_params() { ConvertBaseOperation::hash_output_params(); @@ -341,23 +225,6 @@ ConvertRGBToYUVOperation::ConvertRGBToYUVOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Color); } -void ConvertRGBToYUVOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - rgb_to_yuv(input_color[0], - input_color[1], - input_color[2], - &output[0], - &output[1], - &output[2], - BLI_YUV_ITU_BT709); - output[3] = input_color[3]; -} - void ConvertRGBToYUVOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -375,23 +242,6 @@ ConvertYUVToRGBOperation::ConvertYUVToRGBOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Color); } -void ConvertYUVToRGBOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - yuv_to_rgb(input_color[0], - input_color[1], - input_color[2], - &output[0], - &output[1], - &output[2], - BLI_YUV_ITU_BT709); - output[3] = input_color[3]; -} - void ConvertYUVToRGBOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -409,17 +259,6 @@ ConvertRGBToHSVOperation::ConvertRGBToHSVOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Color); } -void ConvertRGBToHSVOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - rgb_to_hsv_v(input_color, output); - output[3] = input_color[3]; -} - void ConvertRGBToHSVOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -437,20 +276,6 @@ ConvertHSVToRGBOperation::ConvertHSVToRGBOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Color); } -void ConvertHSVToRGBOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - hsv_to_rgb_v(input_color, output); - output[0] = max_ff(output[0], 0.0f); - output[1] = max_ff(output[1], 0.0f); - output[2] = max_ff(output[2], 0.0f); - output[3] = input_color[3]; -} - void ConvertHSVToRGBOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -471,17 +296,6 @@ ConvertRGBToHSLOperation::ConvertRGBToHSLOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Color); } -void ConvertRGBToHSLOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - rgb_to_hsl_v(input_color, output); - output[3] = input_color[3]; -} - void ConvertRGBToHSLOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -499,20 +313,6 @@ ConvertHSLToRGBOperation::ConvertHSLToRGBOperation() : ConvertBaseOperation() this->add_output_socket(DataType::Color); } -void ConvertHSLToRGBOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_operation_->read_sampled(input_color, x, y, sampler); - hsl_to_rgb_v(input_color, output); - output[0] = max_ff(output[0], 0.0f); - output[1] = max_ff(output[1], 0.0f); - output[2] = max_ff(output[2], 0.0f); - output[3] = input_color[3]; -} - void ConvertHSLToRGBOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -533,17 +333,6 @@ ConvertPremulToStraightOperation::ConvertPremulToStraightOperation() : ConvertBa this->add_output_socket(DataType::Color); } -void ConvertPremulToStraightOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - ColorSceneLinear4f input; - input_operation_->read_sampled(input, x, y, sampler); - ColorSceneLinear4f converted = input.unpremultiply_alpha(); - copy_v4_v4(output, converted); -} - void ConvertPremulToStraightOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -559,17 +348,6 @@ ConvertStraightToPremulOperation::ConvertStraightToPremulOperation() : ConvertBa this->add_output_socket(DataType::Color); } -void ConvertStraightToPremulOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - ColorSceneLinear4f input; - input_operation_->read_sampled(input, x, y, sampler); - ColorSceneLinear4f converted = input.premultiply_alpha(); - copy_v4_v4(output, converted); -} - void ConvertStraightToPremulOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -583,28 +361,8 @@ SeparateChannelOperation::SeparateChannelOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Value); - input_operation_ = nullptr; flags_.can_be_constant = true; } -void SeparateChannelOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void SeparateChannelOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - -void SeparateChannelOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input[4]; - input_operation_->read_sampled(input, x, y, sampler); - output[0] = input[channel_]; -} void SeparateChannelOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -625,54 +383,10 @@ CombineChannelsOperation::CombineChannelsOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_channel1_operation_ = nullptr; - input_channel2_operation_ = nullptr; - input_channel3_operation_ = nullptr; - input_channel4_operation_ = nullptr; flags_.can_be_constant = true; } -void CombineChannelsOperation::init_execution() -{ - input_channel1_operation_ = this->get_input_socket_reader(0); - input_channel2_operation_ = this->get_input_socket_reader(1); - input_channel3_operation_ = this->get_input_socket_reader(2); - input_channel4_operation_ = this->get_input_socket_reader(3); -} - -void CombineChannelsOperation::deinit_execution() -{ - input_channel1_operation_ = nullptr; - input_channel2_operation_ = nullptr; - input_channel3_operation_ = nullptr; - input_channel4_operation_ = nullptr; -} - -void CombineChannelsOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input[4]; - if (input_channel1_operation_) { - input_channel1_operation_->read_sampled(input, x, y, sampler); - output[0] = input[0]; - } - if (input_channel2_operation_) { - input_channel2_operation_->read_sampled(input, x, y, sampler); - output[1] = input[0]; - } - if (input_channel3_operation_) { - input_channel3_operation_->read_sampled(input, x, y, sampler); - output[2] = input[0]; - } - if (input_channel4_operation_) { - input_channel4_operation_->read_sampled(input, x, y, sampler); - output[3] = input[0]; - } -} - void CombineChannelsOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ConvertOperation.h b/source/blender/compositor/operations/COM_ConvertOperation.h index 2c6add73d04..70b58af2dda 100644 --- a/source/blender/compositor/operations/COM_ConvertOperation.h +++ b/source/blender/compositor/operations/COM_ConvertOperation.h @@ -9,15 +9,9 @@ namespace blender::compositor { class ConvertBaseOperation : public MultiThreadedOperation { - protected: - SocketReader *input_operation_; - public: ConvertBaseOperation(); - void init_execution() override; - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) final; @@ -31,8 +25,6 @@ class ConvertValueToColorOperation : public ConvertBaseOperation { public: ConvertValueToColorOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -41,8 +33,6 @@ class ConvertColorToValueOperation : public ConvertBaseOperation { public: ConvertColorToValueOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -51,8 +41,6 @@ class ConvertColorToBWOperation : public ConvertBaseOperation { public: ConvertColorToBWOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -61,8 +49,6 @@ class ConvertColorToVectorOperation : public ConvertBaseOperation { public: ConvertColorToVectorOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -71,8 +57,6 @@ class ConvertValueToVectorOperation : public ConvertBaseOperation { public: ConvertValueToVectorOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -81,8 +65,6 @@ class ConvertVectorToColorOperation : public ConvertBaseOperation { public: ConvertVectorToColorOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -91,8 +73,6 @@ class ConvertVectorToValueOperation : public ConvertBaseOperation { public: ConvertVectorToValueOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -105,8 +85,6 @@ class ConvertRGBToYCCOperation : public ConvertBaseOperation { public: ConvertRGBToYCCOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - /** Set the YCC mode */ void set_mode(int mode); @@ -123,8 +101,6 @@ class ConvertYCCToRGBOperation : public ConvertBaseOperation { public: ConvertYCCToRGBOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - /** Set the YCC mode */ void set_mode(int mode); @@ -137,8 +113,6 @@ class ConvertRGBToYUVOperation : public ConvertBaseOperation { public: ConvertRGBToYUVOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -147,8 +121,6 @@ class ConvertYUVToRGBOperation : public ConvertBaseOperation { public: ConvertYUVToRGBOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -157,8 +129,6 @@ class ConvertRGBToHSVOperation : public ConvertBaseOperation { public: ConvertRGBToHSVOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -167,8 +137,6 @@ class ConvertHSVToRGBOperation : public ConvertBaseOperation { public: ConvertHSVToRGBOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -177,8 +145,6 @@ class ConvertRGBToHSLOperation : public ConvertBaseOperation { public: ConvertRGBToHSLOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -187,8 +153,6 @@ class ConvertHSLToRGBOperation : public ConvertBaseOperation { public: ConvertHSLToRGBOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -197,8 +161,6 @@ class ConvertPremulToStraightOperation : public ConvertBaseOperation { public: ConvertPremulToStraightOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; @@ -207,23 +169,16 @@ class ConvertStraightToPremulOperation : public ConvertBaseOperation { public: ConvertStraightToPremulOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class SeparateChannelOperation : public MultiThreadedOperation { private: - SocketReader *input_operation_; int channel_; public: SeparateChannelOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; void set_channel(int channel) { @@ -236,18 +191,8 @@ class SeparateChannelOperation : public MultiThreadedOperation { }; class CombineChannelsOperation : public MultiThreadedOperation { - private: - SocketReader *input_channel1_operation_; - SocketReader *input_channel2_operation_; - SocketReader *input_channel3_operation_; - SocketReader *input_channel4_operation_; - public: CombineChannelsOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc index cdfeb9b5ac6..e4d0d967de7 100644 --- a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc +++ b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cc @@ -6,80 +6,6 @@ namespace blender::compositor { -void ConvolutionEdgeFilterOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - float in1[4], in2[4], res1[4] = {0.0}, res2[4] = {0.0}; - - int x1 = x - 1; - int x2 = x; - int x3 = x + 1; - int y1 = y - 1; - int y2 = y; - int y3 = y + 1; - CLAMP(x1, 0, get_width() - 1); - CLAMP(x2, 0, get_width() - 1); - CLAMP(x3, 0, get_width() - 1); - CLAMP(y1, 0, get_height() - 1); - CLAMP(y2, 0, get_height() - 1); - CLAMP(y3, 0, get_height() - 1); - - float value[4]; - input_value_operation_->read(value, x2, y2, nullptr); - float mval = 1.0f - value[0]; - - input_operation_->read(in1, x1, y1, nullptr); - madd_v3_v3fl(res1, in1, filter_[0]); - madd_v3_v3fl(res2, in1, filter_[0]); - - input_operation_->read(in1, x2, y1, nullptr); - madd_v3_v3fl(res1, in1, filter_[1]); - madd_v3_v3fl(res2, in1, filter_[3]); - - input_operation_->read(in1, x3, y1, nullptr); - madd_v3_v3fl(res1, in1, filter_[2]); - madd_v3_v3fl(res2, in1, filter_[6]); - - input_operation_->read(in1, x1, y2, nullptr); - madd_v3_v3fl(res1, in1, filter_[3]); - madd_v3_v3fl(res2, in1, filter_[1]); - - input_operation_->read(in2, x2, y2, nullptr); - madd_v3_v3fl(res1, in2, filter_[4]); - madd_v3_v3fl(res2, in2, filter_[4]); - - input_operation_->read(in1, x3, y2, nullptr); - madd_v3_v3fl(res1, in1, filter_[5]); - madd_v3_v3fl(res2, in1, filter_[7]); - - input_operation_->read(in1, x1, y3, nullptr); - madd_v3_v3fl(res1, in1, filter_[6]); - madd_v3_v3fl(res2, in1, filter_[2]); - - input_operation_->read(in1, x2, y3, nullptr); - madd_v3_v3fl(res1, in1, filter_[7]); - madd_v3_v3fl(res2, in1, filter_[5]); - - input_operation_->read(in1, x3, y3, nullptr); - madd_v3_v3fl(res1, in1, filter_[8]); - madd_v3_v3fl(res2, in1, filter_[8]); - - output[0] = sqrt(res1[0] * res1[0] + res2[0] * res2[0]); - output[1] = sqrt(res1[1] * res1[1] + res2[1] * res2[1]); - output[2] = sqrt(res1[2] * res1[2] + res2[2] * res2[2]); - - output[0] = output[0] * value[0] + in2[0] * mval; - output[1] = output[1] * value[0] + in2[1] * mval; - output[2] = output[2] * value[0] + in2[2] * mval; - - output[3] = in2[3]; - - /* Make sure we don't return negative color. */ - output[0] = std::max(output[0], 0.0f); - output[1] = std::max(output[1], 0.0f); - output[2] = std::max(output[2], 0.0f); - output[3] = std::max(output[3], 0.0f); -} - void ConvolutionEdgeFilterOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h index a48871682b3..9411a221d4a 100644 --- a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h +++ b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h @@ -10,8 +10,6 @@ namespace blender::compositor { class ConvolutionEdgeFilterOperation : public ConvolutionFilterOperation { public: - void execute_pixel(float output[4], int x, int y, void *data) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc index 42728282bef..14b5df26e6f 100644 --- a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc +++ b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cc @@ -12,15 +12,8 @@ ConvolutionFilterOperation::ConvolutionFilterOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_operation_ = nullptr; - flags_.complex = true; flags_.can_be_constant = true; } -void ConvolutionFilterOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); - input_value_operation_ = this->get_input_socket_reader(1); -} void ConvolutionFilterOperation::set3x3Filter( float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9) @@ -38,78 +31,6 @@ void ConvolutionFilterOperation::set3x3Filter( filter_width_ = 3; } -void ConvolutionFilterOperation::deinit_execution() -{ - input_operation_ = nullptr; - input_value_operation_ = nullptr; -} - -void ConvolutionFilterOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - float in1[4]; - float in2[4]; - int x1 = x - 1; - int x2 = x; - int x3 = x + 1; - int y1 = y - 1; - int y2 = y; - int y3 = y + 1; - CLAMP(x1, 0, get_width() - 1); - CLAMP(x2, 0, get_width() - 1); - CLAMP(x3, 0, get_width() - 1); - CLAMP(y1, 0, get_height() - 1); - CLAMP(y2, 0, get_height() - 1); - CLAMP(y3, 0, get_height() - 1); - float value[4]; - input_value_operation_->read(value, x2, y2, nullptr); - const float mval = 1.0f - value[0]; - - zero_v4(output); - input_operation_->read(in1, x1, y1, nullptr); - madd_v4_v4fl(output, in1, filter_[0]); - input_operation_->read(in1, x2, y1, nullptr); - madd_v4_v4fl(output, in1, filter_[1]); - input_operation_->read(in1, x3, y1, nullptr); - madd_v4_v4fl(output, in1, filter_[2]); - input_operation_->read(in1, x1, y2, nullptr); - madd_v4_v4fl(output, in1, filter_[3]); - input_operation_->read(in2, x2, y2, nullptr); - madd_v4_v4fl(output, in2, filter_[4]); - input_operation_->read(in1, x3, y2, nullptr); - madd_v4_v4fl(output, in1, filter_[5]); - input_operation_->read(in1, x1, y3, nullptr); - madd_v4_v4fl(output, in1, filter_[6]); - input_operation_->read(in1, x2, y3, nullptr); - madd_v4_v4fl(output, in1, filter_[7]); - input_operation_->read(in1, x3, y3, nullptr); - madd_v4_v4fl(output, in1, filter_[8]); - - output[0] = output[0] * value[0] + in2[0] * mval; - output[1] = output[1] * value[0] + in2[1] * mval; - output[2] = output[2] * value[0] + in2[2] * mval; - output[3] = output[3] * value[0] + in2[3] * mval; - - /* Make sure we don't return negative color. */ - output[0] = std::max(output[0], 0.0f); - output[1] = std::max(output[1], 0.0f); - output[2] = std::max(output[2], 0.0f); - output[3] = std::max(output[3], 0.0f); -} - -bool ConvolutionFilterOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - int addx = (filter_width_ - 1) / 2 + 1; - int addy = (filter_height_ - 1) / 2 + 1; - new_input.xmax = input->xmax + addx; - new_input.xmin = input->xmin - addx; - new_input.ymax = input->ymax + addy; - new_input.ymin = input->ymin - addy; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void ConvolutionFilterOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h index daadad6f9c4..2ed01dea786 100644 --- a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h +++ b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h @@ -18,21 +18,12 @@ class ConvolutionFilterOperation : public MultiThreadedOperation { int filter_height_; protected: - SocketReader *input_operation_; - SocketReader *input_value_operation_; float filter_[9]; public: ConvolutionFilterOperation(); void set3x3Filter( float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel(float output[4], int x, int y, void *data) override; - - void init_execution() override; - void deinit_execution() override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) final; virtual void update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_CropOperation.cc b/source/blender/compositor/operations/COM_CropOperation.cc index 75742e5606b..ce5d1c93159 100644 --- a/source/blender/compositor/operations/COM_CropOperation.cc +++ b/source/blender/compositor/operations/COM_CropOperation.cc @@ -12,7 +12,6 @@ CropBaseOperation::CropBaseOperation() { this->add_input_socket(DataType::Color, ResizeMode::Align); this->add_output_socket(DataType::Color); - input_operation_ = nullptr; settings_ = nullptr; flags_.can_be_constant = true; } @@ -47,30 +46,14 @@ void CropBaseOperation::update_area() void CropBaseOperation::init_execution() { - input_operation_ = this->get_input_socket_reader(0); update_area(); } -void CropBaseOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - CropOperation::CropOperation() : CropBaseOperation() { /* pass */ } -void CropOperation::execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) -{ - if ((x < xmax_ && x >= xmin_) && (y < ymax_ && y >= ymin_)) { - input_operation_->read_sampled(output, x, y, sampler); - } - else { - zero_v4(output); - } -} - void CropOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -90,20 +73,6 @@ CropImageOperation::CropImageOperation() : CropBaseOperation() /* pass */ } -bool CropImageOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - - new_input.xmax = input->xmax + xmin_; - new_input.xmin = input->xmin + xmin_; - new_input.ymax = input->ymax + ymin_; - new_input.ymin = input->ymin + ymin_; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void CropImageOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) @@ -124,19 +93,6 @@ void CropImageOperation::determine_canvas(const rcti &preferred_area, rcti &r_ar r_area.ymax = r_area.ymin + (ymax_ - ymin_); } -void CropImageOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - if (x >= 0 && x < get_width() && y >= 0 && y < get_height()) { - input_operation_->read_sampled(output, (x + xmin_), (y + ymin_), sampler); - } - else { - zero_v4(output); - } -} - void CropImageOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_CropOperation.h b/source/blender/compositor/operations/COM_CropOperation.h index b40bfc81b0e..55cad40f52b 100644 --- a/source/blender/compositor/operations/COM_CropOperation.h +++ b/source/blender/compositor/operations/COM_CropOperation.h @@ -10,7 +10,6 @@ namespace blender::compositor { class CropBaseOperation : public MultiThreadedOperation { protected: - SocketReader *input_operation_; NodeTwoXYs *settings_; bool relative_; int xmax_; @@ -23,7 +22,6 @@ class CropBaseOperation : public MultiThreadedOperation { public: CropBaseOperation(); void init_execution() override; - void deinit_execution() override; void set_crop_settings(NodeTwoXYs *settings) { settings_ = settings; @@ -38,8 +36,6 @@ class CropOperation : public CropBaseOperation { private: public: CropOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; @@ -49,12 +45,7 @@ class CropImageOperation : public CropBaseOperation { private: public: CropImageOperation(); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.cc b/source/blender/compositor/operations/COM_CryptomatteOperation.cc index dc5cb210329..924c06d09ed 100644 --- a/source/blender/compositor/operations/COM_CryptomatteOperation.cc +++ b/source/blender/compositor/operations/COM_CryptomatteOperation.cc @@ -13,7 +13,6 @@ CryptomatteOperation::CryptomatteOperation(size_t num_inputs) this->add_input_socket(DataType::Color); } this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; } @@ -31,33 +30,6 @@ void CryptomatteOperation::add_object_index(float object_index) } } -void CryptomatteOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float input[4]; - output[0] = output[1] = output[2] = output[3] = 0.0f; - for (size_t i = 0; i < inputs.size(); i++) { - inputs[i]->read(input, x, y, data); - if (i == 0) { - /* Write the front-most object as false color for picking. */ - output[0] = input[0]; - uint32_t m3hash; - ::memcpy(&m3hash, &input[0], sizeof(uint32_t)); - /* Since the red channel is likely to be out of display range, - * setting green and blue gives more meaningful images. */ - output[1] = (float(m3hash << 8) / float(UINT32_MAX)); - output[2] = (float(m3hash << 16) / float(UINT32_MAX)); - } - for (float hash : object_index_) { - if (input[0] == hash) { - output[3] += input[1]; - } - if (input[2] == hash) { - output[3] += input[3]; - } - } - } -} - void CryptomatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.h b/source/blender/compositor/operations/COM_CryptomatteOperation.h index 908a44fea11..8b99755c3e1 100644 --- a/source/blender/compositor/operations/COM_CryptomatteOperation.h +++ b/source/blender/compositor/operations/COM_CryptomatteOperation.h @@ -18,7 +18,6 @@ class CryptomatteOperation : public MultiThreadedOperation { CryptomatteOperation(size_t num_inputs = 6); void init_execution() override; - void execute_pixel(float output[4], int x, int y, void *data) override; void add_object_index(float object_index); diff --git a/source/blender/compositor/operations/COM_CurveBaseOperation.h b/source/blender/compositor/operations/COM_CurveBaseOperation.h index 085ca91bfd2..432ef9a823d 100644 --- a/source/blender/compositor/operations/COM_CurveBaseOperation.h +++ b/source/blender/compositor/operations/COM_CurveBaseOperation.h @@ -12,18 +12,12 @@ namespace blender::compositor { class CurveBaseOperation : public MultiThreadedOperation { protected: - /** - * Cached reference to the input_program - */ CurveMapping *curve_mapping_; public: CurveBaseOperation(); ~CurveBaseOperation(); - /** - * Initialize the execution - */ void init_execution() override; void deinit_execution() override; diff --git a/source/blender/compositor/operations/COM_DenoiseOperation.cc b/source/blender/compositor/operations/COM_DenoiseOperation.cc index 0c8b94c7612..45bb65aaf61 100644 --- a/source/blender/compositor/operations/COM_DenoiseOperation.cc +++ b/source/blender/compositor/operations/COM_DenoiseOperation.cc @@ -113,26 +113,10 @@ class DenoiseFilter { DenoiseBaseOperation::DenoiseBaseOperation() { - flags_.is_fullframe_operation = true; flags_.can_be_constant = true; output_rendered_ = false; } -bool DenoiseBaseOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - if (is_cached()) { - return false; - } - - rcti new_input; - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void DenoiseBaseOperation::get_area_of_interest(const int /*input_idx*/, const rcti & /*output_area*/, rcti &r_input_area) @@ -148,21 +132,6 @@ DenoiseOperation::DenoiseOperation() this->add_output_socket(DataType::Color); settings_ = nullptr; } -void DenoiseOperation::init_execution() -{ - SingleThreadedOperation::init_execution(); - input_program_color_ = get_input_socket_reader(0); - input_program_normal_ = get_input_socket_reader(1); - input_program_albedo_ = get_input_socket_reader(2); -} - -void DenoiseOperation::deinit_execution() -{ - input_program_color_ = nullptr; - input_program_normal_ = nullptr; - input_program_albedo_ = nullptr; - SingleThreadedOperation::deinit_execution(); -} static bool are_guiding_passes_noise_free(const NodeDenoise *settings) { @@ -183,21 +152,6 @@ void DenoiseOperation::hash_output_params() } } -MemoryBuffer *DenoiseOperation::create_memory_buffer(rcti *rect2) -{ - MemoryBuffer *tile_color = (MemoryBuffer *)input_program_color_->initialize_tile_data(rect2); - MemoryBuffer *tile_normal = (MemoryBuffer *)input_program_normal_->initialize_tile_data(rect2); - MemoryBuffer *tile_albedo = (MemoryBuffer *)input_program_albedo_->initialize_tile_data(rect2); - rcti rect; - rect.xmin = 0; - rect.ymin = 0; - rect.xmax = get_width(); - rect.ymax = get_height(); - MemoryBuffer *result = new MemoryBuffer(DataType::Color, rect); - this->generate_denoise(result, tile_color, tile_normal, tile_albedo, settings_); - return result; -} - void DenoiseOperation::generate_denoise(MemoryBuffer *output, MemoryBuffer *input_color, MemoryBuffer *input_normal, @@ -258,18 +212,6 @@ void DenoisePrefilterOperation::hash_output_params() hash_param(image_name_); } -MemoryBuffer *DenoisePrefilterOperation::create_memory_buffer(rcti *rect2) -{ - MemoryBuffer *input = (MemoryBuffer *)this->get_input_operation(0)->initialize_tile_data(rect2); - rcti rect; - BLI_rcti_init(&rect, 0, get_width(), 0, get_height()); - - MemoryBuffer *result = new MemoryBuffer(get_output_socket()->get_data_type(), rect); - generate_denoise(result, input); - - return result; -} - void DenoisePrefilterOperation::generate_denoise(MemoryBuffer *output, MemoryBuffer *input) { if (input->is_a_single_elem()) { diff --git a/source/blender/compositor/operations/COM_DenoiseOperation.h b/source/blender/compositor/operations/COM_DenoiseOperation.h index 156ac5eacbb..4aa4a1eb6c8 100644 --- a/source/blender/compositor/operations/COM_DenoiseOperation.h +++ b/source/blender/compositor/operations/COM_DenoiseOperation.h @@ -4,14 +4,14 @@ #pragma once -#include "COM_SingleThreadedOperation.h" +#include "COM_NodeOperation.h" #include "DNA_node_types.h" namespace blender::compositor { bool COM_is_denoise_supported(); -class DenoiseBaseOperation : public SingleThreadedOperation { +class DenoiseBaseOperation : public NodeOperation { protected: bool output_rendered_; @@ -19,22 +19,11 @@ class DenoiseBaseOperation : public SingleThreadedOperation { DenoiseBaseOperation(); public: - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; }; class DenoiseOperation : public DenoiseBaseOperation { private: - /** - * \brief Cached reference to the input programs - */ - SocketReader *input_program_color_; - SocketReader *input_program_albedo_; - SocketReader *input_program_normal_; - /** * \brief settings of the denoise node. */ @@ -42,15 +31,6 @@ class DenoiseOperation : public DenoiseBaseOperation { public: DenoiseOperation(); - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; void set_denoise_settings(const NodeDenoise *settings) { @@ -68,8 +48,6 @@ class DenoiseOperation : public DenoiseBaseOperation { MemoryBuffer *input_normal, MemoryBuffer *input_albedo, const NodeDenoise *settings); - - MemoryBuffer *create_memory_buffer(rcti *rect) override; }; class DenoisePrefilterOperation : public DenoiseBaseOperation { @@ -90,7 +68,6 @@ class DenoisePrefilterOperation : public DenoiseBaseOperation { protected: void hash_output_params() override; - MemoryBuffer *create_memory_buffer(rcti *rect) override; private: void generate_denoise(MemoryBuffer *output, MemoryBuffer *input); diff --git a/source/blender/compositor/operations/COM_DespeckleOperation.cc b/source/blender/compositor/operations/COM_DespeckleOperation.cc index c6585356af7..0dc4f72dfc4 100644 --- a/source/blender/compositor/operations/COM_DespeckleOperation.cc +++ b/source/blender/compositor/operations/COM_DespeckleOperation.cc @@ -14,21 +14,8 @@ DespeckleOperation::DespeckleOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_operation_ = nullptr; - flags_.complex = true; flags_.can_be_constant = true; } -void DespeckleOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); - input_value_operation_ = this->get_input_socket_reader(1); -} - -void DespeckleOperation::deinit_execution() -{ - input_operation_ = nullptr; - input_value_operation_ = nullptr; -} BLI_INLINE int color_diff(const float a[3], const float b[3], const float threshold) { @@ -36,105 +23,6 @@ BLI_INLINE int color_diff(const float a[3], const float b[3], const float thresh (fabsf(a[2] - b[2]) > threshold)); } -void DespeckleOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - float w = 0.0f; - float color_org[4]; - float color_mid[4]; - float color_mid_ok[4]; - float in1[4]; - int x1 = x - 1; - int x2 = x; - int x3 = x + 1; - int y1 = y - 1; - int y2 = y; - int y3 = y + 1; - CLAMP(x1, 0, get_width() - 1); - CLAMP(x2, 0, get_width() - 1); - CLAMP(x3, 0, get_width() - 1); - CLAMP(y1, 0, get_height() - 1); - CLAMP(y2, 0, get_height() - 1); - CLAMP(y3, 0, get_height() - 1); - float value[4]; - input_value_operation_->read(value, x2, y2, nullptr); - // const float mval = 1.0f - value[0]; - - input_operation_->read(color_org, x2, y2, nullptr); - -#define TOT_DIV_ONE 1.0f -#define TOT_DIV_CNR float(M_SQRT1_2) - -#define WTOT (TOT_DIV_ONE * 4 + TOT_DIV_CNR * 4) - -#define COLOR_ADD(fac) \ - { \ - madd_v4_v4fl(color_mid, in1, fac); \ - if (color_diff(in1, color_org, threshold_)) { \ - w += fac; \ - madd_v4_v4fl(color_mid_ok, in1, fac); \ - } \ - } - - zero_v4(color_mid); - zero_v4(color_mid_ok); - - input_operation_->read(in1, x1, y1, nullptr); - COLOR_ADD(TOT_DIV_CNR) - input_operation_->read(in1, x2, y1, nullptr); - COLOR_ADD(TOT_DIV_ONE) - input_operation_->read(in1, x3, y1, nullptr); - COLOR_ADD(TOT_DIV_CNR) - input_operation_->read(in1, x1, y2, nullptr); - COLOR_ADD(TOT_DIV_ONE) - -#if 0 - input_operation_->read(in2, x2, y2, nullptr); - madd_v4_v4fl(color_mid, in2, filter_[4]); -#endif - - input_operation_->read(in1, x3, y2, nullptr); - COLOR_ADD(TOT_DIV_ONE) - input_operation_->read(in1, x1, y3, nullptr); - COLOR_ADD(TOT_DIV_CNR) - input_operation_->read(in1, x2, y3, nullptr); - COLOR_ADD(TOT_DIV_ONE) - input_operation_->read(in1, x3, y3, nullptr); - COLOR_ADD(TOT_DIV_CNR) - - mul_v4_fl(color_mid, 1.0f / (4.0f + (4.0f * float(M_SQRT1_2)))); - // mul_v4_fl(color_mid, 1.0f / w); - - if ((w != 0.0f) && ((w / WTOT) > (threshold_neighbor_)) && - color_diff(color_mid, color_org, threshold_)) - { - mul_v4_fl(color_mid_ok, 1.0f / w); - interp_v4_v4v4(output, color_org, color_mid_ok, value[0]); - } - else { - copy_v4_v4(output, color_org); - } - -#undef TOT_DIV_ONE -#undef TOT_DIV_CNR -#undef WTOT -#undef COLOR_ADD -} - -bool DespeckleOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - int addx = 2; //(filter_width_ - 1) / 2 + 1; - int addy = 2; //(filter_height_ - 1) / 2 + 1; - new_input.xmax = input->xmax + addx; - new_input.xmin = input->xmin - addx; - new_input.ymax = input->ymax + addy; - new_input.ymin = input->ymin - addy; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void DespeckleOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_DespeckleOperation.h b/source/blender/compositor/operations/COM_DespeckleOperation.h index ca726ad025f..b0c307f9d92 100644 --- a/source/blender/compositor/operations/COM_DespeckleOperation.h +++ b/source/blender/compositor/operations/COM_DespeckleOperation.h @@ -19,16 +19,8 @@ class DespeckleOperation : public MultiThreadedOperation { // int filter_width_; // int filter_height_; - protected: - SocketReader *input_operation_; - SocketReader *input_value_operation_; - public: DespeckleOperation(); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel(float output[4], int x, int y, void *data) override; void set_threshold(float threshold) { @@ -39,9 +31,6 @@ class DespeckleOperation : public MultiThreadedOperation { threshold_neighbor_ = threshold; } - void init_execution() override; - void deinit_execution() override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc index 08c3a380978..0b4bfd511bd 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cc @@ -12,66 +12,9 @@ DifferenceMatteOperation::DifferenceMatteOperation() add_input_socket(DataType::Color); add_output_socket(DataType::Value); - input_image1_program_ = nullptr; - input_image2_program_ = nullptr; flags_.can_be_constant = true; } -void DifferenceMatteOperation::init_execution() -{ - input_image1_program_ = this->get_input_socket_reader(0); - input_image2_program_ = this->get_input_socket_reader(1); -} -void DifferenceMatteOperation::deinit_execution() -{ - input_image1_program_ = nullptr; - input_image2_program_ = nullptr; -} - -void DifferenceMatteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_color1[4]; - float in_color2[4]; - - const float tolerance = settings_->t1; - const float falloff = settings_->t2; - float difference; - float alpha; - - input_image1_program_->read_sampled(in_color1, x, y, sampler); - input_image2_program_->read_sampled(in_color2, x, y, sampler); - - difference = (fabsf(in_color2[0] - in_color1[0]) + fabsf(in_color2[1] - in_color1[1]) + - fabsf(in_color2[2] - in_color1[2])); - - /* average together the distances */ - difference = difference / 3.0f; - - /* make 100% transparent */ - if (difference <= tolerance) { - output[0] = 0.0f; - } - /* In the falloff region, make partially transparent. */ - else if (difference <= falloff + tolerance) { - difference = difference - tolerance; - alpha = difference / falloff; - /* Only change if more transparent than before. */ - if (alpha < in_color1[3]) { - output[0] = alpha; - } - else { /* leave as before */ - output[0] = in_color1[3]; - } - } - else { - /* foreground object */ - output[0] = in_color1[3]; - } -} - void DifferenceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h index 92edba3d17f..ab306d95249 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h @@ -15,23 +15,10 @@ namespace blender::compositor { class DifferenceMatteOperation : public MultiThreadedOperation { private: NodeChroma *settings_; - SocketReader *input_image1_program_; - SocketReader *input_image2_program_; public: - /** - * Default constructor - */ DifferenceMatteOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void set_settings(NodeChroma *node_chroma) { settings_ = node_chroma; diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cc b/source/blender/compositor/operations/COM_DilateErodeOperation.cc index 4d932daf34d..e2b2f0696fa 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cc +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cc @@ -3,7 +3,6 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "COM_DilateErodeOperation.h" -#include "COM_OpenCLDevice.h" namespace blender::compositor { @@ -11,9 +10,7 @@ DilateErodeThresholdOperation::DilateErodeThresholdOperation() { this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - flags_.complex = true; flags_.can_be_constant = true; - input_program_ = nullptr; inset_ = 0.0f; switch_ = 0.5f; distance_ = 0.0f; @@ -37,117 +34,6 @@ void DilateErodeThresholdOperation::init_data() } } -void DilateErodeThresholdOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void *DilateErodeThresholdOperation::initialize_tile_data(rcti * /*rect*/) -{ - void *buffer = input_program_->initialize_tile_data(nullptr); - return buffer; -} - -void DilateErodeThresholdOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float input_value[4]; - const float sw = switch_; - const float distance = distance_; - float pixelvalue; - const float rd = scope_ * scope_; - const float inset = inset_; - float mindist = rd * 2; - - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - float *buffer = input_buffer->get_buffer(); - const rcti &input_rect = input_buffer->get_rect(); - const int minx = std::max(x - scope_, input_rect.xmin); - const int miny = std::max(y - scope_, input_rect.ymin); - const int maxx = std::min(x + scope_, input_rect.xmax); - const int maxy = std::min(y + scope_, input_rect.ymax); - const int buffer_width = input_buffer->get_width(); - int offset; - - input_buffer->read(input_value, x, y); - if (input_value[0] > sw) { - for (int yi = miny; yi < maxy; yi++) { - const float dy = yi - y; - offset = ((yi - input_rect.ymin) * buffer_width + (minx - input_rect.xmin)); - for (int xi = minx; xi < maxx; xi++) { - if (buffer[offset] < sw) { - const float dx = xi - x; - const float dis = dx * dx + dy * dy; - mindist = std::min(mindist, dis); - } - offset++; - } - } - pixelvalue = -sqrtf(mindist); - } - else { - for (int yi = miny; yi < maxy; yi++) { - const float dy = yi - y; - offset = ((yi - input_rect.ymin) * buffer_width + (minx - input_rect.xmin)); - for (int xi = minx; xi < maxx; xi++) { - if (buffer[offset] > sw) { - const float dx = xi - x; - const float dis = dx * dx + dy * dy; - mindist = std::min(mindist, dis); - } - offset++; - } - } - pixelvalue = sqrtf(mindist); - } - - if (distance > 0.0f) { - const float delta = distance - pixelvalue; - if (delta >= 0.0f) { - if (delta >= inset) { - output[0] = 1.0f; - } - else { - output[0] = delta / inset; - } - } - else { - output[0] = 0.0f; - } - } - else { - const float delta = -distance + pixelvalue; - if (delta < 0.0f) { - if (delta < -inset) { - output[0] = 1.0f; - } - else { - output[0] = (-delta) / inset; - } - } - else { - output[0] = 0.0f; - } - } -} - -void DilateErodeThresholdOperation::deinit_execution() -{ - input_program_ = nullptr; -} - -bool DilateErodeThresholdOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - new_input.xmax = input->xmax + scope_; - new_input.xmin = input->xmin - scope_; - new_input.ymax = input->ymax + scope_; - new_input.ymin = input->ymin - scope_; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void DilateErodeThresholdOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) @@ -258,10 +144,7 @@ DilateDistanceOperation::DilateDistanceOperation() { this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_program_ = nullptr; distance_ = 0.0f; - flags_.complex = true; - flags_.open_cl = true; flags_.can_be_constant = true; } @@ -273,91 +156,6 @@ void DilateDistanceOperation::init_data() } } -void DilateDistanceOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void *DilateDistanceOperation::initialize_tile_data(rcti * /*rect*/) -{ - void *buffer = input_program_->initialize_tile_data(nullptr); - return buffer; -} - -void DilateDistanceOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - const float distance = distance_; - const float mindist = distance * distance; - - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - float *buffer = input_buffer->get_buffer(); - const rcti &input_rect = input_buffer->get_rect(); - const int minx = std::max(x - scope_, input_rect.xmin); - const int miny = std::max(y - scope_, input_rect.ymin); - const int maxx = std::min(x + scope_, input_rect.xmax); - const int maxy = std::min(y + scope_, input_rect.ymax); - const int buffer_width = input_buffer->get_width(); - int offset; - - float value = 0.0f; - - for (int yi = miny; yi < maxy; yi++) { - const float dy = yi - y; - offset = ((yi - input_rect.ymin) * buffer_width + (minx - input_rect.xmin)); - for (int xi = minx; xi < maxx; xi++) { - const float dx = xi - x; - const float dis = dx * dx + dy * dy; - if (dis <= mindist) { - value = std::max(buffer[offset], value); - } - offset++; - } - } - output[0] = value; -} - -void DilateDistanceOperation::deinit_execution() -{ - input_program_ = nullptr; -} - -bool DilateDistanceOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - new_input.xmax = input->xmax + scope_; - new_input.xmin = input->xmin - scope_; - new_input.ymax = input->ymax + scope_; - new_input.ymin = input->ymin - scope_; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - -void DilateDistanceOperation::execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel dilate_kernel = device->COM_cl_create_kernel("dilate_kernel", nullptr); - - cl_int distance_squared = distance_ * distance_; - cl_int scope = scope_; - - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - dilate_kernel, 0, 2, cl_mem_to_clean_up, input_memory_buffers, input_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter( - dilate_kernel, 1, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - dilate_kernel, 3, output_memory_buffer); - clSetKernelArg(dilate_kernel, 4, sizeof(cl_int), &scope); - clSetKernelArg(dilate_kernel, 5, sizeof(cl_int), &distance_squared); - device->COM_cl_attach_size_to_kernel_parameter(dilate_kernel, 6, this); - device->COM_cl_enqueue_range(dilate_kernel, output_memory_buffer, 7, this); -} - void DilateDistanceOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) @@ -449,62 +247,6 @@ ErodeDistanceOperation::ErodeDistanceOperation() : DilateDistanceOperation() /* pass */ } -void ErodeDistanceOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - const float distance = distance_; - const float mindist = distance * distance; - - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - float *buffer = input_buffer->get_buffer(); - const rcti &input_rect = input_buffer->get_rect(); - const int minx = std::max(x - scope_, input_rect.xmin); - const int miny = std::max(y - scope_, input_rect.ymin); - const int maxx = std::min(x + scope_, input_rect.xmax); - const int maxy = std::min(y + scope_, input_rect.ymax); - const int buffer_width = input_buffer->get_width(); - int offset; - - float value = 1.0f; - - for (int yi = miny; yi < maxy; yi++) { - const float dy = yi - y; - offset = ((yi - input_rect.ymin) * buffer_width + (minx - input_rect.xmin)); - for (int xi = minx; xi < maxx; xi++) { - const float dx = xi - x; - const float dis = dx * dx + dy * dy; - if (dis <= mindist) { - value = std::min(buffer[offset], value); - } - offset++; - } - } - output[0] = value; -} - -void ErodeDistanceOperation::execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel erode_kernel = device->COM_cl_create_kernel("erode_kernel", nullptr); - - cl_int distance_squared = distance_ * distance_; - cl_int scope = scope_; - - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - erode_kernel, 0, 2, cl_mem_to_clean_up, input_memory_buffers, input_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter( - erode_kernel, 1, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - erode_kernel, 3, output_memory_buffer); - clSetKernelArg(erode_kernel, 4, sizeof(cl_int), &scope); - clSetKernelArg(erode_kernel, 5, sizeof(cl_int), &distance_squared); - device->COM_cl_attach_size_to_kernel_parameter(erode_kernel, 6, this); - device->COM_cl_enqueue_range(erode_kernel, output_memory_buffer, 7, this); -} - void ErodeDistanceOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -520,156 +262,6 @@ DilateStepOperation::DilateStepOperation() { this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - flags_.complex = true; - input_program_ = nullptr; -} -void DilateStepOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -/* Small helper to pass data from initialize_tile_data to execute_pixel. */ -struct tile_info { - rcti rect; - int width; - float *buffer; -}; - -static tile_info *create_cache(int xmin, int xmax, int ymin, int ymax) -{ - tile_info *result = (tile_info *)MEM_mallocN(sizeof(tile_info), "dilate erode tile"); - result->rect.xmin = xmin; - result->rect.xmax = xmax; - result->rect.ymin = ymin; - result->rect.ymax = ymax; - result->width = xmax - xmin; - result->buffer = (float *)MEM_callocN(sizeof(float) * (ymax - ymin) * result->width, - "dilate erode cache"); - return result; -} - -void *DilateStepOperation::initialize_tile_data(rcti *rect) -{ - MemoryBuffer *tile = (MemoryBuffer *)input_program_->initialize_tile_data(nullptr); - int x, y, i; - int width = tile->get_width(); - int height = tile->get_height(); - float *buffer = tile->get_buffer(); - - int half_window = iterations_; - int window = half_window * 2 + 1; - - int xmin = std::max(0, rect->xmin - half_window); - int ymin = std::max(0, rect->ymin - half_window); - int xmax = std::min(width, rect->xmax + half_window); - int ymax = std::min(height, rect->ymax + half_window); - - int bwidth = rect->xmax - rect->xmin; - int bheight = rect->ymax - rect->ymin; - - /* NOTE: Cache buffer has original tile-size width, but new height. - * We have to calculate the additional rows in the first pass, - * to have valid data available for the second pass. */ - tile_info *result = create_cache(rect->xmin, rect->xmax, ymin, ymax); - float *rectf = result->buffer; - - /* temp holds maxima for every step in the algorithm, buf holds a - * single row or column of input values, padded with FLT_MAX's to - * simplify the logic. */ - float *temp = (float *)MEM_mallocN(sizeof(float) * (2 * window - 1), "dilate erode temp"); - float *buf = (float *)MEM_mallocN(sizeof(float) * (std::max(bwidth, bheight) + 5 * half_window), - "dilate erode buf"); - - /* The following is based on the van Herk/Gil-Werman algorithm for morphology operations. - * first pass, horizontal dilate/erode. */ - for (y = ymin; y < ymax; y++) { - for (x = 0; x < bwidth + 5 * half_window; x++) { - buf[x] = -FLT_MAX; - } - for (x = xmin; x < xmax; x++) { - buf[x - rect->xmin + window - 1] = buffer[(y * width + x)]; - } - - for (i = 0; i < (bwidth + 3 * half_window) / window; i++) { - int start = (i + 1) * window - 1; - - temp[window - 1] = buf[start]; - for (x = 1; x < window; x++) { - temp[window - 1 - x] = std::max(temp[window - x], buf[start - x]); - temp[window - 1 + x] = std::max(temp[window + x - 2], buf[start + x]); - } - - start = half_window + (i - 1) * window + 1; - for (x = -std::min(0, start); x < window - std::max(0, start + window - bwidth); x++) { - rectf[bwidth * (y - ymin) + (start + x)] = std::max(temp[x], temp[x + window - 1]); - } - } - } - - /* Second pass, vertical dilate/erode. */ - for (x = 0; x < bwidth; x++) { - for (y = 0; y < bheight + 5 * half_window; y++) { - buf[y] = -FLT_MAX; - } - for (y = ymin; y < ymax; y++) { - buf[y - rect->ymin + window - 1] = rectf[(y - ymin) * bwidth + x]; - } - - for (i = 0; i < (bheight + 3 * half_window) / window; i++) { - int start = (i + 1) * window - 1; - - temp[window - 1] = buf[start]; - for (y = 1; y < window; y++) { - temp[window - 1 - y] = std::max(temp[window - y], buf[start - y]); - temp[window - 1 + y] = std::max(temp[window + y - 2], buf[start + y]); - } - - start = half_window + (i - 1) * window + 1; - for (y = -std::min(0, start); y < window - std::max(0, start + window - bheight); y++) { - rectf[bwidth * (y + start + (rect->ymin - ymin)) + x] = std::max(temp[y], - temp[y + window - 1]); - } - } - } - - MEM_freeN(temp); - MEM_freeN(buf); - - return result; -} - -void DilateStepOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - tile_info *tile = (tile_info *)data; - int nx = x - tile->rect.xmin; - int ny = y - tile->rect.ymin; - output[0] = tile->buffer[tile->width * ny + nx]; -} - -void DilateStepOperation::deinit_execution() -{ - input_program_ = nullptr; -} - -void DilateStepOperation::deinitialize_tile_data(rcti * /*rect*/, void *data) -{ - tile_info *tile = (tile_info *)data; - MEM_freeN(tile->buffer); - MEM_freeN(tile); -} - -bool DilateStepOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - int it = iterations_; - new_input.xmax = input->xmax + it; - new_input.xmin = input->xmin - it; - new_input.ymax = input->ymax + it; - new_input.ymin = input->ymin - it; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); } void DilateStepOperation::get_area_of_interest(const int input_idx, @@ -798,96 +390,6 @@ ErodeStepOperation::ErodeStepOperation() : DilateStepOperation() /* pass */ } -void *ErodeStepOperation::initialize_tile_data(rcti *rect) -{ - MemoryBuffer *tile = (MemoryBuffer *)input_program_->initialize_tile_data(nullptr); - int x, y, i; - int width = tile->get_width(); - int height = tile->get_height(); - float *buffer = tile->get_buffer(); - - int half_window = iterations_; - int window = half_window * 2 + 1; - - int xmin = std::max(0, rect->xmin - half_window); - int ymin = std::max(0, rect->ymin - half_window); - int xmax = std::min(width, rect->xmax + half_window); - int ymax = std::min(height, rect->ymax + half_window); - - int bwidth = rect->xmax - rect->xmin; - int bheight = rect->ymax - rect->ymin; - - /* NOTE: Cache buffer has original tile-size width, but new height. - * We have to calculate the additional rows in the first pass, - * to have valid data available for the second pass. */ - tile_info *result = create_cache(rect->xmin, rect->xmax, ymin, ymax); - float *rectf = result->buffer; - - /* temp holds maxima for every step in the algorithm, buf holds a - * single row or column of input values, padded with FLT_MAX's to - * simplify the logic. */ - float *temp = (float *)MEM_mallocN(sizeof(float) * (2 * window - 1), "dilate erode temp"); - float *buf = (float *)MEM_mallocN(sizeof(float) * (std::max(bwidth, bheight) + 5 * half_window), - "dilate erode buf"); - - /* The following is based on the van Herk/Gil-Werman algorithm for morphology operations. - * first pass, horizontal dilate/erode */ - for (y = ymin; y < ymax; y++) { - for (x = 0; x < bwidth + 5 * half_window; x++) { - buf[x] = FLT_MAX; - } - for (x = xmin; x < xmax; x++) { - buf[x - rect->xmin + window - 1] = buffer[(y * width + x)]; - } - - for (i = 0; i < (bwidth + 3 * half_window) / window; i++) { - int start = (i + 1) * window - 1; - - temp[window - 1] = buf[start]; - for (x = 1; x < window; x++) { - temp[window - 1 - x] = std::min(temp[window - x], buf[start - x]); - temp[window - 1 + x] = std::min(temp[window + x - 2], buf[start + x]); - } - - start = half_window + (i - 1) * window + 1; - for (x = -std::min(0, start); x < window - std::max(0, start + window - bwidth); x++) { - rectf[bwidth * (y - ymin) + (start + x)] = std::min(temp[x], temp[x + window - 1]); - } - } - } - - /* Second pass, vertical dilate/erode. */ - for (x = 0; x < bwidth; x++) { - for (y = 0; y < bheight + 5 * half_window; y++) { - buf[y] = FLT_MAX; - } - for (y = ymin; y < ymax; y++) { - buf[y - rect->ymin + window - 1] = rectf[(y - ymin) * bwidth + x]; - } - - for (i = 0; i < (bheight + 3 * half_window) / window; i++) { - int start = (i + 1) * window - 1; - - temp[window - 1] = buf[start]; - for (y = 1; y < window; y++) { - temp[window - 1 - y] = std::min(temp[window - y], buf[start - y]); - temp[window - 1 + y] = std::min(temp[window + y - 2], buf[start + y]); - } - - start = half_window + (i - 1) * window + 1; - for (y = -std::min(0, start); y < window - std::max(0, start + window - bheight); y++) { - rectf[bwidth * (y + start + (rect->ymin - ymin)) + x] = std::min(temp[y], - temp[y + window - 1]); - } - } - } - - MEM_freeN(temp); - MEM_freeN(buf); - - return result; -} - struct Min2Selector { float operator()(float f1, float f2) const { diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.h b/source/blender/compositor/operations/COM_DilateErodeOperation.h index 817f2940a38..15895a40da6 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.h +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.h @@ -13,11 +13,6 @@ class DilateErodeThresholdOperation : public MultiThreadedOperation { struct PixelData; private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - float distance_; float switch_; float inset_; @@ -32,22 +27,7 @@ class DilateErodeThresholdOperation : public MultiThreadedOperation { /* DilateErode Distance Threshold */ DilateErodeThresholdOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - void init_data() override; - /** - * Initialize the execution - */ - void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; void set_distance(float distance) { @@ -62,10 +42,6 @@ class DilateErodeThresholdOperation : public MultiThreadedOperation { inset_ = inset; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -77,10 +53,6 @@ class DilateDistanceOperation : public MultiThreadedOperation { struct PixelData; protected: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; float distance_; int scope_; @@ -88,38 +60,12 @@ class DilateDistanceOperation : public MultiThreadedOperation { /* Dilate Distance. */ DilateDistanceOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - void init_data() override; - /** - * Initialize the execution - */ - void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; void set_distance(float distance) { distance_ = distance; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) final; virtual void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -131,18 +77,6 @@ class ErodeDistanceOperation : public DilateDistanceOperation { /* Erode Distance */ ErodeDistanceOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; @@ -150,43 +84,17 @@ class ErodeDistanceOperation : public DilateDistanceOperation { class DilateStepOperation : public MultiThreadedOperation { protected: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - int iterations_; public: /* Dilate step */ DilateStepOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void deinitialize_tile_data(rcti *rect, void *data) override; - void set_iterations(int iterations) { iterations_ = iterations; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) final; virtual void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -198,7 +106,6 @@ class ErodeStepOperation : public DilateStepOperation { /** Erode step. */ ErodeStepOperation(); - void *initialize_tile_data(rcti *rect) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_DirectionalBlurOperation.cc b/source/blender/compositor/operations/COM_DirectionalBlurOperation.cc index 0191ee70057..4e4315272c4 100644 --- a/source/blender/compositor/operations/COM_DirectionalBlurOperation.cc +++ b/source/blender/compositor/operations/COM_DirectionalBlurOperation.cc @@ -3,7 +3,6 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "COM_DirectionalBlurOperation.h" -#include "COM_OpenCLDevice.h" namespace blender::compositor { @@ -11,15 +10,11 @@ DirectionalBlurOperation::DirectionalBlurOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - flags_.complex = true; - flags_.open_cl = true; flags_.can_be_constant = true; - input_program_ = nullptr; } void DirectionalBlurOperation::init_execution() { - input_program_ = get_input_socket_reader(0); QualityStepHelper::init_execution(COM_QH_INCREASE); const float angle = data_->angle; const float zoom = data_->zoom; @@ -45,90 +40,6 @@ void DirectionalBlurOperation::init_execution() rot_ = itsc * spin; } -void DirectionalBlurOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - const int iterations = pow(2.0f, data_->iter); - float col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float col2[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - input_program_->read_sampled(col2, x, y, PixelSampler::Bilinear); - float ltx = tx_; - float lty = ty_; - float lsc = sc_; - float lrot = rot_; - /* blur the image */ - for (int i = 0; i < iterations; i++) { - const float cs = cosf(lrot), ss = sinf(lrot); - const float isc = 1.0f / (1.0f + lsc); - - const float v = isc * (y - center_y_pix_) + lty; - const float u = isc * (x - center_x_pix_) + ltx; - - input_program_->read_sampled(col, - cs * u + ss * v + center_x_pix_, - cs * v - ss * u + center_y_pix_, - PixelSampler::Bilinear); - - add_v4_v4(col2, col); - - /* double transformations */ - ltx += tx_; - lty += ty_; - lrot += rot_; - lsc += sc_; - } - - mul_v4_v4fl(output, col2, 1.0f / (iterations + 1)); -} - -void DirectionalBlurOperation::execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel directional_blur_kernel = device->COM_cl_create_kernel("directional_blur_kernel", - nullptr); - - cl_int iterations = pow(2.0f, data_->iter); - cl_float2 ltxy = {{tx_, ty_}}; - cl_float2 centerpix = {{center_x_pix_, center_y_pix_}}; - cl_float lsc = sc_; - cl_float lrot = rot_; - - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - directional_blur_kernel, 0, -1, cl_mem_to_clean_up, input_memory_buffers, input_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter( - directional_blur_kernel, 1, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - directional_blur_kernel, 2, output_memory_buffer); - clSetKernelArg(directional_blur_kernel, 3, sizeof(cl_int), &iterations); - clSetKernelArg(directional_blur_kernel, 4, sizeof(cl_float), &lsc); - clSetKernelArg(directional_blur_kernel, 5, sizeof(cl_float), &lrot); - clSetKernelArg(directional_blur_kernel, 6, sizeof(cl_float2), <xy); - clSetKernelArg(directional_blur_kernel, 7, sizeof(cl_float2), ¢erpix); - - device->COM_cl_enqueue_range(directional_blur_kernel, output_memory_buffer, 8, this); -} - -void DirectionalBlurOperation::deinit_execution() -{ - input_program_ = nullptr; -} - -bool DirectionalBlurOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void DirectionalBlurOperation::get_area_of_interest(const int input_idx, const rcti & /*output_area*/, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_DirectionalBlurOperation.h b/source/blender/compositor/operations/COM_DirectionalBlurOperation.h index a08f893bb18..b399c541558 100644 --- a/source/blender/compositor/operations/COM_DirectionalBlurOperation.h +++ b/source/blender/compositor/operations/COM_DirectionalBlurOperation.h @@ -11,7 +11,6 @@ namespace blender::compositor { class DirectionalBlurOperation : public MultiThreadedOperation, public QualityStepHelper { private: - SocketReader *input_program_; const NodeDBlurData *data_; float center_x_pix_, center_y_pix_; @@ -21,37 +20,13 @@ class DirectionalBlurOperation : public MultiThreadedOperation, public QualitySt public: DirectionalBlurOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void set_data(const NodeDBlurData *data) { data_ = data; } - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.cc b/source/blender/compositor/operations/COM_DisplaceOperation.cc index 8dccb35bde8..d71030f182a 100644 --- a/source/blender/compositor/operations/COM_DisplaceOperation.cc +++ b/source/blender/compositor/operations/COM_DisplaceOperation.cc @@ -13,29 +13,12 @@ DisplaceOperation::DisplaceOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - - input_color_program_ = nullptr; } void DisplaceOperation::init_execution() { - input_color_program_ = this->get_input_socket_reader(0); NodeOperation *vector = this->get_input_socket_reader(1); - NodeOperation *scale_x = this->get_input_socket_reader(2); - NodeOperation *scale_y = this->get_input_socket_reader(3); - if (execution_model_ == eExecutionModel::Tiled) { - vector_read_fn_ = [=](float x, float y, float *out) { - vector->read_sampled(out, x, y, PixelSampler::Bilinear); - }; - scale_x_read_fn_ = [=](float x, float y, float *out) { - scale_x->read_sampled(out, x, y, PixelSampler::Nearest); - }; - scale_y_read_fn_ = [=](float x, float y, float *out) { - scale_y->read_sampled(out, x, y, PixelSampler::Nearest); - }; - } width_x4_ = this->get_width() * 4; height_x4_ = this->get_height() * 4; @@ -43,24 +26,6 @@ void DisplaceOperation::init_execution() input_vector_height_ = vector->get_height(); } -void DisplaceOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - float xy[2] = {x, y}; - float uv[2], deriv[2][2]; - - pixel_transform(xy, uv, deriv); - if (is_zero_v2(deriv[0]) && is_zero_v2(deriv[1])) { - input_color_program_->read_sampled(output, uv[0], uv[1], PixelSampler::Bilinear); - } - else { - /* EWA filtering (without nearest it gets blurry with NO distortion) */ - input_color_program_->read_filtered(output, uv[0], uv[1], deriv[0], deriv[1]); - } -} - bool DisplaceOperation::read_displacement( float x, float y, float xscale, float yscale, const float origin[2], float &r_u, float &r_v) { @@ -138,58 +103,6 @@ void DisplaceOperation::pixel_transform(const float xy[2], float r_uv[2], float } } -void DisplaceOperation::deinit_execution() -{ - input_color_program_ = nullptr; - vector_read_fn_ = nullptr; - scale_x_read_fn_ = nullptr; - scale_y_read_fn_ = nullptr; -} - -bool DisplaceOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti color_input; - rcti vector_input; - NodeOperation *operation = nullptr; - - /* the vector buffer only needs a 2x2 buffer. The image needs whole buffer */ - /* image */ - operation = get_input_operation(0); - color_input.xmax = operation->get_width(); - color_input.xmin = 0; - color_input.ymax = operation->get_height(); - color_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&color_input, read_operation, output)) { - return true; - } - - /* vector */ - operation = get_input_operation(1); - vector_input.xmax = input->xmax + 1; - vector_input.xmin = input->xmin - 1; - vector_input.ymax = input->ymax + 1; - vector_input.ymin = input->ymin - 1; - if (operation->determine_depending_area_of_interest(&vector_input, read_operation, output)) { - return true; - } - - /* scale x */ - operation = get_input_operation(2); - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - - /* scale y */ - operation = get_input_operation(3); - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - - return false; -} - void DisplaceOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.h b/source/blender/compositor/operations/COM_DisplaceOperation.h index fb28a0d89fd..f8915c8888a 100644 --- a/source/blender/compositor/operations/COM_DisplaceOperation.h +++ b/source/blender/compositor/operations/COM_DisplaceOperation.h @@ -10,11 +10,6 @@ namespace blender::compositor { class DisplaceOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_color_program_; - float width_x4_; float height_x4_; @@ -28,30 +23,10 @@ class DisplaceOperation : public MultiThreadedOperation { public: DisplaceOperation(); - /** - * we need a 2x2 differential filter for Vector Input and full buffer for the image - */ - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void pixel_transform(const float xy[2], float r_uv[2], float r_deriv[2][2]); - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_started(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc index 9d07b189992..6fafa03cb31 100644 --- a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc +++ b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cc @@ -14,109 +14,15 @@ DisplaceSimpleOperation::DisplaceSimpleOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_color_program_ = nullptr; - input_vector_program_ = nullptr; - input_scale_xprogram_ = nullptr; - input_scale_yprogram_ = nullptr; - flags_.can_be_constant = true; } void DisplaceSimpleOperation::init_execution() { - input_color_program_ = this->get_input_socket_reader(0); - input_vector_program_ = this->get_input_socket_reader(1); - input_scale_xprogram_ = this->get_input_socket_reader(2); - input_scale_yprogram_ = this->get_input_socket_reader(3); - width_x4_ = this->get_width() * 4; height_x4_ = this->get_height() * 4; } -/* minimum distance (in pixels) a pixel has to be displaced - * in order to take effect */ -// #define DISPLACE_EPSILON 0.01f - -void DisplaceSimpleOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_vector[4]; - float in_scale[4]; - - float p_dx, p_dy; /* main displacement in pixel space */ - float u, v; - - input_scale_xprogram_->read_sampled(in_scale, x, y, sampler); - float xs = in_scale[0]; - input_scale_yprogram_->read_sampled(in_scale, x, y, sampler); - float ys = in_scale[0]; - - /* clamp x and y displacement to triple image resolution - - * to prevent hangs from huge values mistakenly plugged in eg. z buffers */ - CLAMP(xs, -width_x4_, width_x4_); - CLAMP(ys, -height_x4_, height_x4_); - - input_vector_program_->read_sampled(in_vector, x, y, sampler); - p_dx = in_vector[0] * xs; - p_dy = in_vector[1] * ys; - - /* displaced pixel in uv coords, for image sampling */ - /* clamp nodes to avoid glitches */ - u = x - p_dx + 0.5f; - v = y - p_dy + 0.5f; - CLAMP(u, 0.0f, this->get_width() - 1.0f); - CLAMP(v, 0.0f, this->get_height() - 1.0f); - - input_color_program_->read_sampled(output, u, v, sampler); -} - -void DisplaceSimpleOperation::deinit_execution() -{ - input_color_program_ = nullptr; - input_vector_program_ = nullptr; - input_scale_xprogram_ = nullptr; - input_scale_yprogram_ = nullptr; -} - -bool DisplaceSimpleOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti color_input; - NodeOperation *operation = nullptr; - - /* the vector buffer only needs a 2x2 buffer. The image needs whole buffer */ - /* image */ - operation = get_input_operation(0); - color_input.xmax = operation->get_width(); - color_input.xmin = 0; - color_input.ymax = operation->get_height(); - color_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&color_input, read_operation, output)) { - return true; - } - - /* vector */ - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - - /* scale x */ - operation = get_input_operation(2); - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - - /* scale y */ - operation = get_input_operation(3); - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - - return false; -} - void DisplaceSimpleOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h index 31e8dcd269c..0f0e0ccbb64 100644 --- a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h +++ b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h @@ -10,42 +10,14 @@ namespace blender::compositor { class DisplaceSimpleOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_color_program_; - SocketReader *input_vector_program_; - SocketReader *input_scale_xprogram_; - SocketReader *input_scale_yprogram_; - float width_x4_; float height_x4_; public: DisplaceSimpleOperation(); - /** - * we need a full buffer for the image - */ - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc index 261eb17151d..d36347dc358 100644 --- a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc +++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cc @@ -12,73 +12,14 @@ DistanceRGBMatteOperation::DistanceRGBMatteOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Value); - input_image_program_ = nullptr; - input_key_program_ = nullptr; flags_.can_be_constant = true; } -void DistanceRGBMatteOperation::init_execution() -{ - input_image_program_ = this->get_input_socket_reader(0); - input_key_program_ = this->get_input_socket_reader(1); -} - -void DistanceRGBMatteOperation::deinit_execution() -{ - input_image_program_ = nullptr; - input_key_program_ = nullptr; -} - float DistanceRGBMatteOperation::calculate_distance(const float key[4], const float image[4]) { return len_v3v3(key, image); } -void DistanceRGBMatteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_key[4]; - float in_image[4]; - - const float tolerance = settings_->t1; - const float falloff = settings_->t2; - - float distance; - float alpha; - - input_key_program_->read_sampled(in_key, x, y, sampler); - input_image_program_->read_sampled(in_image, x, y, sampler); - - distance = this->calculate_distance(in_key, in_image); - - /* Store matte(alpha) value in [0] to go with - * COM_SetAlphaMultiplyOperation and the Value output. - */ - - /* Make 100% transparent. */ - if (distance < tolerance) { - output[0] = 0.0f; - } - /* In the falloff region, make partially transparent. */ - else if (distance < falloff + tolerance) { - distance = distance - tolerance; - alpha = distance / falloff; - /* Only change if more transparent than before. */ - if (alpha < in_image[3]) { - output[0] = alpha; - } - else { /* leave as before */ - output[0] = in_image[3]; - } - } - else { - /* leave as before */ - output[0] = in_image[3]; - } -} - void DistanceRGBMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h index dc80b8959e0..1e7a4e86b7e 100644 --- a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h +++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.h @@ -15,25 +15,12 @@ namespace blender::compositor { class DistanceRGBMatteOperation : public MultiThreadedOperation { protected: const NodeChroma *settings_; - SocketReader *input_image_program_; - SocketReader *input_key_program_; virtual float calculate_distance(const float key[4], const float image[4]); public: - /** - * Default constructor - */ DistanceRGBMatteOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void set_settings(const NodeChroma *node_chroma) { settings_ = node_chroma; diff --git a/source/blender/compositor/operations/COM_DotproductOperation.cc b/source/blender/compositor/operations/COM_DotproductOperation.cc index ea8690be6ad..3c9720f2480 100644 --- a/source/blender/compositor/operations/COM_DotproductOperation.cc +++ b/source/blender/compositor/operations/COM_DotproductOperation.cc @@ -12,35 +12,8 @@ DotproductOperation::DotproductOperation() this->add_input_socket(DataType::Vector); this->add_output_socket(DataType::Value); this->set_canvas_input_index(0); - input1Operation_ = nullptr; - input2Operation_ = nullptr; flags_.can_be_constant = true; } -void DotproductOperation::init_execution() -{ - input1Operation_ = this->get_input_socket_reader(0); - input2Operation_ = this->get_input_socket_reader(1); -} - -void DotproductOperation::deinit_execution() -{ - input1Operation_ = nullptr; - input2Operation_ = nullptr; -} - -/** \todo current implementation is the inverse of a dot-product. not 'logically' correct - */ -void DotproductOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input1[4]; - float input2[4]; - input1Operation_->read_sampled(input1, x, y, sampler); - input2Operation_->read_sampled(input2, x, y, sampler); - output[0] = -(input1[0] * input2[0] + input1[1] * input2[1] + input1[2] * input2[2]); -} void DotproductOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_DotproductOperation.h b/source/blender/compositor/operations/COM_DotproductOperation.h index 4c261a4793f..640e986bec0 100644 --- a/source/blender/compositor/operations/COM_DotproductOperation.h +++ b/source/blender/compositor/operations/COM_DotproductOperation.h @@ -9,16 +9,8 @@ namespace blender::compositor { class DotproductOperation : public MultiThreadedOperation { - private: - SocketReader *input1Operation_; - SocketReader *input2Operation_; - public: DotproductOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc index c02f4810eba..61f2fe863eb 100644 --- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc +++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cc @@ -143,76 +143,12 @@ DoubleEdgeMaskOperation::DoubleEdgeMaskOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_inner_mask_ = nullptr; - input_outer_mask_ = nullptr; include_all_inner_edges_ = false; include_edges_of_image_ = false; - flags_.complex = true; flags_.can_be_constant = true; is_output_rendered_ = false; } -bool DoubleEdgeMaskOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - if (cached_instance_ == nullptr) { - rcti new_input; - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); - } - - return false; -} - -void DoubleEdgeMaskOperation::init_execution() -{ - input_inner_mask_ = this->get_input_socket_reader(0); - input_outer_mask_ = this->get_input_socket_reader(1); - init_mutex(); - cached_instance_ = nullptr; -} - -void *DoubleEdgeMaskOperation::initialize_tile_data(rcti *rect) -{ - if (cached_instance_) { - return cached_instance_; - } - - lock_mutex(); - if (cached_instance_ == nullptr) { - MemoryBuffer *inner_mask = (MemoryBuffer *)input_inner_mask_->initialize_tile_data(rect); - MemoryBuffer *outer_mask = (MemoryBuffer *)input_outer_mask_->initialize_tile_data(rect); - float *data = (float *)MEM_mallocN(sizeof(float) * this->get_width() * this->get_height(), - __func__); - float *imask = inner_mask->get_buffer(); - float *omask = outer_mask->get_buffer(); - compute_double_edge_mask(imask, omask, data); - cached_instance_ = data; - } - unlock_mutex(); - return cached_instance_; -} -void DoubleEdgeMaskOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float *buffer = (float *)data; - int index = (y * this->get_width() + x); - output[0] = buffer[index]; -} - -void DoubleEdgeMaskOperation::deinit_execution() -{ - input_inner_mask_ = nullptr; - input_outer_mask_ = nullptr; - deinit_mutex(); - if (cached_instance_) { - MEM_freeN(cached_instance_); - cached_instance_ = nullptr; - } -} - void DoubleEdgeMaskOperation::get_area_of_interest(int /*input_idx*/, const rcti & /*output_area*/, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h index 3339aa0133b..cb1d2235538 100644 --- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h +++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h @@ -12,17 +12,9 @@ namespace blender::compositor { class DoubleEdgeMaskOperation : public NodeOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_outer_mask_; - SocketReader *input_inner_mask_; bool include_all_inner_edges_; bool include_edges_of_image_; - /* TODO(manzanilla): To be removed with tiled implementation. */ - float *cached_instance_; - bool is_output_rendered_; public: @@ -43,27 +35,6 @@ class DoubleEdgeMaskOperation : public NodeOperation { const float *outer_mask, float *output_mask); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void set_include_all_inner_edges(bool include_all_inner_edges) { include_all_inner_edges_ = include_all_inner_edges; diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.cc b/source/blender/compositor/operations/COM_EllipseMaskOperation.cc index 10f08a1964f..d257b47fb37 100644 --- a/source/blender/compositor/operations/COM_EllipseMaskOperation.cc +++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.cc @@ -11,93 +11,17 @@ EllipseMaskOperation::EllipseMaskOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_mask_ = nullptr; - input_value_ = nullptr; cosine_ = 0.0f; sine_ = 0.0f; } void EllipseMaskOperation::init_execution() { - input_mask_ = this->get_input_socket_reader(0); - input_value_ = this->get_input_socket_reader(1); const double rad = double(data_->rotation); cosine_ = cos(rad); sine_ = sin(rad); aspect_ratio_ = float(this->get_width()) / this->get_height(); } -void EllipseMaskOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_mask[4]; - float input_value[4]; - - float rx = x / std::max(this->get_width() - 1.0f, FLT_EPSILON); - float ry = y / std::max(this->get_height() - 1.0f, FLT_EPSILON); - - const float dy = (ry - data_->y) / aspect_ratio_; - const float dx = rx - data_->x; - rx = data_->x + (cosine_ * dx + sine_ * dy); - ry = data_->y + (-sine_ * dx + cosine_ * dy); - - input_mask_->read_sampled(input_mask, x, y, sampler); - input_value_->read_sampled(input_value, x, y, sampler); - - const float half_height = (data_->height) / 2.0f; - const float half_width = data_->width / 2.0f; - float sx = rx - data_->x; - sx *= sx; - const float tx = half_width * half_width; - float sy = ry - data_->y; - sy *= sy; - const float ty = half_height * half_height; - - bool inside = ((sx / tx) + (sy / ty)) <= (1.0f + FLT_EPSILON); - - switch (mask_type_) { - case CMP_NODE_MASKTYPE_ADD: - if (inside) { - output[0] = std::max(input_mask[0], input_value[0]); - } - else { - output[0] = input_mask[0]; - } - break; - case CMP_NODE_MASKTYPE_SUBTRACT: - if (inside) { - output[0] = input_mask[0] - input_value[0]; - CLAMP(output[0], 0, 1); - } - else { - output[0] = input_mask[0]; - } - break; - case CMP_NODE_MASKTYPE_MULTIPLY: - if (inside) { - output[0] = input_mask[0] * input_value[0]; - } - else { - output[0] = 0; - } - break; - case CMP_NODE_MASKTYPE_NOT: - if (inside) { - if (input_mask[0] > 0.0f) { - output[0] = 0; - } - else { - output[0] = input_value[0]; - } - } - else { - output[0] = input_mask[0]; - } - break; - } -} - void EllipseMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -169,10 +93,4 @@ void EllipseMaskOperation::apply_mask(MemoryBuffer *output, } } -void EllipseMaskOperation::deinit_execution() -{ - input_mask_ = nullptr; - input_value_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.h b/source/blender/compositor/operations/COM_EllipseMaskOperation.h index 431b954e5af..19231971bd3 100644 --- a/source/blender/compositor/operations/COM_EllipseMaskOperation.h +++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.h @@ -12,12 +12,6 @@ class EllipseMaskOperation : public MultiThreadedOperation { private: using MaskFunc = std::function; - /** - * Cached reference to the input_program - */ - SocketReader *input_mask_; - SocketReader *input_value_; - float sine_; float cosine_; float aspect_ratio_; @@ -28,21 +22,8 @@ class EllipseMaskOperation : public MultiThreadedOperation { public: EllipseMaskOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ void init_execution() override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_data(NodeEllipseMask *data) { data_ = data; diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc index ec87e31d5d2..42321fdd3c7 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cc @@ -14,39 +14,6 @@ FastGaussianBlurOperation::FastGaussianBlurOperation() : BlurBaseOperation(DataT data_.filtertype = R_FILTER_FAST_GAUSS; } -void FastGaussianBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *new_data = (MemoryBuffer *)data; - new_data->read(output, x, y); -} - -bool FastGaussianBlurOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - - NodeOperation *operation = this->get_input_operation(1); - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - - if (iirgaus_) { - return false; - } - - new_input.xmin = 0; - new_input.ymin = 0; - new_input.xmax = this->get_width(); - new_input.ymax = this->get_height(); - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void FastGaussianBlurOperation::init_data() { BlurBaseOperation::init_data(); @@ -57,7 +24,6 @@ void FastGaussianBlurOperation::init_data() void FastGaussianBlurOperation::init_execution() { BlurBaseOperation::init_execution(); - BlurBaseOperation::init_mutex(); } void FastGaussianBlurOperation::deinit_execution() @@ -66,7 +32,6 @@ void FastGaussianBlurOperation::deinit_execution() delete iirgaus_; iirgaus_ = nullptr; } - BlurBaseOperation::deinit_mutex(); } void FastGaussianBlurOperation::set_size(int size_x, int size_y) @@ -78,41 +43,6 @@ void FastGaussianBlurOperation::set_size(int size_x, int size_y) sizeavailable_ = true; } -void *FastGaussianBlurOperation::initialize_tile_data(rcti *rect) -{ - lock_mutex(); - if (!iirgaus_) { - MemoryBuffer *new_buf = (MemoryBuffer *)input_program_->initialize_tile_data(rect); - MemoryBuffer *copy = new MemoryBuffer(*new_buf); - update_size(); - - int c; - sx_ = data_.sizex * size_ / 2.0f; - sy_ = data_.sizey * size_ / 2.0f; - - if ((sx_ == sy_) && (sx_ > 0.0f)) { - for (c = 0; c < COM_DATA_TYPE_COLOR_CHANNELS; c++) { - IIR_gauss(copy, sx_, c, 3); - } - } - else { - if (sx_ > 0.0f) { - for (c = 0; c < COM_DATA_TYPE_COLOR_CHANNELS; c++) { - IIR_gauss(copy, sx_, c, 1); - } - } - if (sy_ > 0.0f) { - for (c = 0; c < COM_DATA_TYPE_COLOR_CHANNELS; c++) { - IIR_gauss(copy, sy_, c, 2); - } - } - } - iirgaus_ = copy; - } - unlock_mutex(); - return iirgaus_; -} - void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, uint chan, uint xy) { BLI_assert(!src->is_a_single_elem()); @@ -316,40 +246,11 @@ FastGaussianBlurValueOperation::FastGaussianBlurValueOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); iirgaus_ = nullptr; - inputprogram_ = nullptr; sigma_ = 1.0f; overlay_ = 0; - flags_.complex = true; } -void FastGaussianBlurValueOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *new_data = (MemoryBuffer *)data; - new_data->read(output, x, y); -} - -bool FastGaussianBlurValueOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - if (iirgaus_) { - return false; - } - - new_input.xmin = 0; - new_input.ymin = 0; - new_input.xmax = this->get_width(); - new_input.ymax = this->get_height(); - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - -void FastGaussianBlurValueOperation::init_execution() -{ - inputprogram_ = get_input_socket_reader(0); - init_mutex(); -} +void FastGaussianBlurValueOperation::init_execution() {} void FastGaussianBlurValueOperation::deinit_execution() { @@ -357,44 +258,6 @@ void FastGaussianBlurValueOperation::deinit_execution() delete iirgaus_; iirgaus_ = nullptr; } - deinit_mutex(); -} - -void *FastGaussianBlurValueOperation::initialize_tile_data(rcti *rect) -{ - lock_mutex(); - if (!iirgaus_) { - MemoryBuffer *new_buf = (MemoryBuffer *)inputprogram_->initialize_tile_data(rect); - MemoryBuffer *copy = new MemoryBuffer(*new_buf); - FastGaussianBlurOperation::IIR_gauss(copy, sigma_, 0, 3); - - if (overlay_ == FAST_GAUSS_OVERLAY_MIN) { - float *src = new_buf->get_buffer(); - float *dst = copy->get_buffer(); - for (int i = copy->get_width() * copy->get_height(); i != 0; - i--, src += COM_DATA_TYPE_VALUE_CHANNELS, dst += COM_DATA_TYPE_VALUE_CHANNELS) - { - if (*src < *dst) { - *dst = *src; - } - } - } - else if (overlay_ == FAST_GAUSS_OVERLAY_MAX) { - float *src = new_buf->get_buffer(); - float *dst = copy->get_buffer(); - for (int i = copy->get_width() * copy->get_height(); i != 0; - i--, src += COM_DATA_TYPE_VALUE_CHANNELS, dst += COM_DATA_TYPE_VALUE_CHANNELS) - { - if (*src > *dst) { - *dst = *src; - } - } - } - - iirgaus_ = copy; - } - unlock_mutex(); - return iirgaus_; } void FastGaussianBlurValueOperation::get_area_of_interest(const int /*input_idx*/, diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h index 200f76771c7..99b5bfacac6 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h @@ -17,13 +17,8 @@ class FastGaussianBlurOperation : public BlurBaseOperation { public: FastGaussianBlurOperation(); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel(float output[4], int x, int y, void *data) override; static void IIR_gauss(MemoryBuffer *src, float sigma, unsigned int channel, unsigned int xy); - void *initialize_tile_data(rcti *rect) override; void init_data() override; void deinit_execution() override; void init_execution() override; @@ -51,7 +46,6 @@ class FastGaussianBlurValueOperation : public MultiThreadedOperation { private: float sigma_; MemoryBuffer *iirgaus_; - SocketReader *inputprogram_; /** * -1: re-mix with darker @@ -62,12 +56,7 @@ class FastGaussianBlurValueOperation : public MultiThreadedOperation { public: FastGaussianBlurValueOperation(); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel(float output[4], int x, int y, void *data) override; - void *initialize_tile_data(rcti *rect) override; void deinit_execution() override; void init_execution() override; void set_sigma(float sigma) diff --git a/source/blender/compositor/operations/COM_FileOutputOperation.cc b/source/blender/compositor/operations/COM_FileOutputOperation.cc index a0c6d6295f7..a03a785178d 100644 --- a/source/blender/compositor/operations/COM_FileOutputOperation.cc +++ b/source/blender/compositor/operations/COM_FileOutputOperation.cc @@ -51,34 +51,6 @@ static float *initialize_buffer(uint width, uint height, DataType datatype) MEM_malloc_arrayN(size_t(width) * height, sizeof(float) * size, "File Output Buffer.")); } -static void write_buffer_rect( - rcti *rect, SocketReader *reader, float *buffer, uint width, DataType datatype) -{ - - if (!buffer) { - return; - } - int x1 = rect->xmin; - int y1 = rect->ymin; - int x2 = rect->xmax; - int y2 = rect->ymax; - - int size = get_channels_count(datatype); - int offset = (y1 * width + x1) * size; - for (int y = y1; y < y2; y++) { - for (int x = x1; x < x2; x++) { - float color[4]; - reader->read_sampled(color, x, y, PixelSampler::Nearest); - - for (int i = 0; i < size; i++) { - buffer[offset + i] = color[i]; - } - offset += size; - } - offset += (width - (x2 - x1)) * size; - } -} - FileOutputOperation::FileOutputOperation(const CompositorContext *context, const NodeImageMultiFile *node_data, Vector inputs) @@ -102,17 +74,6 @@ void FileOutputOperation::init_execution() } } -void FileOutputOperation::execute_region(rcti *rect, uint /*tile_number*/) -{ - for (int i = 0; i < file_output_inputs_.size(); i++) { - const FileOutputInput &input = file_output_inputs_[i]; - if (!input.image_input || !input.output_buffer) { - continue; - } - write_buffer_rect(rect, input.image_input, input.output_buffer, get_width(), input.data_type); - } -} - void FileOutputOperation::update_memory_buffer_partial(MemoryBuffer * /*output*/, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_FileOutputOperation.h b/source/blender/compositor/operations/COM_FileOutputOperation.h index 61d9ef0ae94..33a5f09569e 100644 --- a/source/blender/compositor/operations/COM_FileOutputOperation.h +++ b/source/blender/compositor/operations/COM_FileOutputOperation.h @@ -40,7 +40,6 @@ class FileOutputOperation : public MultiThreadedOperation { const NodeImageMultiFile *node_data, Vector inputs); - void execute_region(rcti *rect, unsigned int tile_number) override; bool is_output_operation(bool /*rendering*/) const override { return true; diff --git a/source/blender/compositor/operations/COM_FlipOperation.cc b/source/blender/compositor/operations/COM_FlipOperation.cc index fdd10a4f645..16754c3e531 100644 --- a/source/blender/compositor/operations/COM_FlipOperation.cc +++ b/source/blender/compositor/operations/COM_FlipOperation.cc @@ -11,28 +11,10 @@ FlipOperation::FlipOperation() this->add_input_socket(DataType::Color, ResizeMode::None); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_operation_ = nullptr; flip_x_ = true; flip_y_ = false; flags_.can_be_constant = true; } -void FlipOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void FlipOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - -void FlipOperation::execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) -{ - float nx = flip_x_ ? (int(this->get_width()) - 1) - x : x; - float ny = flip_y_ ? (int(this->get_height()) - 1) - y : y; - - input_operation_->read_sampled(output, nx, ny, sampler); -} void FlipOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_FlipOperation.h b/source/blender/compositor/operations/COM_FlipOperation.h index 98884887dbc..0f2ef54c0d9 100644 --- a/source/blender/compositor/operations/COM_FlipOperation.h +++ b/source/blender/compositor/operations/COM_FlipOperation.h @@ -10,16 +10,12 @@ namespace blender::compositor { class FlipOperation : public MultiThreadedOperation { private: - SocketReader *input_operation_; bool flip_x_; bool flip_y_; public: FlipOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void init_execution() override; - void deinit_execution() override; void setFlipX(bool flipX) { flip_x_ = flipX; diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.cc b/source/blender/compositor/operations/COM_GammaCorrectOperation.cc index d3fc957d6d9..a7f5163486d 100644 --- a/source/blender/compositor/operations/COM_GammaCorrectOperation.cc +++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.cc @@ -10,39 +10,8 @@ GammaCorrectOperation::GammaCorrectOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_program_ = nullptr; flags_.can_be_constant = true; } -void GammaCorrectOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void GammaCorrectOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_program_->read_sampled(input_color, x, y, sampler); - if (input_color[3] > 0.0f) { - input_color[0] /= input_color[3]; - input_color[1] /= input_color[3]; - input_color[2] /= input_color[3]; - } - - /* Check for negative to avoid NAN's. */ - output[0] = input_color[0] > 0.0f ? input_color[0] * input_color[0] : 0.0f; - output[1] = input_color[1] > 0.0f ? input_color[1] * input_color[1] : 0.0f; - output[2] = input_color[2] > 0.0f ? input_color[2] * input_color[2] : 0.0f; - output[3] = input_color[3]; - - if (input_color[3] > 0.0f) { - output[0] *= input_color[3]; - output[1] *= input_color[3]; - output[2] *= input_color[3]; - } -} void GammaCorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -72,48 +41,12 @@ void GammaCorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void GammaCorrectOperation::deinit_execution() -{ - input_program_ = nullptr; -} - GammaUncorrectOperation::GammaUncorrectOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_program_ = nullptr; flags_.can_be_constant = true; } -void GammaUncorrectOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void GammaUncorrectOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color[4]; - input_program_->read_sampled(input_color, x, y, sampler); - - if (input_color[3] > 0.0f) { - input_color[0] /= input_color[3]; - input_color[1] /= input_color[3]; - input_color[2] /= input_color[3]; - } - - output[0] = input_color[0] > 0.0f ? sqrtf(input_color[0]) : 0.0f; - output[1] = input_color[1] > 0.0f ? sqrtf(input_color[1]) : 0.0f; - output[2] = input_color[2] > 0.0f ? sqrtf(input_color[2]) : 0.0f; - output[3] = input_color[3]; - - if (input_color[3] > 0.0f) { - output[0] *= input_color[3]; - output[1] *= input_color[3]; - output[2] *= input_color[3]; - } -} void GammaUncorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -142,9 +75,4 @@ void GammaUncorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void GammaUncorrectOperation::deinit_execution() -{ - input_program_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.h b/source/blender/compositor/operations/COM_GammaCorrectOperation.h index 6f4e02f72b1..ed5b889670e 100644 --- a/source/blender/compositor/operations/COM_GammaCorrectOperation.h +++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.h @@ -9,60 +9,18 @@ namespace blender::compositor { class GammaCorrectOperation : public MultiThreadedOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - public: GammaCorrectOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; }; class GammaUncorrectOperation : public MultiThreadedOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - public: GammaUncorrectOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_GammaOperation.cc b/source/blender/compositor/operations/COM_GammaOperation.cc index e3c6e043aba..27928285bc8 100644 --- a/source/blender/compositor/operations/COM_GammaOperation.cc +++ b/source/blender/compositor/operations/COM_GammaOperation.cc @@ -11,31 +11,8 @@ GammaOperation::GammaOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_program_ = nullptr; - input_gamma_program_ = nullptr; flags_.can_be_constant = true; } -void GammaOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); - input_gamma_program_ = this->get_input_socket_reader(1); -} - -void GammaOperation::execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) -{ - float input_value[4]; - float input_gamma[4]; - - input_program_->read_sampled(input_value, x, y, sampler); - input_gamma_program_->read_sampled(input_gamma, x, y, sampler); - const float gamma = input_gamma[0]; - /* check for negative to avoid NAN's */ - output[0] = input_value[0] > 0.0f ? powf(input_value[0], gamma) : input_value[0]; - output[1] = input_value[1] > 0.0f ? powf(input_value[1], gamma) : input_value[1]; - output[2] = input_value[2] > 0.0f ? powf(input_value[2], gamma) : input_value[2]; - - output[3] = input_value[3]; -} void GammaOperation::update_memory_buffer_row(PixelCursor &p) { @@ -51,10 +28,4 @@ void GammaOperation::update_memory_buffer_row(PixelCursor &p) } } -void GammaOperation::deinit_execution() -{ - input_program_ = nullptr; - input_gamma_program_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GammaOperation.h b/source/blender/compositor/operations/COM_GammaOperation.h index bc6bd791e1a..728060faf83 100644 --- a/source/blender/compositor/operations/COM_GammaOperation.h +++ b/source/blender/compositor/operations/COM_GammaOperation.h @@ -9,31 +9,9 @@ namespace blender::compositor { class GammaOperation : public MultiThreadedRowOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - SocketReader *input_gamma_program_; - public: GammaOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_row(PixelCursor &p) override; }; diff --git a/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc index 2d31e6a1875..dd88529d5b5 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc +++ b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.cc @@ -18,20 +18,16 @@ GaussianAlphaBlurBaseOperation::GaussianAlphaBlurBaseOperation(eDimension dim) void GaussianAlphaBlurBaseOperation::init_data() { BlurBaseOperation::init_data(); - if (execution_model_ == eExecutionModel::FullFrame) { - rad_ = max_ff(size_ * this->get_blur_size(dimension_), 0.0f); - rad_ = min_ff(rad_, MAX_GAUSSTAB_RADIUS); - filtersize_ = min_ii(ceil(rad_), MAX_GAUSSTAB_RADIUS); - } + rad_ = max_ff(size_ * this->get_blur_size(dimension_), 0.0f); + rad_ = min_ff(rad_, MAX_GAUSSTAB_RADIUS); + filtersize_ = min_ii(ceil(rad_), MAX_GAUSSTAB_RADIUS); } void GaussianAlphaBlurBaseOperation::init_execution() { BlurBaseOperation::init_execution(); - if (execution_model_ == eExecutionModel::FullFrame) { - gausstab_ = BlurBaseOperation::make_gausstab(rad_, filtersize_); - distbuf_inv_ = BlurBaseOperation::make_dist_fac_inverse(rad_, filtersize_, falloff_); - } + gausstab_ = BlurBaseOperation::make_gausstab(rad_, filtersize_); + distbuf_inv_ = BlurBaseOperation::make_dist_fac_inverse(rad_, filtersize_, falloff_); } void GaussianAlphaBlurBaseOperation::deinit_execution() diff --git a/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h index 33e4af006ae..b0ed3608fb1 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h +++ b/source/blender/compositor/operations/COM_GaussianAlphaBlurBaseOperation.h @@ -48,4 +48,14 @@ class GaussianAlphaBlurBaseOperation : public BlurBaseOperation { } }; +class GaussianAlphaXBlurOperation : public GaussianAlphaBlurBaseOperation { + public: + GaussianAlphaXBlurOperation() : GaussianAlphaBlurBaseOperation(eDimension::X) {} +}; + +class GaussianAlphaYBlurOperation : public GaussianAlphaBlurBaseOperation { + public: + GaussianAlphaYBlurOperation() : GaussianAlphaBlurBaseOperation(eDimension::Y) {} +}; + } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc deleted file mode 100644 index eaf19d77b1c..00000000000 --- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cc +++ /dev/null @@ -1,170 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_GaussianAlphaXBlurOperation.h" - -namespace blender::compositor { - -GaussianAlphaXBlurOperation::GaussianAlphaXBlurOperation() - : GaussianAlphaBlurBaseOperation(eDimension::X) -{ -} - -void *GaussianAlphaXBlurOperation::initialize_tile_data(rcti * /*rect*/) -{ - lock_mutex(); - if (!sizeavailable_) { - update_gauss(); - } - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - unlock_mutex(); - return buffer; -} - -void GaussianAlphaXBlurOperation::init_execution() -{ - GaussianAlphaBlurBaseOperation::init_execution(); - - init_mutex(); - - if (sizeavailable_ && execution_model_ == eExecutionModel::Tiled) { - float rad = max_ff(size_ * data_.sizex, 0.0f); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); - distbuf_inv_ = BlurBaseOperation::make_dist_fac_inverse(rad, filtersize_, falloff_); - } -} - -void GaussianAlphaXBlurOperation::update_gauss() -{ - if (gausstab_ == nullptr) { - update_size(); - float rad = max_ff(size_ * data_.sizex, 0.0f); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); - } - - if (distbuf_inv_ == nullptr) { - update_size(); - float rad = max_ff(size_ * data_.sizex, 0.0f); - rad = min_ff(rad, MAX_GAUSSTAB_RADIUS); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - distbuf_inv_ = BlurBaseOperation::make_dist_fac_inverse(rad, filtersize_, falloff_); - } -} - -void GaussianAlphaXBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - const bool do_invert = do_subtract_; - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - float *buffer = input_buffer->get_buffer(); - int bufferwidth = input_buffer->get_width(); - const rcti &input_rect = input_buffer->get_rect(); - int bufferstartx = input_rect.xmin; - int bufferstarty = input_rect.ymin; - - const rcti &rect = input_buffer->get_rect(); - int xmin = max_ii(x - filtersize_, rect.xmin); - int xmax = min_ii(x + filtersize_ + 1, rect.xmax); - int ymin = max_ii(y, rect.ymin); - - /* *** this is the main part which is different to 'GaussianXBlurOperation' *** */ - int step = get_step(); - int bufferindex = (xmin - bufferstartx) + ((ymin - bufferstarty) * bufferwidth); - - /* gauss */ - float alpha_accum = 0.0f; - float multiplier_accum = 0.0f; - - /* dilate */ - float value_max = finv_test( - buffer[(x) + (y * bufferwidth)], - do_invert); /* init with the current color to avoid unneeded lookups */ - float distfacinv_max = 1.0f; /* 0 to 1 */ - - for (int nx = xmin; nx < xmax; nx += step) { - const int index = (nx - x) + filtersize_; - float value = finv_test(buffer[bufferindex], do_invert); - float multiplier; - - /* gauss */ - { - multiplier = gausstab_[index]; - alpha_accum += value * multiplier; - multiplier_accum += multiplier; - } - - /* dilate - find most extreme color */ - if (value > value_max) { - multiplier = distbuf_inv_[index]; - value *= multiplier; - if (value > value_max) { - value_max = value; - distfacinv_max = multiplier; - } - } - bufferindex += step; - } - - /* blend between the max value and gauss blue - gives nice feather */ - const float value_blur = alpha_accum / multiplier_accum; - const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max)); - output[0] = finv_test(value_final, do_invert); -} - -void GaussianAlphaXBlurOperation::deinit_execution() -{ - GaussianAlphaBlurBaseOperation::deinit_execution(); - - if (gausstab_) { - MEM_freeN(gausstab_); - gausstab_ = nullptr; - } - - if (distbuf_inv_) { - MEM_freeN(distbuf_inv_); - distbuf_inv_ = nullptr; - } - - deinit_mutex(); -} - -bool GaussianAlphaXBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; -#if 0 /* until we add size input */ - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - - NodeOperation *operation = this->get_input_operation(1); - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - else -#endif - { - if (sizeavailable_ && gausstab_ != nullptr) { - new_input.xmax = input->xmax + filtersize_ + 1; - new_input.xmin = input->xmin - filtersize_ - 1; - new_input.ymax = input->ymax; - new_input.ymin = input->ymin; - } - else { - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - } - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h deleted file mode 100644 index 7d6c9c0213f..00000000000 --- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_GaussianAlphaBlurBaseOperation.h" - -namespace blender::compositor { - -/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */ -class GaussianAlphaXBlurOperation : public GaussianAlphaBlurBaseOperation { - private: - void update_gauss(); - - public: - GaussianAlphaXBlurOperation(); - - /** - * \brief The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * \brief initialize the execution - */ - void init_execution() override; - - /** - * \brief Deinitialize the execution - */ - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc deleted file mode 100644 index 865a63b4e99..00000000000 --- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cc +++ /dev/null @@ -1,171 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_GaussianAlphaYBlurOperation.h" - -namespace blender::compositor { - -GaussianAlphaYBlurOperation::GaussianAlphaYBlurOperation() - : GaussianAlphaBlurBaseOperation(eDimension::Y) -{ -} - -void *GaussianAlphaYBlurOperation::initialize_tile_data(rcti * /*rect*/) -{ - lock_mutex(); - if (!sizeavailable_) { - update_gauss(); - } - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - unlock_mutex(); - return buffer; -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void GaussianAlphaYBlurOperation::init_execution() -{ - GaussianAlphaBlurBaseOperation::init_execution(); - - init_mutex(); - - if (sizeavailable_ && execution_model_ == eExecutionModel::Tiled) { - float rad = max_ff(size_ * data_.sizey, 0.0f); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); - distbuf_inv_ = BlurBaseOperation::make_dist_fac_inverse(rad, filtersize_, falloff_); - } -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void GaussianAlphaYBlurOperation::update_gauss() -{ - if (gausstab_ == nullptr) { - update_size(); - float rad = max_ff(size_ * data_.sizey, 0.0f); - rad = min_ff(rad, MAX_GAUSSTAB_RADIUS); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); - } - - if (distbuf_inv_ == nullptr) { - update_size(); - float rad = max_ff(size_ * data_.sizey, 0.0f); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - distbuf_inv_ = BlurBaseOperation::make_dist_fac_inverse(rad, filtersize_, falloff_); - } -} - -void GaussianAlphaYBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - const bool do_invert = do_subtract_; - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - const rcti &input_rect = input_buffer->get_rect(); - float *buffer = input_buffer->get_buffer(); - int bufferwidth = input_buffer->get_width(); - int bufferstartx = input_rect.xmin; - int bufferstarty = input_rect.ymin; - - int xmin = max_ii(x, input_rect.xmin); - int ymin = max_ii(y - filtersize_, input_rect.ymin); - int ymax = min_ii(y + filtersize_ + 1, input_rect.ymax); - - /* *** this is the main part which is different to 'GaussianYBlurOperation' *** */ - int step = get_step(); - - /* gauss */ - float alpha_accum = 0.0f; - float multiplier_accum = 0.0f; - - /* dilate */ - float value_max = finv_test( - buffer[(x) + (y * bufferwidth)], - do_invert); /* init with the current color to avoid unneeded lookups */ - float distfacinv_max = 1.0f; /* 0 to 1 */ - - for (int ny = ymin; ny < ymax; ny += step) { - int bufferindex = (xmin - bufferstartx) + ((ny - bufferstarty) * bufferwidth); - - const int index = (ny - y) + filtersize_; - float value = finv_test(buffer[bufferindex], do_invert); - float multiplier; - - /* gauss */ - { - multiplier = gausstab_[index]; - alpha_accum += value * multiplier; - multiplier_accum += multiplier; - } - - /* dilate - find most extreme color */ - if (value > value_max) { - multiplier = distbuf_inv_[index]; - value *= multiplier; - if (value > value_max) { - value_max = value; - distfacinv_max = multiplier; - } - } - } - - /* blend between the max value and gauss blue - gives nice feather */ - const float value_blur = alpha_accum / multiplier_accum; - const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max)); - output[0] = finv_test(value_final, do_invert); -} - -void GaussianAlphaYBlurOperation::deinit_execution() -{ - GaussianAlphaBlurBaseOperation::deinit_execution(); - - if (gausstab_) { - MEM_freeN(gausstab_); - gausstab_ = nullptr; - } - - if (distbuf_inv_) { - MEM_freeN(distbuf_inv_); - distbuf_inv_ = nullptr; - } - - deinit_mutex(); -} - -bool GaussianAlphaYBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; -#if 0 /* until we add size input */ - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - - NodeOperation *operation = this->get_input_operation(1); - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - else -#endif - { - if (sizeavailable_ && gausstab_ != nullptr) { - new_input.xmax = input->xmax; - new_input.xmin = input->xmin; - new_input.ymax = input->ymax + filtersize_ + 1; - new_input.ymin = input->ymin - filtersize_ - 1; - } - else { - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - } - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h deleted file mode 100644 index 4125eeb8744..00000000000 --- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_GaussianAlphaBlurBaseOperation.h" - -namespace blender::compositor { - -/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */ -class GaussianAlphaYBlurOperation : public GaussianAlphaBlurBaseOperation { - private: - void update_gauss(); - - public: - GaussianAlphaYBlurOperation(); - - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * \brief initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc index 3007a17f2b0..ac2ff5407ea 100644 --- a/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc +++ b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.cc @@ -21,22 +21,18 @@ GaussianBlurBaseOperation::GaussianBlurBaseOperation(eDimension dim) void GaussianBlurBaseOperation::init_data() { BlurBaseOperation::init_data(); - if (execution_model_ == eExecutionModel::FullFrame) { - rad_ = max_ff(size_ * this->get_blur_size(dimension_), 0.0f); - rad_ = min_ff(rad_, MAX_GAUSSTAB_RADIUS); - filtersize_ = min_ii(ceil(rad_), MAX_GAUSSTAB_RADIUS); - } + rad_ = max_ff(size_ * this->get_blur_size(dimension_), 0.0f); + rad_ = min_ff(rad_, MAX_GAUSSTAB_RADIUS); + filtersize_ = min_ii(ceil(rad_), MAX_GAUSSTAB_RADIUS); } void GaussianBlurBaseOperation::init_execution() { BlurBaseOperation::init_execution(); - if (execution_model_ == eExecutionModel::FullFrame) { - gausstab_ = BlurBaseOperation::make_gausstab(rad_, filtersize_); + gausstab_ = BlurBaseOperation::make_gausstab(rad_, filtersize_); #if BLI_HAVE_SSE2 - gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_); + gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_); #endif - } } void GaussianBlurBaseOperation::deinit_execution() diff --git a/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h index f72c6e604fd..c35fe56e199 100644 --- a/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h +++ b/source/blender/compositor/operations/COM_GaussianBlurBaseOperation.h @@ -31,4 +31,14 @@ class GaussianBlurBaseOperation : public BlurBaseOperation { Span inputs) override; }; +class GaussianXBlurOperation : public GaussianBlurBaseOperation { + public: + GaussianXBlurOperation() : GaussianBlurBaseOperation(eDimension::X) {} +}; + +class GaussianYBlurOperation : public GaussianBlurBaseOperation { + public: + GaussianYBlurOperation() : GaussianBlurBaseOperation(eDimension::Y) {} +}; + } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc index 3f514f69d11..d2b9786234c 100644 --- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc +++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cc @@ -13,27 +13,14 @@ GaussianBokehBlurOperation::GaussianBokehBlurOperation() : BlurBaseOperation(Dat gausstab_ = nullptr; } -void *GaussianBokehBlurOperation::initialize_tile_data(rcti * /*rect*/) -{ - lock_mutex(); - if (!sizeavailable_) { - update_gauss(); - } - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - unlock_mutex(); - return buffer; -} - void GaussianBokehBlurOperation::init_data() { BlurBaseOperation::init_data(); const float width = this->get_width(); const float height = this->get_height(); - if (execution_model_ == eExecutionModel::FullFrame) { - if (!sizeavailable_) { - update_size(); - } + if (!sizeavailable_) { + update_size(); } radxf_ = size_ * float(data_.sizex); @@ -51,8 +38,6 @@ void GaussianBokehBlurOperation::init_execution() { BlurBaseOperation::init_execution(); - init_mutex(); - if (sizeavailable_) { update_gauss(); } @@ -97,62 +82,6 @@ void GaussianBokehBlurOperation::update_gauss() } } -void GaussianBokehBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float result[4]; - input_size_->read_sampled(result, 0, 0, PixelSampler::Nearest); - size_ = result[0]; - - const float width = this->get_width(); - const float height = this->get_height(); - - radxf_ = size_ * float(data_.sizex); - CLAMP(radxf_, 0.0f, width / 2.0f); - - radyf_ = size_ * float(data_.sizey); - CLAMP(radyf_, 0.0f, height / 2.0f); - - radx_ = ceil(radxf_); - rady_ = ceil(radyf_); - - float temp_color[4]; - temp_color[0] = 0; - temp_color[1] = 0; - temp_color[2] = 0; - temp_color[3] = 0; - float multiplier_accum = 0; - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - float *buffer = input_buffer->get_buffer(); - int bufferwidth = input_buffer->get_width(); - const rcti &input_rect = input_buffer->get_rect(); - int bufferstartx = input_rect.xmin; - int bufferstarty = input_rect.ymin; - - int ymin = max_ii(y - rady_, input_rect.ymin); - int ymax = min_ii(y + rady_ + 1, input_rect.ymax); - int xmin = max_ii(x - radx_, input_rect.xmin); - int xmax = min_ii(x + radx_ + 1, input_rect.xmax); - - int index; - int step = QualityStepHelper::get_step(); - int offsetadd = QualityStepHelper::get_offset_add(); - const int add_const = (xmin - x + radx_); - const int mul_const = (radx_ * 2 + 1); - for (int ny = ymin; ny < ymax; ny += step) { - index = ((ny - y) + rady_) * mul_const + add_const; - int bufferindex = ((xmin - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth); - for (int nx = xmin; nx < xmax; nx += step) { - const float multiplier = gausstab_[index]; - madd_v4_v4fl(temp_color, &buffer[bufferindex], multiplier); - multiplier_accum += multiplier; - index += step; - bufferindex += offsetadd; - } - } - - mul_v4_v4fl(output, temp_color, 1.0f / multiplier_accum); -} - void GaussianBokehBlurOperation::deinit_execution() { BlurBaseOperation::deinit_execution(); @@ -161,41 +90,6 @@ void GaussianBokehBlurOperation::deinit_execution() MEM_freeN(gausstab_); gausstab_ = nullptr; } - - deinit_mutex(); -} - -bool GaussianBokehBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - NodeOperation *operation = this->get_input_operation(1); - - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - - if (sizeavailable_ && gausstab_ != nullptr) { - new_input.xmin = 0; - new_input.ymin = 0; - new_input.xmax = this->get_width(); - new_input.ymax = this->get_height(); - } - else { - int addx = radx_; - int addy = rady_; - new_input.xmax = input->xmax + addx; - new_input.xmin = input->xmin - addx; - new_input.ymax = input->ymax + addy; - new_input.ymin = input->ymin - addy; - } - return BlurBaseOperation::determine_depending_area_of_interest( - &new_input, read_operation, output); } void GaussianBokehBlurOperation::get_area_of_interest(const int input_idx, @@ -303,12 +197,6 @@ void GaussianBlurReferenceOperation::init_data() rady_ = float(filtersizey_); } -void *GaussianBlurReferenceOperation::initialize_tile_data(rcti * /*rect*/) -{ - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - return buffer; -} - void GaussianBlurReferenceOperation::init_execution() { BlurBaseOperation::init_execution(); @@ -326,73 +214,6 @@ void GaussianBlurReferenceOperation::update_gauss() } } -void GaussianBlurReferenceOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *memorybuffer = (MemoryBuffer *)data; - float *buffer = memorybuffer->get_buffer(); - float *gausstabx, *gausstabcenty; - float *gausstaby, *gausstabcentx; - int i, j; - float *src; - float sum, val; - float rval, gval, bval, aval; - int imgx = get_width(); - int imgy = get_height(); - float temp_size[4]; - input_size_->read(temp_size, x, y, data); - float ref_size = temp_size[0]; - int refradx = int(ref_size * radx_); - int refrady = int(ref_size * rady_); - if (refradx > filtersizex_) { - refradx = filtersizex_; - } - else if (refradx < 1) { - refradx = 1; - } - if (refrady > filtersizey_) { - refrady = filtersizey_; - } - else if (refrady < 1) { - refrady = 1; - } - - if (refradx == 1 && refrady == 1) { - memorybuffer->read_no_check(output, x, y); - } - else { - int minxr = x - refradx < 0 ? -x : -refradx; - int maxxr = x + refradx > imgx ? imgx - x : refradx; - int minyr = y - refrady < 0 ? -y : -refrady; - int maxyr = y + refrady > imgy ? imgy - y : refrady; - - float *srcd = buffer + COM_DATA_TYPE_COLOR_CHANNELS * ((y + minyr) * imgx + x + minxr); - - gausstabx = maintabs_[refradx - 1]; - gausstabcentx = gausstabx + refradx; - gausstaby = maintabs_[refrady - 1]; - gausstabcenty = gausstaby + refrady; - - sum = gval = rval = bval = aval = 0.0f; - for (i = minyr; i < maxyr; i++, srcd += COM_DATA_TYPE_COLOR_CHANNELS * imgx) { - src = srcd; - for (j = minxr; j < maxxr; j++, src += COM_DATA_TYPE_COLOR_CHANNELS) { - - val = gausstabcenty[i] * gausstabcentx[j]; - sum += val; - rval += val * src[0]; - gval += val * src[1]; - bval += val * src[2]; - aval += val * src[3]; - } - } - sum = 1.0f / sum; - output[0] = rval * sum; - output[1] = gval * sum; - output[2] = bval * sum; - output[3] = aval * sum; - } -} - void GaussianBlurReferenceOperation::deinit_execution() { int x, i; @@ -404,25 +225,6 @@ void GaussianBlurReferenceOperation::deinit_execution() BlurBaseOperation::deinit_execution(); } -bool GaussianBlurReferenceOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - NodeOperation *operation = this->get_input_operation(1); - - if (operation->determine_depending_area_of_interest(input, read_operation, output)) { - return true; - } - - int addx = data_.sizex + 2; - int addy = data_.sizey + 2; - new_input.xmax = input->xmax + addx; - new_input.xmin = input->xmin - addx; - new_input.ymax = input->ymax + addy; - new_input.ymin = input->ymin - addy; - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void GaussianBlurReferenceOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h index 14bb7074569..a21d4063191 100644 --- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h @@ -22,21 +22,8 @@ class GaussianBokehBlurOperation : public BlurBaseOperation { GaussianBokehBlurOperation(); void init_data() override; void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Deinitialize the execution - */ void deinit_execution() override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -57,21 +44,9 @@ class GaussianBlurReferenceOperation : public BlurBaseOperation { GaussianBlurReferenceOperation(); void init_data() override; void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - /** - * Deinitialize the execution - */ void deinit_execution() override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc deleted file mode 100644 index 537ad0fefa3..00000000000 --- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cc +++ /dev/null @@ -1,185 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_GaussianXBlurOperation.h" -#include "COM_OpenCLDevice.h" - -namespace blender::compositor { - -GaussianXBlurOperation::GaussianXBlurOperation() : GaussianBlurBaseOperation(eDimension::X) {} - -void *GaussianXBlurOperation::initialize_tile_data(rcti * /*rect*/) -{ - lock_mutex(); - if (!sizeavailable_) { - update_gauss(); - } - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - unlock_mutex(); - return buffer; -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void GaussianXBlurOperation::init_execution() -{ - GaussianBlurBaseOperation::init_execution(); - - init_mutex(); - - if (sizeavailable_ && execution_model_ == eExecutionModel::Tiled) { - float rad = max_ff(size_ * data_.sizex, 0.0f); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - /* TODO(sergey): De-duplicate with the case below and Y blur. */ - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); -#if BLI_HAVE_SSE2 - gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_); -#endif - } -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void GaussianXBlurOperation::update_gauss() -{ - if (gausstab_ == nullptr) { - update_size(); - float rad = max_ff(size_ * data_.sizex, 0.0f); - rad = min_ff(rad, MAX_GAUSSTAB_RADIUS); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); -#if BLI_HAVE_SSE2 - gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_); -#endif - } -} - -void GaussianXBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float ATTR_ALIGN(16) color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float multiplier_accum = 0.0f; - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - const rcti &input_rect = input_buffer->get_rect(); - float *buffer = input_buffer->get_buffer(); - int bufferwidth = input_buffer->get_width(); - int bufferstartx = input_rect.xmin; - int bufferstarty = input_rect.ymin; - - int xmin = max_ii(x - filtersize_, input_rect.xmin); - int xmax = min_ii(x + filtersize_ + 1, input_rect.xmax); - int ymin = max_ii(y, input_rect.ymin); - - int step = get_step(); - int offsetadd = get_offset_add(); - int bufferindex = ((xmin - bufferstartx) * 4) + ((ymin - bufferstarty) * 4 * bufferwidth); - -#if BLI_HAVE_SSE2 - __m128 accum_r = _mm_load_ps(color_accum); - for (int nx = xmin, index = (xmin - x) + filtersize_; nx < xmax; nx += step, index += step) { - __m128 reg_a = _mm_load_ps(&buffer[bufferindex]); - reg_a = _mm_mul_ps(reg_a, gausstab_sse_[index]); - accum_r = _mm_add_ps(accum_r, reg_a); - multiplier_accum += gausstab_[index]; - bufferindex += offsetadd; - } - _mm_store_ps(color_accum, accum_r); -#else - for (int nx = xmin, index = (xmin - x) + filtersize_; nx < xmax; nx += step, index += step) { - const float multiplier = gausstab_[index]; - madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier); - multiplier_accum += multiplier; - bufferindex += offsetadd; - } -#endif - mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum); -} - -void GaussianXBlurOperation::execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel gaussian_xblur_operation_kernel = device->COM_cl_create_kernel( - "gaussian_xblur_operation_kernel", nullptr); - cl_int filter_size = filtersize_; - - cl_mem gausstab = clCreateBuffer(device->get_context(), - CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, - sizeof(float) * (filtersize_ * 2 + 1), - gausstab_, - nullptr); - - device->COM_cl_attach_memory_buffer_to_kernel_parameter(gaussian_xblur_operation_kernel, - 0, - 1, - cl_mem_to_clean_up, - input_memory_buffers, - input_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter( - gaussian_xblur_operation_kernel, 2, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - gaussian_xblur_operation_kernel, 3, output_memory_buffer); - clSetKernelArg(gaussian_xblur_operation_kernel, 4, sizeof(cl_int), &filter_size); - device->COM_cl_attach_size_to_kernel_parameter(gaussian_xblur_operation_kernel, 5, this); - clSetKernelArg(gaussian_xblur_operation_kernel, 6, sizeof(cl_mem), &gausstab); - - device->COM_cl_enqueue_range(gaussian_xblur_operation_kernel, output_memory_buffer, 7, this); - - clReleaseMemObject(gausstab); -} - -void GaussianXBlurOperation::deinit_execution() -{ - GaussianBlurBaseOperation::deinit_execution(); - - if (gausstab_) { - MEM_freeN(gausstab_); - gausstab_ = nullptr; - } -#if BLI_HAVE_SSE2 - if (gausstab_sse_) { - MEM_freeN(gausstab_sse_); - gausstab_sse_ = nullptr; - } -#endif - - deinit_mutex(); -} - -bool GaussianXBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - if (!sizeavailable_) { - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - NodeOperation *operation = this->get_input_operation(1); - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - } - { - if (sizeavailable_ && gausstab_ != nullptr) { - new_input.xmax = input->xmax + filtersize_ + 1; - new_input.xmin = input->xmin - filtersize_ - 1; - new_input.ymax = input->ymax; - new_input.ymin = input->ymin; - } - else { - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - } - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianXBlurOperation.h deleted file mode 100644 index e01110ff697..00000000000 --- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.h +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_GaussianBlurBaseOperation.h" - -namespace blender::compositor { - -/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */ -class GaussianXBlurOperation : public GaussianBlurBaseOperation { - private: - void update_gauss(); - - public: - GaussianXBlurOperation(); - - /** - * \brief The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - - /** - * \brief initialize the execution - */ - void init_execution() override; - - /** - * \brief Deinitialize the execution - */ - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - void check_opencl() - { - flags_.open_cl = (data_.sizex >= 128); - } -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc deleted file mode 100644 index 3d6219147cc..00000000000 --- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cc +++ /dev/null @@ -1,185 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_GaussianYBlurOperation.h" -#include "COM_OpenCLDevice.h" - -namespace blender::compositor { - -GaussianYBlurOperation::GaussianYBlurOperation() : GaussianBlurBaseOperation(eDimension::Y) {} - -void *GaussianYBlurOperation::initialize_tile_data(rcti * /*rect*/) -{ - lock_mutex(); - if (!sizeavailable_) { - update_gauss(); - } - void *buffer = get_input_operation(0)->initialize_tile_data(nullptr); - unlock_mutex(); - return buffer; -} - -void GaussianYBlurOperation::init_execution() -{ - GaussianBlurBaseOperation::init_execution(); - - init_mutex(); - - if (sizeavailable_ && execution_model_ == eExecutionModel::Tiled) { - float rad = max_ff(size_ * data_.sizey, 0.0f); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); -#if BLI_HAVE_SSE2 - gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_); -#endif - } -} - -void GaussianYBlurOperation::update_gauss() -{ - if (gausstab_ == nullptr) { - update_size(); - float rad = max_ff(size_ * data_.sizey, 0.0f); - rad = min_ff(rad, MAX_GAUSSTAB_RADIUS); - filtersize_ = min_ii(ceil(rad), MAX_GAUSSTAB_RADIUS); - - gausstab_ = BlurBaseOperation::make_gausstab(rad, filtersize_); -#if BLI_HAVE_SSE2 - gausstab_sse_ = BlurBaseOperation::convert_gausstab_sse(gausstab_, filtersize_); -#endif - } -} - -void GaussianYBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float ATTR_ALIGN(16) color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float multiplier_accum = 0.0f; - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - const rcti &input_rect = input_buffer->get_rect(); - float *buffer = input_buffer->get_buffer(); - int bufferwidth = input_buffer->get_width(); - int bufferstartx = input_rect.xmin; - int bufferstarty = input_rect.ymin; - - int xmin = max_ii(x, input_rect.xmin); - int ymin = max_ii(y - filtersize_, input_rect.ymin); - int ymax = min_ii(y + filtersize_ + 1, input_rect.ymax); - - int index; - int step = get_step(); - const int buffer_indexx = ((xmin - bufferstartx) * 4); - -#if BLI_HAVE_SSE2 - __m128 accum_r = _mm_load_ps(color_accum); - for (int ny = ymin; ny < ymax; ny += step) { - index = (ny - y) + filtersize_; - int bufferindex = buffer_indexx + ((ny - bufferstarty) * 4 * bufferwidth); - const float multiplier = gausstab_[index]; - __m128 reg_a = _mm_load_ps(&buffer[bufferindex]); - reg_a = _mm_mul_ps(reg_a, gausstab_sse_[index]); - accum_r = _mm_add_ps(accum_r, reg_a); - multiplier_accum += multiplier; - } - _mm_store_ps(color_accum, accum_r); -#else - for (int ny = ymin; ny < ymax; ny += step) { - index = (ny - y) + filtersize_; - int bufferindex = buffer_indexx + ((ny - bufferstarty) * 4 * bufferwidth); - const float multiplier = gausstab_[index]; - madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier); - multiplier_accum += multiplier; - } -#endif - mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum); -} - -void GaussianYBlurOperation::execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel gaussian_yblur_operation_kernel = device->COM_cl_create_kernel( - "gaussian_yblur_operation_kernel", nullptr); - cl_int filter_size = filtersize_; - - cl_mem gausstab = clCreateBuffer(device->get_context(), - CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, - sizeof(float) * (filtersize_ * 2 + 1), - gausstab_, - nullptr); - - device->COM_cl_attach_memory_buffer_to_kernel_parameter(gaussian_yblur_operation_kernel, - 0, - 1, - cl_mem_to_clean_up, - input_memory_buffers, - input_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter( - gaussian_yblur_operation_kernel, 2, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - gaussian_yblur_operation_kernel, 3, output_memory_buffer); - clSetKernelArg(gaussian_yblur_operation_kernel, 4, sizeof(cl_int), &filter_size); - device->COM_cl_attach_size_to_kernel_parameter(gaussian_yblur_operation_kernel, 5, this); - clSetKernelArg(gaussian_yblur_operation_kernel, 6, sizeof(cl_mem), &gausstab); - - device->COM_cl_enqueue_range(gaussian_yblur_operation_kernel, output_memory_buffer, 7, this); - - clReleaseMemObject(gausstab); -} - -void GaussianYBlurOperation::deinit_execution() -{ - GaussianBlurBaseOperation::deinit_execution(); - - if (gausstab_) { - MEM_freeN(gausstab_); - gausstab_ = nullptr; - } -#if BLI_HAVE_SSE2 - if (gausstab_sse_) { - MEM_freeN(gausstab_sse_); - gausstab_sse_ = nullptr; - } -#endif - - deinit_mutex(); -} - -bool GaussianYBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - if (!sizeavailable_) { - rcti size_input; - size_input.xmin = 0; - size_input.ymin = 0; - size_input.xmax = 5; - size_input.ymax = 5; - NodeOperation *operation = this->get_input_operation(1); - if (operation->determine_depending_area_of_interest(&size_input, read_operation, output)) { - return true; - } - } - { - if (sizeavailable_ && gausstab_ != nullptr) { - new_input.xmax = input->xmax; - new_input.xmin = input->xmin; - new_input.ymax = input->ymax + filtersize_ + 1; - new_input.ymin = input->ymin - filtersize_ - 1; - } - else { - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - } - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); - } -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianYBlurOperation.h deleted file mode 100644 index 4a84196c451..00000000000 --- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.h +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_GaussianBlurBaseOperation.h" - -namespace blender::compositor { - -/* TODO(manzanilla): everything to be removed with tiled implementation except the constructor. */ -class GaussianYBlurOperation : public GaussianBlurBaseOperation { - private: - void update_gauss(); - - public: - GaussianYBlurOperation(); - - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - - /** - * \brief initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - void check_opencl() - { - flags_.open_cl = (data_.sizex >= 128); - } -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.cc b/source/blender/compositor/operations/COM_GlareBaseOperation.cc index 4cfa1ee9b3c..1f49351d27a 100644 --- a/source/blender/compositor/operations/COM_GlareBaseOperation.cc +++ b/source/blender/compositor/operations/COM_GlareBaseOperation.cc @@ -11,51 +11,9 @@ GlareBaseOperation::GlareBaseOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); settings_ = nullptr; - flags_.is_fullframe_operation = true; flags_.can_be_constant = true; is_output_rendered_ = false; } -void GlareBaseOperation::init_execution() -{ - SingleThreadedOperation::init_execution(); - input_program_ = get_input_socket_reader(0); -} - -void GlareBaseOperation::deinit_execution() -{ - input_program_ = nullptr; - SingleThreadedOperation::deinit_execution(); -} - -MemoryBuffer *GlareBaseOperation::create_memory_buffer(rcti *rect2) -{ - MemoryBuffer *tile = (MemoryBuffer *)input_program_->initialize_tile_data(rect2); - rcti rect; - rect.xmin = 0; - rect.ymin = 0; - rect.xmax = get_width(); - rect.ymax = get_height(); - MemoryBuffer *result = new MemoryBuffer(DataType::Color, rect); - float *data = result->get_buffer(); - this->generate_glare(data, tile, settings_); - return result; -} - -bool GlareBaseOperation::determine_depending_area_of_interest(rcti * /*input*/, - ReadBufferOperation *read_operation, - rcti *output) -{ - if (is_cached()) { - return false; - } - - rcti new_input; - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} void GlareBaseOperation::get_area_of_interest(const int input_idx, const rcti & /*output_area*/, diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.h b/source/blender/compositor/operations/COM_GlareBaseOperation.h index 784c6232f6a..fb9bed305ca 100644 --- a/source/blender/compositor/operations/COM_GlareBaseOperation.h +++ b/source/blender/compositor/operations/COM_GlareBaseOperation.h @@ -4,7 +4,7 @@ #pragma once -#include "COM_SingleThreadedOperation.h" +#include "COM_NodeOperation.h" #include "DNA_node_types.h" namespace blender::compositor { @@ -23,13 +23,8 @@ typedef float fRGB[4]; } \ (void)0 -class GlareBaseOperation : public SingleThreadedOperation { +class GlareBaseOperation : public NodeOperation { private: - /** - * \brief Cached reference to the input_program - */ - SocketReader *input_program_; - /** * \brief settings of the glare node. */ @@ -38,23 +33,10 @@ class GlareBaseOperation : public SingleThreadedOperation { bool is_output_rendered_; public: - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_glare_settings(const NodeGlare *settings) { settings_ = settings; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) final; @@ -68,8 +50,6 @@ class GlareBaseOperation : public SingleThreadedOperation { virtual void generate_glare(float *data, MemoryBuffer *input_tile, const NodeGlare *settings) = 0; - - MemoryBuffer *create_memory_buffer(rcti *rect) override; }; } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.cc b/source/blender/compositor/operations/COM_GlareThresholdOperation.cc index 94f257f4834..18be474ede1 100644 --- a/source/blender/compositor/operations/COM_GlareThresholdOperation.cc +++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.cc @@ -12,7 +12,6 @@ GlareThresholdOperation::GlareThresholdOperation() { this->add_input_socket(DataType::Color, ResizeMode::FitAny); this->add_output_socket(DataType::Color); - input_program_ = nullptr; flags_.can_be_constant = true; } @@ -26,38 +25,6 @@ void GlareThresholdOperation::determine_canvas(const rcti &preferred_area, rcti r_area.ymax = r_area.ymin + height; } -void GlareThresholdOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void GlareThresholdOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - const float threshold = settings_->threshold; - - input_program_->read_sampled(output, x, y, sampler); - if (IMB_colormanagement_get_luminance(output) >= threshold) { - output[0] -= threshold; - output[1] -= threshold; - output[2] -= threshold; - - output[0] = std::max(output[0], 0.0f); - output[1] = std::max(output[1], 0.0f); - output[2] = std::max(output[2], 0.0f); - } - else { - zero_v3(output); - } -} - -void GlareThresholdOperation::deinit_execution() -{ - input_program_ = nullptr; -} - void GlareThresholdOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.h b/source/blender/compositor/operations/COM_GlareThresholdOperation.h index ead0f5bbdaa..0f2f535b52a 100644 --- a/source/blender/compositor/operations/COM_GlareThresholdOperation.h +++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.h @@ -11,11 +11,6 @@ namespace blender::compositor { class GlareThresholdOperation : public MultiThreadedOperation { private: - /** - * \brief Cached reference to the input_program - */ - SocketReader *input_program_; - /** * \brief settings of the glare node. */ @@ -24,21 +19,6 @@ class GlareThresholdOperation : public MultiThreadedOperation { public: GlareThresholdOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_glare_settings(const NodeGlare *settings) { settings_ = settings; diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc index de2eceeb1ba..3945ce793e7 100644 --- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc +++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cc @@ -14,52 +14,6 @@ HueSaturationValueCorrectOperation::HueSaturationValueCorrectOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - - input_program_ = nullptr; -} -void HueSaturationValueCorrectOperation::init_execution() -{ - CurveBaseOperation::init_execution(); - input_program_ = this->get_input_socket_reader(0); -} - -void HueSaturationValueCorrectOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float hsv[4], f; - - input_program_->read_sampled(hsv, x, y, sampler); - - /* We parameterize the curve using the hue value. */ - const float parameter = hsv[0]; - - /* adjust hue, scaling returned default 0.5 up to 1 */ - f = BKE_curvemapping_evaluateF(curve_mapping_, 0, parameter); - hsv[0] += f - 0.5f; - - /* adjust saturation, scaling returned default 0.5 up to 1 */ - f = BKE_curvemapping_evaluateF(curve_mapping_, 1, parameter); - hsv[1] *= (f * 2.0f); - - /* adjust value, scaling returned default 0.5 up to 1 */ - f = BKE_curvemapping_evaluateF(curve_mapping_, 2, parameter); - hsv[2] *= (f * 2.0f); - - hsv[0] = hsv[0] - floorf(hsv[0]); /* mod 1.0 */ - CLAMP(hsv[1], 0.0f, 1.0f); - - output[0] = hsv[0]; - output[1] = hsv[1]; - output[2] = hsv[2]; - output[3] = hsv[3]; -} - -void HueSaturationValueCorrectOperation::deinit_execution() -{ - CurveBaseOperation::deinit_execution(); - input_program_ = nullptr; } void HueSaturationValueCorrectOperation::update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h index 1957a719565..444325d4b7b 100644 --- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h +++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h @@ -5,35 +5,13 @@ #pragma once #include "COM_CurveBaseOperation.h" -#include "COM_NodeOperation.h" namespace blender::compositor { class HueSaturationValueCorrectOperation : public CurveBaseOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - public: HueSaturationValueCorrectOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_IDMaskOperation.cc b/source/blender/compositor/operations/COM_IDMaskOperation.cc index 270f5e3acf7..15b6a24f168 100644 --- a/source/blender/compositor/operations/COM_IDMaskOperation.cc +++ b/source/blender/compositor/operations/COM_IDMaskOperation.cc @@ -10,25 +10,9 @@ IDMaskOperation::IDMaskOperation() { this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - flags_.complex = true; flags_.can_be_constant = true; } -void *IDMaskOperation::initialize_tile_data(rcti *rect) -{ - void *buffer = get_input_operation(0)->initialize_tile_data(rect); - return buffer; -} - -void IDMaskOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - const int buffer_width = input_buffer->get_width(); - float *buffer = input_buffer->get_buffer(); - int buffer_index = (y * buffer_width + x); - output[0] = (roundf(buffer[buffer_index]) == object_index_) ? 1.0f : 0.0f; -} - void IDMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_IDMaskOperation.h b/source/blender/compositor/operations/COM_IDMaskOperation.h index bb1e689c168..814316eeec2 100644 --- a/source/blender/compositor/operations/COM_IDMaskOperation.h +++ b/source/blender/compositor/operations/COM_IDMaskOperation.h @@ -15,9 +15,6 @@ class IDMaskOperation : public MultiThreadedOperation { public: IDMaskOperation(); - void *initialize_tile_data(rcti *rect) override; - void execute_pixel(float output[4], int x, int y, void *data) override; - void set_object_index(float object_index) { object_index_ = object_index; diff --git a/source/blender/compositor/operations/COM_ImageOperation.cc b/source/blender/compositor/operations/COM_ImageOperation.cc index 8cff2ad0910..61570dc9e00 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cc +++ b/source/blender/compositor/operations/COM_ImageOperation.cc @@ -15,8 +15,6 @@ BaseImageOperation::BaseImageOperation() { image_ = nullptr; buffer_ = nullptr; - image_float_buffer_ = nullptr; - image_byte_buffer_ = nullptr; image_user_ = nullptr; imagewidth_ = 0; imageheight_ = 0; @@ -62,8 +60,6 @@ void BaseImageOperation::init_execution() ImBuf *stackbuf = get_im_buf(); buffer_ = stackbuf; if (stackbuf) { - image_float_buffer_ = stackbuf->float_buffer.data; - image_byte_buffer_ = stackbuf->byte_buffer.data; imagewidth_ = stackbuf->x; imageheight_ = stackbuf->y; number_of_channels_ = stackbuf->channels; @@ -72,8 +68,6 @@ void BaseImageOperation::init_execution() void BaseImageOperation::deinit_execution() { - image_float_buffer_ = nullptr; - image_byte_buffer_ = nullptr; BKE_image_release_ibuf(image_, buffer_, nullptr); } @@ -90,67 +84,6 @@ void BaseImageOperation::determine_canvas(const rcti & /*preferred_area*/, rcti BKE_image_release_ibuf(image_, stackbuf, nullptr); } -static void sample_image_at_location(ImBuf *ibuf, - float x, - float y, - PixelSampler sampler, - bool make_linear_rgb, - bool ensure_premultiplied, - float color[4]) -{ - if (ibuf->float_buffer.data) { - switch (sampler) { - case PixelSampler::Nearest: - imbuf::interpolate_nearest_fl(ibuf, color, x, y); - break; - case PixelSampler::Bilinear: - imbuf::interpolate_bilinear_border_fl(ibuf, color, x, y); - break; - case PixelSampler::Bicubic: - imbuf::interpolate_cubic_bspline_fl(ibuf, color, x, y); - break; - } - } - else { - uchar4 byte_color; - switch (sampler) { - case PixelSampler::Nearest: - byte_color = imbuf::interpolate_nearest_byte(ibuf, x, y); - break; - case PixelSampler::Bilinear: - byte_color = imbuf::interpolate_bilinear_border_byte(ibuf, x, y); - break; - case PixelSampler::Bicubic: - byte_color = imbuf::interpolate_cubic_bspline_byte(ibuf, x, y); - break; - } - rgba_uchar_to_float(color, byte_color); - if (make_linear_rgb) { - IMB_colormanagement_colorspace_to_scene_linear_v4( - color, false, ibuf->byte_buffer.colorspace); - } - if (ensure_premultiplied) { - straight_to_premul_v4(color); - } - } -} - -void ImageOperation::execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) -{ - int ix = x, iy = y; - if (image_float_buffer_ == nullptr && image_byte_buffer_ == nullptr) { - zero_v4(output); - } - else if (ix < 0 || iy < 0 || ix >= buffer_->x || iy >= buffer_->y) { - zero_v4(output); - } - else { - const bool ensure_premultiplied = !ELEM( - image_->alpha_mode, IMA_ALPHA_CHANNEL_PACKED, IMA_ALPHA_IGNORE); - sample_image_at_location(buffer_, x, y, sampler, true, ensure_premultiplied, output); - } -} - void ImageOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) @@ -160,23 +93,6 @@ void ImageOperation::update_memory_buffer_partial(MemoryBuffer *output, output->copy_from(buffer_, area, ensure_premultiplied, true); } -void ImageAlphaOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float tempcolor[4]; - - if (image_float_buffer_ == nullptr && image_byte_buffer_ == nullptr) { - output[0] = 0.0f; - } - else { - tempcolor[3] = 1.0f; - sample_image_at_location(buffer_, x, y, sampler, false, false, tempcolor); - output[0] = tempcolor[3]; - } -} - void ImageAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) diff --git a/source/blender/compositor/operations/COM_ImageOperation.h b/source/blender/compositor/operations/COM_ImageOperation.h index dfc73b739c9..547fb1b0a86 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.h +++ b/source/blender/compositor/operations/COM_ImageOperation.h @@ -24,9 +24,6 @@ class BaseImageOperation : public MultiThreadedOperation { ImBuf *buffer_; Image *image_; ImageUser *image_user_; - /* TODO: Remove raw buffers when removing Tiled implementation. */ - float *image_float_buffer_; - uint8_t *image_byte_buffer_; int imageheight_; int imagewidth_; @@ -73,7 +70,6 @@ class ImageOperation : public BaseImageOperation { * Constructor */ ImageOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -85,7 +81,6 @@ class ImageAlphaOperation : public BaseImageOperation { * Constructor */ ImageAlphaOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_InpaintOperation.cc b/source/blender/compositor/operations/COM_InpaintOperation.cc index d12b7c0dea5..bdfc4b9d82e 100644 --- a/source/blender/compositor/operations/COM_InpaintOperation.cc +++ b/source/blender/compositor/operations/COM_InpaintOperation.cc @@ -153,47 +153,18 @@ InpaintSimpleOperation::InpaintSimpleOperation() { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_image_program_ = nullptr; cached_buffer_ = nullptr; cached_buffer_ready_ = false; - flags_.complex = true; - flags_.is_fullframe_operation = true; flags_.can_be_constant = true; } void InpaintSimpleOperation::init_execution() { - input_image_program_ = this->get_input_socket_reader(0); cached_buffer_ = nullptr; cached_buffer_ready_ = false; - this->init_mutex(); -} - -void *InpaintSimpleOperation::initialize_tile_data(rcti *rect) -{ - if (cached_buffer_ready_) { - return cached_buffer_; - } - lock_mutex(); - if (!cached_buffer_ready_) { - MemoryBuffer *input = (MemoryBuffer *)input_image_program_->initialize_tile_data(rect); - cached_buffer_ = new MemoryBuffer(DataType::Color, input->get_rect()); - inpaint(input, cached_buffer_); - cached_buffer_ready_ = true; - } - - unlock_mutex(); - return cached_buffer_; -} - -void InpaintSimpleOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - copy_v4_v4(output, cached_buffer_->get_elem(x, y)); } void InpaintSimpleOperation::deinit_execution() { - input_image_program_ = nullptr; - this->deinit_mutex(); if (cached_buffer_) { delete cached_buffer_; cached_buffer_ = nullptr; @@ -202,23 +173,6 @@ void InpaintSimpleOperation::deinit_execution() cached_buffer_ready_ = false; } -bool InpaintSimpleOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - if (cached_buffer_ready_) { - return false; - } - - rcti new_input; - - new_input.xmax = get_width(); - new_input.xmin = 0; - new_input.ymax = get_height(); - new_input.ymin = 0; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void InpaintSimpleOperation::get_area_of_interest(const int input_idx, const rcti & /*output_area*/, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_InpaintOperation.h b/source/blender/compositor/operations/COM_InpaintOperation.h index 1d3b22d2a7d..be3c4aff53c 100644 --- a/source/blender/compositor/operations/COM_InpaintOperation.h +++ b/source/blender/compositor/operations/COM_InpaintOperation.h @@ -14,7 +14,6 @@ namespace blender::compositor { class InpaintSimpleOperation : public NodeOperation { protected: - SocketReader *input_image_program_; MemoryBuffer *cached_buffer_; bool cached_buffer_ready_; int max_distance_; @@ -37,12 +36,8 @@ class InpaintSimpleOperation : public NodeOperation { void inpaint(const MemoryBuffer *input, MemoryBuffer *output); - void execute_pixel(float output[4], int x, int y, void *data) override; - void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - void deinit_execution() override; void set_max_distance(int max_distance) @@ -50,10 +45,6 @@ class InpaintSimpleOperation : public NodeOperation { max_distance_ = max_distance; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_InvertOperation.cc b/source/blender/compositor/operations/COM_InvertOperation.cc index 05dfb4dce90..40d70cddc90 100644 --- a/source/blender/compositor/operations/COM_InvertOperation.cc +++ b/source/blender/compositor/operations/COM_InvertOperation.cc @@ -11,54 +11,11 @@ InvertOperation::InvertOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_value_program_ = nullptr; - input_color_program_ = nullptr; color_ = true; alpha_ = false; set_canvas_input_index(1); flags_.can_be_constant = true; } -void InvertOperation::init_execution() -{ - input_value_program_ = this->get_input_socket_reader(0); - input_color_program_ = this->get_input_socket_reader(1); -} - -void InvertOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value[4]; - float input_color[4]; - input_value_program_->read_sampled(input_value, x, y, sampler); - input_color_program_->read_sampled(input_color, x, y, sampler); - - const float value = input_value[0]; - const float inverted_value = 1.0f - value; - - if (color_) { - output[0] = (1.0f - input_color[0]) * value + input_color[0] * inverted_value; - output[1] = (1.0f - input_color[1]) * value + input_color[1] * inverted_value; - output[2] = (1.0f - input_color[2]) * value + input_color[2] * inverted_value; - } - else { - copy_v3_v3(output, input_color); - } - - if (alpha_) { - output[3] = (1.0f - input_color[3]) * value + input_color[3] * inverted_value; - } - else { - output[3] = input_color[3]; - } -} - -void InvertOperation::deinit_execution() -{ - input_value_program_ = nullptr; - input_color_program_ = nullptr; -} void InvertOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_InvertOperation.h b/source/blender/compositor/operations/COM_InvertOperation.h index ce7ab8a5972..c99ace2e2e7 100644 --- a/source/blender/compositor/operations/COM_InvertOperation.h +++ b/source/blender/compositor/operations/COM_InvertOperation.h @@ -10,33 +10,12 @@ namespace blender::compositor { class InvertOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_value_program_; - SocketReader *input_color_program_; - bool alpha_; bool color_; public: InvertOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_color(bool color) { color_ = color; diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.cc b/source/blender/compositor/operations/COM_KeyingBlurOperation.cc index d237ba99727..9ac991d1cff 100644 --- a/source/blender/compositor/operations/COM_KeyingBlurOperation.cc +++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.cc @@ -14,71 +14,9 @@ KeyingBlurOperation::KeyingBlurOperation() size_ = 0; axis_ = BLUR_AXIS_X; - flags_.complex = true; flags_.can_be_constant = true; } -void *KeyingBlurOperation::initialize_tile_data(rcti *rect) -{ - void *buffer = get_input_operation(0)->initialize_tile_data(rect); - - return buffer; -} - -void KeyingBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - const int buffer_width = input_buffer->get_width(); - float *buffer = input_buffer->get_buffer(); - int count = 0; - float average = 0.0f; - - if (axis_ == 0) { - const int start = std::max(0, x - size_ + 1); - const int end = std::min(buffer_width, x + size_); - for (int cx = start; cx < end; cx++) { - int buffer_index = (y * buffer_width + cx); - average += buffer[buffer_index]; - count++; - } - } - else { - const int start = std::max(0, y - size_ + 1); - const int end = std::min(input_buffer->get_height(), y + size_); - for (int cy = start; cy < end; cy++) { - int buffer_index = (cy * buffer_width + x); - average += buffer[buffer_index]; - count++; - } - } - - average /= float(count); - - output[0] = average; -} - -bool KeyingBlurOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - - if (axis_ == BLUR_AXIS_X) { - new_input.xmin = input->xmin - size_; - new_input.ymin = input->ymin; - new_input.xmax = input->xmax + size_; - new_input.ymax = input->ymax; - } - else { - new_input.xmin = input->xmin; - new_input.ymin = input->ymin - size_; - new_input.xmax = input->xmax; - new_input.ymax = input->ymax + size_; - } - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void KeyingBlurOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.h b/source/blender/compositor/operations/COM_KeyingBlurOperation.h index 0f5a699ad44..dd04d2b2a20 100644 --- a/source/blender/compositor/operations/COM_KeyingBlurOperation.h +++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.h @@ -33,14 +33,6 @@ class KeyingBlurOperation : public MultiThreadedOperation { axis_ = value; } - void *initialize_tile_data(rcti *rect) override; - - void execute_pixel(float output[4], int x, int y, void *data) override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.cc b/source/blender/compositor/operations/COM_KeyingClipOperation.cc index f1b02b3f4ae..55fb357a044 100644 --- a/source/blender/compositor/operations/COM_KeyingClipOperation.cc +++ b/source/blender/compositor/operations/COM_KeyingClipOperation.cc @@ -19,97 +19,9 @@ KeyingClipOperation::KeyingClipOperation() is_edge_matte_ = false; - flags_.complex = true; flags_.can_be_constant = true; } -void *KeyingClipOperation::initialize_tile_data(rcti *rect) -{ - void *buffer = get_input_operation(0)->initialize_tile_data(rect); - - return buffer; -} - -void KeyingClipOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - const int delta = kernel_radius_; - const float tolerance = kernel_tolerance_; - - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - float *buffer = input_buffer->get_buffer(); - - int buffer_width = input_buffer->get_width(); - int buffer_height = input_buffer->get_height(); - - float value = buffer[(y * buffer_width + x)]; - - bool ok = false; - - const int start_x = max_ff(0, x - delta); - const int start_y = max_ff(0, y - delta); - const int end_x = min_ff(x + delta, buffer_width - 1); - const int end_y = min_ff(y + delta, buffer_height - 1); - - int count = 0, total_count = (end_x - start_x + 1) * (end_y - start_y + 1); - int threshold_count = ceil(float(total_count) * 0.9f); - - if (delta == 0) { - ok = true; - } - - for (int cx = start_x; ok == false && cx <= end_x; cx++) { - for (int cy = start_y; ok == false && cy <= end_y; cy++) { - int buffer_index = (cy * buffer_width + cx); - float current_value = buffer[buffer_index]; - - if (fabsf(current_value - value) < tolerance) { - count++; - if (count >= threshold_count) { - ok = true; - } - } - } - } - - if (is_edge_matte_) { - if (ok) { - output[0] = 0.0f; - } - else { - output[0] = 1.0f; - } - } - else { - output[0] = value; - - if (ok) { - if (output[0] < clip_black_) { - output[0] = 0.0f; - } - else if (output[0] >= clip_white_) { - output[0] = 1.0f; - } - else { - output[0] = (output[0] - clip_black_) / (clip_white_ - clip_black_); - } - } - } -} - -bool KeyingClipOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - - new_input.xmin = input->xmin - kernel_radius_; - new_input.ymin = input->ymin - kernel_radius_; - new_input.xmax = input->xmax + kernel_radius_; - new_input.ymax = input->ymax + kernel_radius_; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void KeyingClipOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.h b/source/blender/compositor/operations/COM_KeyingClipOperation.h index bde4ec3ec13..f58a818a400 100644 --- a/source/blender/compositor/operations/COM_KeyingClipOperation.h +++ b/source/blender/compositor/operations/COM_KeyingClipOperation.h @@ -47,14 +47,6 @@ class KeyingClipOperation : public MultiThreadedOperation { is_edge_matte_ = value; } - void *initialize_tile_data(rcti *rect) override; - - void execute_pixel(float output[4], int x, int y, void *data) override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_KeyingDespillOperation.cc b/source/blender/compositor/operations/COM_KeyingDespillOperation.cc index a3bc7726212..11534866362 100644 --- a/source/blender/compositor/operations/COM_KeyingDespillOperation.cc +++ b/source/blender/compositor/operations/COM_KeyingDespillOperation.cc @@ -17,55 +17,9 @@ KeyingDespillOperation::KeyingDespillOperation() despill_factor_ = 0.5f; color_balance_ = 0.5f; - pixel_reader_ = nullptr; - screen_reader_ = nullptr; flags_.can_be_constant = true; } -void KeyingDespillOperation::init_execution() -{ - pixel_reader_ = this->get_input_socket_reader(0); - screen_reader_ = this->get_input_socket_reader(1); -} - -void KeyingDespillOperation::deinit_execution() -{ - pixel_reader_ = nullptr; - screen_reader_ = nullptr; -} - -void KeyingDespillOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float pixel_color[4]; - float screen_color[4]; - - pixel_reader_->read_sampled(pixel_color, x, y, sampler); - screen_reader_->read_sampled(screen_color, x, y, sampler); - - const int screen_primary_channel = max_axis_v3(screen_color); - const int other_1 = (screen_primary_channel + 1) % 3; - const int other_2 = (screen_primary_channel + 2) % 3; - - const int min_channel = std::min(other_1, other_2); - const int max_channel = std::max(other_1, other_2); - - float average_value, amount; - - average_value = color_balance_ * pixel_color[min_channel] + - (1.0f - color_balance_) * pixel_color[max_channel]; - amount = (pixel_color[screen_primary_channel] - average_value); - - copy_v4_v4(output, pixel_color); - - const float amount_despill = despill_factor_ * amount; - if (amount_despill > 0.0f) { - output[screen_primary_channel] = pixel_color[screen_primary_channel] - amount_despill; - } -} - void KeyingDespillOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_KeyingDespillOperation.h b/source/blender/compositor/operations/COM_KeyingDespillOperation.h index 7fdbd4d79ac..16c4cf22a4a 100644 --- a/source/blender/compositor/operations/COM_KeyingDespillOperation.h +++ b/source/blender/compositor/operations/COM_KeyingDespillOperation.h @@ -13,17 +13,12 @@ namespace blender::compositor { */ class KeyingDespillOperation : public MultiThreadedOperation { protected: - SocketReader *pixel_reader_; - SocketReader *screen_reader_; float despill_factor_; float color_balance_; public: KeyingDespillOperation(); - void init_execution() override; - void deinit_execution() override; - void set_despill_factor(float value) { despill_factor_ = value; @@ -33,8 +28,6 @@ class KeyingDespillOperation : public MultiThreadedOperation { color_balance_ = value; } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_KeyingOperation.cc b/source/blender/compositor/operations/COM_KeyingOperation.cc index 7288d11a31b..8756c6070c4 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.cc +++ b/source/blender/compositor/operations/COM_KeyingOperation.cc @@ -32,71 +32,9 @@ KeyingOperation::KeyingOperation() screen_balance_ = 0.5f; - pixel_reader_ = nullptr; - screen_reader_ = nullptr; - flags_.can_be_constant = true; } -void KeyingOperation::init_execution() -{ - pixel_reader_ = this->get_input_socket_reader(0); - screen_reader_ = this->get_input_socket_reader(1); -} - -void KeyingOperation::deinit_execution() -{ - pixel_reader_ = nullptr; - screen_reader_ = nullptr; -} - -void KeyingOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float pixel_color[4]; - float screen_color[4]; - - pixel_reader_->read_sampled(pixel_color, x, y, sampler); - screen_reader_->read_sampled(screen_color, x, y, sampler); - - const int primary_channel = max_axis_v3(screen_color); - const float min_pixel_color = min_fff(pixel_color[0], pixel_color[1], pixel_color[2]); - - if (min_pixel_color > 1.0f) { - /* overexposure doesn't happen on screen itself and usually happens - * on light sources in the shot, this need to be checked separately - * because saturation and falloff calculation is based on the fact - * that pixels are not overexposed - */ - output[0] = 1.0f; - } - else { - float saturation = get_pixel_saturation(pixel_color, screen_balance_, primary_channel); - float screen_saturation = get_pixel_saturation(screen_color, screen_balance_, primary_channel); - - if (saturation < 0) { - /* means main channel of pixel is different from screen, - * assume this is completely a foreground - */ - output[0] = 1.0f; - } - else if (saturation >= screen_saturation) { - /* matched main channels and higher saturation on pixel - * is treated as completely background - */ - output[0] = 0.0f; - } - else { - /* nice alpha falloff on edges */ - float distance = 1.0f - saturation / screen_saturation; - - output[0] = distance; - } - } -} - void KeyingOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_KeyingOperation.h b/source/blender/compositor/operations/COM_KeyingOperation.h index 87e3247767d..02f1a5dd54c 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.h +++ b/source/blender/compositor/operations/COM_KeyingOperation.h @@ -17,24 +17,16 @@ namespace blender::compositor { */ class KeyingOperation : public MultiThreadedOperation { protected: - SocketReader *pixel_reader_; - SocketReader *screen_reader_; - float screen_balance_; public: KeyingOperation(); - void init_execution() override; - void deinit_execution() override; - void set_screen_balance(float value) { screen_balance_ = value; } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cc b/source/blender/compositor/operations/COM_KeyingScreenOperation.cc index ed56fd27812..8966f084f1e 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cc +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cc @@ -26,21 +26,14 @@ KeyingScreenOperation::KeyingScreenOperation() movie_clip_ = nullptr; framenumber_ = 0; tracking_object_[0] = 0; - flags_.complex = true; cached_marker_points_ = nullptr; } void KeyingScreenOperation::init_execution() { - init_mutex(); - if (execution_model_ == eExecutionModel::FullFrame) { - BLI_assert(cached_marker_points_ == nullptr); - if (movie_clip_) { - cached_marker_points_ = compute_marker_points(); - } - } - else { - cached_marker_points_ = nullptr; + BLI_assert(cached_marker_points_ == nullptr); + if (movie_clip_) { + cached_marker_points_ = compute_marker_points(); } } @@ -144,23 +137,6 @@ Array *KeyingScreenOperation::compute_marker return marker_points; } -void *KeyingScreenOperation::initialize_tile_data(rcti * /*rect*/) -{ - if (movie_clip_ == nullptr) { - return nullptr; - } - - if (!cached_marker_points_) { - lock_mutex(); - if (cached_marker_points_ == nullptr) { - cached_marker_points_ = compute_marker_points(); - } - unlock_mutex(); - } - - return nullptr; -} - void KeyingScreenOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { r_area = COM_AREA_NONE; @@ -178,31 +154,6 @@ void KeyingScreenOperation::determine_canvas(const rcti &preferred_area, rcti &r } } -void KeyingScreenOperation::execute_pixel(float output[4], int x, int y, void * /* data */) -{ - if (!cached_marker_points_) { - copy_v4_fl(output, 0.0f); - return; - } - - const int2 size = int2(this->get_width(), this->get_height()); - const float2 normalized_pixel_location = float2(x, y) / float2(size); - const float squared_shape_parameter = math::square(1.0f / smoothness_); - - float4 weighted_sum = float4(0.0f); - float sum_of_weights = 0.0f; - for (const MarkerPoint &marker_point : *cached_marker_points_) { - const float2 difference = normalized_pixel_location - marker_point.position; - const float squared_distance = math::dot(difference, difference); - const float gaussian = math::exp(-squared_distance * squared_shape_parameter); - weighted_sum += marker_point.color * gaussian; - sum_of_weights += gaussian; - } - weighted_sum /= sum_of_weights; - - copy_v4_v4(output, weighted_sum); -} - void KeyingScreenOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.h b/source/blender/compositor/operations/COM_KeyingScreenOperation.h index aae53312c86..f9d0484db40 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.h +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.h @@ -47,8 +47,6 @@ class KeyingScreenOperation : public MultiThreadedOperation { void init_execution() override; void deinit_execution() override; - void *initialize_tile_data(rcti *rect) override; - void set_movie_clip(MovieClip *clip) { movie_clip_ = clip; @@ -66,8 +64,6 @@ class KeyingScreenOperation : public MultiThreadedOperation { framenumber_ = framenumber; } - void execute_pixel(float output[4], int x, int y, void *data) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.cc b/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.cc index d52d61700e7..85a17a28dbc 100644 --- a/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.cc +++ b/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.cc @@ -19,279 +19,9 @@ KuwaharaAnisotropicOperation::KuwaharaAnisotropicOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - this->flags_.is_fullframe_operation = true; this->flags_.can_be_constant = true; } -void KuwaharaAnisotropicOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); - size_reader_ = this->get_input_socket_reader(1); - structure_tensor_reader_ = this->get_input_socket_reader(2); -} - -void KuwaharaAnisotropicOperation::deinit_execution() -{ - image_reader_ = nullptr; - size_reader_ = nullptr; - structure_tensor_reader_ = nullptr; -} - -/* An implementation of the Anisotropic Kuwahara filter described in the paper: - * - * Kyprianidis, Jan Eric, Henry Kang, and Jurgen Dollner. "Image and video abstraction by - * anisotropic Kuwahara filtering." 2009. - * - * But with the polynomial weighting functions described in the paper: - * - * Kyprianidis, Jan Eric, et al. "Anisotropic Kuwahara Filtering with Polynomial Weighting - * Functions." 2010. - * - * And the sector weight function described in the paper: - * - * Kyprianidis, Jan Eric. "Image and video abstraction by multi-scale anisotropic Kuwahara - * filtering." 2011. - */ -void KuwaharaAnisotropicOperation::execute_pixel_sampled(float output[4], - float x_float, - float y_float, - PixelSampler /*sampler*/) -{ - using namespace math; - const int x = x_float; - const int y = y_float; - - /* The structure tensor is encoded in a float4 using a column major storage order, as can be - * seen in the KuwaharaAnisotropicStructureTensorOperation. */ - float4 encoded_structure_tensor; - structure_tensor_reader_->read(encoded_structure_tensor, x, y, nullptr); - float dxdx = encoded_structure_tensor.x; - float dxdy = encoded_structure_tensor.y; - float dydy = encoded_structure_tensor.w; - - /* Compute the first and second eigenvalues of the structure tensor using the equations in - * section "3.1 Orientation and Anisotropy Estimation" of the paper. */ - float eigenvalue_first_term = (dxdx + dydy) / 2.0f; - float eigenvalue_square_root_term = sqrt(square(dxdx - dydy) + 4.0f * square(dxdy)) / 2.0f; - float first_eigenvalue = eigenvalue_first_term + eigenvalue_square_root_term; - float second_eigenvalue = eigenvalue_first_term - eigenvalue_square_root_term; - - /* Compute the normalized eigenvector of the structure tensor oriented in direction of the - * minimum rate of change using the equations in section "3.1 Orientation and Anisotropy - * Estimation" of the paper. */ - float2 eigenvector = float2(first_eigenvalue - dxdx, -dxdy); - float eigenvector_length = length(eigenvector); - float2 unit_eigenvector = eigenvector_length != 0.0f ? eigenvector / eigenvector_length : - float2(1.0f); - - /* Compute the amount of anisotropy using equations in section "3.1 Orientation and Anisotropy - * Estimation" of the paper. The anisotropy ranges from 0 to 1, where 0 corresponds to - * isotropic and 1 corresponds to entirely anisotropic regions. */ - float eigenvalue_sum = first_eigenvalue + second_eigenvalue; - float eigenvalue_difference = first_eigenvalue - second_eigenvalue; - float anisotropy = eigenvalue_sum > 0.0f ? eigenvalue_difference / eigenvalue_sum : 0.0f; - - float4 size; - size_reader_->read(size, x, y, nullptr); - float radius = max(0.0f, size.x); - - /* Compute the width and height of an ellipse that is more width-elongated for high anisotropy - * and more circular for low anisotropy, controlled using the eccentricity factor. Since the - * anisotropy is in the [0, 1] range, the width factor tends to 1 as the eccentricity tends to - * infinity and tends to infinity when the eccentricity tends to zero. This is based on the - * equations in section "3.2. Anisotropic Kuwahara Filtering" of the paper. */ - float ellipse_width_factor = (get_eccentricity() + anisotropy) / get_eccentricity(); - float ellipse_width = ellipse_width_factor * radius; - float ellipse_height = radius / ellipse_width_factor; - - /* Compute the cosine and sine of the angle that the eigenvector makes with the x axis. Since - * the eigenvector is normalized, its x and y components are the cosine and sine of the angle - * it makes with the x axis. */ - float cosine = unit_eigenvector.x; - float sine = unit_eigenvector.y; - - /* Compute an inverse transformation matrix that represents an ellipse of the given width and - * height and makes and an angle with the x axis of the given cosine and sine. This is an - * inverse matrix, so it transforms the ellipse into a disk of unit radius. */ - float2x2 inverse_ellipse_matrix = float2x2( - float2(cosine / ellipse_width, -sine / ellipse_height), - float2(sine / ellipse_width, cosine / ellipse_height)); - - /* Compute the bounding box of a zero centered ellipse whose major axis is aligned with the - * eigenvector and has the given width and height. This is based on the equations described in: - * - * https://iquilezles.org/articles/ellipses/ - * - * Notice that we only compute the upper bound, the lower bound is just negative that since the - * ellipse is zero centered. Also notice that we take the ceiling of the bounding box, just to - * ensure the filter window is at least 1x1. */ - float2 ellipse_major_axis = ellipse_width * unit_eigenvector; - float2 ellipse_minor_axis = ellipse_height * float2(unit_eigenvector.y, unit_eigenvector.x) * - float2(-1, 1); - int2 ellipse_bounds = int2(ceil(sqrt(square(ellipse_major_axis) + square(ellipse_minor_axis)))); - - /* Compute the overlap polynomial parameters for 8-sector ellipse based on the equations in - * section "3 Alternative Weighting Functions" of the polynomial weights paper. More on this - * later in the code. */ - const int number_of_sectors = 8; - float sector_center_overlap_parameter = 2.0f / radius; - float sector_envelope_angle = ((3.0f / 2.0f) * M_PI) / number_of_sectors; - float cross_sector_overlap_parameter = (sector_center_overlap_parameter + - cos(sector_envelope_angle)) / - square(sin(sector_envelope_angle)); - - /* We need to compute the weighted mean of color and squared color of each of the 8 sectors of - * the ellipse, so we declare arrays for accumulating those and initialize them in the next - * code section. */ - float4 weighted_mean_of_squared_color_of_sectors[8]; - float4 weighted_mean_of_color_of_sectors[8]; - float sum_of_weights_of_sectors[8]; - - /* The center pixel (0, 0) is exempt from the main loop below for reasons that are explained in - * the first if statement in the loop, so we need to accumulate its color, squared color, and - * weight separately first. Luckily, the zero coordinates of the center pixel zeros out most of - * the complex computations below, and it can easily be shown that the weight for the center - * pixel in all sectors is simply (1 / number_of_sectors). */ - float4 center_color; - image_reader_->read(center_color, x, y, nullptr); - float4 center_color_squared = center_color * center_color; - float center_weight = 1.0f / number_of_sectors; - float4 weighted_center_color = center_color * center_weight; - float4 weighted_center_color_squared = center_color_squared * center_weight; - for (int i = 0; i < number_of_sectors; i++) { - weighted_mean_of_squared_color_of_sectors[i] = weighted_center_color_squared; - weighted_mean_of_color_of_sectors[i] = weighted_center_color; - sum_of_weights_of_sectors[i] = center_weight; - } - - /* Loop over the window of pixels inside the bounding box of the ellipse. However, we utilize - * the fact that ellipses are mirror symmetric along the horizontal axis, so we reduce the - * window to only the upper two quadrants, and compute each two mirrored pixels at the same - * time using the same weight as an optimization. */ - for (int j = 0; j <= ellipse_bounds.y; j++) { - for (int i = -ellipse_bounds.x; i <= ellipse_bounds.x; i++) { - /* Since we compute each two mirrored pixels at the same time, we need to also exempt the - * pixels whose x coordinates are negative and their y coordinates are zero, that's because - * those are mirrored versions of the pixels whose x coordinates are positive and their y - * coordinates are zero, and we don't want to compute and accumulate them twice. Moreover, - * we also need to exempt the center pixel with zero coordinates for the same reason, - * however, since the mirror of the center pixel is itself, it need to be accumulated - * separately, hence why we did that in the code section just before this loop. */ - if (j == 0 && i <= 0) { - continue; - } - - /* Map the pixels of the ellipse into a unit disk, exempting any points that are not part - * of the ellipse or disk. */ - float2 disk_point = inverse_ellipse_matrix * float2(i, j); - float disk_point_length_squared = dot(disk_point, disk_point); - if (disk_point_length_squared > 1.0f) { - continue; - } - - /* While each pixel belongs to a single sector in the ellipse, we expand the definition of - * a sector a bit to also overlap with other sectors as illustrated in Figure 8 of the - * polynomial weights paper. So each pixel may contribute to multiple sectors, and thus we - * compute its weight in each of the 8 sectors. */ - float sector_weights[8]; - - /* We evaluate the weighting polynomial at each of the 8 sectors by rotating the disk point - * by 45 degrees and evaluating the weighting polynomial at each incremental rotation. To - * avoid potentially expensive rotations, we utilize the fact that rotations by 90 degrees - * are simply swapping of the coordinates and negating the x component. We also note that - * since the y term of the weighting polynomial is squared, it is not affected by the sign - * and can be computed once for the x and once for the y coordinates. So we compute every - * other even-indexed 4 weights by successive 90 degree rotations as discussed. */ - float2 polynomial = sector_center_overlap_parameter - - cross_sector_overlap_parameter * square(disk_point); - sector_weights[0] = square(max(0.0f, disk_point.y + polynomial.x)); - sector_weights[2] = square(max(0.0f, -disk_point.x + polynomial.y)); - sector_weights[4] = square(max(0.0f, -disk_point.y + polynomial.x)); - sector_weights[6] = square(max(0.0f, disk_point.x + polynomial.y)); - - /* Then we rotate the disk point by 45 degrees, which is a simple expression involving a - * constant as can be demonstrated by applying a 45 degree rotation matrix. */ - float2 rotated_disk_point = M_SQRT1_2 * - float2(disk_point.x - disk_point.y, disk_point.x + disk_point.y); - - /* Finally, we compute every other odd-index 4 weights starting from the 45 degree rotated - * disk point. */ - float2 rotated_polynomial = sector_center_overlap_parameter - - cross_sector_overlap_parameter * square(rotated_disk_point); - sector_weights[1] = square(max(0.0f, rotated_disk_point.y + rotated_polynomial.x)); - sector_weights[3] = square(max(0.0f, -rotated_disk_point.x + rotated_polynomial.y)); - sector_weights[5] = square(max(0.0f, -rotated_disk_point.y + rotated_polynomial.x)); - sector_weights[7] = square(max(0.0f, rotated_disk_point.x + rotated_polynomial.y)); - - /* We compute a radial Gaussian weighting component such that pixels further away from the - * sector center gets attenuated, and we also divide by the sum of sector weights to - * normalize them, since the radial weight will eventually be multiplied to the sector - * weight below. */ - float sector_weights_sum = sector_weights[0] + sector_weights[1] + sector_weights[2] + - sector_weights[3] + sector_weights[4] + sector_weights[5] + - sector_weights[6] + sector_weights[7]; - float radial_gaussian_weight = exp(-M_PI * disk_point_length_squared) / sector_weights_sum; - - /* Load the color of the pixel and its mirrored pixel and compute their square. */ - float4 upper_color; - image_reader_->read(upper_color, - clamp(x + i, 0, int(this->get_width()) - 1), - clamp(y + j, 0, int(this->get_height()) - 1), - nullptr); - float4 lower_color; - image_reader_->read(lower_color, - clamp(x - i, 0, int(this->get_width()) - 1), - clamp(y - j, 0, int(this->get_height()) - 1), - nullptr); - float4 upper_color_squared = upper_color * upper_color; - float4 lower_color_squared = lower_color * lower_color; - - for (int k = 0; k < number_of_sectors; k++) { - float weight = sector_weights[k] * radial_gaussian_weight; - - /* Accumulate the pixel to each of the sectors multiplied by the sector weight. */ - int upper_index = k; - sum_of_weights_of_sectors[upper_index] += weight; - weighted_mean_of_color_of_sectors[upper_index] += upper_color * weight; - weighted_mean_of_squared_color_of_sectors[upper_index] += upper_color_squared * weight; - - /* Accumulate the mirrored pixel to each of the sectors multiplied by the sector weight. - */ - int lower_index = (k + number_of_sectors / 2) % number_of_sectors; - sum_of_weights_of_sectors[lower_index] += weight; - weighted_mean_of_color_of_sectors[lower_index] += lower_color * weight; - weighted_mean_of_squared_color_of_sectors[lower_index] += lower_color_squared * weight; - } - } - } - - /* Compute the weighted sum of mean of sectors, such that sectors with lower standard deviation - * gets more significant weight than sectors with higher standard deviation. */ - float sum_of_weights = 0.0f; - float4 weighted_sum = float4(0.0f); - for (int i = 0; i < number_of_sectors; i++) { - weighted_mean_of_color_of_sectors[i] /= sum_of_weights_of_sectors[i]; - weighted_mean_of_squared_color_of_sectors[i] /= sum_of_weights_of_sectors[i]; - - float4 color_mean = weighted_mean_of_color_of_sectors[i]; - float4 squared_color_mean = weighted_mean_of_squared_color_of_sectors[i]; - float4 color_variance = abs(squared_color_mean - color_mean * color_mean); - - float standard_deviation = dot(sqrt(color_variance.xyz()), float3(1.0)); - - /* Compute the sector weight based on the weight function introduced in section "3.3.1 - * Single-scale Filtering" of the multi-scale paper. Use a threshold of 0.02 to avoid zero - * division and avoid artifacts in homogeneous regions as demonstrated in the paper. */ - float weight = 1.0f / pow(max(0.02f, standard_deviation), get_sharpness()); - - sum_of_weights += weight; - weighted_sum += color_mean * weight; - } - weighted_sum /= sum_of_weights; - - copy_v4_v4(output, weighted_sum); -} - /* An implementation of the Anisotropic Kuwahara filter described in the paper: * * Kyprianidis, Jan Eric, Henry Kang, and Jurgen Dollner. "Image and video abstraction by diff --git a/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.h b/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.h index 76b41c04cb9..69175c26c77 100644 --- a/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.h +++ b/source/blender/compositor/operations/COM_KuwaharaAnisotropicOperation.h @@ -11,18 +11,11 @@ namespace blender::compositor { class KuwaharaAnisotropicOperation : public MultiThreadedOperation { - SocketReader *image_reader_; - SocketReader *size_reader_; - SocketReader *structure_tensor_reader_; - public: NodeKuwaharaData data; KuwaharaAnisotropicOperation(); - void init_execution() override; - void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.cc b/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.cc index e6c693a90a8..665bac0e26a 100644 --- a/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.cc +++ b/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.cc @@ -15,81 +15,9 @@ KuwaharaAnisotropicStructureTensorOperation::KuwaharaAnisotropicStructureTensorO { this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - this->flags_.is_fullframe_operation = true; this->flags_.can_be_constant = true; } -void KuwaharaAnisotropicStructureTensorOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); -} - -void KuwaharaAnisotropicStructureTensorOperation::deinit_execution() -{ - image_reader_ = nullptr; -} - -/* Computes the structure tensor of the image using a Dirac delta window function as described in - * section "3.2 Local Structure Estimation" of the paper: - * - * Kyprianidis, Jan Eric. "Image and video abstraction by multi-scale anisotropic Kuwahara - * filtering." 2011. - * - * The structure tensor should then be smoothed using a Gaussian function to eliminate high - * frequency details. */ -void KuwaharaAnisotropicStructureTensorOperation::execute_pixel_sampled(float output[4], - float x_float, - float y_float, - PixelSampler /*sampler*/) -{ - using math::max, math::min, math::dot; - const int x = x_float; - const int y = y_float; - const int width = this->get_width(); - const int height = this->get_height(); - - /* The weight kernels of the filter optimized for rotational symmetry described in section "3.2.1 - * Gradient Calculation". */ - const float corner_weight = 0.182f; - const float center_weight = 1.0f - 2.0f * corner_weight; - - float4 input_color; - float3 x_partial_derivative = float3(0.0f); - image_reader_->read(input_color, max(0, x - 1), min(height - 1, y + 1), nullptr); - x_partial_derivative += input_color.xyz() * -corner_weight; - image_reader_->read(input_color, max(0, x - 1), y, nullptr); - x_partial_derivative += input_color.xyz() * -center_weight; - image_reader_->read(input_color, max(0, x - 1), max(0, y - 1), nullptr); - x_partial_derivative += input_color.xyz() * -corner_weight; - image_reader_->read(input_color, min(width, x + 1), min(height - 1, y + 1), nullptr); - x_partial_derivative += input_color.xyz() * corner_weight; - image_reader_->read(input_color, min(width, x + 1), y, nullptr); - x_partial_derivative += input_color.xyz() * center_weight; - image_reader_->read(input_color, min(width, x + 1), max(0, y - 1), nullptr); - x_partial_derivative += input_color.xyz() * corner_weight; - - float3 y_partial_derivative = float3(0.0f); - image_reader_->read(input_color, max(0, x - 1), min(height - 1, y + 1), nullptr); - y_partial_derivative += input_color.xyz() * corner_weight; - image_reader_->read(input_color, x, min(height - 1, y + 1), nullptr); - y_partial_derivative += input_color.xyz() * center_weight; - image_reader_->read(input_color, min(width, x + 1), min(height - 1, y + 1), nullptr); - y_partial_derivative += input_color.xyz() * corner_weight; - image_reader_->read(input_color, max(0, x - 1), max(0, y - 1), nullptr); - y_partial_derivative += input_color.xyz() * -corner_weight; - image_reader_->read(input_color, x, max(0, y - 1), nullptr); - y_partial_derivative += input_color.xyz() * -center_weight; - image_reader_->read(input_color, min(width, x + 1), max(0, y - 1), nullptr); - y_partial_derivative += input_color.xyz() * -corner_weight; - - /* We encode the structure tensor in a float4 using a column major storage order. */ - float4 structure_tensor = float4(dot(x_partial_derivative, x_partial_derivative), - dot(x_partial_derivative, y_partial_derivative), - dot(x_partial_derivative, y_partial_derivative), - dot(y_partial_derivative, y_partial_derivative)); - copy_v4_v4(output, structure_tensor); -} - /* Computes the structure tensor of the image using a Dirac delta window function as described in * section "3.2 Local Structure Estimation" of the paper: * diff --git a/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.h b/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.h index 2a76cfd3e7e..5a8f6069e10 100644 --- a/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.h +++ b/source/blender/compositor/operations/COM_KuwaharaAnisotropicStructureTensorOperation.h @@ -9,14 +9,9 @@ namespace blender::compositor { class KuwaharaAnisotropicStructureTensorOperation : public MultiThreadedOperation { - SocketReader *image_reader_; - public: KuwaharaAnisotropicStructureTensorOperation(); - void init_execution() override; - void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_KuwaharaClassicOperation.cc b/source/blender/compositor/operations/COM_KuwaharaClassicOperation.cc index 856d9562518..a325cd715e3 100644 --- a/source/blender/compositor/operations/COM_KuwaharaClassicOperation.cc +++ b/source/blender/compositor/operations/COM_KuwaharaClassicOperation.cc @@ -19,135 +19,9 @@ KuwaharaClassicOperation::KuwaharaClassicOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - this->flags_.is_fullframe_operation = true; this->flags_.can_be_constant = true; } -void KuwaharaClassicOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); - size_reader_ = this->get_input_socket_reader(1); - sat_reader_ = this->get_input_socket_reader(2); - sat_squared_reader_ = this->get_input_socket_reader(3); -} - -void KuwaharaClassicOperation::deinit_execution() -{ - image_reader_ = nullptr; - size_reader_ = nullptr; - sat_reader_ = nullptr; - sat_squared_reader_ = nullptr; -} - -void KuwaharaClassicOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float4 mean_of_color[] = {float4(0.0f), float4(0.0f), float4(0.0f), float4(0.0f)}; - float4 mean_of_squared_color[] = {float4(0.0f), float4(0.0f), float4(0.0f), float4(0.0f)}; - int quadrant_pixel_count[] = {0, 0, 0, 0}; - - float4 size; - size_reader_->read_sampled(size, x, y, sampler); - const int kernel_size = int(math::max(0.0f, size[0])); - - /* For high radii, we accelerate the filter using a summed area table, making the filter - * execute in constant time as opposed to having quadratic complexity. Except if high precision - * is enabled, since summed area tables are less precise. */ - if (!data_->high_precision && size[0] > 5.0f) { - for (int q = 0; q < 4; q++) { - /* A fancy expression to compute the sign of the quadrant q. */ - int2 sign = int2((q % 2) * 2 - 1, ((q / 2) * 2 - 1)); - - int2 lower_bound = int2(x, y) - - int2(sign.x > 0 ? 0 : kernel_size, sign.y > 0 ? 0 : kernel_size); - int2 upper_bound = int2(x, y) + - int2(sign.x < 0 ? 0 : kernel_size, sign.y < 0 ? 0 : kernel_size); - - /* Limit the quadrants to the image bounds. */ - int2 image_bound = int2(this->get_width(), this->get_height()) - int2(1); - int2 corrected_lower_bound = math::min(image_bound, math::max(int2(0, 0), lower_bound)); - int2 corrected_upper_bound = math::min(image_bound, math::max(int2(0, 0), upper_bound)); - int2 region_size = corrected_upper_bound - corrected_lower_bound + int2(1, 1); - quadrant_pixel_count[q] = region_size.x * region_size.y; - - rcti kernel_area; - kernel_area.xmin = corrected_lower_bound[0]; - kernel_area.ymin = corrected_lower_bound[1]; - kernel_area.xmax = corrected_upper_bound[0]; - kernel_area.ymax = corrected_upper_bound[1]; - - mean_of_color[q] = summed_area_table_sum_tiled(sat_reader_, kernel_area); - mean_of_squared_color[q] = summed_area_table_sum_tiled(sat_squared_reader_, kernel_area); - } - } - else { - /* Split surroundings of pixel into 4 overlapping regions. */ - for (int dy = -kernel_size; dy <= kernel_size; dy++) { - for (int dx = -kernel_size; dx <= kernel_size; dx++) { - - int xx = x + dx; - int yy = y + dy; - if (xx < 0 || yy < 0 || xx >= this->get_width() || yy >= this->get_height()) { - continue; - } - - float4 color; - image_reader_->read_sampled(color, xx, yy, sampler); - - if (dx >= 0 && dy >= 0) { - const int quadrant_index = 0; - mean_of_color[quadrant_index] += color; - mean_of_squared_color[quadrant_index] += color * color; - quadrant_pixel_count[quadrant_index]++; - } - - if (dx <= 0 && dy >= 0) { - const int quadrant_index = 1; - mean_of_color[quadrant_index] += color; - mean_of_squared_color[quadrant_index] += color * color; - quadrant_pixel_count[quadrant_index]++; - } - - if (dx <= 0 && dy <= 0) { - const int quadrant_index = 2; - mean_of_color[quadrant_index] += color; - mean_of_squared_color[quadrant_index] += color * color; - quadrant_pixel_count[quadrant_index]++; - } - - if (dx >= 0 && dy <= 0) { - const int quadrant_index = 3; - mean_of_color[quadrant_index] += color; - mean_of_squared_color[quadrant_index] += color * color; - quadrant_pixel_count[quadrant_index]++; - } - } - } - } - - /* Choose the region with lowest variance. */ - float min_var = FLT_MAX; - int min_index = 0; - for (int i = 0; i < 4; i++) { - mean_of_color[i] /= quadrant_pixel_count[i]; - mean_of_squared_color[i] /= quadrant_pixel_count[i]; - float4 color_variance = mean_of_squared_color[i] - mean_of_color[i] * mean_of_color[i]; - - float variance = math::dot(color_variance.xyz(), float3(1.0f)); - if (variance < min_var) { - min_var = variance; - min_index = i; - } - } - - output[0] = mean_of_color[min_index].x; - output[1] = mean_of_color[min_index].y; - output[2] = mean_of_color[min_index].z; - output[3] = mean_of_color[min_index].w; /* Also apply filter to alpha channel. */ -} - void KuwaharaClassicOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_KuwaharaClassicOperation.h b/source/blender/compositor/operations/COM_KuwaharaClassicOperation.h index 2b049036b7a..2627ee0b15f 100644 --- a/source/blender/compositor/operations/COM_KuwaharaClassicOperation.h +++ b/source/blender/compositor/operations/COM_KuwaharaClassicOperation.h @@ -10,10 +10,6 @@ namespace blender::compositor { class KuwaharaClassicOperation : public MultiThreadedOperation { const NodeKuwaharaData *data_; - SocketReader *image_reader_; - SocketReader *size_reader_; - SocketReader *sat_reader_; - SocketReader *sat_squared_reader_; public: KuwaharaClassicOperation(); @@ -23,10 +19,6 @@ class KuwaharaClassicOperation : public MultiThreadedOperation { data_ = data; } - void init_execution() override; - void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc index 99f90946ae0..bb84cd6c3b6 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cc @@ -13,58 +13,9 @@ LuminanceMatteOperation::LuminanceMatteOperation() add_input_socket(DataType::Color); add_output_socket(DataType::Value); - input_image_program_ = nullptr; flags_.can_be_constant = true; } -void LuminanceMatteOperation::init_execution() -{ - input_image_program_ = this->get_input_socket_reader(0); -} - -void LuminanceMatteOperation::deinit_execution() -{ - input_image_program_ = nullptr; -} - -void LuminanceMatteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float in_color[4]; - input_image_program_->read_sampled(in_color, x, y, sampler); - - const float high = settings_->t1; - const float low = settings_->t2; - const float luminance = IMB_colormanagement_get_luminance(in_color); - - float alpha; - - /* one line thread-friend algorithm: - * output[0] = std::min(input_value[3], std::min(1.0f, std::max(0.0f, ((luminance - low) / (high - * - low)))); - */ - - /* test range */ - if (luminance > high) { - alpha = 1.0f; - } - else if (luminance < low) { - alpha = 0.0f; - } - else { /* Blend. */ - alpha = (luminance - low) / (high - low); - } - - /* Store matte(alpha) value in [0] to go with - * COM_SetAlphaMultiplyOperation and the Value output. - */ - - /* don't make something that was more transparent less transparent */ - output[0] = min_ff(alpha, in_color[3]); -} - void LuminanceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h index 5ceeb6c70f5..31e56c2448b 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h @@ -15,7 +15,6 @@ namespace blender::compositor { class LuminanceMatteOperation : public MultiThreadedOperation { private: NodeChroma *settings_; - SocketReader *input_image_program_; public: /** @@ -23,14 +22,6 @@ class LuminanceMatteOperation : public MultiThreadedOperation { */ LuminanceMatteOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void set_settings(NodeChroma *node_chroma) { settings_ = node_chroma; diff --git a/source/blender/compositor/operations/COM_MapRangeOperation.cc b/source/blender/compositor/operations/COM_MapRangeOperation.cc index 2d04616b7d0..781df2ca46c 100644 --- a/source/blender/compositor/operations/COM_MapRangeOperation.cc +++ b/source/blender/compositor/operations/COM_MapRangeOperation.cc @@ -14,83 +14,14 @@ MapRangeOperation::MapRangeOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_operation_ = nullptr; use_clamp_ = false; flags_.can_be_constant = true; } -void MapRangeOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); - source_min_operation_ = this->get_input_socket_reader(1); - source_max_operation_ = this->get_input_socket_reader(2); - dest_min_operation_ = this->get_input_socket_reader(3); - dest_max_operation_ = this->get_input_socket_reader(4); -} - /* The code below assumes all data is inside range +- this, and that input buffer is single channel */ #define BLENDER_ZMAX 10000.0f -void MapRangeOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float inputs[8]; /* includes the 5 inputs + 3 pads */ - float value; - float source_min, source_max; - float dest_min, dest_max; - - input_operation_->read_sampled(inputs, x, y, sampler); - source_min_operation_->read_sampled(inputs + 1, x, y, sampler); - source_max_operation_->read_sampled(inputs + 2, x, y, sampler); - dest_min_operation_->read_sampled(inputs + 3, x, y, sampler); - dest_max_operation_->read_sampled(inputs + 4, x, y, sampler); - - value = inputs[0]; - source_min = inputs[1]; - source_max = inputs[2]; - dest_min = inputs[3]; - dest_max = inputs[4]; - - if (fabsf(source_max - source_min) < 1e-6f) { - output[0] = 0.0f; - return; - } - - if (value >= -BLENDER_ZMAX && value <= BLENDER_ZMAX) { - value = (value - source_min) / (source_max - source_min); - value = dest_min + value * (dest_max - dest_min); - } - else if (value > BLENDER_ZMAX) { - value = dest_max; - } - else { - value = dest_min; - } - - if (use_clamp_) { - if (dest_max > dest_min) { - CLAMP(value, dest_min, dest_max); - } - else { - CLAMP(value, dest_max, dest_min); - } - } - - output[0] = value; -} - -void MapRangeOperation::deinit_execution() -{ - input_operation_ = nullptr; - source_min_operation_ = nullptr; - source_max_operation_ = nullptr; - dest_min_operation_ = nullptr; - dest_max_operation_ = nullptr; -} - void MapRangeOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_MapRangeOperation.h b/source/blender/compositor/operations/COM_MapRangeOperation.h index 214b00812e5..c4dfb823233 100644 --- a/source/blender/compositor/operations/COM_MapRangeOperation.h +++ b/source/blender/compositor/operations/COM_MapRangeOperation.h @@ -15,15 +15,6 @@ namespace blender::compositor { */ class MapRangeOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_operation_; - SocketReader *source_min_operation_; - SocketReader *source_max_operation_; - SocketReader *dest_min_operation_; - SocketReader *dest_max_operation_; - bool use_clamp_; public: @@ -32,21 +23,6 @@ class MapRangeOperation : public MultiThreadedOperation { */ MapRangeOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - /** * Clamp the output */ diff --git a/source/blender/compositor/operations/COM_MapUVOperation.cc b/source/blender/compositor/operations/COM_MapUVOperation.cc index a9e8e50f260..556c23cedd0 100644 --- a/source/blender/compositor/operations/COM_MapUVOperation.cc +++ b/source/blender/compositor/operations/COM_MapUVOperation.cc @@ -13,12 +13,8 @@ MapUVOperation::MapUVOperation() this->add_output_socket(DataType::Color); alpha_ = 0.0f; nearest_neighbour_ = false; - flags_.complex = true; flags_.can_be_constant = true; set_canvas_input_index(UV_INPUT_INDEX); - - inputUVProgram_ = nullptr; - input_color_program_ = nullptr; } void MapUVOperation::init_data() @@ -32,61 +28,6 @@ void MapUVOperation::init_data() uv_height_ = uv_input->get_height(); } -void MapUVOperation::init_execution() -{ - input_color_program_ = this->get_input_socket_reader(0); - inputUVProgram_ = this->get_input_socket_reader(1); - if (execution_model_ == eExecutionModel::Tiled) { - uv_input_read_fn_ = [=](float x, float y, float *out) { - inputUVProgram_->read_sampled(out, x, y, PixelSampler::Bilinear); - }; - } -} - -void MapUVOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - float xy[2] = {x, y}; - float uv[2], deriv[2][2], alpha; - - pixel_transform(xy, uv, deriv, alpha); - if (alpha == 0.0f) { - zero_v4(output); - return; - } - - if (nearest_neighbour_) { - input_color_program_->read_sampled(output, uv[0], uv[1], PixelSampler::Nearest); - } - else { - /* EWA filtering */ - input_color_program_->read_filtered(output, uv[0], uv[1], deriv[0], deriv[1]); - - /* UV to alpha threshold */ - const float threshold = alpha_ * 0.05f; - /* XXX alpha threshold is used to fade out pixels on boundaries with invalid derivatives. - * this calculation is not very well defined, should be looked into if it becomes a problem ... - */ - float du = len_v2(deriv[0]); - float dv = len_v2(deriv[1]); - float factor = 1.0f - threshold * (du / input_color_program_->get_width() + - dv / input_color_program_->get_height()); - if (factor < 0.0f) { - alpha = 0.0f; - } - else { - alpha *= factor; - } - } - - /* "premul" */ - if (alpha < 1.0f) { - mul_v4_fl(output, alpha); - } -} - bool MapUVOperation::read_uv(float x, float y, float &r_u, float &r_v, float &r_alpha) { if (x < 0.0f || x >= uv_width_ || y < 0.0f || y >= uv_height_) { @@ -155,43 +96,6 @@ void MapUVOperation::pixel_transform(const float xy[2], } } -void MapUVOperation::deinit_execution() -{ - inputUVProgram_ = nullptr; - input_color_program_ = nullptr; -} - -bool MapUVOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti color_input; - rcti uv_input; - NodeOperation *operation = nullptr; - - /* the uv buffer only needs a 3x3 buffer. The image needs whole buffer */ - - operation = get_input_operation(0); - color_input.xmax = operation->get_width(); - color_input.xmin = 0; - color_input.ymax = operation->get_height(); - color_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&color_input, read_operation, output)) { - return true; - } - - operation = get_input_operation(1); - uv_input.xmax = input->xmax + 1; - uv_input.xmin = input->xmin - 1; - uv_input.ymax = input->ymax + 1; - uv_input.ymin = input->ymin - 1; - if (operation->determine_depending_area_of_interest(&uv_input, read_operation, output)) { - return true; - } - - return false; -} - void MapUVOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_MapUVOperation.h b/source/blender/compositor/operations/COM_MapUVOperation.h index a20b09dc00e..ca86af65407 100644 --- a/source/blender/compositor/operations/COM_MapUVOperation.h +++ b/source/blender/compositor/operations/COM_MapUVOperation.h @@ -12,11 +12,6 @@ class MapUVOperation : public MultiThreadedOperation { private: static constexpr int IMAGE_INPUT_INDEX = 0; static constexpr int UV_INPUT_INDEX = 1; - /** - * Cached reference to the input_program - */ - SocketReader *inputUVProgram_; - SocketReader *input_color_program_; int uv_width_; int uv_height_; @@ -30,32 +25,10 @@ class MapUVOperation : public MultiThreadedOperation { public: MapUVOperation(); - /** - * we need a 3x3 differential filter for UV Input and full buffer for the image - */ - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void pixel_transform(const float xy[2], float r_uv[2], float r_deriv[2][2], float &r_alpha); void init_data() override; - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_alpha(float alpha) { alpha_ = alpha; diff --git a/source/blender/compositor/operations/COM_MapValueOperation.cc b/source/blender/compositor/operations/COM_MapValueOperation.cc index 09eda657142..cb385711baa 100644 --- a/source/blender/compositor/operations/COM_MapValueOperation.cc +++ b/source/blender/compositor/operations/COM_MapValueOperation.cc @@ -10,43 +10,9 @@ MapValueOperation::MapValueOperation() { this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_operation_ = nullptr; flags_.can_be_constant = true; } -void MapValueOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void MapValueOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float src[4]; - input_operation_->read_sampled(src, x, y, sampler); - const TexMapping *texmap = settings_; - float value = (src[0] + texmap->loc[0]) * texmap->size[0]; - if (texmap->flag & TEXMAP_CLIP_MIN) { - if (value < texmap->min[0]) { - value = texmap->min[0]; - } - } - if (texmap->flag & TEXMAP_CLIP_MAX) { - if (value > texmap->max[0]) { - value = texmap->max[0]; - } - } - - output[0] = value; -} - -void MapValueOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - void MapValueOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_MapValueOperation.h b/source/blender/compositor/operations/COM_MapValueOperation.h index 2bcc077c659..26ed2ed466d 100644 --- a/source/blender/compositor/operations/COM_MapValueOperation.h +++ b/source/blender/compositor/operations/COM_MapValueOperation.h @@ -15,33 +15,11 @@ namespace blender::compositor { */ class MapValueOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_operation_; const TexMapping *settings_; public: - /** - * Default constructor - */ MapValueOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - /** * \brief set the TexMapping settings */ diff --git a/source/blender/compositor/operations/COM_MaskOperation.cc b/source/blender/compositor/operations/COM_MaskOperation.cc index 9496f153490..545ef9e8936 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cc +++ b/source/blender/compositor/operations/COM_MaskOperation.cc @@ -94,39 +94,6 @@ void MaskOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) } } -void MaskOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - const float xy[2] = { - (x * mask_width_inv_) + mask_px_ofs_[0], - (y * mask_height_inv_) + mask_px_ofs_[1], - }; - - if (raster_mask_handle_tot_ == 1) { - if (raster_mask_handles_[0]) { - output[0] = BKE_maskrasterize_handle_sample(raster_mask_handles_[0], xy); - } - else { - output[0] = 0.0f; - } - } - else { - /* In case loop below fails. */ - output[0] = 0.0f; - - for (uint i = 0; i < raster_mask_handle_tot_; i++) { - if (raster_mask_handles_[i]) { - output[0] += BKE_maskrasterize_handle_sample(raster_mask_handles_[i], xy); - } - } - - /* until we get better falloff */ - output[0] /= raster_mask_handle_tot_; - } -} - void MaskOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h index 498231771be..b79766ec53c 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.h +++ b/source/blender/compositor/operations/COM_MaskOperation.h @@ -90,8 +90,6 @@ class MaskOperation : public MultiThreadedOperation { frame_shutter_ = shutter; } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cc b/source/blender/compositor/operations/COM_MathBaseOperation.cc index 35cd7caf605..abe29702da0 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cc +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cc @@ -16,27 +16,10 @@ MathBaseOperation::MathBaseOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - input_value1_operation_ = nullptr; - input_value2_operation_ = nullptr; - input_value3_operation_ = nullptr; use_clamp_ = false; flags_.can_be_constant = true; } -void MathBaseOperation::init_execution() -{ - input_value1_operation_ = this->get_input_socket_reader(0); - input_value2_operation_ = this->get_input_socket_reader(1); - input_value3_operation_ = this->get_input_socket_reader(2); -} - -void MathBaseOperation::deinit_execution() -{ - input_value1_operation_ = nullptr; - input_value2_operation_ = nullptr; - input_value3_operation_ = nullptr; -} - void MathBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { NodeOperationInput *socket; @@ -52,13 +35,6 @@ void MathBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_are NodeOperation::determine_canvas(preferred_area, r_area); } -void MathBaseOperation::clamp_if_needed(float *color) -{ - if (use_clamp_) { - CLAMP(color[0], 0.0f, 1.0f); - } -} - void MathBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -67,75 +43,6 @@ void MathBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, update_memory_buffer_partial(it); } -void MathAddOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = input_value1[0] + input_value2[0]; - - clamp_if_needed(output); -} - -void MathSubtractOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = input_value1[0] - input_value2[0]; - - clamp_if_needed(output); -} - -void MathMultiplyOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = input_value1[0] * input_value2[0]; - - clamp_if_needed(output); -} - -void MathDivideOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value2[0] == 0) { /* We don't want to divide by zero. */ - output[0] = 0.0; - } - else { - output[0] = input_value1[0] / input_value2[0]; - } - - clamp_if_needed(output); -} - void MathDivideOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -144,22 +51,6 @@ void MathDivideOperation::update_memory_buffer_partial(BuffersIterator &i } } -void MathSineOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = sin(input_value1[0]); - - clamp_if_needed(output); -} - void MathSineOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -168,22 +59,6 @@ void MathSineOperation::update_memory_buffer_partial(BuffersIterator &it) } } -void MathCosineOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = cos(input_value1[0]); - - clamp_if_needed(output); -} - void MathCosineOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -192,22 +67,6 @@ void MathCosineOperation::update_memory_buffer_partial(BuffersIterator &i } } -void MathTangentOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = tan(input_value1[0]); - - clamp_if_needed(output); -} - void MathTangentOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -216,22 +75,6 @@ void MathTangentOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathHyperbolicSineOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = sinh(input_value1[0]); - - clamp_if_needed(output); -} - void MathHyperbolicSineOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -240,22 +83,6 @@ void MathHyperbolicSineOperation::update_memory_buffer_partial(BuffersIteratorread_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = cosh(input_value1[0]); - - clamp_if_needed(output); -} - void MathHyperbolicCosineOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -264,22 +91,6 @@ void MathHyperbolicCosineOperation::update_memory_buffer_partial(BuffersIterator } } -void MathHyperbolicTangentOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = tanh(input_value1[0]); - - clamp_if_needed(output); -} - void MathHyperbolicTangentOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -288,27 +99,6 @@ void MathHyperbolicTangentOperation::update_memory_buffer_partial(BuffersIterato } } -void MathArcSineOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value1[0] <= 1 && input_value1[0] >= -1) { - output[0] = asin(input_value1[0]); - } - else { - output[0] = 0.0; - } - - clamp_if_needed(output); -} - void MathArcSineOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -317,27 +107,6 @@ void MathArcSineOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathArcCosineOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value1[0] <= 1 && input_value1[0] >= -1) { - output[0] = acos(input_value1[0]); - } - else { - output[0] = 0.0; - } - - clamp_if_needed(output); -} - void MathArcCosineOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -346,22 +115,6 @@ void MathArcCosineOperation::update_memory_buffer_partial(BuffersIterator } } -void MathArcTangentOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = atan(input_value1[0]); - - clamp_if_needed(output); -} - void MathArcTangentOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -370,34 +123,6 @@ void MathArcTangentOperation::update_memory_buffer_partial(BuffersIteratorread_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value1[0] >= 0) { - output[0] = pow(input_value1[0], input_value2[0]); - } - else { - float y_mod_1 = fmod(input_value2[0], 1); - /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ - if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { - output[0] = pow(input_value1[0], floorf(input_value2[0] + 0.5f)); - } - else { - output[0] = 0.0; - } - } - - clamp_if_needed(output); -} - void MathPowerOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -421,27 +146,6 @@ void MathPowerOperation::update_memory_buffer_partial(BuffersIterator &it } } -void MathLogarithmOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value1[0] > 0 && input_value2[0] > 0) { - output[0] = log(input_value1[0]) / log(input_value2[0]); - } - else { - output[0] = 0.0; - } - - clamp_if_needed(output); -} - void MathLogarithmOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -457,22 +161,6 @@ void MathLogarithmOperation::update_memory_buffer_partial(BuffersIterator } } -void MathMinimumOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = std::min(input_value1[0], input_value2[0]); - - clamp_if_needed(output); -} - void MathMinimumOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -481,22 +169,6 @@ void MathMinimumOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathMaximumOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = std::max(input_value1[0], input_value2[0]); - - clamp_if_needed(output); -} - void MathMaximumOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -505,22 +177,6 @@ void MathMaximumOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathRoundOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = round(input_value1[0]); - - clamp_if_needed(output); -} - void MathRoundOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -529,59 +185,6 @@ void MathRoundOperation::update_memory_buffer_partial(BuffersIterator &it } } -void MathLessThanOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = input_value1[0] < input_value2[0] ? 1.0f : 0.0f; - - clamp_if_needed(output); -} - -void MathGreaterThanOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = input_value1[0] > input_value2[0] ? 1.0f : 0.0f; - - clamp_if_needed(output); -} - -void MathModuloOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value2[0] == 0) { - output[0] = 0.0; - } - else { - output[0] = fmod(input_value1[0], input_value2[0]); - } - - clamp_if_needed(output); -} - void MathModuloOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -591,27 +194,6 @@ void MathModuloOperation::update_memory_buffer_partial(BuffersIterator &i } } -void MathFlooredModuloOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value2[0] == 0) { - output[0] = 0.0; - } - else { - output[0] = input_value1[0] - floorf(input_value1[0] / input_value2[0]) * input_value2[0]; - } - - clamp_if_needed(output); -} - void MathFlooredModuloOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -621,20 +203,6 @@ void MathFlooredModuloOperation::update_memory_buffer_partial(BuffersIteratorread_sampled(input_value1, x, y, sampler); - - output[0] = fabs(input_value1[0]); - - clamp_if_needed(output); -} - void MathAbsoluteOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -643,20 +211,6 @@ void MathAbsoluteOperation::update_memory_buffer_partial(BuffersIterator } } -void MathRadiansOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = DEG2RADF(input_value1[0]); - - clamp_if_needed(output); -} - void MathRadiansOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -665,20 +219,6 @@ void MathRadiansOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathDegreesOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = RAD2DEGF(input_value1[0]); - - clamp_if_needed(output); -} - void MathDegreesOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -687,22 +227,6 @@ void MathDegreesOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathArcTan2Operation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = atan2(input_value1[0], input_value2[0]); - - clamp_if_needed(output); -} - void MathArcTan2Operation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -711,20 +235,6 @@ void MathArcTan2Operation::update_memory_buffer_partial(BuffersIterator & } } -void MathFloorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = floor(input_value1[0]); - - clamp_if_needed(output); -} - void MathFloorOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -733,20 +243,6 @@ void MathFloorOperation::update_memory_buffer_partial(BuffersIterator &it } } -void MathCeilOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = ceil(input_value1[0]); - - clamp_if_needed(output); -} - void MathCeilOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -755,20 +251,6 @@ void MathCeilOperation::update_memory_buffer_partial(BuffersIterator &it) } } -void MathFractOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = input_value1[0] - floor(input_value1[0]); - - clamp_if_needed(output); -} - void MathFractOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -777,25 +259,6 @@ void MathFractOperation::update_memory_buffer_partial(BuffersIterator &it } } -void MathSqrtOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - if (input_value1[0] > 0) { - output[0] = sqrt(input_value1[0]); - } - else { - output[0] = 0.0f; - } - - clamp_if_needed(output); -} - void MathSqrtOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -804,25 +267,6 @@ void MathSqrtOperation::update_memory_buffer_partial(BuffersIterator &it) } } -void MathInverseSqrtOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - if (input_value1[0] > 0) { - output[0] = 1.0f / sqrt(input_value1[0]); - } - else { - output[0] = 0.0f; - } - - clamp_if_needed(output); -} - void MathInverseSqrtOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -831,20 +275,6 @@ void MathInverseSqrtOperation::update_memory_buffer_partial(BuffersIteratorread_sampled(input_value1, x, y, sampler); - - output[0] = compatible_signf(input_value1[0]); - - clamp_if_needed(output); -} - void MathSignOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -853,20 +283,6 @@ void MathSignOperation::update_memory_buffer_partial(BuffersIterator &it) } } -void MathExponentOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = expf(input_value1[0]); - - clamp_if_needed(output); -} - void MathExponentOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -875,20 +291,6 @@ void MathExponentOperation::update_memory_buffer_partial(BuffersIterator } } -void MathTruncOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - - output[0] = (input_value1[0] >= 0.0f) ? floor(input_value1[0]) : ceil(input_value1[0]); - - clamp_if_needed(output); -} - void MathTruncOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -898,27 +300,6 @@ void MathTruncOperation::update_memory_buffer_partial(BuffersIterator &it } } -void MathSnapOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - if (input_value1[0] == 0 || input_value2[0] == 0) { /* We don't want to divide by zero. */ - output[0] = 0.0f; - } - else { - output[0] = floorf(input_value1[0] / input_value2[0]) * input_value2[0]; - } - - clamp_if_needed(output); -} - void MathSnapOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -934,24 +315,6 @@ void MathSnapOperation::update_memory_buffer_partial(BuffersIterator &it) } } -void MathWrapOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - float input_value3[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - input_value3_operation_->read_sampled(input_value3, x, y, sampler); - - output[0] = wrapf(input_value1[0], input_value2[0], input_value3[0]); - - clamp_if_needed(output); -} - void MathWrapOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -960,22 +323,6 @@ void MathWrapOperation::update_memory_buffer_partial(BuffersIterator &it) } } -void MathPingpongOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - - output[0] = pingpongf(input_value1[0], input_value2[0]); - - clamp_if_needed(output); -} - void MathPingpongOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -984,26 +331,6 @@ void MathPingpongOperation::update_memory_buffer_partial(BuffersIterator } } -void MathCompareOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - float input_value3[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - input_value3_operation_->read_sampled(input_value3, x, y, sampler); - - output[0] = (fabsf(input_value1[0] - input_value2[0]) <= std::max(input_value3[0], 1e-5f)) ? - 1.0f : - 0.0f; - - clamp_if_needed(output); -} - void MathCompareOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -1012,24 +339,6 @@ void MathCompareOperation::update_memory_buffer_partial(BuffersIterator & } } -void MathMultiplyAddOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - float input_value3[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - input_value3_operation_->read_sampled(input_value3, x, y, sampler); - - output[0] = input_value1[0] * input_value2[0] + input_value3[0]; - - clamp_if_needed(output); -} - void MathMultiplyAddOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -1038,24 +347,6 @@ void MathMultiplyAddOperation::update_memory_buffer_partial(BuffersIteratorread_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - input_value3_operation_->read_sampled(input_value3, x, y, sampler); - - output[0] = smoothminf(input_value1[0], input_value2[0], input_value3[0]); - - clamp_if_needed(output); -} - void MathSmoothMinOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { @@ -1064,24 +355,6 @@ void MathSmoothMinOperation::update_memory_buffer_partial(BuffersIterator } } -void MathSmoothMaxOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value1[4]; - float input_value2[4]; - float input_value3[4]; - - input_value1_operation_->read_sampled(input_value1, x, y, sampler); - input_value2_operation_->read_sampled(input_value2, x, y, sampler); - input_value3_operation_->read_sampled(input_value3, x, y, sampler); - - output[0] = -smoothminf(-input_value1[0], -input_value2[0], input_value3[0]); - - clamp_if_needed(output); -} - void MathSmoothMaxOperation::update_memory_buffer_partial(BuffersIterator &it) { for (; !it.is_end(); ++it) { diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h index 6d96e53d645..d59ec3b579d 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.h +++ b/source/blender/compositor/operations/COM_MathBaseOperation.h @@ -14,24 +14,11 @@ namespace blender::compositor { */ class MathBaseOperation : public MultiThreadedOperation { protected: - /** - * Prefetched reference to the input_program - */ - SocketReader *input_value1_operation_; - SocketReader *input_value2_operation_; - SocketReader *input_value3_operation_; - bool use_clamp_; protected: - /** - * Default constructor - */ MathBaseOperation(); - /* TODO(manzanilla): to be removed with tiled implementation. */ - void clamp_if_needed(float color[4]); - float clamp_when_enabled(float value) { if (use_clamp_) { @@ -48,16 +35,6 @@ class MathBaseOperation : public MultiThreadedOperation { } public: - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - /** * Determine resolution */ @@ -88,298 +65,175 @@ class MathFunctor2Operation : public MathBaseOperation { } }; -class MathAddOperation : public MathFunctor2Operation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; -}; -class MathSubtractOperation : public MathFunctor2Operation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; -}; -class MathMultiplyOperation : public MathFunctor2Operation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; -}; +class MathAddOperation : public MathFunctor2Operation {}; +class MathSubtractOperation : public MathFunctor2Operation {}; +class MathMultiplyOperation : public MathFunctor2Operation {}; class MathDivideOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathSineOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathCosineOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathTangentOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathHyperbolicSineOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathHyperbolicCosineOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathHyperbolicTangentOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathArcSineOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathArcCosineOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathArcTangentOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathPowerOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathLogarithmOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathMinimumOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathMaximumOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathRoundOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; -class MathLessThanOperation : public MathFunctor2Operation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; -}; -class MathGreaterThanOperation : public MathFunctor2Operation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; -}; +class MathLessThanOperation : public MathFunctor2Operation {}; +class MathGreaterThanOperation : public MathFunctor2Operation {}; class MathModuloOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathFlooredModuloOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathAbsoluteOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathRadiansOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathDegreesOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathArcTan2Operation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathFloorOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathCeilOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathFractOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathSqrtOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathInverseSqrtOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathSignOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathExponentOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathTruncOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathSnapOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathWrapOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathPingpongOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathCompareOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathMultiplyAddOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathSmoothMinOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; class MathSmoothMaxOperation : public MathBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_partial(BuffersIterator &it) override; }; diff --git a/source/blender/compositor/operations/COM_MixOperation.cc b/source/blender/compositor/operations/COM_MixOperation.cc index a2a9bbd5e92..059d810aae9 100644 --- a/source/blender/compositor/operations/COM_MixOperation.cc +++ b/source/blender/compositor/operations/COM_MixOperation.cc @@ -16,45 +16,11 @@ MixBaseOperation::MixBaseOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - input_value_operation_ = nullptr; - input_color1_operation_ = nullptr; - input_color2_operation_ = nullptr; this->set_use_value_alpha_multiply(false); this->set_use_clamp(false); flags_.can_be_constant = true; } -void MixBaseOperation::init_execution() -{ - input_value_operation_ = this->get_input_socket_reader(0); - input_color1_operation_ = this->get_input_socket_reader(1); - input_color2_operation_ = this->get_input_socket_reader(2); -} - -void MixBaseOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = valuem * (input_color1[0]) + value * (input_color2[0]); - output[1] = valuem * (input_color1[1]) + value * (input_color2[1]); - output[2] = valuem * (input_color1[2]) + value * (input_color2[2]); - output[3] = input_color1[3]; -} - void MixBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { NodeOperationInput *socket; @@ -78,13 +44,6 @@ void MixBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_area NodeOperation::determine_canvas(preferred_area, r_area); } -void MixBaseOperation::deinit_execution() -{ - input_value_operation_ = nullptr; - input_color1_operation_ = nullptr; - input_color2_operation_ = nullptr; -} - void MixBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -126,31 +85,6 @@ void MixBaseOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Add Operation ******** */ -void MixAddOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - output[0] = input_color1[0] + value * input_color2[0]; - output[1] = input_color1[1] + value * input_color2[1]; - output[2] = input_color1[2] + value * input_color2[2]; - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixAddOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -170,33 +104,6 @@ void MixAddOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Blend Operation ******** */ -void MixBlendOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - float value; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - value = input_value[0]; - - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = valuem * (input_color1[0]) + value * (input_color2[0]); - output[1] = valuem * (input_color1[1]) + value * (input_color2[1]); - output[2] = valuem * (input_color1[2]) + value * (input_color2[2]); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixBlendOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -217,82 +124,6 @@ void MixBlendOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Burn Operation ******** */ -void MixColorBurnOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - float tmp; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - tmp = valuem + value * input_color2[0]; - if (tmp <= 0.0f) { - output[0] = 0.0f; - } - else { - tmp = 1.0f - (1.0f - input_color1[0]) / tmp; - if (tmp < 0.0f) { - output[0] = 0.0f; - } - else if (tmp > 1.0f) { - output[0] = 1.0f; - } - else { - output[0] = tmp; - } - } - - tmp = valuem + value * input_color2[1]; - if (tmp <= 0.0f) { - output[1] = 0.0f; - } - else { - tmp = 1.0f - (1.0f - input_color1[1]) / tmp; - if (tmp < 0.0f) { - output[1] = 0.0f; - } - else if (tmp > 1.0f) { - output[1] = 1.0f; - } - else { - output[1] = tmp; - } - } - - tmp = valuem + value * input_color2[2]; - if (tmp <= 0.0f) { - output[2] = 0.0f; - } - else { - tmp = 1.0f - (1.0f - input_color1[2]) / tmp; - if (tmp < 0.0f) { - output[2] = 0.0f; - } - else if (tmp > 1.0f) { - output[2] = 1.0f; - } - else { - output[2] = tmp; - } - } - - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixColorBurnOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -337,44 +168,6 @@ void MixColorBurnOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Color Operation ******** */ -void MixColorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - float colH, colS, colV; - rgb_to_hsv(input_color2[0], input_color2[1], input_color2[2], &colH, &colS, &colV); - if (colS != 0.0f) { - float rH, rS, rV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(input_color1[0], input_color1[1], input_color1[2], &rH, &rS, &rV); - hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb); - output[0] = (valuem * input_color1[0]) + (value * tmpr); - output[1] = (valuem * input_color1[1]) + (value * tmpg); - output[2] = (valuem * input_color1[2]) + (value * tmpb); - } - else { - copy_v3_v3(output, input_color1); - } - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixColorOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -407,32 +200,6 @@ void MixColorOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Darken Operation ******** */ -void MixDarkenOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = min_ff(input_color1[0], input_color2[0]) * value + input_color1[0] * valuem; - output[1] = min_ff(input_color1[1], input_color2[1]) * value + input_color1[1] * valuem; - output[2] = min_ff(input_color1[2], input_color2[2]) * value + input_color1[2] * valuem; - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixDarkenOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -453,32 +220,6 @@ void MixDarkenOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Difference Operation ******** */ -void MixDifferenceOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = valuem * input_color1[0] + value * fabsf(input_color1[0] - input_color2[0]); - output[1] = valuem * input_color1[1] + value * fabsf(input_color1[1] - input_color2[1]); - output[2] = valuem * input_color1[2] + value * fabsf(input_color1[2] - input_color2[2]); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixDifferenceOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -499,38 +240,6 @@ void MixDifferenceOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Exclusion Operation ******** */ -void MixExclusionOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = max_ff(valuem * input_color1[0] + value * (input_color1[0] + input_color2[0] - - 2.0f * input_color1[0] * input_color2[0]), - 0.0f); - output[1] = max_ff(valuem * input_color1[1] + value * (input_color1[1] + input_color2[1] - - 2.0f * input_color1[1] * input_color2[1]), - 0.0f); - output[2] = max_ff(valuem * input_color1[2] + value * (input_color1[2] + input_color2[2] - - 2.0f * input_color1[2] * input_color2[2]), - 0.0f); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixExclusionOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -557,49 +266,6 @@ void MixExclusionOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Divide Operation ******** */ -void MixDivideOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - if (input_color2[0] != 0.0f) { - output[0] = valuem * (input_color1[0]) + value * (input_color1[0]) / input_color2[0]; - } - else { - output[0] = 0.0f; - } - if (input_color2[1] != 0.0f) { - output[1] = valuem * (input_color1[1]) + value * (input_color1[1]) / input_color2[1]; - } - else { - output[1] = 0.0f; - } - if (input_color2[2] != 0.0f) { - output[2] = valuem * (input_color1[2]) + value * (input_color1[2]) / input_color2[2]; - } - else { - output[2] = 0.0f; - } - - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixDivideOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -637,87 +303,6 @@ void MixDivideOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Dodge Operation ******** */ -void MixDodgeOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - float tmp; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - - if (input_color1[0] != 0.0f) { - tmp = 1.0f - value * input_color2[0]; - if (tmp <= 0.0f) { - output[0] = 1.0f; - } - else { - tmp = input_color1[0] / tmp; - if (tmp > 1.0f) { - output[0] = 1.0f; - } - else { - output[0] = tmp; - } - } - } - else { - output[0] = 0.0f; - } - - if (input_color1[1] != 0.0f) { - tmp = 1.0f - value * input_color2[1]; - if (tmp <= 0.0f) { - output[1] = 1.0f; - } - else { - tmp = input_color1[1] / tmp; - if (tmp > 1.0f) { - output[1] = 1.0f; - } - else { - output[1] = tmp; - } - } - } - else { - output[1] = 0.0f; - } - - if (input_color1[2] != 0.0f) { - tmp = 1.0f - value * input_color2[2]; - if (tmp <= 0.0f) { - output[2] = 1.0f; - } - else { - tmp = input_color1[2] / tmp; - if (tmp > 1.0f) { - output[2] = 1.0f; - } - else { - output[2] = tmp; - } - } - } - else { - output[2] = 0.0f; - } - - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixDodgeOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -778,39 +363,6 @@ void MixDodgeOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Glare Operation ******** */ -void MixGlareOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - float value, input_weight, glare_weight; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - value = input_value[0]; - /* Linear interpolation between 3 cases: - * value=-1:output=input value=0:output=input+glare value=1:output=glare - */ - if (value < 0.0f) { - input_weight = 1.0f; - glare_weight = 1.0f + value; - } - else { - input_weight = 1.0f - value; - glare_weight = 1.0f; - } - output[0] = input_weight * std::max(input_color1[0], 0.0f) + glare_weight * input_color2[0]; - output[1] = input_weight * std::max(input_color1[1], 0.0f) + glare_weight * input_color2[1]; - output[2] = input_weight * std::max(input_color1[2], 0.0f) + glare_weight * input_color2[2]; - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixGlareOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -840,44 +392,6 @@ void MixGlareOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Hue Operation ******** */ -void MixHueOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - float colH, colS, colV; - rgb_to_hsv(input_color2[0], input_color2[1], input_color2[2], &colH, &colS, &colV); - if (colS != 0.0f) { - float rH, rS, rV; - float tmpr, tmpg, tmpb; - rgb_to_hsv(input_color1[0], input_color1[1], input_color1[2], &rH, &rS, &rV); - hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); - output[0] = valuem * (input_color1[0]) + value * tmpr; - output[1] = valuem * (input_color1[1]) + value * tmpg; - output[2] = valuem * (input_color1[2]) + value * tmpb; - } - else { - copy_v3_v3(output, input_color1); - } - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixHueOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -910,32 +424,6 @@ void MixHueOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Lighten Operation ******** */ -void MixLightenOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = max_ff(input_color1[0], input_color2[0]) * value + input_color1[0] * valuem; - output[1] = max_ff(input_color1[1], input_color2[1]) * value + input_color1[1] * valuem; - output[2] = max_ff(input_color1[2], input_color2[2]) * value + input_color1[2] * valuem; - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixLightenOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -956,47 +444,6 @@ void MixLightenOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Linear Light Operation ******** */ -void MixLinearLightOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - if (input_color2[0] > 0.5f) { - output[0] = input_color1[0] + value * (2.0f * (input_color2[0] - 0.5f)); - } - else { - output[0] = input_color1[0] + value * (2.0f * (input_color2[0]) - 1.0f); - } - if (input_color2[1] > 0.5f) { - output[1] = input_color1[1] + value * (2.0f * (input_color2[1] - 0.5f)); - } - else { - output[1] = input_color1[1] + value * (2.0f * (input_color2[1]) - 1.0f); - } - if (input_color2[2] > 0.5f) { - output[2] = input_color1[2] + value * (2.0f * (input_color2[2] - 0.5f)); - } - else { - output[2] = input_color1[2] + value * (2.0f * (input_color2[2]) - 1.0f); - } - - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixLinearLightOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1032,32 +479,6 @@ void MixLinearLightOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Multiply Operation ******** */ -void MixMultiplyOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - output[0] = input_color1[0] * (valuem + value * input_color2[0]); - output[1] = input_color1[1] * (valuem + value * input_color2[1]); - output[2] = input_color1[2] * (valuem + value * input_color2[2]); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixMultiplyOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1079,52 +500,6 @@ void MixMultiplyOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Overlay Operation ******** */ -void MixOverlayOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - - float valuem = 1.0f - value; - - if (input_color1[0] < 0.5f) { - output[0] = input_color1[0] * (valuem + 2.0f * value * input_color2[0]); - } - else { - output[0] = 1.0f - - (valuem + 2.0f * value * (1.0f - input_color2[0])) * (1.0f - input_color1[0]); - } - if (input_color1[1] < 0.5f) { - output[1] = input_color1[1] * (valuem + 2.0f * value * input_color2[1]); - } - else { - output[1] = 1.0f - - (valuem + 2.0f * value * (1.0f - input_color2[1])) * (1.0f - input_color1[1]); - } - if (input_color1[2] < 0.5f) { - output[2] = input_color1[2] * (valuem + 2.0f * value * input_color2[2]); - } - else { - output[2] = 1.0f - - (valuem + 2.0f * value * (1.0f - input_color2[2])) * (1.0f - input_color1[2]); - } - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixOverlayOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1161,41 +536,6 @@ void MixOverlayOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Saturation Operation ******** */ -void MixSaturationOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - float rH, rS, rV; - rgb_to_hsv(input_color1[0], input_color1[1], input_color1[2], &rH, &rS, &rV); - if (rS != 0.0f) { - float colH, colS, colV; - rgb_to_hsv(input_color2[0], input_color2[1], input_color2[2], &colH, &colS, &colV); - hsv_to_rgb(rH, (valuem * rS + value * colS), rV, &output[0], &output[1], &output[2]); - } - else { - copy_v3_v3(output, input_color1); - } - - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixSaturationOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1225,33 +565,6 @@ void MixSaturationOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Screen Operation ******** */ -void MixScreenOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - output[0] = 1.0f - (valuem + value * (1.0f - input_color2[0])) * (1.0f - input_color1[0]); - output[1] = 1.0f - (valuem + value * (1.0f - input_color2[1])) * (1.0f - input_color1[1]); - output[2] = 1.0f - (valuem + value * (1.0f - input_color2[2])) * (1.0f - input_color1[2]); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixScreenOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1273,45 +586,6 @@ void MixScreenOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Soft Light Operation ******** */ -void MixSoftLightOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - float scr, scg, scb; - - /* first calculate non-fac based Screen mix */ - scr = 1.0f - (1.0f - input_color2[0]) * (1.0f - input_color1[0]); - scg = 1.0f - (1.0f - input_color2[1]) * (1.0f - input_color1[1]); - scb = 1.0f - (1.0f - input_color2[2]) * (1.0f - input_color1[2]); - - output[0] = valuem * (input_color1[0]) + - value * (((1.0f - input_color1[0]) * input_color2[0] * (input_color1[0])) + - (input_color1[0] * scr)); - output[1] = valuem * (input_color1[1]) + - value * (((1.0f - input_color1[1]) * input_color2[1] * (input_color1[1])) + - (input_color1[1] * scg)); - output[2] = valuem * (input_color1[2]) + - value * (((1.0f - input_color1[2]) * input_color2[2] * (input_color1[2])) + - (input_color1[2] * scb)); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixSoftLightOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1342,31 +616,6 @@ void MixSoftLightOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Subtract Operation ******** */ -void MixSubtractOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - output[0] = input_color1[0] - value * (input_color2[0]); - output[1] = input_color1[1] - value * (input_color2[1]); - output[2] = input_color1[2] - value * (input_color2[2]); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixSubtractOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { @@ -1386,35 +635,6 @@ void MixSubtractOperation::update_memory_buffer_row(PixelCursor &p) /* ******** Mix Value Operation ******** */ -void MixValueOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_color1[4]; - float input_color2[4]; - float input_value[4]; - - input_value_operation_->read_sampled(input_value, x, y, sampler); - input_color1_operation_->read_sampled(input_color1, x, y, sampler); - input_color2_operation_->read_sampled(input_color2, x, y, sampler); - - float value = input_value[0]; - if (this->use_value_alpha_multiply()) { - value *= input_color2[3]; - } - float valuem = 1.0f - value; - - float rH, rS, rV; - float colH, colS, colV; - rgb_to_hsv(input_color1[0], input_color1[1], input_color1[2], &rH, &rS, &rV); - rgb_to_hsv(input_color2[0], input_color2[1], input_color2[2], &colH, &colS, &colV); - hsv_to_rgb(rH, rS, (valuem * rV + value * colV), &output[0], &output[1], &output[2]); - output[3] = input_color1[3]; - - clamp_if_needed(output); -} - void MixValueOperation::update_memory_buffer_row(PixelCursor &p) { while (p.out < p.row_end) { diff --git a/source/blender/compositor/operations/COM_MixOperation.h b/source/blender/compositor/operations/COM_MixOperation.h index 9f422faf0a6..7d6ebbb083e 100644 --- a/source/blender/compositor/operations/COM_MixOperation.h +++ b/source/blender/compositor/operations/COM_MixOperation.h @@ -35,12 +35,6 @@ class MixBaseOperation : public MultiThreadedOperation { } }; - /** - * Prefetched reference to the input_program - */ - SocketReader *input_value_operation_; - SocketReader *input_color1_operation_; - SocketReader *input_color2_operation_; bool value_alpha_multiply_; bool use_clamp_; @@ -52,26 +46,8 @@ class MixBaseOperation : public MultiThreadedOperation { } public: - /** - * Default constructor - */ MixBaseOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; void set_use_value_alpha_multiply(const bool value) @@ -96,161 +72,101 @@ class MixBaseOperation : public MultiThreadedOperation { }; class MixAddOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixBlendOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixColorBurnOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixColorOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixDarkenOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixDifferenceOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixExclusionOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixDivideOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixDodgeOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixGlareOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixHueOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixLightenOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixLinearLightOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixMultiplyOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixOverlayOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixSaturationOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixScreenOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixSoftLightOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixSubtractOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; class MixValueOperation : public MixBaseOperation { - public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - protected: void update_memory_buffer_row(PixelCursor &p) override; }; diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc index 7aad3c3ce31..4e3b2009b44 100644 --- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc +++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cc @@ -75,14 +75,6 @@ void MovieClipAttributeOperation::calc_value() } } -void MovieClipAttributeOperation::execute_pixel_sampled(float output[4], - float /*x*/, - float /*y*/, - PixelSampler /*sampler*/) -{ - output[0] = value_; -} - void MovieClipAttributeOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { r_area = preferred_area; diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h index 90969f6ff4b..13a8b3f29e6 100644 --- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h @@ -38,10 +38,6 @@ class MovieClipAttributeOperation : public ConstantOperation { void init_execution() override; - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; const float *get_constant_elem() override; diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cc b/source/blender/compositor/operations/COM_MovieClipOperation.cc index 1ea9f78e491..2485c4aea7e 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cc +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cc @@ -65,35 +65,6 @@ void MovieClipBaseOperation::determine_canvas(const rcti & /*preferred_area*/, r } } -void MovieClipBaseOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - ImBuf *ibuf = movie_clip_buffer_; - - if (ibuf == nullptr) { - zero_v4(output); - } - else if (ibuf->byte_buffer.data == nullptr && ibuf->float_buffer.data == nullptr) { - /* Happens for multi-layer EXR, i.e. */ - zero_v4(output); - } - else { - switch (sampler) { - case PixelSampler::Nearest: - imbuf::interpolate_nearest_fl(ibuf, output, x, y); - break; - case PixelSampler::Bilinear: - imbuf::interpolate_bilinear_border_fl(ibuf, output, x, y); - break; - case PixelSampler::Bicubic: - imbuf::interpolate_cubic_bspline_fl(ibuf, output, x, y); - break; - } - } -} - void MovieClipBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) @@ -116,16 +87,6 @@ MovieClipAlphaOperation::MovieClipAlphaOperation() : MovieClipBaseOperation() this->add_output_socket(DataType::Value); } -void MovieClipAlphaOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float result[4]; - MovieClipBaseOperation::execute_pixel_sampled(result, x, y, sampler); - output[0] = result[3]; -} - void MovieClipAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.h b/source/blender/compositor/operations/COM_MovieClipOperation.h index 007a4619c35..1df02a380f0 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipOperation.h @@ -51,7 +51,6 @@ class MovieClipBaseOperation : public MultiThreadedOperation { { framenumber_ = framenumber; } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -66,7 +65,6 @@ class MovieClipOperation : public MovieClipBaseOperation { class MovieClipAlphaOperation : public MovieClipBaseOperation { public: MovieClipAlphaOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.cc b/source/blender/compositor/operations/COM_MovieDistortionOperation.cc index 77b00de0c36..7bfc85e45d2 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.cc +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.cc @@ -15,7 +15,6 @@ MovieDistortionOperation::MovieDistortionOperation(bool distortion) this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_operation_ = nullptr; movie_clip_ = nullptr; apply_ = distortion; @@ -57,7 +56,6 @@ void MovieDistortionOperation::init_data() void MovieDistortionOperation::init_execution() { - input_operation_ = this->get_input_socket_reader(0); if (movie_clip_) { MovieTracking *tracking = &movie_clip_->tracking; distortion_ = BKE_tracking_distortion_new(tracking, calibration_width_, calibration_height_); @@ -69,66 +67,12 @@ void MovieDistortionOperation::init_execution() void MovieDistortionOperation::deinit_execution() { - input_operation_ = nullptr; movie_clip_ = nullptr; if (distortion_ != nullptr) { BKE_tracking_distortion_free(distortion_); } } -void MovieDistortionOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - const int width = this->get_width(); - const int height = this->get_height(); - if (distortion_ == nullptr || width == 0 || height == 0) { - /* When there is no precomputed distortion pass-through the coordinate as-is to the input - * samples. - * If the frame size is zero do the same and bypass any math. In theory it is probably more - * correct to zero the output but it is easier and safe to let the input to do so than to deal - * with possible different number of channels here. */ - input_operation_->read_sampled(output, x, y, PixelSampler::Bilinear); - return; - } - - // float overscan = 0.0f; - const float w = float(width) /* / (1 + overscan) */; - const float h = float(height) /* / (1 + overscan) */; - const float pixel_aspect = pixel_aspect_; - const float aspx = w / float(calibration_width_); - const float aspy = h / float(calibration_height_); - float in[2]; - float out[2]; - - in[0] = (x /* - 0.5 * overscan * w */) / aspx; - in[1] = (y /* - 0.5 * overscan * h */) / aspy / pixel_aspect; - - if (apply_) { - BKE_tracking_distortion_undistort_v2(distortion_, in, out); - } - else { - BKE_tracking_distortion_distort_v2(distortion_, in, out); - } - - float u = out[0] * aspx /* + 0.5 * overscan * w */, - v = (out[1] * aspy /* + 0.5 * overscan * h */) * pixel_aspect; - - input_operation_->read_sampled(output, u, v, PixelSampler::Bilinear); -} - -bool MovieDistortionOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - new_input.xmin = input->xmin - margin_[0]; - new_input.ymin = input->ymin - margin_[1]; - new_input.xmax = input->xmax + margin_[0]; - new_input.ymax = input->ymax + margin_[1]; - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void MovieDistortionOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.h b/source/blender/compositor/operations/COM_MovieDistortionOperation.h index 7f16ac77e05..2d1f9f94a6c 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.h +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.h @@ -14,7 +14,6 @@ namespace blender::compositor { class MovieDistortionOperation : public MultiThreadedOperation { private: - SocketReader *input_operation_; MovieClip *movie_clip_; int margin_[2]; @@ -28,7 +27,6 @@ class MovieDistortionOperation : public MultiThreadedOperation { public: MovieDistortionOperation(bool distortion); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void init_data() override; void init_execution() override; @@ -42,9 +40,6 @@ class MovieDistortionOperation : public MultiThreadedOperation { { framenumber_ = framenumber; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_MultilayerImageOperation.cc b/source/blender/compositor/operations/COM_MultilayerImageOperation.cc index b7e3fed43ef..6f3aa56c55d 100644 --- a/source/blender/compositor/operations/COM_MultilayerImageOperation.cc +++ b/source/blender/compositor/operations/COM_MultilayerImageOperation.cc @@ -76,82 +76,4 @@ std::unique_ptr MultilayerColorOperation::get_meta_data() return std::move(callback_data.meta_data); } -void MultilayerColorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - if (image_float_buffer_ == nullptr) { - zero_v4(output); - } - else { - if (number_of_channels_ == 4) { - switch (sampler) { - case PixelSampler::Nearest: - imbuf::interpolate_nearest_fl(buffer_, output, x, y); - break; - case PixelSampler::Bilinear: - imbuf::interpolate_bilinear_border_fl(buffer_, output, x, y); - break; - case PixelSampler::Bicubic: - imbuf::interpolate_cubic_bspline_fl(buffer_, output, x, y); - break; - } - } - else { - int yi = y; - int xi = x; - if (xi < 0 || yi < 0 || uint(xi) >= this->get_width() || uint(yi) >= this->get_height()) { - zero_v4(output); - } - else { - int offset = (yi * this->get_width() + xi) * 3; - copy_v3_v3(output, &image_float_buffer_[offset]); - } - } - } -} - -void MultilayerValueOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - if (image_float_buffer_ == nullptr) { - output[0] = 0.0f; - } - else { - int yi = y; - int xi = x; - if (xi < 0 || yi < 0 || uint(xi) >= this->get_width() || uint(yi) >= this->get_height()) { - output[0] = 0.0f; - } - else { - float result = image_float_buffer_[yi * this->get_width() + xi]; - output[0] = result; - } - } -} - -void MultilayerVectorOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - if (image_float_buffer_ == nullptr) { - output[0] = 0.0f; - } - else { - int yi = y; - int xi = x; - if (xi < 0 || yi < 0 || uint(xi) >= this->get_width() || uint(yi) >= this->get_height()) { - output[0] = 0.0f; - } - else { - int offset = (yi * this->get_width() + xi) * 3; - copy_v3_v3(output, &image_float_buffer_[offset]); - } - } -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_MultilayerImageOperation.h b/source/blender/compositor/operations/COM_MultilayerImageOperation.h index d7679de0517..76a04687d8f 100644 --- a/source/blender/compositor/operations/COM_MultilayerImageOperation.h +++ b/source/blender/compositor/operations/COM_MultilayerImageOperation.h @@ -36,7 +36,6 @@ class MultilayerColorOperation : public MultilayerBaseOperation { { this->add_output_socket(DataType::Color); } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; std::unique_ptr get_meta_data() override; }; @@ -47,7 +46,6 @@ class MultilayerValueOperation : public MultilayerBaseOperation { { this->add_output_socket(DataType::Value); } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; }; class MultilayerVectorOperation : public MultilayerBaseOperation { @@ -57,7 +55,6 @@ class MultilayerVectorOperation : public MultilayerBaseOperation { { this->add_output_socket(DataType::Vector); } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; }; } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_NormalizeOperation.cc b/source/blender/compositor/operations/COM_NormalizeOperation.cc index 56d53af0692..5cd8f3e9dc9 100644 --- a/source/blender/compositor/operations/COM_NormalizeOperation.cc +++ b/source/blender/compositor/operations/COM_NormalizeOperation.cc @@ -10,111 +10,20 @@ NormalizeOperation::NormalizeOperation() { this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Value); - image_reader_ = nullptr; cached_instance_ = nullptr; - flags_.complex = true; flags_.can_be_constant = true; } -void NormalizeOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); - NodeOperation::init_mutex(); -} - -void NormalizeOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - /* using generic two floats struct to store `x: min`, `y: multiply` */ - NodeTwoFloats *minmult = (NodeTwoFloats *)data; - - image_reader_->read(output, x, y, nullptr); - - output[0] = (output[0] - minmult->x) * minmult->y; - - /* clamp infinities */ - if (output[0] > 1.0f) { - output[0] = 1.0f; - } - else if (output[0] < 0.0f) { - output[0] = 0.0f; - } -} void NormalizeOperation::deinit_execution() { - image_reader_ = nullptr; delete cached_instance_; cached_instance_ = nullptr; - NodeOperation::deinit_mutex(); -} - -bool NormalizeOperation::determine_depending_area_of_interest(rcti * /*input*/, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti image_input; - if (cached_instance_) { - return false; - } - - NodeOperation *operation = get_input_operation(0); - image_input.xmax = operation->get_width(); - image_input.xmin = 0; - image_input.ymax = operation->get_height(); - image_input.ymin = 0; - - if (operation->determine_depending_area_of_interest(&image_input, read_operation, output)) { - return true; - } - return false; } /* The code below assumes all data is inside range +- this, and that input buffer is single channel */ #define BLENDER_ZMAX 10000.0f -void *NormalizeOperation::initialize_tile_data(rcti *rect) -{ - lock_mutex(); - if (cached_instance_ == nullptr) { - MemoryBuffer *tile = (MemoryBuffer *)image_reader_->initialize_tile_data(rect); - /* using generic two floats struct to store `x: min`, `y: multiply`. */ - NodeTwoFloats *minmult = new NodeTwoFloats(); - - float *buffer = tile->get_buffer(); - int p = tile->get_width() * tile->get_height(); - float *bc = buffer; - - float minv = 1.0f + BLENDER_ZMAX; - float maxv = -1.0f - BLENDER_ZMAX; - - float value; - while (p--) { - value = bc[0]; - if ((value > maxv) && (value <= BLENDER_ZMAX)) { - maxv = value; - } - if ((value < minv) && (value >= -BLENDER_ZMAX)) { - minv = value; - } - bc++; - } - - minmult->x = minv; - /* The rare case of flat buffer would cause a divide by 0 */ - minmult->y = ((maxv != minv) ? 1.0f / (maxv - minv) : 0.0f); - - cached_instance_ = minmult; - } - - unlock_mutex(); - return cached_instance_; -} - -void NormalizeOperation::deinitialize_tile_data(rcti * /*rect*/, void * /*data*/) -{ - /* pass */ -} - void NormalizeOperation::get_area_of_interest(const int /*input_idx*/, const rcti & /*output_area*/, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_NormalizeOperation.h b/source/blender/compositor/operations/COM_NormalizeOperation.h index 4d868204851..50ec78fdd8a 100644 --- a/source/blender/compositor/operations/COM_NormalizeOperation.h +++ b/source/blender/compositor/operations/COM_NormalizeOperation.h @@ -15,11 +15,6 @@ namespace blender::compositor { */ class NormalizeOperation : public MultiThreadedOperation { protected: - /** - * \brief Cached reference to the reader - */ - SocketReader *image_reader_; - /** * \brief temporarily cache of the execution storage * it stores `x->min` and `y->multiply`. @@ -29,28 +24,8 @@ class NormalizeOperation : public MultiThreadedOperation { public: NormalizeOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - void deinitialize_tile_data(rcti *rect, void *data) override; - - /** - * Deinitialize the execution - */ void deinit_execution() override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_started(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl b/source/blender/compositor/operations/COM_OpenCLKernels.cl deleted file mode 100644 index 589eb51d5f5..00000000000 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl +++ /dev/null @@ -1,297 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -/* This file contains all opencl kernels for node-operation implementations. */ - -/* Global SAMPLERS. */ -const sampler_t SAMPLER_NEAREST = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST; -const sampler_t SAMPLER_NEAREST_CLAMP = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; - -__constant const int2 zero = {0,0}; - -// KERNEL --- BOKEH BLUR --- -__kernel void bokeh_blur_kernel(__read_only image2d_t bounding_box, __read_only image2d_t input_image, - __read_only image2d_t bokeh_image, __write_only image2d_t output, - int2 offset_input, int2 offset_output, int radius, int step, int2 dimension, int2 offset) -{ - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - float temp_bounding_box; - float4 color = {0.0f,0.0f,0.0f,0.0f}; - float4 multiplyer = {0.0f,0.0f,0.0f,0.0f}; - float4 bokeh; - const float radius2 = radius*2.0f; - const int2 real_coordinate = coords + offset_output; - int2 image_coordinates = real_coordinate - offset_input; - - temp_bounding_box = read_imagef(bounding_box, SAMPLER_NEAREST, coords).s0; - - if (temp_bounding_box > 0.0f && radius > 0 ) { - const int2 bokeh_image_dim = get_image_dim(bokeh_image); - const int2 bokeh_image_center = bokeh_image_dim/2; - const int2 minXY = max(real_coordinate - radius, zero); - const int2 maxXY = min(real_coordinate + radius, dimension); - int nx, ny; - - float2 uv; - int2 input_xy; - - if (radius < 2) { - color = read_imagef(input_image, SAMPLER_NEAREST, image_coordinates); - multiplyer = (float4)(1.0f, 1.0f, 1.0f, 1.0f); - } - - for (ny = minXY.y, input_xy.y = ny - offset_input.y ; ny < maxXY.y ; ny += step, input_xy.y += step) { - uv.y = ((real_coordinate.y-ny)/radius2)*bokeh_image_dim.y+bokeh_image_center.y; - - for (nx = minXY.x, input_xy.x = nx - offset_input.x; nx < maxXY.x ; nx += step, input_xy.x += step) { - uv.x = ((real_coordinate.x-nx)/radius2)*bokeh_image_dim.x+bokeh_image_center.x; - bokeh = read_imagef(bokeh_image, SAMPLER_NEAREST, uv); - color += bokeh * read_imagef(input_image, SAMPLER_NEAREST, input_xy); - multiplyer += bokeh; - } - } - color /= multiplyer; - } - else { - color = read_imagef(input_image, SAMPLER_NEAREST, image_coordinates); - } - - write_imagef(output, coords, color); -} - -//KERNEL --- DEFOCUS /VARIABLESIZEBOKEHBLUR --- -__kernel void defocus_kernel(__read_only image2d_t input_image, __read_only image2d_t bokeh_image, - __read_only image2d_t input_size, - __write_only image2d_t output, int2 offset_input, int2 offset_output, - int step, int max_blur_scalar, float threshold, float scalar, int2 dimension, int2 offset) -{ - float4 color = {1.0f, 0.0f, 0.0f, 1.0f}; - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - const int2 real_coordinate = coords + offset_output; - - float4 read_color; - float4 temp_color; - float4 bokeh; - float size; - float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f}; - float4 color_accum; - - int minx = max(real_coordinate.s0 - max_blur_scalar, 0); - int miny = max(real_coordinate.s1 - max_blur_scalar, 0); - int maxx = min(real_coordinate.s0 + max_blur_scalar, dimension.s0); - int maxy = min(real_coordinate.s1 + max_blur_scalar, dimension.s1); - - { - int2 input_coordinate = real_coordinate - offset_input; - float size_center = read_imagef(input_size, SAMPLER_NEAREST, input_coordinate).s0 * scalar; - color_accum = read_imagef(input_image, SAMPLER_NEAREST, input_coordinate); - read_color = color_accum; - - if (size_center > threshold) { - for (int ny = miny; ny < maxy; ny += step) { - input_coordinate.s1 = ny - offset_input.s1; - float dy = ny - real_coordinate.s1; - for (int nx = minx; nx < maxx; nx += step) { - float dx = nx - real_coordinate.s0; - if (dx != 0 || dy != 0) { - input_coordinate.s0 = nx - offset_input.s0; - size = min(read_imagef(input_size, SAMPLER_NEAREST, input_coordinate).s0 * scalar, size_center); - if (size > threshold) { - if (size >= fabs(dx) && size >= fabs(dy)) { - float2 uv = {256.0f + dx * 255.0f / size, - 256.0f + dy * 255.0f / size}; - bokeh = read_imagef(bokeh_image, SAMPLER_NEAREST, uv); - temp_color = read_imagef(input_image, SAMPLER_NEAREST, input_coordinate); - color_accum += bokeh * temp_color; - multiplier_accum += bokeh; - } - } - } - } - } - } - - color = color_accum * (1.0f / multiplier_accum); - - /* blend in out values over the threshold, otherwise we get sharp, ugly transitions */ - if ((size_center > threshold) && - (size_center < threshold * 2.0f)) - { - /* factor from 0-1 */ - float fac = (size_center - threshold) / threshold; - color = (read_color * (1.0f - fac)) + (color * fac); - } - - write_imagef(output, coords, color); - } -} - - -// KERNEL --- DILATE --- -__kernel void dilate_kernel(__read_only image2d_t input_image, __write_only image2d_t output, - int2 offset_input, int2 offset_output, int scope, int distance_squared, int2 dimension, - int2 offset) -{ - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - const int2 real_coordinate = coords + offset_output; - - const int2 minXY = max(real_coordinate - scope, zero); - const int2 maxXY = min(real_coordinate + scope, dimension); - - float value = 0.0f; - int nx, ny; - int2 input_xy; - - for (ny = minXY.y, input_xy.y = ny - offset_input.y ; ny < maxXY.y ; ny ++, input_xy.y++) { - const float deltaY = (real_coordinate.y - ny); - for (nx = minXY.x, input_xy.x = nx - offset_input.x; nx < maxXY.x ; nx ++, input_xy.x++) { - const float deltaX = (real_coordinate.x - nx); - const float measured_distance = deltaX * deltaX + deltaY * deltaY; - if (measured_distance <= distance_squared) { - value = max(value, read_imagef(input_image, SAMPLER_NEAREST, input_xy).s0); - } - } - } - - float4 color = {value,0.0f,0.0f,0.0f}; - write_imagef(output, coords, color); -} - -// KERNEL --- DILATE --- -__kernel void erode_kernel(__read_only image2d_t input_image, __write_only image2d_t output, - int2 offset_input, int2 offset_output, int scope, int distance_squared, int2 dimension, - int2 offset) -{ - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - const int2 real_coordinate = coords + offset_output; - - const int2 minXY = max(real_coordinate - scope, zero); - const int2 maxXY = min(real_coordinate + scope, dimension); - - float value = 1.0f; - int nx, ny; - int2 input_xy; - - for (ny = minXY.y, input_xy.y = ny - offset_input.y ; ny < maxXY.y ; ny ++, input_xy.y++) { - for (nx = minXY.x, input_xy.x = nx - offset_input.x; nx < maxXY.x ; nx ++, input_xy.x++) { - const float deltaX = (real_coordinate.x - nx); - const float deltaY = (real_coordinate.y - ny); - const float measured_distance = deltaX * deltaX+deltaY * deltaY; - if (measured_distance <= distance_squared) { - value = min(value, read_imagef(input_image, SAMPLER_NEAREST, input_xy).s0); - } - } - } - - float4 color = {value,0.0f,0.0f,0.0f}; - write_imagef(output, coords, color); -} - -// KERNEL --- DIRECTIONAL BLUR --- -__kernel void directional_blur_kernel(__read_only image2d_t input_image, __write_only image2d_t output, - int2 offset_output, int iterations, float scale, float rotation, float2 translate, - float2 center, int2 offset) -{ - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - const int2 real_coordinate = coords + offset_output; - - float4 col; - float2 ltxy = translate; - float lsc = scale; - float lrot = rotation; - - col = read_imagef(input_image, SAMPLER_NEAREST, real_coordinate); - - /* blur the image */ - for (int i = 0; i < iterations; ++i) { - const float cs = cos(lrot), ss = sin(lrot); - const float isc = 1.0f / (1.0f + lsc); - - const float v = isc * (real_coordinate.s1 - center.s1) + ltxy.s1; - const float u = isc * (real_coordinate.s0 - center.s0) + ltxy.s0; - float2 uv = { - cs * u + ss * v + center.s0, - cs * v - ss * u + center.s1 - }; - - col += read_imagef(input_image, SAMPLER_NEAREST_CLAMP, uv); - - /* double transformations */ - ltxy += translate; - lrot += rotation; - lsc += scale; - } - - col *= (1.0f/(iterations+1)); - - write_imagef(output, coords, col); -} - -// KERNEL --- GAUSSIAN BLUR --- -__kernel void gaussian_xblur_operation_kernel(__read_only image2d_t input_image, - int2 offset_input, - __write_only image2d_t output, - int2 offset_output, - int filter_size, - int2 dimension, - __global float *gausstab, - int2 offset) -{ - float4 color = {0.0f, 0.0f, 0.0f, 0.0f}; - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - const int2 real_coordinate = coords + offset_output; - int2 input_coordinate = real_coordinate - offset_input; - float weight = 0.0f; - - int xmin = max(real_coordinate.x - filter_size, 0) - offset_input.x; - int xmax = min(real_coordinate.x + filter_size + 1, dimension.x) - offset_input.x; - - for (int nx = xmin, i = max(filter_size - real_coordinate.x, 0); nx < xmax; ++nx, ++i) { - float w = gausstab[i]; - input_coordinate.x = nx; - color += read_imagef(input_image, SAMPLER_NEAREST, input_coordinate) * w; - weight += w; - } - - color *= (1.0f / weight); - - write_imagef(output, coords, color); -} - -__kernel void gaussian_yblur_operation_kernel(__read_only image2d_t input_image, - int2 offset_input, - __write_only image2d_t output, - int2 offset_output, - int filter_size, - int2 dimension, - __global float *gausstab, - int2 offset) -{ - float4 color = {0.0f, 0.0f, 0.0f, 0.0f}; - int2 coords = {get_global_id(0), get_global_id(1)}; - coords += offset; - const int2 real_coordinate = coords + offset_output; - int2 input_coordinate = real_coordinate - offset_input; - float weight = 0.0f; - - int ymin = max(real_coordinate.y - filter_size, 0) - offset_input.y; - int ymax = min(real_coordinate.y + filter_size + 1, dimension.y) - offset_input.y; - - for (int ny = ymin, i = max(filter_size - real_coordinate.y, 0); ny < ymax; ++ny, ++i) { - float w = gausstab[i]; - input_coordinate.y = ny; - color += read_imagef(input_image, SAMPLER_NEAREST, input_coordinate) * w; - weight += w; - } - - color *= (1.0f / weight); - - write_imagef(output, coords, color); -} diff --git a/source/blender/compositor/operations/COM_PixelateOperation.cc b/source/blender/compositor/operations/COM_PixelateOperation.cc index 9a540eee36a..9e07173a170 100644 --- a/source/blender/compositor/operations/COM_PixelateOperation.cc +++ b/source/blender/compositor/operations/COM_PixelateOperation.cc @@ -13,67 +13,12 @@ PixelateOperation::PixelateOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_operation_ = nullptr; flags_.can_be_constant = true; pixel_size_ = 1; } -void PixelateOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void PixelateOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - -bool PixelateOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - - new_input.xmin = input->xmin; - new_input.xmax = input->xmax + pixel_size_ - 1; - new_input.ymax = input->ymax; - new_input.ymax = input->ymax + pixel_size_ - 1; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - -void PixelateOperation::execute_pixel_sampled(float output[4], - const float x, - const float y, - const PixelSampler sampler) -{ - const int width = this->get_width(); - const int height = this->get_height(); - - const int x_start = (int(x) / pixel_size_) * pixel_size_; - const int y_start = (int(y) / pixel_size_) * pixel_size_; - - const int x_end = std::min(x_start + pixel_size_, width); - const int y_end = std::min(y_start + pixel_size_, height); - - float4 color_accum(0, 0, 0, 0); - - for (int iy = y_start; iy < y_end; ++iy) { - for (int ix = x_start; ix < x_end; ++ix) { - float4 color; - input_operation_->read_sampled(color, ix, iy, sampler); - - color_accum += color; - } - } - - const int scale = (x_end - x_start) * (y_end - y_start); - - copy_v4_v4(output, color_accum / float(scale)); -} - void PixelateOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_PixelateOperation.h b/source/blender/compositor/operations/COM_PixelateOperation.h index eb2a368b1f2..e4479354562 100644 --- a/source/blender/compositor/operations/COM_PixelateOperation.h +++ b/source/blender/compositor/operations/COM_PixelateOperation.h @@ -8,20 +8,8 @@ namespace blender::compositor { -/** - * \brief Pixelate operation - * - * The Tile compositor is by default sub-pixel accurate. - * For some setups you don want this. - * This operation will remove the sub-pixel accuracy - */ class PixelateOperation : public MultiThreadedOperation { private: - /** - * \brief cached reference to the input operation - */ - SocketReader *input_operation_; - int pixel_size_; public: @@ -36,29 +24,6 @@ class PixelateOperation : public MultiThreadedOperation { pixel_size_ = pixel_size; } - /** - * \brief initialization of the execution - */ - void init_execution() override; - - /** - * \brief de-initialization of the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - /** - * \brief execute_pixel - * \param output: result - * \param x: x-coordinate - * \param y: y-coordinate - * \param sampler: sampler - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc index 9eda293ec53..ecd70de6566 100644 --- a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc +++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cc @@ -42,36 +42,6 @@ static bool check_corners(float corners[4][2]) return true; } -/* TODO(manzanilla): to be removed with tiled implementation. */ -static void read_corners_from_sockets(rcti *rect, SocketReader *readers[4], float corners[4][2]) -{ - for (int i = 0; i < 4; i++) { - float result[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - readers[i]->read_sampled(result, rect->xmin, rect->ymin, PixelSampler::Nearest); - corners[i][0] = result[0]; - corners[i][1] = result[1]; - } - - /* convexity check: - * concave corners need to be prevented, otherwise - * BKE_tracking_homography_between_two_quads will freeze - */ - if (!check_corners(corners)) { - /* simply revert to default corners - * there could be a more elegant solution, - * this prevents freezing at least. - */ - corners[0][0] = 0.0f; - corners[0][1] = 0.0f; - corners[1][0] = 1.0f; - corners[1][1] = 0.0f; - corners[2][0] = 1.0f; - corners[2][1] = 1.0f; - corners[3][0] = 0.0f; - corners[3][1] = 1.0f; - } -} - static void set_default_corner(const int corner_idx, float r_corner[2]) { BLI_assert(corner_idx >= 0 && corner_idx < 4); @@ -121,78 +91,25 @@ static void read_input_corners(NodeOperation *op, const int first_input_idx, flo /* ******** PlaneCornerPinMaskOperation ******** */ -PlaneCornerPinMaskOperation::PlaneCornerPinMaskOperation() : corners_ready_(false) +PlaneCornerPinMaskOperation::PlaneCornerPinMaskOperation() { add_input_socket(DataType::Vector); add_input_socket(DataType::Vector); add_input_socket(DataType::Vector); add_input_socket(DataType::Vector); - - /* XXX this is stupid: we need to make this "complex", - * so we can use the initialize_tile_data function - * to read corners from input sockets ... - */ - flags_.complex = true; } void PlaneCornerPinMaskOperation::init_data() { - if (execution_model_ == eExecutionModel::FullFrame) { - float corners[4][2]; - read_input_corners(this, 0, corners); - calculate_corners(corners, true, 0); - } -} - -/* TODO(manzanilla): to be removed with tiled implementation. Same for #deinit_execution and do the - * same on #PlaneCornerPinWarpImageOperation. */ -void PlaneCornerPinMaskOperation::init_execution() -{ - PlaneDistortMaskOperation::init_execution(); - - init_mutex(); -} - -void PlaneCornerPinMaskOperation::deinit_execution() -{ - PlaneDistortMaskOperation::deinit_execution(); - - deinit_mutex(); -} - -void *PlaneCornerPinMaskOperation::initialize_tile_data(rcti *rect) -{ - void *data = PlaneDistortMaskOperation::initialize_tile_data(rect); - - /* get corner values once, by reading inputs at (0,0) - * XXX this assumes invariable values (no image inputs), - * we don't have a nice generic system for that yet - */ - lock_mutex(); - if (!corners_ready_) { - SocketReader *readers[4] = { - get_input_socket_reader(0), - get_input_socket_reader(1), - get_input_socket_reader(2), - get_input_socket_reader(3), - }; - float corners[4][2]; - read_corners_from_sockets(rect, readers, corners); - calculate_corners(corners, true, 0); - - corners_ready_ = true; - } - unlock_mutex(); - - return data; + float corners[4][2]; + read_input_corners(this, 0, corners); + calculate_corners(corners, true, 0); } void PlaneCornerPinMaskOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { - if (execution_model_ == eExecutionModel::FullFrame) { - /* Determine input canvases. */ - PlaneDistortMaskOperation::determine_canvas(preferred_area, r_area); - } + /* Determine input canvases. */ + PlaneDistortMaskOperation::determine_canvas(preferred_area, r_area); r_area = preferred_area; } @@ -206,7 +123,7 @@ void PlaneCornerPinMaskOperation::get_area_of_interest(const int /*input_idx*/, /* ******** PlaneCornerPinWarpImageOperation ******** */ -PlaneCornerPinWarpImageOperation::PlaneCornerPinWarpImageOperation() : corners_ready_(false) +PlaneCornerPinWarpImageOperation::PlaneCornerPinWarpImageOperation() { add_input_socket(DataType::Vector); add_input_socket(DataType::Vector); @@ -216,79 +133,9 @@ PlaneCornerPinWarpImageOperation::PlaneCornerPinWarpImageOperation() : corners_r void PlaneCornerPinWarpImageOperation::init_data() { - if (execution_model_ == eExecutionModel::FullFrame) { - float corners[4][2]; - read_input_corners(this, 1, corners); - calculate_corners(corners, true, 0); - } -} - -void PlaneCornerPinWarpImageOperation::init_execution() -{ - PlaneDistortWarpImageOperation::init_execution(); - - init_mutex(); -} - -void PlaneCornerPinWarpImageOperation::deinit_execution() -{ - PlaneDistortWarpImageOperation::deinit_execution(); - - deinit_mutex(); -} - -void *PlaneCornerPinWarpImageOperation::initialize_tile_data(rcti *rect) -{ - void *data = PlaneDistortWarpImageOperation::initialize_tile_data(rect); - - /* get corner values once, by reading inputs at (0,0) - * XXX this assumes invariable values (no image inputs), - * we don't have a nice generic system for that yet - */ - lock_mutex(); - if (!corners_ready_) { - /* corner sockets start at index 1 */ - SocketReader *readers[4] = { - get_input_socket_reader(1), - get_input_socket_reader(2), - get_input_socket_reader(3), - get_input_socket_reader(4), - }; - float corners[4][2]; - read_corners_from_sockets(rect, readers, corners); - calculate_corners(corners, true, 0); - - corners_ready_ = true; - } - unlock_mutex(); - - return data; -} - -bool PlaneCornerPinWarpImageOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - for (int i = 0; i < 4; i++) { - if (get_input_operation(i + 1)->determine_depending_area_of_interest( - input, read_operation, output)) - { - return true; - } - } - - /* XXX this is bad, but unavoidable with the current design: - * we don't know the actual corners and matrix at this point, - * so all we can do is get the full input image - */ - output->xmin = 0; - output->ymin = 0; - output->xmax = get_input_operation(0)->get_width(); - output->ymax = get_input_operation(0)->get_height(); - return true; -#if 0 - return PlaneDistortWarpImageOperation::determine_depending_area_of_interest( - input, read_operation, output); -#endif + float corners[4][2]; + read_input_corners(this, 1, corners); + calculate_corners(corners, true, 0); } void PlaneCornerPinWarpImageOperation::get_area_of_interest(const int input_idx, diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h index 17b0fccada8..fdc8fd8a300 100644 --- a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h +++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.h @@ -4,31 +4,15 @@ #pragma once -#include - #include "COM_PlaneDistortCommonOperation.h" -#include "DNA_movieclip_types.h" -#include "DNA_tracking_types.h" - -#include "BLI_listbase.h" -#include "BLI_string.h" - namespace blender::compositor { class PlaneCornerPinMaskOperation : public PlaneDistortMaskOperation { - private: - /* TODO(manzanilla): to be removed with tiled implementation. */ - bool corners_ready_; - public: PlaneCornerPinMaskOperation(); void init_data() override; - void init_execution() override; - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; @@ -36,21 +20,10 @@ class PlaneCornerPinMaskOperation : public PlaneDistortMaskOperation { }; class PlaneCornerPinWarpImageOperation : public PlaneDistortWarpImageOperation { - private: - bool corners_ready_; - public: PlaneCornerPinWarpImageOperation(); void init_data() override; - void init_execution() override; - void deinit_execution() override; - - void *initialize_tile_data(rcti *rect) override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; }; diff --git a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc index d52bf7fb373..6a1c48beed2 100644 --- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc +++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cc @@ -61,8 +61,6 @@ PlaneDistortWarpImageOperation::PlaneDistortWarpImageOperation() : PlaneDistortB { this->add_input_socket(DataType::Color, ResizeMode::Align); this->add_output_socket(DataType::Color); - pixel_reader_ = nullptr; - flags_.complex = true; } void PlaneDistortWarpImageOperation::calculate_corners(const float corners[4][2], @@ -90,39 +88,6 @@ void PlaneDistortWarpImageOperation::calculate_corners(const float corners[4][2] sample_data->frame_space_corners, frame_corners, sample_data->perspective_matrix); } -void PlaneDistortWarpImageOperation::init_execution() -{ - pixel_reader_ = this->get_input_socket_reader(0); -} - -void PlaneDistortWarpImageOperation::deinit_execution() -{ - pixel_reader_ = nullptr; -} - -void PlaneDistortWarpImageOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - float uv[2]; - float deriv[2][2]; - if (motion_blur_samples_ == 1) { - warp_coord(x, y, samples_[0].perspective_matrix, uv, deriv); - pixel_reader_->read_filtered(output, uv[0], uv[1], deriv[0], deriv[1]); - } - else { - zero_v4(output); - for (int sample = 0; sample < motion_blur_samples_; sample++) { - float color[4]; - warp_coord(x, y, samples_[sample].perspective_matrix, uv, deriv); - pixel_reader_->read_filtered(color, uv[0], uv[1], deriv[0], deriv[1]); - add_v4_v4(output, color); - } - mul_v4_fl(output, 1.0f / float(motion_blur_samples_)); - } -} - void PlaneDistortWarpImageOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -151,36 +116,6 @@ void PlaneDistortWarpImageOperation::update_memory_buffer_partial(MemoryBuffer * } } -bool PlaneDistortWarpImageOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - float min[2], max[2]; - INIT_MINMAX2(min, max); - - for (int sample = 0; sample < motion_blur_samples_; sample++) { - float UVs[4][2]; - float deriv[2][2]; - MotionSample *sample_data = &samples_[sample]; - /* TODO(sergey): figure out proper way to do this. */ - warp_coord(input->xmin - 2, input->ymin - 2, sample_data->perspective_matrix, UVs[0], deriv); - warp_coord(input->xmax + 2, input->ymin - 2, sample_data->perspective_matrix, UVs[1], deriv); - warp_coord(input->xmax + 2, input->ymax + 2, sample_data->perspective_matrix, UVs[2], deriv); - warp_coord(input->xmin - 2, input->ymax + 2, sample_data->perspective_matrix, UVs[3], deriv); - for (int i = 0; i < 4; i++) { - minmax_v2v2_v2(min, max, UVs[i]); - } - } - - rcti new_input; - - new_input.xmin = min[0] - 1; - new_input.ymin = min[1] - 1; - new_input.xmax = max[0] + 1; - new_input.ymax = max[1] + 1; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void PlaneDistortWarpImageOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) @@ -250,55 +185,6 @@ void PlaneDistortMaskOperation::init_execution() BLI_jitter_init(jitter_, osa_); } -void PlaneDistortMaskOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - float point[2]; - int inside_counter = 0; - if (motion_blur_samples_ == 1) { - MotionSample *sample_data = &samples_[0]; - for (int sample = 0; sample < osa_; sample++) { - point[0] = x + jitter_[sample][0]; - point[1] = y + jitter_[sample][1]; - if (isect_point_tri_v2(point, - sample_data->frame_space_corners[0], - sample_data->frame_space_corners[1], - sample_data->frame_space_corners[2]) || - isect_point_tri_v2(point, - sample_data->frame_space_corners[0], - sample_data->frame_space_corners[2], - sample_data->frame_space_corners[3])) - { - inside_counter++; - } - } - output[0] = float(inside_counter) / osa_; - } - else { - for (int motion_sample = 0; motion_sample < motion_blur_samples_; motion_sample++) { - MotionSample *sample_data = &samples_[motion_sample]; - for (int osa_sample = 0; osa_sample < osa_; osa_sample++) { - point[0] = x + jitter_[osa_sample][0]; - point[1] = y + jitter_[osa_sample][1]; - if (isect_point_tri_v2(point, - sample_data->frame_space_corners[0], - sample_data->frame_space_corners[1], - sample_data->frame_space_corners[2]) || - isect_point_tri_v2(point, - sample_data->frame_space_corners[0], - sample_data->frame_space_corners[2], - sample_data->frame_space_corners[3])) - { - inside_counter++; - } - } - } - output[0] = float(inside_counter) / (osa_ * motion_blur_samples_); - } -} - void PlaneDistortMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) diff --git a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h index 90efd7d17ae..d995edc31a9 100644 --- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h +++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h @@ -48,23 +48,11 @@ class PlaneDistortBaseOperation : public MultiThreadedOperation { }; class PlaneDistortWarpImageOperation : public PlaneDistortBaseOperation { - protected: - SocketReader *pixel_reader_; - public: PlaneDistortWarpImageOperation(); void calculate_corners(const float corners[4][2], bool normalized, int sample) override; - void init_execution() override; - void deinit_execution() override; - - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -81,8 +69,6 @@ class PlaneDistortMaskOperation : public PlaneDistortBaseOperation { void init_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_PlaneTrackOperation.cc b/source/blender/compositor/operations/COM_PlaneTrackOperation.cc index 6660b0114ea..eb6316d4b78 100644 --- a/source/blender/compositor/operations/COM_PlaneTrackOperation.cc +++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.cc @@ -81,18 +81,7 @@ void PlaneTrackCommon::determine_canvas(const rcti &preferred_area, rcti &r_area void PlaneTrackMaskOperation::init_data() { PlaneDistortMaskOperation::init_data(); - if (execution_model_ == eExecutionModel::FullFrame) { - PlaneTrackCommon::read_and_calculate_corners(this); - } -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void PlaneTrackMaskOperation::init_execution() -{ - PlaneDistortMaskOperation::init_execution(); - if (execution_model_ == eExecutionModel::Tiled) { - PlaneTrackCommon::read_and_calculate_corners(this); - } + PlaneTrackCommon::read_and_calculate_corners(this); } /* ******** PlaneTrackWarpImageOperation ******** */ @@ -100,18 +89,7 @@ void PlaneTrackMaskOperation::init_execution() void PlaneTrackWarpImageOperation::init_data() { PlaneDistortWarpImageOperation::init_data(); - if (execution_model_ == eExecutionModel::FullFrame) { - PlaneTrackCommon::read_and_calculate_corners(this); - } -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void PlaneTrackWarpImageOperation::init_execution() -{ - PlaneDistortWarpImageOperation::init_execution(); - if (execution_model_ == eExecutionModel::Tiled) { - PlaneTrackCommon::read_and_calculate_corners(this); - } + PlaneTrackCommon::read_and_calculate_corners(this); } } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_PlaneTrackOperation.h b/source/blender/compositor/operations/COM_PlaneTrackOperation.h index 21294ebba26..da07a7ab340 100644 --- a/source/blender/compositor/operations/COM_PlaneTrackOperation.h +++ b/source/blender/compositor/operations/COM_PlaneTrackOperation.h @@ -11,9 +11,6 @@ #include "DNA_movieclip_types.h" #include "DNA_tracking_types.h" -#include "BLI_listbase.h" -#include "BLI_string.h" - namespace blender::compositor { class PlaneTrackCommon { @@ -59,8 +56,6 @@ class PlaneTrackMaskOperation : public PlaneDistortMaskOperation, public PlaneTr void init_data() override; - void init_execution() override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override { PlaneTrackCommon::determine_canvas(preferred_area, r_area); @@ -78,8 +73,6 @@ class PlaneTrackWarpImageOperation : public PlaneDistortWarpImageOperation, void init_data() override; - void init_execution() override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override { PlaneTrackCommon::determine_canvas(preferred_area, r_area); diff --git a/source/blender/compositor/operations/COM_PosterizeOperation.cc b/source/blender/compositor/operations/COM_PosterizeOperation.cc index 05c2bca73b8..51c246b0274 100644 --- a/source/blender/compositor/operations/COM_PosterizeOperation.cc +++ b/source/blender/compositor/operations/COM_PosterizeOperation.cc @@ -11,36 +11,9 @@ PosterizeOperation::PosterizeOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_program_ = nullptr; - input_steps_program_ = nullptr; flags_.can_be_constant = true; } -void PosterizeOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); - input_steps_program_ = this->get_input_socket_reader(1); -} - -void PosterizeOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input_value[4]; - float input_steps[4]; - - input_program_->read_sampled(input_value, x, y, sampler); - input_steps_program_->read_sampled(input_steps, x, y, sampler); - CLAMP(input_steps[0], 2.0f, 1024.0f); - const float steps_inv = 1.0f / input_steps[0]; - - output[0] = floor(input_value[0] / steps_inv) * steps_inv; - output[1] = floor(input_value[1] / steps_inv) * steps_inv; - output[2] = floor(input_value[2] / steps_inv) * steps_inv; - output[3] = input_value[3]; -} - void PosterizeOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -59,10 +32,4 @@ void PosterizeOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void PosterizeOperation::deinit_execution() -{ - input_program_ = nullptr; - input_steps_program_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_PosterizeOperation.h b/source/blender/compositor/operations/COM_PosterizeOperation.h index 01a17a9f7c1..d2cfbf809be 100644 --- a/source/blender/compositor/operations/COM_PosterizeOperation.h +++ b/source/blender/compositor/operations/COM_PosterizeOperation.h @@ -9,31 +9,9 @@ namespace blender::compositor { class PosterizeOperation : public MultiThreadedOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - SocketReader *input_steps_program_; - public: PosterizeOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_PreviewOperation.cc b/source/blender/compositor/operations/COM_PreviewOperation.cc index 9b819b87c5a..40e59bb32b9 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.cc +++ b/source/blender/compositor/operations/COM_PreviewOperation.cc @@ -19,7 +19,6 @@ PreviewOperation::PreviewOperation(const ColorManagedViewSettings *view_settings this->add_input_socket(DataType::Color, ResizeMode::Align); preview_ = nullptr; output_image_ = nullptr; - input_ = nullptr; divider_ = 1.0f; view_settings_ = view_settings; display_settings_ = display_settings; @@ -39,7 +38,6 @@ void PreviewOperation::verify_preview(bNodeInstanceHash *previews, bNodeInstance void PreviewOperation::init_execution() { - input_ = get_input_socket_reader(0); output_image_ = preview_->ibuf; if (this->get_width() == uint(preview_->ibuf->x) && @@ -57,49 +55,8 @@ void PreviewOperation::init_execution() void PreviewOperation::deinit_execution() { output_image_ = nullptr; - input_ = nullptr; } -void PreviewOperation::execute_region(rcti *rect, uint /*tile_number*/) -{ - int offset; - float color[4]; - ColormanageProcessor *cm_processor; - - cm_processor = IMB_colormanagement_display_processor_new(view_settings_, display_settings_); - - for (int y = rect->ymin; y < rect->ymax; y++) { - offset = (y * get_width() + rect->xmin) * 4; - for (int x = rect->xmin; x < rect->xmax; x++) { - float rx = floor(x / divider_); - float ry = floor(y / divider_); - - color[0] = 0.0f; - color[1] = 0.0f; - color[2] = 0.0f; - color[3] = 1.0f; - input_->read_sampled(color, rx, ry, PixelSampler::Nearest); - IMB_colormanagement_processor_apply_v4(cm_processor, color); - rgba_float_to_uchar(output_image_->byte_buffer.data + offset, color); - offset += 4; - } - } - - IMB_colormanagement_processor_free(cm_processor); -} -bool PreviewOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - - new_input.xmin = input->xmin / divider_; - new_input.xmax = input->xmax / divider_; - new_input.ymin = input->ymin / divider_; - new_input.ymax = input->ymax / divider_; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} void PreviewOperation::determine_canvas(const rcti & /*preferred_area*/, rcti &r_area) { /* Use default preview resolution as preferred ensuring it has size so that diff --git a/source/blender/compositor/operations/COM_PreviewOperation.h b/source/blender/compositor/operations/COM_PreviewOperation.h index bcf60f0ab2e..20be8f3e86b 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.h +++ b/source/blender/compositor/operations/COM_PreviewOperation.h @@ -20,7 +20,6 @@ class PreviewOperation : public MultiThreadedOperation { * \brief holds reference to the SDNA bNode, where this nodes will render the preview image for */ bNodePreview *preview_; - SocketReader *input_; float divider_; unsigned int default_width_; unsigned int default_height_; @@ -43,11 +42,7 @@ class PreviewOperation : public MultiThreadedOperation { void deinit_execution() override; eCompositorPriority get_render_priority() const override; - void execute_region(rcti *rect, unsigned int tile_number) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc index c2e2d9e5da8..7eecd4e8fea 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cc @@ -12,123 +12,26 @@ ProjectorLensDistortionOperation::ProjectorLensDistortionOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - input_program_ = nullptr; - dispersion_available_ = false; dispersion_ = 0.0f; } void ProjectorLensDistortionOperation::init_data() { - if (execution_model_ == eExecutionModel::FullFrame) { - NodeOperation *dispersion_input = get_input_operation(1); - if (dispersion_input->get_flags().is_constant_operation) { - dispersion_ = static_cast(dispersion_input)->get_constant_elem()[0]; - } - kr_ = 0.25f * max_ff(min_ff(dispersion_, 1.0f), 0.0f); - kr2_ = kr_ * 20; + NodeOperation *dispersion_input = get_input_operation(1); + if (dispersion_input->get_flags().is_constant_operation) { + dispersion_ = static_cast(dispersion_input)->get_constant_elem()[0]; } -} - -void ProjectorLensDistortionOperation::init_execution() -{ - this->init_mutex(); - input_program_ = this->get_input_socket_reader(0); -} - -void *ProjectorLensDistortionOperation::initialize_tile_data(rcti * /*rect*/) -{ - update_dispersion(); - void *buffer = input_program_->initialize_tile_data(nullptr); - return buffer; -} - -void ProjectorLensDistortionOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float input_value[4]; - const float height = this->get_height(); - const float width = this->get_width(); - const float v = (y + 0.5f) / height; - const float u = (x + 0.5f) / width; - MemoryBuffer *input_buffer = (MemoryBuffer *)data; - input_buffer->read_bilinear(input_value, (u * width + kr2_) - 0.5f, v * height - 0.5f); - output[0] = input_value[0]; - input_buffer->read(input_value, x, y); - output[1] = input_value[1]; - input_buffer->read_bilinear(input_value, (u * width - kr2_) - 0.5f, v * height - 0.5f); - output[2] = input_value[2]; - output[3] = 1.0f; -} - -void ProjectorLensDistortionOperation::deinit_execution() -{ - this->deinit_mutex(); - input_program_ = nullptr; -} - -bool ProjectorLensDistortionOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - if (dispersion_available_) { - new_input.ymax = input->ymax; - new_input.ymin = input->ymin; - new_input.xmin = input->xmin - kr2_ - 2; - new_input.xmax = input->xmax + kr2_ + 2; - } - else { - rcti disp_input; - BLI_rcti_init(&disp_input, 0, 5, 0, 5); - if (this->get_input_operation(1)->determine_depending_area_of_interest( - &disp_input, read_operation, output)) - { - return true; - } - new_input.xmin = input->xmin - 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */ - new_input.ymin = input->ymin; - new_input.ymax = input->ymax; - new_input.xmax = input->xmax + 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */ - } - if (this->get_input_operation(0)->determine_depending_area_of_interest( - &new_input, read_operation, output)) - { - return true; - } - return false; -} - -/* TODO(manzanilla): to be removed with tiled implementation. */ -void ProjectorLensDistortionOperation::update_dispersion() -{ - if (dispersion_available_) { - return; - } - this->lock_mutex(); - if (!dispersion_available_) { - float result[4]; - this->get_input_socket_reader(1)->read_sampled(result, 1, 1, PixelSampler::Nearest); - dispersion_ = result[0]; - kr_ = 0.25f * max_ff(min_ff(dispersion_, 1.0f), 0.0f); - kr2_ = kr_ * 20; - dispersion_available_ = true; - } - this->unlock_mutex(); + kr_ = 0.25f * max_ff(min_ff(dispersion_, 1.0f), 0.0f); + kr2_ = kr_ * 20; } void ProjectorLensDistortionOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { - switch (execution_model_) { - case eExecutionModel::FullFrame: { - set_determined_canvas_modifier([=](rcti &canvas) { - /* Ensure screen space. */ - BLI_rcti_translate(&canvas, -canvas.xmin, -canvas.ymin); - }); - break; - } - default: - break; - } + set_determined_canvas_modifier([=](rcti &canvas) { + /* Ensure screen space. */ + BLI_rcti_translate(&canvas, -canvas.xmin, -canvas.ymin); + }); NodeOperation::determine_canvas(preferred_area, r_area); } diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h index e80cba1cc9d..c0ab16b2b18 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h @@ -11,42 +11,14 @@ namespace blender::compositor { class ProjectorLensDistortionOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - float dispersion_; - /* TODO(manzanilla): to be removed with tiled implementation. */ - bool dispersion_available_; float kr_, kr2_; public: ProjectorLensDistortionOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - void init_data() override; - /** - * Initialize the execution - */ - void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - - void update_dispersion(); void determine_canvas(const rcti &preferred_area, rcti &r_area) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; diff --git a/source/blender/compositor/operations/COM_QualityStepHelper.h b/source/blender/compositor/operations/COM_QualityStepHelper.h index c4e930b649a..1795c788073 100644 --- a/source/blender/compositor/operations/COM_QualityStepHelper.h +++ b/source/blender/compositor/operations/COM_QualityStepHelper.h @@ -20,9 +20,6 @@ class QualityStepHelper { int offsetadd_; protected: - /** - * Initialize the execution - */ void init_execution(QualityHelper helper); inline int get_step() const diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.cc b/source/blender/compositor/operations/COM_ReadBufferOperation.cc deleted file mode 100644 index 654d136ebac..00000000000 --- a/source/blender/compositor/operations/COM_ReadBufferOperation.cc +++ /dev/null @@ -1,125 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_ReadBufferOperation.h" - -#include "COM_ExecutionGroup.h" -#include "COM_WriteBufferOperation.h" - -namespace blender::compositor { - -ReadBufferOperation::ReadBufferOperation(DataType datatype) -{ - this->add_output_socket(datatype); - single_value_ = false; - offset_ = 0; - buffer_ = nullptr; - flags_.is_read_buffer_operation = true; -} - -void *ReadBufferOperation::initialize_tile_data(rcti * /*rect*/) -{ - return buffer_; -} - -void ReadBufferOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) -{ - if (memory_proxy_ != nullptr) { - WriteBufferOperation *operation = memory_proxy_->get_write_buffer_operation(); - operation->determine_canvas(preferred_area, r_area); - operation->set_canvas(r_area); - - /** \todo may not occur! But does with blur node. */ - if (memory_proxy_->get_executor()) { - uint resolution[2] = {uint(BLI_rcti_size_x(&r_area)), uint(BLI_rcti_size_y(&r_area))}; - memory_proxy_->get_executor()->set_resolution(resolution); - } - - single_value_ = operation->is_single_value(); - } -} -void ReadBufferOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - if (single_value_) { - /* write buffer has a single value stored at (0,0) */ - buffer_->read(output, 0, 0); - } - else { - switch (sampler) { - case PixelSampler::Nearest: - buffer_->read(output, x, y); - break; - case PixelSampler::Bilinear: - default: - buffer_->read_bilinear(output, x, y); - break; - case PixelSampler::Bicubic: - buffer_->read_bilinear(output, x, y); - break; - } - } -} - -void ReadBufferOperation::execute_pixel_extend(float output[4], - float x, - float y, - PixelSampler sampler, - MemoryBufferExtend extend_x, - MemoryBufferExtend extend_y) -{ - if (single_value_) { - /* write buffer has a single value stored at (0,0) */ - buffer_->read(output, 0, 0); - } - else if (sampler == PixelSampler::Nearest) { - buffer_->read(output, x, y, extend_x, extend_y); - } - else { - buffer_->read_bilinear(output, x, y, extend_x, extend_y); - } -} - -void ReadBufferOperation::execute_pixel_filtered( - float output[4], float x, float y, float dx[2], float dy[2]) -{ - if (single_value_) { - /* write buffer has a single value stored at (0,0) */ - buffer_->read(output, 0, 0); - } - else { - const float uv[2] = {x, y}; - const float deriv[2][2] = {{dx[0], dx[1]}, {dy[0], dy[1]}}; - buffer_->readEWA(output, uv, deriv); - } -} - -bool ReadBufferOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - if (this == read_operation) { - BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax); - return true; - } - return false; -} - -void ReadBufferOperation::read_resolution_from_write_buffer() -{ - if (memory_proxy_ != nullptr) { - WriteBufferOperation *operation = memory_proxy_->get_write_buffer_operation(); - this->set_width(operation->get_width()); - this->set_height(operation->get_height()); - } -} - -void ReadBufferOperation::update_memory_buffer() -{ - buffer_ = this->get_memory_proxy()->get_buffer(); -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.h b/source/blender/compositor/operations/COM_ReadBufferOperation.h deleted file mode 100644 index 0fbd7a9bf4e..00000000000 --- a/source/blender/compositor/operations/COM_ReadBufferOperation.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_MemoryBuffer.h" -#include "COM_MemoryProxy.h" -#include "COM_NodeOperation.h" - -namespace blender::compositor { - -class ReadBufferOperation : public NodeOperation { - private: - MemoryProxy *memory_proxy_; - bool single_value_; /* single value stored in buffer, copied from associated write operation */ - unsigned int offset_; - MemoryBuffer *buffer_; - - public: - ReadBufferOperation(DataType datatype); - void set_memory_proxy(MemoryProxy *memory_proxy) - { - memory_proxy_ = memory_proxy; - } - - MemoryProxy *get_memory_proxy() const - { - return memory_proxy_; - } - - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; - - void *initialize_tile_data(rcti *rect) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void execute_pixel_extend(float output[4], - float x, - float y, - PixelSampler sampler, - MemoryBufferExtend extend_x, - MemoryBufferExtend extend_y); - void execute_pixel_filtered( - float output[4], float x, float y, float dx[2], float dy[2]) override; - void set_offset(unsigned int offset) - { - offset_ = offset; - } - unsigned int get_offset() const - { - return offset_; - } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - MemoryBuffer *get_input_memory_buffer(MemoryBuffer **memory_buffers) override - { - return memory_buffers[offset_]; - } - void read_resolution_from_write_buffer(); - void update_memory_buffer(); -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_RenderLayersProg.cc b/source/blender/compositor/operations/COM_RenderLayersProg.cc index 02afacc2108..abdb2174f08 100644 --- a/source/blender/compositor/operations/COM_RenderLayersProg.cc +++ b/source/blender/compositor/operations/COM_RenderLayersProg.cc @@ -86,71 +86,6 @@ void RenderLayersProg::do_interpolation(float output[4], float x, float y, Pixel } } -void RenderLayersProg::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ -#if 0 - const RenderData *rd = rd_; - - int dx = 0, dy = 0; - - if (rd->mode & R_BORDER && rd->mode & R_CROP) { - /* see comment in execute_region describing coordinate mapping, - * here it simply goes other way around - */ - int full_width, full_height; - BKE_render_resolution(rd, false, &full_width, &full_height); - - dx = rd->border.xmin * full_width - (full_width - this->get_width()) / 2.0f; - dy = rd->border.ymin * full_height - (full_height - this->get_height()) / 2.0f; - } - - int ix = x - dx; - int iy = y - dy; -#endif - -#ifndef NDEBUG - { - const DataType data_type = this->get_output_socket()->get_data_type(); - int actual_element_size = elementsize_; - int expected_element_size; - if (data_type == DataType::Value) { - expected_element_size = 1; - } - else if (data_type == DataType::Vector) { - expected_element_size = 3; - } - else if (data_type == DataType::Color) { - expected_element_size = 4; - } - else { - expected_element_size = 0; - BLI_assert_msg(0, "Something horribly wrong just happened"); - } - BLI_assert(expected_element_size == actual_element_size); - } -#endif - - if (input_buffer_ == nullptr) { - int elemsize = elementsize_; - if (elemsize == 1) { - output[0] = 0.0f; - } - else if (elemsize == 3) { - zero_v3(output); - } - else { - BLI_assert(elemsize == 4); - zero_v4(output); - } - } - else { - do_interpolation(output, x, y, sampler); - } -} - void RenderLayersProg::deinit_execution() { input_buffer_ = nullptr; @@ -240,21 +175,6 @@ void RenderLayersProg::update_memory_buffer_partial(MemoryBuffer *output, /* ******** Render Layers AO Operation ******** */ -void RenderLayersAOOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float *input_buffer = this->get_input_buffer(); - if (input_buffer == nullptr) { - zero_v3(output); - } - else { - do_interpolation(output, x, y, sampler); - } - output[3] = 1.0f; -} - void RenderLayersAOOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) @@ -272,23 +192,6 @@ void RenderLayersAOOperation::update_memory_buffer_partial(MemoryBuffer *output, /* ******** Render Layers Alpha Operation ******** */ -void RenderLayersAlphaProg::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float *input_buffer = this->get_input_buffer(); - - if (input_buffer == nullptr) { - output[0] = 0.0f; - } - else { - float temp[4]; - do_interpolation(temp, x, y, sampler); - output[0] = temp[3]; - } -} - void RenderLayersAlphaProg::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) @@ -305,26 +208,6 @@ void RenderLayersAlphaProg::update_memory_buffer_partial(MemoryBuffer *output, /* ******** Render Layers Depth Operation ******** */ -void RenderLayersDepthProg::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - int ix = x; - int iy = y; - float *input_buffer = this->get_input_buffer(); - - if (input_buffer == nullptr || ix < 0 || iy < 0 || ix >= int(this->get_width()) || - iy >= int(this->get_height())) - { - output[0] = 10e10f; - } - else { - uint offset = (iy * this->get_width() + ix); - output[0] = input_buffer[offset]; - } -} - void RenderLayersDepthProg::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span /*inputs*/) diff --git a/source/blender/compositor/operations/COM_RenderLayersProg.h b/source/blender/compositor/operations/COM_RenderLayersProg.h index 40aa4c66078..5d5ecc638cf 100644 --- a/source/blender/compositor/operations/COM_RenderLayersProg.h +++ b/source/blender/compositor/operations/COM_RenderLayersProg.h @@ -111,7 +111,6 @@ class RenderLayersProg : public MultiThreadedOperation { } void init_execution() override; void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; std::unique_ptr get_meta_data() override; @@ -126,7 +125,6 @@ class RenderLayersAOOperation : public RenderLayersProg { : RenderLayersProg(pass_name, type, elementsize) { } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -139,7 +137,6 @@ class RenderLayersAlphaProg : public RenderLayersProg { : RenderLayersProg(pass_name, type, elementsize) { } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -152,7 +149,6 @@ class RenderLayersDepthProg : public RenderLayersProg { : RenderLayersProg(pass_name, type, elementsize) { } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_RotateOperation.cc b/source/blender/compositor/operations/COM_RotateOperation.cc index d4d69364204..4c3f7880a96 100644 --- a/source/blender/compositor/operations/COM_RotateOperation.cc +++ b/source/blender/compositor/operations/COM_RotateOperation.cc @@ -14,8 +14,6 @@ RotateOperation::RotateOperation() this->add_input_socket(DataType::Value, ResizeMode::None); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - image_socket_ = nullptr; - degree_socket_ = nullptr; do_degree2_rad_conversion_ = false; is_degree_set_ = false; sampler_ = PixelSampler::Bilinear; @@ -113,44 +111,19 @@ void RotateOperation::get_rotation_canvas(const rcti &input_canvas, BLI_rcti_translate(&r_canvas, -offset_x, -offset_y); } -void RotateOperation::init_data() -{ - if (execution_model_ == eExecutionModel::Tiled) { - get_rotation_center(get_canvas(), center_x_, center_y_); - } -} - -void RotateOperation::init_execution() -{ - image_socket_ = this->get_input_socket_reader(0); - degree_socket_ = this->get_input_socket_reader(1); -} - -void RotateOperation::deinit_execution() -{ - image_socket_ = nullptr; - degree_socket_ = nullptr; -} +void RotateOperation::init_data() {} inline void RotateOperation::ensure_degree() { if (!is_degree_set_) { - float degree[4]; - switch (execution_model_) { - case eExecutionModel::Tiled: - degree_socket_->read_sampled(degree, 0, 0, PixelSampler::Nearest); - break; - case eExecutionModel::FullFrame: - degree[0] = get_input_operation(DEGREE_INPUT_INDEX)->get_constant_value_default(0.0f); - break; - } + float degree = get_input_operation(DEGREE_INPUT_INDEX)->get_constant_value_default(0.0f); double rad; if (do_degree2_rad_conversion_) { - rad = DEG2RAD(double(degree[0])); + rad = DEG2RAD(double(degree)); } else { - rad = degree[0]; + rad = degree; } cosine_ = cos(rad); sine_ = sin(rad); @@ -159,59 +132,8 @@ inline void RotateOperation::ensure_degree() } } -void RotateOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - ensure_degree(); - const float dy = y - center_y_; - const float dx = x - center_x_; - const float nx = center_x_ + (cosine_ * dx + sine_ * dy); - const float ny = center_y_ + (-sine_ * dx + cosine_ * dy); - image_socket_->read_sampled(output, nx, ny, sampler); -} - -bool RotateOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - ensure_degree(); - rcti new_input; - - const float dxmin = input->xmin - center_x_; - const float dymin = input->ymin - center_y_; - const float dxmax = input->xmax - center_x_; - const float dymax = input->ymax - center_y_; - - const float x1 = center_x_ + (cosine_ * dxmin + sine_ * dymin); - const float x2 = center_x_ + (cosine_ * dxmax + sine_ * dymin); - const float x3 = center_x_ + (cosine_ * dxmin + sine_ * dymax); - const float x4 = center_x_ + (cosine_ * dxmax + sine_ * dymax); - const float y1 = center_y_ + (-sine_ * dxmin + cosine_ * dymin); - const float y2 = center_y_ + (-sine_ * dxmax + cosine_ * dymin); - const float y3 = center_y_ + (-sine_ * dxmin + cosine_ * dymax); - const float y4 = center_y_ + (-sine_ * dxmax + cosine_ * dymax); - const float minx = std::min(x1, std::min(x2, std::min(x3, x4))); - const float maxx = std::max(x1, std::max(x2, std::max(x3, x4))); - const float miny = std::min(y1, std::min(y2, std::min(y3, y4))); - const float maxy = std::max(y1, std::max(y2, std::max(y3, y4))); - - new_input.xmax = ceil(maxx) + 1; - new_input.xmin = floor(minx) - 1; - new_input.ymax = ceil(maxy) + 1; - new_input.ymin = floor(miny) - 1; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void RotateOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { - if (execution_model_ == eExecutionModel::Tiled) { - NodeOperation::determine_canvas(preferred_area, r_area); - return; - } - const bool image_determined = get_input_socket(IMAGE_INPUT_INDEX)->determine_canvas(preferred_area, r_area); if (image_determined) { diff --git a/source/blender/compositor/operations/COM_RotateOperation.h b/source/blender/compositor/operations/COM_RotateOperation.h index 150e5c4d667..536153e3f9a 100644 --- a/source/blender/compositor/operations/COM_RotateOperation.h +++ b/source/blender/compositor/operations/COM_RotateOperation.h @@ -13,12 +13,6 @@ class RotateOperation : public MultiThreadedOperation { constexpr static int IMAGE_INPUT_INDEX = 0; constexpr static int DEGREE_INPUT_INDEX = 1; - SocketReader *image_socket_; - SocketReader *degree_socket_; - /* TODO(manzanilla): to be removed with tiled implementation. */ - float center_x_; - float center_y_; - float cosine_; float sine_; bool do_degree2_rad_conversion_; @@ -57,13 +51,7 @@ class RotateOperation : public MultiThreadedOperation { float cosine, rcti &r_canvas); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void init_data() override; - void init_execution() override; - void deinit_execution() override; void set_do_degree2_rad_conversion(bool abool) { diff --git a/source/blender/compositor/operations/COM_SMAAOperation.cc b/source/blender/compositor/operations/COM_SMAAOperation.cc index 32204cb7aea..f49a069a81e 100644 --- a/source/blender/compositor/operations/COM_SMAAOperation.cc +++ b/source/blender/compositor/operations/COM_SMAAOperation.cc @@ -42,18 +42,6 @@ namespace blender::compositor { /*-----------------------------------------------------------------------------*/ /* Internal Functions to Sample Pixel Color from Image */ -/* TODO(manzanilla): to be removed with tiled implementation. Replace it with - * #buffer->read_elem_checked. */ -static inline void sample(SocketReader *reader, int x, int y, float color[4]) -{ - if (x < 0 || x >= reader->get_width() || y < 0 || y >= reader->get_height()) { - color[0] = color[1] = color[2] = color[3] = 0.0; - return; - } - - reader->read(color, x, y, nullptr); -} - static inline void sample(MemoryBuffer *reader, int x, int y, float color[4]) { reader->read_elem_checked(x, y, color); @@ -152,26 +140,11 @@ SMAAEdgeDetectionOperation::SMAAEdgeDetectionOperation() this->add_input_socket(DataType::Color); /* image */ this->add_input_socket(DataType::Value); /* Depth, material ID, etc. TODO: currently unused. */ this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - image_reader_ = nullptr; - value_reader_ = nullptr; this->set_threshold(CMP_DEFAULT_SMAA_THRESHOLD); this->set_local_contrast_adaptation_factor(CMP_DEFAULT_SMAA_CONTRAST_LIMIT); } -void SMAAEdgeDetectionOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); - value_reader_ = this->get_input_socket_reader(1); -} - -void SMAAEdgeDetectionOperation::deinit_execution() -{ - image_reader_ = nullptr; - value_reader_ = nullptr; -} - void SMAAEdgeDetectionOperation::set_threshold(float threshold) { /* UI values are between 0 and 1 for simplicity but algorithm expects values between 0 and 0.5 */ @@ -184,18 +157,6 @@ void SMAAEdgeDetectionOperation::set_local_contrast_adaptation_factor(float fact contrast_limit_ = scalenorm(1, 10, factor); } -bool SMAAEdgeDetectionOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - new_input.xmax = input->xmax + 1; - new_input.xmin = input->xmin - 2; - new_input.ymax = input->ymax + 1; - new_input.ymin = input->ymin - 2; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void SMAAEdgeDetectionOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) @@ -206,87 +167,6 @@ void SMAAEdgeDetectionOperation::get_area_of_interest(const int /*input_idx*/, r_input_area.ymin = output_area.ymin - 2; } -void SMAAEdgeDetectionOperation::execute_pixel(float output[4], int x, int y, void * /*data*/) -{ - float color[4]; - - /* Calculate luma deltas: */ - sample(image_reader_, x, y, color); - float L = IMB_colormanagement_get_luminance(color); - sample(image_reader_, x - 1, y, color); - float Lleft = IMB_colormanagement_get_luminance(color); - sample(image_reader_, x, y - 1, color); - float Ltop = IMB_colormanagement_get_luminance(color); - float Dleft = fabsf(L - Lleft); - float Dtop = fabsf(L - Ltop); - - /* We do the usual threshold: */ - output[0] = (x > 0 && Dleft >= threshold_) ? 1.0f : 0.0f; - output[1] = (y > 0 && Dtop >= threshold_) ? 1.0f : 0.0f; - output[2] = 0.0f; - output[3] = 1.0f; - - /* Then discard if there is no edge: */ - if (is_zero_v2(output)) { - return; - } - - /* Calculate right and bottom deltas: */ - sample(image_reader_, x + 1, y, color); - float Lright = IMB_colormanagement_get_luminance(color); - sample(image_reader_, x, y + 1, color); - float Lbottom = IMB_colormanagement_get_luminance(color); - float Dright = fabsf(L - Lright); - float Dbottom = fabsf(L - Lbottom); - - /* Calculate the maximum delta in the direct neighborhood: */ - float max_delta = fmaxf(fmaxf(Dleft, Dright), fmaxf(Dtop, Dbottom)); - - /* Calculate luma used for both left and top edges: */ - sample(image_reader_, x - 1, y - 1, color); - float Llefttop = IMB_colormanagement_get_luminance(color); - - /* Left edge */ - if (output[0] != 0.0f) { - /* Calculate deltas around the left pixel: */ - sample(image_reader_, x - 2, y, color); - float Lleftleft = IMB_colormanagement_get_luminance(color); - sample(image_reader_, x - 1, y + 1, color); - float Lleftbottom = IMB_colormanagement_get_luminance(color); - float Dleftleft = fabsf(Lleft - Lleftleft); - float Dlefttop = fabsf(Lleft - Llefttop); - float Dleftbottom = fabsf(Lleft - Lleftbottom); - - /* Calculate the final maximum delta: */ - max_delta = fmaxf(max_delta, fmaxf(Dleftleft, fmaxf(Dlefttop, Dleftbottom))); - - /* Local contrast adaptation: */ - if (max_delta > contrast_limit_ * Dleft) { - output[0] = 0.0f; - } - } - - /* Top edge */ - if (output[1] != 0.0f) { - /* Calculate top-top delta: */ - sample(image_reader_, x, y - 2, color); - float Ltoptop = IMB_colormanagement_get_luminance(color); - sample(image_reader_, x + 1, y - 1, color); - float Ltopright = IMB_colormanagement_get_luminance(color); - float Dtoptop = fabsf(Ltop - Ltoptop); - float Dtopleft = fabsf(Ltop - Llefttop); - float Dtopright = fabsf(Ltop - Ltopright); - - /* Calculate the final maximum delta: */ - max_delta = fmaxf(max_delta, fmaxf(Dtoptop, fmaxf(Dtopleft, Dtopright))); - - /* Local contrast adaptation: */ - if (max_delta > contrast_limit_ * Dtop) { - output[1] = 0.0f; - } - } -} - void SMAAEdgeDetectionOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -383,128 +263,16 @@ SMAABlendingWeightCalculationOperation::SMAABlendingWeightCalculationOperation() { this->add_input_socket(DataType::Color); /* edges */ this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - image_reader_ = nullptr; this->set_corner_rounding(CMP_DEFAULT_SMAA_CORNER_ROUNDING); } -void *SMAABlendingWeightCalculationOperation::initialize_tile_data(rcti *rect) -{ - return get_input_operation(0)->initialize_tile_data(rect); -} - -void SMAABlendingWeightCalculationOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); - if (execution_model_ == eExecutionModel::Tiled) { - sample_image_fn_ = [=](int x, int y, float *out) { sample(image_reader_, x, y, out); }; - } -} - void SMAABlendingWeightCalculationOperation::set_corner_rounding(float rounding) { /* UI values are between 0 and 1 for simplicity but algorithm expects values between 0 and 100 */ corner_rounding_ = int(scalenorm(0, 100, rounding)); } -void SMAABlendingWeightCalculationOperation::execute_pixel(float output[4], - int x, - int y, - void * /*data*/) -{ - float edges[4], c[4]; - - zero_v4(output); - sample(image_reader_, x, y, edges); - - /* Edge at north */ - if (edges[1] > 0.0f) { - /* Diagonals have both north and west edges, so calculating weights for them */ - /* in one of the boundaries is enough. */ - calculate_diag_weights(x, y, edges, output); - - /* We give priority to diagonals, so if we find a diagonal we skip. */ - /* horizontal/vertical processing. */ - if (!is_zero_v2(output)) { - return; - } - - /* Find the distance to the left and the right: */ - int left = search_xleft(x, y); - int right = search_xright(x, y); - int d1 = x - left, d2 = right - x; - - /* Fetch the left and right crossing edges: */ - int e1 = 0, e2 = 0; - sample(image_reader_, left, y - 1, c); - if (c[0] > 0.0) { - e1 += 1; - } - sample(image_reader_, left, y, c); - if (c[0] > 0.0) { - e1 += 2; - } - sample(image_reader_, right + 1, y - 1, c); - if (c[0] > 0.0) { - e2 += 1; - } - sample(image_reader_, right + 1, y, c); - if (c[0] > 0.0) { - e2 += 2; - } - - /* Ok, we know how this pattern looks like, now it is time for getting */ - /* the actual area: */ - area(d1, d2, e1, e2, output); /* R, G */ - - /* Fix corners: */ - if (corner_rounding_) { - detect_horizontal_corner_pattern(output, left, right, y, d1, d2); - } - } - - /* Edge at west */ - if (edges[0] > 0.0f) { - /* Did we already do diagonal search for this west edge from the left neighboring pixel? */ - if (is_vertical_search_unneeded(x, y)) { - return; - } - - /* Find the distance to the top and the bottom: */ - int top = search_yup(x, y); - int bottom = search_ydown(x, y); - int d1 = y - top, d2 = bottom - y; - - /* Fetch the top and bottom crossing edges: */ - int e1 = 0, e2 = 0; - sample(image_reader_, x - 1, top, c); - if (c[1] > 0.0) { - e1 += 1; - } - sample(image_reader_, x, top, c); - if (c[1] > 0.0) { - e1 += 2; - } - sample(image_reader_, x - 1, bottom + 1, c); - if (c[1] > 0.0) { - e2 += 1; - } - sample(image_reader_, x, bottom + 1, c); - if (c[1] > 0.0) { - e2 += 2; - } - - /* Get the area for this direction: */ - area(d1, d2, e1, e2, output + 2); /* B, A */ - - /* Fix corners: */ - if (corner_rounding_) { - detect_vertical_corner_pattern(output + 2, x, top, bottom, d1, d2); - } - } -} - void SMAABlendingWeightCalculationOperation::update_memory_buffer_started( MemoryBuffer * /*output*/, const rcti & /*out_area*/, Span inputs) { @@ -612,26 +380,6 @@ void SMAABlendingWeightCalculationOperation::update_memory_buffer_partial( } } -void SMAABlendingWeightCalculationOperation::deinit_execution() -{ - image_reader_ = nullptr; -} - -bool SMAABlendingWeightCalculationOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - new_input.xmax = input->xmax + fmax(SMAA_MAX_SEARCH_STEPS, SMAA_MAX_SEARCH_STEPS_DIAG + 1); - new_input.xmin = input->xmin - - fmax(fmax(SMAA_MAX_SEARCH_STEPS - 1, 1), SMAA_MAX_SEARCH_STEPS_DIAG + 1); - new_input.ymax = input->ymax + fmax(SMAA_MAX_SEARCH_STEPS, SMAA_MAX_SEARCH_STEPS_DIAG); - new_input.ymin = input->ymin - - fmax(fmax(SMAA_MAX_SEARCH_STEPS - 1, 1), SMAA_MAX_SEARCH_STEPS_DIAG); - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void SMAABlendingWeightCalculationOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) @@ -990,69 +738,7 @@ SMAANeighborhoodBlendingOperation::SMAANeighborhoodBlendingOperation() this->add_input_socket(DataType::Color); /* image */ this->add_input_socket(DataType::Color); /* blend */ this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - image1Reader_ = nullptr; - image2Reader_ = nullptr; -} - -void *SMAANeighborhoodBlendingOperation::initialize_tile_data(rcti *rect) -{ - return get_input_operation(0)->initialize_tile_data(rect); -} - -void SMAANeighborhoodBlendingOperation::init_execution() -{ - image1Reader_ = this->get_input_socket_reader(0); - image2Reader_ = this->get_input_socket_reader(1); -} - -void SMAANeighborhoodBlendingOperation::execute_pixel(float output[4], - int x, - int y, - void * /*data*/) -{ - float w[4]; - - /* Fetch the blending weights for current pixel: */ - sample(image2Reader_, x, y, w); - float left = w[2], top = w[0]; - sample(image2Reader_, x + 1, y, w); - float right = w[3]; - sample(image2Reader_, x, y + 1, w); - float bottom = w[1]; - - /* Is there any blending weight with a value greater than 0.0? */ - if (right + bottom + left + top < 1e-5f) { - sample(image1Reader_, x, y, output); - return; - } - - /* Calculate the blending offsets: */ - void (*samplefunc)(SocketReader *reader, int x, int y, float xoffset, float color[4]); - float offset1, offset2, weight1, weight2, color1[4], color2[4]; - - if (fmaxf(right, left) > fmaxf(bottom, top)) { /* max(horizontal) > max(vertical) */ - samplefunc = sample_bilinear_horizontal; - offset1 = right; - offset2 = -left; - weight1 = right / (right + left); - weight2 = left / (right + left); - } - else { - samplefunc = sample_bilinear_vertical; - offset1 = bottom; - offset2 = -top; - weight1 = bottom / (bottom + top); - weight2 = top / (bottom + top); - } - - /* We exploit bilinear filtering to mix current pixel with the chosen neighbor: */ - samplefunc(image1Reader_, x, y, offset1, color1); - samplefunc(image1Reader_, x, y, offset2, color2); - - mul_v4_v4fl(output, color1, weight1); - madd_v4_v4fl(output, color2, weight2); } void SMAANeighborhoodBlendingOperation::update_memory_buffer_partial(MemoryBuffer *output, @@ -1108,25 +794,6 @@ void SMAANeighborhoodBlendingOperation::update_memory_buffer_partial(MemoryBuffe } } -void SMAANeighborhoodBlendingOperation::deinit_execution() -{ - image1Reader_ = nullptr; - image2Reader_ = nullptr; -} - -bool SMAANeighborhoodBlendingOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - new_input.xmax = input->xmax + 1; - new_input.xmin = input->xmin - 1; - new_input.ymax = input->ymax + 1; - new_input.ymin = input->ymin - 1; - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void SMAANeighborhoodBlendingOperation::get_area_of_interest(const int /*input_idx*/, const rcti &output_area, rcti &r_input_area) diff --git a/source/blender/compositor/operations/COM_SMAAOperation.h b/source/blender/compositor/operations/COM_SMAAOperation.h index d82346313bd..845611705e2 100644 --- a/source/blender/compositor/operations/COM_SMAAOperation.h +++ b/source/blender/compositor/operations/COM_SMAAOperation.h @@ -13,38 +13,16 @@ namespace blender::compositor { class SMAAEdgeDetectionOperation : public MultiThreadedOperation { protected: - SocketReader *image_reader_; - SocketReader *value_reader_; - float threshold_; float contrast_limit_; public: SMAAEdgeDetectionOperation(); - /** - * the inner loop of this program - */ - virtual void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_threshold(float threshold); void set_local_contrast_adaptation_factor(float factor); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -56,35 +34,14 @@ class SMAAEdgeDetectionOperation : public MultiThreadedOperation { class SMAABlendingWeightCalculationOperation : public MultiThreadedOperation { private: - SocketReader *image_reader_; std::function sample_image_fn_; int corner_rounding_; public: SMAABlendingWeightCalculationOperation(); - /** - * the inner loop of this program - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_corner_rounding(float rounding); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_started(MemoryBuffer *output, const rcti &area, @@ -123,33 +80,9 @@ class SMAABlendingWeightCalculationOperation : public MultiThreadedOperation { /* Neighborhood Blending (Third Pass) */ class SMAANeighborhoodBlendingOperation : public MultiThreadedOperation { - private: - SocketReader *image1Reader_; - SocketReader *image2Reader_; - public: SMAANeighborhoodBlendingOperation(); - /** - * the inner loop of this program - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cc b/source/blender/compositor/operations/COM_ScaleOperation.cc index 3194245a9dd..e59f53807ae 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.cc +++ b/source/blender/compositor/operations/COM_ScaleOperation.cc @@ -32,9 +32,6 @@ ScaleOperation::ScaleOperation(DataType data_type) : BaseScaleOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(data_type); - input_operation_ = nullptr; - input_xoperation_ = nullptr; - input_yoperation_ = nullptr; flags_.can_be_constant = true; } @@ -97,20 +94,6 @@ void ScaleOperation::init_data() canvas_center_y_ = canvas_.ymin + get_height() / 2.0f; } -void ScaleOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); - input_xoperation_ = this->get_input_socket_reader(1); - input_yoperation_ = this->get_input_socket_reader(2); -} - -void ScaleOperation::deinit_execution() -{ - input_operation_ = nullptr; - input_xoperation_ = nullptr; - input_yoperation_ = nullptr; -} - void ScaleOperation::get_scale_offset(const rcti &input_canvas, const rcti &scale_canvas, float &r_scale_offset_x, @@ -194,11 +177,6 @@ void ScaleOperation::update_memory_buffer_partial(MemoryBuffer *output, void ScaleOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { - if (execution_model_ == eExecutionModel::Tiled) { - NodeOperation::determine_canvas(preferred_area, r_area); - return; - } - const bool image_determined = get_input_socket(IMAGE_INPUT_INDEX)->determine_canvas(preferred_area, r_area); if (image_determined) { @@ -232,127 +210,11 @@ ScaleRelativeOperation::ScaleRelativeOperation() : ScaleOperation() {} ScaleRelativeOperation::ScaleRelativeOperation(DataType data_type) : ScaleOperation(data_type) {} -void ScaleRelativeOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - PixelSampler effective_sampler = get_effective_sampler(sampler); - - float scaleX[4]; - float scaleY[4]; - - input_xoperation_->read_sampled(scaleX, x, y, effective_sampler); - input_yoperation_->read_sampled(scaleY, x, y, effective_sampler); - - const float scx = scaleX[0]; - const float scy = scaleY[0]; - - float nx = this->canvas_center_x_ + (x - this->canvas_center_x_) / scx; - float ny = this->canvas_center_y_ + (y - this->canvas_center_y_) / scy; - input_operation_->read_sampled(output, nx, ny, effective_sampler); -} - -bool ScaleRelativeOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - if (!variable_size_) { - float scaleX[4]; - float scaleY[4]; - - input_xoperation_->read_sampled(scaleX, 0, 0, PixelSampler::Nearest); - input_yoperation_->read_sampled(scaleY, 0, 0, PixelSampler::Nearest); - - const float scx = scaleX[0]; - const float scy = scaleY[0]; - - new_input.xmax = this->canvas_center_x_ + (input->xmax - this->canvas_center_x_) / scx + 1; - new_input.xmin = this->canvas_center_x_ + (input->xmin - this->canvas_center_x_) / scx - 1; - new_input.ymax = this->canvas_center_y_ + (input->ymax - this->canvas_center_y_) / scy + 1; - new_input.ymin = this->canvas_center_y_ + (input->ymin - this->canvas_center_y_) / scy - 1; - } - else { - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - } - return BaseScaleOperation::determine_depending_area_of_interest( - &new_input, read_operation, output); -} - -void ScaleAbsoluteOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - PixelSampler effective_sampler = get_effective_sampler(sampler); - - float scaleX[4]; - float scaleY[4]; - - input_xoperation_->read_sampled(scaleX, x, y, effective_sampler); - input_yoperation_->read_sampled(scaleY, x, y, effective_sampler); - - const float scx = scaleX[0]; /* Target absolute scale. */ - const float scy = scaleY[0]; /* Target absolute scale. */ - - const float width = this->get_width(); - const float height = this->get_height(); - /* Divide. */ - float relative_xscale = scx / width; - float relative_yscale = scy / height; - - float nx = this->canvas_center_x_ + (x - this->canvas_center_x_) / relative_xscale; - float ny = this->canvas_center_y_ + (y - this->canvas_center_y_) / relative_yscale; - - input_operation_->read_sampled(output, nx, ny, effective_sampler); -} - -bool ScaleAbsoluteOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - if (!variable_size_) { - float scaleX[4]; - float scaleY[4]; - - input_xoperation_->read_sampled(scaleX, 0, 0, PixelSampler::Nearest); - input_yoperation_->read_sampled(scaleY, 0, 0, PixelSampler::Nearest); - - const float scx = scaleX[0]; - const float scy = scaleY[0]; - const float width = this->get_width(); - const float height = this->get_height(); - /* Divide. */ - float relateve_xscale = scx / width; - float relateve_yscale = scy / height; - - new_input.xmax = this->canvas_center_x_ + - (input->xmax - this->canvas_center_x_) / relateve_xscale; - new_input.xmin = this->canvas_center_x_ + - (input->xmin - this->canvas_center_x_) / relateve_xscale; - new_input.ymax = this->canvas_center_y_ + - (input->ymax - this->canvas_center_y_) / relateve_yscale; - new_input.ymin = this->canvas_center_y_ + - (input->ymin - this->canvas_center_y_) / relateve_yscale; - } - else { - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - } - return ScaleOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - ScaleFixedSizeOperation::ScaleFixedSizeOperation() : BaseScaleOperation() { this->add_input_socket(DataType::Color, ResizeMode::None); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - input_operation_ = nullptr; is_offset_ = false; } @@ -395,7 +257,7 @@ void ScaleFixedSizeOperation::init_data(const rcti &input_canvas) const float div = asp_src / asp_dst; rel_x_ /= div; offset_x_ += ((w_src - (w_src * div)) / (w_src / w_dst)) / 2.0f; - if (is_crop_ && execution_model_ == eExecutionModel::FullFrame) { + if (is_crop_) { int fit_width = new_width_ * div; const int added_width = fit_width - new_width_; @@ -408,7 +270,7 @@ void ScaleFixedSizeOperation::init_data(const rcti &input_canvas) const float div = asp_dst / asp_src; rel_y_ /= div; offset_y_ += ((h_src - (h_src * div)) / (h_src / h_dst)) / 2.0f; - if (is_crop_ && execution_model_ == eExecutionModel::FullFrame) { + if (is_crop_) { int fit_height = new_height_ * div; const int added_height = fit_height - new_height_; @@ -423,47 +285,6 @@ void ScaleFixedSizeOperation::init_data(const rcti &input_canvas) /* *** end framing options *** */ } -void ScaleFixedSizeOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); -} - -void ScaleFixedSizeOperation::deinit_execution() -{ - input_operation_ = nullptr; -} - -void ScaleFixedSizeOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - PixelSampler effective_sampler = get_effective_sampler(sampler); - - if (is_offset_) { - float nx = ((x - offset_x_) * rel_x_); - float ny = ((y - offset_y_) * rel_y_); - input_operation_->read_sampled(output, nx, ny, effective_sampler); - } - else { - input_operation_->read_sampled(output, x * rel_x_, y * rel_y_, effective_sampler); - } -} - -bool ScaleFixedSizeOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input; - - new_input.xmax = (input->xmax - offset_x_) * rel_x_ + 1; - new_input.xmin = (input->xmin - offset_x_) * rel_x_; - new_input.ymax = (input->ymax - offset_y_) * rel_y_ + 1; - new_input.ymin = (input->ymin - offset_y_) * rel_y_; - - return BaseScaleOperation::determine_depending_area_of_interest( - &new_input, read_operation, output); -} - void ScaleFixedSizeOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { rcti local_preferred = preferred_area; @@ -475,12 +296,10 @@ void ScaleFixedSizeOperation::determine_canvas(const rcti &preferred_area, rcti if (input_determined) { init_data(input_canvas); r_area = input_canvas; - if (execution_model_ == eExecutionModel::FullFrame) { - r_area.xmin /= rel_x_; - r_area.ymin /= rel_y_; - r_area.xmin += offset_x_; - r_area.ymin += offset_y_; - } + r_area.xmin /= rel_x_; + r_area.ymin /= rel_y_; + r_area.xmin += offset_x_; + r_area.ymin += offset_y_; r_area.xmax = r_area.xmin + new_width_; r_area.ymax = r_area.ymin + new_height_; diff --git a/source/blender/compositor/operations/COM_ScaleOperation.h b/source/blender/compositor/operations/COM_ScaleOperation.h index 25895ba7a26..254a24b4284 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.h +++ b/source/blender/compositor/operations/COM_ScaleOperation.h @@ -29,7 +29,6 @@ class BaseScaleOperation : public MultiThreadedOperation { } int sampler_; - /* TODO(manzanilla): to be removed with tiled implementation. */ bool variable_size_; }; @@ -42,9 +41,6 @@ class ScaleOperation : public BaseScaleOperation { static constexpr int X_INPUT_INDEX = 1; static constexpr int Y_INPUT_INDEX = 2; - SocketReader *input_operation_; - SocketReader *input_xoperation_; - SocketReader *input_yoperation_; float canvas_center_x_; float canvas_center_y_; @@ -78,8 +74,6 @@ class ScaleOperation : public BaseScaleOperation { static void clamp_area_size_max(rcti &area, Size2f max_size); void init_data() override; - void init_execution() override; - void deinit_execution() override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, @@ -103,10 +97,6 @@ class ScaleRelativeOperation : public ScaleOperation { public: ScaleRelativeOperation(); ScaleRelativeOperation(DataType data_type); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; float get_relative_scale_x_factor(float /*width*/) override { @@ -121,11 +111,6 @@ class ScaleRelativeOperation : public ScaleOperation { class ScaleAbsoluteOperation : public ScaleOperation { public: - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - float get_relative_scale_x_factor(float width) override { return 1.0f / width; @@ -138,7 +123,6 @@ class ScaleAbsoluteOperation : public ScaleOperation { }; class ScaleFixedSizeOperation : public BaseScaleOperation { - SocketReader *input_operation_; int new_width_; int new_height_; float rel_x_; @@ -156,14 +140,8 @@ class ScaleFixedSizeOperation : public BaseScaleOperation { public: /** Absolute fixed size. */ ScaleFixedSizeOperation(); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void init_execution() override; - void deinit_execution() override; void set_new_width(int width) { new_width_ = width; diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc index 0fcf13bbbc9..9d9c5f92bae 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cc @@ -17,9 +17,7 @@ ScreenLensDistortionOperation::ScreenLensDistortionOperation() this->add_input_socket(DataType::Value); this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - flags_.complex = true; flags_.can_be_constant = true; - input_program_ = nullptr; distortion_ = 0.0f; dispersion_ = 0.0f; distortion_const_ = false; @@ -44,71 +42,26 @@ void ScreenLensDistortionOperation::init_data() cx_ = 0.5f * float(get_width()); cy_ = 0.5f * float(get_height()); - switch (execution_model_) { - case eExecutionModel::FullFrame: { - NodeOperation *distortion_op = get_input_operation(1); - NodeOperation *dispersion_op = get_input_operation(2); - if (!distortion_const_ && distortion_op->get_flags().is_constant_operation) { - distortion_ = static_cast(distortion_op)->get_constant_elem()[0]; - } - if (!dispersion_const_ && distortion_op->get_flags().is_constant_operation) { - dispersion_ = static_cast(dispersion_op)->get_constant_elem()[0]; - } - update_variables(distortion_, dispersion_); - break; - } - case eExecutionModel::Tiled: { - /* If both are constant, init variables once. */ - if (distortion_const_ && dispersion_const_) { - update_variables(distortion_, dispersion_); - variables_ready_ = true; - } - break; - } + NodeOperation *distortion_op = get_input_operation(1); + NodeOperation *dispersion_op = get_input_operation(2); + if (!distortion_const_ && distortion_op->get_flags().is_constant_operation) { + distortion_ = static_cast(distortion_op)->get_constant_elem()[0]; } + if (!dispersion_const_ && distortion_op->get_flags().is_constant_operation) { + dispersion_ = static_cast(dispersion_op)->get_constant_elem()[0]; + } + update_variables(distortion_, dispersion_); } void ScreenLensDistortionOperation::init_execution() { - input_program_ = this->get_input_socket_reader(0); - this->init_mutex(); + SocketReader *input_reader = this->get_input_socket_reader(0); uint rng_seed = uint(BLI_time_now_seconds_i() & UINT_MAX); - rng_seed ^= uint(POINTER_AS_INT(input_program_)); + rng_seed ^= uint(POINTER_AS_INT(input_reader)); rng_ = BLI_rng_new(rng_seed); } -void *ScreenLensDistortionOperation::initialize_tile_data(rcti * /*rect*/) -{ - void *buffer = input_program_->initialize_tile_data(nullptr); - - /* get distortion/dispersion values once, by reading inputs at (0,0) - * XXX this assumes invariable values (no image inputs), - * we don't have a nice generic system for that yet - */ - if (!variables_ready_) { - this->lock_mutex(); - - if (!distortion_const_) { - float result[4]; - get_input_socket_reader(1)->read_sampled(result, 0, 0, PixelSampler::Nearest); - distortion_ = result[0]; - } - if (!dispersion_const_) { - float result[4]; - get_input_socket_reader(2)->read_sampled(result, 0, 0, PixelSampler::Nearest); - dispersion_ = result[0]; - } - - update_variables(distortion_, dispersion_); - variables_ready_ = true; - - this->unlock_mutex(); - } - - return buffer; -} - void ScreenLensDistortionOperation::get_uv(const float xy[2], float uv[2]) const { uv[0] = sc_ * ((xy[0] + 0.5f) - cx_) / cx_; @@ -160,14 +113,7 @@ void ScreenLensDistortionOperation::accumulate(const MemoryBuffer *buffer, float xy[2]; distort_uv(uv, t, xy); - switch (execution_model_) { - case eExecutionModel::Tiled: - buffer->read_bilinear(color, xy[0], xy[1]); - break; - case eExecutionModel::FullFrame: - buffer->read_elem_bilinear(xy[0], xy[1], color); - break; - } + buffer->read_elem_bilinear(xy[0], xy[1], color); sum[a] += (1.0f - tz) * color[a]; sum[b] += (tz)*color[b]; @@ -176,48 +122,8 @@ void ScreenLensDistortionOperation::accumulate(const MemoryBuffer *buffer, } } -void ScreenLensDistortionOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - MemoryBuffer *buffer = (MemoryBuffer *)data; - float xy[2] = {float(x), float(y)}; - float uv[2]; - get_uv(xy, uv); - float uv_dot = len_squared_v2(uv); - - int count[3] = {0, 0, 0}; - float delta[3][2]; - float sum[4] = {0, 0, 0, 0}; - - bool valid_r = get_delta(uv_dot, k4_[0], uv, delta[0]); - bool valid_g = get_delta(uv_dot, k4_[1], uv, delta[1]); - bool valid_b = get_delta(uv_dot, k4_[2], uv, delta[2]); - - if (valid_r && valid_g && valid_b) { - accumulate(buffer, 0, 1, uv_dot, uv, delta, sum, count); - accumulate(buffer, 1, 2, uv_dot, uv, delta, sum, count); - - if (count[0]) { - output[0] = 2.0f * sum[0] / float(count[0]); - } - if (count[1]) { - output[1] = 2.0f * sum[1] / float(count[1]); - } - if (count[2]) { - output[2] = 2.0f * sum[2] / float(count[2]); - } - - /* set alpha */ - output[3] = 1.0f; - } - else { - zero_v4(output); - } -} - void ScreenLensDistortionOperation::deinit_execution() { - this->deinit_mutex(); - input_program_ = nullptr; BLI_rng_free(rng_); } @@ -236,121 +142,6 @@ void ScreenLensDistortionOperation::determineUV(float result[6], float x, float get_delta(uv_dot, k4_[2], uv, result + 4); } -bool ScreenLensDistortionOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_input_value; - new_input_value.xmin = 0; - new_input_value.ymin = 0; - new_input_value.xmax = 2; - new_input_value.ymax = 2; - - NodeOperation *operation = get_input_operation(1); - if (operation->determine_depending_area_of_interest(&new_input_value, read_operation, output)) { - return true; - } - - operation = get_input_operation(2); - if (operation->determine_depending_area_of_interest(&new_input_value, read_operation, output)) { - return true; - } - - /* XXX the original method of estimating the area-of-interest does not work - * it assumes a linear increase/decrease of mapped coordinates, which does not - * yield correct results for the area and leaves uninitialized buffer areas. - * So now just use the full image area, which may not be as efficient but works at least ... - */ -#if 1 - rcti image_input; - - operation = get_input_operation(0); - image_input.xmax = operation->get_width(); - image_input.xmin = 0; - image_input.ymax = operation->get_height(); - image_input.ymin = 0; - - if (operation->determine_depending_area_of_interest(&image_input, read_operation, output)) { - return true; - } - return false; -#else - rcti new_input; - const float margin = 2; - - BLI_rcti_init_minmax(&new_input); - - if (dispersion_const_ && distortion_const_) { - /* update from fixed distortion/dispersion */ -# define UPDATE_INPUT(x, y) \ - { \ - float coords[6]; \ - determineUV(coords, x, y); \ - new_input.xmin = min_ffff(new_input.xmin, coords[0], coords[2], coords[4]); \ - new_input.ymin = min_ffff(new_input.ymin, coords[1], coords[3], coords[5]); \ - new_input.xmax = max_ffff(new_input.xmax, coords[0], coords[2], coords[4]); \ - new_input.ymax = max_ffff(new_input.ymax, coords[1], coords[3], coords[5]); \ - } \ - (void)0 - - UPDATE_INPUT(input->xmin, input->xmax); - UPDATE_INPUT(input->xmin, input->ymax); - UPDATE_INPUT(input->xmax, input->ymax); - UPDATE_INPUT(input->xmax, input->ymin); - -# undef UPDATE_INPUT - } - else { - /* use maximum dispersion 1.0 if not const */ - float dispersion = dispersion_const_ ? dispersion_ : 1.0f; - -# define UPDATE_INPUT(x, y, distortion) \ - { \ - float coords[6]; \ - update_variables(distortion, dispersion); \ - determineUV(coords, x, y); \ - new_input.xmin = min_ffff(new_input.xmin, coords[0], coords[2], coords[4]); \ - new_input.ymin = min_ffff(new_input.ymin, coords[1], coords[3], coords[5]); \ - new_input.xmax = max_ffff(new_input.xmax, coords[0], coords[2], coords[4]); \ - new_input.ymax = max_ffff(new_input.ymax, coords[1], coords[3], coords[5]); \ - } \ - (void)0 - - if (distortion_const_) { - /* update from fixed distortion */ - UPDATE_INPUT(input->xmin, input->xmax, distortion_); - UPDATE_INPUT(input->xmin, input->ymax, distortion_); - UPDATE_INPUT(input->xmax, input->ymax, distortion_); - UPDATE_INPUT(input->xmax, input->ymin, distortion_); - } - else { - /* update from min/max distortion (-1..1) */ - UPDATE_INPUT(input->xmin, input->xmax, -1.0f); - UPDATE_INPUT(input->xmin, input->ymax, -1.0f); - UPDATE_INPUT(input->xmax, input->ymax, -1.0f); - UPDATE_INPUT(input->xmax, input->ymin, -1.0f); - - UPDATE_INPUT(input->xmin, input->xmax, 1.0f); - UPDATE_INPUT(input->xmin, input->ymax, 1.0f); - UPDATE_INPUT(input->xmax, input->ymax, 1.0f); - UPDATE_INPUT(input->xmax, input->ymin, 1.0f); - -# undef UPDATE_INPUT - } - } - - new_input.xmin -= margin; - new_input.ymin -= margin; - new_input.xmax += margin; - new_input.ymax += margin; - - operation = get_input_operation(0); - if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { - return true; - } - return false; -#endif -} - void ScreenLensDistortionOperation::update_variables(float distortion, float dispersion) { k_[1] = max_ff(min_ff(distortion, 1.0f), -0.999f); @@ -369,17 +160,10 @@ void ScreenLensDistortionOperation::update_variables(float distortion, float dis void ScreenLensDistortionOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { - switch (execution_model_) { - case eExecutionModel::FullFrame: { - set_determined_canvas_modifier([=](rcti &canvas) { - /* Ensure screen space. */ - BLI_rcti_translate(&canvas, -canvas.xmin, -canvas.ymin); - }); - break; - } - default: - break; - } + set_determined_canvas_modifier([=](rcti &canvas) { + /* Ensure screen space. */ + BLI_rcti_translate(&canvas, -canvas.xmin, -canvas.ymin); + }); NodeOperation::determine_canvas(preferred_area, r_area); } @@ -398,86 +182,8 @@ void ScreenLensDistortionOperation::get_area_of_interest(const int input_idx, * yield correct results for the area and leaves uninitialized buffer areas. * So now just use the full image area, which may not be as efficient but works at least ... */ -#if 1 NodeOperation *image = get_input_operation(0); r_input_area = image->get_canvas(); - -#else /* Original method in tiled implementation. */ - rcti new_input; - const float margin = 2; - - BLI_rcti_init_minmax(&new_input); - - if (dispersion_const_ && distortion_const_) { - /* update from fixed distortion/dispersion */ -# define UPDATE_INPUT(x, y) \ - { \ - float coords[6]; \ - determineUV(coords, x, y); \ - new_input.xmin = min_ffff(new_input.xmin, coords[0], coords[2], coords[4]); \ - new_input.ymin = min_ffff(new_input.ymin, coords[1], coords[3], coords[5]); \ - new_input.xmax = max_ffff(new_input.xmax, coords[0], coords[2], coords[4]); \ - new_input.ymax = max_ffff(new_input.ymax, coords[1], coords[3], coords[5]); \ - } \ - (void)0 - - UPDATE_INPUT(input->xmin, input->xmax); - UPDATE_INPUT(input->xmin, input->ymax); - UPDATE_INPUT(input->xmax, input->ymax); - UPDATE_INPUT(input->xmax, input->ymin); - -# undef UPDATE_INPUT - } - else { - /* use maximum dispersion 1.0 if not const */ - float dispersion = dispersion_const_ ? dispersion_ : 1.0f; - -# define UPDATE_INPUT(x, y, distortion) \ - { \ - float coords[6]; \ - update_variables(distortion, dispersion); \ - determineUV(coords, x, y); \ - new_input.xmin = min_ffff(new_input.xmin, coords[0], coords[2], coords[4]); \ - new_input.ymin = min_ffff(new_input.ymin, coords[1], coords[3], coords[5]); \ - new_input.xmax = max_ffff(new_input.xmax, coords[0], coords[2], coords[4]); \ - new_input.ymax = max_ffff(new_input.ymax, coords[1], coords[3], coords[5]); \ - } \ - (void)0 - - if (distortion_const_) { - /* update from fixed distortion */ - UPDATE_INPUT(input->xmin, input->xmax, distortion_); - UPDATE_INPUT(input->xmin, input->ymax, distortion_); - UPDATE_INPUT(input->xmax, input->ymax, distortion_); - UPDATE_INPUT(input->xmax, input->ymin, distortion_); - } - else { - /* update from min/max distortion (-1..1) */ - UPDATE_INPUT(input->xmin, input->xmax, -1.0f); - UPDATE_INPUT(input->xmin, input->ymax, -1.0f); - UPDATE_INPUT(input->xmax, input->ymax, -1.0f); - UPDATE_INPUT(input->xmax, input->ymin, -1.0f); - - UPDATE_INPUT(input->xmin, input->xmax, 1.0f); - UPDATE_INPUT(input->xmin, input->ymax, 1.0f); - UPDATE_INPUT(input->xmax, input->ymax, 1.0f); - UPDATE_INPUT(input->xmax, input->ymin, 1.0f); - -# undef UPDATE_INPUT - } - } - - new_input.xmin -= margin; - new_input.ymin -= margin; - new_input.xmax += margin; - new_input.ymax += margin; - - operation = get_input_operation(0); - if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { - return true; - } - return false; -#endif } void ScreenLensDistortionOperation::update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h index 18f49fe6ffd..c261c37d39e 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h @@ -13,10 +13,6 @@ namespace blender::compositor { class ScreenLensDistortionOperation : public MultiThreadedOperation { private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; struct RNG *rng_; bool fit_; @@ -38,20 +34,7 @@ class ScreenLensDistortionOperation : public MultiThreadedOperation { void init_data() override; - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - /** - * Deinitialize the execution - */ void deinit_execution() override; void set_fit(bool fit) @@ -68,10 +51,6 @@ class ScreenLensDistortionOperation : public MultiThreadedOperation { /** Set constant dispersion value */ void set_dispersion(float dispersion); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc index 5d036d273ca..7d26407ce42 100644 --- a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc +++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cc @@ -12,37 +12,9 @@ SetAlphaMultiplyOperation::SetAlphaMultiplyOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_color_ = nullptr; - input_alpha_ = nullptr; flags_.can_be_constant = true; } -void SetAlphaMultiplyOperation::init_execution() -{ - input_color_ = get_input_socket_reader(0); - input_alpha_ = get_input_socket_reader(1); -} - -void SetAlphaMultiplyOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float color_input[4]; - float alpha_input[4]; - - input_color_->read_sampled(color_input, x, y, sampler); - input_alpha_->read_sampled(alpha_input, x, y, sampler); - - mul_v4_v4fl(output, color_input, alpha_input[0]); -} - -void SetAlphaMultiplyOperation::deinit_execution() -{ - input_color_ = nullptr; - input_alpha_ = nullptr; -} - void SetAlphaMultiplyOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h index b29a8f36e5f..b1eb1b51b9c 100644 --- a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h +++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h @@ -14,18 +14,9 @@ namespace blender::compositor { * `output color.rgba = input color.rgba * input alpha` */ class SetAlphaMultiplyOperation : public MultiThreadedOperation { - private: - SocketReader *input_color_; - SocketReader *input_alpha_; - public: SetAlphaMultiplyOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc index fa5817a31fc..d0c12c251a7 100644 --- a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc +++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cc @@ -12,35 +12,9 @@ SetAlphaReplaceOperation::SetAlphaReplaceOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - input_color_ = nullptr; - input_alpha_ = nullptr; flags_.can_be_constant = true; } -void SetAlphaReplaceOperation::init_execution() -{ - input_color_ = get_input_socket_reader(0); - input_alpha_ = get_input_socket_reader(1); -} - -void SetAlphaReplaceOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float alpha_input[4]; - - input_color_->read_sampled(output, x, y, sampler); - input_alpha_->read_sampled(alpha_input, x, y, sampler); - output[3] = alpha_input[0]; -} - -void SetAlphaReplaceOperation::deinit_execution() -{ - input_color_ = nullptr; - input_alpha_ = nullptr; -} - void SetAlphaReplaceOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) diff --git a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h index fd3cfed84dd..899b056bffa 100644 --- a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h +++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h @@ -13,24 +13,9 @@ namespace blender::compositor { * it assumes we are in sRGB color space. */ class SetAlphaReplaceOperation : public MultiThreadedOperation { - private: - SocketReader *input_color_; - SocketReader *input_alpha_; - public: - /** - * Default constructor - */ SetAlphaReplaceOperation(); - /** - * the inner loop of this program - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_SetColorOperation.cc b/source/blender/compositor/operations/COM_SetColorOperation.cc index c9c54a4324c..8897f6b7d5c 100644 --- a/source/blender/compositor/operations/COM_SetColorOperation.cc +++ b/source/blender/compositor/operations/COM_SetColorOperation.cc @@ -12,14 +12,6 @@ SetColorOperation::SetColorOperation() flags_.is_set_operation = true; } -void SetColorOperation::execute_pixel_sampled(float output[4], - float /*x*/, - float /*y*/, - PixelSampler /*sampler*/) -{ - copy_v4_v4(output, color_); -} - void SetColorOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { r_area = preferred_area; diff --git a/source/blender/compositor/operations/COM_SetColorOperation.h b/source/blender/compositor/operations/COM_SetColorOperation.h index 13ab49cbe73..30a9774a9bc 100644 --- a/source/blender/compositor/operations/COM_SetColorOperation.h +++ b/source/blender/compositor/operations/COM_SetColorOperation.h @@ -64,11 +64,6 @@ class SetColorOperation : public ConstantOperation { copy_v4_v4(color_, value); } - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; }; diff --git a/source/blender/compositor/operations/COM_SetSamplerOperation.cc b/source/blender/compositor/operations/COM_SetSamplerOperation.cc index 78c283c9706..c1fc0793d8d 100644 --- a/source/blender/compositor/operations/COM_SetSamplerOperation.cc +++ b/source/blender/compositor/operations/COM_SetSamplerOperation.cc @@ -12,21 +12,4 @@ SetSamplerOperation::SetSamplerOperation() this->add_output_socket(DataType::Color); } -void SetSamplerOperation::init_execution() -{ - reader_ = this->get_input_socket_reader(0); -} -void SetSamplerOperation::deinit_execution() -{ - reader_ = nullptr; -} - -void SetSamplerOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - reader_->read_sampled(output, x, y, sampler_); -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_SetSamplerOperation.h b/source/blender/compositor/operations/COM_SetSamplerOperation.h index 87b96995c74..17e28bd3006 100644 --- a/source/blender/compositor/operations/COM_SetSamplerOperation.h +++ b/source/blender/compositor/operations/COM_SetSamplerOperation.h @@ -15,25 +15,14 @@ namespace blender::compositor { class SetSamplerOperation : public NodeOperation { private: PixelSampler sampler_; - SocketReader *reader_; public: - /** - * Default constructor - */ SetSamplerOperation(); void set_sampler(PixelSampler sampler) { sampler_ = sampler; } - - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void init_execution() override; - void deinit_execution() override; }; } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_SetValueOperation.cc b/source/blender/compositor/operations/COM_SetValueOperation.cc index 237bab490ce..79f04b1eb1a 100644 --- a/source/blender/compositor/operations/COM_SetValueOperation.cc +++ b/source/blender/compositor/operations/COM_SetValueOperation.cc @@ -12,14 +12,6 @@ SetValueOperation::SetValueOperation() flags_.is_set_operation = true; } -void SetValueOperation::execute_pixel_sampled(float output[4], - float /*x*/, - float /*y*/, - PixelSampler /*sampler*/) -{ - output[0] = value_; -} - void SetValueOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { r_area = preferred_area; diff --git a/source/blender/compositor/operations/COM_SetValueOperation.h b/source/blender/compositor/operations/COM_SetValueOperation.h index 9d075c565b4..9f503ab9d17 100644 --- a/source/blender/compositor/operations/COM_SetValueOperation.h +++ b/source/blender/compositor/operations/COM_SetValueOperation.h @@ -36,11 +36,6 @@ class SetValueOperation : public ConstantOperation { value_ = value; } - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; }; diff --git a/source/blender/compositor/operations/COM_SetVectorOperation.cc b/source/blender/compositor/operations/COM_SetVectorOperation.cc index 1d71833c8e7..557f3a94ba4 100644 --- a/source/blender/compositor/operations/COM_SetVectorOperation.cc +++ b/source/blender/compositor/operations/COM_SetVectorOperation.cc @@ -12,16 +12,6 @@ SetVectorOperation::SetVectorOperation() flags_.is_set_operation = true; } -void SetVectorOperation::execute_pixel_sampled(float output[4], - float /*x*/, - float /*y*/, - PixelSampler /*sampler*/) -{ - output[0] = vector_.x; - output[1] = vector_.y; - output[2] = vector_.z; -} - void SetVectorOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { r_area = preferred_area; diff --git a/source/blender/compositor/operations/COM_SetVectorOperation.h b/source/blender/compositor/operations/COM_SetVectorOperation.h index 9ae9366afc0..d91ca9a894e 100644 --- a/source/blender/compositor/operations/COM_SetVectorOperation.h +++ b/source/blender/compositor/operations/COM_SetVectorOperation.h @@ -65,11 +65,6 @@ class SetVectorOperation : public ConstantOperation { vector_.w = value; } - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; void set_vector(const float vector[3]) diff --git a/source/blender/compositor/operations/COM_SplitOperation.cc b/source/blender/compositor/operations/COM_SplitOperation.cc index 033dea840e7..add20b80844 100644 --- a/source/blender/compositor/operations/COM_SplitOperation.cc +++ b/source/blender/compositor/operations/COM_SplitOperation.cc @@ -11,41 +11,10 @@ SplitOperation::SplitOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - image1Input_ = nullptr; - image2Input_ = nullptr; flags_.can_be_constant = true; } -void SplitOperation::init_execution() -{ - /* When initializing the tree during initial load the width and height can be zero. */ - image1Input_ = get_input_socket_reader(0); - image2Input_ = get_input_socket_reader(1); -} - -void SplitOperation::deinit_execution() -{ - image1Input_ = nullptr; - image2Input_ = nullptr; -} - -void SplitOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - int perc = x_split_ ? split_percentage_ * this->get_width() / 100.0f : - split_percentage_ * this->get_height() / 100.0f; - bool image1 = x_split_ ? x >= perc : y >= perc; - if (image1) { - image1Input_->read_sampled(output, x, y, PixelSampler::Nearest); - } - else { - image2Input_->read_sampled(output, x, y, PixelSampler::Nearest); - } -} - void SplitOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { rcti unused_area = COM_AREA_NONE; diff --git a/source/blender/compositor/operations/COM_SplitOperation.h b/source/blender/compositor/operations/COM_SplitOperation.h index 16b6389b591..ff5ea9e4683 100644 --- a/source/blender/compositor/operations/COM_SplitOperation.h +++ b/source/blender/compositor/operations/COM_SplitOperation.h @@ -10,17 +10,11 @@ namespace blender::compositor { class SplitOperation : public MultiThreadedOperation { private: - SocketReader *image1Input_; - SocketReader *image2Input_; - float split_percentage_; bool x_split_; public: SplitOperation(); - void init_execution() override; - void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; void set_split_percentage(float split_percentage) { diff --git a/source/blender/compositor/operations/COM_SummedAreaTableOperation.cc b/source/blender/compositor/operations/COM_SummedAreaTableOperation.cc index f96ab032d64..276d120da1e 100644 --- a/source/blender/compositor/operations/COM_SummedAreaTableOperation.cc +++ b/source/blender/compositor/operations/COM_SummedAreaTableOperation.cc @@ -17,38 +17,9 @@ SummedAreaTableOperation::SummedAreaTableOperation() mode_ = eMode::Identity; - this->flags_.is_fullframe_operation = true; this->flags_.can_be_constant = true; } -void SummedAreaTableOperation::init_execution() -{ - SingleThreadedOperation::init_execution(); - image_reader_ = this->get_input_socket_reader(0); -} - -void SummedAreaTableOperation::deinit_execution() -{ - image_reader_ = nullptr; - SingleThreadedOperation::deinit_execution(); -} - -bool SummedAreaTableOperation::determine_depending_area_of_interest( - rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output) -{ - rcti image_input; - - NodeOperation *operation = get_input_operation(0); - image_input.xmax = operation->get_width(); - image_input.xmin = 0; - image_input.ymax = operation->get_height(); - image_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&image_input, read_operation, output)) { - return true; - } - return false; -} - void SummedAreaTableOperation::get_area_of_interest(int input_idx, const rcti & /*output_area*/, rcti &r_input_area) @@ -90,41 +61,6 @@ void SummedAreaTableOperation::update_memory_buffer(MemoryBuffer *output, }); } -MemoryBuffer *SummedAreaTableOperation::create_memory_buffer(rcti *area) -{ - /* Note: although this is a single threaded call, multithreading is used. */ - MemoryBuffer *output = new MemoryBuffer(DataType::Color, *area); - - /* First pass: copy input to output and sum horizontally. */ - threading::parallel_for( - IndexRange(area->ymin, area->ymax - area->ymin), 1, [&](const IndexRange range_y) { - for (const int y : range_y) { - float4 accumulated_color = float4(0.0f); - for (const int x : IndexRange(area->xmin, area->xmax - area->xmin)) { - float4 color; - image_reader_->read(&color.x, x, y, nullptr); - accumulated_color += mode_ == eMode::Squared ? color * color : color; - copy_v4_v4(output->get_elem(x, y), accumulated_color); - } - } - }); - - /* Second pass: vertical sum. */ - threading::parallel_for( - IndexRange(area->xmin, area->xmax - area->xmin), 1, [&](const IndexRange range_x) { - for (const int x : range_x) { - float4 accumulated_color = float4(0.0f); - for (const int y : IndexRange(area->ymin, area->ymax - area->ymin)) { - - accumulated_color += float4(output->get_elem(x, y)); - copy_v4_v4(output->get_elem(x, y), accumulated_color); - } - } - }); - - return output; -} - void SummedAreaTableOperation::set_mode(eMode mode) { mode_ = mode; @@ -135,52 +71,6 @@ SummedAreaTableOperation::eMode SummedAreaTableOperation::get_mode() return mode_; } -float4 summed_area_table_sum_tiled(SocketReader *buffer, const rcti &area) -{ - /* - * a, b, c and d are the bounding box of the given area. They are defined as follows: - * - * y - * â–² - * │ - * ├──────x───────x - * │ │c d│ - * ├──────x───────x - * │ │a b│ - * └──────┴───────┴──────► x - * - * Note: this is the same definition as in https://en.wikipedia.org/wiki/Summed-area_table - * but using the blender convention with the origin being at the lower left. - */ - - BLI_assert(area.xmin <= area.xmax && area.ymin <= area.ymax); - - int2 lower_bound(area.xmin, area.ymin); - int2 upper_bound(area.xmax, area.ymax); - - int2 corrected_lower_bound = lower_bound - int2(1, 1); - int2 corrected_upper_bound; - corrected_upper_bound[0] = math::min(int(buffer->get_width()) - 1, upper_bound[0]); - corrected_upper_bound[1] = math::min(int(buffer->get_height()) - 1, upper_bound[1]); - - float4 a, b, c, d, addend, substrahend; - buffer->read_sampled( - &a.x, corrected_upper_bound[0], corrected_upper_bound[1], PixelSampler::Nearest); - buffer->read_sampled( - &d.x, corrected_lower_bound[0], corrected_lower_bound[1], PixelSampler::Nearest); - addend = a + d; - - buffer->read_sampled( - &b.x, corrected_lower_bound[0], corrected_upper_bound[1], PixelSampler::Nearest); - buffer->read_sampled( - &c.x, corrected_upper_bound[0], corrected_lower_bound[1], PixelSampler::Nearest); - substrahend = b + c; - - float4 sum = addend - substrahend; - - return sum; -} - float4 summed_area_table_sum(MemoryBuffer *buffer, const rcti &area) { /* diff --git a/source/blender/compositor/operations/COM_SummedAreaTableOperation.h b/source/blender/compositor/operations/COM_SummedAreaTableOperation.h index e4766a56740..37bab63478a 100644 --- a/source/blender/compositor/operations/COM_SummedAreaTableOperation.h +++ b/source/blender/compositor/operations/COM_SummedAreaTableOperation.h @@ -4,14 +4,14 @@ #pragma once -#include "COM_SingleThreadedOperation.h" +#include "COM_NodeOperation.h" namespace blender::compositor { /** * \brief SummedAreaTableOperation class computes the summed area table. */ -class SummedAreaTableOperation : public SingleThreadedOperation { +class SummedAreaTableOperation : public NodeOperation { public: SummedAreaTableOperation(); @@ -21,36 +21,18 @@ class SummedAreaTableOperation : public SingleThreadedOperation { void set_mode(const eMode mode); eMode get_mode(); - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; - MemoryBuffer *create_memory_buffer(rcti *rect) override; - void update_memory_buffer(MemoryBuffer *output, const rcti &area, Span inputs) override; private: - SocketReader *image_reader_; eMode mode_; }; /* Computes the sum of the rectangular region defined by the given area from the * given summed area table. All coordinates within the area are included. */ float4 summed_area_table_sum(MemoryBuffer *buffer, const rcti &area); -float4 summed_area_table_sum_tiled(SocketReader *buffer, const rcti &area); } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.cc b/source/blender/compositor/operations/COM_SunBeamsOperation.cc index b519ecb7e0e..1449df2393c 100644 --- a/source/blender/compositor/operations/COM_SunBeamsOperation.cc +++ b/source/blender/compositor/operations/COM_SunBeamsOperation.cc @@ -18,65 +18,6 @@ SunBeamsOperation::SunBeamsOperation() this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); this->set_canvas_input_index(0); - - flags_.complex = true; -} - -void SunBeamsOperation::init_execution() -{ - input_program_ = this->get_input_socket_reader(0); -} - -void SunBeamsOperation::execute_pixel(float output[4], int x, int y, void * /* data */) -{ - const float2 input_size = float2(input_program_->get_width(), input_program_->get_height()); - const int max_steps = int(data_.ray_length * math::length(input_size)); - const float2 source = float2(data_.source); - - const float2 texel = float2(x, y); - - /* The number of steps is the distance in pixels from the source to the current texel. With - * at least a single step and at most the user specified maximum ray length, which is - * proportional to the diagonal pixel count. */ - const float unbounded_steps = math::max(1.0f, math::distance(texel, source * input_size)); - const int steps = math::min(max_steps, int(unbounded_steps)); - - /* We integrate from the current pixel to the source pixel, so compute the start coordinates - * and step vector in the direction to source. Notice that the step vector is still computed - * from the unbounded steps, such that the total integration length becomes limited by the - * bounded steps, and thus by the maximum ray length. */ - const float2 coordinates = (texel + float2(0.5f)) / input_size; - const float2 vector_to_source = source - coordinates; - const float2 step_vector = vector_to_source / unbounded_steps; - - float accumulated_weight = 0.0f; - float4 accumulated_color = float4(0.0f); - for (int i = 0; i <= steps; i++) { - float2 position = coordinates + i * step_vector; - - /* We are already past the image boundaries, and any future steps are also past the image - * boundaries, so break. */ - if (position.x < 0.0f || position.y < 0.0f || position.x > 1.0f || position.y > 1.0f) { - break; - } - - const float2 coordinates = position * input_size; - - float4 sample_color; - input_program_->read_sampled( - sample_color, coordinates.x, coordinates.y, PixelSampler::Bilinear); - - /* Attenuate the contributions of pixels that are further away from the source using a - * quadratic falloff. Also weight by the alpha to give more significance to opaque pixels. - */ - const float weight = (math::square(1.0f - i / float(steps))) * sample_color.w; - - accumulated_weight += weight; - accumulated_color += sample_color * weight; - } - - accumulated_color /= accumulated_weight != 0.0f ? accumulated_weight : 1.0f; - copy_v4_v4(output, accumulated_color); } void SunBeamsOperation::update_memory_buffer_partial(MemoryBuffer *output, @@ -138,9 +79,4 @@ void SunBeamsOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void SunBeamsOperation::deinit_execution() -{ - input_program_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.h b/source/blender/compositor/operations/COM_SunBeamsOperation.h index 302908bd8c8..b9afe0faa4d 100644 --- a/source/blender/compositor/operations/COM_SunBeamsOperation.h +++ b/source/blender/compositor/operations/COM_SunBeamsOperation.h @@ -12,10 +12,6 @@ class SunBeamsOperation : public MultiThreadedOperation { public: SunBeamsOperation(); - void execute_pixel(float output[4], int x, int y, void *data) override; - - void init_execution() override; - void set_data(const NodeSunBeams &data) { data_ = data; @@ -25,11 +21,8 @@ class SunBeamsOperation : public MultiThreadedOperation { const rcti &area, Span inputs) override; - void deinit_execution() override; - private: NodeSunBeams data_; - SocketReader *input_program_; }; } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_TextureOperation.cc b/source/blender/compositor/operations/COM_TextureOperation.cc index a2bd8a63297..e87a57cffb0 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.cc +++ b/source/blender/compositor/operations/COM_TextureOperation.cc @@ -18,12 +18,9 @@ TextureBaseOperation::TextureBaseOperation() this->add_input_socket(DataType::Vector); // offset this->add_input_socket(DataType::Vector); // size texture_ = nullptr; - input_size_ = nullptr; - input_offset_ = nullptr; rd_ = nullptr; pool_ = nullptr; scene_color_manage_ = false; - flags_.complex = true; } TextureOperation::TextureOperation() : TextureBaseOperation() { @@ -36,8 +33,6 @@ TextureAlphaOperation::TextureAlphaOperation() : TextureBaseOperation() void TextureBaseOperation::init_execution() { - input_offset_ = get_input_socket_reader(0); - input_size_ = get_input_socket_reader(1); pool_ = BKE_image_pool_new(); if (texture_ != nullptr && texture_->nodetree != nullptr && texture_->use_nodes) { ntreeTexBeginExecTree(texture_->nodetree); @@ -46,8 +41,6 @@ void TextureBaseOperation::init_execution() } void TextureBaseOperation::deinit_execution() { - input_size_ = nullptr; - input_offset_ = nullptr; BKE_image_pool_free(pool_); pool_ = nullptr; if (texture_ != nullptr && texture_->use_nodes && texture_->nodetree != nullptr && @@ -68,66 +61,9 @@ void TextureBaseOperation::determine_canvas(const rcti &preferred_area, rcti &r_ r_area.ymax = preferred_area.ymin + height; } - if (execution_model_ == eExecutionModel::FullFrame) { - /* Determine inputs. */ - rcti temp = COM_AREA_NONE; - NodeOperation::determine_canvas(r_area, temp); - } -} - -void TextureAlphaOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float color[4]; - TextureBaseOperation::execute_pixel_sampled(color, x, y, sampler); - output[0] = color[3]; -} - -void TextureBaseOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - TexResult texres = {0.0f}; - float texture_size[4]; - float texture_offset[4]; - float vec[3]; - int retval; - const float cx = this->get_width() / 2; - const float cy = this->get_height() / 2; - float u = (x - cx) / this->get_width() * 2; - float v = (y - cy) / this->get_height() * 2; - - /* When no interpolation/filtering happens in multitex() force nearest interpolation. - * We do it here because (a) we can't easily say multitex() that we want nearest - * interpolation and (b) in such configuration multitex() simply floor's the value - * which often produces artifacts. - */ - if (texture_ != nullptr && (texture_->imaflag & TEX_INTERPOL) == 0) { - u += 0.5f / cx; - v += 0.5f / cy; - } - - input_size_->read_sampled(texture_size, x, y, sampler); - input_offset_->read_sampled(texture_offset, x, y, sampler); - - vec[0] = texture_size[0] * (u + texture_offset[0]); - vec[1] = texture_size[1] * (v + texture_offset[1]); - vec[2] = texture_size[2] * texture_offset[2]; - - const int thread_id = WorkScheduler::current_thread_id(); - retval = multitex_ext( - texture_, vec, nullptr, nullptr, 0, &texres, thread_id, pool_, scene_color_manage_, false); - - output[3] = texres.talpha ? texres.trgba[3] : texres.tin; - if (retval & TEX_RGB) { - copy_v3_v3(output, texres.trgba); - } - else { - output[0] = output[1] = output[2] = output[3]; - } + /* Determine inputs. */ + rcti temp = COM_AREA_NONE; + NodeOperation::determine_canvas(r_area, temp); } void TextureBaseOperation::update_memory_buffer_partial(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_TextureOperation.h b/source/blender/compositor/operations/COM_TextureOperation.h index 0fa32bbeb32..51bd5aa8d0e 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.h +++ b/source/blender/compositor/operations/COM_TextureOperation.h @@ -23,8 +23,6 @@ class TextureBaseOperation : public MultiThreadedOperation { private: Tex *texture_; const RenderData *rd_; - SocketReader *input_size_; - SocketReader *input_offset_; struct ImagePool *pool_; bool scene_color_manage_; @@ -40,8 +38,6 @@ class TextureBaseOperation : public MultiThreadedOperation { TextureBaseOperation(); public: - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void set_texture(Tex *texture) { texture_ = texture; @@ -69,7 +65,6 @@ class TextureOperation : public TextureBaseOperation { class TextureAlphaOperation : public TextureBaseOperation { public: TextureAlphaOperation(); - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_TonemapOperation.cc b/source/blender/compositor/operations/COM_TonemapOperation.cc index 949f5ff4229..bea0b03b1c7 100644 --- a/source/blender/compositor/operations/COM_TonemapOperation.cc +++ b/source/blender/compositor/operations/COM_TonemapOperation.cc @@ -14,131 +14,10 @@ TonemapOperation::TonemapOperation() { this->add_input_socket(DataType::Color, ResizeMode::Align); this->add_output_socket(DataType::Color); - image_reader_ = nullptr; data_ = nullptr; cached_instance_ = nullptr; - flags_.complex = true; flags_.can_be_constant = true; } -void TonemapOperation::init_execution() -{ - image_reader_ = this->get_input_socket_reader(0); - NodeOperation::init_mutex(); -} - -void TonemapOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - AvgLogLum *avg = (AvgLogLum *)data; - - image_reader_->read(output, x, y, nullptr); - mul_v3_fl(output, avg->al); - float dr = output[0] + data_->offset; - float dg = output[1] + data_->offset; - float db = output[2] + data_->offset; - output[0] /= ((dr == 0.0f) ? 1.0f : dr); - output[1] /= ((dg == 0.0f) ? 1.0f : dg); - output[2] /= ((db == 0.0f) ? 1.0f : db); - const float igm = avg->igm; - if (igm != 0.0f) { - output[0] = powf(std::max(output[0], 0.0f), igm); - output[1] = powf(std::max(output[1], 0.0f), igm); - output[2] = powf(std::max(output[2], 0.0f), igm); - } -} -void PhotoreceptorTonemapOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - AvgLogLum *avg = (AvgLogLum *)data; - const NodeTonemap *ntm = data_; - - const float f = expf(-data_->f); - const float m = (ntm->m > 0.0f) ? ntm->m : (0.3f + 0.7f * powf(avg->auto_key, 1.4f)); - const float ic = 1.0f - ntm->c, ia = 1.0f - ntm->a; - - image_reader_->read(output, x, y, nullptr); - - const float L = IMB_colormanagement_get_luminance(output); - float I_l = output[0] + ic * (L - output[0]); - float I_g = avg->cav[0] + ic * (avg->lav - avg->cav[0]); - float I_a = I_l + ia * (I_g - I_l); - output[0] /= (output[0] + powf(f * I_a, m)); - I_l = output[1] + ic * (L - output[1]); - I_g = avg->cav[1] + ic * (avg->lav - avg->cav[1]); - I_a = I_l + ia * (I_g - I_l); - output[1] /= (output[1] + powf(f * I_a, m)); - I_l = output[2] + ic * (L - output[2]); - I_g = avg->cav[2] + ic * (avg->lav - avg->cav[2]); - I_a = I_l + ia * (I_g - I_l); - output[2] /= (output[2] + powf(f * I_a, m)); -} - -void TonemapOperation::deinit_execution() -{ - image_reader_ = nullptr; - delete cached_instance_; - NodeOperation::deinit_mutex(); -} - -bool TonemapOperation::determine_depending_area_of_interest(rcti * /*input*/, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti image_input; - - NodeOperation *operation = get_input_operation(0); - image_input.xmax = operation->get_width(); - image_input.xmin = 0; - image_input.ymax = operation->get_height(); - image_input.ymin = 0; - if (operation->determine_depending_area_of_interest(&image_input, read_operation, output)) { - return true; - } - return false; -} - -void *TonemapOperation::initialize_tile_data(rcti *rect) -{ - lock_mutex(); - if (cached_instance_ == nullptr) { - MemoryBuffer *tile = (MemoryBuffer *)image_reader_->initialize_tile_data(rect); - AvgLogLum *data = new AvgLogLum(); - - float *buffer = tile->get_buffer(); - - float lsum = 0.0f; - int p = tile->get_width() * tile->get_height(); - float *bc = buffer; - float avl, maxl = -1e10f, minl = 1e10f; - const float sc = 1.0f / p; - float Lav = 0.0f; - float cav[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - while (p--) { - float L = IMB_colormanagement_get_luminance(bc); - Lav += L; - add_v3_v3(cav, bc); - lsum += logf(std::max(L, 0.0f) + 1e-5f); - maxl = (L > maxl) ? L : maxl; - minl = (L < minl) ? L : minl; - bc += 4; - } - data->lav = Lav * sc; - mul_v3_v3fl(data->cav, cav, sc); - maxl = log(double(maxl) + 1e-5); - minl = log(double(minl) + 1e-5); - avl = lsum * sc; - data->auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.0f; - float al = exp(double(avl)); - data->al = (al == 0.0f) ? 0.0f : (data_->key / al); - data->igm = (data_->gamma == 0.0f) ? 1 : (1.0f / data_->gamma); - cached_instance_ = data; - } - unlock_mutex(); - return cached_instance_; -} - -void TonemapOperation::deinitialize_tile_data(rcti * /*rect*/, void * /*data*/) -{ - /* pass */ -} void TonemapOperation::get_area_of_interest(const int input_idx, const rcti & /*output_area*/, diff --git a/source/blender/compositor/operations/COM_TonemapOperation.h b/source/blender/compositor/operations/COM_TonemapOperation.h index fcb11d2148b..6254c9177bd 100644 --- a/source/blender/compositor/operations/COM_TonemapOperation.h +++ b/source/blender/compositor/operations/COM_TonemapOperation.h @@ -27,11 +27,6 @@ typedef struct AvgLogLum { */ class TonemapOperation : public MultiThreadedOperation { protected: - /** - * \brief Cached reference to the reader - */ - SocketReader *image_reader_; - /** * \brief settings of the Tone-map */ @@ -45,33 +40,11 @@ class TonemapOperation : public MultiThreadedOperation { public: TonemapOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - void *initialize_tile_data(rcti *rect) override; - void deinitialize_tile_data(rcti *rect, void *data) override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void set_data(const NodeTonemap *data) { data_ = data; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_started(MemoryBuffer *output, const rcti &area, @@ -88,11 +61,6 @@ class TonemapOperation : public MultiThreadedOperation { */ class PhotoreceptorTonemapOperation : public TonemapOperation { public: - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cc b/source/blender/compositor/operations/COM_TrackPositionOperation.cc index 8366d3906c0..5cfbbfe8603 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.cc +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cc @@ -113,21 +113,6 @@ void TrackPositionOperation::calc_track_position() } } -void TrackPositionOperation::execute_pixel_sampled(float output[4], - float /*x*/, - float /*y*/, - PixelSampler /*sampler*/) -{ - output[0] = marker_pos_[axis_] - relative_pos_[axis_]; - - if (axis_ == 0) { - output[0] *= width_; - } - else { - output[0] *= height_; - } -} - const float *TrackPositionOperation::get_constant_elem() { if (!is_track_position_calculated_) { diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h index 79d984ba9a9..0421185d4db 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.h +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h @@ -79,8 +79,6 @@ class TrackPositionOperation : public ConstantOperation { void init_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - const float *get_constant_elem() override; private: diff --git a/source/blender/compositor/operations/COM_TranslateOperation.cc b/source/blender/compositor/operations/COM_TranslateOperation.cc index 223817bfec3..e69527a0cc3 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.cc +++ b/source/blender/compositor/operations/COM_TranslateOperation.cc @@ -14,9 +14,6 @@ TranslateOperation::TranslateOperation(DataType data_type, ResizeMode resize_mod this->add_input_socket(DataType::Value, ResizeMode::None); this->add_output_socket(data_type); this->set_canvas_input_index(0); - input_operation_ = nullptr; - input_xoperation_ = nullptr; - input_yoperation_ = nullptr; is_delta_set_ = false; is_relative_ = false; this->x_extend_mode_ = MemoryBufferExtend::Clip; @@ -25,49 +22,6 @@ TranslateOperation::TranslateOperation(DataType data_type, ResizeMode resize_mod this->flags_.can_be_constant = true; } -void TranslateOperation::init_execution() -{ - input_operation_ = this->get_input_socket_reader(0); - input_xoperation_ = this->get_input_socket_reader(1); - input_yoperation_ = this->get_input_socket_reader(2); -} - -void TranslateOperation::deinit_execution() -{ - input_operation_ = nullptr; - input_xoperation_ = nullptr; - input_yoperation_ = nullptr; -} - -void TranslateOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler /*sampler*/) -{ - ensure_delta(); - - float original_xpos = x - this->get_delta_x(); - float original_ypos = y - this->get_delta_y(); - - input_operation_->read_sampled(output, original_xpos, original_ypos, PixelSampler::Bilinear); -} - -bool TranslateOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - - ensure_delta(); - - new_input.xmin = input->xmin - this->get_delta_x(); - new_input.xmax = input->xmax - this->get_delta_x(); - new_input.ymin = input->ymin - this->get_delta_y(); - new_input.ymax = input->ymax - this->get_delta_y(); - - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); -} - void TranslateOperation::set_wrapping(int wrapping_type) { switch (wrapping_type) { diff --git a/source/blender/compositor/operations/COM_TranslateOperation.h b/source/blender/compositor/operations/COM_TranslateOperation.h index 82333c57dd6..0179cc62c95 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.h +++ b/source/blender/compositor/operations/COM_TranslateOperation.h @@ -16,9 +16,6 @@ class TranslateOperation : public MultiThreadedOperation { static constexpr int Y_INPUT_INDEX = 2; private: - SocketReader *input_operation_; - SocketReader *input_xoperation_; - SocketReader *input_yoperation_; float delta_x_; float delta_y_; bool is_delta_set_; @@ -31,13 +28,6 @@ class TranslateOperation : public MultiThreadedOperation { public: TranslateOperation(); TranslateOperation(DataType data_type, ResizeMode mode = ResizeMode::Center); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void init_execution() override; - void deinit_execution() override; float get_delta_x() { @@ -60,30 +50,15 @@ class TranslateOperation : public MultiThreadedOperation { inline void ensure_delta() { if (!is_delta_set_) { - if (execution_model_ == eExecutionModel::Tiled) { - float temp_delta[4]; - input_xoperation_->read_sampled(temp_delta, 0, 0, PixelSampler::Nearest); - delta_x_ = temp_delta[0]; - input_yoperation_->read_sampled(temp_delta, 0, 0, PixelSampler::Nearest); - delta_y_ = temp_delta[0]; - if (get_is_relative()) { - const int input_width = BLI_rcti_size_x(&input_operation_->get_canvas()); - const int input_height = BLI_rcti_size_y(&input_operation_->get_canvas()); - delta_x_ *= input_width; - delta_y_ *= input_height; - } - } - else { - delta_x_ = get_input_operation(X_INPUT_INDEX)->get_constant_value_default(0.0f); - delta_y_ = get_input_operation(Y_INPUT_INDEX)->get_constant_value_default(0.0f); - if (get_is_relative()) { - const int input_width = BLI_rcti_size_x( - &get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); - const int input_height = BLI_rcti_size_y( - &get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); - delta_x_ *= input_width; - delta_y_ *= input_height; - } + delta_x_ = get_input_operation(X_INPUT_INDEX)->get_constant_value_default(0.0f); + delta_y_ = get_input_operation(Y_INPUT_INDEX)->get_constant_value_default(0.0f); + if (get_is_relative()) { + const int input_width = BLI_rcti_size_x( + &get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); + const int input_height = BLI_rcti_size_y( + &get_input_operation(IMAGE_INPUT_INDEX)->get_canvas()); + delta_x_ *= input_width; + delta_y_ *= input_height; } is_delta_set_ = true; diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc index ebe2cd454f3..9ad0dabb22d 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc @@ -5,7 +5,6 @@ #include "BLI_math_base.hh" #include "BLI_math_vector.hh" -#include "COM_OpenCLDevice.h" #include "COM_VariableSizeBokehBlurOperation.h" namespace blender::compositor { @@ -21,31 +20,15 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() this->add_input_socket(DataType::Color, ResizeMode::None); #endif this->add_output_socket(DataType::Color); - flags_.complex = true; - flags_.open_cl = true; flags_.can_be_constant = true; - input_program_ = nullptr; - input_bokeh_program_ = nullptr; - input_size_program_ = nullptr; - input_mask_program_ = nullptr; max_blur_ = 32.0f; threshold_ = 1.0f; do_size_scale_ = false; -#ifdef COM_DEFOCUS_SEARCH - input_search_program_ = nullptr; -#endif } void VariableSizeBokehBlurOperation::init_execution() { - input_program_ = get_input_socket_reader(0); - input_bokeh_program_ = get_input_socket_reader(1); - input_size_program_ = get_input_socket_reader(2); - input_mask_program_ = get_input_socket_reader(3); -#ifdef COM_DEFOCUS_SEARCH - input_search_program_ = get_input_socket_reader(4); -#endif QualityStepHelper::init_execution(COM_QH_INCREASE); } struct VariableSizeBokehBlurTileData { @@ -56,192 +39,6 @@ struct VariableSizeBokehBlurTileData { int max_blur_scalar; }; -void *VariableSizeBokehBlurOperation::initialize_tile_data(rcti *rect) -{ - VariableSizeBokehBlurTileData *data = new VariableSizeBokehBlurTileData(); - data->color = (MemoryBuffer *)input_program_->initialize_tile_data(rect); - data->bokeh = (MemoryBuffer *)input_bokeh_program_->initialize_tile_data(rect); - data->size = (MemoryBuffer *)input_size_program_->initialize_tile_data(rect); - data->mask = (MemoryBuffer *)input_mask_program_->initialize_tile_data(rect); - - rcti rect2 = COM_AREA_NONE; - this->determine_depending_area_of_interest( - rect, (ReadBufferOperation *)input_size_program_, &rect2); - - const float max_dim = std::max(this->get_width(), this->get_height()); - const float scalar = do_size_scale_ ? (max_dim / 100.0f) : 1.0f; - - data->max_blur_scalar = int(data->size->get_max_value(rect2) * scalar); - CLAMP(data->max_blur_scalar, 0, max_blur_); - return data; -} - -void VariableSizeBokehBlurOperation::deinitialize_tile_data(rcti * /*rect*/, void *data) -{ - VariableSizeBokehBlurTileData *result = (VariableSizeBokehBlurTileData *)data; - delete result; -} - -void VariableSizeBokehBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - VariableSizeBokehBlurTileData *tile_data = (VariableSizeBokehBlurTileData *)data; - MemoryBuffer *input_buffer = tile_data->color; - MemoryBuffer *bokeh_buffer = tile_data->bokeh; - MemoryBuffer *size_buffer = tile_data->size; - MemoryBuffer *mask_buffer = tile_data->mask; - - if (*mask_buffer->get_elem(x, y) <= 0.0f) { - copy_v4_v4(output, input_buffer->get_elem(x, y)); - return; - } - - const float max_dim = std::max(get_width(), get_height()); - const float base_size = do_size_scale_ ? (max_dim / 100.0f) : 1.0f; - const int search_radius = tile_data->max_blur_scalar; - const int2 bokeh_size = int2(bokeh_buffer->get_width(), bokeh_buffer->get_height()); - const float center_size = math::max(0.0f, *size_buffer->get_elem(x, y) * base_size); - - float4 accumulated_color = float4(input_buffer->get_elem(x, y)); - float4 accumulated_weight = float4(1.0f); - const int step = get_step(); - if (center_size >= threshold_) { - for (int yi = -search_radius; yi <= search_radius; yi += step) { - for (int xi = -search_radius; xi <= search_radius; xi += step) { - if (xi == 0 && yi == 0) { - continue; - } - const float candidate_size = math::max( - 0.0f, *size_buffer->get_elem_clamped(x + xi, y + yi) * base_size); - const float size = math::min(center_size, candidate_size); - if (size < threshold_ || math::max(math::abs(xi), math::abs(yi)) > size) { - continue; - } - - const float2 normalized_texel = (float2(xi, yi) + size + 0.5f) / (size * 2.0f + 1.0f); - const float2 weight_texel = (1.0f - normalized_texel) * float2(bokeh_size - 1); - const float4 weight = bokeh_buffer->get_elem(int(weight_texel.x), int(weight_texel.y)); - const float4 color = input_buffer->get_elem_clamped(x + xi, y + yi); - accumulated_color += color * weight; - accumulated_weight += weight; - } - } - } - - const float4 final_color = math::safe_divide(accumulated_color, accumulated_weight); - copy_v4_v4(output, final_color); - - /* blend in out values over the threshold, otherwise we get sharp, ugly transitions */ - if ((center_size > threshold_) && (center_size < threshold_ * 2.0f)) { - /* factor from 0-1 */ - float fac = (center_size - threshold_) / threshold_; - interp_v4_v4v4(output, input_buffer->get_elem(x, y), output, fac); - } -} - -void VariableSizeBokehBlurOperation::execute_opencl( - OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list * /*cl_kernels_to_clean_up*/) -{ - cl_kernel defocus_kernel = device->COM_cl_create_kernel("defocus_kernel", nullptr); - - cl_int step = this->get_step(); - cl_int max_blur; - cl_float threshold = threshold_; - - MemoryBuffer *size_memory_buffer = input_size_program_->get_input_memory_buffer( - input_memory_buffers); - - const float max_dim = std::max(get_width(), get_height()); - cl_float scalar = do_size_scale_ ? (max_dim / 100.0f) : 1.0f; - - max_blur = (cl_int)min_ff(size_memory_buffer->get_max_value() * scalar, float(max_blur_)); - - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - defocus_kernel, 0, -1, cl_mem_to_clean_up, input_memory_buffers, input_program_); - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - defocus_kernel, 1, -1, cl_mem_to_clean_up, input_memory_buffers, input_bokeh_program_); - device->COM_cl_attach_memory_buffer_to_kernel_parameter( - defocus_kernel, 2, 4, cl_mem_to_clean_up, input_memory_buffers, input_size_program_); - device->COM_cl_attach_output_memory_buffer_to_kernel_parameter( - defocus_kernel, 3, cl_output_buffer); - device->COM_cl_attach_memory_buffer_offset_to_kernel_parameter( - defocus_kernel, 5, output_memory_buffer); - clSetKernelArg(defocus_kernel, 6, sizeof(cl_int), &step); - clSetKernelArg(defocus_kernel, 7, sizeof(cl_int), &max_blur); - clSetKernelArg(defocus_kernel, 8, sizeof(cl_float), &threshold); - clSetKernelArg(defocus_kernel, 9, sizeof(cl_float), &scalar); - device->COM_cl_attach_size_to_kernel_parameter(defocus_kernel, 10, this); - - device->COM_cl_enqueue_range(defocus_kernel, output_memory_buffer, 11, this); -} - -void VariableSizeBokehBlurOperation::deinit_execution() -{ - input_program_ = nullptr; - input_bokeh_program_ = nullptr; - input_size_program_ = nullptr; - input_mask_program_ = nullptr; -#ifdef COM_DEFOCUS_SEARCH - input_search_program_ = nullptr; -#endif -} - -bool VariableSizeBokehBlurOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - if (read_operation == (ReadBufferOperation *)get_input_operation(BOKEH_INPUT_INDEX)) { - rcti bokeh_input; - bokeh_input.xmax = COM_BLUR_BOKEH_PIXELS; - bokeh_input.xmin = 0; - bokeh_input.ymax = COM_BLUR_BOKEH_PIXELS; - bokeh_input.ymin = 0; - - NodeOperation *operation = get_input_operation(BOKEH_INPUT_INDEX); - return operation->determine_depending_area_of_interest(&bokeh_input, read_operation, output); - } - - const float max_dim = std::max(get_width(), get_height()); - const float scalar = do_size_scale_ ? (max_dim / 100.0f) : 1.0f; - int max_blur_scalar = max_blur_ * scalar; - - rcti new_input; - new_input.xmax = input->xmax + max_blur_scalar + 2; - new_input.xmin = input->xmin - max_blur_scalar + 2; - new_input.ymax = input->ymax + max_blur_scalar - 2; - new_input.ymin = input->ymin - max_blur_scalar - 2; - - NodeOperation *operation = get_input_operation(SIZE_INPUT_INDEX); - if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { - return true; - } -#ifdef COM_DEFOCUS_SEARCH - rcti search_input; - search_input.xmax = (input->xmax / InverseSearchRadiusOperation::DIVIDER) + 1; - search_input.xmin = (input->xmin / InverseSearchRadiusOperation::DIVIDER) - 1; - search_input.ymax = (input->ymax / InverseSearchRadiusOperation::DIVIDER) + 1; - search_input.ymin = (input->ymin / InverseSearchRadiusOperation::DIVIDER) - 1; - operation = get_input_operation(DEFOCUS_INPUT_INDEX); - if (operation->determine_depending_area_of_interest(&search_input, read_operation, output)) { - return true; - } -#endif - operation = get_input_operation(IMAGE_INPUT_INDEX); - if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { - return true; - } - - operation = get_input_operation(BOUNDING_BOX_INPUT_INDEX); - if (operation->determine_depending_area_of_interest(&new_input, read_operation, output)) { - return true; - } - - return false; -} - void VariableSizeBokehBlurOperation::get_area_of_interest(const int input_idx, const rcti &output_area, rcti &r_input_area) @@ -345,88 +142,6 @@ InverseSearchRadiusOperation::InverseSearchRadiusOperation() { this->add_input_socket(DataType::Value, ResizeMode::Align); /* Radius. */ this->add_output_socket(DataType::Color); - this->flags.complex = true; - input_radius_ = nullptr; -} - -void InverseSearchRadiusOperation::init_execution() -{ - input_radius_ = this->get_input_socket_reader(0); -} - -void *InverseSearchRadiusOperation::initialize_tile_data(rcti *rect) -{ - MemoryBuffer *data = new MemoryBuffer(DataType::Color, rect); - float *buffer = data->get_buffer(); - int x, y; - int width = input_radius_->get_width(); - int height = input_radius_->get_height(); - float temp[4]; - int offset = 0; - for (y = rect->ymin; y < rect->ymax; y++) { - for (x = rect->xmin; x < rect->xmax; x++) { - int rx = x * DIVIDER; - int ry = y * DIVIDER; - buffer[offset] = std::max(rx - max_blur_, 0); - buffer[offset + 1] = std::max(ry - max_blur_, 0); - buffer[offset + 2] = std::min(rx + DIVIDER + max_blur_, width); - buffer[offset + 3] = std::min(ry + DIVIDER + max_blur_, height); - offset += 4; - } - } -# if 0 - for (x = rect->xmin; x < rect->xmax; x++) { - for (y = rect->ymin; y < rect->ymax; y++) { - int rx = x * DIVIDER; - int ry = y * DIVIDER; - float radius = 0.0f; - float maxx = x; - float maxy = y; - - for (int x2 = 0; x2 < DIVIDER; x2++) { - for (int y2 = 0; y2 < DIVIDER; y2++) { - input_radius_->read(temp, rx + x2, ry + y2, PixelSampler::Nearest); - if (radius < temp[0]) { - radius = temp[0]; - maxx = x2; - maxy = y2; - } - } - } - int impact_radius = ceil(radius / DIVIDER); - for (int x2 = x - impact_radius; x2 < x + impact_radius; x2++) { - for (int y2 = y - impact_radius; y2 < y + impact_radius; y2++) { - data->read(temp, x2, y2); - temp[0] = std::min(temp[0], maxx); - temp[1] = std::min(temp[1], maxy); - temp[2] = std::max(temp[2], maxx); - temp[3] = std::max(temp[3], maxy); - data->write_pixel(x2, y2, temp); - } - } - } - } -# endif - return data; -} - -void InverseSearchRadiusOperation::execute_pixel_chunk(float output[4], int x, int y, void *data) -{ - MemoryBuffer *buffer = (MemoryBuffer *)data; - buffer->read_no_check(output, x, y); -} - -void InverseSearchRadiusOperation::deinitialize_tile_data(rcti *rect, void *data) -{ - if (data) { - MemoryBuffer *mb = (MemoryBuffer *)data; - delete mb; - } -} - -void InverseSearchRadiusOperation::deinit_execution() -{ - input_radius_ = nullptr; } void InverseSearchRadiusOperation::determine_resolution(uint resolution[2], @@ -437,16 +152,6 @@ void InverseSearchRadiusOperation::determine_resolution(uint resolution[2], resolution[1] = resolution[1] / DIVIDER; } -bool InverseSearchRadiusOperation::determine_depending_area_of_interest( - rcti *input, ReadBufferOperation *read_operation, rcti *output) -{ - rcti new_rect; - new_rect.ymin = input->ymin * DIVIDER - max_blur_; - new_rect.ymax = input->ymax * DIVIDER + max_blur_; - new_rect.xmin = input->xmin * DIVIDER - max_blur_; - new_rect.xmax = input->xmax * DIVIDER + max_blur_; - return NodeOperation::determine_depending_area_of_interest(&new_rect, read_operation, output); -} #endif } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h index bd1184f5b11..28728d9298f 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h @@ -24,40 +24,12 @@ class VariableSizeBokehBlurOperation : public MultiThreadedOperation, public Qua int max_blur_; float threshold_; bool do_size_scale_; /* scale size, matching 'BokehBlurNode' */ - SocketReader *input_program_; - SocketReader *input_bokeh_program_; - SocketReader *input_size_program_; - SocketReader *input_mask_program_; -#ifdef COM_DEFOCUS_SEARCH - SocketReader *input_search_program_; -#endif public: VariableSizeBokehBlurOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - - void deinitialize_tile_data(rcti *rect, void *data) override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void set_max_blur(int max_radius) { max_blur_ = max_radius; @@ -73,13 +45,6 @@ class VariableSizeBokehBlurOperation : public MultiThreadedOperation, public Qua do_size_scale_ = scale_size; } - void execute_opencl(OpenCLDevice *device, - MemoryBuffer *output_memory_buffer, - cl_mem cl_output_buffer, - MemoryBuffer **input_memory_buffers, - std::list *cl_mem_to_clean_up, - std::list *cl_kernels_to_clean_up) override; - void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, @@ -91,33 +56,12 @@ class VariableSizeBokehBlurOperation : public MultiThreadedOperation, public Qua class InverseSearchRadiusOperation : public NodeOperation { private: int max_blur_; - SocketReader *input_radius_; public: static const int DIVIDER = 4; InverseSearchRadiusOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_chunk(float output[4], int x, int y, void *data); - - /** - * Initialize the execution - */ - void init_execution() override; - void *initialize_tile_data(rcti *rect) override; - void deinitialize_tile_data(rcti *rect, void *data) override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; void set_max_blur(int max_radius) diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cc b/source/blender/compositor/operations/COM_VectorBlurOperation.cc index c3311bea5c9..152231633f7 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.cc +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cc @@ -35,74 +35,20 @@ VectorBlurOperation::VectorBlurOperation() this->add_output_socket(DataType::Color); settings_ = nullptr; cached_instance_ = nullptr; - input_image_program_ = nullptr; - input_speed_program_ = nullptr; - input_zprogram_ = nullptr; - flags_.complex = true; - flags_.is_fullframe_operation = true; } void VectorBlurOperation::init_execution() { - init_mutex(); - input_image_program_ = get_input_socket_reader(0); - input_zprogram_ = get_input_socket_reader(1); - input_speed_program_ = get_input_socket_reader(2); cached_instance_ = nullptr; QualityStepHelper::init_execution(COM_QH_INCREASE); } -void VectorBlurOperation::execute_pixel(float output[4], int x, int y, void *data) -{ - float *buffer = (float *)data; - int index = (y * this->get_width() + x) * COM_DATA_TYPE_COLOR_CHANNELS; - copy_v4_v4(output, &buffer[index]); -} - void VectorBlurOperation::deinit_execution() { - deinit_mutex(); - input_image_program_ = nullptr; - input_speed_program_ = nullptr; - input_zprogram_ = nullptr; if (cached_instance_) { MEM_freeN(cached_instance_); cached_instance_ = nullptr; } } -void *VectorBlurOperation::initialize_tile_data(rcti *rect) -{ - if (cached_instance_) { - return cached_instance_; - } - - lock_mutex(); - if (cached_instance_ == nullptr) { - MemoryBuffer *tile = (MemoryBuffer *)input_image_program_->initialize_tile_data(rect); - MemoryBuffer *speed = (MemoryBuffer *)input_speed_program_->initialize_tile_data(rect); - MemoryBuffer *z = (MemoryBuffer *)input_zprogram_->initialize_tile_data(rect); - float *data = (float *)MEM_dupallocN(tile->get_buffer()); - this->generate_vector_blur(data, tile, speed, z); - cached_instance_ = data; - } - unlock_mutex(); - return cached_instance_; -} - -bool VectorBlurOperation::determine_depending_area_of_interest(rcti * /*input*/, - ReadBufferOperation *read_operation, - rcti *output) -{ - if (cached_instance_ == nullptr) { - rcti new_input; - new_input.xmax = this->get_width(); - new_input.xmin = 0; - new_input.ymax = this->get_height(); - new_input.ymin = 0; - return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output); - } - - return false; -} void VectorBlurOperation::get_area_of_interest(const int /*input_idx*/, const rcti & /*output_area*/, diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.h b/source/blender/compositor/operations/COM_VectorBlurOperation.h index d01d928b6f7..f7bac082372 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.h +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.h @@ -16,13 +16,6 @@ class VectorBlurOperation : public NodeOperation, public QualityStepHelper { static constexpr int Z_INPUT_INDEX = 1; static constexpr int SPEED_INPUT_INDEX = 2; - /** - * \brief Cached reference to the input_program - */ - SocketReader *input_image_program_; - SocketReader *input_speed_program_; - SocketReader *input_zprogram_; - /** * \brief settings of the glare node. */ @@ -33,30 +26,13 @@ class VectorBlurOperation : public NodeOperation, public QualityStepHelper { public: VectorBlurOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel(float output[4], int x, int y, void *data) override; - - /** - * Initialize the execution - */ void init_execution() override; - - /** - * Deinitialize the execution - */ void deinit_execution() override; - void *initialize_tile_data(rcti *rect) override; - void set_vector_blur_settings(const NodeBlurData *settings) { settings_ = settings; } - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; void update_memory_buffer(MemoryBuffer *output, diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.cc b/source/blender/compositor/operations/COM_VectorCurveOperation.cc index 41bf7f44907..a293d958237 100644 --- a/source/blender/compositor/operations/COM_VectorCurveOperation.cc +++ b/source/blender/compositor/operations/COM_VectorCurveOperation.cc @@ -13,33 +13,8 @@ VectorCurveOperation::VectorCurveOperation() this->add_input_socket(DataType::Vector); this->add_output_socket(DataType::Vector); - input_program_ = nullptr; - this->flags_.can_be_constant = true; } -void VectorCurveOperation::init_execution() -{ - CurveBaseOperation::init_execution(); - input_program_ = this->get_input_socket_reader(0); -} - -void VectorCurveOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float input[4]; - - input_program_->read_sampled(input, x, y, sampler); - - BKE_curvemapping_evaluate_premulRGBF(curve_mapping_, output, input); -} - -void VectorCurveOperation::deinit_execution() -{ - CurveBaseOperation::deinit_execution(); - input_program_ = nullptr; -} void VectorCurveOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.h b/source/blender/compositor/operations/COM_VectorCurveOperation.h index 683894ae021..ee5413abf7b 100644 --- a/source/blender/compositor/operations/COM_VectorCurveOperation.h +++ b/source/blender/compositor/operations/COM_VectorCurveOperation.h @@ -5,35 +5,13 @@ #pragma once #include "COM_CurveBaseOperation.h" -#include "COM_NodeOperation.h" namespace blender::compositor { class VectorCurveOperation : public CurveBaseOperation { - private: - /** - * Cached reference to the input_program - */ - SocketReader *input_program_; - public: VectorCurveOperation(); - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - /** - * Initialize the execution - */ - void init_execution() override; - - /** - * Deinitialize the execution - */ - void deinit_execution() override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cc b/source/blender/compositor/operations/COM_ViewerOperation.cc index 51498b3a27a..e0f34c527cd 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.cc +++ b/source/blender/compositor/operations/COM_ViewerOperation.cc @@ -26,8 +26,6 @@ ViewerOperation::ViewerOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Value); - image_input_ = nullptr; - alpha_input_ = nullptr; rd_ = nullptr; view_name_ = nullptr; flags_.use_viewer_border = true; @@ -36,10 +34,6 @@ ViewerOperation::ViewerOperation() void ViewerOperation::init_execution() { - /* When initializing the tree during initial load the width and height can be zero. */ - image_input_ = get_input_socket_reader(0); - alpha_input_ = get_input_socket_reader(1); - if (is_active_viewer_output() && !exec_system_->is_breaked()) { init_image(); } @@ -47,50 +41,9 @@ void ViewerOperation::init_execution() void ViewerOperation::deinit_execution() { - image_input_ = nullptr; - alpha_input_ = nullptr; output_buffer_ = nullptr; } -void ViewerOperation::execute_region(rcti *rect, uint /*tile_number*/) -{ - float *buffer = output_buffer_; - if (!buffer) { - return; - } - const int x1 = rect->xmin; - const int y1 = rect->ymin; - const int x2 = rect->xmax; - const int y2 = rect->ymax; - const int offsetadd = (this->get_width() - (x2 - x1)); - const int offsetadd4 = offsetadd * 4; - int offset = (y1 * this->get_width() + x1); - int offset4 = offset * 4; - float alpha[4]; - int x; - int y; - bool breaked = false; - - for (y = y1; y < y2 && (!breaked); y++) { - for (x = x1; x < x2; x++) { - image_input_->read_sampled(&(buffer[offset4]), x, y, PixelSampler::Nearest); - if (use_alpha_input_) { - alpha_input_->read_sampled(alpha, x, y, PixelSampler::Nearest); - buffer[offset4 + 3] = alpha[0]; - } - - offset++; - offset4 += 4; - } - if (is_braked()) { - breaked = true; - } - offset += offsetadd; - offset4 += offsetadd4; - } - update_image(rect); -} - void ViewerOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) { int scene_render_width, scene_render_height; diff --git a/source/blender/compositor/operations/COM_ViewerOperation.h b/source/blender/compositor/operations/COM_ViewerOperation.h index 83f98049997..0a6e90c7727 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.h +++ b/source/blender/compositor/operations/COM_ViewerOperation.h @@ -21,7 +21,6 @@ class ViewerOperation : public MultiThreadedOperation { bool active_; float center_x_; float center_y_; - ChunkOrdering chunk_order_; ImBuf *ibuf_; bool use_alpha_input_; const RenderData *rd_; @@ -30,14 +29,10 @@ class ViewerOperation : public MultiThreadedOperation { const ColorManagedViewSettings *view_settings_; const ColorManagedDisplaySettings *display_settings_; - SocketReader *image_input_; - SocketReader *alpha_input_; - public: ViewerOperation(); void init_execution() override; void deinit_execution() override; - void execute_region(rcti *rect, unsigned int tile_number) override; void determine_canvas(const rcti &preferred_area, rcti &r_area) override; bool is_output_operation(bool /*rendering*/) const override { @@ -70,10 +65,6 @@ class ViewerOperation : public MultiThreadedOperation { { center_y_ = centerY; } - void set_chunk_order(ChunkOrdering tile_order) - { - chunk_order_ = tile_order; - } float getCenterX() const { return center_x_; @@ -82,10 +73,6 @@ class ViewerOperation : public MultiThreadedOperation { { return center_y_; } - ChunkOrdering get_chunk_order() const - { - return chunk_order_; - } eCompositorPriority get_render_priority() const override; void set_use_alpha_input(bool value) { diff --git a/source/blender/compositor/operations/COM_WrapOperation.cc b/source/blender/compositor/operations/COM_WrapOperation.cc deleted file mode 100644 index def8afd0a6a..00000000000 --- a/source/blender/compositor/operations/COM_WrapOperation.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include - -#include "COM_WrapOperation.h" - -namespace blender::compositor { - -WrapOperation::WrapOperation(DataType datatype) : ReadBufferOperation(datatype) -{ - wrapping_type_ = CMP_NODE_WRAP_NONE; -} - -inline float WrapOperation::get_wrapped_original_xpos(float x) -{ - if (this->get_width() == 0) { - return 0; - } - while (x < 0) { - x += this->get_width(); - } - return fmodf(x, this->get_width()); -} - -inline float WrapOperation::get_wrapped_original_ypos(float y) -{ - if (this->get_height() == 0) { - return 0; - } - while (y < 0) { - y += this->get_height(); - } - return fmodf(y, this->get_height()); -} - -void WrapOperation::execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) -{ - float nx, ny; - nx = x; - ny = y; - MemoryBufferExtend extend_x = MemoryBufferExtend::Clip, extend_y = MemoryBufferExtend::Clip; - switch (wrapping_type_) { - case CMP_NODE_WRAP_NONE: - /* Intentionally empty, original_xpos and original_ypos have been set before. */ - break; - case CMP_NODE_WRAP_X: - /* Wrap only on the x-axis. */ - nx = this->get_wrapped_original_xpos(x); - extend_x = MemoryBufferExtend::Repeat; - break; - case CMP_NODE_WRAP_Y: - /* Wrap only on the y-axis. */ - ny = this->get_wrapped_original_ypos(y); - extend_y = MemoryBufferExtend::Repeat; - break; - case CMP_NODE_WRAP_XY: - /* Wrap on both. */ - nx = this->get_wrapped_original_xpos(x); - ny = this->get_wrapped_original_ypos(y); - extend_x = MemoryBufferExtend::Repeat; - extend_y = MemoryBufferExtend::Repeat; - break; - } - - execute_pixel_extend(output, nx, ny, sampler, extend_x, extend_y); -} - -bool WrapOperation::determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) -{ - rcti new_input; - new_input.xmin = input->xmin; - new_input.xmax = input->xmax; - new_input.ymin = input->ymin; - new_input.ymax = input->ymax; - - if (ELEM(wrapping_type_, CMP_NODE_WRAP_X, CMP_NODE_WRAP_XY)) { - /* Wrap only on the x-axis if tile is wrapping. */ - new_input.xmin = get_wrapped_original_xpos(input->xmin); - new_input.xmax = roundf(get_wrapped_original_xpos(input->xmax)); - if (new_input.xmin >= new_input.xmax) { - new_input.xmin = 0; - new_input.xmax = this->get_width(); - } - } - if (ELEM(wrapping_type_, CMP_NODE_WRAP_Y, CMP_NODE_WRAP_XY)) { - /* Wrap only on the y-axis if tile is wrapping. */ - new_input.ymin = get_wrapped_original_ypos(input->ymin); - new_input.ymax = roundf(get_wrapped_original_ypos(input->ymax)); - if (new_input.ymin >= new_input.ymax) { - new_input.ymin = 0; - new_input.ymax = this->get_height(); - } - } - - return ReadBufferOperation::determine_depending_area_of_interest( - &new_input, read_operation, output); -} - -void WrapOperation::set_wrapping(int wrapping_type) -{ - wrapping_type_ = wrapping_type; -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_WrapOperation.h b/source/blender/compositor/operations/COM_WrapOperation.h deleted file mode 100644 index bfb73b1a42a..00000000000 --- a/source/blender/compositor/operations/COM_WrapOperation.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_ReadBufferOperation.h" - -namespace blender::compositor { - -class WrapOperation : public ReadBufferOperation { - private: - int wrapping_type_; - - public: - WrapOperation(DataType datatype); - bool determine_depending_area_of_interest(rcti *input, - ReadBufferOperation *read_operation, - rcti *output) override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - - void set_wrapping(int wrapping_type); - float get_wrapped_original_xpos(float x); - float get_wrapped_original_ypos(float y); - - void setFactorXY(float factorX, float factorY); -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cc b/source/blender/compositor/operations/COM_WriteBufferOperation.cc deleted file mode 100644 index d53abfd0094..00000000000 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#include "COM_WriteBufferOperation.h" -#include "COM_OpenCLDevice.h" - -namespace blender::compositor { - -WriteBufferOperation::WriteBufferOperation(DataType datatype) -{ - this->add_input_socket(datatype); - memory_proxy_ = new MemoryProxy(datatype); - memory_proxy_->set_write_buffer_operation(this); - memory_proxy_->set_executor(nullptr); - flags_.is_write_buffer_operation = true; -} -WriteBufferOperation::~WriteBufferOperation() -{ - if (memory_proxy_) { - delete memory_proxy_; - memory_proxy_ = nullptr; - } -} - -void WriteBufferOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - input_->read_sampled(output, x, y, sampler); -} - -void WriteBufferOperation::init_execution() -{ - input_ = this->get_input_operation(0); - memory_proxy_->allocate(this->get_width(), this->get_height()); -} - -void WriteBufferOperation::deinit_execution() -{ - input_ = nullptr; - memory_proxy_->free(); -} - -void WriteBufferOperation::execute_region(rcti *rect, uint /*tile_number*/) -{ - MemoryBuffer *memory_buffer = memory_proxy_->get_buffer(); - float *buffer = memory_buffer->get_buffer(); - const uint8_t num_channels = memory_buffer->get_num_channels(); - if (input_->get_flags().complex) { - void *data = input_->initialize_tile_data(rect); - int x1 = rect->xmin; - int y1 = rect->ymin; - int x2 = rect->xmax; - int y2 = rect->ymax; - int x; - int y; - bool breaked = false; - for (y = y1; y < y2 && (!breaked); y++) { - int offset4 = (y * memory_buffer->get_width() + x1) * num_channels; - for (x = x1; x < x2; x++) { - input_->read(&(buffer[offset4]), x, y, data); - offset4 += num_channels; - } - if (is_braked()) { - breaked = true; - } - } - if (data) { - input_->deinitialize_tile_data(rect, data); - data = nullptr; - } - } - else { - int x1 = rect->xmin; - int y1 = rect->ymin; - int x2 = rect->xmax; - int y2 = rect->ymax; - - int x; - int y; - bool breaked = false; - for (y = y1; y < y2 && (!breaked); y++) { - int offset4 = (y * memory_buffer->get_width() + x1) * num_channels; - for (x = x1; x < x2; x++) { - input_->read_sampled(&(buffer[offset4]), x, y, PixelSampler::Nearest); - offset4 += num_channels; - } - if (is_braked()) { - breaked = true; - } - } - } -} - -void WriteBufferOperation::execute_opencl_region(OpenCLDevice *device, - rcti * /*rect*/, - uint /*chunk_number*/, - MemoryBuffer **input_memory_buffers, - MemoryBuffer *output_buffer) -{ - float *output_float_buffer = output_buffer->get_buffer(); - cl_int error; - /* - * 1. create cl_mem from output_buffer. - * 2. call NodeOperation (input) executeOpenCLChunk(...). - * 3. schedule read back from OPENCL to main device (output_buffer). - * 4. schedule native callback. - * - * NOTE: list of cl_mem will be filled by 2, and needs to be cleaned up by 4 - */ - /* STEP 1 */ - const uint output_buffer_width = output_buffer->get_width(); - const uint output_buffer_height = output_buffer->get_height(); - - const cl_image_format *image_format = OpenCLDevice::determine_image_format(output_buffer); - - cl_mem cl_output_buffer = clCreateImage2D(device->get_context(), - CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR, - image_format, - output_buffer_width, - output_buffer_height, - 0, - output_float_buffer, - &error); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - - /* STEP 2 */ - std::list *cl_mem_to_clean_up = new std::list(); - cl_mem_to_clean_up->push_back(cl_output_buffer); - std::list *cl_kernels_to_clean_up = new std::list(); - - input_->execute_opencl(device, - output_buffer, - cl_output_buffer, - input_memory_buffers, - cl_mem_to_clean_up, - cl_kernels_to_clean_up); - - /* STEP 3 */ - - size_t origin[3] = {0, 0, 0}; - size_t region[3] = {output_buffer_width, output_buffer_height, 1}; - - // clFlush(queue); - // clFinish(queue); - - error = clEnqueueBarrier(device->get_queue()); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - error = clEnqueueReadImage(device->get_queue(), - cl_output_buffer, - CL_TRUE, - origin, - region, - 0, - 0, - output_float_buffer, - 0, - nullptr, - nullptr); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - - this->get_memory_proxy()->get_buffer()->fill_from(*output_buffer); - - /* STEP 4 */ - while (!cl_mem_to_clean_up->empty()) { - cl_mem mem = cl_mem_to_clean_up->front(); - error = clReleaseMemObject(mem); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - cl_mem_to_clean_up->pop_front(); - } - - while (!cl_kernels_to_clean_up->empty()) { - cl_kernel kernel = cl_kernels_to_clean_up->front(); - error = clReleaseKernel(kernel); - if (error != CL_SUCCESS) { - printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); - } - cl_kernels_to_clean_up->pop_front(); - } - delete cl_kernels_to_clean_up; -} - -void WriteBufferOperation::determine_canvas(const rcti &preferred_area, rcti &r_area) -{ - NodeOperation::determine_canvas(preferred_area, r_area); - /* make sure there is at least one pixel stored in case the input is a single value */ - single_value_ = false; - if (BLI_rcti_size_x(&r_area) == 0) { - r_area.xmax += 1; - single_value_ = true; - } - if (BLI_rcti_size_y(&r_area) == 0) { - r_area.ymax += 1; - single_value_ = true; - } -} - -void WriteBufferOperation::read_resolution_from_input_socket() -{ - NodeOperation *input_operation = this->get_input_operation(0); - this->set_width(input_operation->get_width()); - this->set_height(input_operation->get_height()); -} - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.h b/source/blender/compositor/operations/COM_WriteBufferOperation.h deleted file mode 100644 index 8a615c0d2cb..00000000000 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.h +++ /dev/null @@ -1,53 +0,0 @@ -/* SPDX-FileCopyrightText: 2011 Blender Authors - * - * SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include "COM_MemoryProxy.h" -#include "COM_NodeOperation.h" - -namespace blender::compositor { - -class OpenCLDevice; -class MemoryProxy; - -/** - * \brief NodeOperation to write to a tile - * \ingroup Operation - */ -class WriteBufferOperation : public NodeOperation { - MemoryProxy *memory_proxy_; - bool single_value_; /* single value stored in buffer */ - NodeOperation *input_; - - public: - WriteBufferOperation(DataType datatype); - ~WriteBufferOperation(); - MemoryProxy *get_memory_proxy() - { - return memory_proxy_; - } - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - bool is_single_value() const - { - return single_value_; - } - - void execute_region(rcti *rect, unsigned int tile_number) override; - void init_execution() override; - void deinit_execution() override; - void execute_opencl_region(OpenCLDevice *device, - rcti *rect, - unsigned int chunk_number, - MemoryBuffer **memory_buffers, - MemoryBuffer *output_buffer) override; - void determine_canvas(const rcti &preferred_area, rcti &r_area) override; - void read_resolution_from_input_socket(); - inline NodeOperation *get_input() - { - return input_; - } -}; - -} // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.cc b/source/blender/compositor/operations/COM_ZCombineOperation.cc index c4d696b65b4..cfaf4f1672a 100644 --- a/source/blender/compositor/operations/COM_ZCombineOperation.cc +++ b/source/blender/compositor/operations/COM_ZCombineOperation.cc @@ -14,39 +14,9 @@ ZCombineOperation::ZCombineOperation() this->add_input_socket(DataType::Value); this->add_output_socket(DataType::Color); - image1Reader_ = nullptr; - depth1Reader_ = nullptr; - image2Reader_ = nullptr; - depth2Reader_ = nullptr; flags_.can_be_constant = true; } -void ZCombineOperation::init_execution() -{ - image1Reader_ = this->get_input_socket_reader(0); - depth1Reader_ = this->get_input_socket_reader(1); - image2Reader_ = this->get_input_socket_reader(2); - depth2Reader_ = this->get_input_socket_reader(3); -} - -void ZCombineOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float depth1[4]; - float depth2[4]; - - depth1Reader_->read_sampled(depth1, x, y, sampler); - depth2Reader_->read_sampled(depth2, x, y, sampler); - if (depth1[0] < depth2[0]) { - image1Reader_->read_sampled(output, x, y, sampler); - } - else { - image2Reader_->read_sampled(output, x, y, sampler); - } -} - void ZCombineOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -59,34 +29,6 @@ void ZCombineOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void ZCombineAlphaOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float depth1[4]; - float depth2[4]; - float color1[4]; - float color2[4]; - - depth1Reader_->read_sampled(depth1, x, y, sampler); - depth2Reader_->read_sampled(depth2, x, y, sampler); - if (depth1[0] < depth2[0]) { - image1Reader_->read_sampled(color1, x, y, sampler); - image2Reader_->read_sampled(color2, x, y, sampler); - } - else { - image1Reader_->read_sampled(color2, x, y, sampler); - image2Reader_->read_sampled(color1, x, y, sampler); - } - float fac = color1[3]; - float ifac = 1.0f - fac; - output[0] = fac * color1[0] + ifac * color2[0]; - output[1] = fac * color1[1] + ifac * color2[1]; - output[2] = fac * color1[2] + ifac * color2[2]; - output[3] = std::max(color1[3], color2[3]); -} - void ZCombineAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -113,14 +55,6 @@ void ZCombineAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void ZCombineOperation::deinit_execution() -{ - image1Reader_ = nullptr; - depth1Reader_ = nullptr; - image2Reader_ = nullptr; - depth2Reader_ = nullptr; -} - // MASK combine ZCombineMaskOperation::ZCombineMaskOperation() { @@ -128,33 +62,6 @@ ZCombineMaskOperation::ZCombineMaskOperation() this->add_input_socket(DataType::Color); this->add_input_socket(DataType::Color); this->add_output_socket(DataType::Color); - - mask_reader_ = nullptr; - image1Reader_ = nullptr; - image2Reader_ = nullptr; -} - -void ZCombineMaskOperation::init_execution() -{ - mask_reader_ = this->get_input_socket_reader(0); - image1Reader_ = this->get_input_socket_reader(1); - image2Reader_ = this->get_input_socket_reader(2); -} - -void ZCombineMaskOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float mask[4]; - float color1[4]; - float color2[4]; - - mask_reader_->read_sampled(mask, x, y, sampler); - image1Reader_->read_sampled(color1, x, y, sampler); - image2Reader_->read_sampled(color2, x, y, sampler); - - interp_v4_v4v4(output, color1, color2, 1.0f - mask[0]); } void ZCombineMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, @@ -169,28 +76,6 @@ void ZCombineMaskOperation::update_memory_buffer_partial(MemoryBuffer *output, } } -void ZCombineMaskAlphaOperation::execute_pixel_sampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float mask[4]; - float color1[4]; - float color2[4]; - - mask_reader_->read_sampled(mask, x, y, sampler); - image1Reader_->read_sampled(color1, x, y, sampler); - image2Reader_->read_sampled(color2, x, y, sampler); - - float fac = (1.0f - mask[0]) * (1.0f - color1[3]) + mask[0] * color2[3]; - float mfac = 1.0f - fac; - - output[0] = color1[0] * mfac + color2[0] * fac; - output[1] = color1[1] * mfac + color2[1] * fac; - output[2] = color1[2] * mfac + color2[2] * fac; - output[3] = std::max(color1[3], color2[3]); -} - void ZCombineMaskAlphaOperation::update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) @@ -209,11 +94,4 @@ void ZCombineMaskAlphaOperation::update_memory_buffer_partial(MemoryBuffer *outp } } -void ZCombineMaskOperation::deinit_execution() -{ - image1Reader_ = nullptr; - mask_reader_ = nullptr; - image2Reader_ = nullptr; -} - } // namespace blender::compositor diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.h b/source/blender/compositor/operations/COM_ZCombineOperation.h index 52b461ccce8..efe0b2a2075 100644 --- a/source/blender/compositor/operations/COM_ZCombineOperation.h +++ b/source/blender/compositor/operations/COM_ZCombineOperation.h @@ -13,59 +13,29 @@ namespace blender::compositor { * it assumes we are in sRGB color space. */ class ZCombineOperation : public MultiThreadedOperation { - protected: - SocketReader *image1Reader_; - SocketReader *depth1Reader_; - SocketReader *image2Reader_; - SocketReader *depth2Reader_; - public: - /** - * Default constructor - */ ZCombineOperation(); - void init_execution() override; - void deinit_execution() override; - - /** - * The inner loop of this operation. - */ - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; }; class ZCombineAlphaOperation : public ZCombineOperation { - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; }; class ZCombineMaskOperation : public MultiThreadedOperation { - protected: - SocketReader *mask_reader_; - SocketReader *image1Reader_; - SocketReader *image2Reader_; - public: ZCombineMaskOperation(); - void init_execution() override; - void deinit_execution() override; - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; }; class ZCombineMaskAlphaOperation : public ZCombineMaskOperation { - void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; - void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span inputs) override; diff --git a/source/blender/compositor/tests/COM_ComputeSummedAreaTableOperation_test.cc b/source/blender/compositor/tests/COM_ComputeSummedAreaTableOperation_test.cc index e69738f335a..b4b63f596ef 100644 --- a/source/blender/compositor/tests/COM_ComputeSummedAreaTableOperation_test.cc +++ b/source/blender/compositor/tests/COM_ComputeSummedAreaTableOperation_test.cc @@ -11,7 +11,6 @@ namespace blender::compositor::tests { struct SatParams { /* Input parameters. */ SummedAreaTableOperation::eMode mode; - eExecutionModel execution_model; rcti area; float4 fill_value; @@ -27,7 +26,6 @@ TEST_P(SummedAreaTableTestP, Values) SummedAreaTableOperation sat = SummedAreaTableOperation(); - sat.set_execution_model(params.execution_model); sat.set_mode(params.mode); const rcti area = params.area; MemoryBuffer output(DataType::Color, area); @@ -52,7 +50,6 @@ INSTANTIATE_TEST_SUITE_P(FullFrame5x2_IdentityOnes, SummedAreaTableTestP, testing::Values(SatParams{ SummedAreaTableOperation::eMode::Identity, - eExecutionModel::FullFrame, rcti{0, 5, 0, 2}, /* Area. */ {1.0f, 1.0f, 1.0f, 1.0f}, /* Fill value. */ @@ -66,7 +63,6 @@ INSTANTIATE_TEST_SUITE_P( SummedAreaTableTestP, testing::Values(SatParams{ SummedAreaTableOperation::eMode::Squared, - eExecutionModel::FullFrame, rcti{0, 5, 0, 2}, /* Area. */ {1.0f, 1.0f, 1.0f, 1.0f}, /* Fill value. */ @@ -78,7 +74,6 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(FullFrame3x2_Squared, SummedAreaTableTestP, testing::Values(SatParams{SummedAreaTableOperation::eMode::Squared, - eExecutionModel::FullFrame, rcti{0, 3, 0, 2}, /* Area. */ {2.0f, 2.0f, 1.5f, .1f}, /* Fill value. */ @@ -98,7 +93,6 @@ class SummedAreaTableSumTest : public ::testing::Test { protected: void SetUp() override { - operation_->set_execution_model(eExecutionModel::FullFrame); operation_->set_mode(SummedAreaTableOperation::eMode::Squared); area_ = rcti{0, 5, 0, 4}; diff --git a/source/blender/compositor/tests/COM_NodeOperation_test.cc b/source/blender/compositor/tests/COM_NodeOperation_test.cc index 0230b01b891..efb2488ab60 100644 --- a/source/blender/compositor/tests/COM_NodeOperation_test.cc +++ b/source/blender/compositor/tests/COM_NodeOperation_test.cc @@ -14,8 +14,7 @@ class NonHashedOperation : public NodeOperation { { set_id(id); add_output_socket(DataType::Value); - set_width(2); - set_height(3); + set_canvas({0, 2, 0, 3}); } }; @@ -27,8 +26,7 @@ class NonHashedConstantOperation : public ConstantOperation { { set_id(id); add_output_socket(DataType::Value); - set_width(2); - set_height(3); + set_canvas({0, 2, 0, 3}); constant_ = 1.0f; } @@ -53,8 +51,7 @@ class HashedOperation : public NodeOperation { { add_input_socket(DataType::Value); add_output_socket(DataType::Color); - set_width(width); - set_height(height); + set_canvas({0, width, 0, height}); param1 = 2; param2 = 7.0f;