From 81a1e435f92ffb0edc83eb3d8d38a0d4a0e6bcf0 Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Tue, 11 Sep 2018 16:14:07 +0200 Subject: [PATCH] Delegate all MemoryManager::pushAllocationForResidency() calls through CSR This prepares for moving this method from MemoryManager to CSR. Change-Id: I82393289c48990f26ed3ac922bcd64e2b6c11f28 Signed-off-by: Maciej Dziuban --- .../command_stream_receiver.cpp | 6 +- .../command_stream/command_stream_receiver.h | 1 + .../tbx_command_stream_tests.cpp | 5 +- .../windows/wddm_memory_manager_tests.cpp | 77 ++++++------------- 4 files changed, 30 insertions(+), 59 deletions(-) diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 0f177d973b..4b547e4537 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -68,7 +68,7 @@ CommandStreamReceiver::~CommandStreamReceiver() { void CommandStreamReceiver::makeResident(GraphicsAllocation &gfxAllocation) { auto submissionTaskCount = this->taskCount + 1; if (gfxAllocation.residencyTaskCount < (int)submissionTaskCount) { - getMemoryManager()->pushAllocationForResidency(&gfxAllocation); + this->pushAllocationForResidency(&gfxAllocation); gfxAllocation.taskCount = submissionTaskCount; if (gfxAllocation.residencyTaskCount == ObjectNotResident) { this->totalMemoryUsed += gfxAllocation.getUnderlyingBufferSize(); @@ -268,6 +268,10 @@ ResidencyContainer &CommandStreamReceiver::getResidencyAllocations() { return this->memoryManager->getResidencyAllocations(); } +void CommandStreamReceiver::pushAllocationForResidency(GraphicsAllocation *gfxAllocation) { + this->memoryManager->pushAllocationForResidency(gfxAllocation); +} + void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) {} GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 53c73bb62c..69b02066ac 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -90,6 +90,7 @@ class CommandStreamReceiver { void setMemoryManager(MemoryManager *mm); ResidencyContainer &getResidencyAllocations(); + void pushAllocationForResidency(GraphicsAllocation *gfxAllocation); virtual GmmPageTableMngr *createPageTableManager() { return nullptr; } diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 5405a11e26..d352072ca7 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -235,7 +235,6 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenWriteMemoryIsCa HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidencyIsCalledWithoutAllocationsForResidencyThenItShouldProcessAllocationsFromMemoryManager) { TbxCommandStreamReceiverHw *tbxCsr = (TbxCommandStreamReceiverHw *)pCommandStreamReceiver; TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager(); - ResidencyContainer &allocationsForResidency = memoryManager->getResidencyAllocations(); ASSERT_NE(nullptr, memoryManager); auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096); @@ -243,8 +242,8 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidenc EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount); - memoryManager->pushAllocationForResidency(graphicsAllocation); - tbxCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext()); + tbxCsr->pushAllocationForResidency(graphicsAllocation); + tbxCsr->processResidency(&tbxCsr->getResidencyAllocations(), *pDevice->getOsContext()); EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount); EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index 4ee001c109..e18325dbe4 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1042,13 +1042,9 @@ TEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListWithNonNullEntrie TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllocationsResident) { MockWddmAllocation allocation1, allocation2, allocation3, allocation4; + ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(&allocation2); - memoryManager->pushAllocationForResidency(&allocation3); - memoryManager->pushAllocationForResidency(&allocation4); - - memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_TRUE(allocation1.getResidencyData().resident); EXPECT_TRUE(allocation2.getResidencyData().resident); @@ -1058,15 +1054,11 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllo TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdatesLastFence) { MockWddmAllocation allocation1, allocation2, allocation3, allocation4; - - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(&allocation2); - memoryManager->pushAllocationForResidency(&allocation3); - memoryManager->pushAllocationForResidency(&allocation4); + ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; osContext->get()->getMonitoredFence().currentFenceValue = 20; - memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_EQ(20u, allocation1.getResidencyData().getFenceValueForContextId(osContext->getContextId())); EXPECT_EQ(20u, allocation2.getResidencyData().getFenceValueForContextId(osContext->getContextId())); @@ -1079,12 +1071,9 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTrip void *ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1500); WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); + ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(allocationTriple); - memoryManager->pushAllocationForResidency(&allocation2); - - memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident); @@ -1102,11 +1091,8 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLastF osContext->get()->getMonitoredFence().currentFenceValue = 20; - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(allocationTriple); - memoryManager->pushAllocationForResidency(&allocation2); - - memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; + memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->getFenceValueForContextId(0)); @@ -1732,12 +1718,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAlloca ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2); - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(&allocation2); - memoryManager->pushAllocationForResidency(&allocation3); - memoryManager->pushAllocationForResidency(&allocation4); - - bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_FALSE(result); @@ -1758,11 +1740,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTriple ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2); - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(allocationTriple); - memoryManager->pushAllocationForResidency(&allocation2); - - bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2}; + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_FALSE(result); @@ -1781,12 +1760,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeResi ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2); - memoryManager->pushAllocationForResidency(&allocation1); - memoryManager->pushAllocationForResidency(&allocation2); - memoryManager->pushAllocationForResidency(&allocation3); - memoryManager->pushAllocationForResidency(&allocation4); - - bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4}; + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_FALSE(result); @@ -1805,24 +1780,18 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsCallsMakeResident EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, false, ::testing::_)).Times(1); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, true, ::testing::_)).Times(1); - memoryManager->pushAllocationForResidency(&allocation1); - - bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + ResidencyContainer residencyPack{&allocation1}; + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_FALSE(result); } -TEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResidentThenTheyAreUsedInsteadOfMemoryManagerMembers) { +TEST_F(WddmMemoryManagerTest2, givenAllocationPackPassedWhenCallingMakeResidentResidencyAllocationsThenItIsUsed) { MockWddmAllocation allocation1; MockWddmAllocation allocation2; - MockWddmAllocation allocation3; allocation1.handle = 1; allocation2.handle = 2; - allocation3.handle = 3; - - ResidencyContainer residencyPack; - residencyPack.push_back(&allocation1); - residencyPack.push_back(&allocation2); + ResidencyContainer residencyPack{&allocation1, &allocation2}; auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { EXPECT_EQ(1, handles[0]); @@ -1832,7 +1801,6 @@ TEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResiden ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, 2, false, ::testing::_)).Times(1); - memoryManager->pushAllocationForResidency(&allocation3); bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_TRUE(result); } @@ -1851,9 +1819,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR memoryManager->addToTrimCandidateList(&allocationToTrim); - memoryManager->pushAllocationForResidency(&allocation1); - - bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + ResidencyContainer residencyPack{&allocation1}; + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_TRUE(result); @@ -1862,14 +1829,14 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR TEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemoryBudgetExhaustedIsReturnedAsTrue) { MockWddmAllocation allocation1; + ResidencyContainer residencyPack{&allocation1}; auto makeResidentThatFails = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { return false; }; auto makeResidentThatSucceds = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { return true; }; EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(makeResidentThatFails)).WillOnce(::testing::Invoke(makeResidentThatSucceds)); - memoryManager->pushAllocationForResidency(&allocation1); - bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext); + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext); EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted()); }