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 // CLPlatformVk.cpp: Implements the class methods for CLPlatformVk.
7
8 #include "libANGLE/renderer/vulkan/CLPlatformVk.h"
9
10 #include "libANGLE/renderer/vulkan/CLDeviceVk.h"
11
12 #include "libANGLE/CLPlatform.h"
13
14 #include "anglebase/no_destructor.h"
15 #include "common/angle_version_info.h"
16
17 namespace rx
18 {
19
20 namespace
21 {
22
CreateExtensionString(const NameVersionVector & extList)23 std::string CreateExtensionString(const NameVersionVector &extList)
24 {
25 std::string extensions;
26 for (const cl_name_version &ext : extList)
27 {
28 extensions += ext.name;
29 extensions += ' ';
30 }
31 if (!extensions.empty())
32 {
33 extensions.pop_back();
34 }
35 return extensions;
36 }
37
38 } // namespace
39
40 CLPlatformVk::~CLPlatformVk() = default;
41
createInfo() const42 CLPlatformImpl::Info CLPlatformVk::createInfo() const
43 {
44 NameVersionVector extList = {
45 cl_name_version{CL_MAKE_VERSION(1, 0, 0), "cl_khr_icd"},
46 cl_name_version{CL_MAKE_VERSION(1, 0, 0), "cl_khr_extended_versioning"}};
47
48 Info info;
49 info.initializeExtensions(CreateExtensionString(extList));
50 info.profile.assign("FULL_PROFILE");
51 info.versionStr.assign(GetVersionString());
52 info.version = GetVersion();
53 info.name.assign("ANGLE Vulkan");
54 info.extensionsWithVersion = std::move(extList);
55 info.hostTimerRes = 0u;
56 return info;
57 }
58
createDevices() const59 CLDeviceImpl::CreateDatas CLPlatformVk::createDevices() const
60 {
61 cl::DeviceType type; // TODO(jplate) Fetch device type from Vulkan
62 CLDeviceImpl::CreateDatas createDatas;
63 createDatas.emplace_back(
64 type, [](const cl::Device &device) { return CLDeviceVk::Ptr(new CLDeviceVk(device)); });
65 return createDatas;
66 }
67
createContext(cl::Context & context,const cl::DevicePtrs & devices,bool userSync,cl_int & errorCode)68 CLContextImpl::Ptr CLPlatformVk::createContext(cl::Context &context,
69 const cl::DevicePtrs &devices,
70 bool userSync,
71 cl_int &errorCode)
72 {
73 CLContextImpl::Ptr contextImpl;
74 return contextImpl;
75 }
76
createContextFromType(cl::Context & context,cl::DeviceType deviceType,bool userSync,cl_int & errorCode)77 CLContextImpl::Ptr CLPlatformVk::createContextFromType(cl::Context &context,
78 cl::DeviceType deviceType,
79 bool userSync,
80 cl_int &errorCode)
81 {
82 CLContextImpl::Ptr contextImpl;
83 return contextImpl;
84 }
85
unloadCompiler()86 cl_int CLPlatformVk::unloadCompiler()
87 {
88 return CL_SUCCESS;
89 }
90
Initialize(CreateFuncs & createFuncs)91 void CLPlatformVk::Initialize(CreateFuncs &createFuncs)
92 {
93 createFuncs.emplace_back(
94 [](const cl::Platform &platform) { return Ptr(new CLPlatformVk(platform)); });
95 }
96
GetVersionString()97 const std::string &CLPlatformVk::GetVersionString()
98 {
99 static const angle::base::NoDestructor<const std::string> sVersion(
100 "OpenCL " + std::to_string(CL_VERSION_MAJOR(GetVersion())) + "." +
101 std::to_string(CL_VERSION_MINOR(GetVersion())) + " ANGLE " +
102 angle::GetANGLEVersionString());
103 return *sVersion;
104 }
105
CLPlatformVk(const cl::Platform & platform)106 CLPlatformVk::CLPlatformVk(const cl::Platform &platform) : CLPlatformImpl(platform) {}
107
108 } // namespace rx
109