@@ -608,3 +608,43 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenDestructionThenNonHeapAllo
608608 cmdContainer.reset ();
609609 EXPECT_EQ (alloc.getUnderlyingBufferSize (), size);
610610}
611+
612+ TEST_F (CommandContainerTest, givenContainerAllocatesNextCommandBufferWhenResetingContainerThenExpectFirstCommandBufferAllocationIsReused) {
613+ auto cmdContainer = std::make_unique<CommandContainer>();
614+ cmdContainer->initialize (pDevice);
615+
616+ auto stream = cmdContainer->getCommandStream ();
617+ ASSERT_NE (nullptr , stream);
618+ auto firstCmdBufferAllocation = stream->getGraphicsAllocation ();
619+ ASSERT_NE (nullptr , firstCmdBufferAllocation);
620+ auto firstCmdBufferCpuPointer = stream->getSpace (0 );
621+ EXPECT_EQ (firstCmdBufferCpuPointer, firstCmdBufferAllocation->getUnderlyingBuffer ());
622+
623+ cmdContainer->allocateNextCommandBuffer ();
624+ auto secondCmdBufferAllocation = stream->getGraphicsAllocation ();
625+ ASSERT_NE (nullptr , secondCmdBufferAllocation);
626+ EXPECT_NE (firstCmdBufferAllocation, secondCmdBufferAllocation);
627+ auto secondCmdBufferCpuPointer = stream->getSpace (0 );
628+ EXPECT_EQ (secondCmdBufferCpuPointer, secondCmdBufferAllocation->getUnderlyingBuffer ());
629+ EXPECT_NE (firstCmdBufferCpuPointer, secondCmdBufferCpuPointer);
630+
631+ cmdContainer->reset ();
632+
633+ auto aferResetCmdBufferAllocation = stream->getGraphicsAllocation ();
634+ ASSERT_NE (nullptr , aferResetCmdBufferAllocation);
635+ auto afterResetCmdBufferCpuPointer = stream->getSpace (0 );
636+ EXPECT_EQ (afterResetCmdBufferCpuPointer, aferResetCmdBufferAllocation->getUnderlyingBuffer ());
637+
638+ EXPECT_EQ (firstCmdBufferAllocation, aferResetCmdBufferAllocation);
639+ EXPECT_EQ (firstCmdBufferCpuPointer, afterResetCmdBufferCpuPointer);
640+
641+ bool firstAllocationFound = false ;
642+ auto &residencyContainer = cmdContainer->getResidencyContainer ();
643+ for (auto *allocation : residencyContainer) {
644+ if (allocation == firstCmdBufferAllocation) {
645+ firstAllocationFound = true ;
646+ break ;
647+ }
648+ }
649+ EXPECT_TRUE (firstAllocationFound);
650+ }
0 commit comments