Use allocateGraphicsMemoryForImage for mipmaps

Change-Id: I0cd740ca4c8286fb73f766b74abc50ed53cfc9d0
This commit is contained in:
Woloszyn, Wojciech
2018-02-28 14:12:27 +01:00
committed by sys_ocldev
parent 3e3c6c28c7
commit 5c8cd51fc8
5 changed files with 182 additions and 30 deletions

2
Jenkinsfile vendored
View File

@@ -1,5 +1,5 @@
#!groovy
neoDependenciesRev='735095-769'
strategy='EQUAL'
allowedF=42
allowedF=41
allowedCD=337

View File

@@ -138,6 +138,7 @@ Image *Image::create(Context *context,
imgInfo.imgDesc = &imageDescriptor;
imgInfo.surfaceFormat = surfaceFormat;
imgInfo.mipLevel = imageDesc->num_mip_levels;
Gmm *gmm = nullptr;
if (imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY) {
@@ -318,6 +319,7 @@ Image *Image::create(Context *context,
image->setImageSlicePitch(imgInfo.slicePitch);
image->setQPitch(imgInfo.qPitch);
image->setSurfaceOffsets(imgInfo.offset, imgInfo.xOffset, imgInfo.yOffset, imgInfo.yOffsetForUVPlane);
image->setMipLevel(imgInfo.mipLevel);
if (parentImage) {
image->setMediaPlaneType(static_cast<cl_uint>(imageDesc->image_depth));
image->setParentSharingHandler(parentImage->getSharingHandler());

View File

@@ -66,7 +66,7 @@ void APIENTRY WddmMemoryManager::trimCallback(_Inout_ D3DKMT_TRIMNOTIFICATION *t
}
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) {
if (!Gmm::allowTiling(*imgInfo.imgDesc)) {
if (!Gmm::allowTiling(*imgInfo.imgDesc) && imgInfo.mipLevel == 0) {
delete gmm;
return allocateGraphicsMemory(imgInfo.size, MemoryConstants::preferredAlignment);
}

View File

@@ -1024,7 +1024,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag
EXPECT_EQ(1, munmapMockCallCount);
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipLevelZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
//GEM CREATE + SET_TILING + WAIT + CLOSE
mock->ioctl_expected = 4;
@@ -1035,8 +1035,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedTh
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
@@ -1047,6 +1046,53 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedTh
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE);
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(imageGraphicsAllocation);
auto imageSize = drmAllocation->getUnderlyingBufferSize();
auto rowPitch = dstImage->getImageDesc().image_row_pitch;
EXPECT_EQ(imageSize, drmAllocation->getBO()->peekUnmapSize());
EXPECT_EQ(1u, this->mock->createParamsHandle);
EXPECT_EQ(imageSize, this->mock->createParamsSize);
__u32 tilingMode = I915_TILING_Y;
EXPECT_EQ(tilingMode, this->mock->setTilingMode);
EXPECT_EQ(rowPitch, this->mock->setTilingStride);
EXPECT_EQ(1u, this->mock->setTilingHandle);
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipLevelNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
//GEM CREATE + SET_TILING + WAIT + CLOSE
mock->ioctl_expected = 4;
MockContext context;
context.setMemoryManager(memoryManager);
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
imageDesc.image_height = 64u;
imageDesc.num_mip_levels = 1u;
auto retVal = CL_SUCCESS;
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
EXPECT_EQ(static_cast<int>(imageDesc.num_mip_levels), dstImage->peekMipLevel());
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
@@ -1074,8 +1120,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedAn
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
@@ -1109,8 +1154,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
@@ -1123,6 +1167,8 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr
cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, data, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
@@ -1142,7 +1188,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr
EXPECT_EQ(1u, this->mock->setTilingHandle);
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipLevelZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
//USERPTR + WAIT + CLOSE
mock->ioctl_expected = 3;
@@ -1153,8 +1199,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgisBeingCreatedT
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imageDesc.image_width = 64u;
@@ -1166,6 +1211,54 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgisBeingCreatedT
cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, data, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE);
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(imageGraphicsAllocation);
EXPECT_EQ(0u, drmAllocation->getBO()->peekUnmapSize());
EXPECT_EQ(0u, this->mock->createParamsHandle);
EXPECT_EQ(0u, this->mock->createParamsSize);
__u32 tilingMode = I915_TILING_NONE;
EXPECT_EQ(tilingMode, this->mock->setTilingMode);
EXPECT_EQ(0u, this->mock->setTilingStride);
EXPECT_EQ(0u, this->mock->setTilingHandle);
EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle());
}
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipLevelNonZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
//USERPTR + WAIT + CLOSE
mock->ioctl_expected = 3;
MockContext context;
context.setMemoryManager(memoryManager);
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imageDesc.image_width = 64u;
imageDesc.num_mip_levels = 1u;
char data[64u * 4 * 8];
auto retVal = CL_SUCCESS;
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, data, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
EXPECT_EQ(static_cast<int>(imageDesc.num_mip_levels), dstImage->peekMipLevel());
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
@@ -1196,8 +1289,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhen1DarrayImageIsBeingCreated
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imageDesc.image_width = 64u;

View File

@@ -253,7 +253,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle
EXPECT_EQ(nullptr, gpuAllocation);
}
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipLevelZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
@@ -262,8 +262,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
@@ -274,11 +273,42 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_EQ(retVal, CL_SUCCESS);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE);
EXPECT_EQ(GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE, imageGraphicsAllocation->gmm->resourceParams.Usage);
}
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipLevelNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
imageDesc.image_height = 64u;
imageDesc.num_mip_levels = 1u;
auto retVal = CL_SUCCESS;
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
EXPECT_EQ(static_cast<int>(imageDesc.num_mip_levels), dstImage->peekMipLevel());
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_EQ(GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE, imageGraphicsAllocation->gmm->resourceParams.Usage);
}
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
@@ -290,8 +320,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
imageDesc.image_width = 64u;
@@ -304,15 +333,15 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat
cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, data, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_EQ(retVal, CL_SUCCESS);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE);
EXPECT_EQ(GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE, imageGraphicsAllocation->gmm->resourceParams.Usage);
}
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipLevelZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
@@ -321,8 +350,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgisBeingCrea
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc;
memset(&imageDesc, 0, sizeof(imageDesc));
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imageDesc.image_width = 64u;
@@ -334,11 +362,41 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgisBeingCrea
cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, data, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_BUFFER);
EXPECT_EQ(GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_BUFFER, imageGraphicsAllocation->gmm->resourceParams.Usage);
}
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipLevelNonZeroisBeingCreatedThenAllocateGraphicsMemoryForImageIsUsed) {
SetUpMm<FamilyType>();
MockContext context;
context.setMemoryManager(memoryManager);
cl_image_format imageFormat;
imageFormat.image_channel_data_type = CL_UNORM_INT8;
imageFormat.image_channel_order = CL_R;
cl_image_desc imageDesc = {};
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
imageDesc.image_width = 64u;
imageDesc.num_mip_levels = 1u;
auto retVal = CL_SUCCESS;
cl_mem_flags flags = CL_MEM_WRITE_ONLY;
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat);
std::unique_ptr<Image> dstImage(Image::create(&context, flags, surfaceFormat, &imageDesc, nullptr, retVal));
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, dstImage);
EXPECT_EQ(static_cast<int>(imageDesc.num_mip_levels), dstImage->peekMipLevel());
auto imageGraphicsAllocation = dstImage->getGraphicsAllocation();
ASSERT_NE(nullptr, imageGraphicsAllocation);
EXPECT_EQ(GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE, imageGraphicsAllocation->gmm->resourceParams.Usage);
}
HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) {