File indexing completed on 2025-01-18 09:30:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_IMAGE_IMAGE2D_HPP
0012 #define BOOST_COMPUTE_IMAGE_IMAGE2D_HPP
0013
0014 #include <boost/throw_exception.hpp>
0015
0016 #include <boost/compute/config.hpp>
0017 #include <boost/compute/context.hpp>
0018 #include <boost/compute/exception/opencl_error.hpp>
0019 #include <boost/compute/image/image_format.hpp>
0020 #include <boost/compute/image/image_object.hpp>
0021 #include <boost/compute/detail/get_object_info.hpp>
0022 #include <boost/compute/type_traits/type_name.hpp>
0023 #include <boost/compute/utility/extents.hpp>
0024
0025 namespace boost {
0026 namespace compute {
0027
0028
0029 class command_queue;
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 class image2d : public image_object
0040 {
0041 public:
0042
0043 image2d()
0044 : image_object()
0045 {
0046 }
0047
0048
0049
0050
0051 image2d(const context &context,
0052 size_t image_width,
0053 size_t image_height,
0054 const image_format &format,
0055 cl_mem_flags flags = read_write,
0056 void *host_ptr = 0,
0057 size_t image_row_pitch = 0)
0058 {
0059 cl_int error = 0;
0060
0061 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0062 cl_image_desc desc;
0063 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
0064 desc.image_width = image_width;
0065 desc.image_height = image_height;
0066 desc.image_depth = 1;
0067 desc.image_array_size = 0;
0068 desc.image_row_pitch = image_row_pitch;
0069 desc.image_slice_pitch = 0;
0070 desc.num_mip_levels = 0;
0071 desc.num_samples = 0;
0072 #ifdef BOOST_COMPUTE_CL_VERSION_2_0
0073 desc.mem_object = 0;
0074 #else
0075 desc.buffer = 0;
0076 #endif
0077
0078 m_mem = clCreateImage(context,
0079 flags,
0080 format.get_format_ptr(),
0081 &desc,
0082 host_ptr,
0083 &error);
0084 #else
0085 m_mem = clCreateImage2D(context,
0086 flags,
0087 format.get_format_ptr(),
0088 image_width,
0089 image_height,
0090 image_row_pitch,
0091 host_ptr,
0092 &error);
0093 #endif
0094
0095 if(!m_mem){
0096 BOOST_THROW_EXCEPTION(opencl_error(error));
0097 }
0098 }
0099
0100
0101 image2d(const context &context,
0102 cl_mem_flags flags,
0103 const image_format &format,
0104 size_t image_width,
0105 size_t image_height,
0106 size_t image_row_pitch = 0,
0107 void *host_ptr = 0)
0108 {
0109 cl_int error = 0;
0110
0111 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0112 cl_image_desc desc;
0113 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
0114 desc.image_width = image_width;
0115 desc.image_height = image_height;
0116 desc.image_depth = 1;
0117 desc.image_array_size = 0;
0118 desc.image_row_pitch = image_row_pitch;
0119 desc.image_slice_pitch = 0;
0120 desc.num_mip_levels = 0;
0121 desc.num_samples = 0;
0122 #ifdef BOOST_COMPUTE_CL_VERSION_2_0
0123 desc.mem_object = 0;
0124 #else
0125 desc.buffer = 0;
0126 #endif
0127
0128 m_mem = clCreateImage(context,
0129 flags,
0130 format.get_format_ptr(),
0131 &desc,
0132 host_ptr,
0133 &error);
0134 #else
0135 m_mem = clCreateImage2D(context,
0136 flags,
0137 format.get_format_ptr(),
0138 image_width,
0139 image_height,
0140 image_row_pitch,
0141 host_ptr,
0142 &error);
0143 #endif
0144
0145 if(!m_mem){
0146 BOOST_THROW_EXCEPTION(opencl_error(error));
0147 }
0148 }
0149
0150
0151 image2d(const image2d &other)
0152 : image_object(other)
0153 {
0154 }
0155
0156
0157 image2d& operator=(const image2d &other)
0158 {
0159 image_object::operator=(other);
0160
0161 return *this;
0162 }
0163
0164 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
0165
0166 image2d(image2d&& other) BOOST_NOEXCEPT
0167 : image_object(std::move(other))
0168 {
0169 }
0170
0171
0172 image2d& operator=(image2d&& other) BOOST_NOEXCEPT
0173 {
0174 image_object::operator=(std::move(other));
0175
0176 return *this;
0177 }
0178 #endif
0179
0180
0181 ~image2d()
0182 {
0183 }
0184
0185
0186 extents<2> size() const
0187 {
0188 extents<2> size;
0189 size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
0190 size[1] = get_info<size_t>(CL_IMAGE_HEIGHT);
0191 return size;
0192 }
0193
0194
0195 extents<2> origin() const
0196 {
0197 return extents<2>();
0198 }
0199
0200
0201
0202
0203 template<class T>
0204 T get_info(cl_image_info info) const
0205 {
0206 return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
0207 }
0208
0209
0210 template<int Enum>
0211 typename detail::get_object_info_type<image2d, Enum>::type
0212 get_info() const;
0213
0214
0215
0216
0217 static std::vector<image_format>
0218 get_supported_formats(const context &context, cl_mem_flags flags = read_write)
0219 {
0220 return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE2D, flags);
0221 }
0222
0223
0224
0225 static bool is_supported_format(const image_format &format,
0226 const context &context,
0227 cl_mem_flags flags = read_write)
0228 {
0229 return image_object::is_supported_format(
0230 format, context, CL_MEM_OBJECT_IMAGE2D, flags
0231 );
0232 }
0233
0234
0235
0236 image2d clone(command_queue &queue) const;
0237 };
0238
0239
0240 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image2d,
0241 ((cl_image_format, CL_IMAGE_FORMAT))
0242 ((size_t, CL_IMAGE_ELEMENT_SIZE))
0243 ((size_t, CL_IMAGE_ROW_PITCH))
0244 ((size_t, CL_IMAGE_SLICE_PITCH))
0245 ((size_t, CL_IMAGE_WIDTH))
0246 ((size_t, CL_IMAGE_HEIGHT))
0247 ((size_t, CL_IMAGE_DEPTH))
0248 )
0249
0250 namespace detail {
0251
0252
0253 template<>
0254 struct set_kernel_arg<image2d> : public set_kernel_arg<image_object> { };
0255
0256 }
0257 }
0258 }
0259
0260 BOOST_COMPUTE_TYPE_NAME(boost::compute::image2d, image2d_t)
0261
0262 #endif