Debian Codegraph @

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

raw
1 /*
2 * Copyright (C) 2023-2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "opencl/source/sharings/gl/linux/lin_enable_gl.h"
9
10 #include "shared/source/debug_settings/debug_settings_manager.h"
11
12 #include "opencl/source/context/context.h"
13 #include "opencl/source/context/context.inl"
14 #include "opencl/source/sharings/gl/cl_gl_api_intel.h"
15 #include "opencl/source/sharings/gl/linux/gl_sharing_linux.h"
16 #include "opencl/source/sharings/sharing_factory.h"
17 #include "opencl/source/sharings/sharing_factory.inl"
18
19 #include <memory>
20
21 namespace NEO {
22
23 struct GlCreateContextProperties {
24 GLType glHDCType = 0;
25 GLContext glHGLRCHandle = 0;
26 GLDisplay glHDCHandle = 0;
27 };
28
29 GlSharingContextBuilder::GlSharingContextBuilder() = default;
30 GlSharingContextBuilder::~GlSharingContextBuilder() = default;
31
32 bool GlSharingContextBuilder::processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) {
33 if (!contextData)
34 contextData = std::make_unique<GlCreateContextProperties>();
35
36 switch (propertyType) {
37 case CL_GL_CONTEXT_KHR:
38 contextData->glHGLRCHandle = reinterpret_cast<GLContext>(propertyValue);
39 return true;
40 case CL_GLX_DISPLAY_KHR:
41 contextData->glHDCType = static_cast<GLType>(CL_GLX_DISPLAY_KHR);
42 contextData->glHDCHandle = reinterpret_cast<GLDisplay>(propertyValue);
43 return true;
44 case CL_EGL_DISPLAY_KHR:
45 contextData->glHDCType = static_cast<GLType>(CL_EGL_DISPLAY_KHR);
46 contextData->glHDCHandle = reinterpret_cast<GLDisplay>(propertyValue);
47 return true;
48 }
49 return false;
50 }
51
52 bool GlSharingContextBuilder::finalizeProperties(Context &context, int32_t &errcodeRet) {
53 if (contextData == nullptr)
54 return true;
55
56 if (contextData->glHGLRCHandle) {
57 context.registerSharing(new GLSharingFunctionsLinux(contextData->glHDCType, contextData->glHGLRCHandle,
58 nullptr, contextData->glHDCHandle));
59 }
60
61 contextData.reset(nullptr);
62 return true;
63 }
64
65 std::unique_ptr<SharingContextBuilder> GlSharingBuilderFactory::createContextBuilder() {
66 return std::make_unique<GlSharingContextBuilder>();
67 };
68
69 void GlSharingBuilderFactory::fillGlobalDispatchTable() {
70 icdGlobalDispatchTable.clCreateFromGLBuffer = clCreateFromGLBuffer;
71 icdGlobalDispatchTable.clCreateFromGLTexture = clCreateFromGLTexture;
72 icdGlobalDispatchTable.clCreateFromGLTexture2D = clCreateFromGLTexture2D;
73 icdGlobalDispatchTable.clCreateFromGLTexture3D = clCreateFromGLTexture3D;
74 icdGlobalDispatchTable.clCreateFromGLRenderbuffer = clCreateFromGLRenderbuffer;
75 icdGlobalDispatchTable.clGetGLObjectInfo = clGetGLObjectInfo;
76 icdGlobalDispatchTable.clGetGLTextureInfo = clGetGLTextureInfo;
77 icdGlobalDispatchTable.clEnqueueAcquireGLObjects = clEnqueueAcquireGLObjects;
78 icdGlobalDispatchTable.clEnqueueReleaseGLObjects = clEnqueueReleaseGLObjects;
79 icdGlobalDispatchTable.clCreateEventFromGLsyncKHR = clCreateEventFromGLsyncKHR;
80 icdGlobalDispatchTable.clGetGLContextInfoKHR = clGetGLContextInfoKHR;
81 }
82
83 std::string GlSharingBuilderFactory::getExtensions(DriverInfo *driverInfo) {
84 auto isGlSharingEnabled = true;
85
86 if (debugManager.flags.AddClGlSharing.get() != -1) {
87 isGlSharingEnabled = debugManager.flags.AddClGlSharing.get();
88 }
89
90 if (isGlSharingEnabled) {
91 return "cl_khr_gl_sharing "
92 "cl_khr_gl_depth_images "
93 "cl_khr_gl_event "
94 "cl_khr_gl_msaa_sharing ";
95 }
96
97 return "";
98 }
99
100 void *GlSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) {
101 if (debugManager.flags.EnableFormatQuery.get() &&
102 functionName == "clGetSupportedGLTextureFormatsINTEL") {
103 return ((void *)(clGetSupportedGLTextureFormatsINTEL));
104 }
105
106 return nullptr;
107 }
108
109 static SharingFactory::RegisterSharing<GlSharingBuilderFactory, GLSharingFunctionsLinux> glSharing;
110 } // namespace NEO