7#ifndef HIP_INCLUDE_HIP_AMD_DETAIL_SURFACE_FUNCTIONS_H
8#define HIP_INCLUDE_HIP_AMD_DETAIL_SURFACE_FUNCTIONS_H
10#if defined(__cplusplus)
12#if !defined(__HIPCC_RTC__)
15#include <hip/amd_detail/texture_fetch_functions.h>
16#include <hip/amd_detail/ockl_image.h>
19#if defined(__HIPCC_RTC__)
20#define __HOST_DEVICE__ __device__
22#define __HOST_DEVICE__ __host__ __device__
25#define __HIP_SURFACE_OBJECT_PARAMETERS_INIT \
26 unsigned int ADDRESS_SPACE_CONSTANT* i = (unsigned int ADDRESS_SPACE_CONSTANT*)surfObj;
34static __HOST_DEVICE__ __forceinline__
int __hipGetPixelAddr(
int x,
int format,
int order) {
56 static const int FormatLUT[] = {0, 1, 0, 1, 3, 1, 1, 1, 0, 1, 2, 0, 1, 2, 1, 2};
57 x = FormatLUT[format] == 3 ? x / FormatLUT[format] : x >> FormatLUT[format];
84 static const int OrderLUT[] = {0, 0, 1, 1, 3, 1, 3, 2, 2, 2, 2, 2, 3, 2, 2, 2, 0, 0, 0, 0};
85 return x = OrderLUT[order] == 3 ? x / OrderLUT[order] : x >> OrderLUT[order];
96template <
typename T,
typename __hip_internal::enable_if<
97 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
98static __device__ __hip_img_chk__
void surf1Dread(T* data,
hipSurfaceObject_t surfObj,
int x,
102 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
103 auto tmp = __ockl_image_load_1D(i, x);
104 *data = __hipMapFrom<T>(tmp);
114template <
typename T,
typename __hip_internal::enable_if<
115 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
116static __device__ __hip_img_chk__
void surf1Dwrite(T data,
hipSurfaceObject_t surfObj,
int x) {
118 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
119 auto tmp = __hipMapTo<float4::Native_vec_>(data);
120 __ockl_image_store_1D(i, x, tmp);
132template <
typename T,
typename __hip_internal::enable_if<
133 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
134static __device__ __hip_img_chk__
void surf2Dread(T* data,
hipSurfaceObject_t surfObj,
int x,
137 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
139 auto tmp = __ockl_image_load_2D(i, get_native_vector(coords));
140 *data = __hipMapFrom<T>(tmp);
152template <
typename T,
typename __hip_internal::enable_if<
153 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
154static __device__ __hip_img_chk__
void surf2Dwrite(T data,
hipSurfaceObject_t surfObj,
int x,
157 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
159 auto tmp = __hipMapTo<float4::Native_vec_>(data);
160 __ockl_image_store_2D(i, get_native_vector(coords), tmp);
173template <
typename T,
typename __hip_internal::enable_if<
174 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
175static __device__ __hip_img_chk__
void surf3Dread(T* data,
hipSurfaceObject_t surfObj,
int x,
int y,
178 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_3D(i), __ockl_image_channel_order_3D(i));
179 int4 coords{x, y, z, 0};
180 auto tmp = __ockl_image_load_3D(i, get_native_vector(coords));
181 *data = __hipMapFrom<T>(tmp);
194template <
typename T,
typename __hip_internal::enable_if<
195 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
196static __device__ __hip_img_chk__
void surf3Dwrite(T data,
hipSurfaceObject_t surfObj,
int x,
int y,
199 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_3D(i), __ockl_image_channel_order_3D(i));
200 int4 coords{x, y, z, 0};
201 auto tmp = __hipMapTo<float4::Native_vec_>(data);
202 __ockl_image_store_3D(i, get_native_vector(coords), tmp);
214template <
typename T,
typename __hip_internal::enable_if<
215 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
216static __device__ __hip_img_chk__
void surf1DLayeredread(T* data,
hipSurfaceObject_t surfObj,
int x,
219 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
220 auto tmp = __ockl_image_load_lod_1D(i, x, layer);
221 *data = __hipMapFrom<T>(tmp);
233template <
typename T,
typename __hip_internal::enable_if<
234 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
235static __device__ __hip_img_chk__
void surf1DLayeredwrite(T data,
hipSurfaceObject_t surfObj,
int x,
238 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
239 auto tmp = __hipMapTo<float4::Native_vec_>(data);
240 __ockl_image_store_lod_1D(i, x, layer, tmp);
253template <
typename T,
typename __hip_internal::enable_if<
254 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
255static __device__ __hip_img_chk__
void surf2DLayeredread(T* data,
hipSurfaceObject_t surfObj,
int x,
258 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
260 auto tmp = __ockl_image_load_lod_2D(i, get_native_vector(coords), layer);
261 *data = __hipMapFrom<T>(tmp);
274template <
typename T,
typename __hip_internal::enable_if<
275 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
276static __device__ __hip_img_chk__
void surf2DLayeredwrite(T data,
hipSurfaceObject_t surfObj,
int x,
279 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
281 auto tmp = __hipMapTo<float4::Native_vec_>(data);
282 __ockl_image_store_lod_2D(i, get_native_vector(coords), layer, tmp);
295template <
typename T,
typename __hip_internal::enable_if<
296 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
297static __device__ __hip_img_chk__
void surfCubemapread(T* data,
hipSurfaceObject_t surfObj,
int x,
300 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
302 auto tmp = __ockl_image_load_CM(i, get_native_vector(coords), face);
303 *data = __hipMapFrom<T>(tmp);
316template <
typename T,
typename __hip_internal::enable_if<
317 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
318static __device__ __hip_img_chk__
void surfCubemapwrite(T data,
hipSurfaceObject_t surfObj,
int x,
321 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
323 auto tmp = __hipMapTo<float4::Native_vec_>(data);
324 __ockl_image_store_CM(i, get_native_vector(coords), face, tmp);
338template <
typename T,
typename __hip_internal::enable_if<
339 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
340static __device__ __hip_img_chk__
void surfCubemapLayeredread(T* data,
hipSurfaceObject_t surfObj,
341 int x,
int y,
int face,
int layer) {
343 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
345 auto tmp = __ockl_image_load_lod_CM(i, get_native_vector(coords), face, layer);
346 *data = __hipMapFrom<T>(tmp);
360template <
typename T,
typename __hip_internal::enable_if<
361 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
362static __device__ __hip_img_chk__
void surfCubemapLayeredwrite(T* data,
hipSurfaceObject_t surfObj,
363 int x,
int y,
int face,
int layer) {
365 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
367 auto tmp = __hipMapTo<float4::Native_vec_>(data);
368 __ockl_image_store_lod_CM(i, get_native_vector(coords), face, layer, tmp);
#define __HIP_SURFACE_OBJECT_PARAMETERS_INIT
Definition amd_surface_functions.h:25
#define __HOST_DEVICE__
Definition amd_surface_functions.h:22
Defines surface types for HIP runtime.
@ hipBoundaryModeZero
Definition surface_types.h:41
struct __hip_surface * hipSurfaceObject_t
Definition surface_types.h:28