@@ -214,16 +214,26 @@ TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAll
214
214
EXPECT_EQ (nullptr , buffer.get ());
215
215
}
216
216
217
- TEST (Buffer, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopyAndAllocateStorage) {
218
- HardwareInfo localHwInfo = *platformDevices[0 ];
217
+ struct RenderCompressedBuffersTests : public ::testing::Test {
218
+ void SetUp () override {
219
+ localHwInfo = *platformDevices[0 ];
220
+ device.reset (Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment ()));
221
+ context = std::make_unique<MockContext>(device.get (), true );
222
+ }
223
+
224
+ cl_int retVal = CL_SUCCESS;
225
+ HardwareInfo localHwInfo = {};
226
+ std::unique_ptr<MockDevice> device;
227
+ std::unique_ptr<MockContext> context;
228
+ std::unique_ptr<Buffer> buffer;
229
+ };
230
+
231
+ TEST_F (RenderCompressedBuffersTests, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopyAndAllocateStorage) {
219
232
localHwInfo.capabilityTable .ftrRenderCompressedBuffers = false ;
220
- std::unique_ptr<MockDevice> device (Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment ()));
221
- auto context = std::make_unique<MockContext>(device.get ());
222
233
223
234
void *cacheAlignedHostPtr = alignedMalloc (MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
224
- cl_int retVal = CL_SUCCESS;
225
235
226
- std::unique_ptr<Buffer> buffer (Buffer::create (context.get (), CL_MEM_USE_HOST_PTR, MemoryConstants::cacheLineSize, cacheAlignedHostPtr, retVal));
236
+ buffer. reset (Buffer::create (context.get (), CL_MEM_USE_HOST_PTR, MemoryConstants::cacheLineSize, cacheAlignedHostPtr, retVal));
227
237
EXPECT_EQ (cacheAlignedHostPtr, buffer->getGraphicsAllocation ()->getUnderlyingBuffer ());
228
238
EXPECT_TRUE (buffer->isMemObjZeroCopy ());
229
239
EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER);
@@ -237,15 +247,10 @@ TEST(Buffer, givenBufferCompressedAllocationAndZeroCopyHostPtrWhenCheckingMemory
237
247
alignedFree (cacheAlignedHostPtr);
238
248
}
239
249
240
- TEST (Buffer, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopy) {
241
- HardwareInfo localHwInfo = *platformDevices[0 ];
250
+ TEST_F (RenderCompressedBuffersTests, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryPropertiesThenForceDisableZeroCopy) {
242
251
localHwInfo.capabilityTable .ftrRenderCompressedBuffers = false ;
243
- std::unique_ptr<MockDevice> device (Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment ()));
244
- auto context = std::make_unique<MockContext>(device.get ());
245
-
246
- cl_int retVal = CL_SUCCESS;
247
252
248
- std::unique_ptr<Buffer> buffer (Buffer::create (context.get (), 0 , MemoryConstants::cacheLineSize, nullptr , retVal));
253
+ buffer. reset (Buffer::create (context.get (), 0 , MemoryConstants::cacheLineSize, nullptr , retVal));
249
254
EXPECT_TRUE (buffer->isMemObjZeroCopy ());
250
255
EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER);
251
256
@@ -255,40 +260,77 @@ TEST(Buffer, givenBufferCompressedAllocationAndNoHostPtrWhenCheckingMemoryProper
255
260
EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
256
261
}
257
262
258
- TEST (Buffer, givenBufferCompressedAllocationWhenSharedContextIsUsedThenForceDisableCompression) {
259
- HardwareInfo localHwInfo = *platformDevices[0 ];
263
+ TEST_F (RenderCompressedBuffersTests, givenBufferCompressedAllocationWhenSharedContextIsUsedThenForceDisableCompression) {
260
264
localHwInfo.capabilityTable .ftrRenderCompressedBuffers = true ;
261
- std::unique_ptr<MockDevice> device (Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment ()));
262
- auto context = std::make_unique<MockContext>(device.get ());
263
265
context->isSharedContext = false ;
264
266
265
- cl_int retVal = CL_SUCCESS;
266
267
uint32_t hostPtr = 0 ;
267
268
268
- std::unique_ptr<Buffer> buffer (Buffer::create (context.get (), 0 , sizeof (uint32_t ), &hostPtr, retVal));
269
+ buffer. reset (Buffer::create (context.get (), 0 , sizeof (uint32_t ), &hostPtr, retVal));
269
270
EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
270
271
271
272
context->isSharedContext = true ;
272
273
buffer.reset (Buffer::create (context.get (), 0 , sizeof (uint32_t ), &hostPtr, retVal));
273
274
EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER);
274
275
}
275
276
276
- TEST (Buffer, givenSvmAllocationWhenCreatingBufferThenForceDisableCompression) {
277
- HardwareInfo localHwInfo = *platformDevices[0 ];
277
+ TEST_F (RenderCompressedBuffersTests, givenSvmAllocationWhenCreatingBufferThenForceDisableCompression) {
278
278
localHwInfo.capabilityTable .ftrRenderCompressedBuffers = true ;
279
- std::unique_ptr<MockDevice> device (Device::create<MockDevice>(&localHwInfo, new ExecutionEnvironment ()));
280
- auto context = std::make_unique<MockContext>(device.get ());
281
279
282
280
auto svmAlloc = context->getSVMAllocsManager ()->createSVMAlloc (sizeof (uint32_t ), false );
283
281
284
- cl_int retVal = CL_SUCCESS;
285
-
286
- std::unique_ptr<Buffer> buffer (Buffer::create (context.get (), CL_MEM_USE_HOST_PTR, sizeof (uint32_t ), svmAlloc, retVal));
282
+ buffer.reset (Buffer::create (context.get (), CL_MEM_USE_HOST_PTR, sizeof (uint32_t ), svmAlloc, retVal));
287
283
EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER);
288
284
289
285
context->getSVMAllocsManager ()->freeSVMAlloc (svmAlloc);
290
286
}
291
287
288
+ struct RenderCompressedBuffersCopyHostMemoryTests : public RenderCompressedBuffersTests {
289
+ void SetUp () override {
290
+ RenderCompressedBuffersTests::SetUp ();
291
+ device->injectMemoryManager (new MockMemoryManager (true ));
292
+ context->setMemoryManager (device->getMemoryManager ());
293
+ mockCmdQ = new MockCommandQueue ();
294
+ context->setSpecialQueue (mockCmdQ);
295
+ }
296
+
297
+ MockCommandQueue *mockCmdQ = nullptr ;
298
+ uint32_t hostPtr = 0 ;
299
+ };
300
+
301
+ TEST_F (RenderCompressedBuffersCopyHostMemoryTests, givenRenderCompressedBufferWhenCopyFromHostPtrIsRequiredThenCallWriteBuffer) {
302
+ localHwInfo.capabilityTable .ftrRenderCompressedBuffers = true ;
303
+
304
+ buffer.reset (Buffer::create (context.get (), CL_MEM_COPY_HOST_PTR, sizeof (uint32_t ), &hostPtr, retVal));
305
+ EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
306
+ EXPECT_EQ (CL_SUCCESS, retVal);
307
+
308
+ EXPECT_EQ (1u , mockCmdQ->writeBufferCounter );
309
+ EXPECT_TRUE (mockCmdQ->writeBufferBlocking );
310
+ EXPECT_EQ (0u , mockCmdQ->writeBufferOffset );
311
+ EXPECT_EQ (sizeof (uint32_t ), mockCmdQ->writeBufferSize );
312
+ EXPECT_EQ (&hostPtr, mockCmdQ->writeBufferPtr );
313
+ }
314
+
315
+ TEST_F (RenderCompressedBuffersCopyHostMemoryTests, givenNonRenderCompressedBufferWhenCopyFromHostPtrIsRequiredThenDontCallWriteBuffer) {
316
+ localHwInfo.capabilityTable .ftrRenderCompressedBuffers = false ;
317
+
318
+ buffer.reset (Buffer::create (context.get (), CL_MEM_COPY_HOST_PTR, sizeof (uint32_t ), &hostPtr, retVal));
319
+ EXPECT_EQ (buffer->getGraphicsAllocation ()->getAllocationType (), GraphicsAllocation::AllocationType::BUFFER);
320
+ EXPECT_EQ (CL_SUCCESS, retVal);
321
+
322
+ EXPECT_EQ (0u , mockCmdQ->writeBufferCounter );
323
+ }
324
+
325
+ TEST_F (RenderCompressedBuffersCopyHostMemoryTests, givenRenderCompressedBufferWhenWriteBufferFailsThenReturnErrorCode) {
326
+ localHwInfo.capabilityTable .ftrRenderCompressedBuffers = true ;
327
+ mockCmdQ->writeBufferRetValue = CL_INVALID_VALUE;
328
+
329
+ buffer.reset (Buffer::create (context.get (), CL_MEM_COPY_HOST_PTR, sizeof (uint32_t ), &hostPtr, retVal));
330
+ EXPECT_EQ (CL_OUT_OF_RESOURCES, retVal);
331
+ EXPECT_EQ (nullptr , buffer.get ());
332
+ }
333
+
292
334
class BufferTest : public DeviceFixture ,
293
335
public testing::TestWithParam<uint64_t /* cl_mem_flags*/ > {
294
336
public:
0 commit comments