Pass context to isSuitableForRenderCompression method

Related-To: NEO-3691

Change-Id: I3417e647f4219451922a4dc905726366b4448890
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2019-10-08 10:38:02 +02:00 committed by sys_ocldev
parent e1ff6603b2
commit e0594d4716
7 changed files with 61 additions and 27 deletions

View File

@ -149,8 +149,7 @@ Buffer *Buffer::create(Context *context,
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(
memoryProperties,
context->isSharedContext,
context->peekContextType(),
*context,
HwHelper::renderCompressedBuffersSupported(context->getDevice(0)->getHardwareInfo()),
memoryManager->isLocalMemorySupported(),
HwHelper::get(context->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(size));
@ -376,10 +375,10 @@ void Buffer::checkMemory(MemoryPropertiesFlags memoryProperties,
return;
}
GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext,
ContextType contextType, bool renderCompressedBuffers,
bool isLocalMemoryEnabled, bool preferCompression) {
if (is32bit || sharedContext || properties.flags.forceSharedPhysicalMemory) {
GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryPropertiesFlags &properties, Context &context,
bool renderCompressedBuffers, bool isLocalMemoryEnabled,
bool preferCompression) {
if (is32bit || context.isSharedContext || properties.flags.forceSharedPhysicalMemory) {
return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
}
@ -387,7 +386,7 @@ GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const Memor
return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
}
if (MemObjHelper::isSuitableForRenderCompression(renderCompressedBuffers, properties, contextType, preferCompression)) {
if (MemObjHelper::isSuitableForRenderCompression(renderCompressedBuffers, properties, context, preferCompression)) {
return GraphicsAllocation::AllocationType::BUFFER_COMPRESSED;
}
return GraphicsAllocation::AllocationType::BUFFER;

View File

@ -149,9 +149,9 @@ class Buffer : public MemObj {
bool &isZeroCopy,
bool &copyMemoryFromHostPtr,
MemoryManager *memMngr);
static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext,
ContextType contextType, bool renderCompressedBuffers,
bool localMemoryEnabled, bool preferCompression);
static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryPropertiesFlags &properties, Context &context,
bool renderCompressedBuffers, bool localMemoryEnabled,
bool preferCompression);
static bool isReadOnlyMemoryPermittedByFlags(const MemoryPropertiesFlags &properties);
void transferData(void *dst, void *src, size_t copySize, size_t copyOffset);

View File

@ -184,7 +184,7 @@ Image *Image::create(Context *context,
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
imgInfo.linearStorage = !hwHelper.tilingAllowed(context->isSharedContext, *imageDesc, memoryProperties.flags.forceLinearStorage);
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(!imgInfo.linearStorage, memoryProperties,
context->peekContextType(), true);
*context, true);
if (!context->getDevice(0)->getDeviceInfo().imageSupport && !imgInfo.linearStorage) {
errcodeRet = CL_INVALID_OPERATION;

View File

@ -11,7 +11,7 @@
namespace NEO {
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression) {
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, Context &context, bool preferCompression) {
return renderCompressed && preferCompression;
}

View File

@ -9,7 +9,6 @@
#include "common/helpers/bit_helpers.h"
#include "core/memory_manager/unified_memory_manager.h"
#include "public/cl_ext_private.h"
#include "runtime/context/context_type.h"
#include "runtime/helpers/mem_properties_parser_helper.h"
#include "runtime/mem_obj/mem_obj.h"
#include "runtime/memory_manager/memory_manager.h"
@ -37,7 +36,7 @@ class MemObjHelper {
static AllocationProperties getAllocationPropertiesWithImageInfo(ImageInfo &imgInfo, bool allocateMemory, const MemoryPropertiesFlags &memoryProperties);
static bool checkMemFlagsForSubBuffer(cl_mem_flags flags);
static SVMAllocsManager::SvmAllocationProperties getSvmAllocationProperties(cl_mem_flags flags);
static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression);
static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, Context &context, bool preferCompression);
protected:
static bool validateExtraMemoryProperties(const MemoryProperties &properties);

View File

@ -501,7 +501,7 @@ TEST_F(PerformanceHintTest, givenUncompressedBufferWhenItsCreatedThenProperPerfo
if (context->getMemoryManager()) {
isCompressed = MemObjHelper::isSuitableForRenderCompression(
HwHelper::renderCompressedBuffersSupported(hwInfo),
memoryProperties, context->peekContextType(),
memoryProperties, *context,
HwHelper::get(hwInfo.platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(size)) &&
!is32bit && !context->isSharedContext &&
(!isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) || context->getMemoryManager()->isLocalMemorySupported()) &&

View File

@ -330,7 +330,10 @@ TEST(Buffer, givenAllocHostPtrFlagPassedToBufferCreateWhenNoSharedContextOrRende
TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturnedIn64Bit) {
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true);
if (is32bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
} else {
@ -340,7 +343,10 @@ TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenB
TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturnedIn64Bit) {
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, true, true);
if (is32bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
} else {
@ -350,13 +356,19 @@ TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocatio
TEST(Buffer, givenSharedContextWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) {
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = true;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true);
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
}
TEST(Buffer, givenSharedContextAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) {
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = true;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true);
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
}
@ -364,7 +376,10 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledWhenAllocationTypeIsQuerie
MemoryProperties properties;
properties.flags = CL_MEM_USE_HOST_PTR;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true);
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
}
@ -372,7 +387,10 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueried
MemoryProperties properties;
properties.flags = CL_MEM_USE_HOST_PTR;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, true, true);
if (is64bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type);
} else {
@ -384,7 +402,10 @@ TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsRet
MemoryProperties properties;
properties.flags = CL_MEM_ALLOC_HOST_PTR;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true);
if (is64bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type);
} else {
@ -396,7 +417,10 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndRenderCompressedBuffers
MemoryProperties properties;
properties.flags = CL_MEM_USE_HOST_PTR;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true);
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
}
@ -404,7 +428,10 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersE
MemoryProperties properties;
properties.flags = CL_MEM_USE_HOST_PTR;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, true, true);
if (is64bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type);
} else {
@ -416,7 +443,10 @@ TEST(Buffer, givenUseHostPointerFlagAndForceSharedPhysicalStorageWhenLocalMemory
MemoryProperties properties;
properties.flags = CL_MEM_USE_HOST_PTR | CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, true, true);
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
}
@ -424,7 +454,10 @@ TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocatio
MemoryProperties properties;
properties.flags = CL_MEM_ALLOC_HOST_PTR;
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true);
if (is64bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type);
} else {
@ -434,7 +467,10 @@ TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocatio
TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) {
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
MockContext context;
context.setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE);
context.isSharedContext = false;
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true);
if (is32bit) {
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
} else {