diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 720b270f4f..cafb66004b 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -28,7 +28,6 @@ namespace Sharing { constexpr auto nonSharedResource = 0u; } -constexpr uint32_t maxOsContextCount = 4u; class Gmm; class GraphicsAllocation : public IDNode { diff --git a/runtime/memory_manager/residency.h b/runtime/memory_manager/residency.h index 77fae13340..7098dab797 100644 --- a/runtime/memory_manager/residency.h +++ b/runtime/memory_manager/residency.h @@ -10,10 +10,15 @@ #include namespace OCLRT { +constexpr uint32_t maxOsContextCount = 4u; + struct ResidencyData { - ResidencyData() = default; + ResidencyData() { + std::fill_n(resident, sizeof(resident), false); + } + ~ResidencyData() = default; - bool resident = false; + bool resident[maxOsContextCount]; void updateCompletionData(uint64_t newFenceValue, uint32_t contextId); uint64_t getFenceValueForContextId(uint32_t contextId); diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index cdde96b926..20b725117e 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -111,9 +111,10 @@ void DrmCommandStreamReceiver::processResidency(ResidencyContainer &i auto drmAlloc = static_cast(alloc); if (drmAlloc->fragmentsStorage.fragmentCount) { for (unsigned int f = 0; f < drmAlloc->fragmentsStorage.fragmentCount; f++) { - if (!drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident) { + const auto osContextId = osContext->getContextId(); + if (!drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId]) { makeResident(drmAlloc->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo); - drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident = true; + drmAlloc->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId] = true; } } } else { @@ -134,7 +135,7 @@ void DrmCommandStreamReceiver::makeNonResident(GraphicsAllocation &gf } if (gfxAllocation.fragmentsStorage.fragmentCount) { for (auto fragmentId = 0u; fragmentId < gfxAllocation.fragmentsStorage.fragmentCount; fragmentId++) { - gfxAllocation.fragmentsStorage.fragmentStorageData[fragmentId].residency->resident = false; + gfxAllocation.fragmentsStorage.fragmentStorageData[fragmentId].residency->resident[osContext->getContextId()] = false; } } } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index f710f53994..281a7f97c9 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -388,9 +388,8 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) { for (unsigned int i = 0; i < maxFragmentsCount; i++) { if (handleStorage.fragmentStorageData[i].freeTheFragment) { - handles[allocationCount] = handleStorage.fragmentStorageData[i].osHandleStorage->handle; - handleStorage.fragmentStorageData[i].residency->resident = false; - allocationCount++; + handles[allocationCount++] = handleStorage.fragmentStorageData[i].osHandleStorage->handle; + std::fill_n(handleStorage.fragmentStorageData[i].residency->resident, maxOsContextCount, false); } } diff --git a/runtime/os_interface/windows/wddm_residency_controller.cpp b/runtime/os_interface/windows/wddm_residency_controller.cpp index ce9c1b6fb5..a26ebe0417 100644 --- a/runtime/os_interface/windows/wddm_residency_controller.cpp +++ b/runtime/os_interface/windows/wddm_residency_controller.cpp @@ -213,7 +213,7 @@ void WddmResidencyController::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, if (!wasAllocationUsedSinceLastTrim(fragmentStorageData.residency->getFenceValueForContextId(osContextId))) { DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict fragment: handle =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle, "lastFence =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(osContextId)); fragmentEvictHandles[fragmentsToEvict++] = fragmentStorageData.osHandleStorage->handle; - fragmentStorageData.residency->resident = false; + fragmentStorageData.residency->resident[osContextId] = false; } } @@ -221,7 +221,7 @@ void WddmResidencyController::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim); } - wddmAllocation->getResidencyData().resident = false; + wddmAllocation->getResidencyData().resident[osContextId] = false; this->removeFromTrimCandidateList(wddmAllocation, false); } @@ -279,7 +279,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) { for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) { if (fragmentStorageData[allocationId].residency->getFenceValueForContextId(osContextId) <= monitoredFence.lastSubmittedFence) { - fragmentStorageData[allocationId].residency->resident = false; + fragmentStorageData[allocationId].residency->resident[osContextId] = false; sizeEvicted += fragmentStorageData[allocationId].fragmentSize; } } @@ -292,7 +292,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) { numberOfBytesToTrim -= sizeEvicted; } - wddmAllocation->getResidencyData().resident = false; + wddmAllocation->getResidencyData().resident[osContextId] = false; this->removeFromTrimCandidateList(wddmAllocation, false); } @@ -317,14 +317,14 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine ResidencyData &residencyData = allocation->getResidencyData(); bool fragmentResidency[3] = {false, false, false}; - DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation =", allocation, residencyData.resident ? "resident" : "not resident"); + DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation =", allocation, residencyData.resident[osContextId] ? "resident" : "not resident"); if (allocation->getTrimCandidateListPosition(this->osContextId) != trimListUnusedPosition) { DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation =", allocation, "on trimCandidateList"); this->removeFromTrimCandidateList(allocation, false); } else { for (uint32_t allocationId = 0; allocationId < allocation->fragmentsStorage.fragmentCount; allocationId++) { - fragmentResidency[allocationId] = allocation->fragmentsStorage.fragmentStorageData[allocationId].residency->resident; + fragmentResidency[allocationId] = allocation->fragmentsStorage.fragmentStorageData[allocationId].residency->resident[osContextId]; DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "fragment handle =", allocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle, fragmentResidency[allocationId] ? "resident" : "not resident"); } } @@ -334,7 +334,7 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine if (!fragmentResidency[allocationId]) handlesForResidency[totalHandlesCount++] = allocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle; } - } else if (!residencyData.resident) { + } else if (!residencyData.resident[osContextId]) { handlesForResidency[totalHandlesCount++] = allocation->handle; } } @@ -358,13 +358,13 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine // Update fence value not to early destroy / evict allocation const auto currentFence = this->getMonitoredFence().currentFenceValue; allocation->getResidencyData().updateCompletionData(currentFence, this->osContextId); - allocation->getResidencyData().resident = true; + allocation->getResidencyData().resident[osContextId] = true; for (uint32_t allocationId = 0; allocationId < allocation->fragmentsStorage.fragmentCount; allocationId++) { auto residencyData = allocation->fragmentsStorage.fragmentStorageData[allocationId].residency; // Update fence value not to remove the fragment referenced by different GA in trimming callback residencyData->updateCompletionData(currentFence, this->osContextId); - residencyData->resident = true; + residencyData->resident[osContextId] = true; } } } diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 4635ec5877..774548669f 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -1175,10 +1175,10 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW tCsr->processResidency(csr->getResidencyAllocations()); - EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident); - EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident); - EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident); - EXPECT_TRUE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident); + EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); + EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident[osContext->getContextId()]); + EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident[osContext->getContextId()]); + EXPECT_TRUE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); auto residency = tCsr->getResidencyVector(); @@ -1187,10 +1187,10 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW tCsr->makeSurfacePackNonResident(tCsr->getResidencyAllocations()); //check that each packet is not resident - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident); - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident); - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident); - EXPECT_FALSE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident); + EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); + EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident[osContext->getContextId()]); + EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident[osContext->getContextId()]); + EXPECT_FALSE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); EXPECT_EQ(0u, residency->size()); @@ -1199,10 +1199,10 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW tCsr->processResidency(csr->getResidencyAllocations()); - EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident); - EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident); - EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident); - EXPECT_TRUE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident); + EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); + EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident[osContext->getContextId()]); + EXPECT_TRUE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident[osContext->getContextId()]); + EXPECT_TRUE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); EXPECT_EQ(3u, residency->size()); @@ -1210,10 +1210,10 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW EXPECT_EQ(0u, residency->size()); - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident); - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident); - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident); - EXPECT_FALSE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident); + EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); + EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[1].residency->resident[osContext->getContextId()]); + EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency->resident[osContext->getContextId()]); + EXPECT_FALSE(graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency->resident[osContext->getContextId()]); mm->freeGraphicsMemory(graphicsAllocation); mm->freeGraphicsMemory(graphicsAllocation2); 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 5486279a6a..736beced5b 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -46,6 +46,13 @@ void WddmMemoryManagerFixture::SetUp() { memoryManager = std::make_unique(wddm, executionEnvironment); } +TEST(ResidencyData, givenNewlyConstructedResidencyDataThenItIsNotResidentOnAnyOsContext) { + ResidencyData residencyData; + for (auto contextId = 0u; contextId < maxOsContextCount; contextId++) { + EXPECT_EQ(false, residencyData.resident[contextId]); + } +} + TEST(WddmMemoryManager, NonCopyable) { EXPECT_FALSE(std::is_move_constructible::value); EXPECT_FALSE(std::is_copy_constructible::value); diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index cd29de9d99..b26ae148b2 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -429,8 +429,8 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(0, osContextId); - allocation1.getResidencyData().resident = true; - allocation2.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; + allocation2.getResidencyData().resident[osContextId] = true; // Set last periodic fence value residencyController->lastTrimFenceValue = 10; @@ -449,8 +449,8 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe // removed from trim candidate list EXPECT_EQ(0u, residencyController->peekTrimCandidateList().size()); // marked nonresident - EXPECT_FALSE(allocation1.getResidencyData().resident); - EXPECT_FALSE(allocation2.getResidencyData().resident); + EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]); + EXPECT_FALSE(allocation2.getResidencyData().resident[osContextId]); } TEST_F(WddmResidencyControllerWithGdiTest, givenOneUsedAllocationFromPreviousPeriodicTrimWhenTrimResidencyPeriodicTrimIsCalledThenOneAllocationIsTrimmed) { @@ -460,11 +460,11 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenOneUsedAllocationFromPreviousPer // allocations have fence value == 0 by default MockWddmAllocation allocation1, allocation2; - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; // mark allocation used from last periodic trim allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(11, osContextId); - allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().resident[osContextId] = true; // Set last periodic fence value residencyController->lastTrimFenceValue = 10; @@ -484,9 +484,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenOneUsedAllocationFromPreviousPer EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition(osContextId)); //marked nonresident - EXPECT_FALSE(allocation1.getResidencyData().resident); + EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]); // second stays resident - EXPECT_TRUE(allocation2.getResidencyData().resident); + EXPECT_TRUE(allocation2.getResidencyData().resident[osContextId]); } TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocationWithUsedAndUnusedFragmentsSincePreviousTrimWhenTrimResidencyPeriodicTrimIsCalledThenProperFragmentsAreEvictedAndMarked) { @@ -504,13 +504,13 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount); allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->updateCompletionData(0, osContextId); - allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId] = true; // this fragment was used allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(11, osContextId); - allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId] = true; allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->updateCompletionData(0, osContextId); - allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId] = true; // Set last periodic fence value *residencyController->getMonitoredFence().cpuAddress = 10; @@ -527,8 +527,8 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation // 2 fragments evicted with one call EXPECT_EQ(1u, wddm->makeNonResidentResult.called); // marked nonresident - EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident); - EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident); + EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]); + EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]); memoryManager->freeGraphicsMemory(allocationTriple); } @@ -574,14 +574,14 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetAllDoneAllocations) { MockWddmAllocation allocation1, allocation2, allocation3; - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(1, osContextId); - allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().resident[osContextId] = true; allocation3.getResidencyData().updateCompletionData(2, osContextId); - allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().resident[osContextId] = true; *residencyController->getMonitoredFence().cpuAddress = 1; residencyController->getMonitoredFence().lastSubmittedFence = 1; @@ -611,7 +611,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetReturnsFalseWhenNumBytesT MockWddmAllocation allocation1; - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); *residencyController->getMonitoredFence().cpuAddress = 1; @@ -634,14 +634,14 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetStopsEvictingWhenNumBytes allocation2(reinterpret_cast(0x1000), 0x3000, nullptr, MemoryPool::MemoryNull, 1u, false), allocation3(reinterpret_cast(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull, 1u, false); - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(1, osContextId); - allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().resident[osContextId] = true; allocation3.getResidencyData().updateCompletionData(2, osContextId); - allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().resident[osContextId] = true; *residencyController->getMonitoredFence().cpuAddress = 1; residencyController->getMonitoredFence().lastSubmittedFence = 1; @@ -669,14 +669,14 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetMarksEvictedAllocationNon MockWddmAllocation allocation1, allocation2, allocation3; - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(1, osContextId); - allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().resident[osContextId] = true; allocation3.getResidencyData().updateCompletionData(2, osContextId); - allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().resident[osContextId] = true; *residencyController->getMonitoredFence().cpuAddress = 1; residencyController->getMonitoredFence().lastSubmittedFence = 1; @@ -690,9 +690,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetMarksEvictedAllocationNon bool status = residencyController->trimResidencyToBudget(3 * 4096); - EXPECT_FALSE(allocation1.getResidencyData().resident); - EXPECT_FALSE(allocation2.getResidencyData().resident); - EXPECT_TRUE(allocation3.getResidencyData().resident); + EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]); + EXPECT_FALSE(allocation2.getResidencyData().resident[osContextId]); + EXPECT_TRUE(allocation3.getResidencyData().resident[osContextId]); } TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetWaitsFromCpuWhenLastFenceIsGreaterThanMonitored) { @@ -700,7 +700,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetWaitsFromCpuWhenLastFence MockWddmAllocation allocation1; - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(2, osContextId); *residencyController->getMonitoredFence().cpuAddress = 1; @@ -717,7 +717,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, trimToBudgetWaitsFromCpuWhenLastFence bool status = residencyController->trimResidencyToBudget(3 * 4096); EXPECT_EQ(1u, wddm->makeNonResidentResult.called); - EXPECT_FALSE(allocation1.getResidencyData().resident); + EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]); EXPECT_EQ(wddm->getDevice(), gdi->getWaitFromCpuArg().hDevice); } @@ -728,23 +728,23 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, trimToBudgetEvictsDon WddmAllocation allocation1(ptr, 0x1000, nullptr, MemoryPool::MemoryNull, 1u, false); WddmAllocation allocation2(ptr, 0x1000, nullptr, MemoryPool::MemoryNull, 1u, false); - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(1, osContextId); - allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().resident[osContextId] = true; void *ptrTriple = reinterpret_cast(reinterpret_cast(ptr) + 0x500); WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemory(8196, ptrTriple)); allocationTriple->getResidencyData().updateCompletionData(1, osContextId); - allocationTriple->getResidencyData().resident = true; + allocationTriple->getResidencyData().resident[osContextId] = true; EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount); for (uint32_t i = 0; i < 3; i++) { allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->updateCompletionData(1, osContextId); - allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident = true; + allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident[osContextId] = true; } // This should not be evicted @@ -764,9 +764,9 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, trimToBudgetEvictsDon EXPECT_EQ(2u, wddm->makeNonResidentResult.called); - EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident); - EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident); - EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident); + EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]); + EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident[osContextId]); + EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]); memoryManager->freeGraphicsMemory(allocationTriple); } @@ -788,14 +788,14 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge WddmAllocation allocation2(ptr2, underlyingSize, nullptr, MemoryPool::MemoryNull, 1u, false); WddmAllocation allocation3(ptr3, underlyingSize, nullptr, MemoryPool::MemoryNull, 1u, false); - allocation1.getResidencyData().resident = true; + allocation1.getResidencyData().resident[osContextId] = true; allocation1.getResidencyData().updateCompletionData(0, osContextId); allocation2.getResidencyData().updateCompletionData(1, osContextId); - allocation2.getResidencyData().resident = true; + allocation2.getResidencyData().resident[osContextId] = true; allocation3.getResidencyData().updateCompletionData(1, osContextId); - allocation3.getResidencyData().resident = true; + allocation3.getResidencyData().resident[osContextId] = true; *residencyController->getMonitoredFence().cpuAddress = 1; residencyController->getMonitoredFence().lastSubmittedFence = 1; @@ -810,9 +810,9 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenThreeAllocationsAlignedSizeBigge bool status = residencyController->trimResidencyToBudget(budget); EXPECT_TRUE(status); - EXPECT_FALSE(allocation1.getResidencyData().resident); - EXPECT_FALSE(allocation2.getResidencyData().resident); - EXPECT_TRUE(allocation3.getResidencyData().resident); + EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]); + EXPECT_FALSE(allocation2.getResidencyData().resident[osContextId]); + EXPECT_TRUE(allocation3.getResidencyData().resident[osContextId]); } using WddmResidencyControllerLockTest = WddmResidencyControllerWithGdiTest; @@ -851,10 +851,10 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidency residencyController->makeResidentResidencyAllocations(residencyPack); - EXPECT_TRUE(allocation1.getResidencyData().resident); - EXPECT_TRUE(allocation2.getResidencyData().resident); - EXPECT_TRUE(allocation3.getResidencyData().resident); - EXPECT_TRUE(allocation4.getResidencyData().resident); + EXPECT_TRUE(allocation1.getResidencyData().resident[osContextId]); + EXPECT_TRUE(allocation2.getResidencyData().resident[osContextId]); + EXPECT_TRUE(allocation3.getResidencyData().resident[osContextId]); + EXPECT_TRUE(allocation4.getResidencyData().resident[osContextId]); } TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidencyAllocationsUpdatesLastFence) { @@ -881,7 +881,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidency residencyController->makeResidentResidencyAllocations(residencyPack); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { - EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident); + EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident[osContextId]); } EXPECT_EQ(5u, gdi->getMakeResidentArg().NumAllocations); @@ -919,10 +919,10 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin EXPECT_FALSE(result); - EXPECT_FALSE(allocation1.getResidencyData().resident); - EXPECT_FALSE(allocation2.getResidencyData().resident); - EXPECT_FALSE(allocation3.getResidencyData().resident); - EXPECT_FALSE(allocation4.getResidencyData().resident); + EXPECT_FALSE(allocation1.getResidencyData().resident[osContextId]); + EXPECT_FALSE(allocation2.getResidencyData().resident[osContextId]); + EXPECT_FALSE(allocation3.getResidencyData().resident[osContextId]); + EXPECT_FALSE(allocation4.getResidencyData().resident[osContextId]); } TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenDontMarkTripleAllocationsAsResident) { @@ -942,7 +942,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin EXPECT_FALSE(result); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { - EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident); + EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident[osContextId]); } memoryManager->freeGraphicsMemory(allocationTriple); @@ -1001,7 +1001,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsAndTrimToB EXPECT_TRUE(result); - EXPECT_TRUE(allocation1.getResidencyData().resident); + EXPECT_TRUE(allocation1.getResidencyData().resident[osContextId]); } TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenMemoryBudgetExhaustedIsSetToTrue) {