From b8c5b2df55c6d303478572c44e7af3fcb159a309 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Wed, 8 Jan 2020 11:11:54 +0100 Subject: [PATCH] Refactor ImageInfo 1/n Change-Id: I1de1a4cca2b089a3cca54ffb1c0488e4c073b904 Signed-off-by: Mateusz Hoppe --- runtime/gmm_helper/gmm.cpp | 60 +++++----- runtime/gmm_helper/gmm.h | 4 +- runtime/gmm_helper/gmm_types_converter.cpp | 10 +- runtime/helpers/surface_formats.h | 25 ++++- runtime/mem_obj/image.cpp | 103 +++++++++++++++--- runtime/mem_obj/image.h | 7 +- runtime/sharings/d3d/d3d_sharing.cpp | 12 +- runtime/sharings/d3d/d3d_sharing.h | 4 +- runtime/sharings/d3d/d3d_surface.cpp | 20 ++-- runtime/sharings/d3d/d3d_texture.cpp | 12 +- runtime/sharings/gl/gl_texture.cpp | 12 +- runtime/sharings/unified/unified_image.cpp | 2 +- runtime/sharings/va/va_surface.cpp | 8 +- unit_tests/gmm_helper/gmm_helper_tests.cpp | 18 ++- unit_tests/mem_obj/image_redescribe_tests.cpp | 6 +- unit_tests/mem_obj/image_set_arg_tests.cpp | 4 +- unit_tests/mem_obj/image_tests.cpp | 86 +++++++++++++-- unit_tests/mem_obj/image_tiled_tests.cpp | 10 +- unit_tests/mocks/mock_gmm.h | 7 +- .../linux/drm_memory_manager_tests.cpp | 14 ++- .../gl/gl_create_from_texture_tests.cpp | 4 +- 21 files changed, 297 insertions(+), 131 deletions(-) diff --git a/runtime/gmm_helper/gmm.cpp b/runtime/gmm_helper/gmm.cpp index 90c040b183..dffdbac886 100644 --- a/runtime/gmm_helper/gmm.cpp +++ b/runtime/gmm_helper/gmm.cpp @@ -68,34 +68,34 @@ Gmm::Gmm(GmmClientContext *clientContext, ImageInfo &inputOutputImgInfo, Storage } void Gmm::setupImageResourceParams(ImageInfo &imgInfo) { - uint64_t imageWidth = static_cast(imgInfo.imgDesc->image_width); + uint64_t imageWidth = static_cast(imgInfo.imgDesc.image_width); uint32_t imageHeight = 1; uint32_t imageDepth = 1; uint32_t imageCount = 1; - switch (imgInfo.imgDesc->image_type) { - case CL_MEM_OBJECT_IMAGE1D: - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - case CL_MEM_OBJECT_IMAGE1D_BUFFER: + switch (imgInfo.imgDesc.image_type) { + case ImageType::Image1D: + case ImageType::Image1DArray: + case ImageType::Image1DBuffer: resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D; break; - case CL_MEM_OBJECT_IMAGE2D: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: + case ImageType::Image2D: + case ImageType::Image2DArray: resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_2D; - imageHeight = static_cast(imgInfo.imgDesc->image_height); + imageHeight = static_cast(imgInfo.imgDesc.image_height); break; - case CL_MEM_OBJECT_IMAGE3D: + case ImageType::Image3D: resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_3D; - imageHeight = static_cast(imgInfo.imgDesc->image_height); - imageDepth = static_cast(imgInfo.imgDesc->image_depth); + imageHeight = static_cast(imgInfo.imgDesc.image_height); + imageDepth = static_cast(imgInfo.imgDesc.image_depth); break; default: return; } - if (imgInfo.imgDesc->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || - imgInfo.imgDesc->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY) { - imageCount = static_cast(imgInfo.imgDesc->image_array_size); + if (imgInfo.imgDesc.image_type == ImageType::Image1DArray || + imgInfo.imgDesc.image_type == ImageType::Image2DArray) { + imageCount = static_cast(imgInfo.imgDesc.image_array_size); } resourceParams.Flags.Info.Linear = imgInfo.linearStorage; @@ -113,8 +113,8 @@ void Gmm::setupImageResourceParams(ImageInfo &imgInfo) { resourceParams.ArraySize = imageCount; resourceParams.Flags.Wa.__ForceOtherHVALIGN4 = hwHelper.hvAlign4Required(); resourceParams.MaxLod = imgInfo.baseMipLevel + imgInfo.mipCount; - if (imgInfo.imgDesc->image_row_pitch && imgInfo.imgDesc->mem_object) { - resourceParams.OverridePitch = (uint32_t)imgInfo.imgDesc->image_row_pitch; + if (imgInfo.imgDesc.image_row_pitch && imgInfo.imgDesc.from_parent) { + resourceParams.OverridePitch = (uint32_t)imgInfo.imgDesc.image_row_pitch; resourceParams.Flags.Info.AllowVirtualPadding = true; } @@ -183,25 +183,25 @@ uint32_t Gmm::queryQPitch(GMM_RESOURCE_TYPE resType) { return gmmResourceInfo->getQPitch(); } -void Gmm::updateImgInfoAndDesc(ImageInfo &imgInfo, cl_image_desc &imgDesc, cl_uint arrayIndex) { - imgDesc.image_width = gmmResourceInfo->getBaseWidth(); - imgDesc.image_row_pitch = gmmResourceInfo->getRenderPitch(); - if (imgDesc.image_row_pitch == 0) { - size_t width = alignUp(imgDesc.image_width, gmmResourceInfo->getHAlign()); - imgDesc.image_row_pitch = width * (gmmResourceInfo->getBitsPerPixel() >> 3); +void Gmm::updateImgInfoAndDesc(ImageInfo &imgInfo, cl_uint arrayIndex) { + imgInfo.imgDesc.image_width = gmmResourceInfo->getBaseWidth(); + imgInfo.imgDesc.image_row_pitch = gmmResourceInfo->getRenderPitch(); + if (imgInfo.imgDesc.image_row_pitch == 0) { + size_t width = alignUp(imgInfo.imgDesc.image_width, gmmResourceInfo->getHAlign()); + imgInfo.imgDesc.image_row_pitch = width * (gmmResourceInfo->getBitsPerPixel() >> 3); } - imgDesc.image_height = gmmResourceInfo->getBaseHeight(); - imgDesc.image_depth = gmmResourceInfo->getBaseDepth(); - imgDesc.image_array_size = gmmResourceInfo->getArraySize(); - if (imgDesc.image_depth > 1 || imgDesc.image_array_size > 1) { + imgInfo.imgDesc.image_height = gmmResourceInfo->getBaseHeight(); + imgInfo.imgDesc.image_depth = gmmResourceInfo->getBaseDepth(); + imgInfo.imgDesc.image_array_size = gmmResourceInfo->getArraySize(); + if (imgInfo.imgDesc.image_depth > 1 || imgInfo.imgDesc.image_array_size > 1) { GMM_REQ_OFFSET_INFO reqOffsetInfo = {}; - reqOffsetInfo.Slice = imgDesc.image_depth > 1 ? 1 : 0; - reqOffsetInfo.ArrayIndex = imgDesc.image_array_size > 1 ? 1 : 0; + reqOffsetInfo.Slice = imgInfo.imgDesc.image_depth > 1 ? 1 : 0; + reqOffsetInfo.ArrayIndex = imgInfo.imgDesc.image_array_size > 1 ? 1 : 0; reqOffsetInfo.ReqLock = 1; gmmResourceInfo->getOffset(reqOffsetInfo); - imgDesc.image_slice_pitch = static_cast(reqOffsetInfo.Lock.Offset); + imgInfo.imgDesc.image_slice_pitch = static_cast(reqOffsetInfo.Lock.Offset); } else { - imgDesc.image_slice_pitch = gmmResourceInfo->getSizeAllocation(); + imgInfo.imgDesc.image_slice_pitch = gmmResourceInfo->getSizeAllocation(); } updateOffsetsInImgInfo(imgInfo, arrayIndex); diff --git a/runtime/gmm_helper/gmm.h b/runtime/gmm_helper/gmm.h index 3b293ce88f..275b6a4b9e 100644 --- a/runtime/gmm_helper/gmm.h +++ b/runtime/gmm_helper/gmm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -40,7 +40,7 @@ class Gmm { bool hasMultisampleControlSurface() const; uint32_t queryQPitch(GMM_RESOURCE_TYPE resType); - void updateImgInfoAndDesc(ImageInfo &imgInfo, cl_image_desc &imgDesc, cl_uint arrayIndex); + void updateImgInfoAndDesc(ImageInfo &imgInfo, cl_uint arrayIndex); void updateOffsetsInImgInfo(ImageInfo &imgInfo, cl_uint arrayIndex); uint8_t resourceCopyBlt(void *sys, void *gpu, uint32_t pitch, uint32_t height, unsigned char upload, OCLPlane plane); diff --git a/runtime/gmm_helper/gmm_types_converter.cpp b/runtime/gmm_helper/gmm_types_converter.cpp index 6868fd3637..8637f4f2ba 100644 --- a/runtime/gmm_helper/gmm_types_converter.cpp +++ b/runtime/gmm_helper/gmm_types_converter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,12 +18,12 @@ using namespace NEO; void GmmTypesConverter::queryImgFromBufferParams(ImageInfo &imgInfo, GraphicsAllocation *gfxAlloc) { // 1D or 2D from buffer - if (imgInfo.imgDesc->image_row_pitch > 0) { - imgInfo.rowPitch = imgInfo.imgDesc->image_row_pitch; + if (imgInfo.imgDesc.image_row_pitch > 0) { + imgInfo.rowPitch = imgInfo.imgDesc.image_row_pitch; } else { - imgInfo.rowPitch = getValidParam(imgInfo.imgDesc->image_width) * imgInfo.surfaceFormat->ImageElementSizeInBytes; + imgInfo.rowPitch = getValidParam(imgInfo.imgDesc.image_width) * imgInfo.surfaceFormat->ImageElementSizeInBytes; } - imgInfo.slicePitch = imgInfo.rowPitch * getValidParam(imgInfo.imgDesc->image_height); + imgInfo.slicePitch = imgInfo.rowPitch * getValidParam(imgInfo.imgDesc.image_height); imgInfo.size = gfxAlloc->getUnderlyingBufferSize(); imgInfo.qPitch = 0; } diff --git a/runtime/helpers/surface_formats.h b/runtime/helpers/surface_formats.h index 06c91d359d..413b6093d0 100644 --- a/runtime/helpers/surface_formats.h +++ b/runtime/helpers/surface_formats.h @@ -200,8 +200,31 @@ struct SurfaceFormatInfo { size_t ImageElementSizeInBytes; }; +enum class ImageType { + Invalid, + Image1D, + Image2D, + Image3D, + Image1DArray, + Image2DArray, + Image1DBuffer +}; + +struct ImageDescriptor { + ImageType image_type; + size_t image_width; + size_t image_height; + size_t image_depth; + size_t image_array_size; + size_t image_row_pitch; + size_t image_slice_pitch; + uint32_t num_mip_levels; + uint32_t num_samples; + bool from_parent; +}; + struct ImageInfo { - const cl_image_desc *imgDesc; + ImageDescriptor imgDesc; const SurfaceFormatInfo *surfaceFormat; size_t size; size_t rowPitch; diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 8dfbc8e211..8374f7cbd0 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -137,14 +137,14 @@ Image *Image::create(Context *context, size_t hostPtrMinSize = 0; cl_image_desc imageDescriptor = *imageDesc; - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; void *hostPtrToSet = nullptr; if (memoryProperties.flags.useHostPtr) { hostPtrToSet = const_cast(hostPtr); } - imgInfo.imgDesc = &imageDescriptor; + imgInfo.imgDesc = Image::convertDescriptor(imageDescriptor); imgInfo.surfaceFormat = surfaceFormat; imgInfo.mipCount = imageDesc->num_mip_levels; Gmm *gmm = nullptr; @@ -321,6 +321,7 @@ Image *Image::create(Context *context, imageDescriptor.image_slice_pitch = 0; imageDescriptor.mem_object = imageDesc->mem_object; parentImage->incRefInternal(); + imgInfo.imgDesc = Image::convertDescriptor(imageDescriptor); } image = createImageHw(context, memoryProperties, flags, flagsIntel, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat, @@ -424,12 +425,12 @@ Image *Image::createSharedImage(Context *context, SharingHandler *sharingHandler GraphicsAllocation *graphicsAllocation, GraphicsAllocation *mcsAllocation, cl_mem_flags flags, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount) { auto sharedImage = createImageHw(context, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0), flags, 0, graphicsAllocation->getUnderlyingBufferSize(), - nullptr, imgInfo.surfaceFormat->OCLImageFormat, *imgInfo.imgDesc, false, graphicsAllocation, false, baseMipLevel, mipCount, imgInfo.surfaceFormat); + nullptr, imgInfo.surfaceFormat->OCLImageFormat, Image::convertDescriptor(imgInfo.imgDesc), false, graphicsAllocation, false, baseMipLevel, mipCount, imgInfo.surfaceFormat); sharedImage->setSharingHandler(sharingHandler); sharedImage->setMcsAllocation(mcsAllocation); sharedImage->setQPitch(imgInfo.qPitch); - sharedImage->setHostPtrRowPitch(imgInfo.imgDesc->image_row_pitch); - sharedImage->setHostPtrSlicePitch(imgInfo.imgDesc->image_slice_pitch); + sharedImage->setHostPtrRowPitch(imgInfo.imgDesc.image_row_pitch); + sharedImage->setHostPtrSlicePitch(imgInfo.imgDesc.image_slice_pitch); sharedImage->setCubeFaceIndex(cubeFaceIndex); sharedImage->setSurfaceOffsets(imgInfo.offset, imgInfo.xOffset, imgInfo.yOffset, imgInfo.yOffsetForUVPlane); sharedImage->setMcsSurfaceInfo(mcsSurfaceInfo); @@ -672,9 +673,9 @@ cl_int Image::getImageParams(Context *context, cl_int retVal = CL_SUCCESS; auto clientContext = context->getDevice(0)->getExecutionEnvironment()->getGmmClientContext(); - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; cl_image_desc imageDescriptor = *imageDesc; - imgInfo.imgDesc = &imageDescriptor; + imgInfo.imgDesc = Image::convertDescriptor(imageDescriptor); imgInfo.surfaceFormat = surfaceFormat; auto gmm = std::make_unique(clientContext, imgInfo, StorageInfo{}); @@ -702,25 +703,25 @@ bool Image::isCopyRequired(ImageInfo &imgInfo, const void *hostPtr) { return false; } - size_t imageWidth = imgInfo.imgDesc->image_width; + size_t imageWidth = imgInfo.imgDesc.image_width; size_t imageHeight = 1; size_t imageDepth = 1; size_t imageCount = 1; - switch (imgInfo.imgDesc->image_type) { - case CL_MEM_OBJECT_IMAGE3D: - imageDepth = imgInfo.imgDesc->image_depth; + switch (imgInfo.imgDesc.image_type) { + case ImageType::Image3D: + imageDepth = imgInfo.imgDesc.image_depth; CPP_ATTRIBUTE_FALLTHROUGH; - case CL_MEM_OBJECT_IMAGE2D: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - imageHeight = imgInfo.imgDesc->image_height; + case ImageType::Image2D: + case ImageType::Image2DArray: + imageHeight = imgInfo.imgDesc.image_height; break; default: break; } - auto hostPtrRowPitch = imgInfo.imgDesc->image_row_pitch ? imgInfo.imgDesc->image_row_pitch : imageWidth * imgInfo.surfaceFormat->ImageElementSizeInBytes; - auto hostPtrSlicePitch = imgInfo.imgDesc->image_slice_pitch ? imgInfo.imgDesc->image_slice_pitch : hostPtrRowPitch * imgInfo.imgDesc->image_height; + auto hostPtrRowPitch = imgInfo.imgDesc.image_row_pitch ? imgInfo.imgDesc.image_row_pitch : imageWidth * imgInfo.surfaceFormat->ImageElementSizeInBytes; + auto hostPtrSlicePitch = imgInfo.imgDesc.image_slice_pitch ? imgInfo.imgDesc.image_slice_pitch : hostPtrRowPitch * imgInfo.imgDesc.image_height; size_t pointerPassedSize = hostPtrRowPitch * imageHeight * imageDepth * imageCount; auto alignedSizePassedPointer = alignSizeWholePage(const_cast(hostPtr), pointerPassedSize); @@ -736,6 +737,76 @@ bool Image::isCopyRequired(ImageInfo &imgInfo, const void *hostPtr) { return copyRequired; } +cl_mem_object_type Image::convertType(const ImageType type) { + switch (type) { + case ImageType::Image2D: + return CL_MEM_OBJECT_IMAGE2D; + case ImageType::Image3D: + return CL_MEM_OBJECT_IMAGE3D; + case ImageType::Image2DArray: + return CL_MEM_OBJECT_IMAGE2D_ARRAY; + case ImageType::Image1D: + return CL_MEM_OBJECT_IMAGE1D; + case ImageType::Image1DArray: + return CL_MEM_OBJECT_IMAGE1D_ARRAY; + case ImageType::Image1DBuffer: + return CL_MEM_OBJECT_IMAGE1D_BUFFER; + default: + break; + } + return 0; +} + +ImageType Image::convertType(const cl_mem_object_type type) { + switch (type) { + case CL_MEM_OBJECT_IMAGE2D: + return ImageType::Image2D; + case CL_MEM_OBJECT_IMAGE3D: + return ImageType::Image3D; + case CL_MEM_OBJECT_IMAGE2D_ARRAY: + return ImageType::Image2DArray; + case CL_MEM_OBJECT_IMAGE1D: + return ImageType::Image1D; + case CL_MEM_OBJECT_IMAGE1D_ARRAY: + return ImageType::Image1DArray; + case CL_MEM_OBJECT_IMAGE1D_BUFFER: + return ImageType::Image1DBuffer; + default: + break; + } + return ImageType::Invalid; +} + +ImageDescriptor Image::convertDescriptor(const cl_image_desc &imageDesc) { + ImageDescriptor desc = {}; + desc.from_parent = imageDesc.mem_object != nullptr; + desc.image_array_size = imageDesc.image_array_size; + desc.image_depth = imageDesc.image_depth; + desc.image_height = imageDesc.image_height; + desc.image_row_pitch = imageDesc.image_row_pitch; + desc.image_slice_pitch = imageDesc.image_slice_pitch; + desc.image_type = convertType(imageDesc.image_type); + desc.image_width = imageDesc.image_width; + desc.num_mip_levels = imageDesc.num_mip_levels; + desc.num_samples = imageDesc.num_samples; + return desc; +} + +cl_image_desc Image::convertDescriptor(const ImageDescriptor &imageDesc) { + cl_image_desc desc = {}; + desc.mem_object = nullptr; + desc.image_array_size = imageDesc.image_array_size; + desc.image_depth = imageDesc.image_depth; + desc.image_height = imageDesc.image_height; + desc.image_row_pitch = imageDesc.image_row_pitch; + desc.image_slice_pitch = imageDesc.image_slice_pitch; + desc.image_type = convertType(imageDesc.image_type); + desc.image_width = imageDesc.image_width; + desc.num_mip_levels = imageDesc.num_mip_levels; + desc.num_samples = imageDesc.num_samples; + return desc; +} + cl_int Image::getImageInfo(cl_image_info paramName, size_t paramValueSize, void *paramValue, diff --git a/runtime/mem_obj/image.h b/runtime/mem_obj/image.h index 514973a8eb..42d4d39de5 100644 --- a/runtime/mem_obj/image.h +++ b/runtime/mem_obj/image.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -120,6 +120,11 @@ class Image : public MemObj { static bool isCopyRequired(ImageInfo &imgInfo, const void *hostPtr); + static ImageType convertType(const cl_mem_object_type type); + static cl_mem_object_type convertType(const ImageType type); + static ImageDescriptor convertDescriptor(const cl_image_desc &imageDesc); + static cl_image_desc convertDescriptor(const ImageDescriptor &imageDesc); + cl_int getImageInfo(cl_image_info paramName, size_t paramValueSize, void *paramValue, diff --git a/runtime/sharings/d3d/d3d_sharing.cpp b/runtime/sharings/d3d/d3d_sharing.cpp index eef8240a5f..59df5f0ee7 100644 --- a/runtime/sharings/d3d/d3d_sharing.cpp +++ b/runtime/sharings/d3d/d3d_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -67,15 +67,15 @@ void D3DSharing::releaseResource(MemObj *memObject) { } template -void D3DSharing::updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, cl_image_desc &imgDesc, OCLPlane oclPlane, cl_uint arrayIndex) { +void D3DSharing::updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, OCLPlane oclPlane, cl_uint arrayIndex) { - gmm->updateImgInfoAndDesc(imgInfo, imgDesc, arrayIndex); + gmm->updateImgInfoAndDesc(imgInfo, arrayIndex); if (oclPlane == OCLPlane::PLANE_U || oclPlane == OCLPlane::PLANE_V || oclPlane == OCLPlane::PLANE_UV) { - imgDesc.image_width /= 2; - imgDesc.image_height /= 2; + imgInfo.imgDesc.image_width /= 2; + imgInfo.imgDesc.image_height /= 2; if (oclPlane != OCLPlane::PLANE_UV) { - imgDesc.image_row_pitch /= 2; + imgInfo.imgDesc.image_row_pitch /= 2; } } } diff --git a/runtime/sharings/d3d/d3d_sharing.h b/runtime/sharings/d3d/d3d_sharing.h index 7e452767ea..63bbae920e 100644 --- a/runtime/sharings/d3d/d3d_sharing.h +++ b/runtime/sharings/d3d/d3d_sharing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -40,7 +40,7 @@ class D3DSharing : public SharingHandler { static bool isFormatWithPlane1(DXGI_FORMAT format); protected: - static void updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, cl_image_desc &imgDesc, OCLPlane oclPlane, cl_uint arrayIndex); + static void updateImgInfoAndDesc(Gmm *gmm, ImageInfo &imgInfo, OCLPlane oclPlane, cl_uint arrayIndex); Context *context; D3DSharingFunctions *sharingFunctions = nullptr; diff --git a/runtime/sharings/d3d/d3d_surface.cpp b/runtime/sharings/d3d/d3d_surface.cpp index e14708b8a2..9df9e43567 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -35,7 +35,6 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo cl_dx9_media_adapter_type_khr adapterType, cl_uint plane, cl_int *retCode) { ErrorCodeHelper err(retCode, CL_SUCCESS); D3D9Surface *surfaceStaging = nullptr; - cl_image_desc imgDesc = {}; ImageInfo imgInfo = {}; cl_image_format imgFormat = {}; McsSurfaceInfo mcsSurfaceInfo = {}; @@ -53,13 +52,12 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo sharingFcns->updateDevice(surfaceInfo->resource); - imgInfo.imgDesc = &imgDesc; - imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imgInfo.imgDesc.image_type = ImageType::Image2D; D3D9SurfaceDesc surfaceDesc = {}; sharingFcns->getTexture2dDesc(&surfaceDesc, surfaceInfo->resource); - imgDesc.image_width = surfaceDesc.Width; - imgDesc.image_height = surfaceDesc.Height; + imgInfo.imgDesc.image_width = surfaceDesc.Width; + imgInfo.imgDesc.image_height = surfaceDesc.Height; if (surfaceDesc.Pool != D3DPOOL_DEFAULT) { err.set(CL_INVALID_DX9_RESOURCE_INTEL); @@ -84,15 +82,15 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo AllocationProperties allocProperties(rootDeviceIndex, false, 0u, GraphicsAllocation::AllocationType::SHARED_IMAGE, false); alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle((osHandle)((UINT_PTR)surfaceInfo->shared_handle), allocProperties, false); - updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imgDesc, oclPlane, 0u); + updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, oclPlane, 0u); } else { lockable = !(surfaceDesc.Usage & D3DResourceFlags::USAGE_RENDERTARGET) || oclPlane != OCLPlane::NO_PLANE; if (!lockable) { sharingFcns->createTexture2d(&surfaceStaging, &surfaceDesc, 0u); } if (oclPlane == OCLPlane::PLANE_U || oclPlane == OCLPlane::PLANE_V || oclPlane == OCLPlane::PLANE_UV) { - imgDesc.image_width /= 2; - imgDesc.image_height /= 2; + imgInfo.imgDesc.image_width /= 2; + imgInfo.imgDesc.image_height /= 2; } MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0); AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, true, memoryProperties); @@ -100,8 +98,8 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo alloc = context->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); - imgDesc.image_row_pitch = imgInfo.rowPitch; - imgDesc.image_slice_pitch = imgInfo.slicePitch; + imgInfo.imgDesc.image_row_pitch = imgInfo.rowPitch; + imgInfo.imgDesc.image_slice_pitch = imgInfo.slicePitch; } DEBUG_BREAK_IF(!alloc); diff --git a/runtime/sharings/d3d/d3d_texture.cpp b/runtime/sharings/d3d/d3d_texture.cpp index dff432ac5d..2a1a066181 100644 --- a/runtime/sharings/d3d/d3d_texture.cpp +++ b/runtime/sharings/d3d/d3d_texture.cpp @@ -29,12 +29,10 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ OCLPlane oclPlane = OCLPlane::NO_PLANE; void *sharedHandle = nullptr; cl_uint arrayIndex = 0u; - cl_image_desc imgDesc = {}; cl_image_format imgFormat = {}; McsSurfaceInfo mcsSurfaceInfo = {}; ImageInfo imgInfo = {}; - imgInfo.imgDesc = &imgDesc; - imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imgInfo.imgDesc.image_type = ImageType::Image2D; D3DTexture2dDesc textureDesc = {}; sharingFcns->getTexture2dDesc(&textureDesc, d3dTexture); @@ -77,7 +75,7 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ } DEBUG_BREAK_IF(!alloc); - updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imgDesc, oclPlane, arrayIndex); + updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, oclPlane, arrayIndex); auto d3dTextureObj = new D3DTexture(context, d3dTexture, subresource, textureStaging, sharedResource); @@ -102,12 +100,10 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ ErrorCodeHelper err(retCode, CL_SUCCESS); auto sharingFcns = context->getSharing>(); void *sharedHandle = nullptr; - cl_image_desc imgDesc = {}; cl_image_format imgFormat = {}; McsSurfaceInfo mcsSurfaceInfo = {}; ImageInfo imgInfo = {}; - imgInfo.imgDesc = &imgDesc; - imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; + imgInfo.imgDesc.image_type = ImageType::Image3D; D3DTexture3dDesc textureDesc = {}; sharingFcns->getTexture3dDesc(&textureDesc, d3dTexture); @@ -141,7 +137,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ } DEBUG_BREAK_IF(!alloc); - updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imgDesc, OCLPlane::NO_PLANE, 0u); + updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, OCLPlane::NO_PLANE, 0u); auto d3dTextureObj = new D3DTexture(context, d3dTexture, subresource, textureStaging, sharedResource); diff --git a/runtime/sharings/gl/gl_texture.cpp b/runtime/sharings/gl/gl_texture.cpp index c81567ea26..3d70855be4 100644 --- a/runtime/sharings/gl/gl_texture.cpp +++ b/runtime/sharings/gl/gl_texture.cpp @@ -128,15 +128,15 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl } mcsSurfaceInfo.multisampleCount = GmmTypesConverter::getRenderMultisamplesCount(static_cast(imgDesc.num_samples)); - ImageInfo imgInfo = {0}; - imgInfo.imgDesc = &imgDesc; - imgInfo.surfaceFormat = &surfaceFormatInfo; - imgInfo.qPitch = qPitch; - if (miplevel < 0) { imgDesc.num_mip_levels = gmm->gmmResourceInfo->getMaxLod() + 1; } + ImageInfo imgInfo = {}; + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); + imgInfo.surfaceFormat = &surfaceFormatInfo; + imgInfo.qPitch = qPitch; + auto glTexture = new GlTexture(sharingFunctions, getClGlObjectType(target), texture, texInfo, target, std::max(miplevel, 0)); auto hwInfo = memoryManager->peekExecutionEnvironment().getHardwareInfo(); @@ -147,7 +147,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl } return Image::createSharedImage(context, glTexture, mcsSurfaceInfo, alloc, mcsAlloc, flags, imgInfo, cubeFaceIndex, - std::max(miplevel, 0), imgDesc.num_mip_levels); + std::max(miplevel, 0), imgInfo.imgDesc.num_mip_levels); } // namespace NEO void GlTexture::synchronizeObject(UpdateData &updateData) { diff --git a/runtime/sharings/unified/unified_image.cpp b/runtime/sharings/unified/unified_image.cpp index bf959ae3ac..21019805e4 100644 --- a/runtime/sharings/unified/unified_image.cpp +++ b/runtime/sharings/unified/unified_image.cpp @@ -25,7 +25,7 @@ Image *UnifiedImage::createSharedUnifiedImage(Context *context, cl_mem_flags fla UnifiedSharingFunctions *sharingFunctions = context->getSharing(); ImageInfo imgInfo = {}; - imgInfo.imgDesc = imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(*imageDesc); imgInfo.surfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat); GraphicsAllocation *graphicsAllocation = createGraphicsAllocation(context, description); diff --git a/runtime/sharings/va/va_surface.cpp b/runtime/sharings/va/va_surface.cpp index 6d20cb20a5..bf1db6dc07 100644 --- a/runtime/sharings/va/va_surface.cpp +++ b/runtime/sharings/va/va_surface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,17 +27,18 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; cl_channel_order channelOrder = CL_RG; cl_channel_type channelType = CL_UNORM_INT8; - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; VAImageID imageId = 0; McsSurfaceInfo mcsSurfaceInfo = {}; sharingFunctions->deriveImage(*surface, &vaImage); imageId = vaImage.image_id; - imgInfo.imgDesc = &imgDesc; + imgDesc.image_width = vaImage.width; imgDesc.image_height = vaImage.height; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); if (plane == 0) { imgInfo.plane = GMM_PLANE_Y; @@ -77,6 +78,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh imgInfo.xOffset = 0; imgInfo.yOffsetForUVPlane = static_cast(imgInfo.offset / vaImage.pitches[0]); } + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); sharingFunctions->destroyImage(vaImage.image_id); auto vaSurface = new VASurface(sharingFunctions, imageId, plane, surface, context->getInteropUserSyncEnabled()); diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 5c94015262..fc5b6fe545 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -241,7 +241,7 @@ TEST_F(GmmTests, given2DimageFromBufferParametersWhenGmmResourceIsCreatedAndPitc SurfaceFormatInfo surfaceFormat = {{CL_RGBA, CL_FLOAT}, GMM_FORMAT_R32G32B32A32_FLOAT_TYPE, (GFX3DSTATE_SURFACEFORMAT)0, 0, 4, 4, 16}; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, &surfaceFormat); - EXPECT_EQ(imgInfo.imgDesc->image_row_pitch, imgDesc.image_row_pitch); + EXPECT_EQ(imgInfo.imgDesc.image_row_pitch, imgDesc.image_row_pitch); auto queryGmm = MockGmm::queryImgParams(executionEnvironment->getGmmClientContext(), imgInfo); auto renderSize = queryGmm->gmmResourceInfo->getSizeAllocation(); @@ -489,8 +489,6 @@ TEST_P(GmmImgTest, updateImgInfoAndDesc) { }; ImageInfo updateImgInfo = {}; - cl_image_desc updateImgDesc = {}; - updateImgInfo.imgDesc = &updateImgDesc; updateImgInfo.plane = GMM_YUV_PLANE::GMM_PLANE_U; uint32_t expectCalls = 1u; @@ -531,15 +529,15 @@ TEST_P(GmmImgTest, updateImgInfoAndDesc) { auto mockResInfo = new NiceMock(&queryGmm->resourceParams); queryGmm->gmmResourceInfo.reset(mockResInfo); - queryGmm->updateImgInfoAndDesc(updateImgInfo, updateImgDesc, arrayIndex); + queryGmm->updateImgInfoAndDesc(updateImgInfo, arrayIndex); EXPECT_EQ(expectCalls, mockResInfo->getOffsetCalled); - EXPECT_EQ(imgDesc.image_width, updateImgDesc.image_width); - EXPECT_EQ(imgDesc.image_height, updateImgDesc.image_height); - EXPECT_EQ(imgDesc.image_depth, updateImgDesc.image_depth); - EXPECT_EQ(imgDesc.image_array_size, updateImgDesc.image_array_size); - EXPECT_GT(updateImgDesc.image_row_pitch, 0u); - EXPECT_GT(updateImgDesc.image_slice_pitch, 0u); + EXPECT_EQ(imgDesc.image_width, updateImgInfo.imgDesc.image_width); + EXPECT_EQ(imgDesc.image_height, updateImgInfo.imgDesc.image_height); + EXPECT_EQ(imgDesc.image_depth, updateImgInfo.imgDesc.image_depth); + EXPECT_EQ(imgDesc.image_array_size, updateImgInfo.imgDesc.image_array_size); + EXPECT_GT(updateImgInfo.imgDesc.image_row_pitch, 0u); + EXPECT_GT(updateImgInfo.imgDesc.image_slice_pitch, 0u); if (expectCalls == 1) { EXPECT_TRUE(memcmp(&expectedReqInfo[1], &mockResInfo->givenReqInfo[0], sizeof(GMM_REQ_OFFSET_INFO)) == 0); diff --git a/unit_tests/mem_obj/image_redescribe_tests.cpp b/unit_tests/mem_obj/image_redescribe_tests.cpp index 8e773e7d8c..f047e0338c 100644 --- a/unit_tests/mem_obj/image_redescribe_tests.cpp +++ b/unit_tests/mem_obj/image_redescribe_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -210,7 +210,7 @@ TEST_P(ImageRedescribeTest, givenImageWithMaxSizesWhenItIsRedescribedThenNewImag imageNew->getImageDesc().image_height); } -static uint32_t ImageType[] = { +static uint32_t ImageTypes[] = { CL_MEM_OBJECT_IMAGE1D, CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE1D_ARRAY, @@ -222,4 +222,4 @@ INSTANTIATE_TEST_CASE_P( ImageRedescribeTest, testing::Combine( ::testing::Range(readWriteSurfaceFormatsStart, SurfaceFormats::readWrite().size()), - ::testing::ValuesIn(ImageType))); + ::testing::ValuesIn(ImageTypes))); diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index f58627eff0..7ba759f7d1 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -272,7 +272,7 @@ HWTEST_F(ImageSetArgTest, givenImageArraySizeGreaterThanOneButTypeIsNotImageArra cl_image_desc imageDesc = Image2dDefaults::imageDesc; imageDesc.image_array_size = 3u; imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER; - imageInfo.imgDesc = &imageDesc; + imageInfo.imgDesc = Image::convertDescriptor(imageDesc); imageInfo.plane = GMM_NO_PLANE; auto gmm = MockGmm::queryImgParams(context.getDevice(0)->getExecutionEnvironment()->getGmmClientContext(), imageInfo); diff --git a/unit_tests/mem_obj/image_tests.cpp b/unit_tests/mem_obj/image_tests.cpp index f4d9e767b6..36f4138a48 100644 --- a/unit_tests/mem_obj/image_tests.cpp +++ b/unit_tests/mem_obj/image_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1194,7 +1194,7 @@ TEST(ImageTest, givenAllowedTilingWhenIsCopyRequiredIsCalledThenTrueIsReturned) cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR; auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat); - imgInfo.imgDesc = &imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(imageDesc); imgInfo.surfaceFormat = surfaceFormat; imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->ImageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; @@ -1220,7 +1220,7 @@ TEST(ImageTest, givenDifferentRowPitchWhenIsCopyRequiredIsCalledThenTrueIsReturn cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR; auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat); - imgInfo.imgDesc = &imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(imageDesc); imgInfo.surfaceFormat = surfaceFormat; imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->ImageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; @@ -1247,7 +1247,7 @@ TEST(ImageTest, givenDifferentSlicePitchAndTilingNotAllowedWhenIsCopyRequiredIsC imageDesc.image_height = 2; imageDesc.image_slice_pitch = imageDesc.image_width * (imageDesc.image_height + 3) * surfaceFormat->ImageElementSizeInBytes; - imgInfo.imgDesc = &imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(imageDesc); imgInfo.surfaceFormat = surfaceFormat; imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->ImageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; @@ -1272,7 +1272,7 @@ TEST(ImageTest, givenNotCachelinAlignedPointerWhenIsCopyRequiredIsCalledThenTrue imageDesc.image_width = 4096; imageDesc.image_height = 1; - imgInfo.imgDesc = &imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(imageDesc); imgInfo.surfaceFormat = surfaceFormat; imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->ImageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; @@ -1297,7 +1297,7 @@ TEST(ImageTest, givenCachelineAlignedPointerAndProperDescriptorValuesWhenIsCopyR imageDesc.image_width = 2; imageDesc.image_height = 1; - imgInfo.imgDesc = &imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(imageDesc); imgInfo.surfaceFormat = surfaceFormat; imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->ImageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; @@ -1330,12 +1330,12 @@ TEST(ImageTest, givenForcedLinearImages3DImageAndProperDescriptorValuesWhenIsCop imageDesc.image_height = 2; imageDesc.image_depth = 2; - imgInfo.imgDesc = &imageDesc; + imgInfo.imgDesc = Image::convertDescriptor(imageDesc); imgInfo.surfaceFormat = surfaceFormat; imgInfo.rowPitch = imageDesc.image_width * surfaceFormat->ImageElementSizeInBytes; imgInfo.slicePitch = imgInfo.rowPitch * imageDesc.image_height; imgInfo.size = imgInfo.slicePitch; - imgInfo.linearStorage = !hwHelper.tilingAllowed(false, Image::isImage1d(*imgInfo.imgDesc), false); + imgInfo.linearStorage = !hwHelper.tilingAllowed(false, Image::isImage1d(Image::convertDescriptor(imgInfo.imgDesc)), false); auto hostPtr = alignedMalloc(imgInfo.size, MemoryConstants::cacheLineSize); @@ -1382,6 +1382,76 @@ TEST(ImageTest, givenClMemCopyHostPointerPassedToImageCreateWhenAllocationIsNotI EXPECT_LT(taskCount, taskCountSent); } +struct ImageConvertTypeTest + : public ::testing::Test { + + void SetUp() override { + } + + void TearDown() override { + } + + std::array, 7> types = {std::make_pair<>(CL_MEM_OBJECT_IMAGE1D, ImageType::Image1D), + std::make_pair<>(CL_MEM_OBJECT_IMAGE2D, ImageType::Image2D), + std::make_pair<>(CL_MEM_OBJECT_IMAGE3D, ImageType::Image3D), + std::make_pair<>(CL_MEM_OBJECT_IMAGE1D_ARRAY, ImageType::Image1DArray), + std::make_pair<>(CL_MEM_OBJECT_IMAGE2D_ARRAY, ImageType::Image2DArray), + std::make_pair<>(CL_MEM_OBJECT_IMAGE1D_BUFFER, ImageType::Image1DBuffer), + std::make_pair<>(0, ImageType::Invalid)}; +}; + +TEST_F(ImageConvertTypeTest, givenClMemObjectTypeWhenConvertedThenCorrectImageTypeIsReturned) { + + for (size_t i = 0; i < types.size(); i++) { + EXPECT_EQ(types[i].second, Image::convertType(static_cast(types[i].first))); + } +} + +TEST_F(ImageConvertTypeTest, givenImageTypeWhenConvertedThenCorrectClMemObjectTypeIsReturned) { + + for (size_t i = 0; i < types.size(); i++) { + EXPECT_EQ(static_cast(types[i].first), Image::convertType(types[i].second)); + } +} + +TEST(ImageConvertDescriptorTest, givenClImageDescWhenConvertedThenCorrectImageDescriptorIsReturned) { + cl_image_desc clDesc = {CL_MEM_OBJECT_IMAGE1D, 16, 24, 1, 1, 1024, 2048, 1, 3, {nullptr}}; + auto desc = Image::convertDescriptor(clDesc); + + EXPECT_EQ(ImageType::Image1D, desc.image_type); + EXPECT_EQ(clDesc.image_array_size, desc.image_array_size); + EXPECT_EQ(clDesc.image_depth, desc.image_depth); + EXPECT_EQ(clDesc.image_height, desc.image_height); + EXPECT_EQ(clDesc.image_row_pitch, desc.image_row_pitch); + EXPECT_EQ(clDesc.image_slice_pitch, desc.image_slice_pitch); + EXPECT_EQ(clDesc.image_width, desc.image_width); + EXPECT_EQ(clDesc.num_mip_levels, desc.num_mip_levels); + EXPECT_EQ(clDesc.num_samples, desc.num_samples); + EXPECT_FALSE(desc.from_parent); + + cl_mem temporary = reinterpret_cast(0x1234); + clDesc.mem_object = temporary; + + desc = Image::convertDescriptor(clDesc); + EXPECT_TRUE(desc.from_parent); +} + +TEST(ImageConvertDescriptorTest, givenImageDescriptorWhenConvertedThenCorrectClImageDescIsReturned) { + ImageDescriptor desc = {ImageType::Image2D, 16, 24, 1, 1, 1024, 2048, 1, 3, false}; + auto clDesc = Image::convertDescriptor(desc); + + EXPECT_EQ(clDesc.image_type, static_cast(CL_MEM_OBJECT_IMAGE2D)); + EXPECT_EQ(clDesc.image_array_size, desc.image_array_size); + EXPECT_EQ(clDesc.image_depth, desc.image_depth); + EXPECT_EQ(clDesc.image_height, desc.image_height); + EXPECT_EQ(clDesc.image_row_pitch, desc.image_row_pitch); + EXPECT_EQ(clDesc.image_slice_pitch, desc.image_slice_pitch); + EXPECT_EQ(clDesc.image_width, desc.image_width); + EXPECT_EQ(clDesc.num_mip_levels, desc.num_mip_levels); + EXPECT_EQ(clDesc.num_samples, desc.num_samples); + EXPECT_EQ(nullptr, clDesc.mem_object); +} + typedef ::testing::TestWithParam MipLevelCoordinateTest; TEST_P(MipLevelCoordinateTest, givenMipmappedImageWhenValidateRegionAndOriginIsCalledThenAdditionalOriginCoordinateIsAnalyzed) { diff --git a/unit_tests/mem_obj/image_tiled_tests.cpp b/unit_tests/mem_obj/image_tiled_tests.cpp index e1e1d2e010..1a0fc9ec70 100644 --- a/unit_tests/mem_obj/image_tiled_tests.cpp +++ b/unit_tests/mem_obj/image_tiled_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -89,13 +89,13 @@ HWTEST_P(CreateTiledImageTest, isTiledImageIsSetForTiledImages) { TEST_P(CreateTiledImageTest, isTiledImageIsSetForSharedImages) { MockContext context; MockGraphicsAllocation *alloc = new MockGraphicsAllocation(0, 0x1000); - ImageInfo info = {0}; + ImageInfo info = {}; McsSurfaceInfo msi = {}; SurfaceFormatInfo surfaceFormat; surfaceFormat.GMMSurfaceFormat = GMM_FORMAT_B8G8R8A8_UNORM; info.surfaceFormat = &surfaceFormat; - info.imgDesc = &imageDesc; + info.imgDesc = Image::convertDescriptor(imageDesc); info.plane = GMM_NO_PLANE; auto gmm = MockGmm::queryImgParams(context.getDevice(0)->getExecutionEnvironment()->getGmmClientContext(), info); @@ -124,7 +124,7 @@ typedef CreateTiledImageTest CreateNonTiledImageTest; TEST_P(CreateNonTiledImageTest, isTiledImageIsNotSetForNonTiledSharedImage) { MockContext context; MockGraphicsAllocation *alloc = new MockGraphicsAllocation(0, 0x1000); - ImageInfo info = {0}; + ImageInfo info = {}; McsSurfaceInfo msi = {}; SurfaceFormatInfo surfaceFormat; @@ -133,7 +133,7 @@ TEST_P(CreateNonTiledImageTest, isTiledImageIsNotSetForNonTiledSharedImage) { surfaceFormat.GMMSurfaceFormat = GMM_FORMAT_B8G8R8A8_UNORM; info.surfaceFormat = &surfaceFormat; - info.imgDesc = &imageDesc; + info.imgDesc = Image::convertDescriptor(imageDesc); info.plane = GMM_NO_PLANE; auto gmm = MockGmm::queryImgParams(context.getDevice(0)->getExecutionEnvironment()->getGmmClientContext(), info); diff --git a/unit_tests/mocks/mock_gmm.h b/unit_tests/mocks/mock_gmm.h index df5a2444fc..8bea8ca796 100644 --- a/unit_tests/mocks/mock_gmm.h +++ b/unit_tests/mocks/mock_gmm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,7 @@ #include "core/helpers/options.h" #include "runtime/gmm_helper/gmm.h" #include "runtime/helpers/surface_formats.h" +#include "runtime/mem_obj/image.h" #include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_gmm_resource_info.h" @@ -29,9 +30,9 @@ class MockGmm : public Gmm { } static ImageInfo initImgInfo(cl_image_desc &imgDesc, int baseMipLevel, const SurfaceFormatInfo *surfaceFormat) { - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; imgInfo.baseMipLevel = baseMipLevel; - imgInfo.imgDesc = &imgDesc; + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); if (!surfaceFormat) { ArrayRef readWriteSurfaceFormats = SurfaceFormats::readWrite(); MockGmmParams::mockSurfaceFormat = readWriteSurfaceFormats[0]; // any valid format diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index d5adef4150..9c88318bf3 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -1186,7 +1186,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag imgDesc.image_width = 512; imgDesc.image_height = 512; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - imgInfo.imgDesc = &imgDesc; + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); imgInfo.size = 4096u; imgInfo.rowPitch = 512u; @@ -1672,12 +1672,13 @@ TEST_F(DrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromShared cl_image_desc imgDesc = {}; cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; const SurfaceFormatInfo *gmmSurfaceFormat = nullptr; - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; - imgInfo.imgDesc = &imgDesc; imgDesc.image_width = 4; imgDesc.image_height = 4; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat); imgInfo.surfaceFormat = gmmSurfaceFormat; imgInfo.plane = GMM_PLANE_Y; @@ -1712,12 +1713,13 @@ TEST_F(DrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedHan cl_image_desc imgDesc = {}; cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; const SurfaceFormatInfo *gmmSurfaceFormat = nullptr; - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; - imgInfo.imgDesc = &imgDesc; imgDesc.image_width = 4; imgDesc.image_height = 4; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat); imgInfo.surfaceFormat = gmmSurfaceFormat; imgInfo.plane = GMM_PLANE_Y; @@ -2006,7 +2008,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAlloca imgDesc.image_width = 512; imgDesc.image_height = 512; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - imgInfo.imgDesc = &imgDesc; + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); imgInfo.size = 4096u; imgInfo.rowPitch = 512u; diff --git a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp index ca5e08af07..8568589602 100644 --- a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -76,7 +76,7 @@ class CreateFromGlTexture : public ::testing::Test { } cl_image_desc imgDesc; - ImageInfo imgInfo = {0}; + ImageInfo imgInfo = {}; std::unique_ptr gmm; std::unique_ptr mcsGmm; TempMM tempMM;