diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 3a121fc1b5..a6eed4c86b 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -1209,4 +1209,21 @@ bool Image::isValidYUVFormat(const cl_image_format *imageFormat) { return isValidOrder && isValidDataType; } + +bool Image::hasAlphaChannel(const cl_image_format *imageFormat) { + auto channelOrder = imageFormat->image_channel_order; + return (channelOrder == CL_A) || + (channelOrder == CL_Rx) || + (channelOrder == CL_RA) || + (channelOrder == CL_RGx) || + (channelOrder == CL_RGBx) || + (channelOrder == CL_RGBA) || + (channelOrder == CL_BGRA) || + (channelOrder == CL_ARGB) || + (channelOrder == CL_INTENSITY) || + (channelOrder == CL_sRGBA) || + (channelOrder == CL_sBGRA) || + (channelOrder == CL_sRGBx) || + (channelOrder == CL_ABGR); +} } // namespace OCLRT diff --git a/runtime/mem_obj/image.h b/runtime/mem_obj/image.h index 67659deb81..d1c61b5f5c 100644 --- a/runtime/mem_obj/image.h +++ b/runtime/mem_obj/image.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -147,7 +147,6 @@ class Image : public MemObj { ImageCreatFunc createFunction; void transferDataFromHostPtrToMemoryStorage() override; - int getImageDimension(cl_image_desc &imgDesc); uint32_t getQPitch() { return qPitch; } void setQPitch(uint32_t qPitch) { this->qPitch = qPitch; } size_t getHostPtrRowPitch() { return hostPtrRowPitch; } @@ -226,6 +225,7 @@ class Image : public MemObj { static bool isValidARGBFormat(const cl_image_format *imageFormat); static bool isValidDepthStencilFormat(const cl_image_format *imageFormat); static bool isValidYUVFormat(const cl_image_format *imageFormat); + static bool hasAlphaChannel(const cl_image_format *imageFormat); }; template @@ -264,6 +264,7 @@ class ImageHw : public Image { void setMediaImageArg(void *memory) override; void setMediaSurfaceRotation(void *memory) override; void setSurfaceMemoryObjectControlStateIndexToMocsTable(void *memory, uint32_t value) override; + void appendSurfaceStateParams(RENDER_SURFACE_STATE *surfaceState); static Image *create(Context *context, cl_mem_flags flags, diff --git a/runtime/mem_obj/image.inl b/runtime/mem_obj/image.inl index 97583d1f1b..1bb3e82aa5 100644 --- a/runtime/mem_obj/image.inl +++ b/runtime/mem_obj/image.inl @@ -172,6 +172,7 @@ void ImageHw::setImageArg(void *memory, bool setAsMediaBlockImage) { } else if (gmm && gmm->isRenderCompressed) { setAuxParamsForCCS(surfaceState, gmm); } + appendSurfaceStateParams(surfaceState); } template @@ -201,6 +202,10 @@ void ImageHw::setAuxParamsForCCS(RENDER_SURFACE_STATE *surfaceState, gmm->gmmResourceInfo->getUnifiedAuxSurfaceOffset(GMM_UNIFIED_AUX_TYPE::GMM_AUX_CCS)); } +template +void ImageHw::appendSurfaceStateParams(RENDER_SURFACE_STATE *surfaceState) { +} + template void ImageHw::setMediaImageArg(void *memory) { using MEDIA_SURFACE_STATE = typename GfxFamily::MEDIA_SURFACE_STATE; diff --git a/runtime/mem_obj/image_factory_init.inl b/runtime/mem_obj/image_factory_init.inl index 9111ae195b..dc7c7fd5b0 100644 --- a/runtime/mem_obj/image_factory_init.inl +++ b/runtime/mem_obj/image_factory_init.inl @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +template class ImageHw; template <> void populateFactoryTable>() { extern ImageFuncs imageFactory[IGFX_MAX_CORE]; diff --git a/unit_tests/gen8/CMakeLists.txt b/unit_tests/gen8/CMakeLists.txt index a48fa9d029..0020de91ac 100644 --- a/unit_tests/gen8/CMakeLists.txt +++ b/unit_tests/gen8/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017, Intel Corporation +# Copyright (c) 2018, Intel Corporation # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -25,6 +25,7 @@ set(IGDRCL_SRCS_tests_gen8 "${CMAKE_CURRENT_SOURCE_DIR}/enqueue_media_kernel.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/gen_cmd_parse.h" "${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/image_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/sampler_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/scheduler_dispatch_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test_device_caps.cpp" diff --git a/unit_tests/gen8/image_tests.cpp b/unit_tests/gen8/image_tests.cpp new file mode 100644 index 0000000000..d572352ee6 --- /dev/null +++ b/unit_tests/gen8/image_tests.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, 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 "unit_tests/fixtures/image_fixture.h" +#include "unit_tests/mocks/mock_context.h" +#include "test.h" + +using namespace OCLRT; + +typedef ::testing::Test gen8ImageTests; + +GEN8TEST_F(gen8ImageTests, appendSurfaceStateParamsDoesNothing) { + typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; + MockContext context; + auto image = std::unique_ptr(ImageHelper::create(&context)); + auto surfaceStateBefore = RENDER_SURFACE_STATE::sInit(); + auto surfaceStateAfter = RENDER_SURFACE_STATE::sInit(); + auto imageHw = static_cast *>(image.get()); + + EXPECT_EQ(0, memcmp(&surfaceStateBefore, &surfaceStateAfter, sizeof(RENDER_SURFACE_STATE))); + + imageHw->appendSurfaceStateParams(&surfaceStateAfter); + + EXPECT_EQ(0, memcmp(&surfaceStateBefore, &surfaceStateAfter, sizeof(RENDER_SURFACE_STATE))); +} diff --git a/unit_tests/gen9/CMakeLists.txt b/unit_tests/gen9/CMakeLists.txt index 281f3ad9b4..20c236f7bb 100644 --- a/unit_tests/gen9/CMakeLists.txt +++ b/unit_tests/gen9/CMakeLists.txt @@ -26,6 +26,7 @@ set(IGDRCL_SRCS_tests_gen9 ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_media_kernel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gen_cmd_parse.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/image_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sampler_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_device_caps.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_device_queue_hw.cpp diff --git a/unit_tests/gen9/image_tests.cpp b/unit_tests/gen9/image_tests.cpp new file mode 100644 index 0000000000..9bbdd581aa --- /dev/null +++ b/unit_tests/gen9/image_tests.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, 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 "unit_tests/fixtures/image_fixture.h" +#include "unit_tests/mocks/mock_context.h" +#include "test.h" + +using namespace OCLRT; + +typedef ::testing::Test gen9ImageTests; + +GEN9TEST_F(gen9ImageTests, appendSurfaceStateParamsDoesNothing) { + typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE; + MockContext context; + auto image = std::unique_ptr(ImageHelper::create(&context)); + auto surfaceStateBefore = RENDER_SURFACE_STATE::sInit(); + auto surfaceStateAfter = RENDER_SURFACE_STATE::sInit(); + auto imageHw = static_cast *>(image.get()); + + EXPECT_EQ(0, memcmp(&surfaceStateBefore, &surfaceStateAfter, sizeof(RENDER_SURFACE_STATE))); + + imageHw->appendSurfaceStateParams(&surfaceStateAfter); + + EXPECT_EQ(0, memcmp(&surfaceStateBefore, &surfaceStateAfter, sizeof(RENDER_SURFACE_STATE))); +} diff --git a/unit_tests/mem_obj/CMakeLists.txt b/unit_tests/mem_obj/CMakeLists.txt index 97f33dfb84..114f9148cf 100644 --- a/unit_tests/mem_obj/CMakeLists.txt +++ b/unit_tests/mem_obj/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017, Intel Corporation +# Copyright (c) 2018, Intel Corporation # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -30,6 +30,7 @@ set(IGDRCL_SRCS_tests_mem_obj "${CMAKE_CURRENT_SOURCE_DIR}/get_mem_object_info_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/get_mem_object_info_subbufer_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/image_copy_tests.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/image_format_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/image_redescribe_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/image_release_mapped_ptr_tests.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/image_set_arg_tests.cpp" diff --git a/unit_tests/mem_obj/image_format_tests.cpp b/unit_tests/mem_obj/image_format_tests.cpp new file mode 100644 index 0000000000..d2ca7615ed --- /dev/null +++ b/unit_tests/mem_obj/image_format_tests.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, 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 "runtime/mem_obj/image.h" +#include "gtest/gtest.h" + +using namespace OCLRT; + +struct MockImage : public Image { + using Image::hasAlphaChannel; +}; + +typedef ::testing::TestWithParam> + HasAlphaChannelTest; + +TEST_P(HasAlphaChannelTest, imageFormatHasAlphaChannel) { + cl_image_format imageFormat; + bool expectedValue; + std::tie(imageFormat.image_channel_order, expectedValue) = GetParam(); + EXPECT_EQ(expectedValue, MockImage::hasAlphaChannel(&imageFormat)); +} + +std::tuple paramsForAlphaChannelTests[] = { + std::make_tuple(CL_R, false), + std::make_tuple(CL_A, true), + std::make_tuple(CL_RG, false), + std::make_tuple(CL_RA, true), + std::make_tuple(CL_RGB, false), + std::make_tuple(CL_RGBA, true), + std::make_tuple(CL_BGRA, true), + std::make_tuple(CL_ARGB, true), + std::make_tuple(CL_INTENSITY, true), + std::make_tuple(CL_LUMINANCE, false), + std::make_tuple(CL_Rx, true), + std::make_tuple(CL_RGx, true), + std::make_tuple(CL_RGBx, true), + std::make_tuple(CL_DEPTH, false), + std::make_tuple(CL_DEPTH_STENCIL, false), + std::make_tuple(CL_sRGB, false), + std::make_tuple(CL_sRGBx, true), + std::make_tuple(CL_sRGBA, true), + std::make_tuple(CL_sBGRA, true), + std::make_tuple(CL_ABGR, true), + std::make_tuple(CL_NV12_INTEL, false), + std::make_tuple(CL_YUYV_INTEL, false), + std::make_tuple(CL_UYVY_INTEL, false), + std::make_tuple(CL_YVYU_INTEL, false), + std::make_tuple(CL_VYUY_INTEL, false)}; + +INSTANTIATE_TEST_CASE_P( + ImageFormatTests, + HasAlphaChannelTest, + ::testing::ValuesIn(paramsForAlphaChannelTests));