clover: Update OpenCL version string to match OpenGL
[mesa.git] / src / gallium / state_trackers / clover / api / platform.cpp
1 //
2 // Copyright 2012 Francisco Jerez
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22
23 #include "api/util.hpp"
24 #include "core/platform.hpp"
25 #include "git_sha1.h"
26
27 using namespace clover;
28
29 namespace {
30 platform _clover_platform;
31 }
32
33 CLOVER_API cl_int
34 clGetPlatformIDs(cl_uint num_entries, cl_platform_id *rd_platforms,
35 cl_uint *rnum_platforms) {
36 if ((!num_entries && rd_platforms) ||
37 (!rnum_platforms && !rd_platforms))
38 return CL_INVALID_VALUE;
39
40 if (rnum_platforms)
41 *rnum_platforms = 1;
42 if (rd_platforms)
43 *rd_platforms = desc(_clover_platform);
44
45 return CL_SUCCESS;
46 }
47
48 cl_int
49 clover::GetPlatformInfo(cl_platform_id d_platform, cl_platform_info param,
50 size_t size, void *r_buf, size_t *r_size) try {
51 property_buffer buf { r_buf, size, r_size };
52
53 obj(d_platform);
54
55 switch (param) {
56 case CL_PLATFORM_PROFILE:
57 buf.as_string() = "FULL_PROFILE";
58 break;
59
60 case CL_PLATFORM_VERSION:
61 buf.as_string() = "OpenCL 1.1 Mesa " PACKAGE_VERSION
62 " (" MESA_GIT_SHA1 ")";
63 break;
64
65 case CL_PLATFORM_NAME:
66 buf.as_string() = "Clover";
67 break;
68
69 case CL_PLATFORM_VENDOR:
70 buf.as_string() = "Mesa";
71 break;
72
73 case CL_PLATFORM_EXTENSIONS:
74 buf.as_string() = "cl_khr_icd";
75 break;
76
77 case CL_PLATFORM_ICD_SUFFIX_KHR:
78 buf.as_string() = "MESA";
79 break;
80
81 default:
82 throw error(CL_INVALID_VALUE);
83 }
84
85 return CL_SUCCESS;
86
87 } catch (error &e) {
88 return e.get();
89 }
90
91 void *
92 clover::GetExtensionFunctionAddress(const char *p_name) {
93 std::string name { p_name };
94
95 if (name == "clIcdGetPlatformIDsKHR")
96 return reinterpret_cast<void *>(IcdGetPlatformIDsKHR);
97 else
98 return NULL;
99 }
100
101 cl_int
102 clover::IcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id *rd_platforms,
103 cl_uint *rnum_platforms) {
104 return clGetPlatformIDs(num_entries, rd_platforms, rnum_platforms);
105 }
106
107 CLOVER_ICD_API cl_int
108 clGetPlatformInfo(cl_platform_id d_platform, cl_platform_info param,
109 size_t size, void *r_buf, size_t *r_size) {
110 return GetPlatformInfo(d_platform, param, size, r_buf, r_size);
111 }
112
113 CLOVER_ICD_API void *
114 clGetExtensionFunctionAddress(const char *p_name) {
115 return GetExtensionFunctionAddress(p_name);
116 }
117
118 CLOVER_ICD_API cl_int
119 clIcdGetPlatformIDsKHR(cl_uint num_entries, cl_platform_id *rd_platforms,
120 cl_uint *rnum_platforms) {
121 return IcdGetPlatformIDsKHR(num_entries, rd_platforms, rnum_platforms);
122 }