Skip to content

Commit bb2defa

Browse files
Rename preferredGpuAddress -> reservedGpuVirtualAddress
Use reservedSizeForGpuVirtualAddress for freeGpuVirtualAddress call Related-To: NEO-2881 Change-Id: Ieafa6ad33f3f9922cbfa414c7f40b4f3a28e7fc5 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 93ed9ab commit bb2defa

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

runtime/os_interface/windows/wddm_allocation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class WddmAllocation : public GraphicsAllocation {
7575
// OS assigned fields
7676
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
7777
bool needsMakeResidentBeforeLock = false;
78-
D3DGPU_VIRTUAL_ADDRESS preferredGpuAddress = 0u;
78+
D3DGPU_VIRTUAL_ADDRESS reservedGpuVirtualAddress = 0u;
79+
uint64_t reservedSizeForGpuVirtualAddress = 0u;
7980

8081
protected:
8182
std::string getHandleInfoString() const {

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
344344
if (input->getReservedAddressPtr()) {
345345
releaseReservedCpuAddressRange(input->getReservedAddressPtr(), input->getReservedAddressSize());
346346
}
347-
if (input->preferredGpuAddress) {
348-
wddm->freeGpuVirtualAddress(input->preferredGpuAddress, input->getAlignedSize());
347+
if (input->reservedGpuVirtualAddress) {
348+
wddm->freeGpuVirtualAddress(input->reservedGpuVirtualAddress, input->reservedSizeForGpuVirtualAddress);
349349
}
350350
delete gfxAllocation;
351351
}
@@ -506,8 +506,8 @@ bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, void *r
506506
obtainGpuAddressIfNeeded(allocation);
507507
bool mapSuccess = mapGpuVirtualAddressWithRetry(allocation, requiredGpuPtr);
508508
if (!mapSuccess) {
509-
if (allocation->preferredGpuAddress) {
510-
wddm->freeGpuVirtualAddress(allocation->preferredGpuAddress, allocation->getAlignedSize());
509+
if (allocation->reservedGpuVirtualAddress) {
510+
wddm->freeGpuVirtualAddress(allocation->reservedGpuVirtualAddress, allocation->reservedSizeForGpuVirtualAddress);
511511
}
512512
wddm->destroyAllocations(allocation->getHandles().data(), allocation->getNumHandles(), allocation->resourceHandle);
513513
return false;
@@ -546,8 +546,8 @@ uint32_t WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *graphicsAllocat
546546
if (!executionEnvironment.isFullRangeSvm()) {
547547
addressToMap = 0u;
548548
}
549-
if (graphicsAllocation->preferredGpuAddress) {
550-
addressToMap = graphicsAllocation->preferredGpuAddress;
549+
if (graphicsAllocation->reservedGpuVirtualAddress) {
550+
addressToMap = graphicsAllocation->reservedGpuVirtualAddress;
551551
}
552552
for (auto handleId = startingIndex; handleId < graphicsAllocation->getNumHandles(); handleId++) {
553553

@@ -564,8 +564,10 @@ uint32_t WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *graphicsAllocat
564564
void WddmMemoryManager::obtainGpuAddressIfNeeded(WddmAllocation *allocation) {
565565
if (allocation->getNumHandles() > 1u) {
566566
auto heapIndex = selectHeap(allocation, false, executionEnvironment.isFullRangeSvm());
567-
allocation->preferredGpuAddress = wddm->reserveGpuVirtualAddress(gfxPartition.getHeapMinimalAddress(heapIndex),
568-
gfxPartition.getHeapLimit(heapIndex), allocation->getAlignedSize());
567+
allocation->reservedSizeForGpuVirtualAddress = allocation->getAlignedSize();
568+
allocation->reservedGpuVirtualAddress = wddm->reserveGpuVirtualAddress(gfxPartition.getHeapMinimalAddress(heapIndex),
569+
gfxPartition.getHeapLimit(heapIndex),
570+
allocation->reservedSizeForGpuVirtualAddress);
569571
}
570572
}
571573

unit_tests/mocks/mock_wddm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ bool WddmMock::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTU
5959
bool WddmMock::freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) {
6060
freeGpuVirtualAddressResult.called++;
6161
freeGpuVirtualAddressResult.uint64ParamPassed = gpuPtr;
62+
freeGpuVirtualAddressResult.sizePassed = size;
6263
return freeGpuVirtualAddressResult.success = Wddm::freeGpuVirtualAddress(gpuPtr, size);
6364
}
6465
NTSTATUS WddmMock::createAllocation(WddmAllocation *wddmAllocation) {

unit_tests/mocks/mock_wddm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ struct KmDafLockCall : CallResult {
4141
struct WaitFromCpuResult : CallResult {
4242
const MonitoredFence *monitoredFence = nullptr;
4343
};
44+
struct FreeGpuVirtualAddressCall : CallResult {
45+
uint64_t sizePassed = -1;
46+
};
4447
} // namespace WddmMockHelpers
4548

4649
class WddmMock : public Wddm {
@@ -119,7 +122,7 @@ class WddmMock : public Wddm {
119122
WddmMockHelpers::MakeResidentCall makeResidentResult;
120123
WddmMockHelpers::CallResult makeNonResidentResult;
121124
WddmMockHelpers::CallResult mapGpuVirtualAddressResult;
122-
WddmMockHelpers::CallResult freeGpuVirtualAddressResult;
125+
WddmMockHelpers::FreeGpuVirtualAddressCall freeGpuVirtualAddressResult;
123126
WddmMockHelpers::CallResult createAllocationResult;
124127
WddmMockHelpers::CallResult destroyAllocationResult;
125128
WddmMockHelpers::CallResult destroyContextResult;

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,27 +1646,33 @@ TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatNeedsMa
16461646
memoryManager->freeGraphicsMemory(allocation);
16471647
EXPECT_EQ(0u, wddm->evictTemporaryResourceResult.called);
16481648
}
1649-
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingAllocationWithPreferredGpuAddressThenReleaseTheAddress) {
1649+
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingAllocationWithReservedGpuVirtualAddressThenReleaseTheAddress) {
16501650
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
16511651
uint64_t gpuAddress = 0x123;
1652-
allocation->preferredGpuAddress = gpuAddress;
1652+
uint64_t sizeForFree = 0x1234;
1653+
allocation->reservedGpuVirtualAddress = gpuAddress;
1654+
allocation->reservedSizeForGpuVirtualAddress = sizeForFree;
16531655
memoryManager->freeGraphicsMemory(allocation);
16541656
EXPECT_EQ(1u, wddm->freeGpuVirtualAddressResult.called);
16551657
EXPECT_EQ(gpuAddress, wddm->freeGpuVirtualAddressResult.uint64ParamPassed);
1658+
EXPECT_EQ(sizeForFree, wddm->freeGpuVirtualAddressResult.sizePassed);
16561659
}
16571660

1658-
TEST_F(WddmMemoryManagerSimpleTest, givenAllocationWithPreferredGpuAddressWhenMapCallFailsDuringCreateWddmAllocationThenReleasePreferredAddress) {
1661+
TEST_F(WddmMemoryManagerSimpleTest, givenAllocationWithReservedGpuVirtualAddressWhenMapCallFailsDuringCreateWddmAllocationThenReleasePreferredAddress) {
16591662
MockWddmAllocation allocation;
16601663
allocation.setAllocationType(GraphicsAllocation::AllocationType::KERNEL_ISA);
16611664
uint64_t gpuAddress = 0x123;
1662-
allocation.preferredGpuAddress = gpuAddress;
1665+
uint64_t sizeForFree = 0x1234;
1666+
allocation.reservedGpuVirtualAddress = gpuAddress;
1667+
allocation.reservedSizeForGpuVirtualAddress = sizeForFree;
16631668

16641669
wddm->callBaseMapGpuVa = false;
16651670
wddm->mapGpuVaStatus = false;
16661671

16671672
memoryManager->createWddmAllocation(&allocation, nullptr);
16681673
EXPECT_EQ(1u, wddm->freeGpuVirtualAddressResult.called);
16691674
EXPECT_EQ(gpuAddress, wddm->freeGpuVirtualAddressResult.uint64ParamPassed);
1675+
EXPECT_EQ(sizeForFree, wddm->freeGpuVirtualAddressResult.sizePassed);
16701676
}
16711677

16721678
TEST_F(WddmMemoryManagerSimpleTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedThenAllocateMemoryReserveGpuVa) {

0 commit comments

Comments
 (0)