Debian Codegraph @

opencl/source/sharings/gl/windows/win_enable_gl.cpp

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