[Bf-blender-cvs] [1a553d8] opensubdiv-modifier: Further refactor of OpenSubdiv C-APi

Sergey Sharybin noreply at git.blender.org
Mon May 12 20:09:01 CEST 2014


Commit: 1a553d84d8b2eaf03909132c1d17d1d6888f93c1
Author: Sergey Sharybin
Date:   Sun May 11 18:33:10 2014 +0200
https://developer.blender.org/rB1a553d84d8b2eaf03909132c1d17d1d6888f93c1

Further refactor of OpenSubdiv C-APi

Now it's possible to create GL Mesh with different types
of controllers and it's OpenSubdiv API which would worry
about how to allocate the controller.

Currently not exposed to UI and still hardcoded to CUDA.x

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

M	build_files/cmake/Modules/FindOpenSubdiv.cmake
M	intern/opensubdiv/CMakeLists.txt
M	intern/opensubdiv/opensubdiv_capi.cc
M	intern/opensubdiv/opensubdiv_capi.h
M	intern/opensubdiv/opensubdiv_gpu_capi.cc
M	source/blender/blenkernel/intern/CCGSubSurf.c
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/SConscript
M	source/blender/windowmanager/intern/wm_init_exit.c

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

diff --git a/build_files/cmake/Modules/FindOpenSubdiv.cmake b/build_files/cmake/Modules/FindOpenSubdiv.cmake
index 0119969..efe3707 100644
--- a/build_files/cmake/Modules/FindOpenSubdiv.cmake
+++ b/build_files/cmake/Modules/FindOpenSubdiv.cmake
@@ -66,6 +66,17 @@ FOREACH(COMPONENT ${_opensubdiv_FIND_COMPONENTS})
   LIST(APPEND _opensubdiv_LIBRARIES "${OPENSUBDIV_${UPPERCOMPONENT}_LIBRARY}")
 ENDFOREACH()
 
+MACRO(OPENSUBDIV_CHECK_CONTROLLER
+      controller_include_file
+      variable_name)
+  IF(EXISTS "${OPENSUBDIV_INCLUDE_DIR}/opensubdiv/osd/${controller_include_file}")
+    SET(${variable_name} TRUE)
+  ELSE()
+    SET(${variable_name} FALSE)
+  ENDIF()
+ENDMACRO()
+
+
 # handle the QUIETLY and REQUIRED arguments and set OPENSUBDIV_FOUND to TRUE if
 # all listed variables are TRUE
 INCLUDE(FindPackageHandleStandardArgs)
@@ -76,14 +87,39 @@ IF(OPENSUBDIV_FOUND)
   SET(OPENSUBDIV_LIBRARIES ${_opensubdiv_LIBRARIES})
   SET(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
 
-  # TODO(sergey): Ideally we do linking to CUDA n 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})
+  # Find available compute controllers.
+
+  FIND_PACKAGE(OpenMP)
+  IF(OPENMP_FOUND)
+    SET(OPENSUBDIV_HAS_OPENMP TRUE)
+  ELSE()
+    SET(OPENSUBDIV_HAS_OPENMP FALSE)
+  ENDIF()
+
+  OPENSUBDIV_CHECK_CONTROLLER("tbbComputeController.h" OPENSUBDIV_HAS_TBB)
+  OPENSUBDIV_CHECK_CONTROLLER("gcdComputeController.h" OPENSUBDIV_HAS_GCD)
+  OPENSUBDIV_CHECK_CONTROLLER("clComputeController.h" OPENSUBDIV_HAS_OPENCL)
+  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()
+
+  IF(OPENSUBDIV_HAS_OPENCL)
+    # TODO(sergey): Exactly the same reason as above.
+    # TODO(sergey): There's no OpenCL finder in CMake
+    #FIND_PACKAGE(OpenCL)
+    LIST(APPEND OPENSUBDIV_LIBRARIES "OpenCL")
   ENDIF()
 ENDIF(OPENSUBDIV_FOUND)
 
diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt
index f6beaa0..942f995 100644
--- a/intern/opensubdiv/CMakeLists.txt
+++ b/intern/opensubdiv/CMakeLists.txt
@@ -35,9 +35,23 @@ set(INC_SYS
 set(SRC
 	opensubdiv_capi.cc
 	opensubdiv_gpu_capi.cc
+	clInit.h
+	cudaInit.h
 	opensubdiv_capi.h
 )
 
+MACRO(OPENSUBDIV_DEFINE_COMPONENT component)
+	if(${component})
+		add_definitions(-D${component})
+	endif()
+ENDMACRO()
+
+OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_OPENMP)
+OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_OPENCL)
+OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_CUDA)
+OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK)
+OPENSUBDIV_DEFINE_COMPONENT(OPENSUBDIV_HAS_GLSL_COMPUTE)
+
 data_to_c_simple(gpu_shader_opensubd_display.glsl SRC)
 
 blender_add_lib(bf_intern_opensubdiv "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/opensubdiv/opensubdiv_capi.cc b/intern/opensubdiv/opensubdiv_capi.cc
index 6c7a9f1..2069c25 100644
--- a/intern/opensubdiv/opensubdiv_capi.cc
+++ b/intern/opensubdiv/opensubdiv_capi.cc
@@ -37,17 +37,47 @@
 #include <opensubdiv/osd/cpuComputeContext.h>
 #include <opensubdiv/osd/cpuComputeController.h>
 
-// CUDA backend
-#include <opensubdiv/osd/cudaGLVertexBuffer.h>
-#include <opensubdiv/osd/cudaComputeContext.h>
-#include <opensubdiv/osd/cudaComputeController.h>
-
-#include "cudaInit.h"
+#ifdef OPENSUBDIV_HAS_OPENMP
+#  include <opensubdiv/osd/ompComputeController.h>
+#endif
+
+#ifdef OPENSUBDIV_HAS_OPENCL
+#  include <opensubdiv/osd/clGLVertexBuffer.h>
+#  include <opensubdiv/osd/clComputeContext.h>
+#  include <opensubdiv/osd/clComputeController.h>
+#  include "clInit.h"
+#endif
+
+#ifdef OPENSUBDIV_HAS_CUDA
+#  include <opensubdiv/osd/cudaGLVertexBuffer.h>
+#  include <opensubdiv/osd/cudaComputeContext.h>
+#  include <opensubdiv/osd/cudaComputeController.h>
+#  include "cudaInit.h"
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
+#  include <opensubdiv/osd/glslTransformFeedbackComputeContext.h>
+#  include <opensubdiv/osd/glslTransformFeedbackComputeController.h>
+#  include <opensubdiv/osd/glVertexBuffer.h>
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
+#  include <opensubdiv/osd/glslComputeContext.h>
+#  include <opensubdiv/osd/glslComputeController.h>
+#  include <opensubdiv/osd/glVertexBuffer.h>
+#endif
 
 #include "MEM_guardedalloc.h"
 
 /* **************** Types declaration **************** */
 
+struct OpenSubdiv_ComputeControllerDescr;
+
+typedef struct OpenSubdiv_ComputeController {
+	int type;
+	OpenSubdiv_ComputeControllerDescr *descriptor;
+} OpenSubdiv_ComputeController;
+
 using OpenSubdiv::OsdCpuComputeController;
 using OpenSubdiv::OsdGLDrawContext;
 using OpenSubdiv::OsdGLMeshInterface;
@@ -56,67 +86,159 @@ using OpenSubdiv::OsdMeshBitset;
 using OpenSubdiv::OsdUtilSubdivTopology;
 using OpenSubdiv::OsdVertex;
 
+typedef OpenSubdiv::HbrMesh<OsdVertex> OsdHbrMesh;
+
+using OpenSubdiv::OsdGLVertexBuffer;
+using OpenSubdiv::OsdGLDrawContext;
+
 // CPU backend
 using OpenSubdiv::OsdCpuGLVertexBuffer;
 using OpenSubdiv::OsdCpuComputeController;
-
-// CUDA backend
+static OpenSubdiv_ComputeController *g_cpuComputeController = NULL;
+typedef OsdMesh<OsdCpuGLVertexBuffer,
+                OsdCpuComputeController,
+                OsdGLDrawContext> OsdCpuMesh;
+
+#ifdef OPENSUBDIV_HAS_OPENMP
+using OpenSubdiv::OsdOmpComputeController;
+static OpenSubdiv_ComputeController *g_ompComputeController = NULL;
+typedef OsdMesh<OsdCpuGLVertexBuffer,
+                OsdOmpComputeController,
+                OsdGLDrawContext> OsdOmpMesh;
+#endif
+
+#ifdef OPENSUBDIV_HAS_OPENCL
+using OpenSubdiv::OsdCLGLVertexBuffer;
+using OpenSubdiv::OsdCLComputeController;
+typedef OsdMesh<OsdCLGLVertexBuffer,
+                OsdCLComputeController,
+                OsdGLDrawContext> OsdCLMesh;
+static OpenSubdiv_ComputeController *g_clComputeController = NULL;
+static cl_context g_clContext;
+static cl_command_queue g_clQueue;
+#endif
+
+#ifdef OPENSUBDIV_HAS_CUDA
 using OpenSubdiv::OsdCudaComputeController;
 using OpenSubdiv::OsdCudaGLVertexBuffer;
-
-typedef OpenSubdiv::HbrMesh<OsdVertex> OsdHbrMesh;
 typedef OsdMesh<OsdCudaGLVertexBuffer,
                 OsdCudaComputeController,
-                OsdGLDrawContext> OsdCPUGLMesh;
-
-/* **************** CPU Compute Controller **************** */
-
-struct OpenSubdiv_CPUComputeController *openSubdiv_createCPUComputeController(void)
+                OsdGLDrawContext> OsdCudaMesh;
+static OpenSubdiv_ComputeController *g_cudaComputeController = NULL;
+static bool g_cudaInitialized = false;
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
+using OpenSubdiv::OsdGLSLTransformFeedbackComputeController;
+typedef OsdMesh<OsdGLVertexBuffer,
+                OsdGLSLTransformFeedbackComputeController,
+                OsdGLDrawContext> OsdGLSLTransformFeedbackMesh;
+static OpenSubdiv_ComputeController *g_glslTransformFeedbackComputeController = NULL;
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
+using OpenSubdiv::OsdGLSLComputeController;
+typedef OsdMesh<OsdGLVertexBuffer,
+                OsdGLSLComputeController,
+                OsdGLDrawContext> OsdGLSLComputeMesh;
+static OpenSubdiv_ComputeController *g_glslOComputeComputeController = NULL;
+#endif
+
+static OpenSubdiv_ComputeController *alloc_controller(int controller_type)
 {
-	return (struct OpenSubdiv_CPUComputeController *) OBJECT_GUARDED_NEW(OsdCpuComputeController);
+	OpenSubdiv_ComputeController *controller =
+		(OpenSubdiv_ComputeController *) OBJECT_GUARDED_NEW(
+			OpenSubdiv_ComputeController);
+	controller->type = controller_type;
+	return controller;
 }
 
-void openSubdiv_deleteCPUComputeController(struct OpenSubdiv_CPUComputeController *controller)
+static OpenSubdiv_ComputeController *openSubdiv_getController(
+	int controller_type)
 {
-	OBJECT_GUARDED_DELETE(controller, OsdCpuComputeController);
-}
-
-/* **************** GLSL Compute Controller **************** */
-/*
-struct OpenSubdiv_GLSLComputeController *openSubdiv_createGLSLComputeController(void)
-{
-	return (struct OpenSubdiv_GLSLComputeController *) OBJECT_GUARDED_NEW(OsdGLSLComputeController);
-}
-
-void openSubdiv_deleteGLSLComputeController(struct OpenSubdiv_GLSLComputeController *controller)
-{
-	OBJECT_GUARDED_DELETE(controller, OsdGLSLComputeController);
-}
-*/
-/* **************** CUDA Compute Controller **************** */
-struct OpenSubdiv_CUDAComputeController *openSubdiv_createCUDAComputeController(void)
-{
-	static bool cudaInitialized = false;
-	if (cudaInitialized == false) {
-		cudaInitialized = true;
-		cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
+#ifdef OPENSUBDIV_HAS_OPENCL
+	if (controller_type == OPENSUBDIV_CONTROLLER_OPENCL &&
+	    g_clContext == NULL)
+	{
+		if (initCL(&g_clContext, &g_clQueue) == false) {
+			printf("Error in initializing OpenCL\n");
+		}
+	}
+#endif
+
+#ifdef OPENSUBDIV_HAS_CUDA
+	if (controller_type == OPENSUBDIV_CONTROLLER_CUDA &&
+	    g_cudaInitialized == false)
+	{
+		g_cudaInitialized = true;
+		cudaGLSetGLDevice(cutGetMaxGflopsDeviceId());
+	}
+#endif
+
+	switch (controller_type) {
+#define CHECK_CONTROLLER_TYPR(type, var, class) \
+	case OPENSUBDIV_CONTROLLER_ ## type: \
+		if (var == NULL) { \
+			var = alloc_controller(controller_type); \
+			var->descriptor = \
+				(OpenSubdiv_ComputeControllerDescr *) new class(); \
+		} \
+		return var;
+
+		CHECK_CONTROLLER_TYPR(CPU,
+		                      g_cpuComputeController,
+		                      OsdCpuComput

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list