[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47180] trunk/blender/source/blender/ compositor/intern/COM_WorkScheduler.cpp: * Compositor fix for OpenCL [ OpenCL platform installed, but no

Jeroen Bakker j.bakker at atmind.nl
Tue May 29 16:13:08 CEST 2012


Revision: 47180
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47180
Author:   jbakker
Date:     2012-05-29 14:13:08 +0000 (Tue, 29 May 2012)
Log Message:
-----------
 * Compositor fix for OpenCL [OpenCL platform installed, but no
available devices]
   - could happen when having laptops with a hard switch between video
cards (intel/NVidia switch)
   - or when an opencl platform was installed on a machine without any
OpenCL compatible GPU

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp

Modified: trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp	2012-05-29 14:00:47 UTC (rev 47179)
+++ trunk/blender/source/blender/compositor/intern/COM_WorkScheduler.cpp	2012-05-29 14:13:08 UTC (rev 47180)
@@ -236,6 +236,7 @@
 		cl_int error;
 		error = clGetPlatformIDs(0, 0, &numberOfPlatforms);
 		if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
+		numberOfPlatforms = 0;
 		if (G.f & G_DEBUG) printf("%d number of platforms\n", numberOfPlatforms);
 		cl_platform_id *platforms = new cl_platform_id[numberOfPlatforms];
 		error = clGetPlatformIDs(numberOfPlatforms, platforms, 0);
@@ -257,37 +258,39 @@
 			clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, numberOfDevices, cldevices+numberOfDevicesReceived*sizeof (cl_device_id), 0);
 			numberOfDevicesReceived += numberOfDevices;
 		}
-		context = clCreateContext(NULL, totalNumberOfDevices, cldevices, clContextError, NULL, &error);
-		if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
-		program = clCreateProgramWithSource(context, 1, &sourcecode, 0, &error);
-		error = clBuildProgram(program, totalNumberOfDevices, cldevices, 0, 0, 0);
-		if (error != CL_SUCCESS) { 
-			cl_int error2;
-			size_t ret_val_size;
-			printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	
-			error2 = clGetProgramBuildInfo(program, cldevices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
-			if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
-			char *build_log =  new char[ret_val_size+1];
-			error2 = clGetProgramBuildInfo(program, cldevices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
-			if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
-			build_log[ret_val_size] = '\0';
-			printf("%s", build_log);
-			delete build_log;
-			
-		}
-		unsigned int indexDevices;
-		for (indexDevices = 0 ; indexDevices < totalNumberOfDevices ; indexDevices ++) {
-			cl_device_id device = cldevices[indexDevices];
-			OpenCLDevice *clDevice = new OpenCLDevice(context, device, program);
-			clDevice->initialize(),
-			gpudevices.push_back(clDevice);
-			if (G.f & G_DEBUG) {
-				char resultString[32];
-				error = clGetDeviceInfo(device, CL_DEVICE_NAME, 32, resultString, 0);
-				printf("OPENCL_DEVICE: %s, ", resultString);
-				error = clGetDeviceInfo(device, CL_DEVICE_VENDOR, 32, resultString, 0);
-				printf("%s\n", resultString);
+		if (totalNumberOfDevices > 0) {
+			context = clCreateContext(NULL, totalNumberOfDevices, cldevices, clContextError, NULL, &error);
+			if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
+			program = clCreateProgramWithSource(context, 1, &sourcecode, 0, &error);
+			error = clBuildProgram(program, totalNumberOfDevices, cldevices, 0, 0, 0);
+			if (error != CL_SUCCESS) { 
+				cl_int error2;
+				size_t ret_val_size;
+				printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	
+				error2 = clGetProgramBuildInfo(program, cldevices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
+				if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
+				char *build_log =  new char[ret_val_size+1];
+				error2 = clGetProgramBuildInfo(program, cldevices[0], CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
+				if (error2 != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error));	}
+				build_log[ret_val_size] = '\0';
+				printf("%s", build_log);
+				delete build_log;
+				
 			}
+			unsigned int indexDevices;
+			for (indexDevices = 0 ; indexDevices < totalNumberOfDevices ; indexDevices ++) {
+				cl_device_id device = cldevices[indexDevices];
+				OpenCLDevice *clDevice = new OpenCLDevice(context, device, program);
+				clDevice->initialize(),
+				gpudevices.push_back(clDevice);
+				if (G.f & G_DEBUG) {
+					char resultString[32];
+					error = clGetDeviceInfo(device, CL_DEVICE_NAME, 32, resultString, 0);
+					printf("OPENCL_DEVICE: %s, ", resultString);
+					error = clGetDeviceInfo(device, CL_DEVICE_VENDOR, 32, resultString, 0);
+					printf("%s\n", resultString);
+				}
+			}
 		}
 		delete [] cldevices;
 		delete [] platforms;




More information about the Bf-blender-cvs mailing list