Fix #136310: Crash when using both viewport and normal compositor with fog glow

The issue is caused by the fact that when both compositors are used,
`fftwf_plan_dft_r2c_2d` can end up being called in parallel, which is
only thread-safe if `fftwf_make_planner_thread_safe` is called before.
This is done by `fftw::initialize_float`, but only if the FFTW threading
support library is available. Said library was not detected correctly on
Windows because of a typo, which this change addresses. This should also
make the fog glow faster on Windows because it'll now use multithreaded
FFT as intended.

This change also moves the call to `initialize_float` to the main
function because the FFTW functions it calls are not thread-safe and
because FFTW is also used by Audaspace, which cannot call it.

Pull Request: https://projects.blender.org/blender/blender/pulls/136557
This commit is contained in:
Jorn Visser
2025-03-27 10:20:15 +01:00
committed by Sergey Sharybin
parent cf25a34fe9
commit 3561b11851
4 changed files with 7 additions and 4 deletions

View File

@@ -472,7 +472,9 @@ if(WITH_FFTW3)
${FFTW3}/lib/fftw3_threads.lib
${FFTW3}/lib/fftw3f_threads.lib
)
set(WITH_FFTW3_THREADS_SUPPORT ON)
set(WITH_FFTW3_THREADS_F_SUPPORT ON)
else()
set(WITH_FFTW3_THREADS_F_SUPPORT OFF)
endif()
set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
set(FFTW3_LIBPATH ${FFTW3}/lib)

View File

@@ -12,7 +12,6 @@
#endif
#include "BLI_enumerable_thread_specific.hh"
#include "BLI_fftw.hh"
#include "BLI_hash.hh"
#include "BLI_index_range.hh"
#include "BLI_math_base.h"
@@ -71,7 +70,6 @@ bool operator==(const FogGlowKernelKey &a, const FogGlowKernelKey &b)
FogGlowKernel::FogGlowKernel(int kernel_size, int2 spatial_size)
{
#if defined(WITH_FFTW3)
fftw::initialize_float();
/* The FFTW real to complex transforms utilizes the hermitian symmetry of real transforms and
* stores only half the output since the other half is redundant, so we only allocate half of

View File

@@ -1949,7 +1949,6 @@ class GlareOperation : public NodeOperation {
Result execute_fog_glow(const Result &highlights)
{
#if defined(WITH_FFTW3)
fftw::initialize_float();
const int kernel_size = compute_fog_glow_kernel_size(highlights);

View File

@@ -28,6 +28,7 @@
#include "DNA_genfile.h"
#include "BLI_fftw.hh"
#include "BLI_string.h"
#include "BLI_system.h"
#include "BLI_task.h"
@@ -475,6 +476,9 @@ int main(int argc,
/* After parsing number of threads argument. */
BLI_task_scheduler_init();
/* Initialize FFTW threading support. */
blender::fftw::initialize_float();
#ifndef WITH_PYTHON_MODULE
/* The settings pass includes:
* - Background-mode assignment (#Global.background), checked by other subsystems