Enqueue write buffer instead of memcpy for renderCompressed allocation

Change-Id: I5505add129e08537fc0009b12228a446aa732645
This commit is contained in:
Dunajski, Bartosz
2018-07-24 09:06:33 +02:00
committed by sys_ocldev
parent c61364bd3f
commit 579367fe4a
6 changed files with 175 additions and 92 deletions

View File

@@ -214,16 +214,26 @@ TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAll
EXPECT_EQ(nullptr, buffer.get());
}
TEST(Buffer, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopyAndAllocateStorage) {
HardwareInfo localHwInfo = *platformDevices[0];
struct RenderCompressedBuffersTests : public ::testing::Test {
void SetUp() override {
localHwInfo = *platformDevices[0];
device.reset(Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment()));
context = std::make_unique<MockContext>(device.get(), true);
}
cl_int retVal = CL_SUCCESS;
HardwareInfo localHwInfo = {};
std::unique_ptr<MockDevice> device;
std::unique_ptr<MockContext> context;
std::unique_ptr<Buffer> buffer;
};
TEST_F(RenderCompressedBuffersTests, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopyAndAllocateStorage) {
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));
buffer.reset(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);
@@ -237,15 +247,10 @@ TEST(Buffer, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemory
alignedFree(cacheAlignedHostPtr);
}
TEST(Buffer, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopy) {
HardwareInfo localHwInfo = *platformDevices[0];
TEST_F(RenderCompressedBuffersTests, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopy) {
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));
buffer.reset(Buffer::create(context.get(), 0, MemoryConstants::cacheLineSize, nullptr, retVal));
EXPECT_TRUE(buffer->isMemObjZeroCopy());
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
@@ -255,17 +260,13 @@ TEST(Buffer, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryProper
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
}
TEST(Buffer, givenBufferCompressedAllocationWhenSharedContextIsUsedThenForceDisableCompression) {
HardwareInfo localHwInfo = *platformDevices[0];
TEST_F(RenderCompressedBuffersTests, givenBufferCompressedAllocationWhenSharedContextIsUsedThenForceDisableCompression) {
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));
buffer.reset(Buffer::create(context.get(), 0, sizeof(uint32_t), &hostPtr, retVal));
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
context->isSharedContext = true;
@@ -273,22 +274,63 @@ TEST(Buffer, givenBufferCompressedAllocationWhenSharedContextIsUsedThenForceDisa
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
}
TEST(Buffer, givenSvmAllocationWhenCreatingBufferThenForceDisableCompression) {
HardwareInfo localHwInfo = *platformDevices[0];
TEST_F(RenderCompressedBuffersTests, givenSvmAllocationWhenCreatingBufferThenForceDisableCompression) {
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));
buffer.reset(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);
}
struct RenderCompressedBuffersCopyHostMemoryTests : public RenderCompressedBuffersTests {
void SetUp() override {
RenderCompressedBuffersTests::SetUp();
device->injectMemoryManager(new MockMemoryManager(true));
context->setMemoryManager(device->getMemoryManager());
mockCmdQ = new MockCommandQueue();
context->setSpecialQueue(mockCmdQ);
}
MockCommandQueue *mockCmdQ = nullptr;
uint32_t hostPtr = 0;
};
TEST_F(RenderCompressedBuffersCopyHostMemoryTests, givenRenderCompressedBufferWhenCopyFromHostPtrIsRequiredThenCallWriteBuffer) {
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
buffer.reset(Buffer::create(context.get(), CL_MEM_COPY_HOST_PTR, sizeof(uint32_t), &hostPtr, retVal));
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, mockCmdQ->writeBufferCounter);
EXPECT_TRUE(mockCmdQ->writeBufferBlocking);
EXPECT_EQ(0u, mockCmdQ->writeBufferOffset);
EXPECT_EQ(sizeof(uint32_t), mockCmdQ->writeBufferSize);
EXPECT_EQ(&hostPtr, mockCmdQ->writeBufferPtr);
}
TEST_F(RenderCompressedBuffersCopyHostMemoryTests, givenNonRenderCompressedBufferWhenCopyFromHostPtrIsRequiredThenDontCallWriteBuffer) {
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = false;
buffer.reset(Buffer::create(context.get(), CL_MEM_COPY_HOST_PTR, sizeof(uint32_t), &hostPtr, retVal));
EXPECT_EQ(buffer->getGraphicsAllocation()->getAllocationType(), GraphicsAllocation::AllocationType::BUFFER);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0u, mockCmdQ->writeBufferCounter);
}
TEST_F(RenderCompressedBuffersCopyHostMemoryTests, givenRenderCompressedBufferWhenWriteBufferFailsThenReturnErrorCode) {
localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true;
mockCmdQ->writeBufferRetValue = CL_INVALID_VALUE;
buffer.reset(Buffer::create(context.get(), CL_MEM_COPY_HOST_PTR, sizeof(uint32_t), &hostPtr, retVal));
EXPECT_EQ(CL_OUT_OF_RESOURCES, retVal);
EXPECT_EQ(nullptr, buffer.get());
}
class BufferTest : public DeviceFixture,
public testing::TestWithParam<uint64_t /*cl_mem_flags*/> {
public: