Debian Codegraph @

opencl/source/sharings/gl/linux/gl_arb_sync_event_linux.cpp

raw
1 /*
2 * Copyright (C) 2023 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/os_interface/os_interface.h"
11
12 #include "opencl/extensions/public/cl_gl_private_intel.h"
13 #include "opencl/source/command_queue/command_queue.h"
14 #include "opencl/source/context/context.h"
15 #include "opencl/source/helpers/base_object.h"
16 #include "opencl/source/sharings/gl/gl_arb_sync_event.h"
17 #include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
18
19 #include <GL/gl.h>
20
21 namespace NEO {
22
23 void cleanupArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) {}
24
25 bool setupArbSyncObject(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {
26 return false;
27 }
28
29 void signalArbSyncObject(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) {}
30
31 void serverWaitForArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) {}
32
33 GlArbSyncEvent::GlArbSyncEvent(Context &context)
34 : Event(&context, nullptr, CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR, CompletionStamp::notReady, CompletionStamp::notReady),
35 glSyncInfo(std::make_unique<CL_GL_SYNC_INFO>()) {
36 }
37
38 bool GlArbSyncEvent::setBaseEvent(Event &ev) {
39 UNRECOVERABLE_IF(this->baseEvent != nullptr);
40 UNRECOVERABLE_IF(ev.getContext() == nullptr);
41 UNRECOVERABLE_IF(ev.getCommandQueue() == nullptr);
42 auto cmdQueue = ev.getCommandQueue();
43 auto osInterface = cmdQueue->getGpgpuCommandStreamReceiver().getOSInterface();
44 UNRECOVERABLE_IF(osInterface == nullptr);
45 if (false == ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectSetup(*osInterface, *glSyncInfo)) {
46 return false;
47 }
48
49 this->baseEvent = &ev;
50 this->cmdQueue = cmdQueue;
51 this->cmdQueue->incRefInternal();
52 this->baseEvent->incRefInternal();
53 this->osInterface = osInterface;
54 ev.addChild(*this);
55 return true;
56 }
57
58 GlArbSyncEvent::~GlArbSyncEvent() {
59 if (baseEvent != nullptr) {
60 ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectCleanup(*osInterface, glSyncInfo.get());
61 baseEvent->decRefInternal();
62 }
63 }
64
65 GlArbSyncEvent *GlArbSyncEvent::create(Event &baseEvent) {
66 if (baseEvent.getContext() == nullptr) {
67 return nullptr;
68 }
69 auto arbSyncEvent = new GlArbSyncEvent(*baseEvent.getContext());
70 if (false == arbSyncEvent->setBaseEvent(baseEvent)) {
71 delete arbSyncEvent;
72 arbSyncEvent = nullptr;
73 }
74
75 return arbSyncEvent;
76 }
77
78 void GlArbSyncEvent::unblockEventBy(Event &event, TaskCountType taskLevel, int32_t transitionStatus) {
79 DEBUG_BREAK_IF(&event != this->baseEvent);
80 if ((transitionStatus > CL_SUBMITTED) || (transitionStatus < 0)) {
81 return;
82 }
83
84 ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectSignal(event.getCommandQueue()->getGpgpuCommandStreamReceiver().getOsContext(), *glSyncInfo);
85 ctx->getSharing<GLSharingFunctionsLinux>()->glArbSyncObjectWaitServer(*osInterface, *glSyncInfo);
86 }
87 } // namespace NEO
88
89 extern "C" CL_API_ENTRY cl_int CL_API_CALL
90 clEnqueueMarkerWithSyncObjectINTEL(cl_command_queue commandQueue,
91 cl_event *event,
92 cl_context *context) {
93 return CL_INVALID_OPERATION;
94 }
95
96 extern "C" CL_API_ENTRY cl_int CL_API_CALL
97 clGetCLObjectInfoINTEL(cl_mem memObj,
98 void *pResourceInfo) {
99 return CL_INVALID_OPERATION;
100 }
101
102 extern "C" CL_API_ENTRY cl_int CL_API_CALL
103 clGetCLEventInfoINTEL(cl_event event, PCL_GL_SYNC_INFO *pSyncInfoHandleRet, cl_context *pClContextRet) {
104 if ((nullptr == pSyncInfoHandleRet) || (nullptr == pClContextRet)) {
105 return CL_INVALID_ARG_VALUE;
106 }
107
108 auto neoEvent = NEO::castToObject<NEO::Event>(event);
109 if (nullptr == neoEvent) {
110 return CL_INVALID_EVENT;
111 }
112
113 if (neoEvent->getCommandType() != CL_COMMAND_RELEASE_GL_OBJECTS) {
114 *pSyncInfoHandleRet = nullptr;
115 *pClContextRet = static_cast<cl_context>(neoEvent->getContext());
116 return CL_SUCCESS;
117 }
118
119 auto sharing = neoEvent->getContext()->getSharing<NEO::GLSharingFunctionsLinux>();
120 if (sharing == nullptr) {
121 return CL_INVALID_OPERATION;
122 }
123
124 NEO::GlArbSyncEvent *arbSyncEvent = sharing->getOrCreateGlArbSyncEvent(*neoEvent);
125 if (nullptr == arbSyncEvent) {
126 return CL_OUT_OF_RESOURCES;
127 }
128
129 neoEvent->updateExecutionStatus();
130 CL_GL_SYNC_INFO *syncInfo = arbSyncEvent->getSyncInfo();
131 *pSyncInfoHandleRet = syncInfo;
132 *pClContextRet = static_cast<cl_context>(neoEvent->getContext());
133
134 return CL_SUCCESS;
135 }
136
137 extern "C" CL_API_ENTRY cl_int CL_API_CALL
138 clReleaseGlSharedEventINTEL(cl_event event) {
139 auto neoEvent = NEO::castToObject<NEO::Event>(event);
140 if (nullptr == neoEvent) {
141 return CL_INVALID_EVENT;
142 }
143 auto arbSyncEvent = neoEvent->getContext()->getSharing<NEO::GLSharingFunctionsLinux>()->getGlArbSyncEvent(*neoEvent);
144 neoEvent->getContext()->getSharing<NEO::GLSharingFunctionsLinux>()->removeGlArbSyncEventMapping(*neoEvent);
145 if (nullptr != arbSyncEvent) {
146 arbSyncEvent->release();
147 }
148 neoEvent->release();
149
150 return CL_SUCCESS;
151 }