]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/image/image_object.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / image / image_object.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
12 #define BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
13
14 #include <algorithm>
15 #include <vector>
16
17 #include <boost/compute/config.hpp>
18 #include <boost/compute/memory_object.hpp>
19 #include <boost/compute/detail/get_object_info.hpp>
20 #include <boost/compute/image/image_format.hpp>
21
22 namespace boost {
23 namespace compute {
24
25 /// \class image_object
26 /// \brief Base-class for image objects.
27 ///
28 /// The image_object class is the base-class for image objects on compute
29 /// devices.
30 ///
31 /// \see image1d, image2d, image3d
32 class image_object : public memory_object
33 {
34 public:
35 image_object()
36 : memory_object()
37 {
38 }
39
40 explicit image_object(cl_mem mem, bool retain = true)
41 : memory_object(mem, retain)
42 {
43 }
44
45 image_object(const image_object &other)
46 : memory_object(other)
47 {
48 }
49
50 image_object& operator=(const image_object &other)
51 {
52 if(this != &other){
53 memory_object::operator=(other);
54 }
55
56 return *this;
57 }
58
59 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
60 image_object(image_object&& other) BOOST_NOEXCEPT
61 : memory_object(std::move(other))
62 {
63 }
64
65 /// \internal_
66 image_object& operator=(image_object&& other) BOOST_NOEXCEPT
67 {
68 memory_object::operator=(std::move(other));
69
70 return *this;
71 }
72 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
73
74 /// Destroys the image object.
75 ~image_object()
76 {
77 }
78
79 /// Returns information about the image object.
80 ///
81 /// \see_opencl_ref{clGetImageInfo}
82 template<class T>
83 T get_image_info(cl_mem_info info) const
84 {
85 return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
86 }
87
88 /// Returns the format for the image.
89 image_format format() const
90 {
91 return image_format(get_image_info<cl_image_format>(CL_IMAGE_FORMAT));
92 }
93
94 /// \internal_ (deprecated)
95 image_format get_format() const
96 {
97 return format();
98 }
99
100 /// Returns the width of the image.
101 size_t width() const
102 {
103 return get_image_info<size_t>(CL_IMAGE_WIDTH);
104 }
105
106 /// Returns the height of the image.
107 ///
108 /// For 1D images, this function will return \c 1.
109 size_t height() const
110 {
111 return get_image_info<size_t>(CL_IMAGE_HEIGHT);
112 }
113
114 /// Returns the depth of the image.
115 ///
116 /// For 1D and 2D images, this function will return \c 1.
117 size_t depth() const
118 {
119 return get_image_info<size_t>(CL_IMAGE_DEPTH);
120 }
121
122 /// Returns the supported image formats for the \p type in \p context.
123 ///
124 /// \see_opencl_ref{clGetSupportedImageFormats}
125 static std::vector<image_format>
126 get_supported_formats(const context &context,
127 cl_mem_object_type type,
128 cl_mem_flags flags = read_write)
129 {
130 cl_uint count = 0;
131 clGetSupportedImageFormats(context, flags, type, 0, 0, &count);
132
133 std::vector<cl_image_format> cl_formats(count);
134 clGetSupportedImageFormats(context, flags, type, count, &cl_formats[0], 0);
135
136 std::vector<image_format> formats;
137 formats.reserve(count);
138
139 for(cl_uint i = 0; i < count; i++){
140 formats.push_back(image_format(cl_formats[i]));
141 }
142
143 return formats;
144 }
145
146 /// Returns \c true if \p format is a supported image format for
147 /// \p type in \p context with \p flags.
148 static bool is_supported_format(const image_format &format,
149 const context &context,
150 cl_mem_object_type type,
151 cl_mem_flags flags = read_write)
152 {
153 const std::vector<image_format> formats =
154 get_supported_formats(context, type, flags);
155
156 return std::find(formats.begin(), formats.end(), format) != formats.end();
157 }
158 };
159
160 namespace detail {
161
162 // set_kernel_arg() specialization for image_object
163 template<>
164 struct set_kernel_arg<image_object> : public set_kernel_arg<memory_object> { };
165
166 } // end detail namespace
167 } // end compute namespace
168 } // end boost namespace
169
170 #endif // BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP