mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +08:00
Render compressed buffer creation flow
Change-Id: I58b7f7eb3b69afcb78c6ab3de1f6fb7524d33f13
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include "runtime/context/context.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/gmm_helper/gmm.h"
|
||||
#include "runtime/gmm_helper/gmm_helper.h"
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/helpers/hw_info.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
@ -93,11 +94,14 @@ Buffer *Buffer::create(Context *context,
|
||||
bool isHostPtrSVM = false;
|
||||
bool allocateMemory = false;
|
||||
bool copyMemoryFromHostPtr = false;
|
||||
GraphicsAllocation::AllocationType allocationType = GmmHelper::hwInfo->capabilityTable.ftrRenderCompressedBuffers
|
||||
? GraphicsAllocation::AllocationType::BUFFER_COMPRESSED
|
||||
: GraphicsAllocation::AllocationType::BUFFER;
|
||||
|
||||
MemoryManager *memoryManager = context->getMemoryManager();
|
||||
UNRECOVERABLE_IF(!memoryManager);
|
||||
|
||||
checkMemory(flags, size, hostPtr, errcodeRet, zeroCopy, allocateMemory, copyMemoryFromHostPtr, memoryManager);
|
||||
checkMemory(flags, size, hostPtr, errcodeRet, zeroCopy, allocateMemory, copyMemoryFromHostPtr, allocationType, memoryManager);
|
||||
|
||||
if (hostPtr && context->isProvidingPerformanceHints()) {
|
||||
if (zeroCopy) {
|
||||
@ -108,6 +112,7 @@ Buffer *Buffer::create(Context *context,
|
||||
}
|
||||
|
||||
if (context->isSharedContext) {
|
||||
allocationType = GraphicsAllocation::AllocationType::BUFFER;
|
||||
zeroCopy = true;
|
||||
copyMemoryFromHostPtr = false;
|
||||
allocateMemory = false;
|
||||
@ -117,6 +122,7 @@ Buffer *Buffer::create(Context *context,
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
memory = context->getSVMAllocsManager()->getSVMAlloc(hostPtr);
|
||||
if (memory) {
|
||||
allocationType = GraphicsAllocation::AllocationType::BUFFER;
|
||||
zeroCopy = true;
|
||||
isHostPtrSVM = true;
|
||||
copyMemoryFromHostPtr = false;
|
||||
@ -125,7 +131,7 @@ Buffer *Buffer::create(Context *context,
|
||||
}
|
||||
|
||||
if (!memory) {
|
||||
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(zeroCopy, allocateMemory, true, false, hostPtr, static_cast<size_t>(size), GraphicsAllocation::AllocationType::BUFFER);
|
||||
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(zeroCopy, allocateMemory, true, false, hostPtr, static_cast<size_t>(size), allocationType);
|
||||
}
|
||||
|
||||
if (allocateMemory) {
|
||||
@ -140,7 +146,7 @@ Buffer *Buffer::create(Context *context,
|
||||
zeroCopy = false;
|
||||
copyMemoryFromHostPtr = true;
|
||||
allocateMemory = true;
|
||||
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(zeroCopy, allocateMemory, true, false, nullptr, static_cast<size_t>(size), GraphicsAllocation::AllocationType::BUFFER);
|
||||
memory = memoryManager->allocateGraphicsMemoryInPreferredPool(zeroCopy, allocateMemory, true, false, nullptr, static_cast<size_t>(size), allocationType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +155,7 @@ Buffer *Buffer::create(Context *context,
|
||||
break;
|
||||
}
|
||||
|
||||
memory->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
|
||||
memory->setAllocationType(allocationType);
|
||||
memory->setMemObjectsAllocationWithWritableFlags(!(flags & (CL_MEM_READ_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)));
|
||||
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, "hostPtr:", hostPtr, "size:", size, "memoryStorage:", memory->getUnderlyingBuffer(), "GPU address:", std::hex, memory->getGpuAddress());
|
||||
@ -198,6 +204,7 @@ void Buffer::checkMemory(cl_mem_flags flags,
|
||||
bool &isZeroCopy,
|
||||
bool &allocateMemory,
|
||||
bool ©MemoryFromHostPtr,
|
||||
GraphicsAllocation::AllocationType allocationType,
|
||||
MemoryManager *memMngr) {
|
||||
errcodeRet = CL_SUCCESS;
|
||||
isZeroCopy = false;
|
||||
@ -219,6 +226,7 @@ void Buffer::checkMemory(cl_mem_flags flags,
|
||||
if (alignUp(hostPtr, MemoryConstants::cacheLineSize) != hostPtr ||
|
||||
alignUp(size, MemoryConstants::cacheLineSize) != size ||
|
||||
minAddress > reinterpret_cast<uintptr_t>(hostPtr) ||
|
||||
GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == allocationType ||
|
||||
DebugManager.flags.DisableZeroCopyForUseHostPtr.get() ||
|
||||
DebugManager.flags.DisableZeroCopyForBuffers.get()) {
|
||||
allocateMemory = true;
|
||||
@ -233,7 +241,8 @@ void Buffer::checkMemory(cl_mem_flags flags,
|
||||
} else {
|
||||
allocateMemory = true;
|
||||
isZeroCopy = true;
|
||||
if (DebugManager.flags.DisableZeroCopyForBuffers.get()) {
|
||||
if (DebugManager.flags.DisableZeroCopyForBuffers.get() ||
|
||||
GraphicsAllocation::AllocationType::BUFFER_COMPRESSED == allocationType) {
|
||||
isZeroCopy = false;
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +136,7 @@ class Buffer : public MemObj {
|
||||
bool &isZeroCopy,
|
||||
bool &allocateMemory,
|
||||
bool ©MemoryFromHostPtr,
|
||||
GraphicsAllocation::AllocationType allocationType,
|
||||
MemoryManager *memMngr);
|
||||
|
||||
static bool isReadOnlyMemoryPermittedByFlags(cl_mem_flags flags);
|
||||
|
@ -214,6 +214,81 @@ TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAll
|
||||
EXPECT_EQ(nullptr, buffer.get());
|
||||
}
|
||||
|
||||
TEST(Buffer, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopyAndAllocateStorage) {
|
||||
HardwareInfo localHwInfo = *platformDevices[0];
|
||||
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = false;
|
||||
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment()));
|
||||
auto context = std::make_unique<MockContext>(device.get());
|
||||
|
||||
void *cacheAlignedHostPtr = alignedMalloc(MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), CL_MEM_USE_HOST_PTR, MemoryConstants::cacheLineSize, cacheAlignedHostPtr, retVal));
|
||||
EXPECT_EQ(cacheAlignedHostPtr, buffer->getGraphicsAllocation()->getUnderlyingBuffer());
|
||||
EXPECT_TRUE(buffer->isMemObjZeroCopy());
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
|
||||
|
||||
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
|
||||
buffer.reset(Buffer::create(context.get(), CL_MEM_USE_HOST_PTR, MemoryConstants::cacheLineSize, cacheAlignedHostPtr, retVal));
|
||||
EXPECT_NE(cacheAlignedHostPtr, buffer->getGraphicsAllocation()->getUnderlyingBuffer());
|
||||
EXPECT_FALSE(buffer->isMemObjZeroCopy());
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
|
||||
|
||||
alignedFree(cacheAlignedHostPtr);
|
||||
}
|
||||
|
||||
TEST(Buffer, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopy) {
|
||||
HardwareInfo localHwInfo = *platformDevices[0];
|
||||
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = false;
|
||||
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment()));
|
||||
auto context = std::make_unique<MockContext>(device.get());
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), 0, MemoryConstants::cacheLineSize, nullptr, retVal));
|
||||
EXPECT_TRUE(buffer->isMemObjZeroCopy());
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
|
||||
|
||||
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
|
||||
buffer.reset(Buffer::create(context.get(), 0, MemoryConstants::cacheLineSize, nullptr, retVal));
|
||||
EXPECT_FALSE(buffer->isMemObjZeroCopy());
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
|
||||
}
|
||||
|
||||
TEST(Buffer, givenBufferCompressedAllocationWhenSharedContextIsUsedThenForceDisableCompression) {
|
||||
HardwareInfo localHwInfo = *platformDevices[0];
|
||||
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
|
||||
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment()));
|
||||
auto context = std::make_unique<MockContext>(device.get());
|
||||
context->isSharedContext = false;
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
uint32_t hostPtr = 0;
|
||||
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), 0, sizeof(uint32_t), &hostPtr, retVal));
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
|
||||
|
||||
context->isSharedContext = true;
|
||||
buffer.reset(Buffer::create(context.get(), 0, sizeof(uint32_t), &hostPtr, retVal));
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
|
||||
}
|
||||
|
||||
TEST(Buffer, givenSvmAllocationWhenCreatingBufferThenForceDisableCompression) {
|
||||
HardwareInfo localHwInfo = *platformDevices[0];
|
||||
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
|
||||
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment()));
|
||||
auto context = std::make_unique<MockContext>(device.get());
|
||||
|
||||
auto svmAlloc = context->getSVMAllocsManager()->createSVMAlloc(sizeof(uint32_t), false);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(context.get(), CL_MEM_USE_HOST_PTR, sizeof(uint32_t), svmAlloc, retVal));
|
||||
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
|
||||
|
||||
context->getSVMAllocsManager()->freeSVMAlloc(svmAlloc);
|
||||
}
|
||||
|
||||
class BufferTest : public DeviceFixture,
|
||||
public testing::TestWithParam<uint64_t /*cl_mem_flags*/> {
|
||||
public:
|
||||
|
Reference in New Issue
Block a user