1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // cl_util.h: Helper functions for the CL back end
7
8 #ifndef LIBANGLE_RENDERER_CL_CL_UTIL_H_
9 #define LIBANGLE_RENDERER_CL_CL_UTIL_H_
10
11 #include "libANGLE/renderer/cl_types.h"
12
13 #include "anglebase/no_destructor.h"
14
15 #include <unordered_set>
16
17 namespace rx
18 {
19
20 // Extract numeric version from OpenCL version string
21 cl_version ExtractCLVersion(const std::string &version);
22
23 using CLExtensionSet = std::unordered_set<std::string>;
24
25 // Get a set of OpenCL extensions which are supported to be passed through
GetSupportedCLExtensions()26 inline const CLExtensionSet &GetSupportedCLExtensions()
27 {
28 static angle::base::NoDestructor<const CLExtensionSet> sExtensions({
29 // clang-format off
30
31 // These Khronos extension names must be returned by all devices that support OpenCL 1.1.
32 "cl_khr_byte_addressable_store",
33 "cl_khr_global_int32_base_atomics",
34 "cl_khr_global_int32_extended_atomics",
35 "cl_khr_local_int32_base_atomics",
36 "cl_khr_local_int32_extended_atomics",
37
38 // These Khronos extension names must be returned by all devices that support
39 // OpenCL 2.0, OpenCL 2.1, or OpenCL 2.2. For devices that support OpenCL 3.0, these
40 // extension names must be returned when and only when the optional feature is supported.
41 "cl_khr_3d_image_writes",
42 "cl_khr_depth_images",
43 "cl_khr_image2d_from_buffer",
44
45 // Optional extensions
46 "cl_khr_extended_versioning",
47 "cl_khr_fp64",
48 "cl_khr_icd",
49 "cl_khr_int64_base_atomics",
50 "cl_khr_int64_extended_atomics"
51
52 // clang-format on
53 });
54 return *sExtensions;
55 }
56
57 // Check if a specific OpenCL extensions is supported to be passed through
IsCLExtensionSupported(const std::string & extension)58 inline bool IsCLExtensionSupported(const std::string &extension)
59 {
60 const CLExtensionSet &supported = GetSupportedCLExtensions();
61 return supported.find(extension) != supported.cend();
62 }
63
64 // Filter out extensions which are not (yet) supported to be passed through
65 void RemoveUnsupportedCLExtensions(std::string &extensions);
66 void RemoveUnsupportedCLExtensions(NameVersionVector &extensions);
67
68 } // namespace rx
69
70 #endif // LIBANGLE_RENDERER_CL_CL_UTIL_H_
71