From 357404e25ffb8e06645ff9b2e6417dfdb522146a Mon Sep 17 00:00:00 2001 From: Vladislav Sytchenko Date: Tue, 17 Mar 2020 17:43:34 -0400 Subject: [PATCH] Rework the texture C++ API Currently the texture C++ API is forwarded to the ihip*Impl() calls, which are not even a part of Cuda. These should be forwarded to their respective Cuda C APIs instead. This change also fixes a bug with hipUnbindTexture() creating a dangling pointer. Change-Id: Ifafc9d106855a11bec84a18ea214b3d89e39990d [ROCm/hip commit: 5429b40afeac311a48df31adb01b2dc37d3b11fd] --- .../include/hip/hcc_detail/hip_runtime_api.h | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/projects/hip/include/hip/hcc_detail/hip_runtime_api.h b/projects/hip/include/hip/hcc_detail/hip_runtime_api.h index fa6b7d95f0..2a781154e1 100644 --- a/projects/hip/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/hip/include/hip/hcc_detail/hip_runtime_api.h @@ -3374,9 +3374,11 @@ hipError_t hipBindTexture(size_t* offset, textureReference* tex, const void* dev const hipChannelFormatDesc* desc, size_t size = UINT_MAX); #endif +#if !__HIP_VDI__ hipError_t ihipBindTextureImpl(TlsData *tls, int dim, enum hipTextureReadMode readMode, size_t* offset, const void* devPtr, const struct hipChannelFormatDesc* desc, size_t size, textureReference* tex); +#endif /* * @brief hipBindTexture Binds size bytes of the memory area pointed to by @p devPtr to the texture @@ -3393,11 +3395,13 @@ hipError_t ihipBindTextureImpl(TlsData *tls, int dim, enum hipTextureReadMode re * @param[in] size - Size of the memory area pointed to by devPtr * @return #hipSuccess, #hipErrorInvalidValue, #hipErrorMemoryFree, #hipErrorUnknown **/ +#if !__HIP_VDI__ template hipError_t hipBindTexture(size_t* offset, struct texture& tex, const void* devPtr, const struct hipChannelFormatDesc& desc, size_t size = UINT_MAX) { return ihipBindTextureImpl(nullptr, dim, readMode, offset, devPtr, &desc, size, &tex); } +#endif /* * @brief hipBindTexture Binds size bytes of the memory area pointed to by @p devPtr to the texture @@ -3413,11 +3417,13 @@ hipError_t hipBindTexture(size_t* offset, struct texture& tex, * @param[in] size - Size of the memory area pointed to by devPtr * @return #hipSuccess, #hipErrorInvalidValue, #hipErrorMemoryFree, #hipErrorUnknown **/ +#if !__HIP_VDI__ template hipError_t hipBindTexture(size_t* offset, struct texture& tex, const void* devPtr, size_t size = UINT_MAX) { return ihipBindTextureImpl(nullptr, dim, readMode, offset, devPtr, &(tex.channelDesc), size, &tex); } +#endif // C API #if __HIP_VDI__ @@ -3435,23 +3441,29 @@ hipError_t hipBindTexture2D(size_t* offset, textureReference* tex, const void* d size_t pitch); #endif +#if !__HIP_VDI__ hipError_t ihipBindTexture2DImpl(int dim, enum hipTextureReadMode readMode, size_t* offset, const void* devPtr, const struct hipChannelFormatDesc* desc, size_t width, size_t height, textureReference* tex, size_t pitch); +#endif +#if !__HIP_VDI__ template hipError_t hipBindTexture2D(size_t* offset, struct texture& tex, const void* devPtr, size_t width, size_t height, size_t pitch) { return ihipBindTexture2DImpl(dim, readMode, offset, devPtr, &(tex.channelDesc), width, height, &tex); } +#endif +#if !__HIP_VDI__ template hipError_t hipBindTexture2D(size_t* offset, struct texture& tex, const void* devPtr, const struct hipChannelFormatDesc& desc, size_t width, size_t height, size_t pitch) { return ihipBindTexture2DImpl(dim, readMode, offset, devPtr, &desc, width, height, &tex); } +#endif // C API #if __HIP_VDI__ @@ -3464,46 +3476,58 @@ hipError_t hipBindTextureToArray(textureReference* tex, hipArray_const_t array, const hipChannelFormatDesc* desc); #endif +#if !__HIP_VDI__ hipError_t ihipBindTextureToArrayImpl(TlsData *tls, int dim, enum hipTextureReadMode readMode, hipArray_const_t array, const struct hipChannelFormatDesc& desc, textureReference* tex); +#endif +#if !__HIP_VDI__ template hipError_t hipBindTextureToArray(struct texture& tex, hipArray_const_t array) { return ihipBindTextureToArrayImpl(nullptr, dim, readMode, array, tex.channelDesc, &tex); } +#endif +#if !__HIP_VDI__ template hipError_t hipBindTextureToArray(struct texture& tex, hipArray_const_t array, const struct hipChannelFormatDesc& desc) { return ihipBindTextureToArrayImpl(nullptr, dim, readMode, array, desc, &tex); } +#endif +#if !__HIP_VDI__ template inline static hipError_t hipBindTextureToArray(struct texture *tex, hipArray_const_t array, const struct hipChannelFormatDesc* desc) { return ihipBindTextureToArrayImpl(nullptr, dim, readMode, array, *desc, tex); } +#endif // C API hipError_t hipBindTextureToMipmappedArray(const textureReference* tex, hipMipmappedArray_const_t mipmappedArray, const hipChannelFormatDesc* desc); +#if !__HIP_VDI__ template hipError_t hipBindTextureToMipmappedArray(const texture& tex, hipMipmappedArray_const_t mipmappedArray) { return hipSuccess; } +#endif +#if !__HIP_VDI__ template hipError_t hipBindTextureToMipmappedArray(const texture& tex, hipMipmappedArray_const_t mipmappedArray, const hipChannelFormatDesc& desc) { return hipSuccess; } +#endif #if __HIP_VDI__ && !defined(__HCC__) @@ -3544,12 +3568,16 @@ inline hipError_t hipExtLaunchMultiKernelMultiDevice(hipLaunchParams* launchPara **/ hipError_t hipUnbindTexture(const textureReference* tex); +#if !__HIP_VDI__ extern hipError_t ihipUnbindTextureImpl(const hipTextureObject_t& textureObject); +#endif +#if !__HIP_VDI__ template hipError_t hipUnbindTexture(struct texture& tex) { return ihipUnbindTextureImpl(tex.textureObject); } +#endif hipError_t hipGetChannelDesc(hipChannelFormatDesc* desc, hipArray_const_t array); hipError_t hipGetTextureAlignmentOffset(size_t* offset, const textureReference* texref); @@ -3593,6 +3621,104 @@ hipError_t hipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject, const hipReso hipError_t hipDestroySurfaceObject(hipSurfaceObject_t surfaceObject); +#if __HIP_VDI__ +template +static inline hipError_t hipBindTexture( + size_t *offset, + const struct texture &tex, + const void *devPtr, + size_t size = UINT_MAX) +{ + return hipBindTexture(offset, tex, devPtr, tex.channelDesc, size); +} + +template +static inline hipError_t hipBindTexture( + size_t *offset, + const struct texture &tex, + const void *devPtr, + const struct hipChannelFormatDesc &desc, + size_t size = UINT_MAX) +{ + return hipBindTexture(offset, &tex, devPtr, &desc, size); +} + +template +static inline hipError_t hipBindTexture2D( + size_t *offset, + const struct texture &tex, + const void *devPtr, + size_t width, + size_t height, + size_t pitch) +{ + return hipBindTexture2D(offset, &tex, devPtr, &tex.channelDesc, width, height, pitch); +} + +template +static inline hipError_t hipBindTexture2D( + size_t *offset, + const struct texture &tex, + const void *devPtr, + const struct hipChannelFormatDesc &desc, + size_t width, + size_t height, + size_t pitch) +{ + return hipBindTexture2D(offset, &tex, devPtr, &desc, width, height, pitch); +} + +template +static inline hipError_t hipBindTextureToArray( + const struct texture &tex, + hipArray_const_t array) +{ + struct cudaChannelFormatDesc desc; + hipError_t err = hipGetChannelDesc(&desc, array); + return (err == hipSuccess) ? hipBindTextureToArray(tex, array, desc) : err; +} + +template +static inline hipError_t hipBindTextureToArray( + const struct texture &tex, + hipArray_const_t array, + const struct hipChannelFormatDesc &desc) +{ + return hipBindTextureToArray(&tex, array, &desc); +} + +template +static inline hipError_t hipBindTextureToMipmappedArray( + const struct texture &tex, + hipMipmappedArray_const_t mipmappedArray) +{ + struct hipChannelFormatDesc desc; + hipArray_t levelArray; + hipError_t err = hipGetMipmappedArrayLevel(&levelArray, mipmappedArray, 0); + if (err != hipSuccess) { + return err; + } + err = hipGetChannelDesc(&desc, levelArray); + return (err == hipSuccess) ? hipBindTextureToMipmappedArray(tex, mipmappedArray, desc) : err; +} + +template +static inline hipError_t hipBindTextureToMipmappedArray( + const struct texture &tex, + hipMipmappedArray_const_t mipmappedArray, + const struct cudaChannelFormatDesc &desc) +{ + return hipBindTextureToMipmappedArray(&tex, mipmappedArray, &desc); +} + +template +static inline hipError_t hipUnbindTexture( + const struct texture &tex) +{ + return hipUnbindTexture(&tex); +} +#endif + // doxygen end Texture /** * @}