| 1 |
/* |
| 2 |
* Copyright (C) 2018-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifdef LIBVA |
| 9 |
|
| 10 |
#include "opencl/source/sharings/va/enable_va.h" |
| 11 |
|
| 12 |
#include "shared/source/os_interface/driver_info.h" |
| 13 |
|
| 14 |
#include "opencl/source/api/api.h" |
| 15 |
#include "opencl/source/context/context.h" |
| 16 |
#include "opencl/source/context/context.inl" |
| 17 |
#include "opencl/source/sharings/sharing_factory.h" |
| 18 |
#include "opencl/source/sharings/sharing_factory.inl" |
| 19 |
#include "opencl/source/sharings/va/cl_va_api.h" |
| 20 |
#include "opencl/source/sharings/va/va_sharing.h" |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
|
| 24 |
namespace NEO { |
| 25 |
|
| 26 |
bool VaSharingContextBuilder::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) { |
| 27 |
if (contextData.get() == nullptr) { |
| 28 |
contextData = std::make_unique<VaCreateContextProperties>(); |
| 29 |
} |
| 30 |
|
| 31 |
switch (propertyType) { |
| 32 |
case CL_CONTEXT_VA_API_DISPLAY_INTEL: |
| 33 |
contextData->vaDisplay = (VADisplay)propertyValue; |
| 34 |
return true; |
| 35 |
} |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
bool VaSharingContextBuilder::finalizeProperties(Context &context, int32_t &errcodeRet) { |
| 40 |
if (contextData.get() == nullptr) |
| 41 |
return true; |
| 42 |
|
| 43 |
if (contextData->vaDisplay) { |
| 44 |
context.registerSharing(new VASharingFunctions(contextData->vaDisplay)); |
| 45 |
if (!context.getSharing<VASharingFunctions>()->isValidVaDisplay()) { |
| 46 |
errcodeRet = CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL; |
| 47 |
return false; |
| 48 |
} |
| 49 |
context.getSharing<VASharingFunctions>()->querySupportedVaImageFormats(contextData->vaDisplay); |
| 50 |
} |
| 51 |
|
| 52 |
return true; |
| 53 |
} |
| 54 |
|
| 55 |
std::unique_ptr<SharingContextBuilder> VaSharingBuilderFactory::createContextBuilder() { |
| 56 |
return std::make_unique<VaSharingContextBuilder>(); |
| 57 |
}; |
| 58 |
|
| 59 |
std::string VaSharingBuilderFactory::getExtensions(DriverInfo *driverInfo) { |
| 60 |
auto imageSupport = driverInfo ? driverInfo->getMediaSharingSupport() : false; |
| 61 |
if (imageSupport && VASharingFunctions::isVaLibraryAvailable()) { |
| 62 |
return "cl_intel_va_api_media_sharing "; |
| 63 |
} |
| 64 |
return ""; |
| 65 |
} |
| 66 |
|
| 67 |
void VaSharingBuilderFactory::fillGlobalDispatchTable() { |
| 68 |
crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL = clCreateFromVA_APIMediaSurfaceINTEL; |
| 69 |
crtGlobalDispatchTable.clGetDeviceIDsFromVA_APIMediaAdapterINTEL = clGetDeviceIDsFromVA_APIMediaAdapterINTEL; |
| 70 |
crtGlobalDispatchTable.clEnqueueReleaseVA_APIMediaSurfacesINTEL = clEnqueueReleaseVA_APIMediaSurfacesINTEL; |
| 71 |
crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL = clEnqueueAcquireVA_APIMediaSurfacesINTEL; |
| 72 |
} |
| 73 |
|
| 74 |
#define RETURN_FUNC_PTR_IF_EXIST(name) \ |
| 75 |
{ \ |
| 76 |
if (functionName == #name) { \ |
| 77 |
return ((void *)(name)); \ |
| 78 |
} \ |
| 79 |
} |
| 80 |
void *VaSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { |
| 81 |
RETURN_FUNC_PTR_IF_EXIST(clCreateFromVA_APIMediaSurfaceINTEL); |
| 82 |
RETURN_FUNC_PTR_IF_EXIST(clGetDeviceIDsFromVA_APIMediaAdapterINTEL); |
| 83 |
RETURN_FUNC_PTR_IF_EXIST(clEnqueueAcquireVA_APIMediaSurfacesINTEL); |
| 84 |
RETURN_FUNC_PTR_IF_EXIST(clEnqueueReleaseVA_APIMediaSurfacesINTEL); |
| 85 |
if (debugManager.flags.EnableFormatQuery.get()) { |
| 86 |
RETURN_FUNC_PTR_IF_EXIST(clGetSupportedVA_APIMediaSurfaceFormatsINTEL); |
| 87 |
} |
| 88 |
auto extraFunction = getExtensionFunctionAddressExtra(functionName); |
| 89 |
return extraFunction; |
| 90 |
} |
| 91 |
|
| 92 |
static SharingFactory::RegisterSharing<VaSharingBuilderFactory, VASharingFunctions> vaSharing; |
| 93 |
} // namespace NEO |
| 94 |
#endif |