Skip to content

Commit 8e743cc

Browse files
Refactor Wddm interface of mapping GPU VA
Change-Id: Ic807dfb17fd0ab664af281db757e48b0cc424fcb Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
1 parent 16e1a05 commit 8e743cc

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

runtime/os_interface/windows/wddm/wddm.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ bool Wddm::makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantT
288288
return success;
289289
}
290290

291-
bool Wddm::mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr) {
292-
void *mapPtr = allocation->getReservedAddressPtr() != nullptr ? allocation->getReservedAddressPtr() : cpuPtr;
293-
return mapGpuVirtualAddressImpl(allocation->getDefaultGmm(), allocation->getDefaultHandle(), mapPtr, allocation->getGpuAddressToModify(),
294-
MemoryManager::selectHeap(allocation, mapPtr, *hardwareInfoTable[gfxPlatform->eProductFamily]));
291+
bool Wddm::mapGpuVirtualAddress(WddmAllocation *allocation, void *requiredGpuPtr) {
292+
return mapGpuVirtualAddressImpl(allocation->getDefaultGmm(), allocation->getDefaultHandle(), requiredGpuPtr, allocation->getGpuAddressToModify(),
293+
MemoryManager::selectHeap(allocation, requiredGpuPtr, *hardwareInfoTable[gfxPlatform->eProductFamily]));
295294
}
296295

297296
bool Wddm::mapGpuVirtualAddress(AllocationStorageData *allocationStorageData) {

runtime/os_interface/windows/wddm/wddm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Wddm {
5858

5959
MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim);
6060
MOCKABLE_VIRTUAL bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim);
61-
bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr);
61+
bool mapGpuVirtualAddress(WddmAllocation *allocation, void *requiredGpuPtr);
6262
bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData);
6363
D3DGPU_VIRTUAL_ADDRESS reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_SIZE_T size);
6464
MOCKABLE_VIRTUAL bool createContext(OsContextWin &osContext);

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImageImpl(const
5050

5151
auto allocation = std::make_unique<WddmAllocation>(allocationData.type, nullptr, allocationData.imgInfo->size, nullptr, MemoryPool::SystemCpuInaccessible, false);
5252
allocation->setDefaultGmm(gmm.get());
53-
if (!createWddmAllocation(allocation.get())) {
53+
if (!createWddmAllocation(allocation.get(), nullptr)) {
5454
return nullptr;
5555
}
5656

@@ -101,7 +101,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithAlignment(const
101101

102102
wddmAllocation->setDefaultGmm(gmm);
103103

104-
if (!createWddmAllocation(wddmAllocation.get())) {
104+
if (!createWddmAllocation(wddmAllocation.get(), wddmAllocation->getAlignedCpuPtr())) {
105105
delete gmm;
106106
freeSystemMemory(pSysMem);
107107
return nullptr;
@@ -124,7 +124,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(co
124124

125125
wddmAllocation->setDefaultGmm(gmm);
126126

127-
if (!createWddmAllocation(wddmAllocation.get())) {
127+
if (!createWddmAllocation(wddmAllocation.get(), wddmAllocation->getAlignedCpuPtr())) {
128128
delete gmm;
129129
return nullptr;
130130
}
@@ -156,7 +156,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithProperties(cons
156156

157157
Gmm *gmm = new Gmm(ptrAligned, sizeAligned, false);
158158
allocation->setDefaultGmm(gmm);
159-
if (createWddmAllocation(allocation)) {
159+
if (createWddmAllocation(allocation, reserve)) {
160160
DebugManager.logAllocation(allocation);
161161
return allocation;
162162
}
@@ -198,7 +198,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
198198
gmm = new Gmm(ptrAligned, sizeAligned, false);
199199
wddmAllocation->setDefaultGmm(gmm);
200200

201-
if (!createWddmAllocation(wddmAllocation.get())) {
201+
if (!createWddmAllocation(wddmAllocation.get(), wddmAllocation->getAlignedCpuPtr())) {
202202
delete gmm;
203203
freeSystemMemory(pSysMem);
204204
return nullptr;
@@ -483,18 +483,18 @@ AlignedMallocRestrictions *WddmMemoryManager::getAlignedMallocRestrictions() {
483483
return &mallocRestrictions;
484484
}
485485

486-
bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation) {
486+
bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr) {
487487
auto wddmSuccess = wddm->createAllocation(allocation->getAlignedCpuPtr(), allocation->getDefaultGmm(), allocation->getHandleToModify(0u));
488488
if (wddmSuccess == STATUS_GRAPHICS_NO_VIDEO_MEMORY && deferredDeleter) {
489489
deferredDeleter->drain(true);
490490
wddmSuccess = wddm->createAllocation(allocation->getAlignedCpuPtr(), allocation->getDefaultGmm(), allocation->getHandleToModify(0u));
491491
}
492492

493493
if (wddmSuccess == STATUS_SUCCESS) {
494-
bool mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr());
494+
bool mapSuccess = wddm->mapGpuVirtualAddress(allocation, requiredGpuPtr);
495495
if (!mapSuccess && deferredDeleter) {
496496
deferredDeleter->drain(true);
497-
mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr());
497+
mapSuccess = wddm->mapGpuVirtualAddress(allocation, requiredGpuPtr);
498498
}
499499
if (!mapSuccess) {
500500
wddm->destroyAllocations(allocation->getHandles().data(), allocation->getNumHandles(), allocation->resourceHandle);

runtime/os_interface/windows/wddm_memory_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class WddmMemoryManager : public MemoryManager {
8282

8383
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle);
8484
static bool validateAllocation(WddmAllocation *alloc);
85-
bool createWddmAllocation(WddmAllocation *allocation);
85+
bool createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr);
8686
AlignedMallocRestrictions mallocRestrictions;
8787

8888
private:

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGpuV
905905

906906
WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, ptr, size, nullptr, MemoryPool::MemoryNull, false);
907907
allocation.setDefaultGmm(gmm.get());
908-
bool ret = memoryManager->createWddmAllocation(&allocation);
908+
bool ret = memoryManager->createWddmAllocation(&allocation, allocation.getAlignedCpuPtr());
909909
EXPECT_FALSE(ret);
910910
}
911911

@@ -921,7 +921,7 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstMap
921921

922922
WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, ptr, size, nullptr, MemoryPool::MemoryNull, false);
923923
allocation.setDefaultGmm(gmm.get());
924-
bool ret = memoryManager->createWddmAllocation(&allocation);
924+
bool ret = memoryManager->createWddmAllocation(&allocation, allocation.getAlignedCpuPtr());
925925
EXPECT_TRUE(ret);
926926
}
927927

@@ -937,7 +937,7 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstAnd
937937

938938
WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, ptr, size, nullptr, MemoryPool::MemoryNull, false);
939939
allocation.setDefaultGmm(gmm.get());
940-
bool ret = memoryManager->createWddmAllocation(&allocation);
940+
bool ret = memoryManager->createWddmAllocation(&allocation, allocation.getAlignedCpuPtr());
941941
EXPECT_FALSE(ret);
942942
}
943943

0 commit comments

Comments
 (0)