1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Fixed and updated OpenCL-VA interoperability

This commit is contained in:
Odianosen Ejale
2020-09-11 11:29:31 +01:00
committed by Maksim Shabunin
parent 0dc28d3446
commit 862fc06b6f
11 changed files with 204 additions and 67 deletions
+3
View File
@@ -80,6 +80,9 @@ endif()
if(HAVE_MEMALIGN)
ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/alloc.cpp "HAVE_MEMALIGN=1")
endif()
if(HAVE_VA_INTEL_OLD_HEADER)
ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/va_intel.cpp" "HAVE_VA_INTEL_OLD_HEADER")
endif()
option(OPENCV_ENABLE_ALLOCATOR_STATS "Enable Allocator metrics" ON)
@@ -29,14 +29,11 @@ namespace cv { namespace va_intel {
/** @addtogroup core_va_intel
This section describes Intel VA-API/OpenCL (CL-VA) interoperability.
To enable CL-VA interoperability support, configure OpenCV using CMake with WITH_VA_INTEL=ON . Currently VA-API is
supported on Linux only. You should also install Intel Media Server Studio (MSS) to use this feature. You may
have to specify the path(s) to MSS components for cmake in environment variables:
To enable basic VA interoperability build OpenCV with libva library integration enabled: `-DWITH_VA=ON` (corresponding dev package should be installed).
- VA_INTEL_IOCL_ROOT for Intel OpenCL (default is "/opt/intel/opencl").
To enable advanced CL-VA interoperability support on Intel HW, enable option: `-DWITH_VA_INTEL=ON` (OpenCL integration should be enabled which is the default setting). Special runtime environment should be set up in order to use this feature: correct combination of [libva](https://github.com/intel/libva), [OpenCL runtime](https://github.com/intel/compute-runtime) and [media driver](https://github.com/intel/media-driver) should be installed.
To use CL-VA interoperability you should first create VADisplay (libva), and then call initializeContextFromVA()
function to create OpenCL context and set up interoperability.
Check usage example for details: samples/va_intel/va_intel_interop.cpp
*/
//! @{
+23 -13
View File
@@ -25,13 +25,17 @@ using namespace cv;
# include "opencl_kernels_core.hpp"
#endif // HAVE_OPENCL
#if defined(HAVE_VA_INTEL) && defined(HAVE_OPENCL)
#ifdef HAVE_VA_INTEL
#ifdef HAVE_VA_INTEL_OLD_HEADER
# include <CL/va_ext.h>
#endif // HAVE_VA_INTEL && HAVE_OPENCL
#else
# include <CL/cl_va_api_media_sharing_intel.h>
#endif
#endif
namespace cv { namespace va_intel {
#if defined(HAVE_VA_INTEL) && defined(HAVE_OPENCL)
#ifdef HAVE_VA_INTEL
static clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn clGetDeviceIDsFromVA_APIMediaAdapterINTEL = NULL;
static clCreateFromVA_APIMediaSurfaceINTEL_fn clCreateFromVA_APIMediaSurfaceINTEL = NULL;
@@ -40,7 +44,7 @@ static clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn clEnqueueReleaseVA_APIMediaS
static bool contextInitialized = false;
#endif // HAVE_VA_INTEL && HAVE_OPENCL
#endif // HAVE_VA_INTEL
namespace ocl {
@@ -50,7 +54,7 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
#if !defined(HAVE_VA)
NO_VA_SUPPORT_ERROR;
#else // !HAVE_VA
# if (defined(HAVE_VA_INTEL) && defined(HAVE_OPENCL))
# ifdef HAVE_VA_INTEL
contextInitialized = false;
if (tryInterop)
{
@@ -137,7 +141,13 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
contextInitialized = true;
cl_platform_id platform = platforms[found];
std::string platformName = PlatformInfo(platform).name();
char platformName[1024] = {0};
size_t sz = 0;
if (clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platformName) - 16, platformName, &sz) != CL_SUCCESS
|| sz >= sizeof(platformName))
{
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Failed to get platform name");
}
OpenCLExecutionContext clExecCtx;
try
@@ -154,7 +164,7 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
return const_cast<Context&>(clExecCtx.getContext());
}
}
# endif // HAVE_VA_INTEL && HAVE_OPENCL
# endif // HAVE_VA_INTEL
{
Context& ctx = Context::getDefault(true);
return ctx;
@@ -162,7 +172,7 @@ Context& initializeContextFromVA(VADisplay display, bool tryInterop)
#endif // !HAVE_VA
}
#if defined(HAVE_VA_INTEL) && defined(HAVE_OPENCL)
#ifdef HAVE_VA_INTEL
static bool ocl_convert_nv12_to_bgr(cl_mem clImageY, cl_mem clImageUV, cl_mem clBuffer, int step, int cols, int rows)
{
ocl::Kernel k;
@@ -188,7 +198,7 @@ static bool ocl_convert_bgr_to_nv12(cl_mem clBuffer, int step, int cols, int row
size_t globalsize[] = { (size_t)cols, (size_t)rows };
return k.run(2, globalsize, 0, false);
}
#endif // HAVE_VA_INTEL && HAVE_OPENCL
#endif // HAVE_VA_INTEL
} // namespace cv::va_intel::ocl
@@ -511,7 +521,7 @@ void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface,
Size srcSize = src.size();
CV_Assert(srcSize.width == size.width && srcSize.height == size.height);
# if (defined(HAVE_VA_INTEL) && defined(HAVE_OPENCL))
#ifdef HAVE_VA_INTEL
if (contextInitialized)
{
UMat u = src.getUMat();
@@ -559,7 +569,7 @@ void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface,
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMem failed (UV plane)");
}
else
# endif // HAVE_VA_INTEL && HAVE_OPENCL
# endif // HAVE_VA_INTEL
{
Mat m = src.getMat();
@@ -612,7 +622,7 @@ void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, Out
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
dst.create(size, dtype);
# if (defined(HAVE_VA_INTEL) && defined(HAVE_OPENCL))
#ifdef HAVE_VA_INTEL
if (contextInitialized)
{
UMat u = dst.getUMat();
@@ -660,7 +670,7 @@ void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, Out
CV_Error(cv::Error::OpenCLApiCallError, "OpenCL: clReleaseMem failed (UV plane)");
}
else
# endif // HAVE_VA_INTEL && HAVE_OPENCL
# endif // HAVE_VA_INTEL
{
Mat m = dst.getMat();