1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
12 #define BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
14 #include <boost/throw_exception.hpp>
16 #include <boost/compute/config.hpp>
17 #include <boost/compute/exception/opencl_error.hpp>
18 #include <boost/compute/image/image_format.hpp>
19 #include <boost/compute/image/image_object.hpp>
20 #include <boost/compute/type_traits/type_name.hpp>
21 #include <boost/compute/utility/extents.hpp>
26 // forward declarations
30 /// \brief An OpenCL 1D image object
32 /// \opencl_version_warning{1,2}
34 /// \see image_format, image2d
35 class image1d : public image_object
38 /// Creates a null image1d object.
44 /// Creates a new image1d object.
46 /// \see_opencl_ref{clCreateImage}
47 image1d(const context &context,
49 const image_format &format,
50 cl_mem_flags flags = read_write,
53 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
55 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
56 desc.image_width = image_width;
57 desc.image_height = 1;
59 desc.image_array_size = 0;
60 desc.image_row_pitch = 0;
61 desc.image_slice_pitch = 0;
62 desc.num_mip_levels = 0;
64 #ifdef BOOST_COMPUTE_CL_VERSION_2_0
72 m_mem = clCreateImage(
73 context, flags, format.get_format_ptr(), &desc, host_ptr, &error
77 BOOST_THROW_EXCEPTION(opencl_error(error));
80 // image1d objects are only supported in OpenCL 1.2 and later
81 BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
85 /// Creates a new image1d as a copy of \p other.
86 image1d(const image1d &other)
91 /// Copies the image1d from \p other.
92 image1d& operator=(const image1d &other)
94 image_object::operator=(other);
99 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
100 /// Move-constructs a new image object from \p other.
101 image1d(image1d&& other) BOOST_NOEXCEPT
102 : image_object(std::move(other))
106 /// Move-assigns the image from \p other to \c *this.
107 image1d& operator=(image1d&& other) BOOST_NOEXCEPT
109 image_object::operator=(std::move(other));
113 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
115 /// Destroys the image1d object.
120 /// Returns the size (width) of the image.
121 extents<1> size() const
124 size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
128 /// Returns the origin of the image (\c 0).
129 extents<1> origin() const
134 /// Returns information about the image.
136 /// \see_opencl_ref{clGetImageInfo}
138 T get_info(cl_image_info info) const
140 return get_image_info<T>(info);
145 typename detail::get_object_info_type<image1d, Enum>::type
148 /// Returns the supported image formats for the context.
150 /// \see_opencl_ref{clGetSupportedImageFormats}
151 static std::vector<image_format>
152 get_supported_formats(const context &context, cl_mem_flags flags = read_write)
154 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
155 return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE1D, flags);
157 return std::vector<image_format>();
161 /// Returns \c true if \p format is a supported 1D image format for
163 static bool is_supported_format(const image_format &format,
164 const context &context,
165 cl_mem_flags flags = read_write)
167 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
168 return image_object::is_supported_format(
169 format, context, CL_MEM_OBJECT_IMAGE1D, flags
176 /// Creates a new image with a copy of the data in \c *this. Uses \p queue
177 /// to perform the copy operation.
178 image1d clone(command_queue &queue) const;
181 /// \internal_ define get_info() specializations for image1d
182 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image1d,
183 ((cl_image_format, CL_IMAGE_FORMAT))
184 ((size_t, CL_IMAGE_ELEMENT_SIZE))
185 ((size_t, CL_IMAGE_ROW_PITCH))
186 ((size_t, CL_IMAGE_SLICE_PITCH))
187 ((size_t, CL_IMAGE_WIDTH))
188 ((size_t, CL_IMAGE_HEIGHT))
189 ((size_t, CL_IMAGE_DEPTH))
194 // set_kernel_arg() specialization for image1d
196 struct set_kernel_arg<image1d> : public set_kernel_arg<image_object> { };
198 } // end detail namespace
199 } // end compute namespace
200 } // end boost namespace
202 BOOST_COMPUTE_TYPE_NAME(boost::compute::image1d, image1d_t)
204 #endif // BOOST_COMPUTE_IMAGE_IMAGE1D_HPP