| 1 |
/* |
| 2 |
* Copyright (C) 2020-2022 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/source/command_stream/command_stream_receiver.h" |
| 9 |
#include "shared/source/device/device.h" |
| 10 |
#include "shared/source/helpers/get_info.h" |
| 11 |
#include "shared/source/helpers/timestamp_packet.h" |
| 12 |
|
| 13 |
#include "opencl/extensions/public/cl_gl_private_intel.h" |
| 14 |
#include "opencl/source/context/context.h" |
| 15 |
#include "opencl/source/event/async_events_handler.h" |
| 16 |
#include "opencl/source/event/event_builder.h" |
| 17 |
#include "opencl/source/platform/platform.h" |
| 18 |
#include "opencl/source/sharings/gl/gl_context_guard.h" |
| 19 |
#include "opencl/source/sharings/gl/gl_sync_event.h" |
| 20 |
#include "opencl/source/sharings/gl/windows/gl_sharing_windows.h" |
| 21 |
|
| 22 |
namespace NEO { |
| 23 |
GlSyncEvent::GlSyncEvent(Context &context, const GL_CL_SYNC_INFO &sync) |
| 24 |
: Event(&context, nullptr, CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR, CompletionStamp::notReady, CompletionStamp::notReady), |
| 25 |
glSync(std::make_unique<GL_CL_SYNC_INFO>(sync)) { |
| 26 |
transitionExecutionStatus(CL_SUBMITTED); |
| 27 |
} |
| 28 |
|
| 29 |
GlSyncEvent::~GlSyncEvent() { |
| 30 |
ctx->getSharing<GLSharingFunctionsWindows>()->releaseSync(glSync->pSync); |
| 31 |
} |
| 32 |
|
| 33 |
GlSyncEvent *GlSyncEvent::create(Context &context, cl_GLsync sync, cl_int *errCode) { |
| 34 |
GLContextGuard guard(*context.getSharing<GLSharingFunctionsWindows>()); |
| 35 |
|
| 36 |
ErrorCodeHelper err(errCode, CL_SUCCESS); |
| 37 |
GL_CL_SYNC_INFO syncInfo = {sync, nullptr}; |
| 38 |
|
| 39 |
context.getSharing<GLSharingFunctionsWindows>()->retainSync(&syncInfo); |
| 40 |
DEBUG_BREAK_IF(!syncInfo.pSync); |
| 41 |
|
| 42 |
EventBuilder eventBuilder; |
| 43 |
eventBuilder.create<GlSyncEvent>(context, syncInfo); |
| 44 |
return static_cast<GlSyncEvent *>(eventBuilder.finalizeAndRelease()); |
| 45 |
} |
| 46 |
|
| 47 |
void GlSyncEvent::updateExecutionStatus() { |
| 48 |
GLContextGuard guard(*ctx->getSharing<GLSharingFunctionsWindows>()); |
| 49 |
int retVal = 0; |
| 50 |
|
| 51 |
ctx->getSharing<GLSharingFunctionsWindows>()->getSynciv(glSync->pSync, GL_SYNC_STATUS, &retVal); |
| 52 |
if (retVal == GL_SIGNALED) { |
| 53 |
setStatus(CL_COMPLETE); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
TaskCountType GlSyncEvent::getTaskLevel() { |
| 58 |
if (peekExecutionStatus() == CL_COMPLETE) { |
| 59 |
return 0; |
| 60 |
} |
| 61 |
return CompletionStamp::notReady; |
| 62 |
} |
| 63 |
} // namespace NEO |