@@ -50,8 +50,7 @@ struct sampled_image_handle {
50
50
51
51
sampled_image_handle () : raw_handle(~0 ) {}
52
52
53
- sampled_image_handle (raw_image_handle_type raw_image_handle)
54
- : raw_handle(raw_image_handle) {}
53
+ sampled_image_handle (raw_image_handle_type handle) : raw_handle(handle) {}
55
54
56
55
raw_image_handle_type raw_handle;
57
56
};
@@ -792,6 +791,43 @@ template <typename DataT> constexpr bool is_recognized_standard_type() {
792
791
std::is_floating_point_v<DataT> || std::is_same_v<DataT, sycl::half>);
793
792
}
794
793
794
+ #ifdef __SYCL_DEVICE_ONLY__
795
+
796
+ // Image types used for generating SPIR-V
797
+ template <int NDims>
798
+ using OCLImageTyRead =
799
+ typename sycl::detail::opencl_image_type<NDims, sycl::access::mode::read,
800
+ sycl::access::target::image>::type;
801
+
802
+ template <int NDims>
803
+ using OCLImageTyWrite =
804
+ typename sycl::detail::opencl_image_type<NDims, sycl::access::mode::write,
805
+ sycl::access::target::image>::type;
806
+
807
+ // Macros are required because it is not legal for a function to return
808
+ // a variable of type 'opencl_image_type'.
809
+ #if defined(__SPIR__)
810
+ #define CONVERT_HANDLE_TO_IMAGE (raw_handle, ImageType ) \
811
+ __spirv_ConvertHandleToImageINTEL<ImageType>(raw_handle)
812
+
813
+ #define CONVERT_HANDLE_TO_SAMPLED_IMAGE (raw_handle, NDims ) \
814
+ __spirv_ConvertHandleToSampledImageINTEL< \
815
+ typename sycl::detail::sampled_opencl_image_type< \
816
+ detail::OCLImageTyRead<NDims>>::type>(raw_handle)
817
+
818
+ #define FETCH_UNSAMPLED_IMAGE (DataT, raw_handle, coords ) \
819
+ __invoke__ImageRead<DataT>(raw_handle, coords)
820
+ #else
821
+ #define CONVERT_HANDLE_TO_IMAGE (raw_handle, ImageType ) raw_handle
822
+
823
+ #define CONVERT_HANDLE_TO_SAMPLED_IMAGE (raw_handle, NDims ) raw_handle
824
+
825
+ #define FETCH_UNSAMPLED_IMAGE (DataT, raw_handle, coords ) \
826
+ __invoke__ImageFetch<DataT>(raw_handle, coords)
827
+ #endif
828
+
829
+ #endif
830
+
795
831
} // namespace detail
796
832
797
833
/* *
@@ -826,15 +862,23 @@ DataT fetch_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
826
862
827
863
#ifdef __SYCL_DEVICE_ONLY__
828
864
if constexpr (detail::is_recognized_standard_type<DataT>()) {
829
- return __invoke__ImageFetch<DataT>(imageHandle.raw_handle , coords);
865
+ return FETCH_UNSAMPLED_IMAGE (
866
+ DataT,
867
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
868
+ detail::OCLImageTyRead<coordSize>),
869
+ coords);
870
+
830
871
} else {
831
872
static_assert (sizeof (HintT) == sizeof (DataT),
832
873
" When trying to read a user-defined type, HintT must be of "
833
874
" the same size as the user-defined DataT." );
834
875
static_assert (detail::is_recognized_standard_type<HintT>(),
835
876
" HintT must always be a recognized standard type" );
836
- return sycl::bit_cast<DataT>(
837
- __invoke__ImageFetch<HintT>(imageHandle.raw_handle , coords));
877
+ return sycl::bit_cast<DataT>(FETCH_UNSAMPLED_IMAGE (
878
+ HintT,
879
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
880
+ detail::OCLImageTyRead<coordSize>),
881
+ coords));
838
882
}
839
883
#else
840
884
assert (false ); // Bindless images not yet implemented on host
@@ -907,10 +951,13 @@ DataT fetch_image(const sampled_image_handle &imageHandle [[maybe_unused]],
907
951
908
952
#ifdef __SYCL_DEVICE_ONLY__
909
953
if constexpr (detail::is_recognized_standard_type<DataT>()) {
910
- return __invoke__SampledImageFetch<DataT>(imageHandle.raw_handle , coords);
954
+ return __invoke__SampledImageFetch<DataT>(
955
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
956
+ coords);
911
957
} else {
912
- return sycl::bit_cast<DataT>(
913
- __invoke__SampledImageFetch<HintT>(imageHandle.raw_handle , coords));
958
+ return sycl::bit_cast<DataT>(__invoke__SampledImageFetch<HintT>(
959
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
960
+ coords));
914
961
}
915
962
#else
916
963
assert (false ); // Bindless images not yet implemented on host.
@@ -954,10 +1001,13 @@ DataT sample_image(const sampled_image_handle &imageHandle [[maybe_unused]],
954
1001
955
1002
#ifdef __SYCL_DEVICE_ONLY__
956
1003
if constexpr (detail::is_recognized_standard_type<DataT>()) {
957
- return __invoke__ImageRead<DataT>(imageHandle.raw_handle , coords);
1004
+ return __invoke__ImageRead<DataT>(
1005
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
1006
+ coords);
958
1007
} else {
959
- return sycl::bit_cast<DataT>(
960
- __invoke__ImageRead<HintT>(imageHandle.raw_handle , coords));
1008
+ return sycl::bit_cast<DataT>(__invoke__ImageRead<HintT>(
1009
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
1010
+ coords));
961
1011
}
962
1012
#else
963
1013
assert (false ); // Bindless images not yet implemented on host.
@@ -1026,15 +1076,18 @@ DataT sample_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
1026
1076
1027
1077
#ifdef __SYCL_DEVICE_ONLY__
1028
1078
if constexpr (detail::is_recognized_standard_type<DataT>()) {
1029
- return __invoke__ImageReadLod<DataT>(imageHandle.raw_handle , coords, level);
1079
+ return __invoke__ImageReadLod<DataT>(
1080
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
1081
+ coords, level);
1030
1082
} else {
1031
1083
static_assert (sizeof (HintT) == sizeof (DataT),
1032
1084
" When trying to read a user-defined type, HintT must be of "
1033
1085
" the same size as the user-defined DataT." );
1034
1086
static_assert (detail::is_recognized_standard_type<HintT>(),
1035
1087
" HintT must always be a recognized standard type" );
1036
- return sycl::bit_cast<DataT>(
1037
- __invoke__ImageReadLod<HintT>(imageHandle.raw_handle , coords, level));
1088
+ return sycl::bit_cast<DataT>(__invoke__ImageReadLod<HintT>(
1089
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
1090
+ coords, level));
1038
1091
}
1039
1092
#else
1040
1093
assert (false ); // Bindless images not yet implemented on host
@@ -1070,16 +1123,18 @@ DataT sample_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
1070
1123
1071
1124
#ifdef __SYCL_DEVICE_ONLY__
1072
1125
if constexpr (detail::is_recognized_standard_type<DataT>()) {
1073
- return __invoke__ImageReadGrad<DataT>(imageHandle.raw_handle , coords, dX,
1074
- dY);
1126
+ return __invoke__ImageReadGrad<DataT>(
1127
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
1128
+ coords, dX, dY);
1075
1129
} else {
1076
1130
static_assert (sizeof (HintT) == sizeof (DataT),
1077
1131
" When trying to read a user-defined type, HintT must be of "
1078
1132
" the same size as the user-defined DataT." );
1079
1133
static_assert (detail::is_recognized_standard_type<HintT>(),
1080
1134
" HintT must always be a recognized standard type" );
1081
- return sycl::bit_cast<DataT>(
1082
- __invoke__ImageReadGrad<HintT>(imageHandle.raw_handle , coords, dX, dY));
1135
+ return sycl::bit_cast<DataT>(__invoke__ImageReadGrad<HintT>(
1136
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , coordSize),
1137
+ coords, dX, dY));
1083
1138
}
1084
1139
#else
1085
1140
assert (false ); // Bindless images not yet implemented on host
@@ -1224,16 +1279,20 @@ DataT fetch_image_array(const unsampled_image_handle &imageHandle
1224
1279
1225
1280
#ifdef __SYCL_DEVICE_ONLY__
1226
1281
if constexpr (detail::is_recognized_standard_type<DataT>()) {
1227
- return __invoke__ImageArrayFetch<DataT>(imageHandle.raw_handle , coords,
1228
- arrayLayer);
1282
+ return __invoke__ImageArrayFetch<DataT>(
1283
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
1284
+ detail::OCLImageTyRead<coordSize>),
1285
+ coords, arrayLayer);
1229
1286
} else {
1230
1287
static_assert (sizeof (HintT) == sizeof (DataT),
1231
1288
" When trying to fetch a user-defined type, HintT must be of "
1232
1289
" the same size as the user-defined DataT." );
1233
1290
static_assert (detail::is_recognized_standard_type<HintT>(),
1234
1291
" HintT must always be a recognized standard type" );
1235
1292
return sycl::bit_cast<DataT>(__invoke__ImageArrayFetch<HintT>(
1236
- imageHandle.raw_handle , coords, arrayLayer));
1293
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
1294
+ detail::OCLImageTyRead<coordSize>),
1295
+ coords, arrayLayer));
1237
1296
}
1238
1297
#else
1239
1298
assert (false ); // Bindless images not yet implemented on host.
@@ -1277,19 +1336,21 @@ DataT fetch_cubemap(const unsampled_image_handle &imageHandle,
1277
1336
template <typename DataT, typename HintT = DataT>
1278
1337
DataT sample_cubemap (const sampled_image_handle &imageHandle [[maybe_unused]],
1279
1338
const sycl::float3 &dirVec [[maybe_unused]]) {
1339
+ [[maybe_unused]] constexpr size_t NDims = 2 ;
1280
1340
1281
1341
#ifdef __SYCL_DEVICE_ONLY__
1282
1342
if constexpr (detail::is_recognized_standard_type<DataT>()) {
1283
- return __invoke__ImageReadCubemap<DataT, uint64_t >(imageHandle. raw_handle ,
1284
- dirVec);
1343
+ return __invoke__ImageReadCubemap<DataT, uint64_t >(
1344
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle. raw_handle , NDims), dirVec);
1285
1345
} else {
1286
1346
static_assert (sizeof (HintT) == sizeof (DataT),
1287
1347
" When trying to read a user-defined type, HintT must be of "
1288
1348
" the same size as the user-defined DataT." );
1289
1349
static_assert (detail::is_recognized_standard_type<HintT>(),
1290
1350
" HintT must always be a recognized standard type" );
1291
1351
return sycl::bit_cast<DataT>(__invoke__ImageReadCubemap<HintT, uint64_t >(
1292
- imageHandle.raw_handle , dirVec));
1352
+ CONVERT_HANDLE_TO_SAMPLED_IMAGE (imageHandle.raw_handle , NDims),
1353
+ dirVec));
1293
1354
}
1294
1355
#else
1295
1356
assert (false ); // Bindless images not yet implemented on host
@@ -1318,12 +1379,17 @@ void write_image(unsampled_image_handle imageHandle [[maybe_unused]],
1318
1379
1319
1380
#ifdef __SYCL_DEVICE_ONLY__
1320
1381
if constexpr (detail::is_recognized_standard_type<DataT>()) {
1321
- __invoke__ImageWrite ((uint64_t )imageHandle.raw_handle , coords, color);
1382
+ __invoke__ImageWrite (
1383
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
1384
+ detail::OCLImageTyWrite<coordSize>),
1385
+ coords, color);
1322
1386
} else {
1323
1387
// Convert DataT to a supported backend write type when user-defined type is
1324
1388
// passed
1325
- __invoke__ImageWrite ((uint64_t )imageHandle.raw_handle , coords,
1326
- detail::convert_color (color));
1389
+ __invoke__ImageWrite (
1390
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
1391
+ detail::OCLImageTyWrite<coordSize>),
1392
+ coords, detail::convert_color (color));
1327
1393
}
1328
1394
#else
1329
1395
assert (false ); // Bindless images not yet implemented on host
@@ -1354,13 +1420,17 @@ void write_image_array(unsampled_image_handle imageHandle [[maybe_unused]],
1354
1420
1355
1421
#ifdef __SYCL_DEVICE_ONLY__
1356
1422
if constexpr (detail::is_recognized_standard_type<DataT>()) {
1357
- __invoke__ImageArrayWrite (static_cast <uint64_t >(imageHandle.raw_handle ),
1358
- coords, arrayLayer, color);
1423
+ __invoke__ImageArrayWrite (
1424
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
1425
+ detail::OCLImageTyRead<coordSize>),
1426
+ coords, arrayLayer, color);
1359
1427
} else {
1360
1428
// Convert DataT to a supported backend write type when user-defined type is
1361
1429
// passed
1362
- __invoke__ImageArrayWrite (static_cast <uint64_t >(imageHandle.raw_handle ),
1363
- coords, arrayLayer, detail::convert_color (color));
1430
+ __invoke__ImageArrayWrite (
1431
+ CONVERT_HANDLE_TO_IMAGE (imageHandle.raw_handle ,
1432
+ detail::OCLImageTyRead<coordSize>),
1433
+ coords, arrayLayer, detail::convert_color (color));
1364
1434
}
1365
1435
#else
1366
1436
assert (false ); // Bindless images not yet implemented on host.
0 commit comments