Re: [FFmpeg-devel] [PATCH 03/15] hwcontext_opencl: VAAPI to OpenCL mapping for Intel i965+beignet
On 2017/11/15 3:47, Mark Thompson wrote: > Supports all surface formats in common between the two. > --- > configure| 6 + > libavutil/hwcontext_opencl.c | 298 > +++ > 2 files changed, 304 insertions(+) > > diff --git a/configure b/configure > index 167db274f1..dcdb5fee1f 100755 > --- a/configure > +++ b/configure > @@ -2121,6 +2121,7 @@ HAVE_LIST=" > $TYPES_LIST > makeinfo > makeinfo_html > +opencl_vaapi_beignet > perl > pod2man > texi2html > @@ -6150,6 +6151,11 @@ enabled vaapi && > check_cpp_condition "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" && > enable vaapi_1 > > +if enabled_all opencl vaapi ; then > +check_type "CL/cl_intel.h" "clCreateImageFromFdINTEL_fn" && > +enable opencl_vaapi_beignet > +fi > + > enabled vdpau && > check_cpp_condition vdpau/vdpau.h "defined > VDP_DECODER_PROFILE_MPEG4_PART2_ASP" || > disable vdpau > diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c > index 0fe25d9500..7f99f5af3f 100644 > --- a/libavutil/hwcontext_opencl.c > +++ b/libavutil/hwcontext_opencl.c > @@ -29,6 +29,14 @@ > #include "mem.h" > #include "pixdesc.h" > > +#if HAVE_OPENCL_VAAPI_BEIGNET > +#include > +#include > +#include > +#include > +#include "hwcontext_vaapi.h" > +#endif > + > > typedef struct OpenCLDeviceContext { > // Default command queue to use for transfer/mapping operations on > @@ -41,6 +49,10 @@ typedef struct OpenCLDeviceContext { > cl_platform_id platform_id; > > // Platform/device-specific functions. > +#if HAVE_OPENCL_VAAPI_BEIGNET > +int vaapi_mapping_usable; > +clCreateImageFromFdINTEL_fn clCreateImageFromFdINTEL; > +#endif > } OpenCLDeviceContext; > > typedef struct OpenCLFramesContext { > @@ -589,6 +601,40 @@ static int opencl_device_init(AVHWDeviceContext *hwdev) > return AVERROR(EIO); > } > > +#define CL_FUNC(name, desc) do {\ > +if (fail) \ > +break; \ > +priv->name = clGetExtensionFunctionAddressForPlatform( \ > +priv->platform_id, #name); \ > +if (!priv->name) { \ > +av_log(hwdev, AV_LOG_VERBOSE, \ > + desc " function not found (%s).\n", #name); \ > +fail = 1; \ > +} else {\ > +av_log(hwdev, AV_LOG_VERBOSE, \ > + desc " function found (%s).\n", #name); \ > +} \ > +} while (0) > + > +#if HAVE_OPENCL_VAAPI_BEIGNET > +{ > +int fail = 0; > + > +CL_FUNC(clCreateImageFromFdINTEL, > +"Intel DRM to OpenCL image mapping"); > + > +if (fail) { > +av_log(hwdev, AV_LOG_WARNING, "VAAPI to OpenCL mapping " > + "not usable.\n"); > +priv->vaapi_mapping_usable = 0; > +} else { > +priv->vaapi_mapping_usable = 1; > +} > +} > +#endif > + > +#undef CL_FUNC > + > return 0; > } > > @@ -606,6 +652,52 @@ static void opencl_device_uninit(AVHWDeviceContext > *hwdev) > } > } > > +static int opencl_device_derive(AVHWDeviceContext *hwdev, > +AVHWDeviceContext *src_ctx, > +int flags) > +{ > +int err; > +switch (src_ctx->type) { > + > +#if HAVE_OPENCL_VAAPI_BEIGNET > +case AV_HWDEVICE_TYPE_VAAPI: > +{ > +// Surface mapping works via DRM PRIME fds with no special > +// initialisation required in advance. This just finds the > +// Beignet ICD by name. > +AVDictionary *opts = NULL; > + > +err = av_dict_set(&opts, "platform_vendor", "Intel", 0); > +if (err >= 0) > +err = av_dict_set(&opts, "platform_version", "beignet", 0); > +if (err >= 0) { > +OpenCLDeviceSelector selector = { > +.platform_index = -1, > +.device_index= 0, > +.context = opts, > +.enumerate_platforms = &opencl_enumerate_platforms, > +.filter_platform = &opencl_filter_platform, > +.enumerate_devices = &opencl_enumerate_devices, > +.filter_device = NULL, > +}; > +err = opencl_device_create_internal(hwdev, &selector, NULL); > +} > +av_dict_free(&opts); > +} > +break; > +#endif > + > +default: > +err = AVERROR(ENOSYS); > +break; > +} > + > +
[FFmpeg-devel] [PATCH 03/15] hwcontext_opencl: VAAPI to OpenCL mapping for Intel i965+beignet
Supports all surface formats in common between the two. --- configure| 6 + libavutil/hwcontext_opencl.c | 298 +++ 2 files changed, 304 insertions(+) diff --git a/configure b/configure index 167db274f1..dcdb5fee1f 100755 --- a/configure +++ b/configure @@ -2121,6 +2121,7 @@ HAVE_LIST=" $TYPES_LIST makeinfo makeinfo_html +opencl_vaapi_beignet perl pod2man texi2html @@ -6150,6 +6151,11 @@ enabled vaapi && check_cpp_condition "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" && enable vaapi_1 +if enabled_all opencl vaapi ; then +check_type "CL/cl_intel.h" "clCreateImageFromFdINTEL_fn" && +enable opencl_vaapi_beignet +fi + enabled vdpau && check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" || disable vdpau diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c index 0fe25d9500..7f99f5af3f 100644 --- a/libavutil/hwcontext_opencl.c +++ b/libavutil/hwcontext_opencl.c @@ -29,6 +29,14 @@ #include "mem.h" #include "pixdesc.h" +#if HAVE_OPENCL_VAAPI_BEIGNET +#include +#include +#include +#include +#include "hwcontext_vaapi.h" +#endif + typedef struct OpenCLDeviceContext { // Default command queue to use for transfer/mapping operations on @@ -41,6 +49,10 @@ typedef struct OpenCLDeviceContext { cl_platform_id platform_id; // Platform/device-specific functions. +#if HAVE_OPENCL_VAAPI_BEIGNET +int vaapi_mapping_usable; +clCreateImageFromFdINTEL_fn clCreateImageFromFdINTEL; +#endif } OpenCLDeviceContext; typedef struct OpenCLFramesContext { @@ -589,6 +601,40 @@ static int opencl_device_init(AVHWDeviceContext *hwdev) return AVERROR(EIO); } +#define CL_FUNC(name, desc) do {\ +if (fail) \ +break; \ +priv->name = clGetExtensionFunctionAddressForPlatform( \ +priv->platform_id, #name); \ +if (!priv->name) { \ +av_log(hwdev, AV_LOG_VERBOSE, \ + desc " function not found (%s).\n", #name); \ +fail = 1; \ +} else {\ +av_log(hwdev, AV_LOG_VERBOSE, \ + desc " function found (%s).\n", #name); \ +} \ +} while (0) + +#if HAVE_OPENCL_VAAPI_BEIGNET +{ +int fail = 0; + +CL_FUNC(clCreateImageFromFdINTEL, +"Intel DRM to OpenCL image mapping"); + +if (fail) { +av_log(hwdev, AV_LOG_WARNING, "VAAPI to OpenCL mapping " + "not usable.\n"); +priv->vaapi_mapping_usable = 0; +} else { +priv->vaapi_mapping_usable = 1; +} +} +#endif + +#undef CL_FUNC + return 0; } @@ -606,6 +652,52 @@ static void opencl_device_uninit(AVHWDeviceContext *hwdev) } } +static int opencl_device_derive(AVHWDeviceContext *hwdev, +AVHWDeviceContext *src_ctx, +int flags) +{ +int err; +switch (src_ctx->type) { + +#if HAVE_OPENCL_VAAPI_BEIGNET +case AV_HWDEVICE_TYPE_VAAPI: +{ +// Surface mapping works via DRM PRIME fds with no special +// initialisation required in advance. This just finds the +// Beignet ICD by name. +AVDictionary *opts = NULL; + +err = av_dict_set(&opts, "platform_vendor", "Intel", 0); +if (err >= 0) +err = av_dict_set(&opts, "platform_version", "beignet", 0); +if (err >= 0) { +OpenCLDeviceSelector selector = { +.platform_index = -1, +.device_index= 0, +.context = opts, +.enumerate_platforms = &opencl_enumerate_platforms, +.filter_platform = &opencl_filter_platform, +.enumerate_devices = &opencl_enumerate_devices, +.filter_device = NULL, +}; +err = opencl_device_create_internal(hwdev, &selector, NULL); +} +av_dict_free(&opts); +} +break; +#endif + +default: +err = AVERROR(ENOSYS); +break; +} + +if (err < 0) +return err; + +return opencl_device_init(hwdev); +} + static int opencl_get_plane_format(enum AVPixelFormat pixfmt, int plane, int width, int height, cl_image_format *image_format, @@ -1263,6 +1355,177 @@ fail: return err; } +#if HAV