diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index ffc597e..a12c39f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -33,6 +33,10 @@ set( BUILDING "" CACHE INTERNAL "" ) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--disable-new-dtags") + +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +set(CMAKE_INSTALL_RPATH "$ORIGIN") append("-std=c++11 ${API_FLAGS}" CMAKE_CXX_FLAGS) diff --git a/samples/build.pl b/samples/build.pl old mode 100644 new mode 100755 diff --git a/samples/sample_plugins/rotate_opencl/CMakeLists.txt b/samples/sample_plugins/rotate_opencl/CMakeLists.txt index d06400c..8710561 100644 --- a/samples/sample_plugins/rotate_opencl/CMakeLists.txt +++ b/samples/sample_plugins/rotate_opencl/CMakeLists.txt @@ -10,11 +10,8 @@ include_directories ( set( LDFLAGS "${LDFLAGS} -Wl,--version-script=${PLUGINS_COMMON_PATH}/mfx_plugin.map" ) -# for clCreateFromGLTexture2D and clCreateFromGLTexture3D in CL/cl_gl.h -set( CFLAGS "-DCL_USE_DEPRECATED_OPENCL_1_1_APIS" ) - list( APPEND LIBS_VARIANT sample_common ) -list(APPEND sources.plus "${PLUGINS_COMMON_PATH}/mfx_plugin_module.cpp") +list( APPEND sources.plus "${PLUGINS_COMMON_PATH}/mfx_plugin_module.cpp") set(DEPENDENCIES opencl libva libmfx dl) make_library( sample_plugin_opencl none shared "nosafestring" ) diff --git a/samples/sample_plugins/rotate_opencl/include/opencl_filter.h b/samples/sample_plugins/rotate_opencl/include/opencl_filter.h index 9ce3fbf..fb53d11 100644 --- a/samples/sample_plugins/rotate_opencl/include/opencl_filter.h +++ b/samples/sample_plugins/rotate_opencl/include/opencl_filter.h @@ -21,12 +21,19 @@ or https://software.intel.com/en-us/media-client-solutions-support. #include #include +#include +#include + +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS #include #include "mfxvideo++.h" #include "logger.h" -#define INIT_CL_EXT_FUNC(x) x = (x ## _fn)clGetExtensionFunctionAddress(#x); +#define DECL_CL_EXT_FUNC(func_name) func_name##_fn func_name +#define INIT_CL_EXT_FUNC(platform_id, func_name) \ + (func_name = (func_name##_fn)clGetExtensionFunctionAddressForPlatform(platform_id, #func_name)) #define SAFE_OCL_FREE(P, FREE_FUNC) { if (P) { FREE_FUNC(P); P = NULL; } } typedef struct { @@ -104,6 +111,7 @@ class OpenCLFilterBase: public OpenCLFilter int m_currentHeight; std::vector m_kernels; + std::vector m_requiredOclExtensions; static const size_t c_shared_surfaces_num = 2; // In and Out static const size_t c_ocl_surface_buffers_num = 2*c_shared_surfaces_num; // YIn, UVIn, YOut, UVOut diff --git a/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx11.h b/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx11.h index 1f495a3..9759867 100644 --- a/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx11.h +++ b/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx11.h @@ -21,10 +21,10 @@ or https://software.intel.com/en-us/media-client-solutions-support. #if defined(_WIN32) || defined(_WIN64) +#include + #include "opencl_filter.h" -#include "d3d11_allocator.h" -#include -#include + class OpenCLFilterDX11 : public OpenCLFilterBase { diff --git a/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx9.h b/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx9.h index ba341d2..204f89e 100644 --- a/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx9.h +++ b/samples/sample_plugins/rotate_opencl/include/opencl_filter_dx9.h @@ -23,7 +23,7 @@ or https://software.intel.com/en-us/media-client-solutions-support. #include "opencl_filter.h" #include "d3d_utils.h" -#include "d3d_allocator.h" + class OpenCLFilterDX9 : public OpenCLFilterBase { diff --git a/samples/sample_plugins/rotate_opencl/include/opencl_filter_va.h b/samples/sample_plugins/rotate_opencl/include/opencl_filter_va.h index 2c911b3..09d158e 100644 --- a/samples/sample_plugins/rotate_opencl/include/opencl_filter_va.h +++ b/samples/sample_plugins/rotate_opencl/include/opencl_filter_va.h @@ -21,20 +21,11 @@ or https://software.intel.com/en-us/media-client-solutions-support. #if !defined(_WIN32) && !defined(_WIN64) -#include "logger.h" -#include -#include -#include - #include -#define DCL_USE_DEPRECATED_OPENCL_1_1_APIS -#include -#include -#include - #include "opencl_filter.h" + class OpenCLFilterVA : public OpenCLFilterBase { public: diff --git a/samples/sample_plugins/rotate_opencl/include/sample_opencl_plugin.h b/samples/sample_plugins/rotate_opencl/include/sample_opencl_plugin.h index f8a5e48..587fb53 100644 --- a/samples/sample_plugins/rotate_opencl/include/sample_opencl_plugin.h +++ b/samples/sample_plugins/rotate_opencl/include/sample_opencl_plugin.h @@ -43,11 +43,6 @@ or https://software.intel.com/en-us/media-client-solutions-support. //#define _interlockedbittestandset64 fake_set64 //#define _interlockedbittestandreset64 fake_reset64 -#if !defined(_WIN32) && !defined(_WIN64) -#include -#define CL_USE_DEPRECATED_OPENCL_1_1_APIS 1 -#endif - #undef CL_VERSION_1_2 #include "CL/cl.hpp" #undef _interlockedbittestandset diff --git a/samples/sample_plugins/rotate_opencl/src/opencl_filter.cpp b/samples/sample_plugins/rotate_opencl/src/opencl_filter.cpp index 97e1604..5d4d679 100644 --- a/samples/sample_plugins/rotate_opencl/src/opencl_filter.cpp +++ b/samples/sample_plugins/rotate_opencl/src/opencl_filter.cpp @@ -17,6 +17,7 @@ The original version of this sample may be obtained from https://software.intel. or https://software.intel.com/en-us/media-client-solutions-support. \**********************************************************************************/ +#include #include #include @@ -127,43 +128,104 @@ cl_int OpenCLFilterBase::InitPlatform() error = clGetPlatformIDs(0, NULL, &num_platforms); if(error) { - log.error() << "OpenCLFilter: Couldn't get platform IDs. \ - Make sure your platform \ - supports OpenCL and can find a proper library." << endl; + log.error() << "OpenCLFilter: Couldn't get number of OCL platform IDs." + << " Make sure your platform supports OpenCL and can find a proper library." << endl; return error; } // Get all of the handles to the installed OpenCL platforms std::vector platforms(num_platforms); error = clGetPlatformIDs(num_platforms, &platforms[0], &num_platforms); - if(error) { - log.error() << "OpenCLFilter: Failed to get OCL platform IDs. Error Code; " << error; + if(error) + { + log.error() << "OpenCLFilter: Failed to get OCL platform IDs." + << " Error code: " << error << endl; return error; } - // Find the platform handle for the installed Gen driver - const size_t max_string_size = 1024; - char platform[max_string_size]; - cl_device_id device_ids[2] = {0}; - for (unsigned int platform_index = 0; platform_index < num_platforms; platform_index++) + for (std::vector::iterator platformIt = platforms.begin(); platformIt != platforms.end(); ++platformIt) { - error = clGetPlatformInfo(platforms[platform_index], CL_PLATFORM_NAME, max_string_size, platform, NULL); - if(error) return error; + cl_uint num_devices = 0; - // Choose only GPU devices - if (clGetDeviceIDs(platforms[platform_index], CL_DEVICE_TYPE_GPU, - sizeof(device_ids)/sizeof(device_ids[0]), device_ids, 0) != CL_SUCCESS) + error = clGetDeviceIDs(*platformIt, CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices); + if(error) + { + log.warning() << "OpenCLFilter: Couldn't get number of GPU devices for current platform." + << " Error code: " << error << endl; continue; + } + + std::vector devices(num_devices); - if(strstr(platform, "Intel")) // Use only Intel platfroms + error = clGetDeviceIDs(*platformIt, CL_DEVICE_TYPE_GPU, devices.size(), &devices[0], 0); + if(error) { - log.info() << "OpenCL platform \"" << platform << "\" is used" << endl; - m_clplatform = platforms[platform_index]; + log.error() << "OpenCLFilter: Couldn't get GPU device IDs." + << " Error code: " << error << endl; + continue; + } + + for(std::vector::iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt) + { + cl_uint deviceVendorId = 0; + + error = clGetDeviceInfo(*deviceIt, CL_DEVICE_VENDOR_ID, sizeof(deviceVendorId), &deviceVendorId, NULL); + + if (error) + { + log.error() << "OpenCLFilter: Couldn't get the device vendor id." + << " Error code: " << error << endl; + continue; + } + + // Skip non-Intel devices + if (deviceVendorId != 0x8086) + { + continue; + } + + size_t extNamesBufferSize = 0; + + error = clGetDeviceInfo(*deviceIt, CL_DEVICE_EXTENSIONS, 0, NULL, &extNamesBufferSize); + if(error) + { + log.error() << "OpenCLFilter: Couldn't get the size of string with supported extensions for device." + << " Error code: " << error << endl; + continue; + } + + std::vector extNamesBuffer(extNamesBufferSize); + + error = clGetDeviceInfo(*deviceIt, CL_DEVICE_EXTENSIONS, extNamesBuffer.size(), &extNamesBuffer[0], 0); + if(error) + { + log.error() << "OpenCLFilter: Couldn't get supported extensions for device." + << " Error code: " << error << endl; + continue; + } + + log.debug() << "OpenCLFilter: Supported extensions for device: " << &extNamesBuffer[0] << endl; + + bool isDeviceAppropriate = true; + + for(std::vector::iterator extNameIt = m_requiredOclExtensions.begin(); extNameIt != m_requiredOclExtensions.end(); ++extNameIt) + { + isDeviceAppropriate = isDeviceAppropriate && (std::strstr(&extNamesBuffer[0], extNameIt->c_str()) != NULL); + } + + if(isDeviceAppropriate) + { + m_clplatform = *platformIt; + log.debug() << "OpenCLFilter: Appropriate OCL platform is found." << endl; + goto _select_platform_loop_end; + } } } + +_select_platform_loop_end: if (0 == m_clplatform) { - log.error() << "OpenCLFilter: Didn't find an Intel platform!" << endl; + log.error() << "OpenCLFilter: Couldn't find an appropriate OCL platform!" << endl; return CL_INVALID_PLATFORM; } diff --git a/samples/sample_plugins/rotate_opencl/src/opencl_filter_dx11.cpp b/samples/sample_plugins/rotate_opencl/src/opencl_filter_dx11.cpp index e2496dc..a42eb02 100644 --- a/samples/sample_plugins/rotate_opencl/src/opencl_filter_dx11.cpp +++ b/samples/sample_plugins/rotate_opencl/src/opencl_filter_dx11.cpp @@ -21,13 +21,9 @@ or https://software.intel.com/en-us/media-client-solutions-support. #if defined(_WIN32) || defined(_WIN64) -#include - #include "opencl_filter_dx11.h" #include "sample_defs.h" -#include "stdexcept" - // INTEL DX9 sharing functions declared deprecated in OpenCL 1.2 #pragma warning( disable : 4996 ) @@ -36,37 +32,25 @@ or https://software.intel.com/en-us/media-client-solutions-support. #define DX_MEDIA_SHARING #define CL_DX9_MEDIA_SHARING_INTEL_EXT -#include +#include #include using std::endl; -#define INIT_CL_EXT_FUNC(x) x = (x ## _fn)clGetExtensionFunctionAddress(#x); #define SAFE_OCL_FREE(P, FREE_FUNC) { if (P) { FREE_FUNC(P); P = NULL; } } #define MAX_PLATFORMS 32 #define MAX_STRING_SIZE 1024 -#define EXT_DECLARE(_name) _name##_fn _name -#define EXT_INIT(_p, _name) _name = (_name##_fn) clGetExtensionFunctionAddressForPlatform((_p), #_name); res &= (_name != NULL); - - -EXT_DECLARE(clGetDeviceIDsFromD3D11KHR); -EXT_DECLARE(clCreateFromD3D11Texture2DKHR); -EXT_DECLARE(clEnqueueAcquireD3D11ObjectsKHR); -EXT_DECLARE(clEnqueueReleaseD3D11ObjectsKHR); -inline int InitD11SharingFunctions(cl_platform_id platform) // get DX11 sharing functions -{ - bool res = true; - EXT_INIT(platform,clGetDeviceIDsFromD3D11KHR); - EXT_INIT(platform,clCreateFromD3D11Texture2DKHR); - EXT_INIT(platform,clEnqueueAcquireD3D11ObjectsKHR); - EXT_INIT(platform,clEnqueueReleaseD3D11ObjectsKHR); - return res; -} +DECL_CL_EXT_FUNC(clGetDeviceIDsFromD3D11KHR); +DECL_CL_EXT_FUNC(clCreateFromD3D11Texture2DKHR); +DECL_CL_EXT_FUNC(clEnqueueAcquireD3D11ObjectsKHR); +DECL_CL_EXT_FUNC(clEnqueueReleaseD3D11ObjectsKHR); OpenCLFilterDX11::OpenCLFilterDX11() : m_pDevice(0) { + m_requiredOclExtensions.push_back("cl_khr_d3d11_sharing"); + for (int i = 0; i +#include #include using std::endl; - -clGetDeviceIDsFromDX9INTEL_fn clGetDeviceIDsFromDX9INTEL = NULL; -clCreateFromDX9MediaSurfaceINTEL_fn clCreateFromDX9MediaSurfaceINTEL = NULL; -clEnqueueAcquireDX9ObjectsINTEL_fn clEnqueueAcquireDX9ObjectsINTEL = NULL; -clEnqueueReleaseDX9ObjectsINTEL_fn clEnqueueReleaseDX9ObjectsINTEL = NULL; +DECL_CL_EXT_FUNC(clGetDeviceIDsFromDX9INTEL); +DECL_CL_EXT_FUNC(clCreateFromDX9MediaSurfaceINTEL); +DECL_CL_EXT_FUNC(clEnqueueAcquireDX9ObjectsINTEL); +DECL_CL_EXT_FUNC(clEnqueueReleaseDX9ObjectsINTEL); OpenCLFilterDX9::OpenCLFilterDX9() { + m_requiredOclExtensions.push_back("cl_intel_dx9_media_sharing"); + for(size_t i=0;i + using std::endl; -clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn clGetDeviceIDsFromVA_APIMediaAdapterINTEL = NULL; -clCreateFromVA_APIMediaSurfaceINTEL_fn clCreateFromVA_APIMediaSurfaceINTEL = NULL; -clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn clEnqueueAcquireVA_APIMediaSurfacesINTEL = NULL; -clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn clEnqueueReleaseVA_APIMediaSurfacesINTEL = NULL; +DECL_CL_EXT_FUNC(clGetDeviceIDsFromVA_APIMediaAdapterINTEL); +DECL_CL_EXT_FUNC(clCreateFromVA_APIMediaSurfaceINTEL); +DECL_CL_EXT_FUNC(clEnqueueAcquireVA_APIMediaSurfacesINTEL); +DECL_CL_EXT_FUNC(clEnqueueReleaseVA_APIMediaSurfacesINTEL); OpenCLFilterVA::OpenCLFilterVA() { + m_requiredOclExtensions.push_back("cl_intel_va_api_media_sharing"); + m_vaDisplay = 0; for(size_t i = 0; i < c_shared_surfaces_num; i++) { @@ -52,25 +56,16 @@ cl_int OpenCLFilterVA::OCLInit(mfxHDL device) cl_int OpenCLFilterVA::InitSurfaceSharingExtension() { - cl_int error = CL_SUCCESS; - - // Hook up the d3d sharing extension functions that we need - INIT_CL_EXT_FUNC(clGetDeviceIDsFromVA_APIMediaAdapterINTEL); - INIT_CL_EXT_FUNC(clCreateFromVA_APIMediaSurfaceINTEL); - INIT_CL_EXT_FUNC(clEnqueueAcquireVA_APIMediaSurfacesINTEL); - INIT_CL_EXT_FUNC(clEnqueueReleaseVA_APIMediaSurfacesINTEL); - - // Check for success - if (!clGetDeviceIDsFromVA_APIMediaAdapterINTEL || - !clCreateFromVA_APIMediaSurfaceINTEL || - !clEnqueueAcquireVA_APIMediaSurfacesINTEL || - !clEnqueueReleaseVA_APIMediaSurfacesINTEL) + if (!INIT_CL_EXT_FUNC(m_clplatform, clGetDeviceIDsFromVA_APIMediaAdapterINTEL) + || !INIT_CL_EXT_FUNC(m_clplatform, clCreateFromVA_APIMediaSurfaceINTEL) + || !INIT_CL_EXT_FUNC(m_clplatform, clEnqueueAcquireVA_APIMediaSurfacesINTEL) + || !INIT_CL_EXT_FUNC(m_clplatform, clEnqueueReleaseVA_APIMediaSurfacesINTEL)) { log.error() << "OpenCLFilter: Couldn't get all of the media sharing routines" << endl; return CL_INVALID_PLATFORM; } - return error; + return CL_SUCCESS; } cl_int OpenCLFilterVA::InitDevice()