compute_command_queue.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 
30 #pragma once
31 
32 #include "api_compute.h"
33 #include <memory>
34 #include "../Display/Image/buffer_usage.h"
35 #include "compute_event.h"
36 #include "compute_wait_list.h"
37 
38 namespace clan
39 {
42 
43 class ComputeContext;
44 class ComputeBuffer;
45 class ComputeKernel;
46 class ComputeMemoryMap;
47 class ComputeCommandQueue_Impl;
48 
50 class CL_API_COMPUTE ComputeCommandQueue
51 {
54 public:
57 
59  ComputeCommandQueue(ComputeContext &context, bool enable_out_of_order_execute = true, bool enable_profiling = false);
60 
63 
66 public:
68  bool is_null() const { return !impl; }
69 
71  void throw_if_null() const;
73 
76 public:
77  ComputeEvent run_task(const ComputeKernel &kernel, const ComputeWaitList &wait_list = ComputeWaitList());
78 
80  const ComputeKernel &kernel,
81  size_t global_work_size,
82  const ComputeWaitList &wait_list = ComputeWaitList())
83  {
84  return run_1d(kernel, global_work_size, 0, 0, wait_list);
85  }
86 
88  const ComputeKernel &kernel,
89  size_t global_work_size,
90  size_t local_work_size,
91  const ComputeWaitList &wait_list = ComputeWaitList())
92  {
93  return run_1d(kernel, global_work_size, local_work_size, 0, wait_list);
94  }
95 
96  ComputeEvent run_1d(
97  const ComputeKernel &kernel,
98  size_t global_work_size,
99  size_t local_work_size,
100  size_t offset,
101  const ComputeWaitList &wait_list = ComputeWaitList());
102 
104  const ComputeKernel &kernel,
105  size_t global_work_size_x,
106  size_t global_work_size_y,
107  const ComputeWaitList &wait_list = ComputeWaitList())
108  {
109  return run_2d(kernel, global_work_size_x, global_work_size_y, 0, 0, 0, 0, wait_list);
110  }
111 
113  const ComputeKernel &kernel,
114  size_t global_work_size_x,
115  size_t global_work_size_y,
116  size_t local_work_size_x,
117  size_t local_work_size_y,
118  const ComputeWaitList &wait_list = ComputeWaitList())
119  {
120  return run_2d(kernel, global_work_size_x, global_work_size_y, local_work_size_x, local_work_size_y, 0, 0, wait_list);
121  }
122 
123  ComputeEvent run_2d(
124  const ComputeKernel &kernel,
125  size_t global_work_size_x,
126  size_t global_work_size_y,
127  size_t local_work_size_x,
128  size_t local_work_size_y,
129  size_t offset_x,
130  size_t offset_y,
131  const ComputeWaitList &wait_list = ComputeWaitList());
132 
134  const ComputeKernel &kernel,
135  size_t global_work_size_x,
136  size_t global_work_size_y,
137  size_t global_work_size_z,
138  const ComputeWaitList &wait_list = ComputeWaitList())
139  {
140  return run_3d(kernel, global_work_size_x, global_work_size_y, global_work_size_z, 0, 0, 0, 0, 0, 0, wait_list);
141  }
142 
144  const ComputeKernel &kernel,
145  size_t global_work_size_x,
146  size_t global_work_size_y,
147  size_t global_work_size_z,
148  size_t local_work_size_x,
149  size_t local_work_size_y,
150  size_t local_work_size_z,
151  const ComputeWaitList &wait_list = ComputeWaitList())
152  {
153  return run_3d(kernel, global_work_size_x, global_work_size_y, global_work_size_z, local_work_size_x, local_work_size_y, local_work_size_z, 0, 0, 0, wait_list);
154  }
155 
156  ComputeEvent run_3d(
157  const ComputeKernel &kernel,
158  size_t global_work_size_x,
159  size_t global_work_size_y,
160  size_t global_work_size_z,
161  size_t local_work_size_x,
162  size_t local_work_size_y,
163  size_t local_work_size_z,
164  size_t offset_x,
165  size_t offset_y,
166  size_t offset_z,
167  const ComputeWaitList &wait_list = ComputeWaitList());
168 
169  ComputeEvent add_barrier(const ComputeWaitList &wait_list = ComputeWaitList());
170  ComputeEvent add_marker(const ComputeWaitList &wait_list = ComputeWaitList());
171 
172  ComputeEvent read_buffer(ComputeBuffer &buffer, bool blocking_read, size_t offset, size_t size, void *ptr, const ComputeWaitList &wait_list = ComputeWaitList());
173  ComputeEvent write_buffer(ComputeBuffer &buffer, bool blocking_write, size_t offset, size_t size, void *ptr, const ComputeWaitList &wait_list = ComputeWaitList());
174  //CL_ComputeEvent read_buffer_rect(ComputeBuffer &buffer);
175  //CL_ComputeEvent write_buffer_rect(ComputeBuffer &buffer);
176  ComputeEvent fill_buffer(ComputeBuffer &buffer, const void *pattern, size_t pattern_size, size_t offset, size_t size, const ComputeWaitList &wait_list = ComputeWaitList());
177  ComputeEvent copy_buffer(ComputeBuffer &src, ComputeBuffer &dest, size_t src_offset, size_t dest_offset, size_t size, const ComputeWaitList &wait_list = ComputeWaitList());
178  //CL_ComputeEvent copy_buffer_rect(ComputeBuffer &src, ComputeBuffer &dest);
179 
180  //CL_ComputeEvent read_image(ComputeBuffer &buffer);
181  //CL_ComputeEvent write_image(ComputeBuffer &buffer);
182  //CL_ComputeEvent fill_image(ComputeBuffer &buffer);
183  //CL_ComputeEvent copy_image(ComputeBuffer &buffer);
184  //CL_ComputeEvent copy_image_to_buffer(ComputeBuffer &buffer);
185  //CL_ComputeEvent copy_buffer_to_image(ComputeBuffer &buffer);
186 
187  ComputeMemoryMap map_buffer(ComputeBuffer &buffer, BufferAccess access, size_t offset, size_t size, const ComputeWaitList &wait_list = ComputeWaitList());
188  //CL_ComputeMemoryMap map_image(ComputeBuffer &buffer);
189 
190  ComputeEvent migrate_buffers(const std::vector<ComputeBuffer> &buffers, bool migrate_to_host = false, bool content_undefined = false, const ComputeWaitList &wait_list = ComputeWaitList());
191 
192  ComputeEvent acquire_display_objects(const std::vector<ComputeBuffer> &buffers, const ComputeWaitList &wait_list = ComputeWaitList());
193  ComputeEvent release_display_objects(const std::vector<ComputeBuffer> &buffers, const ComputeWaitList &wait_list = ComputeWaitList());
194 
195  void flush();
196  void finish();
198 
201 private:
202  ComputeEvent unmap(ComputeBuffer &buffer, void *mapped_ptr, const ComputeWaitList &wait_list = ComputeWaitList());
203 
204  std::shared_ptr<ComputeCommandQueue_Impl> impl;
205  friend class ComputeMemoryMap_Impl;
207 };
208 
209 }
210 
ComputeEvent run_2d(const ComputeKernel &kernel, size_t global_work_size_x, size_t global_work_size_y, const ComputeWaitList &wait_list=ComputeWaitList())
Definition: compute_command_queue.h:103
Compute buffer.
Definition: compute_buffer.h:52
ComputeEvent run_2d(const ComputeKernel &kernel, size_t global_work_size_x, size_t global_work_size_y, size_t local_work_size_x, size_t local_work_size_y, const ComputeWaitList &wait_list=ComputeWaitList())
Definition: compute_command_queue.h:112
ComputeEvent run_3d(const ComputeKernel &kernel, size_t global_work_size_x, size_t global_work_size_y, size_t global_work_size_z, size_t local_work_size_x, size_t local_work_size_y, size_t local_work_size_z, const ComputeWaitList &wait_list=ComputeWaitList())
Definition: compute_command_queue.h:143
bool is_null() const
Returns true if this object is invalid.
Definition: compute_command_queue.h:68
ComputeEvent run_1d(const ComputeKernel &kernel, size_t global_work_size, size_t local_work_size, const ComputeWaitList &wait_list=ComputeWaitList())
Definition: compute_command_queue.h:87
ComputeEvent run_3d(const ComputeKernel &kernel, size_t global_work_size_x, size_t global_work_size_y, size_t global_work_size_z, const ComputeWaitList &wait_list=ComputeWaitList())
Definition: compute_command_queue.h:133
Compute program kernel object.
Definition: compute_kernel.h:47
Compute command queue.
Definition: compute_command_queue.h:50
Compute event object.
Definition: compute_event.h:43
Compute memory mapping.
Definition: compute_memory_map.h:44
List of events that must have completed before a new operation is executed.
Definition: compute_wait_list.h:41
BufferAccess
Array Buffer access enum.
Definition: buffer_usage.h:55
ComputeEvent run_1d(const ComputeKernel &kernel, size_t global_work_size, const ComputeWaitList &wait_list=ComputeWaitList())
Definition: compute_command_queue.h:79
Interface to compute operations.
Definition: compute_context.h:44