[Bf-blender-cvs] [a89362a] opensubdiv-modifier: Expose OpenSubdiv compute type to user preferences
Sergey Sharybin
noreply at git.blender.org
Mon May 12 20:09:02 CEST 2014
Commit: a89362a41a86e1831ecc6349b77ad307c70f94ff
Author: Sergey Sharybin
Date: Sun May 11 19:17:10 2014 +0200
https://developer.blender.org/rBa89362a41a86e1831ecc6349b77ad307c70f94ff
Expose OpenSubdiv compute type to user preferences
Pretty much straightforward change actually.
NOTE: Use with care! Opening userpref during animation
playback crashes Blender here. Should be some sort of
OpenGL context issue, will investigate it later.
Also committing file missing from previons commit.
===================================================================
A intern/opensubdiv/clInit.h
M intern/opensubdiv/opensubdiv_capi.cc
M intern/opensubdiv/opensubdiv_capi.h
M release/scripts/startup/bl_ui/space_userpref.py
M source/blender/blenkernel/intern/CCGSubSurf.c
M source/blender/makesdna/DNA_userdef_types.h
M source/blender/makesrna/intern/CMakeLists.txt
M source/blender/makesrna/intern/SConscript
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/intern/opensubdiv/clInit.h b/intern/opensubdiv/clInit.h
new file mode 100644
index 0000000..20ef736
--- /dev/null
+++ b/intern/opensubdiv/clInit.h
@@ -0,0 +1,139 @@
+//
+// Copyright 2013 Pixar
+//
+// Licensed under the Apache License, Version 2.0 (the "Apache License")
+// with the following modification; you may not use this file except in
+// compliance with the Apache License and the following modification to it:
+// Section 6. Trademarks. is deleted and replaced with:
+//
+// 6. Trademarks. This License does not grant permission to use the trade
+// names, trademarks, service marks, or product names of the Licensor
+// and its affiliates, except as required to comply with Section 4(c) of
+// the License and to reproduce the content of the NOTICE file.
+//
+// You may obtain a copy of the Apache License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the Apache License with the above modification is
+// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the Apache License for the specific
+// language governing permissions and limitations under the Apache License.
+//
+
+#ifndef OSD_EXAMPLE_CL_INIT_H
+#define OSD_EXAMPLE_CL_INIT_H
+
+#if defined(_WIN32)
+ #include <windows.h>
+ #include <CL/opencl.h>
+#elif defined(__APPLE__)
+ #include <OpenGL/OpenGL.h>
+ #include <OpenCL/opencl.h>
+#else
+ #include <GL/glx.h>
+ #include <CL/opencl.h>
+#endif
+
+#include <cstdio>
+
+static bool initCL(cl_context *clContext, cl_command_queue *clQueue)
+{
+ cl_int ciErrNum;
+
+ cl_platform_id cpPlatform = 0;
+ cl_uint num_platforms;
+ ciErrNum = clGetPlatformIDs(0, NULL, &num_platforms);
+ if (ciErrNum != CL_SUCCESS) {
+ printf("Error %d in clGetPlatformIDs call.\n", ciErrNum);
+ return false;
+ }
+ if (num_platforms == 0) {
+ printf("No OpenCL platform found.\n");
+ return false;
+ }
+ cl_platform_id *clPlatformIDs = new cl_platform_id[num_platforms];
+ ciErrNum = clGetPlatformIDs(num_platforms, clPlatformIDs, NULL);
+ char chBuffer[1024];
+ for (cl_uint i = 0; i < num_platforms; ++i) {
+ ciErrNum = clGetPlatformInfo(clPlatformIDs[i], CL_PLATFORM_NAME, 1024, chBuffer,NULL);
+ if (ciErrNum == CL_SUCCESS) {
+ cpPlatform = clPlatformIDs[i];
+ }
+ }
+
+#if defined(_WIN32)
+ cl_context_properties props[] = {
+ CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
+ CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
+ CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform,
+ 0
+ };
+#elif defined(__APPLE__)
+ CGLContextObj kCGLContext = CGLGetCurrentContext();
+ CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
+ cl_context_properties props[] = {
+ CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
+ 0
+ };
+#else
+ cl_context_properties props[] = {
+ CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
+ CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
+ CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform,
+ 0
+ };
+#endif
+ delete[] clPlatformIDs;
+
+#if defined(__APPLE__)
+ *clContext = clCreateContext(props, 0, NULL, clLogMessagesToStdoutAPPLE, NULL, &ciErrNum);
+ if (ciErrNum != CL_SUCCESS) {
+ printf("Error %d in clCreateContext\n", ciErrNum);
+ return false;
+ }
+
+ size_t devicesSize = 0;
+ clGetGLContextInfoAPPLE(*clContext, kCGLContext, CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE, 0, NULL, &devicesSize);
+ int numDevices = int(devicesSize / sizeof(cl_device_id));
+ if (numDevices == 0) {
+ printf("No sharable devices.\n");
+ return false;
+ }
+ cl_device_id *clDevices = new cl_device_id[numDevices];
+ clGetGLContextInfoAPPLE(*clContext, kCGLContext, CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE, numDevices * sizeof(cl_device_id), clDevices, NULL);
+#else
+ cl_uint numDevices = 0;
+ clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_GPU, 0, NULL, &numDevices);
+ if (numDevices == 0) {
+ printf("No sharable devices.\n");
+ return false;
+ }
+ cl_device_id *clDevices = new cl_device_id[numDevices];
+ clGetDeviceIDs(cpPlatform, CL_DEVICE_TYPE_GPU, numDevices, clDevices, NULL);
+
+ *clContext = clCreateContext(props, numDevices, clDevices, NULL, NULL, &ciErrNum);
+ if (ciErrNum != CL_SUCCESS) {
+ printf("Error %d in clCreateContext\n", ciErrNum);
+ delete[] clDevices;
+ return false;
+ }
+#endif
+
+ *clQueue = clCreateCommandQueue(*clContext, clDevices[0], 0, &ciErrNum);
+ delete[] clDevices;
+ if (ciErrNum != CL_SUCCESS) {
+ printf("Error %d in clCreateCommandQueue\n", ciErrNum);
+ return false;
+ }
+ return true;
+}
+
+static void uninitCL(cl_context clContext, cl_command_queue clQueue)
+{
+ clReleaseCommandQueue(clQueue);
+ clReleaseContext(clContext);
+}
+
+#endif // OSD_EXAMPLE_CL_INIT_H
diff --git a/intern/opensubdiv/opensubdiv_capi.cc b/intern/opensubdiv/opensubdiv_capi.cc
index 2069c25..3e7787c 100644
--- a/intern/opensubdiv/opensubdiv_capi.cc
+++ b/intern/opensubdiv/opensubdiv_capi.cc
@@ -393,6 +393,33 @@ void openSubdiv_osdGLMeshBindvertexBuffer(OpenSubdiv_GLMesh *gl_mesh)
((OsdGLMeshInterface *)gl_mesh->descriptor)->BindVertexBuffer();
}
+int openSubdiv_getAvailableControllers(void)
+{
+ int flags = OPENSUBDIV_CONTROLLER_CPU;
+
+#ifdef OPENSUBDIV_HAS_OPENMP
+ flags |= OPENSUBDIV_CONTROLLER_OPENMP;
+#endif
+
+#ifdef OPENSUBDIV_HAS_OPENCL
+ flags |= OPENSUBDIV_CONTROLLER_OPENCL;
+#endif
+
+#ifdef OPENSUBDIV_HAS_CUDA
+ flags |= OPENSUBDIV_CONTROLLER_CUDA;
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
+ flags |= OPENSUBDIV_CONTROLLER_GLSL_TRANSFORM_FEEDBACK;
+#endif
+
+#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
+ flags |= OPENSUBDIV_CONTROLLER_GLSL_COMPUTE;
+#endif
+
+ return flags;
+}
+
void openSubdiv_cleanup(void)
{
#define DELETE_DESCRIPTOR(var, class) \
diff --git a/intern/opensubdiv/opensubdiv_capi.h b/intern/opensubdiv/opensubdiv_capi.h
index d7bd551..e5a68b7 100644
--- a/intern/opensubdiv/opensubdiv_capi.h
+++ b/intern/opensubdiv/opensubdiv_capi.h
@@ -65,13 +65,13 @@ void openSubdiv_osdGLMeshUpdateVertexBuffer(struct OpenSubdiv_GLMesh *gl_mesh,
const float *vertex_data,
int start_vertex,
int num_verts);
-void openSubdiv_osdGLMeshUpdateVertexBufferFromDescr(struct OpenSubdiv_GLMesh *gl_mesh,
- struct OpenSubdiv_MeshDescr *mesh_descr);
void openSubdiv_osdGLMeshRefine(struct OpenSubdiv_GLMesh *gl_mesh);
void openSubdiv_osdGLMeshSynchronize(struct OpenSubdiv_GLMesh *gl_mesh);
void openSubdiv_osdGLMeshDisplay(struct OpenSubdiv_GLMesh *gl_mesh);
void openSubdiv_osdGLMeshBindvertexBuffer(struct OpenSubdiv_GLMesh *gl_mesh);
+int openSubdiv_getAvailableControllers(void);
+
void openSubdiv_cleanup(void);
#ifdef __cplusplus
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 18f7c53..6ad251d 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -406,6 +406,10 @@ class USERPREF_PT_system(Panel):
sub.active = system.compute_device_type != 'CPU'
sub.prop(system, "compute_device", text="")
+ if hasattr(system, "opensubdiv_compute_type"):
+ col.label(text="OpenSubdiv compute:")
+ col.row().prop(system, "opensubdiv_compute_type", text="")
+
# 2. Column
column = split.column()
colsplit = column.split(percentage=0.85)
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 6a4fe11..1e06a67 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -36,6 +36,10 @@
#include "CCGSubSurf.h"
#include "BKE_subsurf.h"
+#include "BKE_subsurf.h"
+
+#include "DNA_userdef_types.h"
+
#ifdef WITH_OPENSUBDIV
# include "opensubdiv_capi.h"
# include <opensubdiv/osdutil/evaluator_capi.h>
@@ -460,6 +464,7 @@ struct CCGSubSurf {
struct OpenSubdiv_GLMesh *osd_mesh;
unsigned int osd_vao;
bool skip_grids;
+ short osd_compute;
#endif
};
@@ -919,6 +924,7 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *a
ss->osd_mesh = NULL;
ss->osd_vao = 0;
ss->skip_grids = false;
+ ss->osd_compute = 0;
#endif
return ss;
@@ -2301,6 +2307,22 @@ static void ccgSubSurf__updateGLMeshCoords(CCGSubSurf *ss)
void ccgSubSurf_prepareGLMesh(CCGSubSurf *ss)
{
+ int compute_type;
+
+ switch (U.opensubdiv_compute_type) {
+#define CHECK_COMPUTE_TYPE(type) \
+ case USER_OPENSUBDIV_COMPUTE_ ## type: \
+ compute_type = OPENSUBDIV_CONTROLLER_ ## type; \
+ break;
+ CHECK_COMPUTE_TYPE(CPU)
+ CHECK_COMPUTE_TYPE(OPENMP)
+ CHECK_COMPUTE_TYPE(OPENCL)
+ CHECK_COMPUTE_TYPE(CUDA)
+ CHECK_COMPUTE_TYPE(GLSL_TRANSFORM_FEEDBACK)
+ CHECK_COMPUTE_TYPE(GLSL_COMPUTE)
+#undef CHECK_COMPUTE_TYPE
+ }
+
if (ss->osd_vao == 0) {
glGenVertexArrays(1, &ss->osd_vao);
}
@@ -2308,7 +2330,7 @@ void ccgSubSurf_prepareGLMesh(CCGSubSurf *ss)
if (ss->osd_mesh == NULL) {
ss->osd_mesh = openSubdiv_createOsdGLMeshFromEvaluator(
ss->osd_evaluator,
- OPENSUBDIV_CONTROLLER_CUDA,
+ compute_type,
ss->subdivLevels);
ccgSubSurf__updateGLMeshCoords(ss);
@@ -2328,6 +2350,8 @@ void ccgSubSurf_prepareGLMesh(CCGSubSurf *ss)
glDisableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
+
+ ss->osd_compute = U.opensubdiv_compute_type;
}
else {
ccgSubSurf__updateGLMeshCoords(ss);
@@ -2469,6 +2493,14 @@ static bool check_topology_changed(CCGSubSurf *ss)
int *indices, *nverts;
int i, index, osd_face_index;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list