[Bf-blender-cvs] [f505dcc] opensubdiv-modifier: Bring new OpenSubdiv with CUEW support

Sergey Sharybin noreply at git.blender.org
Fri May 30 10:27:09 CEST 2014


Commit: f505dccd5fe571d7dc8b92f09892a7c041f33805
Author: Sergey Sharybin
Date:   Fri May 30 13:58:00 2014 +0600
https://developer.blender.org/rBf505dccd5fe571d7dc8b92f09892a7c041f33805

Bring new OpenSubdiv with CUEW support

WARNING: Latest fork of OpenSubdiv is to be used to be able to compile
this revision:

  https://github.com/Nazg-Gul/OpenSubdiv/tree/cuda-dynload

We'll work on pull-request when our branch would be proved to work on
Linux (which seems to work already) and Windows (need to test this,
that's why commit is happening now -- stashing changes, creating a
milestone, easier access from Windows!).

NOTE: Would ask platform maintainers to not bother trying to make this
revision to work yet. Lemme test things on Windows first and it it
all work i'll prepare libs for windows and do a pull-request to an
upstream.

Main idea is to make OpenSubdiv to detect OpenCL and CUDA on runtime.
Before this Blender was linking against libOpenCL and libcuda which
is not good for portability.

OpenCL part was already kind of done, but wasn't properly integrated.
Not sure why it compiled even :)

CUDA is now does the same trick as Cycles does with dynamic load of
cuda driver api library.

That would have been real straightforward change if we wouldn't try
to de-duplicate CUDA/CL wrappers in the Blender sources. The thing
is, Cycles, Compositor and OpenSubdiv all requires wrappers for this
libraries and it was real stupid to have two clew (for Cycles and
Compositor) already.

The idea to solve this is: move clew/cuew to extern/ and make all
the bits which requires cuda/cl to use those wrappers instead of
shipping their own. This is real straightforward change to make
Cycles and Compositor happy since it's easy to re-arrange libraries
we're maintaining in the sources. Making it so OpenSubdiv libraries
can use symbols from our extern_{clew,cuew} was rather a black
magic but it appeared to work pretty well here on Linux. Let's
see how it works on Windows now.

TODO:
- Make sure Windows works
- Remove cuda/cl wrappers from intern/cycles
- Make sure Cycles stadalone works

As for Cycles standalone it's real easy to make it compiled when
building from inside Blender. When/if we'll move Cycles to own
repo it's still easy to make it use clew/cuew by putting them to
extern/ or third_party/ folder in Cycles repo.

===================================================================

M	SConstruct
M	build_files/cmake/Modules/FindOpenSubdiv.cmake
M	build_files/scons/config/linux-config.py
M	build_files/scons/config/win32-vc-config.py
M	build_files/scons/tools/Blender.py
M	extern/CMakeLists.txt
M	extern/SConscript
M	extern/clew/SConscript
A	extern/cuew/CMakeLists.txt
A	extern/cuew/SConscript
A	extern/cuew/include/cuew.h
A	extern/cuew/src/cuew.c
M	intern/opensubdiv/CMakeLists.txt
M	intern/opensubdiv/SConscript
M	intern/opensubdiv/clInit.h
M	intern/opensubdiv/cudaInit.h
M	intern/opensubdiv/opensubdiv_capi.cc
M	source/blenderplayer/CMakeLists.txt
M	source/creator/CMakeLists.txt

===================================================================

diff --git a/SConstruct b/SConstruct
index 8ddba97..fde6cbb 100644
--- a/SConstruct
+++ b/SConstruct
@@ -68,7 +68,7 @@ quickdebug = None
 
 ##### BEGIN SETUP #####
 
-B.possible_types = ['core', 'player', 'player2', 'intern', 'extern']
+B.possible_types = ['core', 'player', 'player2', 'intern', 'extern', 'system']
 
 B.binarykind = ['blender' , 'blenderplayer']
 ##################################
@@ -790,7 +790,7 @@ SConscript(B.root_build_dir+'/extern/SConscript')
 # libraries to give as objects to linking phase
 mainlist = []
 for tp in B.possible_types:
-    if (not tp == 'player') and (not tp == 'player2'):
+    if (not tp == 'player') and (not tp == 'player2') and (not tp == 'system'):
         mainlist += B.create_blender_liblist(env, tp)
 
 if B.arguments.get('BF_PRIORITYLIST', '0')=='1':
@@ -801,6 +801,11 @@ creob = B.creator(env)
 thestatlibs, thelibincs = B.setup_staticlibs(env)
 thesyslibs = B.setup_syslibs(env)
 
+# Hack to pass OSD libraries to linker before extern_{clew,cuew}
+for x in B.create_blender_liblist(env, 'system'):
+    thesyslibs.append(os.path.basename(x))
+    thelibincs.append(os.path.dirname(x))
+
 if 'blender' in B.targets or not env['WITH_BF_NOBLENDER']:
     env.BlenderProg(B.root_build_dir, "blender", creob + mainlist + thestatlibs + dobj, thesyslibs, [B.root_build_dir+'/lib'] + thelibincs, 'blender')
 if env['WITH_BF_PLAYER']:
diff --git a/build_files/cmake/Modules/FindOpenSubdiv.cmake b/build_files/cmake/Modules/FindOpenSubdiv.cmake
index 05847ae..7733c76 100644
--- a/build_files/cmake/Modules/FindOpenSubdiv.cmake
+++ b/build_files/cmake/Modules/FindOpenSubdiv.cmake
@@ -102,18 +102,6 @@ IF(OPENSUBDIV_FOUND)
   OPENSUBDIV_CHECK_CONTROLLER("cudaComputeController.h" OPENSUBDIV_HAS_CUDA)
   OPENSUBDIV_CHECK_CONTROLLER("glslTransformFeedbackComputeController.h" OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK)
   OPENSUBDIV_CHECK_CONTROLLER("osd/glslComputeController.h" OPENSUBDIV_HAS_GLSL_COMPUTE)
-
-  IF(OPENSUBDIV_HAS_CUDA)
-    # TODO(sergey): Ideally we do linking to CUDA runtime, not compile time,
-    # so this way we can have Blender running on the systems which don't have
-   # NVidia or don't have CUDA runtime libraries.
-     #
-    # Or we'll just use GLSL backend on all the systems.
-    FIND_PACKAGE(CUDA)
-    IF(CUDA_FOUND)
-      LIST(APPEND OPENSUBDIV_LIBRARIES ${CUDA_CUDART_LIBRARY})
-    ENDIF()
-  ENDIF()
 ENDIF(OPENSUBDIV_FOUND)
 
 MARK_AS_ADVANCED(
diff --git a/build_files/scons/config/linux-config.py b/build_files/scons/config/linux-config.py
index effad28..f6172f9 100644
--- a/build_files/scons/config/linux-config.py
+++ b/build_files/scons/config/linux-config.py
@@ -230,8 +230,8 @@ WITH_BF_OPENSUBDIV = False
 WITH_BF_STATICOPENSUBDIV = False
 BF_OPENSUBDIV = '/usr'
 BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
-BF_OPENSUBDIV_LIB = 'osdCPU osdGPU osdutil'
-BF_OPENSUBDIV_LIB_STATIC = '${BF_OPENSUBDIV_LIBPATH}/libosdCPU.a ${BF_OPENSUBDIV_LIBPATH}/libosdGPU.a ${BF_OPENSUBDIV_LIBPATH}/libosdutil.a'
+BF_OPENSUBDIV_LIB = 'osdutil osdGPU osdCPU'
+BF_OPENSUBDIV_LIB_STATIC = '${BF_OPENSUBDIV_LIBPATH}/libosdutil.a ${BF_OPENSUBDIV_LIBPATH}/libosdGPU.a ${BF_OPENSUBDIV_LIBPATH}/libosdCPU.a'
 BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
 
 ##
diff --git a/build_files/scons/config/win32-vc-config.py b/build_files/scons/config/win32-vc-config.py
index 18c872e..5502d7b 100644
--- a/build_files/scons/config/win32-vc-config.py
+++ b/build_files/scons/config/win32-vc-config.py
@@ -219,7 +219,7 @@ WITH_BF_FREESTYLE = True
 WITH_BF_OPENSUBDIV = False
 BF_OPENSUBDIV = LIBDIR + '/opensubdiv'
 BF_OPENSUBDIV_INC = '${BF_OPENSUBDIV}/include'
-BF_OPENSUBDIV_LIB = 'osdCPU'
+BF_OPENSUBDIV_LIB = 'osdutil osdGPU osdCPU'
 BF_OPENSUBDIV_LIBPATH = '${BF_OPENSUBDIV}/lib'
 
 WITH_BF_STATICOPENGL = False
diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py
index 87a3467..c5f7158 100644
--- a/build_files/scons/tools/Blender.py
+++ b/build_files/scons/tools/Blender.py
@@ -113,7 +113,6 @@ def create_blender_liblist(lenv = None, libtype = None):
             else:
                 target = os.path.abspath(root_build_dir + 'lib' + os.sep +lenv['LIBPREFIX'] + v + lenv['LIBSUFFIX'])
             lst.append(target)
-
     return lst
 
 ## TODO: static linking
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 301386f..df61988 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -72,6 +72,7 @@ endif()
 
 if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
     add_subdirectory(clew)
+    add_subdirectory(cuew)
 endif()
 
 if(WITH_MOD_BOOLEAN)
diff --git a/extern/SConscript b/extern/SConscript
index c3c026a..daa1315 100644
--- a/extern/SConscript
+++ b/extern/SConscript
@@ -22,6 +22,7 @@ if env['WITH_BF_BULLET']:
 
 if env['WITH_BF_COMPOSITOR'] or env['WITH_BF_OPENSUBDIV']:
     SConscript (['clew/SConscript'])
+    SConscript (['cuew/SConscript'])
 
 if env['WITH_BF_OPENJPEG'] and env['BF_OPENJPEG_LIB'] == '':
     SConscript(['libopenjpeg/SConscript'])
diff --git a/extern/clew/SConscript b/extern/clew/SConscript
index d606d8d..14a03c7 100644
--- a/extern/clew/SConscript
+++ b/extern/clew/SConscript
@@ -32,4 +32,4 @@ sources = env.Glob('src/clew.c')
 incs = 'include'
 defs = ['CL_USE_DEPRECATED_OPENCL_1_1_APIS']
 
-env.BlenderLib ( 'clew', sources, Split(incs), defines=defs, libtype=['core','player'], priority = [192,192] )
+env.BlenderLib ('extern_clew', sources, Split(incs), defines=defs, libtype=['system'], priority = [999])
diff --git a/extern/clew/SConscript b/extern/cuew/CMakeLists.txt
similarity index 76%
copy from extern/clew/SConscript
copy to extern/cuew/CMakeLists.txt
index d606d8d..284fbbc 100644
--- a/extern/clew/SConscript
+++ b/extern/cuew/CMakeLists.txt
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # ***** BEGIN GPL LICENSE BLOCK *****
 #
 # This program is free software; you can redistribute it and/or
@@ -21,15 +19,22 @@
 #
 # The Original Code is: all of this file.
 #
-# Contributor(s): Nathan Letwory.
+# Contributor(s): Jacques Beaurain.
 #
 # ***** END GPL LICENSE BLOCK *****
 
-Import ('env')
+set(INC
+	.
+	include
+)
+
+set(INC_SYS
 
-sources = env.Glob('src/clew.c')
+)
 
-incs = 'include'
-defs = ['CL_USE_DEPRECATED_OPENCL_1_1_APIS']
+set(SRC
+	include/cuew.h
+	src/cuew.c
+)
 
-env.BlenderLib ( 'clew', sources, Split(incs), defines=defs, libtype=['core','player'], priority = [192,192] )
+blender_add_lib(extern_cuew "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/extern/clew/SConscript b/extern/cuew/SConscript
similarity index 84%
copy from extern/clew/SConscript
copy to extern/cuew/SConscript
index d606d8d..9c12c71 100644
--- a/extern/clew/SConscript
+++ b/extern/cuew/SConscript
@@ -27,9 +27,9 @@
 
 Import ('env')
 
-sources = env.Glob('src/clew.c')
+sources = env.Glob('src/cuew.c')
 
 incs = 'include'
-defs = ['CL_USE_DEPRECATED_OPENCL_1_1_APIS']
+defs = []
 
-env.BlenderLib ( 'clew', sources, Split(incs), defines=defs, libtype=['core','player'], priority = [192,192] )
+env.BlenderLib ('extern_cuew', sources, Split(incs), defines=defs, libtype=['system'], priority = [0])
diff --git a/extern/cuew/include/cuew.h b/extern/cuew/include/cuew.h
new file mode 100644
index 0000000..573fea6
--- /dev/null
+++ b/extern/cuew/include/cuew.h
@@ -0,0 +1,624 @@
+/*
+ * Copyright 2011-2014 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#ifndef CUEW_H
+#define CUEW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdlib.h>
+
+/* defines, structs, enums */
+
+#define CUDA_VERSION 3020
+
+typedef unsigned int GLenum;
+typedef unsigned int GLuint;
+
+#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) || defined(__LP64__)
+typedef unsigned long long CUdeviceptr;
+#else
+typedef unsigned int CUdeviceptr;
+#endif
+
+typedef int CUdevice;
+typedef struct CUctx_st *CUcontext;
+typedef struct CUmod_st *CUmodule;
+typedef struct CUfunc_st *CUfunction;
+typedef struct CUarray_st *CUarray;
+typedef struct CUtexref_st *CUtexref;
+typedef struct CUsurfref_st *CUsurfref;
+typedef struct CUevent_st *CUevent;
+typedef struct CUstream_st *CUstream;
+typedef struct CUgraphicsResource_st *CUgraphicsResource;
+
+typedef struct CUuuid_st {
+	char bytes[16];
+} CUuuid;
+
+typedef enum CUctx_flags_enum {
+	CU_CTX_SCHED_AUTO  = 0,
+	CU_CTX_SCHED_SPIN  = 1,
+	CU_CTX_SCHED_YIELD = 2,
+	CU_CTX_SCHED_MASK  = 0x3,
+	CU_CTX_BLOCKING_SYNC = 4,
+	CU_CTX_MAP_HOST = 8,
+	CU_CTX_LMEM_RESIZE_TO_MAX = 16,
+	CU_CTX_FLAGS_MASK  = 0x1f
+} CUctx_flags;
+
+typedef enum CUevent_flags_enum {
+	CU_EVENT_DEFAULT        = 0,
+	CU_EVENT_BLOCKING_SYNC  = 1,
+	CU_EVENT_DISABLE_TIMING = 2
+} CUevent_flags;
+
+typedef enum CUarray_format_enum {
+	CU_AD_FORMAT_UNSIGNED_INT8  = 0x01,
+	CU_AD_FORMAT_UNSIGNED_INT16 = 0x02,
+	CU_AD_FORMAT_UNSIGNED_INT32 = 0x03,
+	CU_AD_FORMAT_SIGNED_INT8    = 0x08,
+	CU_AD_FORMAT_SIGNED_INT16   = 0x09,
+	CU_AD_FORMAT_SIGNED_INT32   = 0x0a,
+	CU_AD_FORMAT_HALF           = 0x10,
+	CU_AD_FORMAT_FLOAT          = 0x20
+} CUarray_format;
+
+typedef enum CUaddress_mode_enum {
+	CU_TR_ADDRESS_MODE_WRAP   = 0,
+	CU_TR_ADDRESS_MODE_CLAMP  = 1,
+	CU_TR_ADDRESS_MODE_MIRROR = 2,
+	CU_TR_ADDRESS_MODE_BORDER = 3
+} CUaddress_mode;
+
+typedef enum CUfilter_mode_enum {
+	CU_TR_FILTER_MODE_POINT  = 0,
+	CU_TR_FILTER_MODE_LINEAR = 1
+} CUfilter_mode;
+
+typedef enum CUdevice_attribute_enum {
+	CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK = 1,
+	CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X = 2,
+	CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y = 3,
+	CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z = 4,
+	CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X = 5,
+	CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y = 6,
+	CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z = 7,
+	CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK = 8,
+	CU_DEVICE_ATTRIBUTE_SHARE

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list