summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodeo <[email protected]>2013-07-01 14:41:20 +0000
committerRodeo <[email protected]>2013-07-01 14:41:20 +0000
commit6efccd133de9e2eb3ff1010119bdfa69f6b86b03 (patch)
tree884c479c6f59c7d9616123218ea69f03cf89618a
parente3837712e452a474a85f4dfa0371c9b0f84909b0 (diff)
x264: build with OpenCL lookahead support by default.
The necessary headers are included in the x264 source, so the only new dependency is perl. The OpenCL-accelerated lookahead is disabled by default and can be enabled at runtime using the "opencl" advanced x264 option. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5628 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--contrib/x264/A01-opencl-fixes.patch235
-rw-r--r--contrib/x264/module.defs5
2 files changed, 237 insertions, 3 deletions
diff --git a/contrib/x264/A01-opencl-fixes.patch b/contrib/x264/A01-opencl-fixes.patch
new file mode 100644
index 000000000..17720c239
--- /dev/null
+++ b/contrib/x264/A01-opencl-fixes.patch
@@ -0,0 +1,235 @@
+From a87c3f61c93351a106976af5b3f5f2b95b277d20 Mon Sep 17 00:00:00 2001
+From: Anton Mitrofanov <[email protected]>
+Date: Wed, 22 May 2013 22:43:59 +0400
+Subject: [PATCH] Fix compilation with OpenCL on MacOS X
+
+Also fix crash in the case of OpenCL error during encoding.
+---
+ common/opencl.c | 46 +++++++++++++++++++++++-----------------------
+ encoder/slicetype-cl.c | 10 ++++++++--
+ extras/cl_platform.h | 38 ++++++++++++++++++++++++++------------
+ 3 files changed, 57 insertions(+), 37 deletions(-)
+
+diff --git a/common/opencl.c b/common/opencl.c
+index 5b1bb69..63c49e8 100644
+--- a/common/opencl.c
++++ b/common/opencl.c
+@@ -34,7 +34,7 @@
+ #else
+ #include <dlfcn.h> //dlopen, dlsym, dlclose
+ #if SYS_MACOSX
+-#define ocl_open dlopen( "libOpenCL.dylib", RTLD_NOW )
++#define ocl_open dlopen( "/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW )
+ #else
+ #define ocl_open dlopen( "libOpenCL.so", RTLD_NOW )
+ #endif
+@@ -119,7 +119,7 @@ static int x264_detect_switchable_graphics( void );
+
+ /* Try to load the cached compiled program binary, verify the device context is
+ * still valid before reuse */
+-static cl_program x264_opencl_cache_load( x264_t *h, char *devname, char *devvendor, char *driverversion )
++static cl_program x264_opencl_cache_load( x264_t *h, char *dev_name, char *dev_vendor, char *driver_version )
+ {
+ /* try to load cached program binary */
+ FILE *fp = fopen( h->param.psz_clbin_file, "rb" );
+@@ -149,9 +149,9 @@ static cl_program x264_opencl_cache_load( x264_t *h, char *devname, char *devven
+ }\
+ } while( 0 )
+
+- CHECK_STRING( devname );
+- CHECK_STRING( devvendor );
+- CHECK_STRING( driverversion );
++ CHECK_STRING( dev_name );
++ CHECK_STRING( dev_vendor );
++ CHECK_STRING( driver_version );
+ CHECK_STRING( x264_opencl_source_hash );
+ #undef CHECK_STRING
+
+@@ -167,7 +167,7 @@ fail:
+
+ /* Save the compiled program binary to a file for later reuse. Device context
+ * is also saved in the cache file so we do not reuse stale binaries */
+-static void x264_opencl_cache_save( x264_t *h, cl_program program, char *devname, char *devvendor, char *driverversion )
++static void x264_opencl_cache_save( x264_t *h, cl_program program, char *dev_name, char *dev_vendor, char *driver_version )
+ {
+ FILE *fp = fopen( h->param.psz_clbin_file, "wb" );
+ if( !fp )
+@@ -186,11 +186,11 @@ static void x264_opencl_cache_save( x264_t *h, cl_program program, char *devname
+ status = ocl->clGetProgramInfo( program, CL_PROGRAM_BINARIES, sizeof(uint8_t *), &binary, NULL );
+ if( status == CL_SUCCESS )
+ {
+- fputs( devname, fp );
++ fputs( dev_name, fp );
+ fputc( '\n', fp );
+- fputs( devvendor, fp );
++ fputs( dev_vendor, fp );
+ fputc( '\n', fp );
+- fputs( driverversion, fp );
++ fputs( driver_version, fp );
+ fputc( '\n', fp );
+ fputs( x264_opencl_source_hash, fp );
+ fputc( '\n', fp );
+@@ -218,17 +218,17 @@ static cl_program x264_opencl_compile( x264_t *h )
+ cl_program program;
+ cl_int status;
+
+- char devname[64];
+- char devvendor[64];
+- char driverversion[64];
+- status = ocl->clGetDeviceInfo( h->opencl.device, CL_DEVICE_NAME, sizeof(devname), devname, NULL );
+- status |= ocl->clGetDeviceInfo( h->opencl.device, CL_DEVICE_VENDOR, sizeof(devvendor), devvendor, NULL );
+- status |= ocl->clGetDeviceInfo( h->opencl.device, CL_DRIVER_VERSION, sizeof(driverversion), driverversion, NULL );
++ char dev_name[64];
++ char dev_vendor[64];
++ char driver_version[64];
++ status = ocl->clGetDeviceInfo( h->opencl.device, CL_DEVICE_NAME, sizeof(dev_name), dev_name, NULL );
++ status |= ocl->clGetDeviceInfo( h->opencl.device, CL_DEVICE_VENDOR, sizeof(dev_vendor), dev_vendor, NULL );
++ status |= ocl->clGetDeviceInfo( h->opencl.device, CL_DRIVER_VERSION, sizeof(driver_version), driver_version, NULL );
+ if( status != CL_SUCCESS )
+ return NULL;
+
+ // Most AMD GPUs have vector registers
+- int vectorize = !strcmp( devvendor, "Advanced Micro Devices, Inc." );
++ int vectorize = !strcmp( dev_vendor, "Advanced Micro Devices, Inc." );
+ h->opencl.b_device_AMD_SI = 0;
+
+ if( vectorize )
+@@ -250,9 +250,9 @@ static cl_program x264_opencl_compile( x264_t *h )
+ }
+ }
+
+- x264_log( h, X264_LOG_INFO, "OpenCL acceleration enabled with %s %s %s\n", devvendor, devname, h->opencl.b_device_AMD_SI ? "(SI)" : "" );
++ x264_log( h, X264_LOG_INFO, "OpenCL acceleration enabled with %s %s %s\n", dev_vendor, dev_name, h->opencl.b_device_AMD_SI ? "(SI)" : "" );
+
+- program = x264_opencl_cache_load( h, devname, devvendor, driverversion );
++ program = x264_opencl_cache_load( h, dev_name, dev_vendor, driver_version );
+ if( !program )
+ {
+ /* clCreateProgramWithSource() requires a pointer variable, you cannot just use &x264_opencl_source */
+@@ -272,7 +272,7 @@ static cl_program x264_opencl_compile( x264_t *h )
+ status = ocl->clBuildProgram( program, 1, &h->opencl.device, buildopts, NULL, NULL );
+ if( status == CL_SUCCESS )
+ {
+- x264_opencl_cache_save( h, program, devname, devvendor, driverversion );
++ x264_opencl_cache_save( h, program, dev_name, dev_vendor, driver_version );
+ return program;
+ }
+
+@@ -388,7 +388,7 @@ fail:
+ return -1;
+ }
+
+-static void x264_opencl_error_notify( const char *errinfo, const void *private_info, size_t cb, void *user_data )
++static void CL_CALLBACK x264_opencl_error_notify( const char *errinfo, const void *private_info, size_t cb, void *user_data )
+ {
+ /* Any error notification can be assumed to be fatal to the OpenCL context.
+ * We need to stop using it immediately to prevent further damage. */
+@@ -493,13 +493,13 @@ int x264_opencl_lookahead_init( x264_t *h )
+ x264_free( imageType );
+ if( !b_has_r || !b_has_rgba )
+ {
+- char devname[64];
+- status = ocl->clGetDeviceInfo( h->opencl.device, CL_DEVICE_NAME, sizeof(devname), devname, NULL );
++ char dev_name[64];
++ status = ocl->clGetDeviceInfo( h->opencl.device, CL_DEVICE_NAME, sizeof(dev_name), dev_name, NULL );
+ if( status == CL_SUCCESS )
+ {
+ /* emit warning if we are discarding the user's explicit choice */
+ int level = h->param.opencl_device_id ? X264_LOG_WARNING : X264_LOG_DEBUG;
+- x264_log( h, level, "OpenCL: %s does not support required image formats\n", devname);
++ x264_log( h, level, "OpenCL: %s does not support required image formats\n", dev_name);
+ }
+ ocl->clReleaseContext( context );
+ continue;
+diff --git a/encoder/slicetype-cl.c b/encoder/slicetype-cl.c
+index 17650c5..334215f 100644
+--- a/encoder/slicetype-cl.c
++++ b/encoder/slicetype-cl.c
+@@ -40,13 +40,18 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int
+ #define CL_QUEUE_THREAD_HANDLE_AMD 0x403E
+
+ #define OCLCHECK( method, ... )\
++do\
++{\
++ if( h->opencl.b_fatal_error )\
++ return -1;\
+ status = ocl->method( __VA_ARGS__ );\
+ if( status != CL_SUCCESS ) {\
+ h->param.b_opencl = 0;\
+ h->opencl.b_fatal_error = 1;\
+ x264_log( h, X264_LOG_ERROR, # method " error '%d'\n", status );\
+- return status;\
+- }
++ return -1;\
++ }\
++} while( 0 )
+
+ void x264_opencl_flush( x264_t *h )
+ {
+@@ -152,6 +157,7 @@ int x264_opencl_lowres_init( x264_t *h, x264_frame_t *fenc, int lambda )
+ CREATEBUF( fenc->opencl.lowres_mv_costs1, CL_MEM_READ_WRITE, mb_count * sizeof(int16_t) * (h->param.i_bframe + 1) );
+ }
+ #undef CREATEBUF
++#undef CREATEIMAGE
+
+ /* Copy image to the GPU, downscale to unpadded 8x8, then continue for all scales */
+
+diff --git a/extras/cl_platform.h b/extras/cl_platform.h
+index edc7321..7b06e09 100644
+--- a/extras/cl_platform.h
++++ b/extras/cl_platform.h
+@@ -47,13 +47,27 @@ extern "C" {
+
+ #ifdef __APPLE__
+ #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import))
+- #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
+- #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
+- #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+- #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+- #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+- #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7
+-
++ #ifndef UNAVAILABLE_ATTRIBUTE
++ #define UNAVAILABLE_ATTRIBUTE
++ #endif
++ #ifdef AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
++ #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
++ #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER
++ #else
++ #define CL_API_SUFFIX__VERSION_1_0 UNAVAILABLE_ATTRIBUTE
++ #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK UNAVAILABLE_ATTRIBUTE
++ #endif
++ #ifdef AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
++ #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
++ #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
++ #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
++ #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7
++ #else
++ #define CL_API_SUFFIX__VERSION_1_1 UNAVAILABLE_ATTRIBUTE
++ #define GCL_API_SUFFIX__VERSION_1_1 UNAVAILABLE_ATTRIBUTE
++ #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK UNAVAILABLE_ATTRIBUTE
++ #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATE CL_EXT_SUFFIX__VERSION_1_0
++ #endif
+ #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+ #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+ #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER
+@@ -61,11 +75,11 @@ extern "C" {
+ #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
+ #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8
+ #else
+- #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here!
+- #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+- #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+- #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
+- #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
++ #define CL_API_SUFFIX__VERSION_1_2 UNAVAILABLE_ATTRIBUTE
++ #define GCL_API_SUFFIX__VERSION_1_2 UNAVAILABLE_ATTRIBUTE
++ #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK UNAVAILABLE_ATTRIBUTE
++ #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
++ #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXT_SUFFIX__VERSION_1_1
+ #endif
+ #else
+ #define CL_EXTENSION_WEAK_LINK
+--
+1.7.12.4 (Apple Git-37)
+
diff --git a/contrib/x264/module.defs b/contrib/x264/module.defs
index 458a6cddf..7c8808500 100644
--- a/contrib/x264/module.defs
+++ b/contrib/x264/module.defs
@@ -6,10 +6,9 @@ X264.EXTRACT.tarbase = x264
X264.CONFIGURE.deps =
X264.CONFIGURE.shared =
-X264.CONFIGURE.static =
-X264.CONFIGURE.extra = --disable-cli --enable-static --enable-strip
-X264.CONFIGURE.extra += --disable-gpac --disable-avs --disable-lavf --disable-ffms --disable-swscale --disable-opencl
+X264.CONFIGURE.extra = --enable-strip --bit-depth=8 --chroma-format=420
+X264.CONFIGURE.extra += --disable-lavf --disable-ffms --disable-avs --disable-swscale --disable-gpac --disable-cli
ifeq (1-mingw,$(BUILD.cross)-$(BUILD.system))
X264.CONFIGURE.extra += --cross-prefix=$(BUILD.spec)-