23 #ifndef HIP_INCLUDE_HIP_AMD_DETAIL_SURFACE_FUNCTIONS_H
24 #define HIP_INCLUDE_HIP_AMD_DETAIL_SURFACE_FUNCTIONS_H
26 #if defined(__cplusplus)
28 #if !defined(__HIPCC_RTC__)
31 #include <hip/amd_detail/texture_fetch_functions.h>
32 #include <hip/amd_detail/ockl_image.h>
35 #if defined(__HIPCC_RTC__)
36 #define __HOST_DEVICE__ __device__
38 #define __HOST_DEVICE__ __host__ __device__
41 #define __HIP_SURFACE_OBJECT_PARAMETERS_INIT \
42 unsigned int ADDRESS_SPACE_CONSTANT* i = (unsigned int ADDRESS_SPACE_CONSTANT*)surfObj;
50 static __HOST_DEVICE__ __forceinline__
int __hipGetPixelAddr(
int x,
int format,
int order) {
72 static const int FormatLUT[] = {0, 1, 0, 1, 3, 1, 1, 1, 0, 1, 2, 0, 1, 2, 1, 2};
73 x = FormatLUT[format] == 3 ? x / FormatLUT[format] : x >> FormatLUT[format];
100 static const int OrderLUT[] = {0, 0, 1, 1, 3, 1, 3, 2, 2, 2, 2, 2, 3, 2, 2, 2, 0, 0, 0, 0};
101 return x = OrderLUT[order] == 3 ? x / OrderLUT[order] : x >> OrderLUT[order];
112 template <
typename T,
typename __hip_internal::enable_if<
113 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
114 static __device__ __hip_img_chk__
void surf1Dread(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 = __ockl_image_load_1D(i, x);
120 *data = __hipMapFrom<T>(tmp);
130 template <
typename T,
typename __hip_internal::enable_if<
131 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
132 static __device__ __hip_img_chk__
void surf1Dwrite(T data,
hipSurfaceObject_t surfObj,
int x) {
134 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
135 auto tmp = __hipMapTo<float4::Native_vec_>(data);
136 __ockl_image_store_1D(i, x, tmp);
148 template <
typename T,
typename __hip_internal::enable_if<
149 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
150 static __device__ __hip_img_chk__
void surf2Dread(T* data,
hipSurfaceObject_t surfObj,
int x,
153 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
155 auto tmp = __ockl_image_load_2D(i, get_native_vector(coords));
156 *data = __hipMapFrom<T>(tmp);
168 template <
typename T,
typename __hip_internal::enable_if<
169 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
170 static __device__ __hip_img_chk__
void surf2Dwrite(T data,
hipSurfaceObject_t surfObj,
int x,
173 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
175 auto tmp = __hipMapTo<float4::Native_vec_>(data);
176 __ockl_image_store_2D(i, get_native_vector(coords), tmp);
189 template <
typename T,
typename __hip_internal::enable_if<
190 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
191 static __device__ __hip_img_chk__
void surf3Dread(T* data,
hipSurfaceObject_t surfObj,
int x,
int y,
194 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_3D(i), __ockl_image_channel_order_3D(i));
195 int4 coords{x, y, z, 0};
196 auto tmp = __ockl_image_load_3D(i, get_native_vector(coords));
197 *data = __hipMapFrom<T>(tmp);
210 template <
typename T,
typename __hip_internal::enable_if<
211 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
212 static __device__ __hip_img_chk__
void surf3Dwrite(T data,
hipSurfaceObject_t surfObj,
int x,
int y,
215 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_3D(i), __ockl_image_channel_order_3D(i));
216 int4 coords{x, y, z, 0};
217 auto tmp = __hipMapTo<float4::Native_vec_>(data);
218 __ockl_image_store_3D(i, get_native_vector(coords), tmp);
230 template <
typename T,
typename __hip_internal::enable_if<
231 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
232 static __device__ __hip_img_chk__
void surf1DLayeredread(T* data,
hipSurfaceObject_t surfObj,
int x,
235 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
236 auto tmp = __ockl_image_load_lod_1D(i, x, layer);
237 *data = __hipMapFrom<T>(tmp);
249 template <
typename T,
typename __hip_internal::enable_if<
250 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
251 static __device__ __hip_img_chk__
void surf1DLayeredwrite(T data,
hipSurfaceObject_t surfObj,
int x,
254 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1D(i), __ockl_image_channel_order_1D(i));
255 auto tmp = __hipMapTo<float4::Native_vec_>(data);
256 __ockl_image_store_lod_1D(i, x, layer, tmp);
269 template <
typename T,
typename __hip_internal::enable_if<
270 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
271 static __device__ __hip_img_chk__
void surf2DLayeredread(T* data,
hipSurfaceObject_t surfObj,
int x,
274 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
276 auto tmp = __ockl_image_load_lod_2D(i, get_native_vector(coords), layer);
277 *data = __hipMapFrom<T>(tmp);
290 template <
typename T,
typename __hip_internal::enable_if<
291 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
292 static __device__ __hip_img_chk__
void surf2DLayeredwrite(T data,
hipSurfaceObject_t surfObj,
int x,
295 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
297 auto tmp = __hipMapTo<float4::Native_vec_>(data);
298 __ockl_image_store_lod_2D(i, get_native_vector(coords), layer, tmp);
311 template <
typename T,
typename __hip_internal::enable_if<
312 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
313 static __device__ __hip_img_chk__
void surfCubemapread(T* data,
hipSurfaceObject_t surfObj,
int x,
316 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
318 auto tmp = __ockl_image_load_CM(i, get_native_vector(coords), face);
319 *data = __hipMapFrom<T>(tmp);
332 template <
typename T,
typename __hip_internal::enable_if<
333 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
334 static __device__ __hip_img_chk__
void surfCubemapwrite(T data,
hipSurfaceObject_t surfObj,
int x,
337 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
339 auto tmp = __hipMapTo<float4::Native_vec_>(data);
340 __ockl_image_store_CM(i, get_native_vector(coords), face, tmp);
354 template <
typename T,
typename __hip_internal::enable_if<
355 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
356 static __device__ __hip_img_chk__
void surfCubemapLayeredread(T* data,
hipSurfaceObject_t surfObj,
357 int x,
int y,
int face,
int layer) {
359 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
361 auto tmp = __ockl_image_load_lod_CM(i, get_native_vector(coords), face, layer);
362 *data = __hipMapFrom<T>(tmp);
376 template <
typename T,
typename __hip_internal::enable_if<
377 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
378 static __device__ __hip_img_chk__
void surfCubemapLayeredwrite(T* data,
hipSurfaceObject_t surfObj,
379 int x,
int y,
int face,
int layer) {
381 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
383 auto tmp = __hipMapTo<float4::Native_vec_>(data);
384 __ockl_image_store_lod_CM(i, get_native_vector(coords), face, layer, tmp);
#define __HIP_SURFACE_OBJECT_PARAMETERS_INIT
Definition: amd_surface_functions.h:41
#define __HOST_DEVICE__
Definition: amd_surface_functions.h:38
Defines surface types for HIP runtime.
@ hipBoundaryModeZero
Definition: surface_types.h:56
struct __hip_surface * hipSurfaceObject_t
Definition: surface_types.h:43