Skip to content
This repository was archived by the owner on Apr 1, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Empty file modified samples/build.pl
100644 → 100755
Empty file.
5 changes: 1 addition & 4 deletions samples/sample_plugins/rotate_opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
10 changes: 9 additions & 1 deletion samples/sample_plugins/rotate_opencl/include/opencl_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ or https://software.intel.com/en-us/media-client-solutions-support.

#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>

#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 {
Expand Down Expand Up @@ -104,6 +111,7 @@ class OpenCLFilterBase: public OpenCLFilter
int m_currentHeight;

std::vector<OCL_YUV_kernel> m_kernels;
std::vector<std::string> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ or https://software.intel.com/en-us/media-client-solutions-support.

#if defined(_WIN32) || defined(_WIN64)

#include <d3d11.h>

#include "opencl_filter.h"
#include "d3d11_allocator.h"
#include <initguid.h>
#include <guiddef.h>


class OpenCLFilterDX11 : public OpenCLFilterBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
11 changes: 1 addition & 10 deletions samples/sample_plugins/rotate_opencl/include/opencl_filter_va.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ or https://software.intel.com/en-us/media-client-solutions-support.

#if !defined(_WIN32) && !defined(_WIN64)

#include "logger.h"
#include <string>
#include <stdio.h>
#include <stdlib.h>

#include <va/va.h>

#define DCL_USE_DEPRECATED_OPENCL_1_1_APIS
#include <CL/cl.h>
#include <CL/opencl.h>
#include <CL/va_ext.h>

#include "opencl_filter.h"


class OpenCLFilterVA : public OpenCLFilterBase
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <va/va.h>
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS 1
#endif

#undef CL_VERSION_1_2
#include "CL/cl.hpp"
#undef _interlockedbittestandset
Expand Down
100 changes: 81 additions & 19 deletions samples/sample_plugins/rotate_opencl/src/opencl_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstring>
#include <fstream>
#include <stdexcept>

Expand Down Expand Up @@ -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<cl_platform_id> 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<cl_platform_id>::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<cl_device_id> 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<cl_device_id>::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<char> 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<std::string>::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;
}

Expand Down
43 changes: 17 additions & 26 deletions samples/sample_plugins/rotate_opencl/src/opencl_filter_dx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ or https://software.intel.com/en-us/media-client-solutions-support.

#if defined(_WIN32) || defined(_WIN64)

#include <fstream>

#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 )

Expand All @@ -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 <CL/opencl.h>
#include <CL/cl_ext.h>
#include <CL/cl_d3d11.h>

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<c_shared_surfaces_num; i++)
m_pSharedSurfaces[i] = 0;
}
Expand All @@ -92,9 +76,16 @@ cl_int OpenCLFilterDX11::OCLInit(mfxHDL device) {


cl_int OpenCLFilterDX11::InitSurfaceSharingExtension() {
if (InitD11SharingFunctions(m_clplatform))
return CL_SUCCESS;
return CL_INVALID_VALUE;
if(!INIT_CL_EXT_FUNC(m_clplatform,clGetDeviceIDsFromD3D11KHR)
|| !INIT_CL_EXT_FUNC(m_clplatform,clCreateFromD3D11Texture2DKHR)
|| !INIT_CL_EXT_FUNC(m_clplatform,clEnqueueAcquireD3D11ObjectsKHR)
|| !INIT_CL_EXT_FUNC(m_clplatform,clEnqueueReleaseD3D11ObjectsKHR))
{
log.error() << "OpenCLFilter: Couldn't get all of the media sharing routines" << endl;
return CL_INVALID_PLATFORM;
}

return CL_SUCCESS;
}

cl_int OpenCLFilterDX11::InitDevice() {
Expand Down
43 changes: 12 additions & 31 deletions samples/sample_plugins/rotate_opencl/src/opencl_filter_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ or https://software.intel.com/en-us/media-client-solutions-support.
#define DX_MEDIA_SHARING
#define CL_DX9_MEDIA_SHARING_INTEL_EXT

#include <CL/opencl.h>
#include <CL/cl_ext.h>
#include <CL/cl_dx9_media_sharing.h>

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<c_shared_surfaces_num;i++)
{
m_hSharedSurfaces[i] = NULL;
Expand Down Expand Up @@ -76,37 +77,17 @@ cl_int OpenCLFilterDX9::OCLInit(mfxHDL device)

cl_int OpenCLFilterDX9::InitSurfaceSharingExtension()
{
cl_int error = CL_SUCCESS;

// Check if surface sharing is available
size_t len = 0;
const size_t max_string_size = 1024;
char extensions[max_string_size];
error = clGetPlatformInfo(m_clplatform, CL_PLATFORM_EXTENSIONS, max_string_size, extensions, &len);
log.info() << "OpenCLFilter: Platform extensions: " << extensions << endl;
if(NULL == strstr(extensions, "cl_intel_dx9_media_sharing"))
{
log.error() << "OpenCLFilter: DX9 media sharing not available!" << endl;
return CL_INVALID_PLATFORM;
}

// Hook up the d3d sharing extension functions that we need
INIT_CL_EXT_FUNC(clGetDeviceIDsFromDX9INTEL);
INIT_CL_EXT_FUNC(clCreateFromDX9MediaSurfaceINTEL);
INIT_CL_EXT_FUNC(clEnqueueAcquireDX9ObjectsINTEL);
INIT_CL_EXT_FUNC(clEnqueueReleaseDX9ObjectsINTEL);

// Check for success
if (!clGetDeviceIDsFromDX9INTEL ||
!clCreateFromDX9MediaSurfaceINTEL ||
!clEnqueueAcquireDX9ObjectsINTEL ||
!clEnqueueReleaseDX9ObjectsINTEL)
if(!INIT_CL_EXT_FUNC(m_clplatform, clGetDeviceIDsFromDX9INTEL)
|| !INIT_CL_EXT_FUNC(m_clplatform, clCreateFromDX9MediaSurfaceINTEL)
|| !INIT_CL_EXT_FUNC(m_clplatform, clEnqueueAcquireDX9ObjectsINTEL)
|| !INIT_CL_EXT_FUNC(m_clplatform, clEnqueueReleaseDX9ObjectsINTEL))
{
log.error() << "OpenCLFilter: Couldn't get all of the media sharing routines" << endl;
return CL_INVALID_PLATFORM;
}

return error;
return CL_SUCCESS;
}

cl_int OpenCLFilterDX9::InitDevice()
Expand Down
Loading