From eaa7fd41cfb7b10276a9fb919ba13cb2244d29c9 Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Mon, 19 Aug 2024 15:02:35 -0400 Subject: [PATCH] SWDEV-474989 - Fix issues of texture tests Change-Id: Ie1d874742b804f82ceda68864fa54f5d59c092b8 [ROCm/clr commit: 4b211f7272c22651bc7b387508785513e7967054] --- projects/clr/hipamd/src/hip_memory.cpp | 38 ++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 7b02d61ac5..c3d8770bd1 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -1086,20 +1086,25 @@ amd::Image* ihipImageCreate(const cl_channel_order channelOrder, hipError_t ihipArrayCreate(hipArray_t* array, const HIP_ARRAY3D_DESCRIPTOR* pAllocateArray, unsigned int numMipmapLevels) { - if (array == nullptr) { + if (!array || !pAllocateArray) { return hipErrorInvalidValue; } - // NumChannels specifies the number of packed components per HIP array element; it may be 1, 2, or 4; if ((pAllocateArray->NumChannels != 1) && (pAllocateArray->NumChannels != 2) && (pAllocateArray->NumChannels != 4)) { return hipErrorInvalidValue; } - - if (pAllocateArray->Flags & hipArrayCubemap) { + unsigned int flags = hipArrayDefault | hipArrayLayered | hipArraySurfaceLoadStore | + hipArrayTextureGather; // hipArrayCubemap isn't supported + if (pAllocateArray->Flags & (~flags)) { return hipErrorInvalidValue; } + if (pAllocateArray->Flags & hipArrayTextureGather) { + // hipArrayTextureGather only works for 2D + if (pAllocateArray->Width == 0 || pAllocateArray->Height == 0 || pAllocateArray->Depth > 0) + return hipErrorInvalidValue; + } const cl_channel_order channelOrder = hip::getCLChannelOrder(pAllocateArray->NumChannels, 0); const cl_channel_type channelType = hip::getCLChannelType(pAllocateArray->Format, hipReadModeElementType); @@ -4282,6 +4287,21 @@ hipError_t ihipMipmapArrayCreate(hipMipmappedArray_t* mipmapped_array_pptr, LogPrintfError("Mipmap not supported on one of the devices, Mip Level: %d", num_mipmap_levels); return hipErrorNotSupported; } + if (!mipmapped_array_pptr || !mipmapped_array_desc_ptr) { + return hipErrorInvalidValue; + } + unsigned int flags = hipArrayDefault | hipArrayLayered | hipArraySurfaceLoadStore | + hipArrayTextureGather; // hipArrayCubemap isn't supported + if (mipmapped_array_desc_ptr->Flags & (~flags)) { + return hipErrorInvalidValue; + } + if (mipmapped_array_desc_ptr->Flags & hipArrayTextureGather) { + // hipArrayTextureGather only works for 2D + if (mipmapped_array_desc_ptr->Width == 0 || mipmapped_array_desc_ptr->Height == 0 || + mipmapped_array_desc_ptr->Depth > 0) + return hipErrorInvalidValue; + } + const cl_channel_order channel_order = hip::getCLChannelOrder( mipmapped_array_desc_ptr->NumChannels, 0); const cl_channel_type channel_type = hip::getCLChannelType(mipmapped_array_desc_ptr->Format, @@ -4353,10 +4373,16 @@ hipError_t ihipMipmappedArrayGetLevel(hipArray_t* level_array_pptr, hipMipmappedArray_t mipmapped_array_ptr, unsigned int mip_level) { - if (level_array_pptr == nullptr || mipmapped_array_ptr == nullptr) { + if (level_array_pptr == nullptr) { + return hipErrorInvalidValue; + } + if (mipmapped_array_ptr == nullptr) { + return hipErrorInvalidHandle; + } + if (mip_level < mipmapped_array_ptr->min_mipmap_level || + mipmapped_array_ptr->max_mipmap_level < mip_level) { return hipErrorInvalidValue; } - // Convert the raw data to amd::Image cl_mem cl_mem_obj = reinterpret_cast(mipmapped_array_ptr->data); if (is_valid(cl_mem_obj) == false) {