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_1Da(i),
220 __ockl_image_channel_order_1Da(i));
221 int2 coords{x, layer};
222 auto tmp = __ockl_image_load_1Da(i, get_native_vector(coords));
223 *data = __hipMapFrom<T>(tmp);
235template <
typename T,
typename __hip_internal::enable_if<
236 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
237static __device__ __hip_img_chk__
void surf1DLayeredwrite(T data,
hipSurfaceObject_t surfObj,
int x,
240 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_1Da(i),
241 __ockl_image_channel_order_1Da(i));
242 int2 coords{x, layer};
243 auto tmp = __hipMapTo<float4::Native_vec_>(data);
244 __ockl_image_store_1Da(i, get_native_vector(coords), tmp);
257template <
typename T,
typename __hip_internal::enable_if<
258 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
259static __device__ __hip_img_chk__
void surf2DLayeredread(T* data,
hipSurfaceObject_t surfObj,
int x,
262 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2Da(i),
263 __ockl_image_channel_order_2Da(i));
264 int4 coords{x, y, layer, 0};
265 auto tmp = __ockl_image_load_2Da(i, get_native_vector(coords));
266 *data = __hipMapFrom<T>(tmp);
279template <
typename T,
typename __hip_internal::enable_if<
280 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
281static __device__ __hip_img_chk__
void surf2DLayeredwrite(T data,
hipSurfaceObject_t surfObj,
int x,
284 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2Da(i),
285 __ockl_image_channel_order_2Da(i));
286 int4 coords{x, y, layer, 0};
287 auto tmp = __hipMapTo<float4::Native_vec_>(data);
288 __ockl_image_store_2Da(i, get_native_vector(coords), tmp);
301template <
typename T,
typename __hip_internal::enable_if<
302 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
303static __device__ __hip_img_chk__
void surfCubemapread(T* data,
hipSurfaceObject_t surfObj,
int x,
306 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
308 auto tmp = __ockl_image_load_CM(i, get_native_vector(coords), face);
309 *data = __hipMapFrom<T>(tmp);
322template <
typename T,
typename __hip_internal::enable_if<
323 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
324static __device__ __hip_img_chk__
void surfCubemapwrite(T data,
hipSurfaceObject_t surfObj,
int x,
327 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
329 auto tmp = __hipMapTo<float4::Native_vec_>(data);
330 __ockl_image_store_CM(i, get_native_vector(coords), face, tmp);
344template <
typename T,
typename __hip_internal::enable_if<
345 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
346static __device__ __hip_img_chk__
void surfCubemapLayeredread(T* data,
hipSurfaceObject_t surfObj,
347 int x,
int y,
int face,
int layer) {
349 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
351 auto tmp = __ockl_image_load_lod_CM(i, get_native_vector(coords), face, layer);
352 *data = __hipMapFrom<T>(tmp);
366template <
typename T,
typename __hip_internal::enable_if<
367 __hip_is_tex_surf_channel_type<T>::value>::type* =
nullptr>
368static __device__ __hip_img_chk__
void surfCubemapLayeredwrite(T* data,
hipSurfaceObject_t surfObj,
369 int x,
int y,
int face,
int layer) {
371 x = __hipGetPixelAddr(x, __ockl_image_channel_data_type_2D(i), __ockl_image_channel_order_2D(i));
373 auto tmp = __hipMapTo<float4::Native_vec_>(data);
374 __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