| 1 |
/* |
| 2 |
* Copyright (C) 2018-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "opencl/source/sharings/va/cl_va_api.h" |
| 9 |
|
| 10 |
#include "shared/source/helpers/get_info.h" |
| 11 |
#include "shared/source/utilities/api_intercept.h" |
| 12 |
|
| 13 |
#include "opencl/source/api/api.h" |
| 14 |
#include "opencl/source/api/api_enter.h" |
| 15 |
#include "opencl/source/cl_device/cl_device.h" |
| 16 |
#include "opencl/source/command_queue/command_queue.h" |
| 17 |
#include "opencl/source/context/context.h" |
| 18 |
#include "opencl/source/helpers/cl_validators.h" |
| 19 |
#include "opencl/source/platform/platform.h" |
| 20 |
#include "opencl/source/sharings/va/va_device.h" |
| 21 |
#include "opencl/source/sharings/va/va_sharing.h" |
| 22 |
#include "opencl/source/sharings/va/va_surface.h" |
| 23 |
#include "opencl/source/utilities/cl_logger.h" |
| 24 |
|
| 25 |
#include "CL/cl.h" |
| 26 |
|
| 27 |
#include <cstring> |
| 28 |
|
| 29 |
using namespace NEO; |
| 30 |
|
| 31 |
cl_mem CL_API_CALL |
| 32 |
clCreateFromVA_APIMediaSurfaceINTEL(cl_context context, cl_mem_flags flags, VASurfaceID *surface, |
| 33 |
cl_uint plane, cl_int *errcodeRet) { |
| 34 |
|
| 35 |
cl_int returnCode = CL_SUCCESS; |
| 36 |
API_ENTER(&returnCode); |
| 37 |
DBG_LOG_INPUTS("context", context, |
| 38 |
"flags", flags, |
| 39 |
"VASurfaceID", surface, |
| 40 |
"plane", plane); |
| 41 |
|
| 42 |
Context *pContext = nullptr; |
| 43 |
cl_mem image = nullptr; |
| 44 |
|
| 45 |
returnCode = validateObject(withCastToInternal(context, &pContext)); |
| 46 |
ErrorCodeHelper err(errcodeRet, returnCode); |
| 47 |
|
| 48 |
if (returnCode != CL_SUCCESS) { |
| 49 |
return nullptr; |
| 50 |
} |
| 51 |
|
| 52 |
if (!VASurface::validate(flags, plane)) { |
| 53 |
returnCode = CL_INVALID_VALUE; |
| 54 |
err.set(returnCode); |
| 55 |
return nullptr; |
| 56 |
} |
| 57 |
|
| 58 |
image = VASurface::createSharedVaSurface(pContext, pContext->getSharing<VASharingFunctions>(), flags, 0, surface, plane, errcodeRet); |
| 59 |
DBG_LOG_INPUTS("image", image); |
| 60 |
return image; |
| 61 |
} |
| 62 |
|
| 63 |
cl_int CL_API_CALL |
| 64 |
clGetDeviceIDsFromVA_APIMediaAdapterINTEL(cl_platform_id platform, cl_va_api_device_source_intel mediaAdapterType, |
| 65 |
void *mediaAdapter, cl_va_api_device_set_intel mediaAdapterSet, cl_uint numEntries, |
| 66 |
cl_device_id *devices, cl_uint *numDevices) { |
| 67 |
cl_int status = CL_SUCCESS; |
| 68 |
API_ENTER(&status); |
| 69 |
DBG_LOG_INPUTS("platform", platform, |
| 70 |
"mediaAdapterType", mediaAdapterType, |
| 71 |
"mediaAdapter", mediaAdapter, |
| 72 |
"mediaAdapterSet", mediaAdapterSet, |
| 73 |
"numEntries", numEntries); |
| 74 |
|
| 75 |
Platform *pPlatform = nullptr; |
| 76 |
status = validateObjects(withCastToInternal(platform, &pPlatform)); |
| 77 |
if (status != CL_SUCCESS) { |
| 78 |
status = CL_INVALID_PLATFORM; |
| 79 |
} else { |
| 80 |
VADevice vaDevice{}; |
| 81 |
cl_device_id device = vaDevice.getDeviceFromVA(pPlatform, mediaAdapter); |
| 82 |
GetInfoHelper::set(devices, device); |
| 83 |
if (device == nullptr) { |
| 84 |
GetInfoHelper::set(numDevices, 0u); |
| 85 |
status = CL_DEVICE_NOT_FOUND; |
| 86 |
} else { |
| 87 |
GetInfoHelper::set(numDevices, 1u); |
| 88 |
} |
| 89 |
} |
| 90 |
return status; |
| 91 |
} |
| 92 |
|
| 93 |
cl_int CL_API_CALL |
| 94 |
clEnqueueAcquireVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue, |
| 95 |
cl_uint numObjects, |
| 96 |
const cl_mem *memObjects, |
| 97 |
cl_uint numEventsInWaitList, |
| 98 |
const cl_event *eventWaitList, |
| 99 |
cl_event *event) { |
| 100 |
cl_int status = CL_SUCCESS; |
| 101 |
API_ENTER(&status); |
| 102 |
DBG_LOG_INPUTS("commandQueue", commandQueue, |
| 103 |
"numObjects", numObjects, |
| 104 |
"memObjects", getClFileLogger().getMemObjects(reinterpret_cast<const uintptr_t *>(memObjects), numObjects), |
| 105 |
"numEventsInWaitList", numEventsInWaitList, |
| 106 |
"eventWaitList", getClFileLogger().getEvents(reinterpret_cast<const uintptr_t *>(eventWaitList), numEventsInWaitList), |
| 107 |
"event", getClFileLogger().getEvents(reinterpret_cast<const uintptr_t *>(event), 1)); |
| 108 |
|
| 109 |
CommandQueue *pCommandQueue = nullptr; |
| 110 |
|
| 111 |
status = validateObjects(withCastToInternal(commandQueue, &pCommandQueue)); |
| 112 |
|
| 113 |
if (status == CL_SUCCESS) { |
| 114 |
status = pCommandQueue->enqueueAcquireSharedObjects(numObjects, memObjects, numEventsInWaitList, |
| 115 |
eventWaitList, event, CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL); |
| 116 |
} |
| 117 |
return status; |
| 118 |
} |
| 119 |
|
| 120 |
cl_int CL_API_CALL |
| 121 |
clEnqueueReleaseVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue, |
| 122 |
cl_uint numObjects, |
| 123 |
const cl_mem *memObjects, |
| 124 |
cl_uint numEventsInWaitList, |
| 125 |
const cl_event *eventWaitList, |
| 126 |
cl_event *event) { |
| 127 |
cl_int status = CL_SUCCESS; |
| 128 |
API_ENTER(&status); |
| 129 |
DBG_LOG_INPUTS("commandQueue", commandQueue, |
| 130 |
"numObjects", numObjects, |
| 131 |
"memObjects", getClFileLogger().getMemObjects(reinterpret_cast<const uintptr_t *>(memObjects), numObjects), |
| 132 |
"numEventsInWaitList", numEventsInWaitList, |
| 133 |
"eventWaitList", getClFileLogger().getEvents(reinterpret_cast<const uintptr_t *>(eventWaitList), numEventsInWaitList), |
| 134 |
"event", getClFileLogger().getEvents(reinterpret_cast<const uintptr_t *>(event), 1)); |
| 135 |
|
| 136 |
CommandQueue *pCommandQueue = nullptr; |
| 137 |
|
| 138 |
status = validateObjects(withCastToInternal(commandQueue, &pCommandQueue)); |
| 139 |
|
| 140 |
if (status == CL_SUCCESS) { |
| 141 |
status = pCommandQueue->enqueueReleaseSharedObjects(numObjects, memObjects, numEventsInWaitList, |
| 142 |
eventWaitList, event, CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL); |
| 143 |
if (!pCommandQueue->getContext().getInteropUserSyncEnabled()) { |
| 144 |
pCommandQueue->finish(); |
| 145 |
} |
| 146 |
} |
| 147 |
return status; |
| 148 |
} |
| 149 |
|
| 150 |
cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL( |
| 151 |
cl_context context, |
| 152 |
cl_mem_flags flags, |
| 153 |
cl_mem_object_type imageType, |
| 154 |
cl_uint plane, |
| 155 |
cl_uint numEntries, |
| 156 |
VAImageFormat *vaApiFormats, |
| 157 |
cl_uint *numImageFormats) { |
| 158 |
|
| 159 |
if (numImageFormats) { |
| 160 |
*numImageFormats = 0; |
| 161 |
} |
| 162 |
|
| 163 |
Context *pContext = castToObjectOrAbort<Context>(context); |
| 164 |
auto pSharing = pContext->getSharing<VASharingFunctions>(); |
| 165 |
if (!pSharing) { |
| 166 |
return CL_INVALID_CONTEXT; |
| 167 |
} |
| 168 |
|
| 169 |
return pSharing->getSupportedFormats(flags, imageType, plane, numEntries, vaApiFormats, numImageFormats); |
| 170 |
} |