123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #ifndef BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
- #define BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
- #include <boost/throw_exception.hpp>
- #include <boost/compute/config.hpp>
- #include <boost/compute/exception/opencl_error.hpp>
- #include <boost/compute/image/image_format.hpp>
- #include <boost/compute/image/image_object.hpp>
- #include <boost/compute/type_traits/type_name.hpp>
- #include <boost/compute/utility/extents.hpp>
- namespace boost {
- namespace compute {
- class command_queue;
- class image1d : public image_object
- {
- public:
-
- image1d()
- : image_object()
- {
- }
-
-
-
- image1d(const context &context,
- size_t image_width,
- const image_format &format,
- cl_mem_flags flags = read_write,
- void *host_ptr = 0)
- {
- #ifdef BOOST_COMPUTE_CL_VERSION_1_2
- cl_image_desc desc;
- desc.image_type = CL_MEM_OBJECT_IMAGE1D;
- desc.image_width = image_width;
- desc.image_height = 1;
- desc.image_depth = 1;
- desc.image_array_size = 0;
- desc.image_row_pitch = 0;
- desc.image_slice_pitch = 0;
- desc.num_mip_levels = 0;
- desc.num_samples = 0;
- #ifdef BOOST_COMPUTE_CL_VERSION_2_0
- desc.mem_object = 0;
- #else
- desc.buffer = 0;
- #endif
- cl_int error = 0;
- m_mem = clCreateImage(
- context, flags, format.get_format_ptr(), &desc, host_ptr, &error
- );
- if(!m_mem){
- BOOST_THROW_EXCEPTION(opencl_error(error));
- }
- #else
-
- BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
- #endif
- }
-
- image1d(const image1d &other)
- : image_object(other)
- {
- }
-
- image1d& operator=(const image1d &other)
- {
- image_object::operator=(other);
- return *this;
- }
- #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
-
- image1d(image1d&& other) BOOST_NOEXCEPT
- : image_object(std::move(other))
- {
- }
-
- image1d& operator=(image1d&& other) BOOST_NOEXCEPT
- {
- image_object::operator=(std::move(other));
- return *this;
- }
- #endif
-
- ~image1d()
- {
- }
-
- extents<1> size() const
- {
- extents<1> size;
- size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
- return size;
- }
-
- extents<1> origin() const
- {
- return extents<1>();
- }
-
-
-
- template<class T>
- T get_info(cl_image_info info) const
- {
- return get_image_info<T>(info);
- }
-
- template<int Enum>
- typename detail::get_object_info_type<image1d, Enum>::type
- get_info() const;
-
-
-
- static std::vector<image_format>
- get_supported_formats(const context &context, cl_mem_flags flags = read_write)
- {
- #ifdef BOOST_COMPUTE_CL_VERSION_1_2
- return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE1D, flags);
- #else
- return std::vector<image_format>();
- #endif
- }
-
-
- static bool is_supported_format(const image_format &format,
- const context &context,
- cl_mem_flags flags = read_write)
- {
- #ifdef BOOST_COMPUTE_CL_VERSION_1_2
- return image_object::is_supported_format(
- format, context, CL_MEM_OBJECT_IMAGE1D, flags
- );
- #else
- return false;
- #endif
- }
-
-
- image1d clone(command_queue &queue) const;
- };
- BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image1d,
- ((cl_image_format, CL_IMAGE_FORMAT))
- ((size_t, CL_IMAGE_ELEMENT_SIZE))
- ((size_t, CL_IMAGE_ROW_PITCH))
- ((size_t, CL_IMAGE_SLICE_PITCH))
- ((size_t, CL_IMAGE_WIDTH))
- ((size_t, CL_IMAGE_HEIGHT))
- ((size_t, CL_IMAGE_DEPTH))
- )
- namespace detail {
- template<>
- struct set_kernel_arg<image1d> : public set_kernel_arg<image_object> { };
- }
- }
- }
- BOOST_COMPUTE_TYPE_NAME(boost::compute::image1d, image1d_t)
- #endif
|