gallium: rename 'state tracker' to 'frontend'
[mesa.git] / src / gallium / frontends / clover / core / error.hpp
1 //
2 // Copyright 2013 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 #ifndef CLOVER_CORE_ERROR_HPP
24 #define CLOVER_CORE_ERROR_HPP
25
26 #include "CL/cl.h"
27
28 #include <stdexcept>
29 #include <string>
30
31 namespace clover {
32 class command_queue;
33 class context;
34 class device;
35 class event;
36 class hard_event;
37 class soft_event;
38 class kernel;
39 class memory_obj;
40 class buffer;
41 class root_buffer;
42 class sub_buffer;
43 class image;
44 class image2d;
45 class image3d;
46 class platform;
47 class program;
48 class sampler;
49
50 ///
51 /// Class that represents an error that can be converted to an
52 /// OpenCL status code.
53 ///
54 class error : public std::runtime_error {
55 public:
56 error(cl_int code, std::string what = "") :
57 std::runtime_error(what), code(code) {
58 }
59
60 cl_int get() const {
61 return code;
62 }
63
64 protected:
65 cl_int code;
66 };
67
68 class invalid_build_options_error : public error {
69 public:
70 invalid_build_options_error(const std::string &what = "") :
71 error(CL_INVALID_BUILD_OPTIONS, what) {}
72 };
73
74 class build_error : public error {
75 public:
76 build_error(const std::string &what = "") :
77 error(CL_BUILD_PROGRAM_FAILURE, what) {}
78 };
79
80 template<typename O>
81 class invalid_object_error;
82
83 template<>
84 class invalid_object_error<command_queue> : public error {
85 public:
86 invalid_object_error(std::string what = "") :
87 error(CL_INVALID_COMMAND_QUEUE, what) {}
88 };
89
90 template<>
91 class invalid_object_error<context> : public error {
92 public:
93 invalid_object_error(std::string what = "") :
94 error(CL_INVALID_CONTEXT, what) {}
95 };
96
97 template<>
98 class invalid_object_error<device> : public error {
99 public:
100 invalid_object_error(std::string what = "") :
101 error(CL_INVALID_DEVICE, what) {}
102 };
103
104 template<>
105 class invalid_object_error<event> : public error {
106 public:
107 invalid_object_error(std::string what = "") :
108 error(CL_INVALID_EVENT, what) {}
109 };
110
111 template<>
112 class invalid_object_error<soft_event> : public error {
113 public:
114 invalid_object_error(std::string what = "") :
115 error(CL_INVALID_EVENT, what) {}
116 };
117
118 template<>
119 class invalid_object_error<kernel> : public error {
120 public:
121 invalid_object_error(std::string what = "") :
122 error(CL_INVALID_KERNEL, what) {}
123 };
124
125 template<>
126 class invalid_object_error<memory_obj> : public error {
127 public:
128 invalid_object_error(std::string what = "") :
129 error(CL_INVALID_MEM_OBJECT, what) {}
130 };
131
132 template<>
133 class invalid_object_error<buffer> : public error {
134 public:
135 invalid_object_error(std::string what = "") :
136 error(CL_INVALID_MEM_OBJECT, what) {}
137 };
138
139 template<>
140 class invalid_object_error<root_buffer> : public error {
141 public:
142 invalid_object_error(std::string what = "") :
143 error(CL_INVALID_MEM_OBJECT, what) {}
144 };
145
146 template<>
147 class invalid_object_error<sub_buffer> : public error {
148 public:
149 invalid_object_error(std::string what = "") :
150 error(CL_INVALID_MEM_OBJECT, what) {}
151 };
152
153 template<>
154 class invalid_object_error<image> : public error {
155 public:
156 invalid_object_error(std::string what = "") :
157 error(CL_INVALID_MEM_OBJECT, what) {}
158 };
159
160 template<>
161 class invalid_object_error<image2d> : public error {
162 public:
163 invalid_object_error(std::string what = "") :
164 error(CL_INVALID_MEM_OBJECT, what) {}
165 };
166
167 template<>
168 class invalid_object_error<image3d> : public error {
169 public:
170 invalid_object_error(std::string what = "") :
171 error(CL_INVALID_MEM_OBJECT, what) {}
172 };
173
174 template<>
175 class invalid_object_error<platform> : public error {
176 public:
177 invalid_object_error(std::string what = "") :
178 error(CL_INVALID_PLATFORM, what) {}
179 };
180
181 template<>
182 class invalid_object_error<program> : public error {
183 public:
184 invalid_object_error(std::string what = "") :
185 error(CL_INVALID_PROGRAM, what) {}
186 };
187
188 template<>
189 class invalid_object_error<sampler> : public error {
190 public:
191 invalid_object_error(std::string what = "") :
192 error(CL_INVALID_SAMPLER, what) {}
193 };
194
195 class invalid_wait_list_error : public error {
196 public:
197 invalid_wait_list_error(std::string what = "") :
198 error(CL_INVALID_EVENT_WAIT_LIST, what) {}
199 };
200 }
201
202 #endif