Skip to content

Commit 81a1e43

Browse files
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 <maciej.dziuban@intel.com>
1 parent a416b0a commit 81a1e43

File tree

4 files changed

+30
-59
lines changed

4 files changed

+30
-59
lines changed

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ CommandStreamReceiver::~CommandStreamReceiver() {
6868
void CommandStreamReceiver::makeResident(GraphicsAllocation &gfxAllocation) {
6969
auto submissionTaskCount = this->taskCount + 1;
7070
if (gfxAllocation.residencyTaskCount < (int)submissionTaskCount) {
71-
getMemoryManager()->pushAllocationForResidency(&gfxAllocation);
71+
this->pushAllocationForResidency(&gfxAllocation);
7272
gfxAllocation.taskCount = submissionTaskCount;
7373
if (gfxAllocation.residencyTaskCount == ObjectNotResident) {
7474
this->totalMemoryUsed += gfxAllocation.getUnderlyingBufferSize();
@@ -268,6 +268,10 @@ ResidencyContainer &CommandStreamReceiver::getResidencyAllocations() {
268268
return this->memoryManager->getResidencyAllocations();
269269
}
270270

271+
void CommandStreamReceiver::pushAllocationForResidency(GraphicsAllocation *gfxAllocation) {
272+
this->memoryManager->pushAllocationForResidency(gfxAllocation);
273+
}
274+
271275
void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) {}
272276

273277
GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) {

runtime/command_stream/command_stream_receiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class CommandStreamReceiver {
9090
void setMemoryManager(MemoryManager *mm);
9191

9292
ResidencyContainer &getResidencyAllocations();
93+
void pushAllocationForResidency(GraphicsAllocation *gfxAllocation);
9394

9495
virtual GmmPageTableMngr *createPageTableManager() { return nullptr; }
9596

unit_tests/command_stream/tbx_command_stream_tests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,15 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenWriteMemoryIsCa
235235
HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenProcessResidencyIsCalledWithoutAllocationsForResidencyThenItShouldProcessAllocationsFromMemoryManager) {
236236
TbxCommandStreamReceiverHw<FamilyType> *tbxCsr = (TbxCommandStreamReceiverHw<FamilyType> *)pCommandStreamReceiver;
237237
TbxMemoryManager *memoryManager = tbxCsr->getMemoryManager();
238-
ResidencyContainer &allocationsForResidency = memoryManager->getResidencyAllocations();
239238
ASSERT_NE(nullptr, memoryManager);
240239

241240
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096);
242241
ASSERT_NE(nullptr, graphicsAllocation);
243242

244243
EXPECT_EQ(ObjectNotResident, graphicsAllocation->residencyTaskCount);
245244

246-
memoryManager->pushAllocationForResidency(graphicsAllocation);
247-
tbxCsr->processResidency(&allocationsForResidency, *pDevice->getOsContext());
245+
tbxCsr->pushAllocationForResidency(graphicsAllocation);
246+
tbxCsr->processResidency(&tbxCsr->getResidencyAllocations(), *pDevice->getOsContext());
248247

249248
EXPECT_NE(ObjectNotResident, graphicsAllocation->residencyTaskCount);
250249
EXPECT_EQ((int)tbxCsr->peekTaskCount() + 1, graphicsAllocation->residencyTaskCount);

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,9 @@ TEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListWithNonNullEntrie
10421042

10431043
TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllocationsResident) {
10441044
MockWddmAllocation allocation1, allocation2, allocation3, allocation4;
1045+
ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4};
10451046

1046-
memoryManager->pushAllocationForResidency(&allocation1);
1047-
memoryManager->pushAllocationForResidency(&allocation2);
1048-
memoryManager->pushAllocationForResidency(&allocation3);
1049-
memoryManager->pushAllocationForResidency(&allocation4);
1050-
1051-
memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1047+
memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
10521048

10531049
EXPECT_TRUE(allocation1.getResidencyData().resident);
10541050
EXPECT_TRUE(allocation2.getResidencyData().resident);
@@ -1058,15 +1054,11 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllo
10581054

10591055
TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdatesLastFence) {
10601056
MockWddmAllocation allocation1, allocation2, allocation3, allocation4;
1061-
1062-
memoryManager->pushAllocationForResidency(&allocation1);
1063-
memoryManager->pushAllocationForResidency(&allocation2);
1064-
memoryManager->pushAllocationForResidency(&allocation3);
1065-
memoryManager->pushAllocationForResidency(&allocation4);
1057+
ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4};
10661058

10671059
osContext->get()->getMonitoredFence().currentFenceValue = 20;
10681060

1069-
memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1061+
memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
10701062

10711063
EXPECT_EQ(20u, allocation1.getResidencyData().getFenceValueForContextId(osContext->getContextId()));
10721064
EXPECT_EQ(20u, allocation2.getResidencyData().getFenceValueForContextId(osContext->getContextId()));
@@ -1079,12 +1071,9 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTrip
10791071
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
10801072

10811073
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr);
1074+
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
10821075

1083-
memoryManager->pushAllocationForResidency(&allocation1);
1084-
memoryManager->pushAllocationForResidency(allocationTriple);
1085-
memoryManager->pushAllocationForResidency(&allocation2);
1086-
1087-
memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1076+
memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
10881077

10891078
for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) {
10901079
EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident);
@@ -1102,11 +1091,8 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLastF
11021091

11031092
osContext->get()->getMonitoredFence().currentFenceValue = 20;
11041093

1105-
memoryManager->pushAllocationForResidency(&allocation1);
1106-
memoryManager->pushAllocationForResidency(allocationTriple);
1107-
memoryManager->pushAllocationForResidency(&allocation2);
1108-
1109-
memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1094+
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
1095+
memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
11101096

11111097
for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) {
11121098
EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->getFenceValueForContextId(0));
@@ -1732,12 +1718,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAlloca
17321718
ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim));
17331719
EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2);
17341720

1735-
memoryManager->pushAllocationForResidency(&allocation1);
1736-
memoryManager->pushAllocationForResidency(&allocation2);
1737-
memoryManager->pushAllocationForResidency(&allocation3);
1738-
memoryManager->pushAllocationForResidency(&allocation4);
1739-
1740-
bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1721+
ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4};
1722+
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
17411723

17421724
EXPECT_FALSE(result);
17431725

@@ -1758,11 +1740,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTriple
17581740
ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim));
17591741
EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2);
17601742

1761-
memoryManager->pushAllocationForResidency(&allocation1);
1762-
memoryManager->pushAllocationForResidency(allocationTriple);
1763-
memoryManager->pushAllocationForResidency(&allocation2);
1764-
1765-
bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1743+
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
1744+
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
17661745

17671746
EXPECT_FALSE(result);
17681747

@@ -1781,12 +1760,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeResi
17811760
ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim));
17821761
EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2);
17831762

1784-
memoryManager->pushAllocationForResidency(&allocation1);
1785-
memoryManager->pushAllocationForResidency(&allocation2);
1786-
memoryManager->pushAllocationForResidency(&allocation3);
1787-
memoryManager->pushAllocationForResidency(&allocation4);
1788-
1789-
bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1763+
ResidencyContainer residencyPack{&allocation1, &allocation2, &allocation3, &allocation4};
1764+
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
17901765

17911766
EXPECT_FALSE(result);
17921767

@@ -1805,24 +1780,18 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsCallsMakeResident
18051780
EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, false, ::testing::_)).Times(1);
18061781
EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, true, ::testing::_)).Times(1);
18071782

1808-
memoryManager->pushAllocationForResidency(&allocation1);
1809-
1810-
bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1783+
ResidencyContainer residencyPack{&allocation1};
1784+
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
18111785

18121786
EXPECT_FALSE(result);
18131787
}
18141788

1815-
TEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResidentThenTheyAreUsedInsteadOfMemoryManagerMembers) {
1789+
TEST_F(WddmMemoryManagerTest2, givenAllocationPackPassedWhenCallingMakeResidentResidencyAllocationsThenItIsUsed) {
18161790
MockWddmAllocation allocation1;
18171791
MockWddmAllocation allocation2;
1818-
MockWddmAllocation allocation3;
18191792
allocation1.handle = 1;
18201793
allocation2.handle = 2;
1821-
allocation3.handle = 3;
1822-
1823-
ResidencyContainer residencyPack;
1824-
residencyPack.push_back(&allocation1);
1825-
residencyPack.push_back(&allocation2);
1794+
ResidencyContainer residencyPack{&allocation1, &allocation2};
18261795

18271796
auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool {
18281797
EXPECT_EQ(1, handles[0]);
@@ -1832,7 +1801,6 @@ TEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResiden
18321801
ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim));
18331802
EXPECT_CALL(*wddm, makeResident(::testing::_, 2, false, ::testing::_)).Times(1);
18341803

1835-
memoryManager->pushAllocationForResidency(&allocation3);
18361804
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
18371805
EXPECT_TRUE(result);
18381806
}
@@ -1851,9 +1819,8 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR
18511819

18521820
memoryManager->addToTrimCandidateList(&allocationToTrim);
18531821

1854-
memoryManager->pushAllocationForResidency(&allocation1);
1855-
1856-
bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1822+
ResidencyContainer residencyPack{&allocation1};
1823+
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
18571824

18581825
EXPECT_TRUE(result);
18591826

@@ -1862,14 +1829,14 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR
18621829

18631830
TEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemoryBudgetExhaustedIsReturnedAsTrue) {
18641831
MockWddmAllocation allocation1;
1832+
ResidencyContainer residencyPack{&allocation1};
18651833

18661834
auto makeResidentThatFails = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { return false; };
18671835
auto makeResidentThatSucceds = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { return true; };
18681836

18691837
EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(makeResidentThatFails)).WillOnce(::testing::Invoke(makeResidentThatSucceds));
18701838

1871-
memoryManager->pushAllocationForResidency(&allocation1);
1872-
bool result = memoryManager->makeResidentResidencyAllocations(&memoryManager->getResidencyAllocations(), *osContext);
1839+
bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack, *osContext);
18731840
EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted());
18741841
}
18751842

0 commit comments

Comments
 (0)