]> granicus.if.org Git - handbrake/commitdiff
OpenCL: fix reading of generated binaries.
authorRodeo <tdskywalker@gmail.com>
Thu, 6 Jun 2013 20:52:46 +0000 (20:52 +0000)
committerRodeo <tdskywalker@gmail.com>
Thu, 6 Jun 2013 20:52:46 +0000 (20:52 +0000)
Since it now works, re-enable it under OS X.

The problem code is left in in case it breaks AMD GPUs under Windows.

git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/opencl@5571 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/openclwrapper.c

index e4d1c569315e30aaf26e30333a105501c5373267..6ea89139c44f302c59789cc6e2f73f914b1cf949 100644 (file)
@@ -812,63 +812,62 @@ int hb_compile_kernel_file( const char *filename, GPUEnv *gpu_info,
     source = source_str;\r
     source_size[0] = strlen( source );\r
 \r
-#ifdef __APPLE__\r
-    binaryExisted = 0;\r
-#else\r
-    binaryExisted = hb_binary_generated(gpu_info->context, filename, &fd);\r
-#endif\r
-    if (binaryExisted == 1)\r
+    if ((binaryExisted = hb_binary_generated(gpu_info->context, filename, &fd)) == 1)\r
     {\r
-        status = clGetContextInfo( gpu_info->context,\r
-                                   CL_CONTEXT_NUM_DEVICES,\r
-                                   sizeof(numDevices),\r
-                                   &numDevices,\r
-                                   NULL );\r
-        if( status != CL_SUCCESS )\r
+        status = clGetContextInfo(gpu_info->context,\r
+                                  CL_CONTEXT_NUM_DEVICES,\r
+                                  sizeof(numDevices),\r
+                                  &numDevices,\r
+                                  NULL);\r
+        if (status != CL_SUCCESS)\r
         {\r
-            hb_log( "OpenCL: Unable to get the number of devices in context." );\r
+            hb_log("OpenCL: Unable to get the number of devices in context.");\r
             return 0;\r
         }\r
 \r
-        devices = (cl_device_id*)malloc( sizeof(cl_device_id) * numDevices );\r
-        if( devices == NULL )\r
+        devices = (cl_device_id*)malloc(sizeof(cl_device_id) * numDevices);\r
+        if (devices == NULL)\r
             return 0;\r
 \r
-        b_error = 0;\r
-        length = 0;\r
-        b_error |= fseek( fd, 0, SEEK_END ) < 0;\r
-        b_error |= ( length = ftell( fd ) ) <= 0;\r
-        b_error |= fseek( fd, 0, SEEK_SET ) < 0;\r
-        if( b_error )\r
+        length   = 0;\r
+        b_error  = 0;\r
+        b_error |= fseek(fd, 0, SEEK_END) <  0;\r
+        b_error |= (length = ftell(fd))   <= 0;\r
+        b_error |= fseek(fd, 0, SEEK_SET) <  0;\r
+        if (b_error)\r
             return 0;\r
 \r
-        binary = (char*)malloc( length+2 );\r
-        if( !binary )\r
+        binary = (char*)calloc(length + 2, sizeof(char));\r
+        if (binary == NULL)\r
             return 0;\r
 \r
-        memset( binary, 0, length+2 );\r
-        b_error |= fread( binary, 1, length, fd ) != length;\r
-        if( binary[length-1] != '\n' )\r
-            binary[length++] = '\n';\r
+        b_error |= fread(binary, 1, length, fd) != length;\r
+#if 0   // this doesn't work under OS X and/or with some non-AMD GPUs\r
+        if (binary[length-1] != '\n')\r
+            binary[length++]  = '\n;\r
+#endif\r
+\r
+        if (b_error)\r
+            return 0;\r
 \r
-        fclose( fd );\r
-        fd = NULL;\r
         /* grab the handles to all of the devices in the context. */\r
-        status = clGetContextInfo( gpu_info->context,\r
-                                   CL_CONTEXT_DEVICES,\r
-                                   sizeof(cl_device_id) * numDevices,\r
-                                   devices,\r
-                                   NULL );\r
-\r
-        gpu_info->programs[idx] = clCreateProgramWithBinary( gpu_info->context,\r
-                                                             numDevices,\r
-                                                             devices,\r
-                                                             &length,\r
-                                                             (const unsigned char**)&binary,\r
-                                                             &binary_status,\r
-                                                             &status );\r
-\r
-        free( devices );\r
+        status = clGetContextInfo(gpu_info->context,\r
+                                  CL_CONTEXT_DEVICES,\r
+                                  sizeof(cl_device_id) * numDevices,\r
+                                  devices,\r
+                                  NULL);\r
+\r
+        gpu_info->programs[idx] = clCreateProgramWithBinary(gpu_info->context,\r
+                                                            numDevices,\r
+                                                            devices,\r
+                                                            &length,\r
+                                                            (const unsigned char**)&binary,\r
+                                                            &binary_status,\r
+                                                            &status);\r
+\r
+        fclose(fd);\r
+        free(devices);\r
+        fd      = NULL;\r
         devices = NULL;\r
     }\r
     else\r
@@ -945,12 +944,10 @@ int hb_compile_kernel_file( const char *filename, GPUEnv *gpu_info,
 \r
     strcpy( gpu_env.kernelSrcFile[idx], filename );\r
 \r
-#ifndef __APPLE__\r
-    if (!binaryExisted)\r
+    if (binaryExisted != 1)\r
     {\r
         hb_generat_bin_from_kernel_source(gpu_env.programs[idx], filename);\r
     }\r
-#endif\r
 \r
     gpu_info->file_count += 1;\r
 \r