File indexing completed on 2025-01-30 09:34:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
0012 #define BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
0013
0014 #include <boost/throw_exception.hpp>
0015
0016 #include <boost/compute/config.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
0034
0035 class image1d : public image_object
0036 {
0037 public:
0038
0039 image1d()
0040 : image_object()
0041 {
0042 }
0043
0044
0045
0046
0047 image1d(const context &context,
0048 size_t image_width,
0049 const image_format &format,
0050 cl_mem_flags flags = read_write,
0051 void *host_ptr = 0)
0052 {
0053 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0054 cl_image_desc desc;
0055 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
0056 desc.image_width = image_width;
0057 desc.image_height = 1;
0058 desc.image_depth = 1;
0059 desc.image_array_size = 0;
0060 desc.image_row_pitch = 0;
0061 desc.image_slice_pitch = 0;
0062 desc.num_mip_levels = 0;
0063 desc.num_samples = 0;
0064 #ifdef BOOST_COMPUTE_CL_VERSION_2_0
0065 desc.mem_object = 0;
0066 #else
0067 desc.buffer = 0;
0068 #endif
0069
0070 cl_int error = 0;
0071
0072 m_mem = clCreateImage(
0073 context, flags, format.get_format_ptr(), &desc, host_ptr, &error
0074 );
0075
0076 if(!m_mem){
0077 BOOST_THROW_EXCEPTION(opencl_error(error));
0078 }
0079 #else
0080
0081 BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
0082 #endif
0083 }
0084
0085
0086 image1d(const image1d &other)
0087 : image_object(other)
0088 {
0089 }
0090
0091
0092 image1d& operator=(const image1d &other)
0093 {
0094 image_object::operator=(other);
0095
0096 return *this;
0097 }
0098
0099 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
0100
0101 image1d(image1d&& other) BOOST_NOEXCEPT
0102 : image_object(std::move(other))
0103 {
0104 }
0105
0106
0107 image1d& operator=(image1d&& other) BOOST_NOEXCEPT
0108 {
0109 image_object::operator=(std::move(other));
0110
0111 return *this;
0112 }
0113 #endif
0114
0115
0116 ~image1d()
0117 {
0118 }
0119
0120
0121 extents<1> size() const
0122 {
0123 extents<1> size;
0124 size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
0125 return size;
0126 }
0127
0128
0129 extents<1> origin() const
0130 {
0131 return extents<1>();
0132 }
0133
0134
0135
0136
0137 template<class T>
0138 T get_info(cl_image_info info) const
0139 {
0140 return get_image_info<T>(info);
0141 }
0142
0143
0144 template<int Enum>
0145 typename detail::get_object_info_type<image1d, Enum>::type
0146 get_info() const;
0147
0148
0149
0150
0151 static std::vector<image_format>
0152 get_supported_formats(const context &context, cl_mem_flags flags = read_write)
0153 {
0154 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0155 return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE1D, flags);
0156 #else
0157 return std::vector<image_format>();
0158 #endif
0159 }
0160
0161
0162
0163 static bool is_supported_format(const image_format &format,
0164 const context &context,
0165 cl_mem_flags flags = read_write)
0166 {
0167 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
0168 return image_object::is_supported_format(
0169 format, context, CL_MEM_OBJECT_IMAGE1D, flags
0170 );
0171 #else
0172 return false;
0173 #endif
0174 }
0175
0176
0177
0178 image1d clone(command_queue &queue) const;
0179 };
0180
0181
0182 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image1d,
0183 ((cl_image_format, CL_IMAGE_FORMAT))
0184 ((size_t, CL_IMAGE_ELEMENT_SIZE))
0185 ((size_t, CL_IMAGE_ROW_PITCH))
0186 ((size_t, CL_IMAGE_SLICE_PITCH))
0187 ((size_t, CL_IMAGE_WIDTH))
0188 ((size_t, CL_IMAGE_HEIGHT))
0189 ((size_t, CL_IMAGE_DEPTH))
0190 )
0191
0192 namespace detail {
0193
0194
0195 template<>
0196 struct set_kernel_arg<image1d> : public set_kernel_arg<image_object> { };
0197
0198 }
0199 }
0200 }
0201
0202 BOOST_COMPUTE_TYPE_NAME(boost::compute::image1d, image1d_t)
0203
0204 #endif