@@ -1421,7 +1421,7 @@ struct MockHeapHelper : public HeapHelper {
14211421 using HeapHelper::storageForReuse;
14221422};
14231423
1424- TEST_F (CommandContainerTest, givenCmdContainerWhenFillReusableAllocationListsThenAllocListsNotEmptyAndHeapAllocsCreated ) {
1424+ TEST_F (CommandContainerTest, givenCmdContainerWhenFillReusableAllocationListsThenAllocListsNotEmptyAndMadeResident ) {
14251425 DebugManagerStateRestore dbgRestore;
14261426 debugManager.flags .SetAmountOfReusableAllocations .set (1 );
14271427 auto cmdContainer = std::make_unique<MyMockCommandContainer>();
@@ -1449,14 +1449,14 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenFillReusableAllocationListsThe
14491449 numHeaps++;
14501450 }
14511451 }
1452- auto numAllocsAddedToResidencyContainer = amountToFill * numHeaps;
1452+ auto numAllocsAddedToResidencyContainer = amountToFill + (amountToFill * numHeaps) ;
14531453 EXPECT_EQ (cmdContainer->getResidencyContainer ().size (), actualResidencyContainerSize + numAllocsAddedToResidencyContainer);
14541454
14551455 cmdContainer.reset ();
14561456 allocList.freeAllGraphicsAllocations (pDevice);
14571457}
14581458
1459- TEST_F (CommandContainerTest, givenCreateSecondaryCmdBufferInHostMemWhenFillReusableAllocationListsThenHeapAllocsCreated ) {
1459+ TEST_F (CommandContainerTest, givenCreateSecondaryCmdBufferInHostMemWhenFillReusableAllocationListsThenCreateAlocsForSecondaryCmdBuffer ) {
14601460 DebugManagerStateRestore dbgRestore;
14611461 debugManager.flags .SetAmountOfReusableAllocations .set (1 );
14621462 auto cmdContainer = std::make_unique<MyMockCommandContainer>();
@@ -1481,149 +1481,13 @@ TEST_F(CommandContainerTest, givenCreateSecondaryCmdBufferInHostMemWhenFillReusa
14811481 numHeaps++;
14821482 }
14831483 }
1484- auto numAllocsAddedToResidencyContainer = amountToFill * numHeaps;
1484+ auto numAllocsAddedToResidencyContainer = 2 * amountToFill + (amountToFill * numHeaps) ;
14851485 EXPECT_EQ (cmdContainer->getResidencyContainer ().size (), actualResidencyContainerSize + numAllocsAddedToResidencyContainer);
14861486
14871487 cmdContainer.reset ();
14881488 allocList.freeAllGraphicsAllocations (pDevice);
14891489}
14901490
1491- TEST_F (CommandContainerTest, givenUnusedCommandBufferInReusableListWhenDetachingAllocationThenBufferIsSuccessfullyReused) {
1492- auto cmdContainer = std::make_unique<MyMockCommandContainer>();
1493- auto csr = pDevice->getDefaultEngine ().commandStreamReceiver ;
1494-
1495- AllocationsList allocList;
1496- cmdContainer->initialize (pDevice, &allocList, HeapSize::getDefaultHeapSize (IndirectHeapType::surfaceState), true , false );
1497- cmdContainer->setImmediateCmdListCsr (csr);
1498-
1499- // Create a command buffer allocation that has never been used
1500- auto unusedCmdBuffer = cmdContainer->allocateCommandBuffer (false );
1501- ASSERT_NE (unusedCmdBuffer, nullptr );
1502-
1503- // Verify it's not used by the OS context
1504- EXPECT_FALSE (unusedCmdBuffer->isUsedByOsContext (csr->getOsContext ().getContextId ()));
1505-
1506- // Add it to the reusable list (shared list) without using it
1507- allocList.pushTailOne (*unusedCmdBuffer);
1508-
1509- // Try to detach an allocation from the reusable list
1510- auto alignedSize = cmdContainer->getAlignedCmdBufferSize ();
1511- auto detachedAllocation = allocList.detachAllocation (
1512- alignedSize, nullptr , false , csr, AllocationType::commandBuffer);
1513-
1514- // Verify the unused buffer was successfully detached and reused
1515- EXPECT_NE (detachedAllocation, nullptr );
1516- EXPECT_EQ (detachedAllocation.get (), unusedCmdBuffer);
1517-
1518- // Clean up
1519- pDevice->getMemoryManager ()->freeGraphicsMemory (detachedAllocation.release ());
1520- cmdContainer.reset ();
1521- allocList.freeAllGraphicsAllocations (pDevice);
1522- }
1523-
1524- TEST_F (CommandContainerTest, givenEmptyImmediateListWhenReuseExistingCmdBufferThenFallbackToReusableList) {
1525- DebugManagerStateRestore dbgRestore;
1526- debugManager.flags .SetAmountOfReusableAllocations .set (1 );
1527- auto cmdContainer = std::make_unique<MyMockCommandContainer>();
1528- auto csr = pDevice->getDefaultEngine ().commandStreamReceiver ;
1529-
1530- AllocationsList allocList;
1531- cmdContainer->initialize (pDevice, &allocList, HeapSize::getDefaultHeapSize (IndirectHeapType::surfaceState), true , false );
1532- cmdContainer->setImmediateCmdListCsr (csr);
1533-
1534- // Initialize immediate reusable list (but keep it empty)
1535- cmdContainer->fillReusableAllocationLists ();
1536- ASSERT_NE (cmdContainer->immediateReusableAllocationList , nullptr );
1537-
1538- // Clear the immediate list to make it empty
1539- while (!cmdContainer->immediateReusableAllocationList ->peekIsEmpty ()) {
1540- auto alloc = cmdContainer->immediateReusableAllocationList ->detachAllocation (
1541- 0 , nullptr , false , csr, AllocationType::commandBuffer);
1542- if (alloc) {
1543- pDevice->getMemoryManager ()->freeGraphicsMemory (alloc.release ());
1544- } else {
1545- break ;
1546- }
1547- }
1548-
1549- // Ensure immediate reusable list is now empty
1550- EXPECT_TRUE (cmdContainer->immediateReusableAllocationList ->peekIsEmpty ());
1551-
1552- // Create a command buffer and add it to the fallback reusable list
1553- auto cmdBuffer = cmdContainer->allocateCommandBuffer (false );
1554- ASSERT_NE (cmdBuffer, nullptr );
1555- allocList.pushTailOne (*cmdBuffer);
1556-
1557- // Verify the fallback list has the allocation
1558- EXPECT_FALSE (allocList.peekIsEmpty ());
1559-
1560- // Call reuseExistingCmdBuffer - should fall back to reusableAllocationList
1561- auto reusedBuffer = cmdContainer->reuseExistingCmdBuffer ();
1562-
1563- // Verify the buffer was successfully retrieved from fallback list
1564- EXPECT_NE (reusedBuffer, nullptr );
1565- EXPECT_EQ (reusedBuffer, cmdBuffer);
1566-
1567- // Verify it was removed from the fallback list
1568- EXPECT_TRUE (allocList.peekIsEmpty ());
1569-
1570- // Clean up
1571- cmdContainer.reset ();
1572- allocList.freeAllGraphicsAllocations (pDevice);
1573- }
1574-
1575- TEST_F (CommandContainerTest, givenFillReusableAllocationListsWhenCommandBufferNotUsedThenNotAddedToResidencyUntilSetCmdBuffer) {
1576- DebugManagerStateRestore dbgRestore;
1577- debugManager.flags .SetAmountOfReusableAllocations .set (1 );
1578- auto cmdContainer = std::make_unique<MyMockCommandContainer>();
1579- auto csr = pDevice->getDefaultEngine ().commandStreamReceiver ;
1580-
1581- AllocationsList allocList;
1582- cmdContainer->initialize (pDevice, &allocList, HeapSize::getDefaultHeapSize (IndirectHeapType::surfaceState), true , false );
1583- cmdContainer->setImmediateCmdListCsr (csr);
1584-
1585- // Get initial residency container size
1586- auto initialResidencySize = cmdContainer->getResidencyContainer ().size ();
1587-
1588- // Fill reusable allocation lists
1589- cmdContainer->fillReusableAllocationLists ();
1590-
1591- // Calculate expected residency increase (only heap allocations, not command buffers)
1592- auto &gfxCoreHelper = pDevice->getGfxCoreHelper ();
1593- auto amountToFill = gfxCoreHelper.getAmountOfAllocationsToFill ();
1594- uint32_t numHeaps = 0 ;
1595- for (int heapType = 0 ; heapType < IndirectHeap::Type::numTypes; heapType++) {
1596- if (!cmdContainer->skipHeapAllocationCreation (static_cast <HeapType>(heapType))) {
1597- numHeaps++;
1598- }
1599- }
1600- auto expectedHeapAllocations = amountToFill * numHeaps;
1601-
1602- // Verify command buffers were NOT added to residency (only heap allocations)
1603- EXPECT_EQ (cmdContainer->getResidencyContainer ().size (), initialResidencySize + expectedHeapAllocations);
1604-
1605- // Verify command buffers are in the immediate reusable list
1606- ASSERT_NE (cmdContainer->immediateReusableAllocationList , nullptr );
1607- EXPECT_FALSE (cmdContainer->immediateReusableAllocationList ->peekIsEmpty ());
1608-
1609- // Get a command buffer from the reusable list
1610- auto reusedBuffer = cmdContainer->reuseExistingCmdBuffer ();
1611- ASSERT_NE (reusedBuffer, nullptr );
1612-
1613- // Record residency size after reuse but before setCmdBuffer
1614- auto residencySizeBeforeSet = cmdContainer->getResidencyContainer ().size ();
1615-
1616- // Now set the command buffer - this should add it to residency
1617- cmdContainer->setCmdBuffer (reusedBuffer);
1618-
1619- // Verify residency increased by 1 (the command buffer)
1620- EXPECT_EQ (cmdContainer->getResidencyContainer ().size (), residencySizeBeforeSet + 1 );
1621-
1622- // Clean up
1623- cmdContainer.reset ();
1624- allocList.freeAllGraphicsAllocations (pDevice);
1625- }
1626-
16271491TEST_F (CommandContainerTest, givenSecondCmdContainerCreatedAfterFirstCmdContainerDestroyedAndReusableAllocationsListUsedThenCommandBuffersAllocationsAreReused) {
16281492 auto cmdContainer = std::make_unique<MyMockCommandContainer>();
16291493
0 commit comments