diff --git a/hipamd/include/hip/hcc_detail/texture_fetch_functions.h b/hipamd/include/hip/hcc_detail/texture_fetch_functions.h index ad8deda400..39ac3ecd89 100644 --- a/hipamd/include/hip/hcc_detail/texture_fetch_functions.h +++ b/hipamd/include/hip/hcc_detail/texture_fetch_functions.h @@ -34,20 +34,106 @@ THE SOFTWARE. unsigned int ADDRESS_SPACE_CONSTANT* i = (unsigned int ADDRESS_SPACE_CONSTANT*)t.textureObject; \ unsigned int ADDRESS_SPACE_CONSTANT* s = i + HIP_SAMPLER_OBJECT_OFFSET_DWORD; -template -struct __hip_tex_ret {}; +template +struct __hip_is_channel_type +{ + static constexpr bool value = + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value; +}; -template -using __hip_tex_ret_t = typename __hip_tex_ret::type; - -template -struct __hip_tex_ret { using type = T; }; +template< + typename T, + unsigned int rank> +struct __hip_is_channel_type> +{ + static constexpr bool value = + __hip_is_channel_type::value && + ((rank == 1) || + (rank == 2) || + (rank == 4)); +}; template -struct __hip_tex_ret { using type = float; }; +struct __hip_is_normalized_channel_type +{ + static constexpr bool value = + std::is_same::value || + std::is_same::value || + std::is_same::value || + std::is_same::value; +}; -template -struct __hip_tex_ret, hipReadModeNormalizedFloat> { using type = HIP_vector_type; }; +template< + typename T, + unsigned int rank> +struct __hip_is_normalized_channel_type> +{ + static constexpr bool value = + __hip_is_normalized_channel_type::value && + ((rank == 1) || + (rank == 2) || + (rank == 4)); +}; + +template < + typename T, + hipTextureReadMode readMode, + typename Enable = void> +struct __hip_tex_ret +{ + static_assert(std::is_same::value, "Invalid channel type!"); +}; + +template < + typename T, + hipTextureReadMode readMode> +using __hip_tex_ret_t = typename __hip_tex_ret::type; + +template +struct __hip_tex_ret< + T, + hipReadModeElementType, + typename std::enable_if<__hip_is_channel_type::value, bool>::type> +{ + using type = T; +}; + +template< + typename T, + unsigned int rank> +struct __hip_tex_ret< + HIP_vector_type, + hipReadModeElementType, + typename std::enable_if<__hip_is_channel_type>::value, bool>::type> +{ + using type = HIP_vector_type<__hip_tex_ret_t, rank>; +}; + +template +struct __hip_tex_ret< + T, + hipReadModeNormalizedFloat, + typename std::enable_if<__hip_is_normalized_channel_type::value, bool>::type> +{ + using type = float; +}; + +template< + typename T, + unsigned int rank> +struct __hip_tex_ret< + HIP_vector_type, + hipReadModeNormalizedFloat, + typename std::enable_if<__hip_is_normalized_channel_type>::value, bool>::type> +{ + using type = HIP_vector_type<__hip_tex_ret_t, rank>; +}; template static __forceinline__ __device__ __hip_tex_ret_t tex1Dfetch(texture t, int x) @@ -229,20 +315,48 @@ static __forceinline__ __device__ __hip_tex_ret_t tex3DGrad(texture return *reinterpret_cast<__hip_tex_ret_t*>(&tmp); } -template -struct __hip_tex2dgather_ret {}; +template < + typename T, + hipTextureReadMode readMode, + typename Enable = void> +struct __hip_tex2dgather_ret +{ + static_assert(std::is_same::value, "Invalid channel type!"); +}; -template -using __hip_tex2dgather_ret_t = typename __hip_tex2dgather_ret::type; +template < + typename T, + hipTextureReadMode readMode> +using __hip_tex2dgather_ret_t = typename __hip_tex2dgather_ret::type; template -struct __hip_tex2dgather_ret { using type = HIP_vector_type; }; +struct __hip_tex2dgather_ret< + T, + hipReadModeElementType, + typename std::enable_if<__hip_is_channel_type::value, bool>::type> +{ + using type = HIP_vector_type; +}; -template -struct __hip_tex2dgather_ret, hipReadModeElementType> { using type = HIP_vector_type; }; +template< + typename T, + unsigned int rank> +struct __hip_tex2dgather_ret< + HIP_vector_type, + hipReadModeElementType, + typename std::enable_if<__hip_is_channel_type>::value, bool>::type> +{ + using type = HIP_vector_type; +}; template -struct __hip_tex2dgather_ret { using type = float4; }; +struct __hip_tex2dgather_ret< + T, + hipReadModeNormalizedFloat, + typename std::enable_if<__hip_is_normalized_channel_type::value, bool>::type> +{ + using type = float4; +}; template static __forceinline__ __device__ __hip_tex2dgather_ret_t tex2Dgather(texture t, float x, float y, int comp=0)