clover: Use conversion operator to initialize build log from compat::string.
[mesa.git] / src / gallium / state_trackers / clover / core / memory.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_MEMORY_HPP
24 #define CLOVER_CORE_MEMORY_HPP
25
26 #include <functional>
27 #include <map>
28 #include <memory>
29
30 #include "core/object.hpp"
31 #include "core/queue.hpp"
32 #include "core/resource.hpp"
33
34 namespace clover {
35 class memory_obj : public ref_counter, public _cl_mem {
36 protected:
37 memory_obj(clover::context &ctx, cl_mem_flags flags,
38 size_t size, void *host_ptr);
39
40 memory_obj(const memory_obj &obj) = delete;
41 memory_obj &
42 operator=(const memory_obj &obj) = delete;
43
44 public:
45 virtual ~memory_obj();
46
47 bool
48 operator==(const memory_obj &obj) const;
49
50 virtual cl_mem_object_type type() const = 0;
51 virtual clover::resource &resource(command_queue &q) = 0;
52
53 void destroy_notify(std::function<void ()> f);
54 cl_mem_flags flags() const;
55 size_t size() const;
56 void *host_ptr() const;
57
58 const intrusive_ref<clover::context> context;
59
60 private:
61 cl_mem_flags _flags;
62 size_t _size;
63 void *_host_ptr;
64 std::function<void ()> _destroy_notify;
65
66 protected:
67 std::string data;
68 };
69
70 class buffer : public memory_obj {
71 protected:
72 buffer(clover::context &ctx, cl_mem_flags flags,
73 size_t size, void *host_ptr);
74
75 public:
76 virtual cl_mem_object_type type() const;
77 };
78
79 class root_buffer : public buffer {
80 public:
81 root_buffer(clover::context &ctx, cl_mem_flags flags,
82 size_t size, void *host_ptr);
83
84 virtual clover::resource &resource(command_queue &q);
85
86 private:
87 std::map<device *,
88 std::unique_ptr<root_resource>> resources;
89 };
90
91 class sub_buffer : public buffer {
92 public:
93 sub_buffer(root_buffer &parent, cl_mem_flags flags,
94 size_t offset, size_t size);
95
96 virtual clover::resource &resource(command_queue &q);
97 size_t offset() const;
98
99 const intrusive_ref<root_buffer> parent;
100
101 private:
102 size_t _offset;
103 std::map<device *,
104 std::unique_ptr<sub_resource>> resources;
105 };
106
107 class image : public memory_obj {
108 protected:
109 image(clover::context &ctx, cl_mem_flags flags,
110 const cl_image_format *format,
111 size_t width, size_t height, size_t depth,
112 size_t row_pitch, size_t slice_pitch, size_t size,
113 void *host_ptr);
114
115 public:
116 virtual clover::resource &resource(command_queue &q);
117 cl_image_format format() const;
118 size_t width() const;
119 size_t height() const;
120 size_t depth() const;
121 size_t pixel_size() const;
122 size_t row_pitch() const;
123 size_t slice_pitch() const;
124
125 private:
126 cl_image_format _format;
127 size_t _width;
128 size_t _height;
129 size_t _depth;
130 size_t _row_pitch;
131 size_t _slice_pitch;
132 std::map<device *,
133 std::unique_ptr<root_resource>> resources;
134 };
135
136 class image2d : public image {
137 public:
138 image2d(clover::context &ctx, cl_mem_flags flags,
139 const cl_image_format *format, size_t width,
140 size_t height, size_t row_pitch,
141 void *host_ptr);
142
143 virtual cl_mem_object_type type() const;
144 };
145
146 class image3d : public image {
147 public:
148 image3d(clover::context &ctx, cl_mem_flags flags,
149 const cl_image_format *format,
150 size_t width, size_t height, size_t depth,
151 size_t row_pitch, size_t slice_pitch,
152 void *host_ptr);
153
154 virtual cl_mem_object_type type() const;
155 };
156 }
157
158 #endif