diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index bae5109a97..14f7a352ef 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -188,12 +188,10 @@ FlushStamp TbxCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer DEBUG_BREAK_IF(currentOffset < batchBuffer.startOffset); auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset; - if (this->dispatchMode == DispatchMode::ImmediateDispatch) { - CommandStreamReceiver::makeResident(*batchBuffer.commandBufferAllocation); - } else { - allocationsForResidency.push_back(batchBuffer.commandBufferAllocation); - batchBuffer.commandBufferAllocation->updateResidencyTaskCount(this->taskCount, this->osContext->getContextId()); - } + auto submissionTaskCount = this->taskCount + 1; + allocationsForResidency.push_back(batchBuffer.commandBufferAllocation); + batchBuffer.commandBufferAllocation->updateResidencyTaskCount(submissionTaskCount, this->osContext->getContextId()); + batchBuffer.commandBufferAllocation->updateTaskCount(submissionTaskCount, osContext->getContextId()); // Write allocations for residency processResidency(allocationsForResidency); diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index d720d39708..72552dce29 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -311,6 +311,32 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh memoryManager->freeGraphicsMemory(graphicsAllocation); } +HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledThenItMakesCommandBufferAllocationsProperlyResident) { + TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; + TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); + ASSERT_NE(nullptr, memoryManager); + + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + ASSERT_NE(nullptr, commandBuffer); + + LinearStream cs(commandBuffer); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + ResidencyContainer allocationsForResidency = {}; + + EXPECT_FALSE(commandBuffer->isResident(tbxCsr->getOsContext().getContextId())); + + tbxCsr->flush(batchBuffer, allocationsForResidency); + + EXPECT_TRUE(commandBuffer->isResident(tbxCsr->getOsContext().getContextId())); + EXPECT_EQ(tbxCsr->peekTaskCount() + 1, commandBuffer->getTaskCount(tbxCsr->getOsContext().getContextId())); + EXPECT_EQ(tbxCsr->peekTaskCount() + 1, commandBuffer->getResidencyTaskCount(tbxCsr->getOsContext().getContextId())); + ASSERT_EQ(1u, allocationsForResidency.size()); + EXPECT_EQ(commandBuffer, allocationsForResidency[0]); + + memoryManager->freeGraphicsMemory(commandBuffer); +} + TEST(TbxMemoryManagerTest, givenTbxMemoryManagerWhenItIsQueriedForSystemSharedMemoryThen1GBIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); TbxMemoryManager memoryManager(executionEnvironment);