Refactor GMM creation

- extract createResourceParams method from queryImageParams
- add tilingMode to ImageInfo

Change-Id: I32cc2a7d32892147545017e592e2796f85057b46
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe 2019-04-01 07:22:13 +02:00 committed by sys_ocldev
parent 68311588e6
commit e82d6e63cb
6 changed files with 114 additions and 29 deletions

View File

@ -57,11 +57,15 @@ Gmm::Gmm(GMM_RESOURCE_INFO *inputGmm) {
}
Gmm::Gmm(ImageInfo &inputOutputImgInfo) {
this->resourceParams = {};
setupImageResourceParams(inputOutputImgInfo);
this->gmmResourceInfo.reset(GmmResourceInfo::create(&this->resourceParams));
UNRECOVERABLE_IF(this->gmmResourceInfo == nullptr);
queryImageParams(inputOutputImgInfo);
}
void Gmm::queryImageParams(ImageInfo &imgInfo) {
this->resourceParams = {};
void Gmm::setupImageResourceParams(ImageInfo &imgInfo) {
uint64_t imageWidth = static_cast<uint64_t>(imgInfo.imgDesc->image_width);
uint32_t imageHeight = 1;
uint32_t imageDepth = 1;
@ -71,15 +75,15 @@ void Gmm::queryImageParams(ImageInfo &imgInfo) {
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
this->resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
break;
case CL_MEM_OBJECT_IMAGE2D:
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
this->resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_2D;
resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_2D;
imageHeight = static_cast<uint32_t>(imgInfo.imgDesc->image_height);
break;
case CL_MEM_OBJECT_IMAGE3D:
this->resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_3D;
resourceParams.Type = GMM_RESOURCE_TYPE::RESOURCE_3D;
imageHeight = static_cast<uint32_t>(imgInfo.imgDesc->image_height);
imageDepth = static_cast<uint32_t>(imgInfo.imgDesc->image_depth);
break;
@ -92,36 +96,50 @@ void Gmm::queryImageParams(ImageInfo &imgInfo) {
imageCount = static_cast<uint32_t>(imgInfo.imgDesc->image_array_size);
}
this->resourceParams.Flags.Info.Linear = 1;
resourceParams.Flags.Info.Linear = 1;
switch (imgInfo.tilingMode) {
case TilingMode::DEFAULT:
if (GmmHelper::allowTiling(*imgInfo.imgDesc)) {
this->resourceParams.Flags.Info.TiledY = 1;
resourceParams.Flags.Info.TiledY = 1;
}
break;
case TilingMode::TILE_Y:
resourceParams.Flags.Info.TiledY = 1;
break;
case TilingMode::NON_TILED:
break;
default:
UNRECOVERABLE_IF(true);
break;
}
this->resourceParams.NoGfxMemory = 1; // dont allocate, only query for params
resourceParams.NoGfxMemory = 1; // dont allocate, only query for params
this->resourceParams.Usage = GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE;
this->resourceParams.Format = imgInfo.surfaceFormat->GMMSurfaceFormat;
this->resourceParams.Flags.Gpu.Texture = 1;
this->resourceParams.BaseWidth64 = imageWidth;
this->resourceParams.BaseHeight = imageHeight;
this->resourceParams.Depth = imageDepth;
this->resourceParams.ArraySize = imageCount;
this->resourceParams.Flags.Wa.__ForceOtherHVALIGN4 = 1;
this->resourceParams.MaxLod = imgInfo.baseMipLevel + imgInfo.mipCount;
resourceParams.Usage = GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE;
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 = 1;
resourceParams.MaxLod = imgInfo.baseMipLevel + imgInfo.mipCount;
if (imgInfo.imgDesc->image_row_pitch && imgInfo.imgDesc->mem_object) {
this->resourceParams.OverridePitch = (uint32_t)imgInfo.imgDesc->image_row_pitch;
this->resourceParams.Flags.Info.AllowVirtualPadding = true;
resourceParams.OverridePitch = (uint32_t)imgInfo.imgDesc->image_row_pitch;
resourceParams.Flags.Info.AllowVirtualPadding = true;
}
applyAuxFlagsForImage(imgInfo);
auto &hwHelper = HwHelper::get(GmmHelper::getInstance()->getHardwareInfo()->pPlatform->eRenderCoreFamily);
if (!hwHelper.supportsYTiling() && this->resourceParams.Flags.Info.TiledY == 1) {
this->resourceParams.Flags.Info.Linear = 0;
this->resourceParams.Flags.Info.TiledY = 0;
if (!hwHelper.supportsYTiling() && resourceParams.Flags.Info.TiledY == 1) {
resourceParams.Flags.Info.Linear = 0;
resourceParams.Flags.Info.TiledY = 0;
}
}
this->gmmResourceInfo.reset(GmmResourceInfo::create(&this->resourceParams));
void Gmm::queryImageParams(ImageInfo &imgInfo) {
auto imageCount = this->gmmResourceInfo->getArraySize();
imgInfo.size = this->gmmResourceInfo->getSizeAllocation();
imgInfo.rowPitch = this->gmmResourceInfo->getRenderPitch();

View File

@ -35,7 +35,6 @@ class Gmm {
uint32_t getRenderHAlignment();
uint32_t getRenderVAlignment();
void applyAuxFlagsForImage(ImageInfo &imgInfo);
void applyAuxFlagsForBuffer(bool preferRenderCompression);
void applyMemoryFlags(bool systemMemoryPool, StorageInfo &storageInfo);
@ -54,5 +53,9 @@ class Gmm {
bool isRenderCompressed = false;
bool useSystemMemoryPool = true;
protected:
void applyAuxFlagsForImage(ImageInfo &imgInfo);
void setupImageResourceParams(ImageInfo &imgInfo);
};
} // namespace NEO

View File

@ -195,6 +195,13 @@ enum class OCLPlane {
PLANE_UV
};
enum class TilingMode {
DEFAULT = 0,
TILE_X = 1,
TILE_Y = 2,
NON_TILED
};
struct SurfaceFormatInfo {
cl_image_format OCLImageFormat;
GMM_RESOURCE_FORMAT GMMSurfaceFormat;
@ -219,6 +226,7 @@ struct ImageInfo {
GMM_YUV_PLANE_ENUM plane;
uint32_t baseMipLevel;
uint32_t mipCount;
TilingMode tilingMode;
bool preferRenderCompression;
bool useLocalMemory;
};

View File

@ -136,9 +136,7 @@ TEST_F(GmmTests, invalidImageTypeQuery) {
imgDesc.image_type = 0; // invalid
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
auto queryGmm = MockGmm::queryImgParams(imgInfo);
EXPECT_EQ(0u, imgInfo.size);
EXPECT_THROW(MockGmm::queryImgParams(imgInfo), std::exception);
}
TEST_F(GmmTests, validImageTypeQuery) {
@ -275,6 +273,57 @@ TEST_F(GmmTests, givenTilableImageWhenEnableForceLinearImagesThenYTilingIsDisabl
EXPECT_EQ(queryGmm->resourceParams.Flags.Info.TiledY, 0u);
}
TEST_F(GmmTests, givenTilingModeSetToTileYWhenHwSupportsTilingThenTileYFlagIsSet) {
cl_image_desc imgDesc{};
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imgDesc.image_width = 4;
imgDesc.image_height = 4;
imgDesc.image_depth = 1;
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
imgInfo.tilingMode = TilingMode::TILE_Y;
auto gmm = std::make_unique<Gmm>(imgInfo);
auto &hwHelper = HwHelper::get(GmmHelper::getInstance()->getHardwareInfo()->pPlatform->eRenderCoreFamily);
bool supportsYTiling = hwHelper.supportsYTiling();
if (!supportsYTiling) {
EXPECT_EQ(gmm->resourceParams.Flags.Info.Linear, 0u);
EXPECT_EQ(gmm->resourceParams.Flags.Info.TiledY, 0u);
} else {
EXPECT_EQ(gmm->resourceParams.Flags.Info.Linear, 1u);
EXPECT_EQ(gmm->resourceParams.Flags.Info.TiledY, 1u);
}
}
TEST_F(GmmTests, givenTilingModeSetToNonTiledWhenCreatingGmmThenLinearFlagIsSet) {
cl_image_desc imgDesc{};
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imgDesc.image_width = 4;
imgDesc.image_height = 4;
imgDesc.image_depth = 1;
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
imgInfo.tilingMode = TilingMode::NON_TILED;
auto gmm = std::make_unique<Gmm>(imgInfo);
EXPECT_EQ(gmm->resourceParams.Flags.Info.Linear, 1u);
EXPECT_EQ(gmm->resourceParams.Flags.Info.TiledY, 0u);
}
TEST_F(GmmTests, givenTilingModeSetToTileXWhenCreatingGmmThenUnrecoverableIfIsCalled) {
cl_image_desc imgDesc{};
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imgDesc.image_width = 4;
imgDesc.image_height = 4;
imgDesc.image_depth = 1;
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
imgInfo.tilingMode = TilingMode::TILE_X;
EXPECT_THROW(new Gmm(imgInfo), std::exception);
}
TEST_F(GmmTests, givenZeroRowPitchWhenQueryImgFromBufferParamsThenCalculate) {
MockGraphicsAllocation bufferAllocation(nullptr, 4096);

View File

@ -1450,6 +1450,10 @@ HWTEST_F(HwImageTest, givenImageHwWithUnifiedSurfaceAndMcsWhenSettingParamsForMu
context.setMemoryManager(&memoryManager);
cl_image_desc imgDesc = {};
imgDesc.image_height = 1;
imgDesc.image_width = 4;
imgDesc.image_depth = 1;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imgDesc.num_samples = 8;
cl_image_format format = {};

View File

@ -14,6 +14,9 @@ using namespace ::testing;
namespace NEO {
GmmResourceInfo *GmmResourceInfo::create(GMM_RESCREATE_PARAMS *resourceCreateParams) {
if (resourceCreateParams->Type == GMM_RESOURCE_TYPE::RESOURCE_INVALID) {
return nullptr;
}
return new ::testing::NiceMock<MockGmmResourceInfo>(resourceCreateParams);
}