Runtime detection of SSE support for raytracing. Also enabled rayoptimization
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 24 Jun 2010 15:54:01 +0000 (15:54 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 24 Jun 2010 15:54:01 +0000 (15:54 +0000)
by default now on all platforms since it shouldn't crash anymore if SSE is
not there. If this breaks compilation on some platforms, please let me know.

CMakeLists.txt
config/linux2-config.py
config/linuxcross-config.py
config/win32-mingw-config.py
config/win32-vc-config.py
config/win64-vc-config.py
source/blender/blenlib/BLI_cpu.h [new file with mode: 0644]
source/blender/blenlib/intern/cpu.c [new file with mode: 0644]
source/blender/render/intern/source/rayshade.c

index 60543e1939a41155c7cd007060deaf69863e7cfc..b4272d5f118d4e9768a9ae79b695259aef983f82 100644 (file)
@@ -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)
 
index 199ea391d4e5b409ccb4d659eafb3590a20d4d46..213c20bd7d00583d52ffcfa9670c976fe891bccc 100644 (file)
@@ -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']
 
 ##
index 8533c8ac9c76c1b47d5cd941211c0930523ccd1d..1650201f8c62d89723518661a814a3f8976df7e6 100644 (file)
@@ -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' ]
index f8b67781172c2e91b95bbe69f6f9fea049bfdc94..9d4c00e569bb2b695a27a6f29dc1c4c3bf85e05e 100644 (file)
@@ -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']
 
 ##
index 02bce0cc7f318fd37d2184e58bf54175d008973e..ce34737fd498e0278ef8199078173a86f5303039 100644 (file)
@@ -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
index de1daa16e0bd5b3474579c7dd1615fc129f94783..46b9034823cca58d22bc74ada117d080d75bd7be 100644 (file)
@@ -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 (file)
index 0000000..d809f1c
--- /dev/null
@@ -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 (file)
index 0000000..490e1c3
--- /dev/null
@@ -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;
+}
+
index bd6e804f13bed6e10f2fc23c1abe90075301239d..bdc1dcc27820ada079e44b15b4c6d4f48d3d61eb 100644 (file)
 #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