diff --git a/CMakeLists.txt b/CMakeLists.txt index 60543e1939a..b4272d5f118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,7 @@ OPTION(WITH_LZO "Enable fast LZO compression (used for pointcache)" ON OPTION(WITH_LZMA "Enable best LZMA compression, (used for pointcache)" ON) # Misc -OPTION(WITH_RAYOPTIMIZATION "Enable use of SIMD (SSE) optimizations for the raytracer" OFF) +OPTION(WITH_RAYOPTIMIZATION "Enable use of SIMD (SSE) optimizations for the raytracer" ON) OPTION(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking" OFF) OPTION(WITH_INSTALL "Install accompanying scripts and language files needed to run blender" ON) diff --git a/config/linux2-config.py b/config/linux2-config.py index 199ea391d4e..213c20bd7d0 100644 --- a/config/linux2-config.py +++ b/config/linux2-config.py @@ -168,7 +168,7 @@ BF_EXPAT_LIBPATH = '/usr/lib' WITH_BF_OPENMP = True #Ray trace optimization -WITH_BF_RAYOPTIMIZATION = False +WITH_BF_RAYOPTIMIZATION = True BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse','-pthread'] ## diff --git a/config/linuxcross-config.py b/config/linuxcross-config.py index 8533c8ac9c7..1650201f8c6 100644 --- a/config/linuxcross-config.py +++ b/config/linuxcross-config.py @@ -169,7 +169,7 @@ BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader Open BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib ${BF_ICONV_LIBPATH}' #Ray trace optimization -WITH_BF_RAYOPTIMIZATION = False +WITH_BF_RAYOPTIMIZATION = True BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse'] CCFLAGS = [ '-pipe', '-funsigned-char', '-fno-strict-aliasing' ] diff --git a/config/win32-mingw-config.py b/config/win32-mingw-config.py index f8b67781172..9d4c00e569b 100644 --- a/config/win32-mingw-config.py +++ b/config/win32-mingw-config.py @@ -155,7 +155,7 @@ BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader Open BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' #Ray trace optimization -WITH_BF_RAYOPTIMIZATION = False +WITH_BF_RAYOPTIMIZATION = True BF_RAYOPTIMIZATION_SSE_FLAGS = ['-msse'] ## diff --git a/config/win32-vc-config.py b/config/win32-vc-config.py index 02bce0cc7f3..ce34737fd49 100644 --- a/config/win32-vc-config.py +++ b/config/win32-vc-config.py @@ -150,7 +150,7 @@ BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader Open BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' #Ray trace optimization -WITH_BF_RAYOPTIMIZATION = False +WITH_BF_RAYOPTIMIZATION = True BF_RAYOPTIMIZATION_SSE_FLAGS = ['/arch:SSE'] WITH_BF_STATICOPENGL = False diff --git a/config/win64-vc-config.py b/config/win64-vc-config.py index de1daa16e0b..46b9034823c 100644 --- a/config/win64-vc-config.py +++ b/config/win64-vc-config.py @@ -163,7 +163,7 @@ BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader Open BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' #Ray trace optimization -WITH_BF_RAYOPTIMIZATION = False +WITH_BF_RAYOPTIMIZATION = True BF_RAYOPTIMIZATION_SSE_FLAGS = ['/arch:SSE','/arch:SSE2'] WITH_BF_STATICOPENGL = False diff --git a/source/blender/blenlib/BLI_cpu.h b/source/blender/blenlib/BLI_cpu.h new file mode 100644 index 00000000000..d809f1cc594 --- /dev/null +++ b/source/blender/blenlib/BLI_cpu.h @@ -0,0 +1,30 @@ +/* + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef BLI_CPU_H +#define BLI_CPU_H + +int BLI_cpu_support_sse2(void); + +#endif + diff --git a/source/blender/blenlib/intern/cpu.c b/source/blender/blenlib/intern/cpu.c new file mode 100644 index 00000000000..490e1c3f02a --- /dev/null +++ b/source/blender/blenlib/intern/cpu.c @@ -0,0 +1,52 @@ +/** + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "BLI_cpu.h" + +int BLI_cpu_support_sse2(void) +{ +#if defined(__x86_64__) || defined(_M_X64) + /* x86_64 always has SSE2 instructions */ + return 1; +#elif defined(__GNUC__) && defined(i386) + /* for GCC x86 we check cpuid */ + unsigned int a, b, c, d; + __asm__("cpuid": "=a"(a), "=b"(b), "=c"(c), "=d"(d): "a"(1)); + return (d & 0x04000000) != 0; +#elif (defined(_MSC_VER) && defined(_M_IX86)) + /* also check cpuid for MSVC x86 */ + unsigned int d; + __asm { + xor eax, eax + inc eax + push ebx + cpuid + pop ebx + mov d, edx + } + return (d & 0x04000000) != 0; +#endif + + return 0; +} + diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index bd6e804f13b..bdc1dcc2782 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -41,9 +41,10 @@ #include "BKE_node.h" #include "BKE_utildefines.h" -#include "BLI_math.h" #include "BLI_blenlib.h" +#include "BLI_cpu.h" #include "BLI_jitter.h" +#include "BLI_math.h" #include "BLI_rand.h" #include "PIL_time.h" @@ -98,7 +99,7 @@ RayObject* RE_rayobject_create(Render *re, int type, int size) //TODO //if(detect_simd()) #ifdef __SSE__ - type = R_RAYSTRUCTURE_SIMD_SVBVH; + type = BLI_cpu_support_sse2()? R_RAYSTRUCTURE_SIMD_SVBVH: R_RAYSTRUCTURE_VBVH; #else type = R_RAYSTRUCTURE_VBVH; #endif