@@ -633,15 +633,26 @@ get_image_num_channels(const image_mem_handle memHandle,
633
633
const sycl::queue &syclQueue);
634
634
635
635
namespace detail {
636
+
637
+ // is sycl::vec
638
+ template <typename T> struct is_vec {
639
+ static constexpr bool value = false ;
640
+ };
641
+ template <typename T, int N> struct is_vec <sycl::vec<T, N>> {
642
+ static constexpr bool value = true ;
643
+ };
644
+ template <typename T> inline constexpr bool is_vec_v = is_vec<T>::value;
645
+
636
646
// Get the number of coordinates
637
647
template <typename CoordT> constexpr size_t coord_size () {
638
- if constexpr (std::is_scalar <CoordT>::value ) {
648
+ if constexpr (std::is_scalar_v <CoordT>) {
639
649
return 1 ;
640
650
} else {
641
651
return CoordT::size ();
642
652
}
643
653
}
644
654
655
+ #if defined(__NVPTX__)
645
656
// bit_cast Color to a type the NVPTX backend is known to accept
646
657
template <typename DataT> constexpr auto convert_color_nvptx (DataT Color) {
647
658
constexpr size_t dataSize = sizeof (DataT);
@@ -662,15 +673,39 @@ template <typename DataT> constexpr auto convert_color_nvptx(DataT Color) {
662
673
return sycl::bit_cast<sycl::vec<uint32_t , 4 >>(Color);
663
674
}
664
675
}
676
+ #endif
677
+
678
+ // assert coords or elements of coords is of an integer type
679
+ template <typename CoordT> constexpr void assert_unsampled_coords () {
680
+ if constexpr (std::is_scalar_v<CoordT>) {
681
+ static_assert (std::is_same_v<CoordT, int >,
682
+ " Expected integer coordinate data type" );
683
+ } else {
684
+ static_assert (is_vec_v<CoordT>, " Expected sycl::vec coordinates" );
685
+ static_assert (std::is_same_v<typename CoordT::element_type, int >,
686
+ " Expected integer coordinates data type" );
687
+ }
688
+ }
665
689
690
+ // assert coords or elements of coords is of a float type
691
+ template <typename CoordT> constexpr void assert_sampled_coords () {
692
+ if constexpr (std::is_scalar_v<CoordT>) {
693
+ static_assert (std::is_same_v<CoordT, float >,
694
+ " Expected float coordinate data type" );
695
+ } else {
696
+ static_assert (is_vec_v<CoordT>, " Expected sycl::vec coordinates" );
697
+ static_assert (std::is_same_v<typename CoordT::element_type, float >,
698
+ " Expected float coordinates data type" );
699
+ }
700
+ }
666
701
} // namespace detail
667
702
668
703
/* *
669
704
* @brief Read an unsampled image using its handle
670
705
*
671
706
* @tparam DataT The return type
672
707
* @tparam CoordT The input coordinate type. e.g. int, int2, or int4 for
673
- * 1D, 2D, and 3D respectively
708
+ * 1D, 2D, and 3D, respectively
674
709
* @param imageHandle The image handle
675
710
* @param coords The coordinates at which to fetch image data
676
711
* @return Image data
@@ -684,10 +719,11 @@ template <typename DataT> constexpr auto convert_color_nvptx(DataT Color) {
684
719
template <typename DataT, typename CoordT>
685
720
DataT read_image (const unsampled_image_handle &imageHandle [[maybe_unused]],
686
721
const CoordT &coords [[maybe_unused]]) {
722
+ detail::assert_unsampled_coords<CoordT>();
687
723
constexpr size_t coordSize = detail::coord_size<CoordT>();
688
724
static_assert (coordSize == 1 || coordSize == 2 || coordSize == 4 ,
689
725
" Expected input coordinate to be have 1, 2, or 4 components "
690
- " for 1D, 2D and 3D images respectively." );
726
+ " for 1D, 2D and 3D images, respectively." );
691
727
692
728
#ifdef __SYCL_DEVICE_ONLY__
693
729
#if defined(__NVPTX__)
@@ -705,7 +741,7 @@ DataT read_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
705
741
*
706
742
* @tparam DataT The return type
707
743
* @tparam CoordT The input coordinate type. e.g. float, float2, or float4 for
708
- * 1D, 2D, and 3D respectively
744
+ * 1D, 2D, and 3D, respectively
709
745
* @param imageHandle The image handle
710
746
* @param coords The coordinates at which to fetch image data
711
747
* @return Sampled image data
@@ -719,10 +755,11 @@ DataT read_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
719
755
template <typename DataT, typename CoordT>
720
756
DataT read_image (const sampled_image_handle &imageHandle [[maybe_unused]],
721
757
const CoordT &coords [[maybe_unused]]) {
758
+ detail::assert_sampled_coords<CoordT>();
722
759
constexpr size_t coordSize = detail::coord_size<CoordT>();
723
760
static_assert (coordSize == 1 || coordSize == 2 || coordSize == 4 ,
724
761
" Expected input coordinate to be have 1, 2, or 4 components "
725
- " for 1D, 2D and 3D images respectively." );
762
+ " for 1D, 2D and 3D images, respectively." );
726
763
727
764
#ifdef __SYCL_DEVICE_ONLY__
728
765
#if defined(__NVPTX__)
@@ -740,7 +777,7 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
740
777
*
741
778
* @tparam DataT The return type
742
779
* @tparam CoordT The input coordinate type. e.g. float, float2, or float4 for
743
- * 1D, 2D, and 3D respectively
780
+ * 1D, 2D, and 3D, respectively
744
781
* @param imageHandle The mipmap image handle
745
782
* @param coords The coordinates at which to fetch mipmap image data
746
783
* @param level The mipmap level at which to sample
@@ -750,10 +787,11 @@ template <typename DataT, typename CoordT>
750
787
DataT read_image (const sampled_image_handle &imageHandle [[maybe_unused]],
751
788
const CoordT &coords [[maybe_unused]],
752
789
const float level [[maybe_unused]]) {
790
+ detail::assert_sampled_coords<CoordT>();
753
791
constexpr size_t coordSize = detail::coord_size<CoordT>();
754
792
static_assert (coordSize == 1 || coordSize == 2 || coordSize == 4 ,
755
793
" Expected input coordinate to be have 1, 2, or 4 components "
756
- " for 1D, 2D and 3D images respectively." );
794
+ " for 1D, 2D and 3D images, respectively." );
757
795
758
796
#ifdef __SYCL_DEVICE_ONLY__
759
797
#if defined(__NVPTX__)
@@ -771,7 +809,7 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
771
809
*
772
810
* @tparam DataT The return type
773
811
* @tparam CoordT The input coordinate type. e.g. float, float2, or float4 for
774
- * 1D, 2D, and 3D respectively
812
+ * 1D, 2D, and 3D, respectively
775
813
* @param imageHandle The mipmap image handle
776
814
* @param coords The coordinates at which to fetch mipmap image data
777
815
* @param dX Screen space gradient in the x dimension
@@ -783,11 +821,11 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
783
821
const CoordT &coords [[maybe_unused]],
784
822
const CoordT &dX [[maybe_unused]],
785
823
const CoordT &dY [[maybe_unused]]) {
824
+ detail::assert_sampled_coords<CoordT>();
786
825
constexpr size_t coordSize = detail::coord_size<CoordT>();
787
826
static_assert (coordSize == 1 || coordSize == 2 || coordSize == 4 ,
788
- " Expected input coordinate and gradient to have 1, 2, or 4 "
789
- " components "
790
- " for 1D, 2D and 3D images respectively." );
827
+ " Expected input coordinates and gradients to have 1, 2, or 4 "
828
+ " components for 1D, 2D, and 3D images, respectively." );
791
829
792
830
#ifdef __SYCL_DEVICE_ONLY__
793
831
#if defined(__NVPTX__)
@@ -805,23 +843,24 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
805
843
*
806
844
* @tparam DataT The data type to write
807
845
* @tparam CoordT The input coordinate type. e.g. int, int2, or int4 for
808
- * 1D, 2D, and 3D respectively
846
+ * 1D, 2D, and 3D, respectively
809
847
* @param imageHandle The image handle
810
848
* @param coords The coordinates at which to write image data
811
849
*/
812
850
template <typename DataT, typename CoordT>
813
851
void write_image (const unsampled_image_handle &imageHandle [[maybe_unused]],
814
- const CoordT &Coords [[maybe_unused]],
815
- const DataT &Color [[maybe_unused]]) {
852
+ const CoordT &coords [[maybe_unused]],
853
+ const DataT &color [[maybe_unused]]) {
854
+ detail::assert_unsampled_coords<CoordT>();
816
855
constexpr size_t coordSize = detail::coord_size<CoordT>();
817
856
static_assert (coordSize == 1 || coordSize == 2 || coordSize == 4 ,
818
857
" Expected input coordinate to be have 1, 2, or 4 components "
819
- " for 1D, 2D and 3D images respectively." );
858
+ " for 1D, 2D and 3D images, respectively." );
820
859
821
860
#ifdef __SYCL_DEVICE_ONLY__
822
861
#if defined(__NVPTX__)
823
- __invoke__ImageWrite ((uint64_t )imageHandle.raw_handle , Coords ,
824
- detail::convert_color_nvptx (Color ));
862
+ __invoke__ImageWrite ((uint64_t )imageHandle.raw_handle , coords ,
863
+ detail::convert_color_nvptx (color ));
825
864
#else
826
865
// TODO: add SPIRV part for unsampled image write
827
866
#endif
0 commit comments