From 40541e4faa14c09042c38b72213150ab2ecd9b3c Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Tue, 12 Mar 2019 14:19:01 +0100 Subject: [PATCH] Update Image compression Change-Id: I3a15dba343a80716b57cdda6b74f2142814021f3 Signed-off-by: Filip Hazubski --- runtime/api/api.cpp | 56 +---------- runtime/mem_obj/buffer.cpp | 2 +- runtime/mem_obj/image.cpp | 3 +- runtime/mem_obj/mem_obj_helper.cpp | 4 +- runtime/mem_obj/mem_obj_helper.h | 94 +++++++++++++++---- unit_tests/api/cl_create_image_tests.cpp | 9 +- unit_tests/mem_obj/CMakeLists.txt | 1 + .../mem_obj/image_compression_fixture.h | 46 +++++++++ unit_tests/mem_obj/image_tests.cpp | 34 +------ unit_tests/mem_obj/mem_obj_helper_tests.cpp | 39 ++++++-- 10 files changed, 169 insertions(+), 119 deletions(-) create mode 100644 unit_tests/mem_obj/image_compression_fixture.h diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index 2d0b90af4d..6db0beee16 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -711,63 +711,15 @@ cl_mem CL_API_CALL clCreateImage(cl_context context, "hostPtr", hostPtr); cl_mem image = nullptr; - - cl_mem_flags allValidFlags = - CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR | - CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS | - CL_MEM_NO_ACCESS_INTEL | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL; - do { /* Are there some invalid flag bits? */ - if ((flags & (~allValidFlags)) != 0) { + if (!MemObjHelper::validateMemoryPropertiesForImage(flags, imageDesc->mem_object)) { retVal = CL_INVALID_VALUE; break; } - /* Check all the invalid flags combination. */ - if (((((CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY) | flags) == flags) || - (((CL_MEM_READ_WRITE | CL_MEM_READ_ONLY) | flags) == flags) || - (((CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY) | flags) == flags) || - (((CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR) | flags) == flags) || - (((CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR) | flags) == flags) || - (((CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY) | flags) == flags) || - (((CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS) | flags) == flags) || - (((CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS) | flags) == flags) || - (((CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_WRITE) | flags) == flags) || - (((CL_MEM_NO_ACCESS_INTEL | CL_MEM_WRITE_ONLY) | flags) == flags) || - (((CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_ONLY) | flags) == flags)) && - (!(flags & CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL))) { - retVal = CL_INVALID_VALUE; - break; - } - MemObj *parentMemObj = castToObject(imageDesc->mem_object); - if (parentMemObj != nullptr) { - cl_mem_flags allValidFlags = - CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | - CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS | - CL_MEM_NO_ACCESS_INTEL | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL; - /* Are there some invalid flag bits? */ - if ((flags & (~allValidFlags)) != 0) { - retVal = CL_INVALID_VALUE; - break; - } - cl_mem_flags parentFlags = parentMemObj->getFlags(); - /* Check whether flag is valid and compatible with parent. */ - if (((!(flags & CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) && (!(parentFlags & CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL))) && - (flags && - (((parentFlags & CL_MEM_WRITE_ONLY) && (flags & (CL_MEM_READ_WRITE | CL_MEM_READ_ONLY))) || - ((parentFlags & CL_MEM_READ_ONLY) && (flags & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY))) || - ((parentFlags & CL_MEM_NO_ACCESS_INTEL) && (flags & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY))) || - ((parentFlags & CL_MEM_HOST_NO_ACCESS) && (flags & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY)))))) { - retVal = CL_INVALID_VALUE; - break; - } - } - if ((flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) && !hostPtr) { - retVal = CL_INVALID_HOST_PTR; - break; - } - if (!(flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) && hostPtr) { + bool isHostPtrUsed = (hostPtr != nullptr); + bool areHostPtrFlagsUsed = isValueSet(flags, CL_MEM_COPY_HOST_PTR) || isValueSet(flags, CL_MEM_USE_HOST_PTR); + if (isHostPtrUsed != areHostPtrFlagsUsed) { retVal = CL_INVALID_HOST_PTR; break; } diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index fdb89c66dc..6b01c95743 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -81,7 +81,7 @@ void Buffer::validateInputAndCreateBuffer(cl_context &context, return; } - if (!MemObjHelper::validateMemoryProperties(properties)) { + if (!MemObjHelper::validateMemoryPropertiesForBuffer(properties)) { retVal = CL_INVALID_VALUE; return; } diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index f10f518236..936f3b2b9b 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -180,7 +180,8 @@ Image *Image::create(Context *context, auto hostPtrRowPitch = imageDesc->image_row_pitch ? imageDesc->image_row_pitch : imageWidth * surfaceFormat->ImageElementSizeInBytes; auto hostPtrSlicePitch = imageDesc->image_slice_pitch ? imageDesc->image_slice_pitch : hostPtrRowPitch * imageHeight; auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc); - imgInfo.preferRenderCompression = isTilingAllowed; + imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, flags, + context->peekContextType()); bool zeroCopy = false; bool transferNeeded = false; diff --git a/runtime/mem_obj/mem_obj_helper.cpp b/runtime/mem_obj/mem_obj_helper.cpp index 2fd178bba4..1f009538c1 100644 --- a/runtime/mem_obj/mem_obj_helper.cpp +++ b/runtime/mem_obj/mem_obj_helper.cpp @@ -46,8 +46,8 @@ StorageInfo MemObjHelper::getStorageInfo(const MemoryProperties &properties) { return {}; } -bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressedBuffers, const MemoryProperties &properties, ContextType contextType) { - return renderCompressedBuffers; +bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType) { + return renderCompressed; } bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) { diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index 3449bcd334..171f78549f 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -21,10 +21,8 @@ class MemObjHelper { public: static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct); - static bool validateMemoryProperties(const MemoryProperties &properties) { - - /* Are there some invalid flag bits? */ - if (!MemObjHelper::checkMemFlagsForBuffer(properties)) { + static bool validateMemoryPropertiesForBuffer(const MemoryProperties &properties) { + if (!MemObjHelper::checkUsedFlagsForBuffer(properties)) { return false; } @@ -43,6 +41,49 @@ class MemObjHelper { return validateExtraMemoryProperties(properties); } + static bool validateMemoryPropertiesForImage(const MemoryProperties &properties, cl_mem parent) { + if (!MemObjHelper::checkUsedFlagsForImage(properties)) { + return false; + } + + /* Check all the invalid flags combination. */ + if ((!isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) && + (isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY) || + isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_READ_ONLY) || + isValueSet(properties.flags, CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY) || + isValueSet(properties.flags, CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR) || + isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR) || + isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY) || + isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS) || + isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS) || + isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_WRITE) || + isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_WRITE_ONLY) || + isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_ONLY))) { + return false; + } + + MemObj *parentMemObj = castToObject(parent); + if (parentMemObj != nullptr && properties.flags) { + auto parentFlags = parentMemObj->getFlags(); + /* Check whether flags are compatible with parent. */ + if ((!isValueSet(parentFlags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) && + (!isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) && + ((isValueSet(parentFlags, CL_MEM_WRITE_ONLY) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) || + (isValueSet(parentFlags, CL_MEM_WRITE_ONLY) && isValueSet(properties.flags, CL_MEM_READ_ONLY)) || + (isValueSet(parentFlags, CL_MEM_READ_ONLY) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) || + (isValueSet(parentFlags, CL_MEM_READ_ONLY) && isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) || + (isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) || + (isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) || + (isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_READ_ONLY)) || + (isValueSet(parentFlags, CL_MEM_HOST_NO_ACCESS) && isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY)) || + (isValueSet(parentFlags, CL_MEM_HOST_NO_ACCESS) && isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY)))) { + return false; + } + } + + return validateExtraMemoryProperties(properties); + } + static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type); static AllocationProperties getAllocationProperties(ImageInfo *imgInfo, bool allocateMemory); @@ -57,28 +98,41 @@ class MemObjHelper { return isFieldValid(flags, allValidFlags); } - static bool isSuitableForRenderCompression(bool renderCompressedBuffers, const MemoryProperties &properties, ContextType contextType); + static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType); protected: - static bool checkMemFlagsForBuffer(const MemoryProperties &properties) { - MemoryProperties additionalAcceptedProperties; - addExtraMemoryProperties(additionalAcceptedProperties); + static bool checkUsedFlagsForBuffer(const MemoryProperties &properties) { + MemoryProperties acceptedProperties; + addCommonMemoryProperties(acceptedProperties); + addExtraMemoryProperties(acceptedProperties); - const cl_mem_flags allValidFlags = - CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | - CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR | - CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS | - additionalAcceptedProperties.flags; - - const cl_mem_flags allValidFlagsIntel = CL_MEM_LOCALLY_UNCACHED_RESOURCE | - additionalAcceptedProperties.flags_intel; - - return (isFieldValid(properties.flags, allValidFlags) && - isFieldValid(properties.flags_intel, allValidFlagsIntel)); + return (isFieldValid(properties.flags, acceptedProperties.flags) && + isFieldValid(properties.flags_intel, acceptedProperties.flags_intel)); } - static bool validateExtraMemoryProperties(const MemoryProperties &properties); + static bool checkUsedFlagsForImage(const MemoryProperties &properties) { + MemoryProperties acceptedProperties; + addCommonMemoryProperties(acceptedProperties); + addImageMemoryProperties(acceptedProperties); + addExtraMemoryProperties(acceptedProperties); + + return (isFieldValid(properties.flags, acceptedProperties.flags) && + isFieldValid(properties.flags_intel, acceptedProperties.flags_intel)); + } + + static inline void addCommonMemoryProperties(MemoryProperties &properties) { + properties.flags |= + CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY | + CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR | + CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS; + properties.flags_intel |= CL_MEM_LOCALLY_UNCACHED_RESOURCE; + } + + static inline void addImageMemoryProperties(MemoryProperties &properties) { + properties.flags |= CL_MEM_NO_ACCESS_INTEL | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL; + } static void addExtraMemoryProperties(MemoryProperties &properties); + static bool validateExtraMemoryProperties(const MemoryProperties &properties); }; } // namespace OCLRT diff --git a/unit_tests/api/cl_create_image_tests.cpp b/unit_tests/api/cl_create_image_tests.cpp index 9c7f64aaaa..3d5d9012ca 100644 --- a/unit_tests/api/cl_create_image_tests.cpp +++ b/unit_tests/api/cl_create_image_tests.cpp @@ -172,7 +172,7 @@ TEST_F(clCreateImageTest, GivenInvalidFlagBitsWhenCreatingImageFromAnotherImageT imageFormat.image_channel_order = CL_RG; imageDesc.mem_object = image; - cl_mem_flags flags = (1 << 3); + cl_mem_flags flags = (1 << 30); auto imageFromImageObject = clCreateImage( pContext, @@ -529,9 +529,14 @@ TEST_P(clCreateImageValidFlagsAndParentFlagsCombinations, GivenValidFlagsAndPare static ImageFlags invalidFlagsAndParentFlags[] = { {CL_MEM_WRITE_ONLY, CL_MEM_READ_WRITE}, + {CL_MEM_WRITE_ONLY, CL_MEM_READ_ONLY}, {CL_MEM_READ_ONLY, CL_MEM_READ_WRITE}, + {CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY}, {CL_MEM_NO_ACCESS_INTEL, CL_MEM_READ_WRITE}, - {CL_MEM_HOST_NO_ACCESS, CL_MEM_HOST_WRITE_ONLY}}; + {CL_MEM_NO_ACCESS_INTEL, CL_MEM_WRITE_ONLY}, + {CL_MEM_NO_ACCESS_INTEL, CL_MEM_READ_ONLY}, + {CL_MEM_HOST_NO_ACCESS, CL_MEM_HOST_WRITE_ONLY}, + {CL_MEM_HOST_NO_ACCESS, CL_MEM_HOST_READ_ONLY}}; typedef clCreateImageTests<::testing::TestWithParam> clCreateImageInvalidFlagsAndParentFlagsCombinations; diff --git a/unit_tests/mem_obj/CMakeLists.txt b/unit_tests/mem_obj/CMakeLists.txt index 953dfdfa38..3f5cf68865 100644 --- a/unit_tests/mem_obj/CMakeLists.txt +++ b/unit_tests/mem_obj/CMakeLists.txt @@ -19,6 +19,7 @@ set(IGDRCL_SRCS_tests_mem_obj ${CMAKE_CURRENT_SOURCE_DIR}/image2d_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image3d_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image_array_size_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/image_compression_fixture.h ${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 diff --git a/unit_tests/mem_obj/image_compression_fixture.h b/unit_tests/mem_obj/image_compression_fixture.h new file mode 100644 index 0000000000..1f2b029605 --- /dev/null +++ b/unit_tests/mem_obj/image_compression_fixture.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/helpers/surface_formats.h" +#include "test.h" +#include "unit_tests/mocks/mock_context.h" +#include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_memory_manager.h" +#include "unit_tests/utilities/base_object_utils.h" + +using namespace OCLRT; + +class ImageCompressionTests : public ::testing::Test { + public: + class MyMemoryManager : public MockMemoryManager { + public: + using MockMemoryManager::MockMemoryManager; + GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override { + mockMethodCalled = true; + capturedImgInfo = *allocationData.imgInfo; + return OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(allocationData); + } + ImageInfo capturedImgInfo = {}; + bool mockMethodCalled = false; + }; + + void SetUp() override { + mockDevice.reset(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); + myMemoryManager = new MyMemoryManager(*mockDevice->getExecutionEnvironment()); + mockDevice->injectMemoryManager(myMemoryManager); + mockContext = make_releaseable(mockDevice.get()); + } + + std::unique_ptr mockDevice; + ReleaseableObjectPtr mockContext; + MyMemoryManager *myMemoryManager = nullptr; + + cl_image_desc imageDesc = {}; + cl_image_format imageFormat{CL_RGBA, CL_UNORM_INT8}; + cl_mem_flags flags = CL_MEM_READ_WRITE; + cl_int retVal = CL_SUCCESS; +}; diff --git a/unit_tests/mem_obj/image_tests.cpp b/unit_tests/mem_obj/image_tests.cpp index 9b1c6594ad..438bba52f5 100644 --- a/unit_tests/mem_obj/image_tests.cpp +++ b/unit_tests/mem_obj/image_tests.cpp @@ -20,6 +20,7 @@ #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/kernel_binary_helper.h" #include "unit_tests/helpers/memory_management.h" +#include "unit_tests/mem_obj/image_compression_fixture.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_gmm.h" #include "unit_tests/mocks/mock_memory_manager.h" @@ -903,37 +904,6 @@ TEST(ImageGetSurfaceFormatInfoTest, givenNullptrFormatWhenGetSurfaceFormatInfoIs EXPECT_EQ(nullptr, surfaceFormat); } -class ImageCompressionTests : public ::testing::Test { - public: - class MyMemoryManager : public MockMemoryManager { - public: - using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override { - mockMethodCalled = true; - capturedImgInfo = *allocationData.imgInfo; - return OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(allocationData); - } - ImageInfo capturedImgInfo = {}; - bool mockMethodCalled = false; - }; - - void SetUp() override { - mockDevice.reset(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); - myMemoryManager = new MyMemoryManager(*mockDevice->getExecutionEnvironment()); - mockDevice->injectMemoryManager(myMemoryManager); - mockContext.reset(new MockContext(mockDevice.get())); - } - - std::unique_ptr mockDevice; - std::unique_ptr mockContext; - MyMemoryManager *myMemoryManager = nullptr; - - cl_image_desc imageDesc = {}; - cl_image_format imageFormat{CL_RGBA, CL_UNORM_INT8}; - cl_mem_flags flags = CL_MEM_READ_WRITE; - cl_int retVal = CL_SUCCESS; -}; - TEST_F(ImageCompressionTests, givenTiledImageWhenCreatingAllocationThenPreferRenderCompression) { imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; imageDesc.image_width = 5; @@ -1511,4 +1481,4 @@ HWTEST_F(HwImageTest, givenImageHwWithUnifiedSurfaceAndMcsWhenSettingParamsForMu mockImage->setAuxParamsForMultisamples(&surfaceState); EXPECT_TRUE(mockImage->setAuxParamsForMCSCCSCalled); -} \ No newline at end of file +} diff --git a/unit_tests/mem_obj/mem_obj_helper_tests.cpp b/unit_tests/mem_obj/mem_obj_helper_tests.cpp index d3eb7a360f..9947989be1 100644 --- a/unit_tests/mem_obj/mem_obj_helper_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_helper_tests.cpp @@ -60,32 +60,53 @@ TEST(MemObjHelper, givenInvalidPropertiesWhenParsingMemoryPropertiesThenFalseIsR TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) { MemoryProperties properties; - EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); + + properties.flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL | CL_MEM_NO_ACCESS_INTEL; + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); + + properties.flags = CL_MEM_NO_ACCESS_INTEL; + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); properties.flags = CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_HOST_NO_ACCESS; - EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); properties.flags = CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY; - EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); properties.flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_NO_ACCESS; - EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE; - EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); properties.flags = 0; - EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); } TEST(MemObjHelper, givenInvalidPropertiesWhenValidatingMemoryPropertiesThenFalseIsReturned) { MemoryProperties properties; properties.flags = (1 << 31); - EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); + + properties.flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL | CL_MEM_NO_ACCESS_INTEL; + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + + properties.flags = CL_MEM_NO_ACCESS_INTEL; + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); properties.flags_intel = (1 << 31); - EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); properties.flags = 0; - EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties)); + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties)); + EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr)); }