From 003e50f6cb7c9faeeaff5561215fa4bbeb6eca1c Mon Sep 17 00:00:00 2001 From: Vlad Sytchenko Date: Mon, 27 Jul 2020 13:22:19 -0400 Subject: [PATCH] Don't align 2D image buffer size Cuda allows creating 2D textures from memory with unaligned size. Aligning it will cause us to overshoot the size of the underlying allocation. Change-Id: Ia20dec2105e36ca4a8448c9c6299d0001b388d25 [ROCm/hip commit: 844dab3b22c66ebe172be93f5e70417ec723653f] --- projects/hip/rocclr/hip_texture.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/hip/rocclr/hip_texture.cpp b/projects/hip/rocclr/hip_texture.cpp index 4980f87eaf..8217dfb6f8 100755 --- a/projects/hip/rocclr/hip_texture.cpp +++ b/projects/hip/rocclr/hip_texture.cpp @@ -269,8 +269,10 @@ hipError_t ihipCreateTextureObject(hipTextureObject_t* pTexObject, case hipResourceTypePitch2D: { const cl_channel_order channelOrder = hip::getCLChannelOrder(hip::getNumChannels(pResDesc->res.pitch2D.desc), pTexDesc->sRGB); const cl_channel_type channelType = hip::getCLChannelType(hip::getArrayFormat(pResDesc->res.pitch2D.desc), pTexDesc->readMode); + const amd::Image::Format imageFormat({channelOrder, channelType}); const cl_mem_object_type imageType = hip::getCLMemObjectType(pResDesc->resType); - const size_t imageSizeInBytes = pResDesc->res.pitch2D.pitchInBytes * pResDesc->res.pitch2D.height; + const size_t imageSizeInBytes = pResDesc->res.pitch2D.width * imageFormat.getElementSize() + + pResDesc->res.pitch2D.pitchInBytes * (pResDesc->res.pitch2D.height - 1); amd::Memory* buffer = getMemoryObjectWithOffset(pResDesc->res.pitch2D.devPtr, imageSizeInBytes); image = ihipImageCreate(channelOrder, channelType,