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