clover: Delete copy constructors and assignment operators in all non-copiable objects.
[mesa.git] / src / gallium / state_trackers / clover / core / kernel.hpp
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 #ifndef CLOVER_CORE_KERNEL_HPP
24 #define CLOVER_CORE_KERNEL_HPP
25
26 #include <memory>
27
28 #include "core/object.hpp"
29 #include "core/program.hpp"
30 #include "core/memory.hpp"
31 #include "core/sampler.hpp"
32 #include "pipe/p_state.h"
33
34 namespace clover {
35 class kernel : public ref_counter, public _cl_kernel {
36 private:
37 ///
38 /// Class containing all the state required to execute a compute
39 /// kernel.
40 ///
41 struct exec_context {
42 exec_context(kernel &kern);
43 ~exec_context();
44
45 exec_context(const exec_context &) = delete;
46 exec_context &
47 operator=(const exec_context &) = delete;
48
49 void *bind(command_queue *q);
50 void unbind();
51
52 kernel &kern;
53 command_queue *q;
54
55 std::vector<uint8_t> input;
56 std::vector<void *> samplers;
57 std::vector<pipe_sampler_view *> sviews;
58 std::vector<pipe_surface *> resources;
59 std::vector<pipe_resource *> g_buffers;
60 std::vector<size_t> g_handles;
61 size_t mem_local;
62
63 private:
64 void *st;
65 pipe_compute_state cs;
66 };
67
68 public:
69 class argument {
70 public:
71 argument();
72
73 argument(const argument &arg) = delete;
74 argument &
75 operator=(const argument &arg) = delete;
76
77 /// \a true if the argument has been set.
78 bool set() const;
79
80 /// Storage space required for the referenced object.
81 virtual size_t storage() const;
82
83 /// Set this argument to some object.
84 virtual void set(size_t size, const void *value) = 0;
85
86 /// Allocate the necessary resources to bind the specified
87 /// object to this argument, and update \a ctx accordingly.
88 virtual void bind(exec_context &ctx,
89 const module::argument &marg) = 0;
90
91 /// Free any resources that were allocated in bind().
92 virtual void unbind(exec_context &ctx) = 0;
93
94 protected:
95 bool _set;
96 };
97
98 kernel(program &prog,
99 const std::string &name,
100 const std::vector<module::argument> &margs);
101
102 kernel(const kernel &kern) = delete;
103 kernel &
104 operator=(const kernel &kern) = delete;
105
106 void launch(command_queue &q,
107 const std::vector<size_t> &grid_offset,
108 const std::vector<size_t> &grid_size,
109 const std::vector<size_t> &block_size);
110
111 size_t mem_local() const;
112 size_t mem_private() const;
113 size_t max_block_size() const;
114
115 const std::string &name() const;
116 std::vector<size_t> block_size() const;
117
118 program &prog;
119 std::vector<std::unique_ptr<argument>> args;
120
121 private:
122 const clover::module &
123 module(const command_queue &q) const;
124
125 class scalar_argument : public argument {
126 public:
127 scalar_argument(size_t size);
128
129 virtual void set(size_t size, const void *value);
130 virtual void bind(exec_context &ctx,
131 const module::argument &marg);
132 virtual void unbind(exec_context &ctx);
133
134 private:
135 size_t size;
136 std::vector<uint8_t> v;
137 };
138
139 class global_argument : public argument {
140 public:
141 virtual void set(size_t size, const void *value);
142 virtual void bind(exec_context &ctx,
143 const module::argument &marg);
144 virtual void unbind(exec_context &ctx);
145
146 private:
147 buffer *buf;
148 };
149
150 class local_argument : public argument {
151 public:
152 virtual size_t storage() const;
153
154 virtual void set(size_t size, const void *value);
155 virtual void bind(exec_context &ctx,
156 const module::argument &marg);
157 virtual void unbind(exec_context &ctx);
158
159 private:
160 size_t _storage;
161 };
162
163 class constant_argument : public argument {
164 public:
165 virtual void set(size_t size, const void *value);
166 virtual void bind(exec_context &ctx,
167 const module::argument &marg);
168 virtual void unbind(exec_context &ctx);
169
170 private:
171 buffer *buf;
172 pipe_surface *st;
173 };
174
175 class image_rd_argument : public argument {
176 public:
177 virtual void set(size_t size, const void *value);
178 virtual void bind(exec_context &ctx,
179 const module::argument &marg);
180 virtual void unbind(exec_context &ctx);
181
182 private:
183 image *img;
184 pipe_sampler_view *st;
185 };
186
187 class image_wr_argument : public argument {
188 public:
189 virtual void set(size_t size, const void *value);
190 virtual void bind(exec_context &ctx,
191 const module::argument &marg);
192 virtual void unbind(exec_context &ctx);
193
194 private:
195 image *img;
196 pipe_surface *st;
197 };
198
199 class sampler_argument : public argument {
200 public:
201 virtual void set(size_t size, const void *value);
202 virtual void bind(exec_context &ctx,
203 const module::argument &marg);
204 virtual void unbind(exec_context &ctx);
205
206 private:
207 sampler *s;
208 void *st;
209 };
210
211 std::string _name;
212 exec_context exec;
213 };
214 }
215
216 #endif