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_IMAGE_OBJECT_HPP
0012 #define BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
0013
0014 #include <algorithm>
0015 #include <vector>
0016
0017 #include <boost/compute/config.hpp>
0018 #include <boost/compute/memory_object.hpp>
0019 #include <boost/compute/detail/get_object_info.hpp>
0020 #include <boost/compute/image/image_format.hpp>
0021
0022 namespace boost {
0023 namespace compute {
0024
0025
0026
0027
0028
0029
0030
0031
0032 class image_object : public memory_object
0033 {
0034 public:
0035 image_object()
0036 : memory_object()
0037 {
0038 }
0039
0040 explicit image_object(cl_mem mem, bool retain = true)
0041 : memory_object(mem, retain)
0042 {
0043 }
0044
0045 image_object(const image_object &other)
0046 : memory_object(other)
0047 {
0048 }
0049
0050 image_object& operator=(const image_object &other)
0051 {
0052 if(this != &other){
0053 memory_object::operator=(other);
0054 }
0055
0056 return *this;
0057 }
0058
0059 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
0060 image_object(image_object&& other) BOOST_NOEXCEPT
0061 : memory_object(std::move(other))
0062 {
0063 }
0064
0065
0066 image_object& operator=(image_object&& other) BOOST_NOEXCEPT
0067 {
0068 memory_object::operator=(std::move(other));
0069
0070 return *this;
0071 }
0072 #endif
0073
0074
0075 ~image_object()
0076 {
0077 }
0078
0079
0080
0081
0082 template<class T>
0083 T get_image_info(cl_mem_info info) const
0084 {
0085 return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
0086 }
0087
0088
0089 image_format format() const
0090 {
0091 return image_format(get_image_info<cl_image_format>(CL_IMAGE_FORMAT));
0092 }
0093
0094
0095 image_format get_format() const
0096 {
0097 return format();
0098 }
0099
0100
0101 size_t width() const
0102 {
0103 return get_image_info<size_t>(CL_IMAGE_WIDTH);
0104 }
0105
0106
0107
0108
0109 size_t height() const
0110 {
0111 return get_image_info<size_t>(CL_IMAGE_HEIGHT);
0112 }
0113
0114
0115
0116
0117 size_t depth() const
0118 {
0119 return get_image_info<size_t>(CL_IMAGE_DEPTH);
0120 }
0121
0122
0123
0124
0125 static std::vector<image_format>
0126 get_supported_formats(const context &context,
0127 cl_mem_object_type type,
0128 cl_mem_flags flags = read_write)
0129 {
0130 cl_uint count = 0;
0131 clGetSupportedImageFormats(context, flags, type, 0, 0, &count);
0132
0133 std::vector<cl_image_format> cl_formats(count);
0134 clGetSupportedImageFormats(context, flags, type, count, &cl_formats[0], 0);
0135
0136 std::vector<image_format> formats;
0137 formats.reserve(count);
0138
0139 for(cl_uint i = 0; i < count; i++){
0140 formats.push_back(image_format(cl_formats[i]));
0141 }
0142
0143 return formats;
0144 }
0145
0146
0147
0148 static bool is_supported_format(const image_format &format,
0149 const context &context,
0150 cl_mem_object_type type,
0151 cl_mem_flags flags = read_write)
0152 {
0153 const std::vector<image_format> formats =
0154 get_supported_formats(context, type, flags);
0155
0156 return std::find(formats.begin(), formats.end(), format) != formats.end();
0157 }
0158 };
0159
0160 namespace detail {
0161
0162
0163 template<>
0164 struct set_kernel_arg<image_object> : public set_kernel_arg<memory_object> { };
0165
0166 }
0167 }
0168 }
0169
0170 #endif