@@ -423,12 +423,26 @@ template <typename ChannelType>
423
423
void convertReadData (const vec<ChannelType, 4 > PixelData,
424
424
const image_channel_type ImageChannelType,
425
425
vec<cl_half, 4 > &RetData) {
426
-
426
+ vec<cl_float, 4 > RetDataFloat;
427
427
switch (ImageChannelType) {
428
428
case image_channel_type::snorm_int8:
429
+ // max(-1.0f, (half)c / 127.0f)
430
+ RetDataFloat = (PixelData.template convert <cl_float>()) / 127 .0f ;
431
+ RetDataFloat = cl::sycl::fmax (RetDataFloat, -1 );
432
+ break ;
429
433
case image_channel_type::snorm_int16:
434
+ // max(-1.0f, (half)c / 32767.0f)
435
+ RetDataFloat = (PixelData.template convert <cl_float>()) / 32767 .0f ;
436
+ RetDataFloat = cl::sycl::fmax (RetDataFloat, -1 );
437
+ break ;
430
438
case image_channel_type::unorm_int8:
439
+ // (half)c / 255.0f
440
+ RetDataFloat = (PixelData.template convert <cl_float>()) / 255 .0f ;
441
+ break ;
431
442
case image_channel_type::unorm_int16:
443
+ // (half)c / 65535.0f
444
+ RetDataFloat = (PixelData.template convert <cl_float>()) / 65535 .0f ;
445
+ break ;
432
446
case image_channel_type::unorm_short_565:
433
447
case image_channel_type::unorm_short_555:
434
448
case image_channel_type::unorm_int_101010:
@@ -452,7 +466,7 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
452
466
PI_INVALID_VALUE);
453
467
case image_channel_type::fp16:
454
468
RetData = PixelData.template convert <cl_half>();
455
- break ;
469
+ return ;
456
470
case image_channel_type::fp32:
457
471
throw cl::sycl::invalid_parameter_error (
458
472
" Datatype to read - cl_half4 is incompatible with the "
@@ -461,6 +475,7 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
461
475
default :
462
476
break ;
463
477
}
478
+ RetData = RetDataFloat.template convert <cl_half>();
464
479
}
465
480
466
481
// Converts data to write into appropriate datatype based on the channel of the
@@ -629,12 +644,20 @@ template <typename ChannelType>
629
644
vec<ChannelType, 4 >
630
645
convertWriteData (const vec<cl_half, 4 > WriteData,
631
646
const image_channel_type ImageChannelType) {
632
-
647
+ vec<cl_float, 4 > WriteDataFloat = WriteData. convert <cl_float>();
633
648
switch (ImageChannelType) {
634
649
case image_channel_type::snorm_int8:
650
+ // convert_char_sat_rte(h * 127.0f)
651
+ return processFloatDataToPixel<ChannelType>(WriteDataFloat, 127 .0f );
635
652
case image_channel_type::snorm_int16:
653
+ // convert_short_sat_rte(h * 32767.0f)
654
+ return processFloatDataToPixel<ChannelType>(WriteDataFloat, 32767 .0f );
636
655
case image_channel_type::unorm_int8:
656
+ // convert_uchar_sat_rte(h * 255.0f)
657
+ return processFloatDataToPixel<ChannelType>(WriteDataFloat, 255 .0f );
637
658
case image_channel_type::unorm_int16:
659
+ // convert_ushort_sat_rte(h * 65535.0f)
660
+ return processFloatDataToPixel<ChannelType>(WriteDataFloat, 65535 .0f );
638
661
case image_channel_type::unorm_short_565:
639
662
case image_channel_type::unorm_short_555:
640
663
case image_channel_type::unorm_int_101010:
@@ -994,10 +1017,13 @@ DataT ReadPixelDataLinearFiltMode(const cl_int8 CoordValues,
994
1017
// ImgChannelType.
995
1018
// Convert to DataT as per conversion rules in section 8.3 in OpenCL Spec.
996
1019
//
997
- // TODO:
998
- // Extend support for Step2 and Step3 for Linear Filtering Mode.
999
- // Extend support to find out of bounds Coordinates and return appropriate
1000
- // value based on Addressing Mode.
1020
+ // TODO: Add additional check for half datatype read.
1021
+ // Based on OpenCL spec 2.0:
1022
+ // "The read_imageh calls that take integer coordinates must use a sampler with
1023
+ // filter mode set to CLK_FILTER_NEAREST, normalized coordinates set to
1024
+ // CLK_NORMALIZED_COORDS_FALSE and addressing mode set to
1025
+ // CLK_ADDRESS_CLAMP_TO_EDGE, CLK_ADDRESS_CLAMP or CLK_ADDRESS_NONE; otherwise
1026
+ // the values returned are undefined."
1001
1027
1002
1028
template <typename CoordT, typename DataT>
1003
1029
DataT imageReadSamplerHostImpl (const CoordT &Coords, const sampler &Smpl,
0 commit comments