Build: Add WITH_OPTIMIZED_BUILD_TOOLS

Enable optimizations on Debug builds for executables used for the build
process (datatoc and glsl_preprocess) and enable unity builds for
shader preprocessing targets.

Debug: From 28.9s to 5.7s
Release: From 4.9s to 3.5s

Pull Request: https://projects.blender.org/blender/blender/pulls/138274
This commit is contained in:
Miguel Pozo
2025-05-02 18:33:44 +02:00
parent 37dcdb2b6a
commit f24ad7a470
7 changed files with 24 additions and 0 deletions

View File

@@ -302,6 +302,12 @@ Use pre-compiled headers to speed up compilation."
endif()
endif()
option(WITH_OPTIMIZED_BUILD_TOOLS "\
Enable optimizations even on Debug builds for executables used for the build process"
ON
)
mark_as_advanced(WITH_OPTIMIZED_BUILD_TOOLS)
option(WITH_IK_ITASC "\
Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)"
ON
@@ -2757,6 +2763,7 @@ if(FIRST_RUN)
info_cfg_text("Compiler Options:")
info_cfg_option(WITH_BUILDINFO)
info_cfg_option(WITH_OPTIMIZED_BUILD_TOOLS)
info_cfg_text("System Options:")
info_cfg_option(WITH_INSTALL_PORTABLE)

View File

@@ -1513,3 +1513,15 @@ function(compile_sources_as_cpp
target_include_directories(${executable} PUBLIC ${INC_GLSL})
target_compile_definitions(${executable} PRIVATE ${define})
endfunction()
macro(optimize_debug_target executable)
if(WITH_OPTIMIZED_BUILD_TOOLS)
if(WIN32)
remove_cc_flag(${executable} "/Od" "/RTC1")
target_compile_options(${executable} PRIVATE "/Ox")
target_compile_definitions(${executable} PRIVATE "_ITERATOR_DEBUG_LEVEL=0")
else()
target_compile_options(${executable} PRIVATE "-O2")
endif()
endif()
endmacro()

View File

@@ -309,6 +309,7 @@ foreach(GLSL_FILE ${GLSL_SRC})
endforeach()
blender_add_lib(bf_compositor_shaders "${GLSL_C}" "" "" "")
blender_set_target_unity_build(bf_compositor_shaders 10)
list(APPEND LIB
bf_compositor_shaders

View File

@@ -11,3 +11,4 @@ set(SRC
# `SRC_DNA_INC` is defined in the parent directory.
add_executable(datatoc ${SRC})
optimize_debug_target(datatoc)

View File

@@ -733,6 +733,7 @@ foreach(GLSL_FILE ${GLSL_SRC})
endforeach()
blender_add_lib(bf_draw_shaders "${GLSL_C}" "" "" "")
blender_set_target_unity_build(bf_draw_shaders 10)
list(APPEND LIB
PRIVATE bf::animrig

View File

@@ -710,6 +710,7 @@ if(WITH_METAL_BACKEND)
endif()
blender_add_lib(bf_gpu_shaders "${SHADER_C}" "" "" "")
blender_set_target_unity_build(bf_gpu_shaders 10)
list(APPEND LIB
bf_gpu_shaders

View File

@@ -17,3 +17,4 @@ endif()
# `SRC_DNA_INC` is defined in the parent directory.
add_executable(glsl_preprocess ${SRC})
optimize_debug_target(glsl_preprocess)