Debian Codegraph @

opencl/source/sharings/gl/gl_sharing.h

raw
1 /*
2 * Copyright (C) 2018-2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #pragma once
9
10 #include "shared/source/os_interface/os_library.h"
11
12 #include "opencl/source/sharings/sharing.h"
13
14 #include "CL/cl.h"
15
16 #if __clang__
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wignored-pragma-intrinsic"
19 #pragma clang diagnostic ignored "-Wpragma-pack"
20 #pragma clang diagnostic ignored "-Wignored-attributes"
21 #pragma clang diagnostic ignored "-Wmacro-redefined"
22 #pragma clang diagnostic ignored "-Wnonportable-include-path"
23 #endif
24
25 #include "GL/gl.h"
26
27 #if __clang__
28 #pragma clang diagnostic pop
29
30 #endif
31 #include "GL/glext.h"
32
33 #include <functional>
34 #include <mutex>
35 #include <unordered_map>
36
37 struct _tagCLGLSyncInfo;
38 typedef struct _tagCLGLSyncInfo CL_GL_SYNC_INFO, *PCL_GL_SYNC_INFO;
39
40 namespace NEO {
41 class Event;
42 class GlArbSyncEvent;
43 class GLSharingFunctions;
44 class OSInterface;
45 class OsContext;
46 class DriverModel;
47
48 typedef unsigned int OS_HANDLE;
49
50 typedef struct CLGLContextInfo {
51 OS_HANDLE deviceHandle;
52 OS_HANDLE contextHandle;
53 } ContextInfo;
54
55 class GLSharingFunctions : public SharingFunctions {
56 public:
57 GLSharingFunctions() = default;
58
59 uint32_t getId() const override {
60 return GLSharingFunctions::sharingId;
61 }
62 static const uint32_t sharingId;
63
64 static cl_int getSupportedFormats(cl_mem_flags flags,
65 cl_mem_object_type imageType,
66 size_t numEntries,
67 cl_GLenum *formats,
68 uint32_t *numImageFormats);
69
70 static std::unique_ptr<GLSharingFunctions> create();
71 virtual bool isHandleCompatible(const DriverModel &driverModel, uint32_t handle) const { return true; }
72 virtual bool isGlHdcHandleMissing(uint32_t handle) const { return false; }
73 virtual GLboolean initGLFunctions() = 0;
74 virtual bool isOpenGlSharingSupported() = 0;
75 };
76
77 class GlSharing : public SharingHandler {
78 public:
79 GlSharing(GLSharingFunctions *sharingFunctions, unsigned int glObjectType, unsigned int glObjectId)
80 : sharingFunctions(sharingFunctions), clGlObjectType(glObjectType), clGlObjectId(glObjectId){};
81 GLSharingFunctions *peekFunctionsHandler() { return sharingFunctions; }
82 void getGlObjectInfo(unsigned int *pClGlObjectType, unsigned int *pClGlObjectId) {
83 if (pClGlObjectType) {
84 *pClGlObjectType = clGlObjectType;
85 }
86 if (pClGlObjectId) {
87 *pClGlObjectId = clGlObjectId;
88 }
89 }
90 static const std::unordered_map<GLenum, const cl_image_format> glToCLFormats;
91
92 protected:
93 int synchronizeHandler(UpdateData &updateData) override;
94 GLSharingFunctions *sharingFunctions = nullptr;
95 unsigned int clGlObjectType = 0u;
96 unsigned int clGlObjectId = 0u;
97 };
98
99 } // namespace NEO