2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2025-02-12 22:06:22 +08:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-09-06 19:01:48 +08:00
|
|
|
#include "shared/source/gmm_helper/resource_info.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2021-04-13 20:00:07 +08:00
|
|
|
#include "shared/test/common/helpers/unit_test_helper.h"
|
2021-10-14 23:37:18 +08:00
|
|
|
#include "shared/test/common/mocks/mock_gmm.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/mem_obj/image.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
|
2020-05-28 20:05:12 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/image_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static const auto dimension = 16;
|
|
|
|
static auto channelType = CL_UNORM_INT8;
|
|
|
|
static auto channelOrder = CL_RGBA;
|
|
|
|
|
2020-05-28 20:05:12 +08:00
|
|
|
class CreateTiledImageTest : public ClDeviceFixture,
|
2017-12-21 07:45:38 +08:00
|
|
|
public testing::TestWithParam<uint32_t>,
|
|
|
|
public CommandQueueHwFixture {
|
|
|
|
typedef CommandQueueHwFixture CommandQueueFixture;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CreateTiledImageTest() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
2022-08-16 22:51:17 +08:00
|
|
|
ClDeviceFixture::setUp();
|
|
|
|
CommandQueueFixture::setUp(pClDevice, 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
type = GetParam();
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
imageFormat.image_channel_data_type = channelType;
|
|
|
|
imageFormat.image_channel_order = channelOrder;
|
|
|
|
|
|
|
|
imageDesc.image_type = type;
|
|
|
|
imageDesc.image_width = dimension;
|
|
|
|
imageDesc.image_height = dimension;
|
|
|
|
imageDesc.image_depth = 1;
|
|
|
|
imageDesc.image_array_size = 1;
|
|
|
|
imageDesc.image_row_pitch = 0;
|
|
|
|
imageDesc.image_slice_pitch = 0;
|
|
|
|
imageDesc.num_mip_levels = 0;
|
|
|
|
imageDesc.num_samples = 0;
|
|
|
|
imageDesc.mem_object = NULL;
|
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
2022-08-16 22:51:17 +08:00
|
|
|
CommandQueueFixture::tearDown();
|
|
|
|
ClDeviceFixture::tearDown();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cl_image_format imageFormat;
|
|
|
|
cl_image_desc imageDesc;
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
cl_mem_object_type type = 0;
|
|
|
|
};
|
|
|
|
|
2020-09-21 19:07:19 +08:00
|
|
|
HWTEST_P(CreateTiledImageTest, GivenImageTypeWhenCheckingIsTiledThenTrueReturnedForTiledImage) {
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
|
|
|
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
2020-04-30 21:47:43 +08:00
|
|
|
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, pClDevice->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
2017-12-21 07:45:38 +08:00
|
|
|
auto image = Image::create(
|
|
|
|
&context,
|
2021-10-07 01:00:24 +08:00
|
|
|
ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, pDevice),
|
2017-12-21 07:45:38 +08:00
|
|
|
flags,
|
2019-10-17 20:18:55 +08:00
|
|
|
0,
|
2017-12-21 07:45:38 +08:00
|
|
|
surfaceFormat,
|
|
|
|
&imageDesc,
|
|
|
|
nullptr,
|
|
|
|
retVal);
|
|
|
|
ASSERT_NE(nullptr, image);
|
|
|
|
|
2023-03-15 21:57:05 +08:00
|
|
|
EXPECT_EQ(defaultHwInfo->capabilityTable.supportsImages, image->isTiledAllocation());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
delete image;
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:07:19 +08:00
|
|
|
TEST_P(CreateTiledImageTest, GivenSharedTiledImageWhenCheckingIsTiledThenTrueReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *alloc = new MockGraphicsAllocation(0, 0x1000);
|
2020-01-08 18:11:54 +08:00
|
|
|
ImageInfo info = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
McsSurfaceInfo msi = {};
|
2020-01-09 00:29:15 +08:00
|
|
|
ClSurfaceFormatInfo surfaceFormat;
|
2023-04-27 17:50:55 +08:00
|
|
|
surfaceFormat.surfaceFormat.gmmSurfaceFormat = GMM_FORMAT_B8G8R8A8_UNORM;
|
2020-01-09 00:29:15 +08:00
|
|
|
info.surfaceFormat = &surfaceFormat.surfaceFormat;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-08 18:11:54 +08:00
|
|
|
info.imgDesc = Image::convertDescriptor(imageDesc);
|
2017-12-21 07:45:38 +08:00
|
|
|
info.plane = GMM_NO_PLANE;
|
|
|
|
|
2022-04-27 18:20:10 +08:00
|
|
|
auto gmm = MockGmm::queryImgParams(context.getDevice(0)->getGmmHelper(), info, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-12 20:24:58 +08:00
|
|
|
alloc->setDefaultGmm(gmm.release());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
auto image = Image::createSharedImage(
|
|
|
|
&context,
|
|
|
|
nullptr,
|
|
|
|
msi,
|
2020-07-16 18:15:52 +08:00
|
|
|
GraphicsAllocationHelper::toMultiGraphicsAllocation(alloc),
|
2017-12-21 07:45:38 +08:00
|
|
|
nullptr,
|
|
|
|
CL_MEM_READ_WRITE,
|
2020-04-26 14:56:42 +08:00
|
|
|
0,
|
2020-01-09 00:29:15 +08:00
|
|
|
&surfaceFormat,
|
2017-12-21 07:45:38 +08:00
|
|
|
info,
|
2025-02-12 22:06:22 +08:00
|
|
|
0, 0, 0, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_NE(nullptr, image);
|
|
|
|
|
2019-08-26 15:27:30 +08:00
|
|
|
EXPECT_TRUE(image->isTiledAllocation());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
delete image;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef CreateTiledImageTest CreateNonTiledImageTest;
|
|
|
|
|
2020-09-21 19:07:19 +08:00
|
|
|
TEST_P(CreateNonTiledImageTest, GivenSharedNonTiledImageWhenCheckingIsTiledThenFalseReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
|
|
|
MockGraphicsAllocation *alloc = new MockGraphicsAllocation(0, 0x1000);
|
2020-01-08 18:11:54 +08:00
|
|
|
ImageInfo info = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
McsSurfaceInfo msi = {};
|
2020-01-09 00:29:15 +08:00
|
|
|
ClSurfaceFormatInfo surfaceFormat;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
imageDesc.image_height = 1;
|
|
|
|
|
2023-04-27 17:50:55 +08:00
|
|
|
surfaceFormat.surfaceFormat.gmmSurfaceFormat = GMM_FORMAT_B8G8R8A8_UNORM;
|
2020-01-09 00:29:15 +08:00
|
|
|
info.surfaceFormat = &surfaceFormat.surfaceFormat;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-08 18:11:54 +08:00
|
|
|
info.imgDesc = Image::convertDescriptor(imageDesc);
|
2017-12-21 07:45:38 +08:00
|
|
|
info.plane = GMM_NO_PLANE;
|
2023-09-06 19:01:48 +08:00
|
|
|
info.linearStorage = true;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-04-27 18:20:10 +08:00
|
|
|
auto gmm = MockGmm::queryImgParams(context.getDevice(0)->getGmmHelper(), info, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-12 20:24:58 +08:00
|
|
|
alloc->setDefaultGmm(gmm.release());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
auto image = Image::createSharedImage(
|
|
|
|
&context,
|
|
|
|
nullptr,
|
|
|
|
msi,
|
2020-07-16 18:15:52 +08:00
|
|
|
GraphicsAllocationHelper::toMultiGraphicsAllocation(alloc),
|
2017-12-21 07:45:38 +08:00
|
|
|
nullptr,
|
|
|
|
CL_MEM_READ_WRITE,
|
2020-04-26 14:56:42 +08:00
|
|
|
0,
|
2020-01-09 00:29:15 +08:00
|
|
|
&surfaceFormat,
|
2017-12-21 07:45:38 +08:00
|
|
|
info,
|
2025-02-12 22:06:22 +08:00
|
|
|
0, 0, 0, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_NE(nullptr, image);
|
|
|
|
|
2019-08-26 15:27:30 +08:00
|
|
|
EXPECT_FALSE(image->isTiledAllocation());
|
2023-09-06 19:01:48 +08:00
|
|
|
EXPECT_EQ(info.linearStorage, image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm()->gmmResourceInfo->getResourceFlags()->Info.Linear);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
delete image;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parameterized test that tests image creation with tiled types
|
2023-12-04 17:18:59 +08:00
|
|
|
static uint32_t tiledImageTypes[] = {
|
2017-12-21 07:45:38 +08:00
|
|
|
CL_MEM_OBJECT_IMAGE2D,
|
|
|
|
CL_MEM_OBJECT_IMAGE2D_ARRAY,
|
|
|
|
CL_MEM_OBJECT_IMAGE3D};
|
|
|
|
|
2023-12-04 17:18:59 +08:00
|
|
|
static uint32_t nonTiledImageTypes[] = {
|
2017-12-21 07:45:38 +08:00
|
|
|
CL_MEM_OBJECT_IMAGE1D};
|
|
|
|
|
2024-05-28 23:09:20 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(CreateTiledImageTest, CreateTiledImageTest, testing::ValuesIn(tiledImageTypes));
|
|
|
|
INSTANTIATE_TEST_SUITE_P(CreateNonTiledImageTest, CreateNonTiledImageTest, testing::ValuesIn(nonTiledImageTypes));
|