Initial commit

Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
Brandon Fliflet
2017-12-21 00:45:38 +01:00
commit 7e9ad41290
1350 changed files with 233156 additions and 0 deletions

View File

@ -0,0 +1,50 @@
# Copyright (c) 2017, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
file(GLOB_RECURSE SHARING_ENABLE_CPPS enable*.cpp)
add_library (${SHARINGS_ENABLE_LIB_NAME} OBJECT ${SHARING_ENABLE_CPPS})
set_target_properties (${SHARINGS_ENABLE_LIB_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(${SHARINGS_ENABLE_LIB_NAME} PRIVATE
${GMM_SOURCE_DIR}/inc/common
${KHRONOS_HEADERS_DIR}
${UMKM_SHAREDDATA_INCLUDE_PATHS}
${IGDRCL__IGC_INCLUDE_DIR}
${THIRD_PARTY_DIR}
)
list (APPEND RUNTIME_SRCS_SHARINGS
${CMAKE_CURRENT_SOURCE_DIR}/sharing_factory.h
${CMAKE_CURRENT_SOURCE_DIR}/sharing_factory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sharing_factory.inl
)
if (WIN32)
target_include_directories(${SHARINGS_ENABLE_LIB_NAME} PUBLIC ${IGDRCL_SOURCE_DIR}/runtime/os_interface/windows)
else (WIN32)
target_include_directories(${SHARINGS_ENABLE_LIB_NAME} PUBLIC ${IGDRCL_SOURCE_DIR}/runtime/os_interface/linux)
endif (WIN32)
add_subdirectory(d3d)
add_subdirectory(va)
set(RUNTIME_SRCS_SHARINGS "${RUNTIME_SRCS_SHARINGS}" PARENT_SCOPE)

View File

@ -0,0 +1,35 @@
# Copyright (c) 2017, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
if(WIN32)
list (APPEND RUNTIME_SRCS_SHARINGS
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt"
"${CMAKE_CURRENT_SOURCE_DIR}/cl_d3d_api.h"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_sharing.h"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_sharing.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_buffer.h"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_texture.h"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_texture.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_surface.h"
"${CMAKE_CURRENT_SOURCE_DIR}/d3d_surface.cpp"
)
set(RUNTIME_SRCS_SHARINGS "${RUNTIME_SRCS_SHARINGS}" PARENT_SCOPE)
endif()

View File

@ -0,0 +1,196 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "config.h"
#include "CL/cl.h"
#include <d3d10_1.h>
#include "CL/cl_dx9_media_sharing.h"
#include "CL/cl_d3d10.h"
#include "CL/cl_d3d11.h"
#define CL_DX9_MEDIA_SHARING_INTEL_EXT
#include "CL/cl_dx9_media_sharing_intel.h"
extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromDX9INTEL(
cl_platform_id platform,
cl_dx9_device_source_intel dx9DeviceSource,
void *dx9Object,
cl_dx9_device_set_intel dx9DeviceSet,
cl_uint numEntries,
cl_device_id *devices,
cl_uint *numDevices);
extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromDX9MediaSurfaceINTEL(
cl_context context,
cl_mem_flags flags,
IDirect3DSurface9 *resource,
HANDLE sharedHandle,
UINT plane,
cl_int *errcodeRet);
extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireDX9ObjectsINTEL(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event);
extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseDX9ObjectsINTEL(
cl_command_queue commandQueue,
cl_uint numObjects,
cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event);
extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromDX9MediaAdapterKHR(
cl_platform_id platform,
cl_uint numMediaAdapters,
cl_dx9_media_adapter_type_khr *mediaAdapterType,
void *mediaAdapters,
cl_dx9_media_adapter_set_khr mediaAdapterSet,
cl_uint numEntries,
cl_device_id *devices,
cl_uint *numDevices) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromDX9MediaSurfaceKHR(
cl_context context,
cl_mem_flags flags,
cl_dx9_media_adapter_type_khr adapterType,
void *surfaceInfo,
cl_uint plane,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireDX9MediaSurfacesKHR(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseDX9MediaSurfacesKHR(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL
clGetDeviceIDsFromD3D10KHR(
cl_platform_id platform,
cl_d3d10_device_source_khr d3dDeviceSource,
void *d3dObject,
cl_d3d10_device_set_khr d3dDeviceSet,
cl_uint numEntries,
cl_device_id *devices,
cl_uint *numDevices) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromD3D10BufferKHR(
cl_context context,
cl_mem_flags flags,
ID3D10Buffer *resource,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromD3D10Texture2DKHR(
cl_context context,
cl_mem_flags flags,
ID3D10Texture2D *resource,
UINT subresource,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromD3D10Texture3DKHR(
cl_context context,
cl_mem_flags flags,
ID3D10Texture3D *resource,
UINT subresource,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueAcquireD3D10ObjectsKHR(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL
clEnqueueReleaseD3D10ObjectsKHR(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) CL_API_SUFFIX__VERSION_1_0;
extern CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDsFromD3D11KHR(
cl_platform_id platform,
cl_d3d11_device_source_khr d3dDeviceSource,
void *d3dObject,
cl_d3d11_device_set_khr d3dDeviceSet,
cl_uint numEntries,
cl_device_id *devices,
cl_uint *numDevices) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D11BufferKHR(
cl_context context,
cl_mem_flags flags,
ID3D11Buffer *resource,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D11Texture2DKHR(
cl_context context,
cl_mem_flags flags,
ID3D11Texture2D *resource,
UINT subresource,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_mem CL_API_CALL clCreateFromD3D11Texture3DKHR(
cl_context context,
cl_mem_flags flags,
ID3D11Texture3D *resource,
UINT subresource,
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueAcquireD3D11ObjectsKHR(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) CL_API_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL clEnqueueReleaseD3D11ObjectsKHR(
cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) CL_API_SUFFIX__VERSION_1_2;

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/d3d/d3d_sharing.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/memory_manager/memory_manager.h"
namespace OCLRT {
class Buffer;
class Context;
template <typename D3D>
class D3DBuffer : public D3DSharing<D3D> {
typedef typename D3D::D3DBufferObj D3DBufferObj;
typedef typename D3D::D3DBufferDesc D3DBufferDesc;
public:
static Buffer *create(Context *context, D3DBufferObj *d3dBuffer, cl_mem_flags flags, cl_int *retCode) {
ErrorCodeHelper err(retCode, CL_SUCCESS);
auto sharingFcns = context->getSharing<D3DSharingFunctions<D3D>>();
void *sharedHandle = nullptr;
D3DBufferDesc bufferDesc = {};
sharingFcns->getBufferDesc(&bufferDesc, d3dBuffer);
bool sharedResource = false;
D3DBufferObj *bufferStaging = nullptr;
if (bufferDesc.MiscFlags & D3DResourceFlags::MISC_SHARED) {
bufferStaging = d3dBuffer;
sharedResource = true;
} else {
sharingFcns->createBuffer(&bufferStaging, bufferDesc.ByteWidth);
}
sharingFcns->getSharedHandle(bufferStaging, &sharedHandle);
auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), true);
auto d3dBufferObj = new D3DBuffer<D3D>(context, d3dBuffer, bufferStaging, sharedResource);
return Buffer::createSharedBuffer(context, flags, d3dBufferObj, alloc);
}
~D3DBuffer() override = default;
protected:
D3DBuffer(Context *context, D3DBufferObj *d3dBuffer, D3DBufferObj *bufferStaging, bool sharedResource)
: D3DSharing(context, d3dBuffer, bufferStaging, 0, sharedResource){};
};
} // namespace OCLRT

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/d3d/d3d_sharing.h"
#include "runtime/context/context.h"
#include "runtime/mem_obj/image.h"
#include "runtime/gmm_helper/gmm_helper.h"
using namespace OCLRT;
template class D3DSharing<D3DTypesHelper::D3D9>;
template class D3DSharing<D3DTypesHelper::D3D10>;
template class D3DSharing<D3DTypesHelper::D3D11>;
template <typename D3D>
D3DSharing<D3D>::D3DSharing(Context *context, D3DResource *resource, D3DResource *resourceStaging, unsigned int subresource, bool sharedResource)
: sharedResource(sharedResource), subresource(subresource), resource(resource), resourceStaging(resourceStaging), context(context) {
sharingFunctions = context->getSharing<D3DSharingFunctions<D3D>>();
sharingFunctions->addRef(resource);
sharingFunctions->createQuery(&this->d3dQuery);
sharingFunctions->track(resource, subresource);
};
template <typename D3D>
D3DSharing<D3D>::~D3DSharing() {
sharingFunctions->untrack(resource, subresource);
if (!sharedResource) {
sharingFunctions->release(resourceStaging);
}
sharingFunctions->release(resource);
sharingFunctions->release(d3dQuery);
};
template <typename D3D>
void D3DSharing<D3D>::synchronizeObject(UpdateData *updateData) {
void *sharedHandle = nullptr;
sharingFunctions->getDeviceContext(d3dQuery);
if (!sharedResource) {
sharingFunctions->copySubresourceRegion(resourceStaging, 0, resource, subresource);
sharingFunctions->flushAndWait(d3dQuery);
} else if (!context->getInteropUserSyncEnabled()) {
sharingFunctions->flushAndWait(d3dQuery);
}
sharingFunctions->releaseDeviceContext(d3dQuery);
updateData->synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}
template <typename D3D>
void D3DSharing<D3D>::releaseResource(MemObj *memObject) {
if (!sharedResource) {
sharingFunctions->getDeviceContext(d3dQuery);
sharingFunctions->copySubresourceRegion(resource, subresource, resourceStaging, 0);
if (!context->getInteropUserSyncEnabled()) {
sharingFunctions->flushAndWait(d3dQuery);
}
sharingFunctions->releaseDeviceContext(d3dQuery);
}
}
template <typename D3D>
void D3DSharing<D3D>::updateImgInfo(Gmm *gmm, ImageInfo &imgInfo, cl_image_desc &imgDesc, OCLPlane oclPlane, cl_uint arrayIndex) {
gmm->updateImgInfo(imgInfo, imgDesc, arrayIndex);
if (oclPlane == OCLPlane::PLANE_U || oclPlane == OCLPlane::PLANE_V || oclPlane == OCLPlane::PLANE_UV) {
imgDesc.image_width /= 2;
imgDesc.image_height /= 2;
if (oclPlane != OCLPlane::PLANE_UV) {
imgDesc.image_row_pitch /= 2;
}
}
}
template <typename D3D>
const SurfaceFormatInfo *D3DSharing<D3D>::findSurfaceFormatInfo(GMM_RESOURCE_FORMAT_ENUM gmmFormat, cl_mem_flags flags) {
const SurfaceFormatInfo *surfaceFormatTable = nullptr;
const SurfaceFormatInfo *surfaceFormatInfo = nullptr;
size_t numSurfaceFormats = 0;
for (size_t i = 0; i < numSnormSurfaceFormats; i++) {
if (gmmFormat == snormSurfaceFormats[i].GMMSurfaceFormat) {
return &snormSurfaceFormats[i];
}
}
if ((flags & CL_MEM_READ_ONLY) == CL_MEM_READ_ONLY) {
surfaceFormatTable = readOnlySurfaceFormats;
numSurfaceFormats = numReadOnlySurfaceFormats;
} else if ((flags & CL_MEM_WRITE_ONLY) == CL_MEM_WRITE_ONLY) {
surfaceFormatTable = writeOnlySurfaceFormats;
numSurfaceFormats = numWriteOnlySurfaceFormats;
} else {
surfaceFormatTable = readWriteSurfaceFormats;
numSurfaceFormats = numReadWriteSurfaceFormats;
}
for (size_t i = 0; i < numSurfaceFormats; i++) {
if (gmmFormat == surfaceFormatTable[i].GMMSurfaceFormat) {
surfaceFormatInfo = &surfaceFormatTable[i];
break;
}
}
return surfaceFormatInfo;
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/d3d/d3d_sharing.h"
#include "d3d_sharing_functions.h"
enum GMM_RESOURCE_FORMAT_ENUM;
namespace OCLRT {
class Context;
class Gmm;
struct SurfaceFormatInfo;
struct ImageInfo;
enum OCLPlane;
template <typename D3D>
class D3DSharing : public SharingHandler {
typedef typename D3D::D3DQuery D3DQuery;
typedef typename D3D::D3DResource D3DResource;
public:
D3DSharing(Context *context, D3DResource *resource, D3DResource *resourceStaging, unsigned int subresource, bool sharedResource);
~D3DSharing() override;
void synchronizeObject(UpdateData *updateData) override;
void releaseResource(MemObj *memObject) override;
D3DResource **getResourceHandler() { return &resource; }
void *getResourceStaging() { return resourceStaging; }
unsigned int &getSubresource() { return subresource; }
typename D3DQuery *getQuery() { return d3dQuery; }
bool isSharedResource() { return sharedResource; }
static const SurfaceFormatInfo *findSurfaceFormatInfo(GMM_RESOURCE_FORMAT_ENUM gmmFormat, cl_mem_flags flags);
protected:
static void updateImgInfo(Gmm *gmm, ImageInfo &imgInfo, cl_image_desc &imgDesc, OCLPlane oclPlane, cl_uint arrayIndex);
Context *context;
D3DSharingFunctions<D3D> *sharingFunctions = nullptr;
D3DResource *resource = nullptr;
D3DResource *resourceStaging = nullptr;
D3DQuery *d3dQuery = nullptr;
bool sharedResource = false;
unsigned int subresource = 0;
};
} // namespace OCLRT

View File

@ -0,0 +1,308 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/d3d/d3d_surface.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/mem_obj/image.h"
#include "runtime/helpers/get_info.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "mmsystem.h"
using namespace OCLRT;
D3DSurface::D3DSurface(Context *context, cl_dx9_surface_info_khr *surfaceInfo, D3D9Surface *surfaceStaging, cl_uint plane,
OCLPlane oclPlane, cl_dx9_media_adapter_type_khr adapterType, bool sharedResource, bool lockable)
: D3DSharing(context, surfaceInfo->resource, surfaceStaging, plane, sharedResource), adapterType(adapterType),
surfaceInfo(*surfaceInfo), lockable(lockable), plane(plane), oclPlane(oclPlane), d3d9Surface(surfaceInfo->resource),
d3d9SurfaceStaging(surfaceStaging) {
resourceDevice = sharingFunctions->getDevice();
};
Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo, cl_mem_flags flags,
cl_dx9_media_adapter_type_khr adapterType, cl_uint plane, cl_int *retCode) {
ErrorCodeHelper err(retCode, CL_SUCCESS);
D3D9Surface *surfaceStaging = nullptr;
cl_image_desc imgDesc = {};
ImageInfo imgInfo = {};
cl_image_format imgFormat = {};
McsSurfaceInfo mcsSurfaceInfo = {};
OCLPlane oclPlane = OCLPlane::NO_PLANE;
if (!context || !context->getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>() || !context->getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>()->getDevice()) {
err.set(CL_INVALID_CONTEXT);
return nullptr;
}
auto sharingFcns = context->getSharing<D3DSharingFunctions<D3DTypesHelper::D3D9>>();
if (sharingFcns->isTracked(surfaceInfo->resource, plane)) {
err.set(CL_INVALID_DX9_RESOURCE_INTEL);
return nullptr;
}
sharingFcns->updateDevice(surfaceInfo->resource);
imgInfo.imgDesc = &imgDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
D3D9SurfaceDesc surfaceDesc = {};
sharingFcns->getTexture2dDesc(&surfaceDesc, surfaceInfo->resource);
imgDesc.image_width = surfaceDesc.Width;
imgDesc.image_height = surfaceDesc.Height;
if (surfaceDesc.Pool != D3DPOOL_DEFAULT) {
err.set(CL_INVALID_DX9_RESOURCE_INTEL);
return nullptr;
}
err.set(findImgFormat(surfaceDesc.Format, imgFormat, plane, oclPlane));
if (err.localErrcode != CL_SUCCESS) {
return nullptr;
}
imgInfo.plane = Gmm::convertPlane(oclPlane);
imgInfo.surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat);
bool isSharedResource = false;
bool lockable = false;
GraphicsAllocation *alloc = nullptr;
if (surfaceInfo->shared_handle) {
isSharedResource = true;
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), false);
updateImgInfo(alloc->gmm, imgInfo, imgDesc, oclPlane, 0u);
} else {
lockable = !(surfaceDesc.Usage & D3DResourceFlags::USAGE_RENDERTARGET) || oclPlane != OCLPlane::NO_PLANE;
if (!lockable) {
sharingFcns->createTexture2d(&surfaceStaging, &surfaceDesc, 0u);
}
if (oclPlane == OCLPlane::PLANE_U || oclPlane == OCLPlane::PLANE_V || oclPlane == OCLPlane::PLANE_UV) {
imgDesc.image_width /= 2;
imgDesc.image_height /= 2;
}
Gmm *gmm = Gmm::queryImgParams(imgInfo, context->getDevice(0)->getRenderCoreFamily());
imgDesc.image_row_pitch = imgInfo.rowPitch;
imgDesc.image_slice_pitch = imgInfo.slicePitch;
alloc = context->getMemoryManager()->allocateGraphicsMemoryForImage(imgInfo, gmm);
}
DEBUG_BREAK_IF(!alloc);
auto surface = new D3DSurface(context, surfaceInfo, surfaceStaging, plane, oclPlane, adapterType, isSharedResource, lockable);
return Image::createSharedImage(context, surface, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
}
void D3DSurface::synchronizeObject(UpdateData *updateData) {
D3DLOCKED_RECT lockedRect = {};
sharingFunctions->setDevice(resourceDevice);
if (sharedResource && !context->getInteropUserSyncEnabled()) {
sharingFunctions->flushAndWait(d3dQuery);
} else if (!sharedResource) {
if (lockable) {
sharingFunctions->lockRect(d3d9Surface, &lockedRect, D3DLOCK_READONLY);
} else {
sharingFunctions->getRenderTargetData(d3d9Surface, d3d9SurfaceStaging);
sharingFunctions->lockRect(d3d9SurfaceStaging, &lockedRect, D3DLOCK_READONLY);
}
auto image = castToObject<Image>(updateData->memObject);
auto sys = lockedRect.pBits;
auto gpu = context->getMemoryManager()->lockResource(image->getGraphicsAllocation());
auto pitch = static_cast<ULONG>(lockedRect.Pitch);
auto height = static_cast<ULONG>(image->getImageDesc().image_height);
image->getGraphicsAllocation()->gmm->resourceCopyBlt(sys, gpu, pitch, height, 1u, oclPlane);
context->getMemoryManager()->unlockResource(updateData->memObject->getGraphicsAllocation());
if (lockable) {
sharingFunctions->unlockRect(d3d9Surface);
} else {
sharingFunctions->unlockRect(d3d9SurfaceStaging);
}
sharingFunctions->flushAndWait(d3dQuery);
}
updateData->synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}
void D3DSurface::releaseResource(MemObj *memObject) {
D3DLOCKED_RECT lockedRect = {};
sharingFunctions->setDevice(resourceDevice);
if (!sharedResource) {
if (lockable) {
sharingFunctions->lockRect(d3d9Surface, &lockedRect, 0);
} else {
sharingFunctions->lockRect(d3d9SurfaceStaging, &lockedRect, 0);
}
auto image = castToObject<Image>(memObject);
auto sys = lockedRect.pBits;
auto gpu = context->getMemoryManager()->lockResource(image->getGraphicsAllocation());
auto pitch = static_cast<ULONG>(lockedRect.Pitch);
auto height = static_cast<ULONG>(image->getImageDesc().image_height);
image->getGraphicsAllocation()->gmm->resourceCopyBlt(sys, gpu, pitch, height, 0u, oclPlane);
context->getMemoryManager()->unlockResource(memObject->getGraphicsAllocation());
if (lockable) {
sharingFunctions->unlockRect(d3d9Surface);
} else {
sharingFunctions->unlockRect(d3d9SurfaceStaging);
sharingFunctions->updateSurface(d3d9SurfaceStaging, d3d9Surface);
}
}
}
cl_int D3DSurface::findImgFormat(D3DFORMAT d3dFormat, cl_image_format &imgFormat, cl_uint plane, OCLPlane &oclPlane) {
oclPlane = OCLPlane::NO_PLANE;
bool noPlaneRequired = true;
switch (d3dFormat) {
case D3DFMT_R32F:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_FLOAT;
break;
case D3DFMT_R16F:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_HALF_FLOAT;
break;
case D3DFMT_L16:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_UNORM_INT16;
break;
case D3DFMT_A8:
imgFormat.image_channel_order = CL_A;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case D3DFMT_L8:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case D3DFMT_G32R32F:
imgFormat.image_channel_order = CL_RG;
imgFormat.image_channel_data_type = CL_FLOAT;
break;
case D3DFMT_G16R16F:
imgFormat.image_channel_order = CL_RG;
imgFormat.image_channel_data_type = CL_HALF_FLOAT;
break;
case D3DFMT_G16R16:
imgFormat.image_channel_order = CL_RG;
imgFormat.image_channel_data_type = CL_UNORM_INT16;
break;
case D3DFMT_A8L8:
imgFormat.image_channel_order = CL_RG;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case D3DFMT_A32B32G32R32F:
imgFormat.image_channel_order = CL_RGBA;
imgFormat.image_channel_data_type = CL_FLOAT;
break;
case D3DFMT_A16B16G16R16F:
imgFormat.image_channel_order = CL_RGBA;
imgFormat.image_channel_data_type = CL_HALF_FLOAT;
break;
case D3DFMT_A16B16G16R16:
imgFormat.image_channel_order = CL_RGBA;
imgFormat.image_channel_data_type = CL_UNORM_INT16;
break;
case D3DFMT_A8B8G8R8:
case D3DFMT_X8B8G8R8:
imgFormat.image_channel_order = CL_RGBA;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
imgFormat.image_channel_order = CL_BGRA;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2'):
switch (plane) {
case 0:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
oclPlane = OCLPlane::PLANE_Y;
break;
case 1:
imgFormat.image_channel_order = CL_RG;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
oclPlane = OCLPlane::PLANE_UV;
break;
default:
imgFormat.image_channel_order = 0;
imgFormat.image_channel_data_type = 0;
return CL_INVALID_VALUE;
}
noPlaneRequired = false;
break;
case (D3DFORMAT)MAKEFOURCC('Y', 'V', '1', '2'):
switch (plane) {
case 0:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
oclPlane = OCLPlane::PLANE_Y;
break;
case 1:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
oclPlane = OCLPlane::PLANE_V;
break;
case 2:
imgFormat.image_channel_order = CL_R;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
oclPlane = OCLPlane::PLANE_U;
break;
default:
imgFormat.image_channel_order = 0;
imgFormat.image_channel_data_type = 0;
return CL_INVALID_VALUE;
}
noPlaneRequired = false;
break;
case D3DFMT_YUY2:
imgFormat.image_channel_order = CL_YUYV_INTEL;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case D3DFMT_UYVY:
imgFormat.image_channel_order = CL_UYVY_INTEL;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case (D3DFORMAT)MAKEFOURCC('Y', 'V', 'Y', 'U'):
imgFormat.image_channel_order = CL_YVYU_INTEL;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
case (D3DFORMAT)MAKEFOURCC('V', 'Y', 'U', 'Y'):
imgFormat.image_channel_order = CL_VYUY_INTEL;
imgFormat.image_channel_data_type = CL_UNORM_INT8;
break;
default:
imgFormat.image_channel_order = 0;
imgFormat.image_channel_data_type = 0;
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
}
if (noPlaneRequired && plane > 0) {
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/d3d/d3d_sharing.h"
struct ErrorCodeHelper;
namespace OCLRT {
class Image;
class Context;
enum OCLPlane;
class D3DSurface : public D3DSharing<D3DTypesHelper::D3D9> {
typedef typename D3DTypesHelper::D3D9::D3DTexture2dDesc D3D9SurfaceDesc;
typedef typename D3DTypesHelper::D3D9::D3DTexture2d D3D9Surface;
typedef typename D3DTypesHelper::D3D9::D3DResource D3DResource;
typedef typename D3DTypesHelper::D3D9::D3DDevice D3DDevice;
public:
static Image *create(Context *context, cl_dx9_surface_info_khr *surfaceInfo, cl_mem_flags flags,
cl_dx9_media_adapter_type_khr adapterType, cl_uint plane, cl_int *retCode);
static cl_int findImgFormat(D3DFORMAT d3dFormat, cl_image_format &imgFormat, cl_uint plane, OCLPlane &oclPlane);
void synchronizeObject(UpdateData *updateData) override;
void releaseResource(MemObj *memObject) override;
cl_dx9_surface_info_khr &getSurfaceInfo() { return surfaceInfo; }
cl_dx9_media_adapter_type_khr &getAdapterType() { return adapterType; }
cl_uint &getPlane() { return plane; }
~D3DSurface() override = default;
const bool lockable = false;
protected:
D3DSurface(Context *context, cl_dx9_surface_info_khr *surfaceInfo, D3D9Surface *surfaceStaging, cl_uint plane,
OCLPlane oclPlane, cl_dx9_media_adapter_type_khr adapterType, bool sharedResource, bool lockable);
cl_dx9_media_adapter_type_khr adapterType = 0u;
cl_dx9_surface_info_khr surfaceInfo = {};
cl_uint plane = 0;
OCLPlane oclPlane;
D3D9Surface *d3d9Surface = nullptr;
D3D9Surface *d3d9SurfaceStaging = nullptr;
D3DDevice *resourceDevice = nullptr;
};
} // namespace OCLRT

View File

@ -0,0 +1,163 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/gmm_helper/resource_info.h"
#include "runtime/helpers/get_info.h"
#include "runtime/mem_obj/image.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/sharings/d3d/d3d_texture.h"
using namespace OCLRT;
template class D3DTexture<D3DTypesHelper::D3D10>;
template class D3DTexture<D3DTypesHelper::D3D11>;
template <typename D3D>
Image *D3DTexture<D3D>::create2d(Context *context, D3DTexture2d *d3dTexture, cl_mem_flags flags, cl_uint subresource, cl_int *retCode) {
ErrorCodeHelper err(retCode, CL_SUCCESS);
auto sharingFcns = context->getSharing<D3DSharingFunctions<D3D>>();
OCLPlane oclPlane = OCLPlane::NO_PLANE;
void *sharedHandle = nullptr;
cl_uint arrayIndex = 0u;
cl_image_desc imgDesc = {};
cl_image_format imgFormat = {};
McsSurfaceInfo mcsSurfaceInfo = {};
ImageInfo imgInfo = {};
imgInfo.imgDesc = &imgDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
D3DTexture2dDesc textureDesc = {};
sharingFcns->getTexture2dDesc(&textureDesc, d3dTexture);
if (textureDesc.Format == DXGI_FORMAT_NV12) {
if ((subresource % 2) == 0) {
oclPlane = OCLPlane::PLANE_Y;
} else {
oclPlane = OCLPlane::PLANE_UV;
}
imgInfo.plane = Gmm::convertPlane(oclPlane);
arrayIndex = subresource / 2u;
} else if (subresource >= textureDesc.MipLevels * textureDesc.ArraySize) {
err.set(CL_INVALID_VALUE);
return nullptr;
}
bool sharedResource = false;
D3DTexture2d *textureStaging = nullptr;
if ((textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED ||
textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_KEYEDMUTEX) &&
subresource % textureDesc.MipLevels == 0) {
textureStaging = d3dTexture;
sharedResource = true;
} else {
sharingFcns->createTexture2d(&textureStaging, &textureDesc, subresource);
}
GraphicsAllocation *alloc = nullptr;
if (textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_NTHANDLE) {
sharingFcns->getSharedNTHandle(textureStaging, &sharedHandle);
alloc = context->getMemoryManager()->createGraphicsAllocationFromNTHandle(sharedHandle);
} else {
sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), false);
}
DEBUG_BREAK_IF(!alloc);
updateImgInfo(alloc->gmm, imgInfo, imgDesc, oclPlane, arrayIndex);
auto d3dTextureObj = new D3DTexture<D3D>(context, d3dTexture, subresource, textureStaging, sharedResource);
if (textureDesc.Format == DXGI_FORMAT_NV12) {
imgInfo.surfaceFormat = findYuvSurfaceFormatInfo(textureDesc.Format, oclPlane, flags);
} else {
imgInfo.surfaceFormat = findSurfaceFormatInfo(alloc->gmm->gmmResourceInfo->getResourceFormat(), flags);
}
return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
}
template <typename D3D>
Image *D3DTexture<D3D>::create3d(Context *context, D3DTexture3d *d3dTexture, cl_mem_flags flags, cl_uint subresource, cl_int *retCode) {
ErrorCodeHelper err(retCode, CL_SUCCESS);
auto sharingFcns = context->getSharing<D3DSharingFunctions<D3D>>();
void *sharedHandle = nullptr;
cl_image_desc imgDesc = {};
cl_image_format imgFormat = {};
McsSurfaceInfo mcsSurfaceInfo = {};
ImageInfo imgInfo = {};
imgInfo.imgDesc = &imgDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
D3DTexture3dDesc textureDesc = {};
sharingFcns->getTexture3dDesc(&textureDesc, d3dTexture);
if (subresource >= textureDesc.MipLevels) {
err.set(CL_INVALID_VALUE);
return nullptr;
}
bool sharedResource = false;
D3DTexture3d *textureStaging = nullptr;
if ((textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED || textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_KEYEDMUTEX) &&
subresource == 0) {
textureStaging = d3dTexture;
sharedResource = true;
} else {
sharingFcns->createTexture3d(&textureStaging, &textureDesc, subresource);
}
GraphicsAllocation *alloc = nullptr;
if (textureDesc.MiscFlags & D3DResourceFlags::MISC_SHARED_NTHANDLE) {
sharingFcns->getSharedNTHandle(textureStaging, &sharedHandle);
alloc = context->getMemoryManager()->createGraphicsAllocationFromNTHandle(sharedHandle);
} else {
sharingFcns->getSharedHandle(textureStaging, &sharedHandle);
alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)sharedHandle), false);
}
DEBUG_BREAK_IF(!alloc);
updateImgInfo(alloc->gmm, imgInfo, imgDesc, OCLPlane::NO_PLANE, 0u);
auto d3dTextureObj = new D3DTexture<D3D>(context, d3dTexture, subresource, textureStaging, sharedResource);
imgInfo.qPitch = alloc->gmm->queryQPitch(context->getDevice(0)->getHardwareInfo().pPlatform->eRenderCoreFamily, GMM_RESOURCE_TYPE::RESOURCE_3D);
imgInfo.surfaceFormat = findSurfaceFormatInfo(alloc->gmm->gmmResourceInfo->getResourceFormat(), flags);
return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
}
template <typename D3D>
const SurfaceFormatInfo *D3DTexture<D3D>::findYuvSurfaceFormatInfo(DXGI_FORMAT dxgiFormat, OCLPlane oclPlane, cl_mem_flags flags) {
cl_image_format imgFormat = {};
if (oclPlane == OCLPlane::PLANE_Y) {
imgFormat.image_channel_order = CL_R;
} else {
imgFormat.image_channel_order = CL_RG;
}
imgFormat.image_channel_data_type = CL_UNORM_INT8;
return Image::getSurfaceFormatFromTable(flags, &imgFormat);
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/d3d/d3d_sharing.h"
namespace OCLRT {
class Context;
class Image;
template <typename D3D>
class D3DTexture : public D3DSharing<D3D> {
typedef typename D3D::D3DTexture2dDesc D3DTexture2dDesc;
typedef typename D3D::D3DTexture3dDesc D3DTexture3dDesc;
typedef typename D3D::D3DTexture2d D3DTexture2d;
typedef typename D3D::D3DTexture3d D3DTexture3d;
typedef typename D3D::D3DResource D3DResource;
public:
~D3DTexture() override = default;
static Image *create2d(Context *context, D3DTexture2d *d3dTexture, cl_mem_flags flags, cl_uint subresource, cl_int *retCode);
static Image *create3d(Context *context, D3DTexture3d *d3dTexture, cl_mem_flags flags, cl_uint subresource, cl_int *retCode);
static const SurfaceFormatInfo *findYuvSurfaceFormatInfo(DXGI_FORMAT dxgiFormat, OCLPlane oclPlane, cl_mem_flags flags);
protected:
D3DTexture(Context *context, D3DResource *d3dTexture, cl_uint subresource, D3DResource *textureStaging, bool sharedResource)
: D3DSharing(context, d3dTexture, textureStaging, subresource, sharedResource){};
};
} // namespace OCLRT

View File

@ -0,0 +1,175 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef WIN32
#include "runtime/api/api.h"
#include "runtime/context/context.h"
#include "runtime/context/context.inl"
#include "runtime/os_interface/windows/d3d_sharing_functions.h"
#include "runtime/sharings/d3d/cl_d3d_api.h"
#include "runtime/sharings/d3d/enable_d3d.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/sharings/sharing_factory.inl"
#include <memory>
namespace OCLRT {
bool D3DSharingContextBuilder<D3DTypesHelper::D3D9>::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) {
if (contextData.get() == nullptr) {
contextData.reset(new D3DCreateContextProperties<D3DTypesHelper::D3D9>);
}
bool res = false;
switch (propertyType) {
case CL_CONTEXT_ADAPTER_D3D9_KHR:
case CL_CONTEXT_ADAPTER_D3D9EX_KHR:
case CL_CONTEXT_ADAPTER_DXVA_KHR:
case CL_CONTEXT_D3D9_DEVICE_INTEL:
case CL_CONTEXT_D3D9EX_DEVICE_INTEL:
case CL_CONTEXT_DXVA_DEVICE_INTEL:
contextData->pDevice = (D3DTypesHelper::D3D9::D3DDevice *)propertyValue;
contextData->argumentsDefined = true;
res = true;
break;
}
return res;
}
bool D3DSharingContextBuilder<D3DTypesHelper::D3D10>::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) {
if (contextData.get() == nullptr) {
contextData.reset(new D3DCreateContextProperties<D3DTypesHelper::D3D10>);
}
bool res = false;
switch (propertyType) {
case CL_CONTEXT_D3D10_DEVICE_KHR:
contextData->pDevice = (D3DTypesHelper::D3D10::D3DDevice *)propertyValue;
contextData->argumentsDefined = true;
res = true;
break;
}
return res;
}
bool D3DSharingContextBuilder<D3DTypesHelper::D3D11>::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) {
if (contextData.get() == nullptr) {
contextData.reset(new D3DCreateContextProperties<D3DTypesHelper::D3D11>);
}
bool res = false;
switch (propertyType) {
case CL_CONTEXT_D3D11_DEVICE_KHR:
contextData->pDevice = (D3DTypesHelper::D3D11::D3DDevice *)propertyValue;
contextData->argumentsDefined = true;
res = true;
break;
}
return res;
}
template <>
void Context::registerSharing(D3DSharingFunctions<D3DTypesHelper::D3D10> *sharing) {
this->sharingFunctions[D3DSharingFunctions<D3DTypesHelper::D3D10>::sharingId].reset(sharing);
this->preferD3dSharedResources = 1u;
}
template <>
void Context::registerSharing(D3DSharingFunctions<D3DTypesHelper::D3D11> *sharing) {
this->sharingFunctions[D3DSharingFunctions<D3DTypesHelper::D3D11>::sharingId].reset(sharing);
this->preferD3dSharedResources = 1u;
}
template <typename D3D>
bool D3DSharingContextBuilder<D3D>::finalizeProperties(Context &context, int32_t &errcodeRet) {
if (contextData.get() == nullptr)
return true;
if (contextData->argumentsDefined) {
context.registerSharing(new D3DSharingFunctions<D3D>(contextData->pDevice));
}
return true;
}
template <typename D3D>
std::unique_ptr<SharingContextBuilder> D3DSharingBuilderFactory<D3D>::createContextBuilder() {
return std::unique_ptr<SharingContextBuilder>(new D3DSharingContextBuilder<D3D>());
};
std::string D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::getExtensions() {
return "cl_intel_dx9_media_sharing cl_khr_dx9_media_sharing ";
}
std::string D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::getExtensions() {
return "cl_khr_d3d10_sharing cl_khr_d3d11_sharing ";
}
std::string D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::getExtensions() {
return "cl_intel_d3d11_nv12_media_sharing ";
}
void D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::fillGlobalDispatchTable() {
icdGlobalDispatchTable.clGetDeviceIDsFromDX9MediaAdapterKHR = clGetDeviceIDsFromDX9MediaAdapterKHR;
icdGlobalDispatchTable.clCreateFromDX9MediaSurfaceKHR = clCreateFromDX9MediaSurfaceKHR;
icdGlobalDispatchTable.clEnqueueReleaseDX9MediaSurfacesKHR = clEnqueueReleaseDX9MediaSurfacesKHR;
icdGlobalDispatchTable.clEnqueueAcquireDX9MediaSurfacesKHR = clEnqueueAcquireDX9MediaSurfacesKHR;
crtGlobalDispatchTable.clGetDeviceIDsFromDX9INTEL = clGetDeviceIDsFromDX9INTEL;
crtGlobalDispatchTable.clCreateFromDX9MediaSurfaceINTEL = clCreateFromDX9MediaSurfaceINTEL;
crtGlobalDispatchTable.clEnqueueAcquireDX9ObjectsINTEL = clEnqueueAcquireDX9ObjectsINTEL;
crtGlobalDispatchTable.clEnqueueReleaseDX9ObjectsINTEL = clEnqueueReleaseDX9ObjectsINTEL;
}
void D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::fillGlobalDispatchTable() {
icdGlobalDispatchTable.clCreateFromD3D10BufferKHR = clCreateFromD3D10BufferKHR;
icdGlobalDispatchTable.clCreateFromD3D10Texture2DKHR = clCreateFromD3D10Texture2DKHR;
icdGlobalDispatchTable.clCreateFromD3D10Texture3DKHR = clCreateFromD3D10Texture3DKHR;
icdGlobalDispatchTable.clEnqueueAcquireD3D10ObjectsKHR = clEnqueueAcquireD3D10ObjectsKHR;
icdGlobalDispatchTable.clEnqueueReleaseD3D10ObjectsKHR = clEnqueueReleaseD3D10ObjectsKHR;
icdGlobalDispatchTable.clGetDeviceIDsFromD3D10KHR = clGetDeviceIDsFromD3D10KHR;
}
void D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::fillGlobalDispatchTable() {
icdGlobalDispatchTable.clCreateFromD3D11BufferKHR = clCreateFromD3D11BufferKHR;
icdGlobalDispatchTable.clCreateFromD3D11Texture2DKHR = clCreateFromD3D11Texture2DKHR;
icdGlobalDispatchTable.clCreateFromD3D11Texture3DKHR = clCreateFromD3D11Texture3DKHR;
icdGlobalDispatchTable.clEnqueueAcquireD3D11ObjectsKHR = clEnqueueAcquireD3D11ObjectsKHR;
icdGlobalDispatchTable.clEnqueueReleaseD3D11ObjectsKHR = clEnqueueReleaseD3D11ObjectsKHR;
icdGlobalDispatchTable.clGetDeviceIDsFromD3D11KHR = clGetDeviceIDsFromD3D11KHR;
}
void *D3DSharingBuilderFactory<D3DTypesHelper::D3D9>::getExtensionFunctionAddress(const std::string &functionName) {
return nullptr;
}
void *D3DSharingBuilderFactory<D3DTypesHelper::D3D10>::getExtensionFunctionAddress(const std::string &functionName) {
return nullptr;
}
void *D3DSharingBuilderFactory<D3DTypesHelper::D3D11>::getExtensionFunctionAddress(const std::string &functionName) {
return nullptr;
}
static SharingFactory::RegisterSharing<D3DSharingBuilderFactory<D3DTypesHelper::D3D9>, D3DSharingFunctions<D3DTypesHelper::D3D9>> D3D9Sharing;
static SharingFactory::RegisterSharing<D3DSharingBuilderFactory<D3DTypesHelper::D3D10>, D3DSharingFunctions<D3DTypesHelper::D3D10>> D3D10Sharing;
static SharingFactory::RegisterSharing<D3DSharingBuilderFactory<D3DTypesHelper::D3D11>, D3DSharingFunctions<D3DTypesHelper::D3D11>> D3D11Sharing;
}
#endif

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/sharing_factory.h"
#include <memory>
namespace OCLRT {
class Context;
template <typename D3D>
struct D3DCreateContextProperties {
typename D3D::D3DDevice *pDevice = nullptr;
bool argumentsDefined = false;
};
template <typename D3D>
class D3DSharingContextBuilder : public SharingContextBuilder {
protected:
std::unique_ptr<D3DCreateContextProperties<D3D>> contextData;
public:
bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) override;
bool finalizeProperties(Context &context, int32_t &errcodeRet) override;
};
template <typename D3D>
class D3DSharingBuilderFactory : public SharingBuilderFactory {
public:
std::unique_ptr<SharingContextBuilder> createContextBuilder() override;
std::string getExtensions() override;
void fillGlobalDispatchTable() override;
void *getExtensionFunctionAddress(const std::string &functionName) override;
};
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "CL/cl.h"
#include "runtime/mem_obj/mem_obj.h"
#include "sharing.h"
#include <memory>
namespace OCLRT {
void SharingHandler::acquire(MemObj *memObj) {
if (acquireCount == 0) {
UpdateData updateData;
auto currentSharedHandle = memObj->getGraphicsAllocation()->peekSharedHandle();
updateData.sharedHandle = currentSharedHandle;
updateData.memObject = memObj;
synchronizeHandler(&updateData);
DEBUG_BREAK_IF(updateData.synchronizationStatus != SynchronizeStatus::ACQUIRE_SUCCESFUL);
DEBUG_BREAK_IF(currentSharedHandle != updateData.sharedHandle);
}
acquireCount++;
}
void SharingHandler::synchronizeHandler(UpdateData *updateData) {
synchronizeObject(updateData);
}
void SharingHandler::release(MemObj *memObject) {
DEBUG_BREAK_IF(acquireCount <= 0);
acquireCount--;
if (acquireCount == 0) {
releaseResource(memObject);
}
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/memory_manager/graphics_allocation.h"
namespace OCLRT {
class Context;
class MemObj;
enum SynchronizeStatus {
SHARED_OBJECT_NOT_CHANGED,
SHARED_OBJECT_REQUIRES_UPDATE,
ACQUIRE_SUCCESFUL,
SYNCHRONIZE_ERROR
};
struct UpdateData {
SynchronizeStatus synchronizationStatus;
osHandle sharedHandle;
MemObj *memObject = nullptr;
void *updateData = nullptr;
};
class SharingFunctions {
public:
virtual uint32_t getId() const = 0;
virtual ~SharingFunctions() = default;
};
class SharingHandler {
public:
void acquire(MemObj *memObj);
void release(MemObj *memObject);
virtual ~SharingHandler() = default;
virtual void getMemObjectInfo(size_t &paramValueSize, void *&paramValue){};
protected:
virtual void synchronizeHandler(UpdateData *updateData);
virtual void synchronizeObject(UpdateData *updateData) { updateData->synchronizationStatus = SYNCHRONIZE_ERROR; }
virtual void releaseResource(MemObj *memObject){};
unsigned int acquireCount = 0u;
};
} // namespace OCLRT

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "sharing_factory.h"
namespace OCLRT {
std::unique_ptr<SharingFactory> SharingFactory::build() {
std::unique_ptr<SharingFactory> res(new SharingFactory());
for (auto &builder : sharingContextBuilder) {
if (builder == nullptr)
continue;
res->sharings.push_back(builder->createContextBuilder());
}
return res;
}
std::string SharingFactory::getExtensions() {
std::string res;
for (auto &builder : sharingContextBuilder) {
if (builder == nullptr)
continue;
res += builder->getExtensions();
}
return res;
}
void SharingFactory::fillGlobalDispatchTable() {
for (auto &builder : sharingContextBuilder) {
if (builder == nullptr)
continue;
builder->fillGlobalDispatchTable();
}
}
void *SharingFactory::getExtensionFunctionAddress(const std::string &functionName) {
for (auto &builder : sharingContextBuilder) {
if (builder == nullptr)
continue;
auto ret = builder->getExtensionFunctionAddress(functionName);
if (ret != nullptr)
return ret;
}
return nullptr;
}
bool SharingFactory::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) {
for (auto &sharing : sharings) {
if (sharing->processProperties(propertyType, propertyValue, errcodeRet))
return true;
}
return false;
}
bool SharingFactory::finalizeProperties(Context &context, int32_t &errcodeRet) {
for (auto &sharing : sharings) {
if (!sharing->finalizeProperties(context, errcodeRet))
return false;
}
return true;
}
SharingBuilderFactory *SharingFactory::sharingContextBuilder[SharingType::MAX_SHARING_VALUE] = {
nullptr,
};
SharingFactory sharingFactory;
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "config.h"
#include "CL/cl.h"
#include <memory>
#include <string>
#include <vector>
namespace OCLRT {
class Context;
enum SharingType {
CLGL_SHARING = 0,
VA_SHARING = 1,
D3D9_SHARING = 2,
D3D10_SHARING = 3,
D3D11_SHARING = 4,
MAX_SHARING_VALUE = 5
};
class SharingContextBuilder {
public:
virtual ~SharingContextBuilder() = default;
virtual bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) = 0;
virtual bool finalizeProperties(Context &context, int32_t &errcodeRet) = 0;
};
class SharingBuilderFactory {
public:
virtual std::unique_ptr<SharingContextBuilder> createContextBuilder() = 0;
virtual std::string getExtensions() = 0;
virtual void fillGlobalDispatchTable() = 0;
virtual void *getExtensionFunctionAddress(const std::string &functionName) = 0;
};
class SharingFactory {
protected:
static SharingBuilderFactory *sharingContextBuilder[SharingType::MAX_SHARING_VALUE];
std::vector<std::unique_ptr<SharingContextBuilder>> sharings;
public:
template <typename F, typename T>
class RegisterSharing {
public:
RegisterSharing();
};
static std::unique_ptr<SharingFactory> build();
bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet);
bool finalizeProperties(Context &context, int32_t &errcodeRet);
std::string getExtensions();
void fillGlobalDispatchTable();
void *getExtensionFunctionAddress(const std::string &functionName);
};
extern SharingFactory sharingFactory;
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/sharing_factory.h"
namespace OCLRT {
template <typename F, typename T>
SharingFactory::RegisterSharing<F, T>::RegisterSharing() {
sharingContextBuilder[T::sharingId] = new F;
};
}

View File

@ -0,0 +1,36 @@
# Copyright (c) 2017, Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
if(LIBVA_FOUND)
list (APPEND RUNTIME_SRCS_SHARINGS
${CMAKE_CURRENT_SOURCE_DIR}/cl_va_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing.h
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_defines.h
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_functions.h
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_functions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/va_surface.h
${CMAKE_CURRENT_SOURCE_DIR}/va_surface.cpp
)
set(RUNTIME_SRCS_SHARINGS "${RUNTIME_SRCS_SHARINGS}" PARENT_SCOPE)
endif(LIBVA_FOUND)

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "runtime/api/api.h"
#include "CL/cl.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/context/context.h"
#include "runtime/helpers/get_info.h"
#include "runtime/sharings/va/va_sharing.h"
#include "runtime/sharings/va/va_surface.h"
#include <cstring>
using namespace OCLRT;
cl_mem CL_API_CALL
clCreateFromVA_APIMediaSurfaceINTEL(cl_context context, cl_mem_flags flags, VASurfaceID *surface,
cl_uint plane, cl_int *errcodeRet) {
Context *pContext = nullptr;
auto returnCode = validateObject(WithCastToInternal(context, &pContext));
ErrorCodeHelper err(errcodeRet, returnCode);
if (returnCode != CL_SUCCESS) {
return nullptr;
}
return VASurface::createSharedVaSurface(pContext, pContext->getSharing<VASharingFunctions>(), flags, surface, plane, errcodeRet);
}
cl_int CL_API_CALL
clEnqueueAcquireVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) {
CommandQueue *pCommandQueue = nullptr;
auto status = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue));
if (status == CL_SUCCESS) {
status = pCommandQueue->enqueueAcquireSharedObjects(numObjects, memObjects, numEventsInWaitList,
eventWaitList, event, CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL);
}
return status;
}
cl_int CL_API_CALL
clEnqueueReleaseVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue,
cl_uint numObjects,
const cl_mem *memObjects,
cl_uint numEventsInWaitList,
const cl_event *eventWaitList,
cl_event *event) {
CommandQueue *pCommandQueue = nullptr;
auto status = validateObjects(WithCastToInternal(commandQueue, &pCommandQueue));
if (status == CL_SUCCESS) {
status = pCommandQueue->enqueueReleaseSharedObjects(numObjects, memObjects, numEventsInWaitList,
eventWaitList, event, CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL);
}
return status;
}

View File

@ -0,0 +1,99 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef LIBVA
#include "runtime/api/api.h"
#include "runtime/context/context.h"
#include "runtime/context/context.inl"
#include "runtime/sharings/va/enable_va.h"
#include "runtime/sharings/va/va_sharing.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/sharings/sharing_factory.inl"
#include <memory>
namespace OCLRT {
bool VaSharingContextBuilder::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) {
if (contextData.get() == nullptr) {
contextData.reset(new VaCreateContextProperties);
}
bool res = false;
switch (propertyType) {
case CL_CONTEXT_VA_API_DISPLAY_INTEL:
contextData->vaDisplay = (VADisplay)propertyValue;
res = true;
break;
}
return res;
}
bool VaSharingContextBuilder::finalizeProperties(Context &context, int32_t &errcodeRet) {
if (contextData.get() == nullptr)
return true;
if (contextData->vaDisplay) {
context.registerSharing(new VASharingFunctions(contextData->vaDisplay));
if (!context.getSharing<VASharingFunctions>()->isValidVaDisplay()) {
errcodeRet = CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL;
return false;
}
}
return true;
}
std::unique_ptr<SharingContextBuilder> VaSharingBuilderFactory::createContextBuilder() {
return std::unique_ptr<SharingContextBuilder>(new VaSharingContextBuilder());
};
std::string VaSharingBuilderFactory::getExtensions() {
if (VASharingFunctions::isVaLibraryAvailable()) {
return "cl_intel_va_api_media_sharing ";
}
return "";
}
void VaSharingBuilderFactory::fillGlobalDispatchTable() {
crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL = clCreateFromVA_APIMediaSurfaceINTEL;
crtGlobalDispatchTable.clEnqueueReleaseVA_APIMediaSurfacesINTEL = clEnqueueReleaseVA_APIMediaSurfacesINTEL;
crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL = clEnqueueAcquireVA_APIMediaSurfacesINTEL;
}
#define RETURN_FUNC_PTR_IF_EXIST(name) \
{ \
if (functionName == #name) { \
return ((void *)(name)); \
} \
}
void *VaSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) {
RETURN_FUNC_PTR_IF_EXIST(clCreateFromVA_APIMediaSurfaceINTEL);
RETURN_FUNC_PTR_IF_EXIST(clEnqueueAcquireVA_APIMediaSurfacesINTEL);
RETURN_FUNC_PTR_IF_EXIST(clEnqueueReleaseVA_APIMediaSurfacesINTEL);
return nullptr;
}
static SharingFactory::RegisterSharing<VaSharingBuilderFactory, VASharingFunctions> vaSharing;
}
#endif

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/sharing_factory.h"
#include "runtime/sharings/va/va_sharing_defines.h"
#include <memory>
namespace OCLRT {
class Context;
struct VaCreateContextProperties {
VADisplay vaDisplay = nullptr;
};
class VaSharingContextBuilder : public SharingContextBuilder {
protected:
std::unique_ptr<VaCreateContextProperties> contextData;
public:
bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue, cl_int &errcodeRet) override;
bool finalizeProperties(Context &context, int32_t &errcodeRet) override;
};
class VaSharingBuilderFactory : public SharingBuilderFactory {
public:
std::unique_ptr<SharingContextBuilder> createContextBuilder() override;
std::string getExtensions() override;
void fillGlobalDispatchTable() override;
void *getExtensionFunctionAddress(const std::string &functionName) override;
};
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/context/context.h"
#include "runtime/sharings/sharing_factory.h"
#include "runtime/sharings/va/va_sharing_defines.h"
#include "runtime/sharings/va/va_sharing_functions.h"
namespace OCLRT {
const uint32_t VASharingFunctions::sharingId = SharingType::VA_SHARING;
template <>
VASharingFunctions *Context::getSharing() {
if (VASharingFunctions::sharingId >= sharingFunctions.size()) {
DEBUG_BREAK_IF(VASharingFunctions::sharingId >= sharingFunctions.size());
return nullptr;
}
return reinterpret_cast<VASharingFunctions *>(sharingFunctions[VASharingFunctions::sharingId].get());
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/api/cl_types.h"
#include "runtime/sharings/sharing.h"
#include "runtime/sharings/va/va_sharing_defines.h"
#include "runtime/sharings/va/va_sharing_functions.h"
namespace OCLRT {
class VASharing : public SharingHandler {
public:
VASharing(VASharingFunctions *sharingFunctions, VAImageID imageId)
: sharingFunctions(sharingFunctions), imageId(imageId){};
VASharingFunctions *peekFunctionsHandler() { return sharingFunctions; }
protected:
VASharingFunctions *sharingFunctions = nullptr;
VAImageID imageId;
};
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "CL/cl.h"
#include "CL/cl_va_api_media_sharing_intel.h"
typedef int (*VADisplayIsValidPFN)(VADisplay vaDisplay);
typedef VAStatus (*VADeriveImagePFN)(VADisplay vaDisplay, VASurfaceID vaSurface, VAImage *vaImage);
typedef VAStatus (*VADestroyImagePFN)(VADisplay vaDisplay, VAImageID vaImageId);
typedef VAStatus (*VAExtGetSurfaceHandlePFN)(VADisplay vaDisplay, VASurfaceID *vaSurface, unsigned int *handleId);
typedef VAStatus (*VASyncSurfacePFN)(VADisplay vaDisplay, VASurfaceID vaSurface);
typedef VAPrivFunc (*VAGetLibFuncPFN)(VADisplay vaDisplay, const char *func);

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/debug_settings_manager.h"
#include "va_sharing_functions.h"
#include <dlfcn.h>
namespace Os {
extern const char *libvaDllName;
}
namespace OCLRT {
std::function<void *(const char *, int)> VASharingFunctions::fdlopen = dlopen;
std::function<void *(void *handle, const char *symbol)> VASharingFunctions::fdlsym = dlsym;
std::function<int(void *handle)> VASharingFunctions::fdlclose = dlclose;
VASharingFunctions::VASharingFunctions(VADisplay vaDisplay) : vaDisplay(vaDisplay) {
initFunctions();
};
VASharingFunctions::~VASharingFunctions() {
if (libHandle != nullptr) {
fdlclose(libHandle);
libHandle = nullptr;
}
}
bool VASharingFunctions::isVaLibraryAvailable() {
auto lib = fdlopen(Os::libvaDllName, RTLD_LAZY);
if (lib) {
fdlclose(lib);
return true;
}
return false;
}
void VASharingFunctions::initFunctions() {
if (DebugManager.flags.EnableVaLibCalls.get()) {
libHandle = fdlopen(Os::libvaDllName, RTLD_LAZY);
if (libHandle) {
vaDisplayIsValidPFN = (VADisplayIsValidPFN)fdlsym(libHandle, "vaDisplayIsValid");
vaDeriveImagePFN = (VADeriveImagePFN)fdlsym(libHandle, "vaDeriveImage");
vaDestroyImagePFN = (VADestroyImagePFN)fdlsym(libHandle, "vaDestroyImage");
vaSyncSurfacePFN = (VASyncSurfacePFN)fdlsym(libHandle, "vaSyncSurface");
vaGetLibFuncPFN = (VAGetLibFuncPFN)fdlsym(libHandle, "vaGetLibFunc");
vaExtGetSurfaceHandlePFN = (VAExtGetSurfaceHandlePFN)getLibFunc("DdiMedia_ExtGetSurfaceHandle");
} else {
vaDisplayIsValidPFN = nullptr;
vaDeriveImagePFN = nullptr;
vaDestroyImagePFN = nullptr;
vaSyncSurfacePFN = nullptr;
vaGetLibFuncPFN = nullptr;
vaExtGetSurfaceHandlePFN = nullptr;
}
}
}
}

View File

@ -0,0 +1,83 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/sharing.h"
#include "runtime/sharings/va/va_sharing_defines.h"
#include <functional>
namespace OCLRT {
class VASharingFunctions : public SharingFunctions {
public:
VASharingFunctions(VADisplay vaDisplay);
~VASharingFunctions();
uint32_t getId() const override {
return VASharingFunctions::sharingId;
}
static const uint32_t sharingId;
bool isValidVaDisplay() {
return vaDisplayIsValidPFN(vaDisplay) == 1;
}
VAStatus deriveImage(VASurfaceID vaSurface, VAImage *vaImage) {
return vaDeriveImagePFN(vaDisplay, vaSurface, vaImage);
}
VAStatus destroyImage(VAImageID vaImageId) {
return vaDestroyImagePFN(vaDisplay, vaImageId);
}
VAStatus extGetSurfaceHandle(VASurfaceID *vaSurface, unsigned int *handleId) {
return vaExtGetSurfaceHandlePFN(vaDisplay, vaSurface, handleId);
}
VAStatus syncSurface(VASurfaceID vaSurface) {
return vaSyncSurfacePFN(vaDisplay, vaSurface);
}
VAPrivFunc getLibFunc(const char *func) {
if (vaGetLibFuncPFN) {
return vaGetLibFuncPFN(vaDisplay, func);
}
return nullptr;
}
void initFunctions();
static std::function<void *(const char *, int)> fdlopen;
static std::function<void *(void *handle, const char *symbol)> fdlsym;
static std::function<int(void *handle)> fdlclose;
static bool isVaLibraryAvailable();
protected:
void *libHandle = nullptr;
VADisplay vaDisplay = nullptr;
VADisplayIsValidPFN vaDisplayIsValidPFN = [](VADisplay vaDisplay) { return 0; };
VADeriveImagePFN vaDeriveImagePFN;
VADestroyImagePFN vaDestroyImagePFN;
VASyncSurfacePFN vaSyncSurfacePFN;
VAExtGetSurfaceHandlePFN vaExtGetSurfaceHandlePFN;
VAGetLibFuncPFN vaGetLibFuncPFN;
};
}

View File

@ -0,0 +1,112 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/sharings/va/va_surface.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/mem_obj/image.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/helpers/get_info.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/gmm_helper/gmm_helper.h"
namespace OCLRT {
Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sharingFunctions,
cl_mem_flags flags, VASurfaceID *surface,
cl_uint plane, cl_int *errcodeRet) {
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
const auto &hwInfo = context->getDevice(0)->getHardwareInfo();
auto memoryManager = context->getMemoryManager();
unsigned int sharedHandle = 0;
VAImage vaImage = {};
cl_image_desc imgDesc = {};
cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8};
cl_image_format imgFormat = {};
const SurfaceFormatInfo *gmmSurfaceFormat = nullptr;
const SurfaceFormatInfo *imgSurfaceFormat = nullptr;
ImageInfo imgInfo = {0};
VAImageID imageId = 0;
McsSurfaceInfo mcsSurfaceInfo = {};
sharingFunctions->deriveImage(*surface, &vaImage);
imageId = vaImage.image_id;
imgInfo.imgDesc = &imgDesc;
imgDesc.image_width = vaImage.width;
imgDesc.image_height = vaImage.height;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat);
imgInfo.surfaceFormat = gmmSurfaceFormat;
if (plane == 0) {
imgInfo.plane = GMM_PLANE_Y;
imgFormat = {CL_R, CL_UNORM_INT8};
} else if (plane == 1) {
imgInfo.plane = GMM_PLANE_U;
imgFormat = {CL_RG, CL_UNORM_INT8};
} else {
imgFormat = {CL_NV12_INTEL, CL_UNORM_INT8};
imgInfo.plane = GMM_NO_PLANE;
}
imgSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat);
sharingFunctions->destroyImage(vaImage.image_id);
sharingFunctions->extGetSurfaceHandle(surface, &sharedHandle);
auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, false, true);
Gmm *gmm = Gmm::queryImgParams(imgInfo, hwInfo.pPlatform->eRenderCoreFamily);
DEBUG_BREAK_IF(alloc->gmm != nullptr);
alloc->gmm = gmm;
imgDesc.image_row_pitch = imgInfo.rowPitch;
imgDesc.image_slice_pitch = 0u;
imgInfo.slicePitch = 0u;
imgInfo.surfaceFormat = imgSurfaceFormat;
if (plane == 1) {
imgDesc.image_width /= 2;
imgDesc.image_height /= 2;
}
auto vaSurface = new VASurface(sharingFunctions, imageId, plane, surface, context->getInteropUserSyncEnabled());
auto image = Image::createSharedImage(context, vaSurface, mcsSurfaceInfo, alloc, nullptr, flags, imgInfo, __GMM_NO_CUBE_MAP, 0);
image->setMediaPlaneType(plane);
return image;
}
void VASurface::synchronizeObject(UpdateData *updateData) {
if (!interopUserSync) {
sharingFunctions->syncSurface(*surfaceId);
}
updateData->synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL;
}
void VASurface::getMemObjectInfo(size_t &paramValueSize, void *&paramValue) {
paramValueSize = sizeof(surfaceId);
paramValue = &surfaceId;
}
} // namespace OCLRT

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "runtime/sharings/va/va_sharing.h"
#include "runtime/mem_obj/image.h"
namespace OCLRT {
class Context;
class Image;
class VASurface : VASharing {
public:
static Image *createSharedVaSurface(Context *context, VASharingFunctions *sharingFunctions,
cl_mem_flags flags, VASurfaceID *surface, cl_uint plane,
cl_int *errcodeRet);
void synchronizeObject(UpdateData *updateData) override;
void getMemObjectInfo(size_t &paramValueSize, void *&paramValue) override;
protected:
VASurface(VASharingFunctions *sharingFunctions, VAImageID imageId,
cl_uint plane, VASurfaceID *surfaceId, bool interopUserSync)
: VASharing(sharingFunctions, imageId), plane(plane), surfaceId(surfaceId), interopUserSync(interopUserSync){};
cl_uint plane;
VASurfaceID *surfaceId;
bool interopUserSync;
};
}