| 1 |
/* |
| 2 |
* Copyright (C) 2019-2024 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "unified_image.h" |
| 9 |
|
| 10 |
#include "shared/source/gmm_helper/gmm.h" |
| 11 |
#include "shared/source/helpers/get_info.h" |
| 12 |
#include "shared/source/helpers/hw_info.h" |
| 13 |
#include "shared/source/helpers/surface_format_info.h" |
| 14 |
#include "shared/source/memory_manager/graphics_allocation.h" |
| 15 |
#include "shared/source/memory_manager/memory_manager.h" |
| 16 |
#include "shared/source/os_interface/product_helper.h" |
| 17 |
|
| 18 |
#include "opencl/source/cl_device/cl_device.h" |
| 19 |
#include "opencl/source/context/context.h" |
| 20 |
#include "opencl/source/mem_obj/image.h" |
| 21 |
|
| 22 |
namespace NEO { |
| 23 |
|
| 24 |
Image *UnifiedImage::createSharedUnifiedImage(Context *context, cl_mem_flags flags, UnifiedSharingMemoryDescription description, |
| 25 |
const cl_image_format *imageFormat, const cl_image_desc *imageDesc, cl_int *errcodeRet) { |
| 26 |
ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS); |
| 27 |
UnifiedSharingFunctions *sharingFunctions = context->getSharing<UnifiedSharingFunctions>(); |
| 28 |
|
| 29 |
auto *clSurfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); |
| 30 |
ImageInfo imgInfo = {}; |
| 31 |
imgInfo.imgDesc = Image::convertDescriptor(*imageDesc); |
| 32 |
imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat; |
| 33 |
|
| 34 |
GraphicsAllocation *graphicsAllocation = createGraphicsAllocation(context, description, &imgInfo, AllocationType::sharedImage); |
| 35 |
if (!graphicsAllocation) { |
| 36 |
errorCode.set(CL_INVALID_MEM_OBJECT); |
| 37 |
return nullptr; |
| 38 |
} |
| 39 |
|
| 40 |
swapGmm(graphicsAllocation, context, &imgInfo); |
| 41 |
|
| 42 |
auto &memoryManager = *context->getMemoryManager(); |
| 43 |
if (graphicsAllocation->getDefaultGmm()->unifiedAuxTranslationCapable()) { |
| 44 |
const auto &hwInfo = context->getDevice(0)->getHardwareInfo(); |
| 45 |
const auto &productHelper = context->getDevice(0)->getProductHelper(); |
| 46 |
graphicsAllocation->getDefaultGmm()->setCompressionEnabled(productHelper.isPageTableManagerSupported(hwInfo) ? memoryManager.mapAuxGpuVA(graphicsAllocation) : true); |
| 47 |
} |
| 48 |
|
| 49 |
const uint32_t baseMipmapIndex = 0u; |
| 50 |
const uint32_t sharedMipmapsCount = imageDesc->num_mip_levels; |
| 51 |
auto sharingHandler = new UnifiedImage(sharingFunctions, description.type); |
| 52 |
auto multiGraphicsAllocation = MultiGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex()); |
| 53 |
multiGraphicsAllocation.addAllocation(graphicsAllocation); |
| 54 |
|
| 55 |
return Image::createSharedImage(context, sharingHandler, McsSurfaceInfo{}, std::move(multiGraphicsAllocation), nullptr, |
| 56 |
flags, 0, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, baseMipmapIndex, sharedMipmapsCount); |
| 57 |
} |
| 58 |
|
| 59 |
} // namespace NEO |