2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-01-22 10:24:28 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/gmm_helper/gmm_helper.h"
|
|
|
|
|
2019-08-02 13:25:45 -07:00
|
|
|
#include "core/helpers/aligned_memory.h"
|
2019-09-05 09:35:56 +02:00
|
|
|
#include "core/helpers/debug_helpers.h"
|
2018-07-23 12:23:48 +02:00
|
|
|
#include "runtime/execution_environment/execution_environment.h"
|
2018-06-21 11:36:47 +02:00
|
|
|
#include "runtime/gmm_helper/gmm.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/gmm_helper/resource_info.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/helpers/get_info.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/helpers/hw_info.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/helpers/surface_formats.h"
|
2019-08-26 09:27:30 +02:00
|
|
|
#include "runtime/mem_obj/buffer.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
2018-07-03 10:00:12 +02:00
|
|
|
#include "runtime/os_interface/os_library.h"
|
2018-07-23 12:23:48 +02:00
|
|
|
#include "runtime/platform/platform.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/sku_info/operations/sku_info_transfer.h"
|
|
|
|
|
|
|
|
#include "gmm_client_context.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-07-23 12:23:48 +02:00
|
|
|
|
|
|
|
GmmClientContext *GmmHelper::getClientContext() {
|
|
|
|
return getInstance()->gmmClientContext.get();
|
|
|
|
}
|
|
|
|
|
2018-07-27 13:59:39 +02:00
|
|
|
const HardwareInfo *GmmHelper::getHardwareInfo() {
|
|
|
|
return hwInfo;
|
|
|
|
}
|
|
|
|
|
2018-07-23 12:23:48 +02:00
|
|
|
GmmHelper *GmmHelper::getInstance() {
|
|
|
|
return platform()->peekExecutionEnvironment()->getGmmHelper();
|
|
|
|
}
|
|
|
|
|
2018-07-27 13:59:39 +02:00
|
|
|
void GmmHelper::setSimplifiedMocsTableUsage(bool value) {
|
|
|
|
useSimplifiedMocsTable = value;
|
|
|
|
}
|
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
void GmmHelper::initContext(const PLATFORM *platform,
|
|
|
|
const FeatureTable *featureTable,
|
|
|
|
const WorkaroundTable *workaroundTable,
|
2018-06-21 11:36:47 +02:00
|
|
|
const GT_SYSTEM_INFO *pGtSysInfo) {
|
2018-07-23 12:23:48 +02:00
|
|
|
_SKU_FEATURE_TABLE gmmFtrTable = {};
|
|
|
|
_WA_TABLE gmmWaTable = {};
|
2019-05-08 16:00:24 +02:00
|
|
|
SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, featureTable);
|
|
|
|
SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, workaroundTable);
|
2018-07-23 12:23:48 +02:00
|
|
|
loadLib();
|
2019-05-08 16:00:24 +02:00
|
|
|
bool success = GMM_SUCCESS == gmmEntries.pfnCreateSingletonContext(*platform, &gmmFtrTable, &gmmWaTable, pGtSysInfo);
|
2018-07-23 12:23:48 +02:00
|
|
|
UNRECOVERABLE_IF(!success);
|
2018-07-31 09:00:31 +02:00
|
|
|
gmmClientContext = GmmHelper::createGmmContextWrapperFunc(GMM_CLIENT::GMM_OCL_VISTA, gmmEntries);
|
2018-07-23 12:23:48 +02:00
|
|
|
UNRECOVERABLE_IF(!gmmClientContext);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 11:36:47 +02:00
|
|
|
uint32_t GmmHelper::getMOCS(uint32_t type) {
|
2018-01-25 08:30:57 +01:00
|
|
|
if (useSimplifiedMocsTable) {
|
|
|
|
if (type == GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED) {
|
|
|
|
return cacheDisabledIndex;
|
|
|
|
} else {
|
|
|
|
return cacheEnabledIndex;
|
|
|
|
}
|
|
|
|
}
|
2018-07-23 12:23:48 +02:00
|
|
|
MEMORY_OBJECT_CONTROL_STATE mocs = gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
return static_cast<uint32_t>(mocs.DwordValue);
|
|
|
|
}
|
|
|
|
|
2018-06-21 11:36:47 +02:00
|
|
|
void GmmHelper::queryImgFromBufferParams(ImageInfo &imgInfo, GraphicsAllocation *gfxAlloc) {
|
2017-12-21 00:45:38 +01:00
|
|
|
// 1D or 2D from buffer
|
|
|
|
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.slicePitch = imgInfo.rowPitch * getValidParam(imgInfo.imgDesc->image_height);
|
|
|
|
imgInfo.size = gfxAlloc->getUnderlyingBufferSize();
|
|
|
|
imgInfo.qPitch = 0;
|
|
|
|
}
|
|
|
|
|
2018-06-21 11:36:47 +02:00
|
|
|
uint64_t GmmHelper::canonize(uint64_t address) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return ((int64_t)((address & 0xFFFFFFFFFFFF) << (64 - 48))) >> (64 - 48);
|
|
|
|
}
|
|
|
|
|
2018-06-21 11:36:47 +02:00
|
|
|
uint64_t GmmHelper::decanonize(uint64_t address) {
|
2018-01-31 11:22:13 +01:00
|
|
|
return (uint64_t)(address & 0xFFFFFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
2018-06-21 11:36:47 +02:00
|
|
|
uint32_t GmmHelper::getRenderMultisamplesCount(uint32_t numSamples) {
|
2017-12-21 00:45:38 +01:00
|
|
|
if (numSamples == 2) {
|
|
|
|
return 1;
|
|
|
|
} else if (numSamples == 4) {
|
|
|
|
return 2;
|
|
|
|
} else if (numSamples == 8) {
|
|
|
|
return 3;
|
|
|
|
} else if (numSamples == 16) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-21 11:36:47 +02:00
|
|
|
GMM_YUV_PLANE GmmHelper::convertPlane(OCLPlane oclPlane) {
|
2017-12-21 00:45:38 +01:00
|
|
|
if (oclPlane == OCLPlane::PLANE_Y) {
|
|
|
|
return GMM_PLANE_Y;
|
|
|
|
} else if (oclPlane == OCLPlane::PLANE_U || oclPlane == OCLPlane::PLANE_UV) {
|
|
|
|
return GMM_PLANE_U;
|
|
|
|
} else if (oclPlane == OCLPlane::PLANE_V) {
|
|
|
|
return GMM_PLANE_V;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GMM_NO_PLANE;
|
|
|
|
}
|
2018-07-27 13:59:39 +02:00
|
|
|
GmmHelper::GmmHelper(const HardwareInfo *pHwInfo) : hwInfo(pHwInfo) {
|
2019-05-08 16:00:24 +02:00
|
|
|
initContext(&pHwInfo->platform, &pHwInfo->featureTable, &pHwInfo->workaroundTable, &pHwInfo->gtSystemInfo);
|
2018-07-03 10:00:12 +02:00
|
|
|
}
|
|
|
|
GmmHelper::~GmmHelper() {
|
2018-07-31 09:00:31 +02:00
|
|
|
gmmEntries.pfnDestroySingletonContext();
|
2018-07-23 12:23:48 +02:00
|
|
|
};
|
2018-07-27 14:08:40 +02:00
|
|
|
decltype(GmmHelper::createGmmContextWrapperFunc) GmmHelper::createGmmContextWrapperFunc = GmmClientContextBase::create<GmmClientContext>;
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|