1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
|
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/surface_format_info.h"
#include "shared/source/memory_manager/allocation_type.h"
#include "shared/source/memory_manager/definitions/storage_info.h"
namespace NEO {
Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_t alignment, GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsage,
bool preferCompressed, const StorageInfo &storageInfo, bool allowLargePages) : gmmHelper(gmmHelper) {
resourceParams.Type = RESOURCE_BUFFER;
resourceParams.Format = GMM_FORMAT_GENERIC_8BIT;
resourceParams.BaseWidth64 = static_cast<uint64_t>(alignedSize);
resourceParams.BaseHeight = 1;
resourceParams.Depth = 1;
resourceParams.BaseAlignment = static_cast<uint32_t>(alignment);
if ((nullptr == alignedPtr) && (false == allowLargePages)) {
resourceParams.Flags.Info.NoOptimizationPadding = true;
if ((resourceParams.BaseWidth64 & MemoryConstants::page64kMask) == 0) {
resourceParams.BaseWidth64 += MemoryConstants::pageSize;
}
}
resourceParams.Usage = gmmResourceUsage;
resourceParams.Flags.Info.Linear = 1;
resourceParams.Flags.Info.Cacheable = !CacheSettingsHelper::isUncachedType(gmmResourceUsage);
resourceParams.Flags.Gpu.Texture = 1;
if (alignedPtr) {
resourceParams.Flags.Info.ExistingSysMem = 1;
resourceParams.pExistingSysMem = castToUint64(alignedPtr);
resourceParams.ExistingSysMemSize = alignedSize;
} else {
resourceParams.NoGfxMemory = 1u;
}
if (resourceParams.BaseWidth64 >= GmmHelper::maxPossiblePitch) {
resourceParams.Flags.Gpu.NoRestriction = 1;
}
applyAuxFlagsForBuffer(preferCompressed);
applyMemoryFlags(storageInfo);
applyAppResource(storageInfo);
applyDebugOverrides();
gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), &resourceParams));
}
Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm) : Gmm(gmmHelper, inputGmm, false) {}
Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm, bool openingHandle) : gmmHelper(gmmHelper) {
gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), inputGmm, openingHandle));
applyDebugOverrides();
}
Gmm::~Gmm() = default;
Gmm::Gmm(GmmHelper *gmmHelper, ImageInfo &inputOutputImgInfo, const StorageInfo &storageInfo, bool preferCompressed) : gmmHelper(gmmHelper) {
this->resourceParams = {};
setupImageResourceParams(inputOutputImgInfo, preferCompressed);
applyMemoryFlags(storageInfo);
applyAppResource(storageInfo);
applyDebugOverrides();
this->gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), &this->resourceParams));
UNRECOVERABLE_IF(this->gmmResourceInfo == nullptr);
queryImageParams(inputOutputImgInfo);
}
void Gmm::setupImageResourceParams(ImageInfo &imgInfo, bool preferCompressed) {
uint64_t imageWidth = static_cast<uint64_t>(imgInfo.imgDesc.imageWidth);
uint32_t imageHeight = 1;
uint32_t imageDepth = 1;
uint32_t imageCount = 1;
switch (imgInfo.imgDesc.imageType) {
case ImageType::Image1D:
case ImageType::Image1DArray:
case ImageType::Image1DBuffer:
resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
break;
case ImageType::Image2D:
case ImageType::Image2DArray:
resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_2D;
imageHeight = static_cast<uint32_t>(imgInfo.imgDesc.imageHeight);
break;
case ImageType::Image3D:
resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_3D;
imageHeight = static_cast<uint32_t>(imgInfo.imgDesc.imageHeight);
imageDepth = static_cast<uint32_t>(imgInfo.imgDesc.imageDepth);
break;
default:
return;
}
if (imgInfo.imgDesc.imageType == ImageType::Image1DArray ||
imgInfo.imgDesc.imageType == ImageType::Image2DArray) {
imageCount = static_cast<uint32_t>(imgInfo.imgDesc.imageArraySize);
}
resourceParams.Flags.Info.Linear = imgInfo.linearStorage;
auto &hwHelper = HwHelper::get(gmmHelper->getClientContext()->getHardwareInfo()->platform.eRenderCoreFamily);
resourceParams.NoGfxMemory = 1; // dont allocate, only query for params
resourceParams.Usage = CacheSettingsHelper::getGmmUsageType(AllocationType::IMAGE, false, *gmmHelper->getClientContext()->getHardwareInfo());
resourceParams.Format = imgInfo.surfaceFormat->GMMSurfaceFormat;
resourceParams.Flags.Gpu.Texture = 1;
resourceParams.BaseWidth64 = imageWidth;
resourceParams.BaseHeight = imageHeight;
resourceParams.Depth = imageDepth;
resourceParams.ArraySize = imageCount;
resourceParams.Flags.Wa.__ForceOtherHVALIGN4 = hwHelper.hvAlign4Required();
resourceParams.MaxLod = imgInfo.baseMipLevel + imgInfo.mipCount;
applyAuxFlagsForImage(imgInfo, preferCompressed);
}
void Gmm::applyAuxFlagsForBuffer(bool preferCompression) {
auto hardwareInfo = gmmHelper->getClientContext()->getHardwareInfo();
bool allowCompression = HwHelper::compressedBuffersSupported(*hardwareInfo) &&
preferCompression;
auto &hwHelper = HwHelper::get(hardwareInfo->platform.eRenderCoreFamily);
if (allowCompression) {
hwHelper.applyRenderCompressionFlag(*this, 1);
resourceParams.Flags.Gpu.CCS = 1;
resourceParams.Flags.Gpu.UnifiedAuxSurface = 1;
isCompressionEnabled = true;
}
hwHelper.applyAdditionalCompressionSettings(*this, !isCompressionEnabled);
}
void Gmm::applyAuxFlagsForImage(ImageInfo &imgInfo, bool preferCompressed) {
uint8_t compressionFormat;
if (this->resourceParams.Flags.Info.MediaCompressed) {
compressionFormat = gmmHelper->getClientContext()->getMediaSurfaceStateCompressionFormat(imgInfo.surfaceFormat->GMMSurfaceFormat);
} else {
compressionFormat = gmmHelper->getClientContext()->getSurfaceStateCompressionFormat(imgInfo.surfaceFormat->GMMSurfaceFormat);
}
bool compressionFormatSupported = false;
if (gmmHelper->getClientContext()->getHardwareInfo()->featureTable.flags.ftrFlatPhysCCS) {
compressionFormatSupported = compressionFormat != GMM_FLATCCS_FORMAT::GMM_FLATCCS_FORMAT_INVALID;
} else {
compressionFormatSupported = compressionFormat != GMM_E2ECOMP_FORMAT::GMM_E2ECOMP_FORMAT_INVALID;
}
const bool isPackedYuv = imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_FORMAT_YUY2 ||
imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_FORMAT_UYVY ||
imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_FORMAT_YVYU ||
imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_FORMAT_VYUY;
auto hwInfo = gmmHelper->getClientContext()->getHardwareInfo();
bool allowCompression = HwHelper::compressedImagesSupported(*hwInfo) &&
preferCompressed &&
compressionFormatSupported &&
imgInfo.surfaceFormat->GMMSurfaceFormat != GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12 &&
imgInfo.plane == GMM_YUV_PLANE_ENUM::GMM_NO_PLANE &&
!isPackedYuv;
auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily);
if (imgInfo.useLocalMemory || !hwInfo->featureTable.flags.ftrLocalMemory) {
if (allowCompression) {
hwHelper.applyRenderCompressionFlag(*this, 1);
this->resourceParams.Flags.Gpu.CCS = 1;
this->resourceParams.Flags.Gpu.UnifiedAuxSurface = 1;
this->resourceParams.Flags.Gpu.IndirectClearColor = 1;
this->isCompressionEnabled = true;
}
}
hwHelper.applyAdditionalCompressionSettings(*this, !isCompressionEnabled);
}
void Gmm::queryImageParams(ImageInfo &imgInfo) {
auto imageCount = this->gmmResourceInfo->getArraySize();
imgInfo.size = this->gmmResourceInfo->getSizeAllocation();
imgInfo.rowPitch = this->gmmResourceInfo->getRenderPitch();
if (imgInfo.rowPitch == 0) { // WA
imgInfo.rowPitch = alignUp(this->gmmResourceInfo->getBaseWidth(), this->gmmResourceInfo->getHAlign());
imgInfo.rowPitch = imgInfo.rowPitch * (this->gmmResourceInfo->getBitsPerPixel() >> 3);
}
// calculate slice pitch
if ((this->resourceParams.Type == GMM_RESOURCE_TYPE::RESOURCE_2D ||
this->resourceParams.Type == GMM_RESOURCE_TYPE::RESOURCE_1D) &&
imageCount == 1) {
// 2D or 1D or 1Darray with array_size=1
imgInfo.slicePitch = imgInfo.size;
} else {
// 3D Image or 2D-Array or 1D-Arrays (array_size>1)
GMM_REQ_OFFSET_INFO reqOffsetInfo = {};
reqOffsetInfo.ReqRender = 1;
reqOffsetInfo.Slice = 1;
reqOffsetInfo.ArrayIndex = (imageCount > 1) ? 1 : 0;
this->gmmResourceInfo->getOffset(reqOffsetInfo);
imgInfo.slicePitch = reqOffsetInfo.Render.Offset;
imgInfo.slicePitch += imgInfo.rowPitch * reqOffsetInfo.Render.YOffset;
imgInfo.slicePitch += reqOffsetInfo.Render.XOffset;
}
if (imgInfo.plane != GMM_NO_PLANE) {
GMM_REQ_OFFSET_INFO reqOffsetInfo = {};
reqOffsetInfo.ReqRender = 1;
reqOffsetInfo.Slice = 0;
reqOffsetInfo.ArrayIndex = 0;
reqOffsetInfo.Plane = imgInfo.plane;
this->gmmResourceInfo->getOffset(reqOffsetInfo);
imgInfo.xOffset = reqOffsetInfo.Render.XOffset / (this->gmmResourceInfo->getBitsPerPixel() / 8);
imgInfo.yOffset = reqOffsetInfo.Render.YOffset;
imgInfo.offset = reqOffsetInfo.Render.Offset;
}
if (imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12 || imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010) {
GMM_REQ_OFFSET_INFO reqOffsetInfo = {};
reqOffsetInfo.ReqLock = 1;
reqOffsetInfo.Slice = 1;
reqOffsetInfo.ArrayIndex = 0;
reqOffsetInfo.Plane = GMM_PLANE_U;
this->gmmResourceInfo->getOffset(reqOffsetInfo);
UNRECOVERABLE_IF(reqOffsetInfo.Lock.Pitch == 0);
imgInfo.yOffsetForUVPlane = reqOffsetInfo.Lock.Offset / reqOffsetInfo.Lock.Pitch;
}
imgInfo.qPitch = queryQPitch(this->resourceParams.Type);
}
uint32_t Gmm::queryQPitch(GMM_RESOURCE_TYPE resType) {
if (gmmHelper->getClientContext()->getHardwareInfo()->platform.eRenderCoreFamily == IGFX_GEN8_CORE && resType == GMM_RESOURCE_TYPE::RESOURCE_3D) {
return 0;
}
return gmmResourceInfo->getQPitch();
}
void Gmm::updateImgInfoAndDesc(ImageInfo &imgInfo, uint32_t arrayIndex) {
imgInfo.imgDesc.imageWidth = gmmResourceInfo->getBaseWidth();
imgInfo.imgDesc.imageRowPitch = gmmResourceInfo->getRenderPitch();
if (imgInfo.imgDesc.imageRowPitch == 0) {
size_t width = alignUp(imgInfo.imgDesc.imageWidth, gmmResourceInfo->getHAlign());
imgInfo.imgDesc.imageRowPitch = width * (gmmResourceInfo->getBitsPerPixel() >> 3);
}
imgInfo.imgDesc.imageHeight = gmmResourceInfo->getBaseHeight();
imgInfo.imgDesc.imageDepth = gmmResourceInfo->getBaseDepth();
imgInfo.imgDesc.imageArraySize = gmmResourceInfo->getArraySize();
if (imgInfo.imgDesc.imageDepth > 1 || imgInfo.imgDesc.imageArraySize > 1) {
GMM_REQ_OFFSET_INFO reqOffsetInfo = {};
reqOffsetInfo.Slice = imgInfo.imgDesc.imageDepth > 1 ? 1 : 0;
reqOffsetInfo.ArrayIndex = imgInfo.imgDesc.imageArraySize > 1 ? 1 : 0;
reqOffsetInfo.ReqLock = 1;
gmmResourceInfo->getOffset(reqOffsetInfo);
imgInfo.imgDesc.imageSlicePitch = static_cast<size_t>(reqOffsetInfo.Lock.Offset);
} else {
imgInfo.imgDesc.imageSlicePitch = gmmResourceInfo->getSizeAllocation();
}
updateOffsetsInImgInfo(imgInfo, arrayIndex);
}
void Gmm::updateOffsetsInImgInfo(ImageInfo &imgInfo, uint32_t arrayIndex) {
GMM_REQ_OFFSET_INFO reqOffsetInfo = {};
reqOffsetInfo.ReqRender = 1;
reqOffsetInfo.Slice = 0;
reqOffsetInfo.ArrayIndex = arrayIndex;
reqOffsetInfo.Plane = imgInfo.plane;
gmmResourceInfo->getOffset(reqOffsetInfo);
UNRECOVERABLE_IF(gmmResourceInfo->getBitsPerPixel() == 0u);
imgInfo.xOffset = reqOffsetInfo.Render.XOffset / (gmmResourceInfo->getBitsPerPixel() / 8);
imgInfo.yOffset = reqOffsetInfo.Render.YOffset;
imgInfo.offset = reqOffsetInfo.Render.Offset;
}
uint8_t Gmm::resourceCopyBlt(void *sys, void *gpu, uint32_t pitch, uint32_t height, unsigned char upload, ImagePlane plane) {
GMM_RES_COPY_BLT gmmResourceCopyBLT = {};
if (plane == ImagePlane::PLANE_V) {
sys = ptrOffset(sys, height * pitch * 2);
pitch /= 2;
} else if (plane == ImagePlane::PLANE_U) {
sys = ptrOffset(sys, height * pitch * 2 + height * pitch / 2);
pitch /= 2;
} else if (plane == ImagePlane::PLANE_UV) {
sys = ptrOffset(sys, height * pitch * 2);
}
uint32_t size = pitch * height;
gmmResourceCopyBLT.Sys.pData = sys;
gmmResourceCopyBLT.Gpu.pData = gpu;
gmmResourceCopyBLT.Sys.RowPitch = pitch;
gmmResourceCopyBLT.Blt.Upload = upload;
gmmResourceCopyBLT.Sys.BufferSize = size;
return this->gmmResourceInfo->cpuBlt(&gmmResourceCopyBLT);
}
bool Gmm::unifiedAuxTranslationCapable() const {
auto gmmFlags = this->gmmResourceInfo->getResourceFlags();
UNRECOVERABLE_IF(gmmFlags->Info.RenderCompressed && gmmFlags->Info.MediaCompressed);
return gmmFlags->Gpu.CCS && gmmFlags->Gpu.UnifiedAuxSurface && (gmmFlags->Info.RenderCompressed | gmmFlags->Info.MediaCompressed);
}
bool Gmm::hasMultisampleControlSurface() const {
return this->gmmResourceInfo->getResourceFlags()->Gpu.MCS;
}
GmmHelper *Gmm::getGmmHelper() const {
return this->gmmHelper;
}
uint32_t Gmm::getUnifiedAuxPitchTiles() {
return this->gmmResourceInfo->getRenderAuxPitchTiles();
}
uint32_t Gmm::getAuxQPitch() {
return this->gmmResourceInfo->getAuxQPitch();
}
void Gmm::applyMemoryFlags(const StorageInfo &storageInfo) {
auto hardwareInfo = gmmHelper->getClientContext()->getHardwareInfo();
if (hardwareInfo->featureTable.flags.ftrLocalMemory) {
if (storageInfo.systemMemoryPlacement) {
resourceParams.Flags.Info.NonLocalOnly = 1;
} else {
if (extraMemoryFlagsRequired()) {
applyExtraMemoryFlags(storageInfo);
} else if (!storageInfo.isLockable) {
resourceParams.Flags.Info.NotLockable = 1;
if (isCompressionEnabled || storageInfo.localOnlyRequired) {
resourceParams.Flags.Info.LocalOnly = 1;
}
}
}
}
if (hardwareInfo->featureTable.flags.ftrMultiTileArch) {
resourceParams.MultiTileArch.Enable = 1;
if (storageInfo.systemMemoryPlacement) {
resourceParams.MultiTileArch.GpuVaMappingSet = hardwareInfo->gtSystemInfo.MultiTileArchInfo.TileMask;
resourceParams.MultiTileArch.LocalMemPreferredSet = 0;
resourceParams.MultiTileArch.LocalMemEligibilitySet = 0;
} else {
auto tileSelected = std::max(storageInfo.memoryBanks.to_ulong(), 1lu);
if (storageInfo.cloningOfPageTables) {
resourceParams.MultiTileArch.GpuVaMappingSet = static_cast<uint8_t>(storageInfo.pageTablesVisibility.to_ulong());
} else {
resourceParams.MultiTileArch.TileInstanced = storageInfo.tileInstanced;
resourceParams.MultiTileArch.GpuVaMappingSet = static_cast<uint8_t>(tileSelected);
}
resourceParams.MultiTileArch.LocalMemPreferredSet = static_cast<uint8_t>(tileSelected);
resourceParams.MultiTileArch.LocalMemEligibilitySet = static_cast<uint8_t>(tileSelected);
}
}
}
void Gmm::applyDebugOverrides() {
if (-1 != DebugManager.flags.OverrideGmmResourceUsageField.get()) {
resourceParams.Usage = static_cast<GMM_RESOURCE_USAGE_TYPE>(DebugManager.flags.OverrideGmmResourceUsageField.get());
}
if (true == (DebugManager.flags.ForceAllResourcesUncached.get())) {
resourceParams.Usage = GMM_RESOURCE_USAGE_SURFACE_UNCACHED;
}
}
} // namespace NEO
|