4141#include " unit_tests/mocks/mock_internal_allocation_storage.h"
4242#include " unit_tests/mocks/mock_kernel.h"
4343#include " unit_tests/mocks/mock_submissions_aggregator.h"
44+ #include " unit_tests/mocks/mock_timestamp_container.h"
4445#include " unit_tests/utilities/base_object_utils.h"
4546
4647#include " reg_configs_common.h"
@@ -276,6 +277,7 @@ struct BcsTests : public CommandStreamReceiverHwTest {
276277 CommandStreamReceiverHwTest::TearDown ();
277278 }
278279
280+ CsrDependencies csrDependencies;
279281 std::unique_ptr<MockContext> context;
280282};
281283
@@ -291,13 +293,34 @@ HWTEST_F(BcsTests, givenBltSizeWhenEstimatingCommandSizeThenAddAllRequiredComman
291293 auto expectedAlignedSize = alignUp (expectedSize + (sizeof (typename FamilyType::XY_COPY_BLT) * alignedNumberOfBlts), MemoryConstants::cacheLineSize);
292294 auto expectedNotAlignedSize = alignUp (expectedSize + (sizeof (typename FamilyType::XY_COPY_BLT) * notAlignedNumberOfBlts), MemoryConstants::cacheLineSize);
293295
294- auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize (alignedBltSize);
295- auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize (notAlignedBltSize);
296+ auto alignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize (alignedBltSize, csrDependencies );
297+ auto notAlignedEstimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize (notAlignedBltSize, csrDependencies );
296298
297299 EXPECT_EQ (expectedAlignedSize, alignedEstimatedSize);
298300 EXPECT_EQ (expectedNotAlignedSize, notAlignedEstimatedSize);
299301}
300302
303+ HWTEST_F (BcsTests, givenBltSizeAndCsrDependenciesWhenEstimatingCommandSizeThenAddAllRequiredCommands) {
304+ uint32_t numberOfBlts = 1 ;
305+ size_t numberNodesPerContainer = 5 ;
306+ auto &csr = pDevice->getUltCommandStreamReceiver <FamilyType>();
307+
308+ MockTimestampPacketContainer timestamp0 (*csr.getTimestampPacketAllocator (), numberNodesPerContainer);
309+ MockTimestampPacketContainer timestamp1 (*csr.getTimestampPacketAllocator (), numberNodesPerContainer);
310+ csrDependencies.push_back (×tamp0);
311+ csrDependencies.push_back (×tamp1);
312+
313+ size_t expectedSize = sizeof (typename FamilyType::MI_FLUSH_DW) + sizeof (typename FamilyType::MI_BATCH_BUFFER_END) +
314+ (sizeof (typename FamilyType::XY_COPY_BLT) * numberOfBlts) +
315+ TimestampPacketHelper::getRequiredCmdStreamSize<FamilyType>(csrDependencies);
316+
317+ auto expectedAlignedSize = alignUp (expectedSize, MemoryConstants::cacheLineSize);
318+
319+ auto estimatedSize = BlitCommandsHelper<FamilyType>::estimateBlitCommandsSize (1 , csrDependencies);
320+
321+ EXPECT_EQ (expectedAlignedSize, estimatedSize);
322+ }
323+
301324HWTEST_F (BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredCommands) {
302325 using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW;
303326 constexpr auto max2DBlitSize = BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight;
@@ -316,7 +339,7 @@ HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredC
316339 uint32_t newTaskCount = 19 ;
317340 csr.taskCount = newTaskCount - 1 ;
318341 EXPECT_EQ (0u , csr.recursiveLockCounter .load ());
319- csr.blitWithHostPtr (*buffer, hostPtr, bltSize, BlitterConstants::BlitWithHostPtrDirection::FromHostPtr);
342+ csr.blitWithHostPtr (*buffer, hostPtr, bltSize, BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies );
320343 EXPECT_EQ (newTaskCount, csr.taskCount );
321344 EXPECT_EQ (newTaskCount, csr.latestFlushedTaskCount );
322345 EXPECT_EQ (newTaskCount, csr.latestSentTaskCount );
@@ -363,6 +386,50 @@ HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredC
363386 }
364387}
365388
389+ HWTEST_F (BcsTests, givenCsrDependenciesWhenProgrammingCommandStreamThenAddSemaphoreAndAtomic) {
390+ auto &csr = pDevice->getUltCommandStreamReceiver <FamilyType>();
391+
392+ cl_int retVal = CL_SUCCESS;
393+ auto buffer = clUniquePtr<Buffer>(Buffer::create (context.get (), CL_MEM_READ_WRITE, 1 , nullptr , retVal));
394+ void *hostPtr = reinterpret_cast <void *>(0x12340000 );
395+ uint32_t numberOfDependencyContainers = 2 ;
396+ size_t numberNodesPerContainer = 5 ;
397+
398+ MockTimestampPacketContainer timestamp0 (*csr.getTimestampPacketAllocator (), numberNodesPerContainer);
399+ MockTimestampPacketContainer timestamp1 (*csr.getTimestampPacketAllocator (), numberNodesPerContainer);
400+ csrDependencies.push_back (×tamp0);
401+ csrDependencies.push_back (×tamp1);
402+
403+ csr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies);
404+
405+ HardwareParse hwParser;
406+ hwParser.parseCommands <FamilyType>(csr.commandStream );
407+ auto &cmdList = hwParser.cmdList ;
408+ bool xyCopyBltCmdFound = false ;
409+ bool dependenciesFound = false ;
410+
411+ for (auto cmdIterator = cmdList.begin (); cmdIterator != cmdList.end (); cmdIterator++) {
412+ if (genCmdCast<typename FamilyType::XY_COPY_BLT *>(*cmdIterator)) {
413+ xyCopyBltCmdFound = true ;
414+ continue ;
415+ }
416+ auto miSemaphore = genCmdCast<typename FamilyType::MI_SEMAPHORE_WAIT *>(*cmdIterator);
417+ if (miSemaphore) {
418+ dependenciesFound = true ;
419+ EXPECT_FALSE (xyCopyBltCmdFound);
420+ auto miAtomic = genCmdCast<typename FamilyType::MI_ATOMIC *>(*(++cmdIterator));
421+ EXPECT_NE (nullptr , miAtomic);
422+
423+ for (uint32_t i = 1 ; i < numberOfDependencyContainers * numberNodesPerContainer; i++) {
424+ EXPECT_NE (nullptr , genCmdCast<typename FamilyType::MI_SEMAPHORE_WAIT *>(*(++cmdIterator)));
425+ EXPECT_NE (nullptr , genCmdCast<typename FamilyType::MI_ATOMIC *>(*(++cmdIterator)));
426+ }
427+ }
428+ }
429+ EXPECT_TRUE (xyCopyBltCmdFound);
430+ EXPECT_TRUE (dependenciesFound);
431+ }
432+
366433HWTEST_F (BcsTests, givenInputAllocationsWhenBlitDispatchedThenMakeAllAllocationsResident) {
367434 auto &csr = pDevice->getUltCommandStreamReceiver <FamilyType>();
368435 csr.storeMakeResidentAllocations = true ;
@@ -373,7 +440,7 @@ HWTEST_F(BcsTests, givenInputAllocationsWhenBlitDispatchedThenMakeAllAllocations
373440
374441 EXPECT_EQ (0u , csr.makeSurfacePackNonResidentCalled );
375442
376- csr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr);
443+ csr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies );
377444
378445 EXPECT_TRUE (csr.isMadeResident (buffer->getGraphicsAllocation ()));
379446 EXPECT_TRUE (csr.isMadeResident (csr.commandStream .getGraphicsAllocation ()));
@@ -397,7 +464,7 @@ HWTEST_F(BcsTests, givenBufferWhenBlitCalledThenFlushCommandBuffer) {
397464
398465 uint32_t newTaskCount = 17 ;
399466 csr.taskCount = newTaskCount - 1 ;
400- csr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr);
467+ csr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies );
401468
402469 EXPECT_EQ (commandStream.getGraphicsAllocation (), csr.latestFlushedBatchBuffer .commandBufferAllocation );
403470 EXPECT_EQ (commandStreamOffset, csr.latestFlushedBatchBuffer .startOffset );
@@ -442,7 +509,7 @@ HWTEST_F(BcsTests, whenBlitFromHostPtrCalledThenCallWaitWithKmdFallback) {
442509 auto buffer = clUniquePtr<Buffer>(Buffer::create (context.get (), CL_MEM_READ_WRITE, 1 , nullptr , retVal));
443510 void *hostPtr = reinterpret_cast <void *>(0x12340000 );
444511
445- myMockCsr->blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr);
512+ myMockCsr->blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies );
446513
447514 EXPECT_EQ (1u , myMockCsr->waitForTaskCountWithKmdNotifyFallbackCalled );
448515 EXPECT_EQ (myMockCsr->taskCount , myMockCsr->taskCountToWaitPassed );
@@ -464,13 +531,13 @@ HWTEST_F(BcsTests, whenBlitFromHostPtrCalledThenCleanTemporaryAllocations) {
464531 bcsCsr.taskCount = newTaskCount - 1 ;
465532
466533 EXPECT_EQ (0u , mockInternalAllocationsStorage->cleanAllocationsCalled );
467- bcsCsr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr);
534+ bcsCsr.blitWithHostPtr (*buffer, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies );
468535 EXPECT_EQ (1u , mockInternalAllocationsStorage->cleanAllocationsCalled );
469536 EXPECT_EQ (newTaskCount, mockInternalAllocationsStorage->lastCleanAllocationsTaskCount );
470537 EXPECT_TRUE (TEMPORARY_ALLOCATION == mockInternalAllocationsStorage->lastCleanAllocationUsage );
471538}
472539
473- HWTEST_F (BcsTests, givenHostPtrWhenBlitWithHostPtrCalledThenProgramCorrectGpuAddresses ) {
540+ HWTEST_F (BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddresses ) {
474541 auto &csr = pDevice->getUltCommandStreamReceiver <FamilyType>();
475542
476543 cl_int retVal = CL_SUCCESS;
@@ -481,7 +548,7 @@ HWTEST_F(BcsTests, givenHostPtrWhenBlitWithHostPtrCalledThenProgramCorrectGpuAdd
481548 {
482549 // from hostPtr
483550 HardwareParse hwParser;
484- csr.blitWithHostPtr (*buffer1, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr);
551+ csr.blitWithHostPtr (*buffer1, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::FromHostPtr, csrDependencies );
485552
486553 hwParser.parseCommands <FamilyType>(csr.commandStream );
487554
@@ -494,7 +561,7 @@ HWTEST_F(BcsTests, givenHostPtrWhenBlitWithHostPtrCalledThenProgramCorrectGpuAdd
494561 // to hostPtr
495562 HardwareParse hwParser;
496563 auto offset = csr.commandStream .getUsed ();
497- csr.blitWithHostPtr (*buffer1, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::ToHostPtr);
564+ csr.blitWithHostPtr (*buffer1, hostPtr, 1 , BlitterConstants::BlitWithHostPtrDirection::ToHostPtr, csrDependencies );
498565
499566 hwParser.parseCommands <FamilyType>(csr.commandStream , offset);
500567
@@ -507,7 +574,7 @@ HWTEST_F(BcsTests, givenHostPtrWhenBlitWithHostPtrCalledThenProgramCorrectGpuAdd
507574 // Buffer to Buffer
508575 HardwareParse hwParser;
509576 auto offset = csr.commandStream .getUsed ();
510- csr.blitBuffer (*buffer1, *buffer2, 1 );
577+ csr.blitBuffer (*buffer1, *buffer2, 1 , csrDependencies );
511578
512579 hwParser.parseCommands <FamilyType>(csr.commandStream , offset);
513580
0 commit comments