Files
test2/build_files/cmake/Modules/FindFftw3.cmake
Omar Emara d4bf23771d Compositor: Optimize Fog Glow Glare node
This patches optimizes the Fog Glow Glare node to be about 25x faster
for 4K images. This is mainly achieved by utilizing the FFTW library and
multi-threading support code. Further improvements are still possible by
caching kernels, but the CPU compositor does not support caching yet.

The old Hartley transform was removed, so the node no longer works when
FFTW is disabled as a build time option, much like the OIDN node. A new
BLI library was introduced for FFTW, it includes some helper routines
relevant for FFTW as well as an initialization routine that sets up
multithreading using TBB as well as thread safety.

Build system support for threaded FFTW was also added, which defines the
relevant variables to detect threading support as well as add the
relevant libraries.

We do not currently have the threaded FFTW libs in our precompiled libs,
so the threading code is disabled until the libs lands in the coming
weeks. So currently, the code is only about 9x faster.

The only functional change is that the kernel is now odd sized, which
should produce more accurate results, but the final result is almost
identical and mostly undetectable.

The plan is to port this to the GPU as well similar to how we implement
OIDN until we have a GPU FFT implementation. GPU compositor can also do
caching, so it should be faster, being able to compute a 4K image in
under half a second.

Pull Request: https://projects.blender.org/blender/blender/pulls/121653
2024-05-17 12:45:21 +02:00

104 lines
2.4 KiB
CMake

# SPDX-FileCopyrightText: 2011 Blender Authors
#
# SPDX-License-Identifier: BSD-3-Clause
# - Find Fftw3 library
# Find the native Fftw3 includes and library
# This module defines
# FFTW3_INCLUDE_DIRS, where to find fftw3.h, Set when
# FFTW3_INCLUDE_DIR is found.
# FFTW3_LIBRARIES, libraries to link against to use Fftw3.
# FFTW3_ROOT_DIR, The base directory to search for Fftw3.
# This can also be an environment variable.
# FFTW3_FOUND, If false, do not try to use Fftw3.
# WITH_FFTW3_THREADS_F_SUPPORT, if true, single precision Fftw3 supports threads.
#
# also defined, but not for general use are
# FFTW3_LIBRARY_F, where to find the Fftw3 library (single precision float).
# FFTW3_LIBRARY_THREADS_F, where to find the Fftw3 threads library (single precision float).
# FFTW3_LIBRARY_D, where to find the Fftw3 library (double precision float).
# If `FFTW3_ROOT_DIR` was defined in the environment, use it.
if(DEFINED FFTW3_ROOT_DIR)
# Pass.
elseif(DEFINED ENV{FFTW3_ROOT_DIR})
set(FFTW3_ROOT_DIR $ENV{FFTW3_ROOT_DIR})
else()
set(FFTW3_ROOT_DIR "")
endif()
set(_fftw3_SEARCH_DIRS
${FFTW3_ROOT_DIR}
)
find_path(FFTW3_INCLUDE_DIR
NAMES
fftw3.h
HINTS
${_fftw3_SEARCH_DIRS}
PATH_SUFFIXES
include
)
set(_FFTW3_LIBRARIES)
find_library(FFTW3_LIBRARY_F
NAMES
fftw3f
HINTS
${_fftw3_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)
find_library(FFTW3_LIBRARY_THREADS_F
NAMES
fftw3f_threads
HINTS
${_fftw3_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)
find_library(FFTW3_LIBRARY_D
NAMES
fftw3
HINTS
${_fftw3_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)
list(APPEND _FFTW3_LIBRARIES "${FFTW3_LIBRARY_F}")
list(APPEND _FFTW3_LIBRARIES "${FFTW3_LIBRARY_D}")
if(FFTW3_LIBRARY_THREADS_F)
list(APPEND _FFTW3_LIBRARIES "${FFTW3_LIBRARY_THREADS_F}")
endif()
# handle the QUIETLY and REQUIRED arguments and set FFTW3_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Fftw3 DEFAULT_MSG
_FFTW3_LIBRARIES FFTW3_INCLUDE_DIR)
if(FFTW3_FOUND)
set(FFTW3_LIBRARIES ${_FFTW3_LIBRARIES})
set(FFTW3_INCLUDE_DIRS ${FFTW3_INCLUDE_DIR})
if(FFTW3_LIBRARY_THREADS_F)
set(WITH_FFTW3_THREADS_F_SUPPORT ON)
else()
set(WITH_FFTW3_THREADS_F_SUPPORT OFF)
endif()
endif()
mark_as_advanced(
FFTW3_INCLUDE_DIR
FFTW3_LIBRARY_F
FFTW3_LIBRARY_THREADS_F
FFTW3_LIBRARY_D
)
unset(_FFTW3_LIBRARIES)
unset(_fftw3_SEARCH_DIRS)