Update Image compression
Change-Id: I3a15dba343a80716b57cdda6b74f2142814021f3 Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
parent
fcdfcb3fc4
commit
40541e4faa
|
@ -711,63 +711,15 @@ cl_mem CL_API_CALL clCreateImage(cl_context context,
|
||||||
"hostPtr", hostPtr);
|
"hostPtr", hostPtr);
|
||||||
|
|
||||||
cl_mem image = nullptr;
|
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 {
|
do {
|
||||||
/* Are there some invalid flag bits? */
|
/* Are there some invalid flag bits? */
|
||||||
if ((flags & (~allValidFlags)) != 0) {
|
if (!MemObjHelper::validateMemoryPropertiesForImage(flags, imageDesc->mem_object)) {
|
||||||
retVal = CL_INVALID_VALUE;
|
retVal = CL_INVALID_VALUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Check all the invalid flags combination. */
|
bool isHostPtrUsed = (hostPtr != nullptr);
|
||||||
if (((((CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY) | flags) == flags) ||
|
bool areHostPtrFlagsUsed = isValueSet(flags, CL_MEM_COPY_HOST_PTR) || isValueSet(flags, CL_MEM_USE_HOST_PTR);
|
||||||
(((CL_MEM_READ_WRITE | CL_MEM_READ_ONLY) | flags) == flags) ||
|
if (isHostPtrUsed != areHostPtrFlagsUsed) {
|
||||||
(((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<MemObj>(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) {
|
|
||||||
retVal = CL_INVALID_HOST_PTR;
|
retVal = CL_INVALID_HOST_PTR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ void Buffer::validateInputAndCreateBuffer(cl_context &context,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MemObjHelper::validateMemoryProperties(properties)) {
|
if (!MemObjHelper::validateMemoryPropertiesForBuffer(properties)) {
|
||||||
retVal = CL_INVALID_VALUE;
|
retVal = CL_INVALID_VALUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,8 @@ Image *Image::create(Context *context,
|
||||||
auto hostPtrRowPitch = imageDesc->image_row_pitch ? imageDesc->image_row_pitch : imageWidth * surfaceFormat->ImageElementSizeInBytes;
|
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 hostPtrSlicePitch = imageDesc->image_slice_pitch ? imageDesc->image_slice_pitch : hostPtrRowPitch * imageHeight;
|
||||||
auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc);
|
auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc);
|
||||||
imgInfo.preferRenderCompression = isTilingAllowed;
|
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, flags,
|
||||||
|
context->peekContextType());
|
||||||
|
|
||||||
bool zeroCopy = false;
|
bool zeroCopy = false;
|
||||||
bool transferNeeded = false;
|
bool transferNeeded = false;
|
||||||
|
|
|
@ -46,8 +46,8 @@ StorageInfo MemObjHelper::getStorageInfo(const MemoryProperties &properties) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressedBuffers, const MemoryProperties &properties, ContextType contextType) {
|
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType) {
|
||||||
return renderCompressedBuffers;
|
return renderCompressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) {
|
bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &properties) {
|
||||||
|
|
|
@ -21,10 +21,8 @@ class MemObjHelper {
|
||||||
public:
|
public:
|
||||||
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct);
|
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct);
|
||||||
|
|
||||||
static bool validateMemoryProperties(const MemoryProperties &properties) {
|
static bool validateMemoryPropertiesForBuffer(const MemoryProperties &properties) {
|
||||||
|
if (!MemObjHelper::checkUsedFlagsForBuffer(properties)) {
|
||||||
/* Are there some invalid flag bits? */
|
|
||||||
if (!MemObjHelper::checkMemFlagsForBuffer(properties)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +41,49 @@ class MemObjHelper {
|
||||||
return validateExtraMemoryProperties(properties);
|
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<MemObj>(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,
|
static AllocationProperties getAllocationProperties(cl_mem_flags_intel flags, bool allocateMemory,
|
||||||
size_t size, GraphicsAllocation::AllocationType type);
|
size_t size, GraphicsAllocation::AllocationType type);
|
||||||
static AllocationProperties getAllocationProperties(ImageInfo *imgInfo, bool allocateMemory);
|
static AllocationProperties getAllocationProperties(ImageInfo *imgInfo, bool allocateMemory);
|
||||||
|
@ -57,28 +98,41 @@ class MemObjHelper {
|
||||||
return isFieldValid(flags, allValidFlags);
|
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:
|
protected:
|
||||||
static bool checkMemFlagsForBuffer(const MemoryProperties &properties) {
|
static bool checkUsedFlagsForBuffer(const MemoryProperties &properties) {
|
||||||
MemoryProperties additionalAcceptedProperties;
|
MemoryProperties acceptedProperties;
|
||||||
addExtraMemoryProperties(additionalAcceptedProperties);
|
addCommonMemoryProperties(acceptedProperties);
|
||||||
|
addExtraMemoryProperties(acceptedProperties);
|
||||||
|
|
||||||
const cl_mem_flags allValidFlags =
|
return (isFieldValid(properties.flags, acceptedProperties.flags) &&
|
||||||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
isFieldValid(properties.flags_intel, acceptedProperties.flags_intel));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 void addExtraMemoryProperties(MemoryProperties &properties);
|
||||||
|
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
|
||||||
};
|
};
|
||||||
} // namespace OCLRT
|
} // namespace OCLRT
|
||||||
|
|
|
@ -172,7 +172,7 @@ TEST_F(clCreateImageTest, GivenInvalidFlagBitsWhenCreatingImageFromAnotherImageT
|
||||||
|
|
||||||
imageFormat.image_channel_order = CL_RG;
|
imageFormat.image_channel_order = CL_RG;
|
||||||
imageDesc.mem_object = image;
|
imageDesc.mem_object = image;
|
||||||
cl_mem_flags flags = (1 << 3);
|
cl_mem_flags flags = (1 << 30);
|
||||||
|
|
||||||
auto imageFromImageObject = clCreateImage(
|
auto imageFromImageObject = clCreateImage(
|
||||||
pContext,
|
pContext,
|
||||||
|
@ -529,9 +529,14 @@ TEST_P(clCreateImageValidFlagsAndParentFlagsCombinations, GivenValidFlagsAndPare
|
||||||
|
|
||||||
static ImageFlags invalidFlagsAndParentFlags[] = {
|
static ImageFlags invalidFlagsAndParentFlags[] = {
|
||||||
{CL_MEM_WRITE_ONLY, CL_MEM_READ_WRITE},
|
{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_READ_WRITE},
|
||||||
|
{CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY},
|
||||||
{CL_MEM_NO_ACCESS_INTEL, CL_MEM_READ_WRITE},
|
{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<ImageFlags>> clCreateImageInvalidFlagsAndParentFlagsCombinations;
|
typedef clCreateImageTests<::testing::TestWithParam<ImageFlags>> clCreateImageInvalidFlagsAndParentFlagsCombinations;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ set(IGDRCL_SRCS_tests_mem_obj
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/image2d_tests.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/image2d_tests.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/image3d_tests.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/image3d_tests.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/image_array_size_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_format_tests.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/image_redescribe_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_release_mapped_ptr_tests.cpp
|
||||||
|
|
|
@ -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<MockDevice>(*platformDevices));
|
||||||
|
myMemoryManager = new MyMemoryManager(*mockDevice->getExecutionEnvironment());
|
||||||
|
mockDevice->injectMemoryManager(myMemoryManager);
|
||||||
|
mockContext = make_releaseable<MockContext>(mockDevice.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<MockDevice> mockDevice;
|
||||||
|
ReleaseableObjectPtr<MockContext> 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;
|
||||||
|
};
|
|
@ -20,6 +20,7 @@
|
||||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||||
#include "unit_tests/helpers/kernel_binary_helper.h"
|
#include "unit_tests/helpers/kernel_binary_helper.h"
|
||||||
#include "unit_tests/helpers/memory_management.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_context.h"
|
||||||
#include "unit_tests/mocks/mock_gmm.h"
|
#include "unit_tests/mocks/mock_gmm.h"
|
||||||
#include "unit_tests/mocks/mock_memory_manager.h"
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
||||||
|
@ -903,37 +904,6 @@ TEST(ImageGetSurfaceFormatInfoTest, givenNullptrFormatWhenGetSurfaceFormatInfoIs
|
||||||
EXPECT_EQ(nullptr, surfaceFormat);
|
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<MockDevice>(*platformDevices));
|
|
||||||
myMemoryManager = new MyMemoryManager(*mockDevice->getExecutionEnvironment());
|
|
||||||
mockDevice->injectMemoryManager(myMemoryManager);
|
|
||||||
mockContext.reset(new MockContext(mockDevice.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<MockDevice> mockDevice;
|
|
||||||
std::unique_ptr<MockContext> 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) {
|
TEST_F(ImageCompressionTests, givenTiledImageWhenCreatingAllocationThenPreferRenderCompression) {
|
||||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||||
imageDesc.image_width = 5;
|
imageDesc.image_width = 5;
|
||||||
|
|
|
@ -60,32 +60,53 @@ TEST(MemObjHelper, givenInvalidPropertiesWhenParsingMemoryPropertiesThenFalseIsR
|
||||||
|
|
||||||
TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) {
|
TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) {
|
||||||
MemoryProperties properties;
|
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;
|
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;
|
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;
|
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;
|
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;
|
properties.flags = 0;
|
||||||
EXPECT_TRUE(MemObjHelper::validateMemoryProperties(properties));
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||||
|
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MemObjHelper, givenInvalidPropertiesWhenValidatingMemoryPropertiesThenFalseIsReturned) {
|
TEST(MemObjHelper, givenInvalidPropertiesWhenValidatingMemoryPropertiesThenFalseIsReturned) {
|
||||||
MemoryProperties properties;
|
MemoryProperties properties;
|
||||||
properties.flags = (1 << 31);
|
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);
|
properties.flags_intel = (1 << 31);
|
||||||
EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties));
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||||
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||||
|
|
||||||
properties.flags = 0;
|
properties.flags = 0;
|
||||||
EXPECT_FALSE(MemObjHelper::validateMemoryProperties(properties));
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||||
|
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue