* Compositor fix for OpenCL [OpenCL platform installed, but no
authorJeroen Bakker <j.bakker@atmind.nl>
Tue, 29 May 2012 14:13:08 +0000 (14:13 +0000)
committerJeroen Bakker <j.bakker@atmind.nl>
Tue, 29 May 2012 14:13:08 +0000 (14:13 +0000)
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

source/blender/compositor/intern/COM_WorkScheduler.cpp

index c5a5a585c19b0438a4d1ff51996cadd46bae9f75..925ff904cc0405873e08e4c743effb39f3a55bbc 100644 (file)
@@ -236,6 +236,7 @@ void WorkScheduler::initialize()
                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,36 +258,38 @@ void WorkScheduler::initialize()
                        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;