DPC++ Runtime
Runtime libraries for oneAPI DPC++
bindless_images.hpp
Go to the documentation of this file.
1 //==----------- bindless_images.hpp --- SYCL bindless images ---------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/context.hpp> // for context
12 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
13 #include <sycl/detail/pi.h> // for pi_uint64
14 #include <sycl/device.hpp> // for device
15 #include <sycl/ext/oneapi/bindless_images_descriptor.hpp> // for image_desc...
16 #include <sycl/ext/oneapi/bindless_images_interop.hpp> // for interop_me...
17 #include <sycl/ext/oneapi/bindless_images_memory.hpp> // for image_mem_...
18 #include <sycl/ext/oneapi/bindless_images_sampler.hpp> // for bindless_i...
19 #include <sycl/image.hpp> // for image_chan...
20 #include <sycl/queue.hpp> // for queue
21 #include <sycl/range.hpp> // for range
22 
23 #include <assert.h> // for assert
24 #include <stddef.h> // for size_t
25 #include <type_traits> // for is_scalar
26 
27 #ifdef __SYCL_DEVICE_ONLY__
28 #include <sycl/detail/image_ocl_types.hpp> // for __invoke__*
29 #endif
30 
31 namespace sycl {
32 inline namespace _V1 {
33 namespace ext::oneapi::experimental {
34 
38 
40 
42  : raw_handle(raw_image_handle) {}
43 
45 };
46 
50 
52 
54  : raw_handle(raw_image_handle) {}
55 
57 };
58 
67 __SYCL_EXPORT image_mem_handle
68 alloc_image_mem(const image_descriptor &desc, const sycl::device &syclDevice,
69  const sycl::context &syclContext);
70 
78 __SYCL_EXPORT image_mem_handle alloc_image_mem(const image_descriptor &desc,
79  const sycl::queue &syclQueue);
80 
88 __SYCL_EXPORT_DEPRECATED("Distinct image frees are deprecated. "
89  "Instead use overload that accepts image_type.")
90 void free_image_mem(image_mem_handle handle, const sycl::device &syclDevice,
91  const sycl::context &syclContext);
92 
99 __SYCL_EXPORT_DEPRECATED("Distinct image frees are deprecated. "
100  "Instead use overload that accepts image_type.")
101 void free_image_mem(image_mem_handle handle, const sycl::queue &syclQueue);
102 
111 __SYCL_EXPORT void free_image_mem(image_mem_handle handle, image_type imageType,
112  const sycl::device &syclDevice,
113  const sycl::context &syclContext);
114 
122 __SYCL_EXPORT void free_image_mem(image_mem_handle handle, image_type imageType,
123  const sycl::queue &syclQueue);
124 
133 __SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
134  "Instead use alloc_image_mem().")
136  const sycl::device &syclDevice,
137  const sycl::context &syclContext);
138 
146 __SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
147  "Instead use alloc_image_mem().")
149  const sycl::device &syclQueue);
150 
158 __SYCL_EXPORT_DEPRECATED(
159  "Distinct mipmap frees are deprecated. "
160  "Instead use free_image_mem() that accepts image_type.")
161 void free_mipmap_mem(image_mem_handle handle, const sycl::device &syclDevice,
162  const sycl::context &syclContext);
163 
170 __SYCL_EXPORT_DEPRECATED(
171  "Distinct mipmap frees are deprecated. "
172  "Instead use free_image_mem() that accepts image_type.")
173 void free_mipmap_mem(image_mem_handle handle, const sycl::queue &syclQueue);
174 
185  const image_mem_handle mipMem, const unsigned int level,
186  const sycl::device &syclDevice, const sycl::context &syclContext);
187 
197  const image_mem_handle mipMem, const unsigned int level,
198  const sycl::queue &syclQueue);
199 
212 template <typename ExternalMemHandleType>
214  external_mem_descriptor<ExternalMemHandleType> externalMem,
215  const sycl::device &syclDevice, const sycl::context &syclContext);
216 
228 template <typename ExternalMemHandleType>
230  external_mem_descriptor<ExternalMemHandleType> externalMem,
231  const sycl::queue &syclQueue);
232 
243 __SYCL_EXPORT_DEPRECATED("map_external_memory_array is deprecated."
246  const image_descriptor &desc,
247  const sycl::device &syclDevice,
248  const sycl::context &syclContext);
249 
259 __SYCL_EXPORT_DEPRECATED("map_external_memory_array is deprecated."
262  const image_descriptor &desc,
263  const sycl::queue &syclQueue);
264 
275 __SYCL_EXPORT
277  const image_descriptor &desc,
278  const sycl::device &syclDevice,
279  const sycl::context &syclContext);
280 
290 __SYCL_EXPORT
292  const image_descriptor &desc,
293  const sycl::queue &syclQueue);
294 
308 template <typename ExternalSemaphoreHandleType>
310  external_semaphore_descriptor<ExternalSemaphoreHandleType>
311  externalSemaphoreDesc,
312  const sycl::device &syclDevice, const sycl::context &syclContext);
313 
325 template <typename ExternalSemaphoreHandleType>
327  external_semaphore_descriptor<ExternalSemaphoreHandleType>
328  externalSemaphoreDesc,
329  const sycl::queue &syclQueue);
330 
340 __SYCL_EXPORT void
342  const sycl::device &syclDevice,
343  const sycl::context &syclContext);
344 
352 __SYCL_EXPORT void
354  const sycl::queue &syclQueue);
355 
365 __SYCL_EXPORT void release_external_memory(interop_mem_handle interopHandle,
366  const sycl::device &syclDevice,
367  const sycl::context &syclContext);
368 
376 __SYCL_EXPORT void release_external_memory(interop_mem_handle interopHandle,
377  const sycl::queue &syclQueue);
378 
388 __SYCL_EXPORT unsampled_image_handle
389 create_image(image_mem &memHandle, const image_descriptor &desc,
390  const sycl::device &syclDevice, const sycl::context &syclContext);
391 
400 __SYCL_EXPORT unsampled_image_handle create_image(image_mem &memHandle,
401  const image_descriptor &desc,
402  const sycl::queue &syclQueue);
403 
413 __SYCL_EXPORT unsampled_image_handle
414 create_image(image_mem_handle memHandle, const image_descriptor &desc,
415  const sycl::device &syclDevice, const sycl::context &syclContext);
416 
426  const image_descriptor &desc,
427  const sycl::queue &syclQueue);
428 
440 __SYCL_EXPORT sampled_image_handle
441 create_image(void *imgMem, size_t pitch, const bindless_image_sampler &sampler,
442  const image_descriptor &desc, const sycl::device &syclDevice,
443  const sycl::context &syclContext);
444 
455 __SYCL_EXPORT sampled_image_handle
456 create_image(void *imgMem, size_t pitch, const bindless_image_sampler &sampler,
457  const image_descriptor &desc, const sycl::queue &syclQueue);
458 
469 __SYCL_EXPORT sampled_image_handle
470 create_image(image_mem &memHandle, const bindless_image_sampler &sampler,
471  const image_descriptor &desc, const sycl::device &syclDevice,
472  const sycl::context &syclContext);
473 
483 __SYCL_EXPORT sampled_image_handle
484 create_image(image_mem &memHandle, const bindless_image_sampler &sampler,
485  const image_descriptor &desc, const sycl::queue &syclQueue);
486 
497 __SYCL_EXPORT sampled_image_handle
498 create_image(image_mem_handle memHandle, const bindless_image_sampler &sampler,
499  const image_descriptor &desc, const sycl::device &syclDevice,
500  const sycl::context &syclContext);
501 
511 __SYCL_EXPORT sampled_image_handle
512 create_image(image_mem_handle memHandle, const bindless_image_sampler &sampler,
513  const image_descriptor &desc, const sycl::queue &syclQueue);
514 
523 __SYCL_EXPORT void destroy_image_handle(unsampled_image_handle &imageHandle,
524  const sycl::device &syclDevice,
525  const sycl::context &syclContext);
526 
534 __SYCL_EXPORT void destroy_image_handle(unsampled_image_handle &imageHandle,
535  const sycl::queue &syclQueue);
536 
545 __SYCL_EXPORT void destroy_image_handle(sampled_image_handle &imageHandle,
546  const sycl::device &syclDevice,
547  const sycl::context &syclContext);
548 
556 __SYCL_EXPORT void destroy_image_handle(sampled_image_handle &imageHandle,
557  const sycl::queue &syclQueue);
558 
569 __SYCL_EXPORT void *pitched_alloc_device(size_t *resultPitch,
570  size_t widthInBytes, size_t height,
571  unsigned int elementSizeBytes,
572  const sycl::queue &syclQueue);
573 
585 __SYCL_EXPORT void *pitched_alloc_device(size_t *resultPitch,
586  size_t widthInBytes, size_t height,
587  unsigned int elementSizeBytes,
588  const sycl::device &syclDevice,
589  const sycl::context &syclContext);
590 
599 __SYCL_EXPORT void *pitched_alloc_device(size_t *resultPitch,
600  const image_descriptor &desc,
601  const sycl::queue &syclQueue);
602 
612 __SYCL_EXPORT void *pitched_alloc_device(size_t *resultPitch,
613  const image_descriptor &desc,
614  const sycl::device &syclDevice,
615  const sycl::context &syclContext);
616 
625 __SYCL_EXPORT sycl::range<3> get_image_range(const image_mem_handle memHandle,
626  const sycl::device &syclDevice,
627  const sycl::context &syclContext);
628 
636 __SYCL_EXPORT sycl::range<3> get_image_range(const image_mem_handle memHandle,
637  const sycl::queue &syclQueue);
638 
647 __SYCL_EXPORT sycl::image_channel_type
649  const sycl::device &syclDevice,
650  const sycl::context &syclContext);
651 
659 __SYCL_EXPORT sycl::image_channel_type
661  const sycl::queue &syclQueue);
662 
671 __SYCL_EXPORT unsigned int
673  const sycl::device &syclDevice,
674  const sycl::context &syclContext);
675 
683 __SYCL_EXPORT unsigned int
685  const sycl::queue &syclQueue);
686 
687 namespace detail {
688 
689 // is sycl::vec
690 template <typename T> struct is_vec { static constexpr bool value = false; };
691 template <typename T, int N> struct is_vec<sycl::vec<T, N>> {
692  static constexpr bool value = true;
693 };
694 template <typename T> inline constexpr bool is_vec_v = is_vec<T>::value;
695 
696 // Get the number of coordinates
697 template <typename CoordT> constexpr size_t coord_size() {
698  if constexpr (std::is_scalar_v<CoordT>) {
699  return 1;
700  } else {
701  return CoordT::size();
702  }
703 }
704 
705 // bit_cast Color to a type the backend is known to accept
706 template <typename DataT> constexpr auto convert_color(DataT Color) {
707  constexpr size_t dataSize = sizeof(DataT);
708  static_assert(
709  dataSize == 1 || dataSize == 2 || dataSize == 4 || dataSize == 8 ||
710  dataSize == 16,
711  "Expected input data type to be of size 1, 2, 4, 8, or 16 bytes.");
712 
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);
721  } else { // dataSize == 16
722  return sycl::bit_cast<sycl::vec<uint32_t, 4>>(Color);
723  }
724 }
725 
726 // assert coords or elements of coords is of an integer type
727 template <typename CoordT> constexpr void assert_unsampled_coords() {
728  if constexpr (std::is_scalar_v<CoordT>) {
729  static_assert(std::is_same_v<CoordT, int>,
730  "Expected integer coordinate data type");
731  } else {
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");
735  }
736 }
737 
738 // assert coords or elements of coords is of a float type
739 template <typename CoordT> constexpr void assert_sampled_coords() {
740  if constexpr (std::is_scalar_v<CoordT>) {
741  static_assert(std::is_same_v<CoordT, float>,
742  "Expected float coordinate data type");
743  } else {
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");
747  }
748 }
749 
750 template <typename DataT> constexpr bool is_data_size_valid() {
751  return (sizeof(DataT) == 1) || (sizeof(DataT) == 2) || (sizeof(DataT) == 4) ||
752  (sizeof(DataT) == 8) || (sizeof(DataT) == 16);
753 }
754 
755 template <typename DataT> constexpr bool is_recognized_standard_type() {
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>);
759 }
760 
761 } // namespace detail
762 
783 template <typename DataT, typename HintT = DataT, typename CoordT>
784 __SYCL_DEPRECATED("read_image for standard unsampled images is deprecated. "
785  "Instead use fetch_image.")
786 DataT read_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
787  const CoordT &coords [[maybe_unused]]) {
788  return fetch_image(imageHandle, coords);
789 }
790 
811 template <typename DataT, typename HintT = DataT, typename CoordT>
812 DataT fetch_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
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.");
819 
820 #ifdef __SYCL_DEVICE_ONLY__
821  if constexpr (detail::is_recognized_standard_type<DataT>()) {
822  return __invoke__ImageRead<DataT>(imageHandle.raw_handle, coords);
823  } else {
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));
831  }
832 #else
833  assert(false); // Bindless images not yet implemented on host
834 #endif
835 }
836 
857 template <typename DataT, typename HintT = DataT, typename CoordT>
858 __SYCL_DEPRECATED("read_image for standard sampled images is deprecated. "
859  "Instead use sample_image.")
860 DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
861  const CoordT &coords [[maybe_unused]]) {
862  return sample_image(imageHandle, coords);
863 }
864 
885 template <typename DataT, typename HintT = DataT, typename CoordT>
886 DataT sample_image(const sampled_image_handle &imageHandle [[maybe_unused]],
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.");
893 
894 #ifdef __SYCL_DEVICE_ONLY__
895  if constexpr (detail::is_recognized_standard_type<DataT>()) {
896  return __invoke__ImageRead<DataT>(imageHandle.raw_handle, coords);
897  } else {
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));
905  }
906 #else
907  assert(false); // Bindless images not yet implemented on host.
908 #endif
909 }
910 
927 template <typename DataT, typename HintT = DataT, typename CoordT>
928 __SYCL_DEPRECATED("read_mipmap has been deprecated. "
929  "Instead use sample_mipmap.")
930 DataT read_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
931  const CoordT &coords [[maybe_unused]],
932  const float level [[maybe_unused]]) {
933  return sample_mipmap(imageHandle, coords, level);
934 }
935 
953 template <typename DataT, typename HintT = DataT, typename CoordT>
954 __SYCL_DEPRECATED("read_mipmap has been deprecated. "
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]]) {
960  return sample_mipmap(imageHandle, coords, dX, dY);
961 }
962 
978 template <typename DataT, typename HintT = DataT, typename CoordT>
979 DataT sample_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
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.");
987 
988 #ifdef __SYCL_DEVICE_ONLY__
989  if constexpr (detail::is_recognized_standard_type<DataT>()) {
990  return __invoke__ImageReadLod<DataT>(imageHandle.raw_handle, coords, level);
991  } else {
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));
999  }
1000 #else
1001  assert(false); // Bindless images not yet implemented on host
1002 #endif
1003 }
1004 
1021 template <typename DataT, typename HintT = DataT, typename CoordT>
1022 DataT sample_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
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.");
1031 
1032 #ifdef __SYCL_DEVICE_ONLY__
1033  if constexpr (detail::is_recognized_standard_type<DataT>()) {
1034  return __invoke__ImageReadGrad<DataT>(imageHandle.raw_handle, coords, dX,
1035  dY);
1036  } else {
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));
1044  }
1045 #else
1046  assert(false); // Bindless images not yet implemented on host
1047 #endif
1048 }
1049 
1066 template <typename DataT, typename HintT = DataT, typename CoordT>
1067 __SYCL_DEPRECATED("read_image for mipmaps is deprecated. "
1068  "Instead use sample_mipmap.")
1069 DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
1070  const CoordT &coords [[maybe_unused]],
1071  const float level [[maybe_unused]]) {
1072  return sample_mipmap(imageHandle, coords, level);
1073 }
1074 
1092 template <typename DataT, typename HintT = DataT, typename CoordT>
1093 __SYCL_DEPRECATED("read_image for mipmaps is deprecated. "
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]]) {
1099  return sample_mipmap(imageHandle, coords, dX, dY);
1100 }
1101 
1123 template <typename DataT, typename HintT = DataT, typename CoordT>
1125  [[maybe_unused]],
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.");
1133 
1134 #ifdef __SYCL_DEVICE_ONLY__
1135  if constexpr (detail::is_recognized_standard_type<DataT>()) {
1136  return __invoke__ImageArrayFetch<DataT>(imageHandle.raw_handle, coords,
1137  arrayLayer);
1138  } else {
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));
1146  }
1147 #else
1148  assert(false); // Bindless images not yet implemented on host.
1149 #endif
1150 }
1151 
1162 template <typename DataT>
1163 DataT fetch_cubemap(const unsampled_image_handle &imageHandle,
1164  const int2 &coords, const unsigned int face) {
1165  return fetch_image_array<DataT>(imageHandle, coords, face);
1166 }
1167 
1178 template <typename DataT, typename HintT = DataT>
1179 DataT sample_cubemap(const sampled_image_handle &imageHandle [[maybe_unused]],
1180  const sycl::float3 &dirVec [[maybe_unused]]) {
1181 
1182 #ifdef __SYCL_DEVICE_ONLY__
1183  if constexpr (detail::is_recognized_standard_type<DataT>()) {
1184  return __invoke__ImageReadCubemap<DataT, uint64_t>(imageHandle.raw_handle,
1185  dirVec);
1186  } else {
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));
1194  }
1195 #else
1196  assert(false); // Bindless images not yet implemented on host
1197 #endif
1198 }
1199 
1210 template <typename DataT, typename CoordT>
1211 void write_image(unsampled_image_handle imageHandle [[maybe_unused]],
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.");
1219 
1220 #ifdef __SYCL_DEVICE_ONLY__
1221  if constexpr (detail::is_recognized_standard_type<DataT>()) {
1222  __invoke__ImageWrite((uint64_t)imageHandle.raw_handle, coords, color);
1223  } else {
1224  // Convert DataT to a supported backend write type when user-defined type is
1225  // passed
1226  __invoke__ImageWrite((uint64_t)imageHandle.raw_handle, coords,
1227  detail::convert_color(color));
1228  }
1229 #else
1230  assert(false); // Bindless images not yet implemented on host
1231 #endif
1232 }
1233 
1245 template <typename DataT, typename CoordT>
1246 void write_image_array(unsampled_image_handle imageHandle [[maybe_unused]],
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.");
1255 
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);
1260  } else {
1261  // Convert DataT to a supported backend write type when user-defined type is
1262  // passed
1263  __invoke__ImageArrayWrite(static_cast<uint64_t>(imageHandle.raw_handle),
1264  coords, arrayLayer, detail::convert_color(color));
1265  }
1266 #else
1267  assert(false); // Bindless images not yet implemented on host.
1268 #endif
1269 }
1270 
1281 template <typename DataT>
1282 void write_cubemap(unsampled_image_handle imageHandle, const sycl::int2 &coords,
1283  const int face, const DataT &color) {
1284  return write_image_array(imageHandle, coords, face, color);
1285 }
1286 
1287 } // namespace ext::oneapi::experimental
1288 } // namespace _V1
1289 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Defines a shared image data.
Definition: image.hpp:443
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:111
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: range.hpp:26
class sycl::vec ///////////////////////// Provides a cross-patform vector class template that works e...
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.
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
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
image_channel_type
Definition: image.hpp:74
Definition: access.hpp:18
uint64_t pi_uint64
Definition: pi.h:214
A struct to describe the properties of an image.
sampled_image_handle(raw_image_handle_type raw_image_handle)
unsampled_image_handle(raw_image_handle_type raw_image_handle)