compute_transfer_buffer.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 "compute_buffer.h"
33 #include "compute_context.h"
34 #include "compute_command_queue.h"
35 #include "compute_event.h"
36 
37 namespace clan
38 {
41 
44 template<typename Type>
46 {
49 public:
51  {
52  }
53 
55  : queue(queue), buffer_local(context, size * sizeof(Type), access_write_only, true), buffer_remote(context, size * sizeof(Type), access_read_only)
56  {
57  memory_map = queue.map_buffer(buffer_local, access_write_only, 0, size * sizeof(Type));
58  data = memory_map.data<Type>();
59  }
60 
62  {
63  }
65 
68 public:
69  Type *data;
70  ComputeEvent &get_upload_event() { return upload_event; }
71  ComputeBuffer &get_buffer_remote() { return buffer_remote; }
73 
76  void upload_range(int start, int length)
77  {
78  upload_event = queue.write_buffer(buffer_remote, false, start * sizeof(Type), length * sizeof(Type), memory_map.data());
79  }
81 
84 private:
85  ComputeCommandQueue queue;
86  ComputeBuffer buffer_local;
87  ComputeBuffer buffer_remote;
88  ComputeEvent upload_event;
89  ComputeMemoryMap memory_map;
91 };
92 
93 }
94 
ComputeMemoryMap map_buffer(ComputeBuffer &buffer, BufferAccess access, size_t offset, size_t size, const ComputeWaitList &wait_list=ComputeWaitList())
ComputeTransferBuffer()
Definition: compute_transfer_buffer.h:50
Compute buffer.
Definition: compute_buffer.h:52
Definition: buffer_usage.h:57
~ComputeTransferBuffer()
Definition: compute_transfer_buffer.h:61
void * data()
Mapped memory pointer.
Type * data
Definition: compute_transfer_buffer.h:69
ComputeBuffer & get_buffer_remote()
Definition: compute_transfer_buffer.h:71
ComputeEvent & get_upload_event()
Definition: compute_transfer_buffer.h:70
ComputeEvent write_buffer(ComputeBuffer &buffer, bool blocking_write, size_t offset, size_t size, void *ptr, const ComputeWaitList &wait_list=ComputeWaitList())
ComputeTransferBuffer(ComputeContext &context, ComputeCommandQueue &queue, int size)
Definition: compute_transfer_buffer.h:54
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
Compute transfer buffer.
Definition: compute_transfer_buffer.h:45
void upload_range(int start, int length)
Definition: compute_transfer_buffer.h:76
Interface to compute operations.
Definition: compute_context.h:44
Definition: buffer_usage.h:58