stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#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 {
|
||||
|
||||
// forward declarations
|
||||
class command_queue;
|
||||
|
||||
/// \class image1d
|
||||
/// \brief An OpenCL 1D image object
|
||||
///
|
||||
/// \opencl_version_warning{1,2}
|
||||
///
|
||||
/// \see image_format, image2d
|
||||
class image1d : public image_object
|
||||
{
|
||||
public:
|
||||
/// Creates a null image1d object.
|
||||
image1d()
|
||||
: image_object()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new image1d object.
|
||||
///
|
||||
/// \see_opencl_ref{clCreateImage}
|
||||
image1d(const context &context,
|
||||
size_t image_width,
|
||||
const image_format &format,
|
||||
cl_mem_flags flags = read_write,
|
||||
void *host_ptr = 0)
|
||||
{
|
||||
#ifdef 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 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
|
||||
// image1d objects are only supported in OpenCL 1.2 and later
|
||||
BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Creates a new image1d as a copy of \p other.
|
||||
image1d(const image1d &other)
|
||||
: image_object(other)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the image1d from \p other.
|
||||
image1d& operator=(const image1d &other)
|
||||
{
|
||||
image_object::operator=(other);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
/// Move-constructs a new image object from \p other.
|
||||
image1d(image1d&& other) BOOST_NOEXCEPT
|
||||
: image_object(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assigns the image from \p other to \c *this.
|
||||
image1d& operator=(image1d&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
image_object::operator=(std::move(other));
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
|
||||
/// Destroys the image1d object.
|
||||
~image1d()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the size (width) of the image.
|
||||
extents<1> size() const
|
||||
{
|
||||
extents<1> size;
|
||||
size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Returns the origin of the image (\c 0).
|
||||
extents<1> origin() const
|
||||
{
|
||||
return extents<1>();
|
||||
}
|
||||
|
||||
/// Returns information about the image.
|
||||
///
|
||||
/// \see_opencl_ref{clGetImageInfo}
|
||||
template<class T>
|
||||
T get_info(cl_image_info info) const
|
||||
{
|
||||
return get_image_info<T>(info);
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template<int Enum>
|
||||
typename detail::get_object_info_type<image1d, Enum>::type
|
||||
get_info() const;
|
||||
|
||||
/// Returns the supported image formats for the context.
|
||||
///
|
||||
/// \see_opencl_ref{clGetSupportedImageFormats}
|
||||
static std::vector<image_format>
|
||||
get_supported_formats(const context &context, cl_mem_flags flags = read_write)
|
||||
{
|
||||
#ifdef CL_VERSION_1_2
|
||||
return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE1D, flags);
|
||||
#else
|
||||
return std::vector<image_format>();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Returns \c true if \p format is a supported 1D image format for
|
||||
/// \p context.
|
||||
static bool is_supported_format(const image_format &format,
|
||||
const context &context,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
#ifdef CL_VERSION_1_2
|
||||
return image_object::is_supported_format(
|
||||
format, context, CL_MEM_OBJECT_IMAGE1D, flags
|
||||
);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Creates a new image with a copy of the data in \c *this. Uses \p queue
|
||||
/// to perform the copy operation.
|
||||
image1d clone(command_queue &queue) const;
|
||||
};
|
||||
|
||||
/// \internal_ define get_info() specializations for image1d
|
||||
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 {
|
||||
|
||||
// set_kernel_arg() specialization for image1d
|
||||
template<>
|
||||
struct set_kernel_arg<image1d> : public set_kernel_arg<image_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(boost::compute::image1d, image1d_t)
|
||||
|
||||
#endif // BOOST_COMPUTE_IMAGE_IMAGE1D_HPP
|
||||
@@ -0,0 +1,262 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_IMAGE_IMAGE2D_HPP
|
||||
#define BOOST_COMPUTE_IMAGE_IMAGE2D_HPP
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/compute/config.hpp>
|
||||
#include <boost/compute/context.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/detail/get_object_info.hpp>
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
#include <boost/compute/utility/extents.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
// forward declarations
|
||||
class command_queue;
|
||||
|
||||
/// \class image2d
|
||||
/// \brief An OpenCL 2D image object
|
||||
///
|
||||
/// For example, to create a 640x480 8-bit RGBA image:
|
||||
///
|
||||
/// \snippet test/test_image2d.cpp create_image
|
||||
///
|
||||
/// \see image_format, image3d
|
||||
class image2d : public image_object
|
||||
{
|
||||
public:
|
||||
/// Creates a null image2d object.
|
||||
image2d()
|
||||
: image_object()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new image2d object.
|
||||
///
|
||||
/// \see_opencl_ref{clCreateImage}
|
||||
image2d(const context &context,
|
||||
size_t image_width,
|
||||
size_t image_height,
|
||||
const image_format &format,
|
||||
cl_mem_flags flags = read_write,
|
||||
void *host_ptr = 0,
|
||||
size_t image_row_pitch = 0)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
#ifdef CL_VERSION_1_2
|
||||
cl_image_desc desc;
|
||||
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
desc.image_width = image_width;
|
||||
desc.image_height = image_height;
|
||||
desc.image_depth = 1;
|
||||
desc.image_array_size = 0;
|
||||
desc.image_row_pitch = image_row_pitch;
|
||||
desc.image_slice_pitch = 0;
|
||||
desc.num_mip_levels = 0;
|
||||
desc.num_samples = 0;
|
||||
#ifdef CL_VERSION_2_0
|
||||
desc.mem_object = 0;
|
||||
#else
|
||||
desc.buffer = 0;
|
||||
#endif
|
||||
|
||||
m_mem = clCreateImage(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
&desc,
|
||||
host_ptr,
|
||||
&error);
|
||||
#else
|
||||
m_mem = clCreateImage2D(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
image_width,
|
||||
image_height,
|
||||
image_row_pitch,
|
||||
host_ptr,
|
||||
&error);
|
||||
#endif
|
||||
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// \internal_ (deprecated)
|
||||
image2d(const context &context,
|
||||
cl_mem_flags flags,
|
||||
const image_format &format,
|
||||
size_t image_width,
|
||||
size_t image_height,
|
||||
size_t image_row_pitch = 0,
|
||||
void *host_ptr = 0)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
#ifdef CL_VERSION_1_2
|
||||
cl_image_desc desc;
|
||||
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
desc.image_width = image_width;
|
||||
desc.image_height = image_height;
|
||||
desc.image_depth = 1;
|
||||
desc.image_array_size = 0;
|
||||
desc.image_row_pitch = image_row_pitch;
|
||||
desc.image_slice_pitch = 0;
|
||||
desc.num_mip_levels = 0;
|
||||
desc.num_samples = 0;
|
||||
#ifdef CL_VERSION_2_0
|
||||
desc.mem_object = 0;
|
||||
#else
|
||||
desc.buffer = 0;
|
||||
#endif
|
||||
|
||||
m_mem = clCreateImage(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
&desc,
|
||||
host_ptr,
|
||||
&error);
|
||||
#else
|
||||
m_mem = clCreateImage2D(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
image_width,
|
||||
image_height,
|
||||
image_row_pitch,
|
||||
host_ptr,
|
||||
&error);
|
||||
#endif
|
||||
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new image2d as a copy of \p other.
|
||||
image2d(const image2d &other)
|
||||
: image_object(other)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the image2d from \p other.
|
||||
image2d& operator=(const image2d &other)
|
||||
{
|
||||
image_object::operator=(other);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
/// Move-constructs a new image object from \p other.
|
||||
image2d(image2d&& other) BOOST_NOEXCEPT
|
||||
: image_object(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assigns the image from \p other to \c *this.
|
||||
image2d& operator=(image2d&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
image_object::operator=(std::move(other));
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
|
||||
/// Destroys the image2d object.
|
||||
~image2d()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the size (width, height) of the image.
|
||||
extents<2> size() const
|
||||
{
|
||||
extents<2> size;
|
||||
size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
|
||||
size[1] = get_info<size_t>(CL_IMAGE_HEIGHT);
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Returns the origin of the image (\c 0, \c 0).
|
||||
extents<2> origin() const
|
||||
{
|
||||
return extents<2>();
|
||||
}
|
||||
|
||||
/// Returns information about the image.
|
||||
///
|
||||
/// \see_opencl_ref{clGetImageInfo}
|
||||
template<class T>
|
||||
T get_info(cl_image_info info) const
|
||||
{
|
||||
return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template<int Enum>
|
||||
typename detail::get_object_info_type<image2d, Enum>::type
|
||||
get_info() const;
|
||||
|
||||
/// Returns the supported image formats for the context.
|
||||
///
|
||||
/// \see_opencl_ref{clGetSupportedImageFormats}
|
||||
static std::vector<image_format>
|
||||
get_supported_formats(const context &context, cl_mem_flags flags = read_write)
|
||||
{
|
||||
return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE2D, flags);
|
||||
}
|
||||
|
||||
/// Returns \c true if \p format is a supported 2D image format for
|
||||
/// \p context.
|
||||
static bool is_supported_format(const image_format &format,
|
||||
const context &context,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
return image_object::is_supported_format(
|
||||
format, context, CL_MEM_OBJECT_IMAGE2D, flags
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a new image with a copy of the data in \c *this. Uses \p queue
|
||||
/// to perform the copy operation.
|
||||
image2d clone(command_queue &queue) const;
|
||||
};
|
||||
|
||||
/// \internal_ define get_info() specializations for image2d
|
||||
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image2d,
|
||||
((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 {
|
||||
|
||||
// set_kernel_arg() specialization for image2d
|
||||
template<>
|
||||
struct set_kernel_arg<image2d> : public set_kernel_arg<image_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(boost::compute::image2d, image2d_t)
|
||||
|
||||
#endif // BOOST_COMPUTE_IMAGE_IMAGE2D_HPP
|
||||
@@ -0,0 +1,265 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_IMAGE_IMAGE3D_HPP
|
||||
#define BOOST_COMPUTE_IMAGE_IMAGE3D_HPP
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/compute/detail/get_object_info.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 {
|
||||
|
||||
// forward declarations
|
||||
class command_queue;
|
||||
|
||||
/// \class image3d
|
||||
/// \brief An OpenCL 3D image object
|
||||
///
|
||||
/// \see image_format, image2d
|
||||
class image3d : public image_object
|
||||
{
|
||||
public:
|
||||
/// Creates a null image3d object.
|
||||
image3d()
|
||||
: image_object()
|
||||
{
|
||||
}
|
||||
|
||||
/// Creates a new image3d object.
|
||||
///
|
||||
/// \see_opencl_ref{clCreateImage}
|
||||
image3d(const context &context,
|
||||
size_t image_width,
|
||||
size_t image_height,
|
||||
size_t image_depth,
|
||||
const image_format &format,
|
||||
cl_mem_flags flags = read_write,
|
||||
void *host_ptr = 0,
|
||||
size_t image_row_pitch = 0,
|
||||
size_t image_slice_pitch = 0)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
#ifdef CL_VERSION_1_2
|
||||
cl_image_desc desc;
|
||||
desc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
desc.image_width = image_width;
|
||||
desc.image_height = image_height;
|
||||
desc.image_depth = image_depth;
|
||||
desc.image_array_size = 0;
|
||||
desc.image_row_pitch = image_row_pitch;
|
||||
desc.image_slice_pitch = image_slice_pitch;
|
||||
desc.num_mip_levels = 0;
|
||||
desc.num_samples = 0;
|
||||
#ifdef CL_VERSION_2_0
|
||||
desc.mem_object = 0;
|
||||
#else
|
||||
desc.buffer = 0;
|
||||
#endif
|
||||
|
||||
m_mem = clCreateImage(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
&desc,
|
||||
host_ptr,
|
||||
&error);
|
||||
#else
|
||||
m_mem = clCreateImage3D(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
image_width,
|
||||
image_height,
|
||||
image_depth,
|
||||
image_row_pitch,
|
||||
image_slice_pitch,
|
||||
host_ptr,
|
||||
&error);
|
||||
#endif
|
||||
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// \internal_ (deprecated)
|
||||
image3d(const context &context,
|
||||
cl_mem_flags flags,
|
||||
const image_format &format,
|
||||
size_t image_width,
|
||||
size_t image_height,
|
||||
size_t image_depth,
|
||||
size_t image_row_pitch,
|
||||
size_t image_slice_pitch = 0,
|
||||
void *host_ptr = 0)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
#ifdef CL_VERSION_1_2
|
||||
cl_image_desc desc;
|
||||
desc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
desc.image_width = image_width;
|
||||
desc.image_height = image_height;
|
||||
desc.image_depth = image_depth;
|
||||
desc.image_array_size = 0;
|
||||
desc.image_row_pitch = image_row_pitch;
|
||||
desc.image_slice_pitch = image_slice_pitch;
|
||||
desc.num_mip_levels = 0;
|
||||
desc.num_samples = 0;
|
||||
#ifdef CL_VERSION_2_0
|
||||
desc.mem_object = 0;
|
||||
#else
|
||||
desc.buffer = 0;
|
||||
#endif
|
||||
|
||||
m_mem = clCreateImage(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
&desc,
|
||||
host_ptr,
|
||||
&error);
|
||||
#else
|
||||
m_mem = clCreateImage3D(context,
|
||||
flags,
|
||||
format.get_format_ptr(),
|
||||
image_width,
|
||||
image_height,
|
||||
image_depth,
|
||||
image_row_pitch,
|
||||
image_slice_pitch,
|
||||
host_ptr,
|
||||
&error);
|
||||
#endif
|
||||
|
||||
if(!m_mem){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new image3d as a copy of \p other.
|
||||
image3d(const image3d &other)
|
||||
: image_object(other)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the image3d from \p other.
|
||||
image3d& operator=(const image3d &other)
|
||||
{
|
||||
image_object::operator=(other);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
/// Move-constructs a new image object from \p other.
|
||||
image3d(image3d&& other) BOOST_NOEXCEPT
|
||||
: image_object(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// Move-assigns the image from \p other to \c *this.
|
||||
image3d& operator=(image3d&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
image_object::operator=(std::move(other));
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
|
||||
/// Destroys the image3d object.
|
||||
~image3d()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns the size (width, height, depth) of the image.
|
||||
extents<3> size() const
|
||||
{
|
||||
extents<3> size;
|
||||
size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
|
||||
size[1] = get_info<size_t>(CL_IMAGE_HEIGHT);
|
||||
size[2] = get_info<size_t>(CL_IMAGE_DEPTH);
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Returns the origin of the image (\c 0, \c 0, \c 0).
|
||||
extents<3> origin() const
|
||||
{
|
||||
return extents<3>();
|
||||
}
|
||||
|
||||
/// Returns information about the image.
|
||||
///
|
||||
/// \see_opencl_ref{clGetImageInfo}
|
||||
template<class T>
|
||||
T get_info(cl_image_info info) const
|
||||
{
|
||||
return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template<int Enum>
|
||||
typename detail::get_object_info_type<image3d, Enum>::type
|
||||
get_info() const;
|
||||
|
||||
/// Returns the supported 3D image formats for the context.
|
||||
///
|
||||
/// \see_opencl_ref{clGetSupportedImageFormats}
|
||||
static std::vector<image_format>
|
||||
get_supported_formats(const context &context, cl_mem_flags flags = read_write)
|
||||
{
|
||||
return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE3D, flags);
|
||||
}
|
||||
|
||||
/// Returns \c true if \p format is a supported 3D image format for
|
||||
/// \p context.
|
||||
static bool is_supported_format(const image_format &format,
|
||||
const context &context,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
return image_object::is_supported_format(
|
||||
format, context, CL_MEM_OBJECT_IMAGE3D, flags
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a new image with a copy of the data in \c *this. Uses \p queue
|
||||
/// to perform the copy operation.
|
||||
image3d clone(command_queue &queue) const;
|
||||
};
|
||||
|
||||
/// \internal_ define get_info() specializations for image3d
|
||||
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image3d,
|
||||
((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 {
|
||||
|
||||
// set_kernel_arg() specialization for image3d
|
||||
template<>
|
||||
struct set_kernel_arg<image3d> : public set_kernel_arg<image_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(boost::compute::image3d, image3d_t)
|
||||
|
||||
#endif // BOOST_COMPUTE_IMAGE_IMAGE3D_HPP
|
||||
@@ -0,0 +1,135 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
|
||||
#define BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
|
||||
|
||||
#include <boost/compute/cl.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// \class image_format
|
||||
/// \brief A OpenCL image format
|
||||
///
|
||||
/// For example, to create a format for a 8-bit RGBA image:
|
||||
/// \code
|
||||
/// boost::compute::image_format rgba8(CL_RGBA, CL_UNSIGNED_INT8);
|
||||
/// \endcode
|
||||
///
|
||||
/// After being constructed, image_format objects are usually passed to the
|
||||
/// constructor of the various image classes (e.g. \ref image2d, \ref image3d)
|
||||
/// to create an image object on a compute device.
|
||||
///
|
||||
/// Image formats supported by a context can be queried with the static
|
||||
/// get_supported_formats() in each image class. For example:
|
||||
/// \code
|
||||
/// std::vector<image_format> formats = image2d::get_supported_formats(ctx);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see image2d
|
||||
class image_format
|
||||
{
|
||||
public:
|
||||
enum channel_order {
|
||||
r = CL_R,
|
||||
a = CL_A,
|
||||
intensity = CL_INTENSITY,
|
||||
luminance = CL_LUMINANCE,
|
||||
rg = CL_RG,
|
||||
ra = CL_RA,
|
||||
rgb = CL_RGB,
|
||||
rgba = CL_RGBA,
|
||||
argb = CL_ARGB,
|
||||
bgra = CL_BGRA
|
||||
};
|
||||
|
||||
enum channel_data_type {
|
||||
snorm_int8 = CL_SNORM_INT8,
|
||||
snorm_int16 = CL_SNORM_INT16,
|
||||
unorm_int8 = CL_UNORM_INT8,
|
||||
unorm_int16 = CL_UNORM_INT16,
|
||||
unorm_short_565 = CL_UNORM_SHORT_565,
|
||||
unorm_short_555 = CL_UNORM_SHORT_555,
|
||||
unorm_int_101010 = CL_UNORM_INT_101010,
|
||||
signed_int8 = CL_SIGNED_INT8,
|
||||
signed_int16 = CL_SIGNED_INT16,
|
||||
signed_int32 = CL_SIGNED_INT32,
|
||||
unsigned_int8 = CL_UNSIGNED_INT8,
|
||||
unsigned_int16 = CL_UNSIGNED_INT16,
|
||||
unsigned_int32 = CL_UNSIGNED_INT32,
|
||||
float16 = CL_HALF_FLOAT,
|
||||
float32 = CL_FLOAT
|
||||
};
|
||||
|
||||
/// Creates a new image format object with \p order and \p type.
|
||||
explicit image_format(cl_channel_order order, cl_channel_type type)
|
||||
{
|
||||
m_format.image_channel_order = order;
|
||||
m_format.image_channel_data_type = type;
|
||||
}
|
||||
|
||||
/// Creates a new image format object from \p format.
|
||||
explicit image_format(const cl_image_format &format)
|
||||
{
|
||||
m_format.image_channel_order = format.image_channel_order;
|
||||
m_format.image_channel_data_type = format.image_channel_data_type;
|
||||
}
|
||||
|
||||
/// Creates a new image format object as a copy of \p other.
|
||||
image_format(const image_format &other)
|
||||
: m_format(other.m_format)
|
||||
{
|
||||
}
|
||||
|
||||
/// Copies the format from \p other to \c *this.
|
||||
image_format& operator=(const image_format &other)
|
||||
{
|
||||
if(this != &other){
|
||||
m_format = other.m_format;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Destroys the image format object.
|
||||
~image_format()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns a pointer to the \c cl_image_format object.
|
||||
const cl_image_format* get_format_ptr() const
|
||||
{
|
||||
return &m_format;
|
||||
}
|
||||
|
||||
/// Returns \c true if \c *this is the same as \p other.
|
||||
bool operator==(const image_format &other) const
|
||||
{
|
||||
return m_format.image_channel_order ==
|
||||
other.m_format.image_channel_order &&
|
||||
m_format.image_channel_data_type ==
|
||||
other.m_format.image_channel_data_type;
|
||||
}
|
||||
|
||||
/// Returns \c true if \c *this is not the same as \p other.
|
||||
bool operator!=(const image_format &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
cl_image_format m_format;
|
||||
};
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
|
||||
@@ -0,0 +1,170 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
|
||||
#define BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/compute/config.hpp>
|
||||
#include <boost/compute/memory_object.hpp>
|
||||
#include <boost/compute/detail/get_object_info.hpp>
|
||||
#include <boost/compute/image/image_format.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// \class image_object
|
||||
/// \brief Base-class for image objects.
|
||||
///
|
||||
/// The image_object class is the base-class for image objects on compute
|
||||
/// devices.
|
||||
///
|
||||
/// \see image1d, image2d, image3d
|
||||
class image_object : public memory_object
|
||||
{
|
||||
public:
|
||||
image_object()
|
||||
: memory_object()
|
||||
{
|
||||
}
|
||||
|
||||
explicit image_object(cl_mem mem, bool retain = true)
|
||||
: memory_object(mem, retain)
|
||||
{
|
||||
}
|
||||
|
||||
image_object(const image_object &other)
|
||||
: memory_object(other)
|
||||
{
|
||||
}
|
||||
|
||||
image_object& operator=(const image_object &other)
|
||||
{
|
||||
if(this != &other){
|
||||
memory_object::operator=(other);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
image_object(image_object&& other) BOOST_NOEXCEPT
|
||||
: memory_object(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
/// \internal_
|
||||
image_object& operator=(image_object&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
memory_object::operator=(std::move(other));
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
|
||||
/// Destroys the image object.
|
||||
~image_object()
|
||||
{
|
||||
}
|
||||
|
||||
/// Returns information about the image object.
|
||||
///
|
||||
/// \see_opencl_ref{clGetImageInfo}
|
||||
template<class T>
|
||||
T get_image_info(cl_mem_info info) const
|
||||
{
|
||||
return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
|
||||
}
|
||||
|
||||
/// Returns the format for the image.
|
||||
image_format format() const
|
||||
{
|
||||
return image_format(get_image_info<cl_image_format>(CL_IMAGE_FORMAT));
|
||||
}
|
||||
|
||||
/// \internal_ (deprecated)
|
||||
image_format get_format() const
|
||||
{
|
||||
return format();
|
||||
}
|
||||
|
||||
/// Returns the width of the image.
|
||||
size_t width() const
|
||||
{
|
||||
return get_image_info<size_t>(CL_IMAGE_WIDTH);
|
||||
}
|
||||
|
||||
/// Returns the height of the image.
|
||||
///
|
||||
/// For 1D images, this function will return \c 1.
|
||||
size_t height() const
|
||||
{
|
||||
return get_image_info<size_t>(CL_IMAGE_HEIGHT);
|
||||
}
|
||||
|
||||
/// Returns the depth of the image.
|
||||
///
|
||||
/// For 1D and 2D images, this function will return \c 1.
|
||||
size_t depth() const
|
||||
{
|
||||
return get_image_info<size_t>(CL_IMAGE_DEPTH);
|
||||
}
|
||||
|
||||
/// Returns the supported image formats for the \p type in \p context.
|
||||
///
|
||||
/// \see_opencl_ref{clGetSupportedImageFormats}
|
||||
static std::vector<image_format>
|
||||
get_supported_formats(const context &context,
|
||||
cl_mem_object_type type,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
cl_uint count = 0;
|
||||
clGetSupportedImageFormats(context, flags, type, 0, 0, &count);
|
||||
|
||||
std::vector<cl_image_format> cl_formats(count);
|
||||
clGetSupportedImageFormats(context, flags, type, count, &cl_formats[0], 0);
|
||||
|
||||
std::vector<image_format> formats;
|
||||
formats.reserve(count);
|
||||
|
||||
for(cl_uint i = 0; i < count; i++){
|
||||
formats.push_back(image_format(cl_formats[i]));
|
||||
}
|
||||
|
||||
return formats;
|
||||
}
|
||||
|
||||
/// Returns \c true if \p format is a supported image format for
|
||||
/// \p type in \p context with \p flags.
|
||||
static bool is_supported_format(const image_format &format,
|
||||
const context &context,
|
||||
cl_mem_object_type type,
|
||||
cl_mem_flags flags = read_write)
|
||||
{
|
||||
const std::vector<image_format> formats =
|
||||
get_supported_formats(context, type, flags);
|
||||
|
||||
return std::find(formats.begin(), formats.end(), format) != formats.end();
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
// set_kernel_arg() specialization for image_object
|
||||
template<>
|
||||
struct set_kernel_arg<image_object> : public set_kernel_arg<memory_object> { };
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
|
||||
@@ -0,0 +1,221 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_IMAGE_IMAGE_SAMPLER_HPP
|
||||
#define BOOST_COMPUTE_IMAGE_IMAGE_SAMPLER_HPP
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/compute/config.hpp>
|
||||
#include <boost/compute/context.hpp>
|
||||
#include <boost/compute/kernel.hpp>
|
||||
#include <boost/compute/detail/get_object_info.hpp>
|
||||
#include <boost/compute/detail/assert_cl_success.hpp>
|
||||
#include <boost/compute/exception/opencl_error.hpp>
|
||||
#include <boost/compute/type_traits/type_name.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// \class image_sampler
|
||||
/// \brief An OpenCL image sampler object
|
||||
///
|
||||
/// \see image2d, image_format
|
||||
class image_sampler
|
||||
{
|
||||
public:
|
||||
enum addressing_mode {
|
||||
none = CL_ADDRESS_NONE,
|
||||
clamp_to_edge = CL_ADDRESS_CLAMP_TO_EDGE,
|
||||
clamp = CL_ADDRESS_CLAMP,
|
||||
repeat = CL_ADDRESS_REPEAT
|
||||
};
|
||||
|
||||
enum filter_mode {
|
||||
nearest = CL_FILTER_NEAREST,
|
||||
linear = CL_FILTER_LINEAR
|
||||
};
|
||||
|
||||
image_sampler()
|
||||
: m_sampler(0)
|
||||
{
|
||||
}
|
||||
|
||||
image_sampler(const context &context,
|
||||
bool normalized_coords,
|
||||
cl_addressing_mode addressing_mode,
|
||||
cl_filter_mode filter_mode)
|
||||
{
|
||||
cl_int error = 0;
|
||||
|
||||
#ifdef CL_VERSION_2_0
|
||||
std::vector<cl_sampler_properties> sampler_properties;
|
||||
sampler_properties.push_back(CL_SAMPLER_NORMALIZED_COORDS);
|
||||
sampler_properties.push_back(cl_sampler_properties(normalized_coords));
|
||||
sampler_properties.push_back(CL_SAMPLER_ADDRESSING_MODE);
|
||||
sampler_properties.push_back(cl_sampler_properties(addressing_mode));
|
||||
sampler_properties.push_back(CL_SAMPLER_FILTER_MODE);
|
||||
sampler_properties.push_back(cl_sampler_properties(filter_mode));
|
||||
sampler_properties.push_back(cl_sampler_properties(0));
|
||||
|
||||
m_sampler = clCreateSamplerWithProperties(
|
||||
context, &sampler_properties[0], &error
|
||||
);
|
||||
#else
|
||||
m_sampler = clCreateSampler(
|
||||
context, normalized_coords, addressing_mode, filter_mode, &error
|
||||
);
|
||||
#endif
|
||||
|
||||
if(!m_sampler){
|
||||
BOOST_THROW_EXCEPTION(opencl_error(error));
|
||||
}
|
||||
}
|
||||
|
||||
explicit image_sampler(cl_sampler sampler, bool retain = true)
|
||||
: m_sampler(sampler)
|
||||
{
|
||||
if(m_sampler && retain){
|
||||
clRetainSampler(m_sampler);
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new image sampler object as a copy of \p other.
|
||||
image_sampler(const image_sampler &other)
|
||||
: m_sampler(other.m_sampler)
|
||||
{
|
||||
if(m_sampler){
|
||||
clRetainSampler(m_sampler);
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies the image sampler object from \p other to \c *this.
|
||||
image_sampler& operator=(const image_sampler &other)
|
||||
{
|
||||
if(this != &other){
|
||||
if(m_sampler){
|
||||
clReleaseSampler(m_sampler);
|
||||
}
|
||||
|
||||
m_sampler = other.m_sampler;
|
||||
|
||||
if(m_sampler){
|
||||
clRetainSampler(m_sampler);
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
image_sampler(image_sampler&& other) BOOST_NOEXCEPT
|
||||
: m_sampler(other.m_sampler)
|
||||
{
|
||||
other.m_sampler = 0;
|
||||
}
|
||||
|
||||
image_sampler& operator=(image_sampler&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
if(m_sampler){
|
||||
clReleaseSampler(m_sampler);
|
||||
}
|
||||
|
||||
m_sampler = other.m_sampler;
|
||||
other.m_sampler = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
#endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
|
||||
|
||||
/// Destroys the image sampler object.
|
||||
~image_sampler()
|
||||
{
|
||||
if(m_sampler){
|
||||
BOOST_COMPUTE_ASSERT_CL_SUCCESS(
|
||||
clReleaseSampler(m_sampler)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the underlying \c cl_sampler object.
|
||||
cl_sampler& get() const
|
||||
{
|
||||
return const_cast<cl_sampler &>(m_sampler);
|
||||
}
|
||||
|
||||
/// Returns the context for the image sampler object.
|
||||
context get_context() const
|
||||
{
|
||||
return context(get_info<cl_context>(CL_SAMPLER_CONTEXT));
|
||||
}
|
||||
|
||||
/// Returns information about the sampler.
|
||||
///
|
||||
/// \see_opencl_ref{clGetSamplerInfo}
|
||||
template<class T>
|
||||
T get_info(cl_sampler_info info) const
|
||||
{
|
||||
return detail::get_object_info<T>(clGetSamplerInfo, m_sampler, info);
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template<int Enum>
|
||||
typename detail::get_object_info_type<image_sampler, Enum>::type
|
||||
get_info() const;
|
||||
|
||||
/// Returns \c true if the sampler is the same at \p other.
|
||||
bool operator==(const image_sampler &other) const
|
||||
{
|
||||
return m_sampler == other.m_sampler;
|
||||
}
|
||||
|
||||
/// Returns \c true if the sampler is different from \p other.
|
||||
bool operator!=(const image_sampler &other) const
|
||||
{
|
||||
return m_sampler != other.m_sampler;
|
||||
}
|
||||
|
||||
operator cl_sampler() const
|
||||
{
|
||||
return m_sampler;
|
||||
}
|
||||
|
||||
private:
|
||||
cl_sampler m_sampler;
|
||||
};
|
||||
|
||||
/// \internal_ define get_info() specializations for image_sampler
|
||||
BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image_sampler,
|
||||
((cl_uint, CL_SAMPLER_REFERENCE_COUNT))
|
||||
((cl_context, CL_SAMPLER_CONTEXT))
|
||||
((cl_addressing_mode, CL_SAMPLER_ADDRESSING_MODE))
|
||||
((cl_filter_mode, CL_SAMPLER_FILTER_MODE))
|
||||
((bool, CL_SAMPLER_NORMALIZED_COORDS))
|
||||
)
|
||||
|
||||
namespace detail {
|
||||
|
||||
// set_kernel_arg specialization for image samplers
|
||||
template<>
|
||||
struct set_kernel_arg<image_sampler>
|
||||
{
|
||||
void operator()(kernel &kernel_, size_t index, const image_sampler &sampler)
|
||||
{
|
||||
kernel_.set_arg(index, sampler.get());
|
||||
}
|
||||
};
|
||||
|
||||
} // end detail namespace
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
BOOST_COMPUTE_TYPE_NAME(boost::compute::image_sampler, sampler_t)
|
||||
|
||||
#endif // BOOST_COMPUTE_IMAGE_IMAGE_SAMPLER_HPP
|
||||
Reference in New Issue
Block a user