1 /*
2  * Copyright (C) 2018-2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #pragma once
9 #include "CL/cl.h"
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 namespace NEO {
16 class Context;
17 class DriverInfo;
18 
19 enum SharingType {
20     CLGL_SHARING = 0,
21     VA_SHARING = 1,
22     D3D9_SHARING = 2,
23     D3D10_SHARING = 3,
24     D3D11_SHARING = 4,
25     UNIFIED_SHARING = 5,
26     MAX_SHARING_VALUE = 6
27 };
28 
29 class SharingContextBuilder {
30   public:
31     virtual ~SharingContextBuilder() = default;
32     virtual bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue) = 0;
33     virtual bool finalizeProperties(Context &context, int32_t &errcodeRet) = 0;
34 };
35 
36 class SharingBuilderFactory {
37   public:
38     virtual ~SharingBuilderFactory() = default;
39     virtual std::unique_ptr<SharingContextBuilder> createContextBuilder() = 0;
40     virtual std::string getExtensions(DriverInfo *driverInfo) = 0;
fillGlobalDispatchTable()41     virtual void fillGlobalDispatchTable() {}
42     virtual void *getExtensionFunctionAddress(const std::string &functionName) = 0;
43     virtual void setExtensionEnabled(DriverInfo *driverInfo);
44 };
45 
46 class SharingFactory {
47   protected:
48     static SharingBuilderFactory *sharingContextBuilder[SharingType::MAX_SHARING_VALUE];
49     std::vector<std::unique_ptr<SharingContextBuilder>> sharings;
50 
51   public:
52     template <typename F, typename T>
53     class RegisterSharing {
54       public:
55         RegisterSharing();
56     };
57 
58     static std::unique_ptr<SharingFactory> build();
59     bool processProperties(cl_context_properties &propertyType, cl_context_properties &propertyValue);
60     bool finalizeProperties(Context &context, int32_t &errcodeRet);
61     std::string getExtensions(DriverInfo *driverInfo);
62     void fillGlobalDispatchTable();
63     void *getExtensionFunctionAddress(const std::string &functionName);
64     void verifyExtensionSupport(DriverInfo *driverInfo);
65 };
66 
67 extern SharingFactory sharingFactory;
68 } // namespace NEO
69