/* * Copyright (c) 2017, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include "hw_cmds.h" #include "runtime/mem_obj/image.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/mocks/mock_context.h" #include "test.h" using namespace OCLRT; static const unsigned int testImageDimensions = 32; class CreateImage2DTest : public DeviceFixture, public testing::TestWithParam { public: CreateImage2DTest() { } protected: void SetUp() override { DeviceFixture::SetUp(); types = GetParam(); // clang-format off imageFormat.image_channel_data_type = CL_UNORM_INT8; imageFormat.image_channel_order = CL_RGBA; imageDesc.image_type = types; imageDesc.image_width = testImageDimensions; imageDesc.image_height = testImageDimensions; imageDesc.image_depth = 0; 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 if (types == CL_MEM_OBJECT_IMAGE2D_ARRAY) { imageDesc.image_array_size = 10; } context = new MockContext(pDevice); } void TearDown() override { delete context; DeviceFixture::TearDown(); } Image *createImageWithFlags(cl_mem_flags flags) { auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat); return Image::create(context, flags, surfaceFormat, &imageDesc, nullptr, retVal); } cl_image_format imageFormat; cl_image_desc imageDesc; cl_int retVal = CL_SUCCESS; MockContext *context; cl_mem_object_type types = 0; }; typedef CreateImage2DTest CreateImage2DType; HWTEST_P(CreateImage2DType, validTypes) { auto image = createImageWithFlags(CL_MEM_READ_WRITE); ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_NE(nullptr, image); auto imgDesc = image->getImageDesc(); EXPECT_NE(0u, imgDesc.image_width); EXPECT_NE(0u, imgDesc.image_height); EXPECT_EQ(0u, imgDesc.image_depth); EXPECT_NE(0u, imgDesc.image_row_pitch); EXPECT_GE(imgDesc.image_slice_pitch, imgDesc.image_row_pitch); if (types == CL_MEM_OBJECT_IMAGE2D) { EXPECT_EQ(0u, imgDesc.image_array_size); } else if (types == CL_MEM_OBJECT_IMAGE2D_ARRAY) { EXPECT_NE(0u, imgDesc.image_array_size); } else { ASSERT_TRUE(false); } EXPECT_EQ(image->getCubeFaceIndex(), static_cast(__GMM_NO_CUBE_MAP)); ASSERT_EQ(true, image->isMemObjZeroCopy()); auto address = image->getCpuAddress(); EXPECT_NE(nullptr, address); typedef typename FamilyType::RENDER_SURFACE_STATE SURFACE_STATE; auto imageHw = static_cast *>(image); EXPECT_EQ(SURFACE_STATE::SURFACE_TYPE_SURFTYPE_2D, imageHw->surfaceType); SurfaceOffsets surfaceOffsets; image->getSurfaceOffsets(surfaceOffsets); EXPECT_EQ(0u, surfaceOffsets.offset); EXPECT_EQ(0u, surfaceOffsets.xOffset); EXPECT_EQ(0u, surfaceOffsets.yOffset); EXPECT_EQ(0u, surfaceOffsets.yOffsetForUVplane); delete image; } static cl_mem_object_type Image2DTypes[] = { CL_MEM_OBJECT_IMAGE2D, CL_MEM_OBJECT_IMAGE2D_ARRAY}; INSTANTIATE_TEST_CASE_P( CreateImage2DTest_Create, CreateImage2DType, testing::ValuesIn(Image2DTypes));