diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp index 9adae10c37..81340363a3 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp @@ -1128,7 +1128,7 @@ TEST_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceForIm auto result = commandList->appendMemoryCopy(dstPtr, srcPtr, 8, nullptr, 0, nullptr); ASSERT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(2U, commandList->commandContainer.getCmdBufferAllocations().size()); + EXPECT_EQ(1U, commandList->commandContainer.getCmdBufferAllocations().size()); } HWTEST2_F(CommandListCreate, GivenGpuHangOnSynchronizingWhenCreatingImmediateCommandListAndWaitingOnEventsThenDeviceLostIsReturned, IsSKL) { diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp index 0ed3c06130..a47ceaba72 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp @@ -1780,12 +1780,12 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceFo commandList->commandContainer.getCommandStream()->getGraphicsAllocation()->updateTaskCount(0u, 0u); commandList->commandContainer.getCommandStream()->getSpace(useSize); reinterpret_cast *>(commandList.get())->checkAvailableSpace(); - EXPECT_EQ(2U, commandList->commandContainer.getCmdBufferAllocations().size()); + EXPECT_EQ(1U, commandList->commandContainer.getCmdBufferAllocations().size()); commandList->commandContainer.getCommandStream()->getSpace(useSize); auto latestFlushedTaskCount = commandList->csr->peekLatestFlushedTaskCount(); reinterpret_cast *>(commandList.get())->checkAvailableSpace(); - EXPECT_EQ(2U, commandList->commandContainer.getCmdBufferAllocations().size()); + EXPECT_EQ(1U, commandList->commandContainer.getCmdBufferAllocations().size()); EXPECT_EQ(latestFlushedTaskCount + 1, commandList->csr->peekLatestFlushedTaskCount()); } diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index fbcce3065e..c6ce1804b5 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -333,10 +333,14 @@ void CommandContainer::ensureHeapSizePrepared(size_t sshRequiredSize, size_t dsh GraphicsAllocation *CommandContainer::reuseExistingCmdBuffer() { size_t alignedSize = alignUp(this->getTotalCmdBufferSize(), MemoryConstants::pageSize64k); auto cmdBufferAllocation = this->reusableAllocationList->detachAllocation(alignedSize, nullptr, this->immediateCmdListCsr, AllocationType::COMMAND_BUFFER).release(); + if (cmdBufferAllocation) { + this->cmdBufferAllocations.push_back(cmdBufferAllocation); + } return cmdBufferAllocation; } void CommandContainer::addCurrentCommandBufferToReusableAllocationList() { + this->cmdBufferAllocations.erase(std::find(this->cmdBufferAllocations.begin(), this->cmdBufferAllocations.end(), this->commandStream->getGraphicsAllocation())); this->storeAllocationAndFlushTagUpdate(this->commandStream->getGraphicsAllocation()); } diff --git a/shared/test/unit_test/command_container/command_container_tests.cpp b/shared/test/unit_test/command_container/command_container_tests.cpp index f8fd5fb15f..180343e0b0 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -879,6 +879,20 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithoutA allocList.freeAllGraphicsAllocations(pDevice); } +TEST_F(CommandContainerTest, givenCmdContainerWhenDestroyCommandContainerThenAllocationListFilledCorrectly) { + auto cmdContainer = std::make_unique(); + AllocationsList allocList; + cmdContainer->initialize(pDevice, &allocList, false); + auto alloc = cmdContainer->getCmdBufferAllocations()[0]; + allocList.pushFrontOne(*alloc); + cmdContainer.reset(); + + EXPECT_TRUE(allocList.peekContains(*alloc)); + EXPECT_EQ(allocList.peekHead()->countThisAndAllConnected(), 1u); + + allocList.freeAllGraphicsAllocations(pDevice); +} + HWTEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithAllocationInListAndCsrTaskCountLowerThanAllocationThenReturnNullptr) { auto cmdContainer = std::make_unique(); auto &csr = pDevice->getUltCommandStreamReceiver(); @@ -888,7 +902,9 @@ HWTEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithAl cmdContainer->initialize(pDevice, &allocList, false); cmdContainer->setImmediateCmdListCsr(&csr); cmdContainer->getCmdBufferAllocations()[0]->updateTaskCount(10, 0); + auto currectContainerSize = cmdContainer->getCmdBufferAllocations().size(); cmdContainer->addCurrentCommandBufferToReusableAllocationList(); + EXPECT_EQ(cmdContainer->getCmdBufferAllocations().size(), currectContainerSize - 1); EXPECT_EQ(cmdContainer->reuseExistingCmdBuffer(), nullptr); @@ -908,7 +924,9 @@ HWTEST_F(CommandContainerTest, givenCmdContainerWhenReuseExistingCmdBufferWithAl cmdContainer->getCmdBufferAllocations()[0]->updateTaskCount(10, 0); cmdContainer->addCurrentCommandBufferToReusableAllocationList(); + auto currectContainerSize = cmdContainer->getCmdBufferAllocations().size(); EXPECT_NE(cmdContainer->reuseExistingCmdBuffer(), nullptr); + EXPECT_EQ(cmdContainer->getCmdBufferAllocations().size(), currectContainerSize + 1); cmdContainer.reset(); allocList.freeAllGraphicsAllocations(pDevice);