Skip to content

Commit b563e07

Browse files
Setting the GpuAddress from a fragment in createGraphicsAllocation
Change-Id: I4f6afbdd4d86ab2958de29cf49aaed9b8e2ea642
1 parent 77ad97d commit b563e07

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,22 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
411411
}
412412
}
413413

414+
void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage) {
415+
if (this->force32bitAllocations && (handleStorage.fragmentCount > 0)) {
416+
auto gpuPtr = handleStorage.fragmentStorageData[0].osHandleStorage->gpuPtr;
417+
for (uint32_t i = 1; i < handleStorage.fragmentCount; i++) {
418+
if (handleStorage.fragmentStorageData[i].osHandleStorage->gpuPtr < gpuPtr) {
419+
gpuPtr = handleStorage.fragmentStorageData[i].osHandleStorage->gpuPtr;
420+
}
421+
}
422+
allocation->setGpuAddress(gpuPtr);
423+
}
424+
}
425+
414426
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
415427
auto allocation = new WddmAllocation(const_cast<void *>(hostPtr), hostPtrSize, const_cast<void *>(hostPtr), hostPtrSize, nullptr);
416428
allocation->fragmentsStorage = handleStorage;
429+
obtainGpuAddresFromFragments(allocation, handleStorage);
417430
return allocation;
418431
}
419432

runtime/os_interface/windows/wddm_memory_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class WddmMemoryManager : public MemoryManager {
6464
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
6565
void cleanOsHandles(OsHandleStorage &handleStorage) override;
6666

67+
void obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
68+
6769
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
6870

6971
static const D3DGPU_VIRTUAL_ADDRESS minimumAddress = static_cast<D3DGPU_VIRTUAL_ADDRESS>(0x0);

unit_tests/os_interface/windows/mock_wddm_memory_manager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class MockWddmMemoryManager : public WddmMemoryManager {
4444
void setDeferredDeleter(DeferredDeleter *deleter) {
4545
this->deferredDeleter.reset(deleter);
4646
}
47-
47+
void setForce32bitAllocations(bool newValue) {
48+
this->force32bitAllocations = newValue;
49+
}
4850
bool validateAllocationMock(WddmAllocation *graphicsAllocation) {
4951
return this->validateAllocation(graphicsAllocation);
5052
}

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,39 @@ HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAlloca
15731573
memoryManager->freeGraphicsMemory(allocation);
15741574
}
15751575

1576+
HWTEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocationIsBeingCreatedThenGraphicsAddressIsPopulatedFromProperFragment) {
1577+
SetUpMm<FamilyType>();
1578+
memoryManager->setForce32bitAllocations(true);
1579+
OsHandleStorage handleStorage;
1580+
D3DGPU_VIRTUAL_ADDRESS lowestAdress = MemoryConstants::pageSize * 1;
1581+
D3DGPU_VIRTUAL_ADDRESS higherAdress = MemoryConstants::pageSize * 2;
1582+
1583+
auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + MemoryConstants::pageSize * 1);
1584+
auto ptr2 = reinterpret_cast<void *>(wddm->virtualAllocAddress + MemoryConstants::pageSize * 2);
1585+
auto size = MemoryConstants::pageSize;
1586+
OsHandle osHandle1;
1587+
OsHandle osHandle2;
1588+
handleStorage.fragmentStorageData[0].cpuPtr = ptr;
1589+
handleStorage.fragmentStorageData[0].fragmentSize = size;
1590+
handleStorage.fragmentStorageData[0].osHandleStorage = &osHandle1;
1591+
handleStorage.fragmentStorageData[0].osHandleStorage->gpuPtr = higherAdress;
1592+
1593+
handleStorage.fragmentStorageData[1].cpuPtr = ptr2;
1594+
handleStorage.fragmentStorageData[1].fragmentSize = size * 2;
1595+
handleStorage.fragmentStorageData[1].osHandleStorage = &osHandle2;
1596+
handleStorage.fragmentStorageData[1].osHandleStorage->gpuPtr = lowestAdress;
1597+
handleStorage.fragmentCount = 2;
1598+
1599+
auto allocation = memoryManager->createGraphicsAllocation(handleStorage, size, ptr);
1600+
1601+
EXPECT_EQ(ptr, allocation->getUnderlyingBuffer());
1602+
EXPECT_EQ(size, allocation->getUnderlyingBufferSize());
1603+
EXPECT_EQ(lowestAdress, allocation->getGpuAddress());
1604+
1605+
allocation->fragmentsStorage.fragmentCount = 0;
1606+
memoryManager->freeGraphicsMemory(allocation);
1607+
}
1608+
15761609
HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAllocationsResidentWhenMakeResidentFails) {
15771610
SetUpMm<FamilyType>();
15781611
WddmAllocation allocation1, allocation2, allocation3, allocation4;

0 commit comments

Comments
 (0)