25 #include <type_traits>
27 #ifdef __SYCL_DEVICE_ONLY__
32 inline namespace _V1 {
33 namespace ext::oneapi::experimental {
88 __SYCL_EXPORT_DEPRECATED(
"Distinct image frees are deprecated. "
89 "Instead use overload that accepts image_type.")
99 __SYCL_EXPORT_DEPRECATED("Distinct
image frees are deprecated. "
133 __SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
146 __SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
158 __SYCL_EXPORT_DEPRECATED(
159 "Distinct mipmap frees are deprecated. "
170 __SYCL_EXPORT_DEPRECATED(
171 "Distinct mipmap frees are deprecated. "
212 template <typename ExternalMemHandleType>
228 template <typename ExternalMemHandleType>
308 template <typename ExternalSemaphoreHandleType>
311 externalSemaphoreDesc,
325 template <typename ExternalSemaphoreHandleType>
328 externalSemaphoreDesc,
570 size_t widthInBytes,
size_t height,
571 unsigned int elementSizeBytes,
586 size_t widthInBytes,
size_t height,
587 unsigned int elementSizeBytes,
671 __SYCL_EXPORT
unsigned int
683 __SYCL_EXPORT
unsigned int
690 template <
typename T>
struct is_vec {
static constexpr
bool value =
false; };
692 static constexpr
bool value =
true;
698 if constexpr (std::is_scalar_v<CoordT>) {
701 return CoordT::size();
707 constexpr
size_t dataSize =
sizeof(DataT);
709 dataSize == 1 || dataSize == 2 || dataSize == 4 || dataSize == 8 ||
711 "Expected input data type to be of size 1, 2, 4, 8, or 16 bytes.");
713 if constexpr (dataSize == 1) {
714 return sycl::bit_cast<uint8_t>(Color);
715 }
else if constexpr (dataSize == 2) {
716 return sycl::bit_cast<uint16_t>(Color);
717 }
else if constexpr (dataSize == 4) {
718 return sycl::bit_cast<uint32_t>(Color);
719 }
else if constexpr (dataSize == 8) {
720 return sycl::bit_cast<sycl::vec<uint32_t, 2>>(Color);
722 return sycl::bit_cast<sycl::vec<uint32_t, 4>>(Color);
728 if constexpr (std::is_scalar_v<CoordT>) {
729 static_assert(std::is_same_v<CoordT, int>,
730 "Expected integer coordinate data type");
732 static_assert(is_vec_v<CoordT>,
"Expected sycl::vec coordinates");
733 static_assert(std::is_same_v<typename CoordT::element_type, int>,
734 "Expected integer coordinates data type");
740 if constexpr (std::is_scalar_v<CoordT>) {
741 static_assert(std::is_same_v<CoordT, float>,
742 "Expected float coordinate data type");
744 static_assert(is_vec_v<CoordT>,
"Expected sycl::vec coordinates");
745 static_assert(std::is_same_v<typename CoordT::element_type, float>,
746 "Expected float coordinates data type");
751 return (
sizeof(DataT) == 1) || (
sizeof(DataT) == 2) || (
sizeof(DataT) == 4) ||
752 (
sizeof(DataT) == 8) || (
sizeof(DataT) == 16);
756 return is_data_size_valid<DataT>() &&
757 (is_vec_v<DataT> || std::is_scalar_v<DataT> ||
758 std::is_floating_point_v<DataT> || std::is_same_v<DataT, sycl::half>);
783 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
785 "Instead use fetch_image.")
811 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
813 const CoordT &
coords [[maybe_unused]]) {
814 detail::assert_unsampled_coords<CoordT>();
815 constexpr
size_t coordSize = detail::coord_size<CoordT>();
816 static_assert(coordSize == 1 || coordSize == 2 || coordSize == 3,
817 "Expected input coordinate to be have 1, 2, or 3 components "
818 "for 1D, 2D and 3D images, respectively.");
820 #ifdef __SYCL_DEVICE_ONLY__
821 if constexpr (detail::is_recognized_standard_type<DataT>()) {
822 return __invoke__ImageRead<DataT>(imageHandle.raw_handle,
coords);
824 static_assert(
sizeof(HintT) ==
sizeof(DataT),
825 "When trying to read a user-defined type, HintT must be of "
826 "the same size as the user-defined DataT.");
827 static_assert(detail::is_recognized_standard_type<HintT>(),
828 "HintT must always be a recognized standard type");
829 return sycl::bit_cast<DataT>(
830 __invoke__ImageRead<HintT>(imageHandle.raw_handle,
coords));
857 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
859 "Instead use sample_image.")
861 const CoordT &
coords [[maybe_unused]]) {
885 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
887 const CoordT &
coords [[maybe_unused]]) {
888 detail::assert_sampled_coords<CoordT>();
889 constexpr
size_t coordSize = detail::coord_size<CoordT>();
890 static_assert(coordSize == 1 || coordSize == 2 || coordSize == 3,
891 "Expected input coordinate to be have 1, 2, or 3 components "
892 "for 1D, 2D and 3D images, respectively.");
894 #ifdef __SYCL_DEVICE_ONLY__
895 if constexpr (detail::is_recognized_standard_type<DataT>()) {
896 return __invoke__ImageRead<DataT>(imageHandle.raw_handle,
coords);
898 static_assert(
sizeof(HintT) ==
sizeof(DataT),
899 "When trying to read a user-defined type, HintT must be of "
900 "the same size as the user-defined DataT.");
901 static_assert(detail::is_recognized_standard_type<HintT>(),
902 "HintT must always be a recognized standard type");
903 return sycl::bit_cast<DataT>(
904 __invoke__ImageRead<HintT>(imageHandle.raw_handle,
coords));
927 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
929 "Instead use sample_mipmap.")
931 const CoordT &
coords [[maybe_unused]],
932 const
float level [[maybe_unused]]) {
953 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
955 "Instead use sample_mipmap.")
956 DataT read_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
957 const CoordT &
coords [[maybe_unused]],
958 const CoordT &
dX [[maybe_unused]],
959 const CoordT &
dY [[maybe_unused]]) {
978 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
980 const CoordT &
coords [[maybe_unused]],
981 const float level [[maybe_unused]]) {
982 detail::assert_sampled_coords<CoordT>();
983 constexpr
size_t coordSize = detail::coord_size<CoordT>();
984 static_assert(coordSize == 1 || coordSize == 2 || coordSize == 3,
985 "Expected input coordinate to be have 1, 2, or 3 components "
986 "for 1D, 2D and 3D images, respectively.");
988 #ifdef __SYCL_DEVICE_ONLY__
989 if constexpr (detail::is_recognized_standard_type<DataT>()) {
990 return __invoke__ImageReadLod<DataT>(imageHandle.raw_handle,
coords,
level);
992 static_assert(
sizeof(HintT) ==
sizeof(DataT),
993 "When trying to read a user-defined type, HintT must be of "
994 "the same size as the user-defined DataT.");
995 static_assert(detail::is_recognized_standard_type<HintT>(),
996 "HintT must always be a recognized standard type");
997 return sycl::bit_cast<DataT>(
998 __invoke__ImageReadLod<HintT>(imageHandle.raw_handle,
coords,
level));
1021 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
1023 const CoordT &
coords [[maybe_unused]],
1024 const CoordT &
dX [[maybe_unused]],
1025 const CoordT &
dY [[maybe_unused]]) {
1026 detail::assert_sampled_coords<CoordT>();
1027 constexpr
size_t coordSize = detail::coord_size<CoordT>();
1028 static_assert(coordSize == 1 || coordSize == 2 || coordSize == 3,
1029 "Expected input coordinates and gradients to have 1, 2, or 3 "
1030 "components for 1D, 2D, and 3D images, respectively.");
1032 #ifdef __SYCL_DEVICE_ONLY__
1033 if constexpr (detail::is_recognized_standard_type<DataT>()) {
1034 return __invoke__ImageReadGrad<DataT>(imageHandle.raw_handle,
coords,
dX,
1037 static_assert(
sizeof(HintT) ==
sizeof(DataT),
1038 "When trying to read a user-defined type, HintT must be of "
1039 "the same size as the user-defined DataT.");
1040 static_assert(detail::is_recognized_standard_type<HintT>(),
1041 "HintT must always be a recognized standard type");
1042 return sycl::bit_cast<DataT>(
1043 __invoke__ImageReadGrad<HintT>(imageHandle.raw_handle,
coords,
dX,
dY));
1066 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
1068 "Instead use sample_mipmap.")
1070 const CoordT &
coords [[maybe_unused]],
1071 const
float level [[maybe_unused]]) {
1092 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
1094 "Instead use sample_mipmap.")
1095 DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
1096 const CoordT &
coords [[maybe_unused]],
1097 const CoordT &
dX [[maybe_unused]],
1098 const CoordT &
dY [[maybe_unused]]) {
1123 template <
typename DataT,
typename H
intT = DataT,
typename CoordT>
1126 const CoordT &
coords [[maybe_unused]],
1127 const int arrayLayer [[maybe_unused]]) {
1128 detail::assert_unsampled_coords<CoordT>();
1129 constexpr
size_t coordSize = detail::coord_size<CoordT>();
1130 static_assert(coordSize == 1 || coordSize == 2,
1131 "Expected input coordinate to be have 1 or 2 components for 1D "
1132 "and 2D images respectively.");
1134 #ifdef __SYCL_DEVICE_ONLY__
1135 if constexpr (detail::is_recognized_standard_type<DataT>()) {
1136 return __invoke__ImageArrayFetch<DataT>(imageHandle.raw_handle,
coords,
1139 static_assert(
sizeof(HintT) ==
sizeof(DataT),
1140 "When trying to fetch a user-defined type, HintT must be of "
1141 "the same size as the user-defined DataT.");
1142 static_assert(detail::is_recognized_standard_type<HintT>(),
1143 "HintT must always be a recognized standard type");
1144 return sycl::bit_cast<DataT>(__invoke__ImageArrayFetch<HintT>(
1145 imageHandle.raw_handle,
coords, arrayLayer));
1162 template <
typename DataT>
1164 const int2 &
coords,
const unsigned int face) {
1165 return fetch_image_array<DataT>(imageHandle,
coords, face);
1178 template <
typename DataT,
typename H
intT = DataT>
1180 const sycl::float3 &dirVec [[maybe_unused]]) {
1182 #ifdef __SYCL_DEVICE_ONLY__
1183 if constexpr (detail::is_recognized_standard_type<DataT>()) {
1184 return __invoke__ImageReadCubemap<DataT, uint64_t>(imageHandle.raw_handle,
1187 static_assert(
sizeof(HintT) ==
sizeof(DataT),
1188 "When trying to read a user-defined type, HintT must be of "
1189 "the same size as the user-defined DataT.");
1190 static_assert(detail::is_recognized_standard_type<HintT>(),
1191 "HintT must always be a recognized standard type");
1192 return sycl::bit_cast<DataT>(__invoke__ImageReadCubemap<DataT, uint64_t>(
1193 imageHandle.raw_handle, dirVec));
1210 template <
typename DataT,
typename CoordT>
1212 const CoordT &
coords [[maybe_unused]],
1213 const DataT &color [[maybe_unused]]) {
1214 detail::assert_unsampled_coords<CoordT>();
1215 constexpr
size_t coordSize = detail::coord_size<CoordT>();
1216 static_assert(coordSize == 1 || coordSize == 2 || coordSize == 3,
1217 "Expected input coordinate to be have 1, 2, or 3 components "
1218 "for 1D, 2D and 3D images, respectively.");
1220 #ifdef __SYCL_DEVICE_ONLY__
1221 if constexpr (detail::is_recognized_standard_type<DataT>()) {
1222 __invoke__ImageWrite((uint64_t)imageHandle.raw_handle,
coords, color);
1226 __invoke__ImageWrite((uint64_t)imageHandle.raw_handle,
coords,
1245 template <
typename DataT,
typename CoordT>
1247 const CoordT &
coords [[maybe_unused]],
1248 const int arrayLayer [[maybe_unused]],
1249 const DataT &color [[maybe_unused]]) {
1250 detail::assert_unsampled_coords<CoordT>();
1251 constexpr
size_t coordSize = detail::coord_size<CoordT>();
1252 static_assert(coordSize == 1 || coordSize == 2,
1253 "Expected input coordinate to be have 1 or 2 components for 1D "
1254 "and 2D images respectively.");
1256 #ifdef __SYCL_DEVICE_ONLY__
1257 if constexpr (detail::is_recognized_standard_type<DataT>()) {
1258 __invoke__ImageArrayWrite(
static_cast<uint64_t
>(imageHandle.raw_handle),
1259 coords, arrayLayer, color);
1263 __invoke__ImageArrayWrite(
static_cast<uint64_t
>(imageHandle.raw_handle),
1281 template <
typename DataT>
1283 const int face,
const DataT &color) {
The context class represents a SYCL context on which kernel functions may be executed.
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
A class that represents image memory.
Defines a shared image data.
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Defines the iteration domain of either a single work-group in a parallel dispatch,...
class sycl::vec ///////////////////////// Provides a cross-patform vector class template that works e...
constexpr size_t coord_size()
constexpr bool is_data_size_valid()
constexpr bool is_recognized_standard_type()
constexpr void assert_sampled_coords()
constexpr void assert_unsampled_coords()
constexpr auto convert_color(DataT Color)
image_mem_handle map_external_image_memory(interop_mem_handle memHandle, const image_descriptor &desc, const sycl::device &syclDevice, const sycl::context &syclContext)
Maps an interop memory handle to an image memory handle (which may have a device optimized memory lay...
sycl::range< 3 > get_image_range(const image_mem_handle memHandle, const sycl::device &syclDevice, const sycl::context &syclContext)
Get the range that describes the image's dimensions.
unsigned int get_image_num_channels(const image_mem_handle memHandle, const sycl::device &syclDevice, const sycl::context &syclContext)
Get the number of channels that describes the image memory.
void write_cubemap(unsampled_image_handle imageHandle, const sycl::int2 &coords, const int face, const DataT &color)
Write to an unsampled cubemap using its handle.
const CoordT const float level
void free_image_mem(image_mem_handle handle, const sycl::device &syclDevice, const sycl::context &syclContext)
[Deprecated] Free image memory
interop_mem_handle import_external_memory(external_mem_descriptor< ExternalMemHandleType > externalMem, const sycl::device &syclDevice, const sycl::context &syclContext)
Import external memory taking an external memory handle (the type of which is dependent on the OS & e...
DataT sample_image(const sampled_image_handle &imageHandle[[maybe_unused]], const CoordT &coords[[maybe_unused]])
Sample data from a sampled image using its handle.
void write_image_array(unsampled_image_handle imageHandle[[maybe_unused]], const CoordT &coords[[maybe_unused]], const int arrayLayer[[maybe_unused]], const DataT &color[[maybe_unused]])
Write to an unsampled image array using its handle.
DataT sample_cubemap(const sampled_image_handle &imageHandle[[maybe_unused]], const sycl::float3 &dirVec[[maybe_unused]])
Sample a cubemap image using its handle.
unsampled_image_handle create_image(image_mem &memHandle, const image_descriptor &desc, const sycl::device &syclDevice, const sycl::context &syclContext)
Create an image and return the device image handle.
const CoordT const CoordT const CoordT & dY
void * pitched_alloc_device(size_t *resultPitch, size_t widthInBytes, size_t height, unsigned int elementSizeBytes, const sycl::queue &syclQueue)
Allocate pitched USM image memory.
DataT fetch_cubemap(const unsampled_image_handle &imageHandle, const int2 &coords, const unsigned int face)
Fetch data from an unsampled cubemap image using its handle.
image_mem_handle map_external_memory_array(interop_mem_handle memHandle, const image_descriptor &desc, const sycl::device &syclDevice, const sycl::context &syclContext)
[Deprecated] Maps an interop memory handle to an image memory handle (which may have a device optimiz...
DataT fetch_image(const unsampled_image_handle &imageHandle[[maybe_unused]], const CoordT &coords[[maybe_unused]])
Fetch data from an unsampled image using its handle.
DataT sample_mipmap(const sampled_image_handle &imageHandle[[maybe_unused]], const CoordT &coords[[maybe_unused]], const float level[[maybe_unused]])
Sample a mipmap image using its handle with LOD filtering.
image_mem_handle alloc_image_mem(const image_descriptor &desc, const sycl::device &syclDevice, const sycl::context &syclContext)
Allocate image memory based on image_descriptor.
__SYCL_DEPRECATED("read_image for standard unsampled images is deprecated. " "Instead use fetch_image.") DataT read_image(const unsampled_image_handle &imageHandle
[Deprecated] Read an unsampled image using its handle
void release_external_memory(interop_mem_handle interopHandle, const sycl::device &syclDevice, const sycl::context &syclContext)
Release external memory.
void destroy_external_semaphore(interop_semaphore_handle semaphoreHandle, const sycl::device &syclDevice, const sycl::context &syclContext)
Destroy the external semaphore handle.
image_mem_handle get_mip_level_mem_handle(const image_mem_handle mipMem, const unsigned int level, const sycl::device &syclDevice, const sycl::context &syclContext)
Retrieve the memory handle to an individual mipmap image.
void free_mipmap_mem(image_mem_handle handle, const sycl::device &syclDevice, const sycl::context &syclContext)
[Deprecated] Free mipmap memory
interop_semaphore_handle import_external_semaphore(external_semaphore_descriptor< ExternalSemaphoreHandleType > externalSemaphoreDesc, const sycl::device &syclDevice, const sycl::context &syclContext)
Import external semaphore taking an external semaphore handle (the type of which is dependent on the ...
void destroy_image_handle(unsampled_image_handle &imageHandle, const sycl::device &syclDevice, const sycl::context &syclContext)
Destroy an unsampled image handle.
DataT fetch_image_array(const unsampled_image_handle &imageHandle[[maybe_unused]], const CoordT &coords[[maybe_unused]], const int arrayLayer[[maybe_unused]])
Fetch data from an unsampled image array using its handle.
const CoordT const CoordT & dX
image_type
image type enum
void write_image(unsampled_image_handle imageHandle[[maybe_unused]], const CoordT &coords[[maybe_unused]], const DataT &color[[maybe_unused]])
Write to an unsampled image using its handle.
sycl::image_channel_type get_image_channel_type(const image_mem_handle memHandle, const sycl::device &syclDevice, const sycl::context &syclContext)
Get the channel type that describes the image memory.
image_mem_handle alloc_mipmap_mem(const image_descriptor &desc, const sycl::device &syclDevice, const sycl::context &syclContext)
[Deprecated] Allocate mipmap memory based on image_descriptor
Opaque external memory descriptor type.
A struct to describe the properties of an image.
Opaque image memory handle type.
Opaque interop memory handle type.
Opaque interop semaphore handle type.
Opaque sampled image handle type.
raw_image_handle_type raw_handle
pi_uint64 raw_image_handle_type
sampled_image_handle(raw_image_handle_type raw_image_handle)
Opaque unsampled image handle type.
pi_uint64 raw_image_handle_type
raw_image_handle_type raw_handle
unsampled_image_handle(raw_image_handle_type raw_image_handle)