Setting the GpuAddress from a fragment in createGraphicsAllocation

Change-Id: I4d60aceea96dfbe50b2af4a1fbaada6a150ddd35
This commit is contained in:
Koska, Andrzej
2018-06-21 11:42:03 +02:00
committed by sys_ocldev
parent 815151cb94
commit 3548876263
3 changed files with 87 additions and 0 deletions

View File

@@ -412,9 +412,27 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
}
}
void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage) {
if (this->force32bitAllocations && (handleStorage.fragmentCount > 0)) {
auto hostPtr = allocation->getUnderlyingBuffer();
auto fragment = hostPtrManager.getFragment(hostPtr);
if (fragment && fragment->driverAllocation) {
auto gpuPtr = handleStorage.fragmentStorageData[0].osHandleStorage->gpuPtr;
for (uint32_t i = 1; i < handleStorage.fragmentCount; i++) {
if (handleStorage.fragmentStorageData[i].osHandleStorage->gpuPtr < gpuPtr) {
gpuPtr = handleStorage.fragmentStorageData[i].osHandleStorage->gpuPtr;
}
}
allocation->allocationOffset = reinterpret_cast<uint64_t>(hostPtr) & MemoryConstants::pageMask;
allocation->setGpuAddress(gpuPtr);
}
}
}
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
auto allocation = new WddmAllocation(const_cast<void *>(hostPtr), hostPtrSize, const_cast<void *>(hostPtr), hostPtrSize, nullptr);
allocation->fragmentsStorage = handleStorage;
obtainGpuAddresFromFragments(allocation, handleStorage);
return allocation;
}

View File

@@ -64,6 +64,8 @@ class WddmMemoryManager : public MemoryManager {
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage) override;
void obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
static const D3DGPU_VIRTUAL_ADDRESS minimumAddress = static_cast<D3DGPU_VIRTUAL_ADDRESS>(0x0);

View File

@@ -1574,6 +1574,73 @@ HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAlloca
memoryManager->freeGraphicsMemory(allocation);
}
HWTEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocationIsBeingCreatedThenGraphicsAddressIsPopulatedFromProperFragment) {
SetUpMm<FamilyType>();
memoryManager->setForce32bitAllocations(true);
OsHandleStorage handleStorage = {};
D3DGPU_VIRTUAL_ADDRESS gpuAdress = MemoryConstants::pageSize * 1;
auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + MemoryConstants::pageSize);
auto size = MemoryConstants::pageSize * 2;
handleStorage.fragmentStorageData[0].cpuPtr = ptr;
handleStorage.fragmentStorageData[0].fragmentSize = size;
handleStorage.fragmentStorageData[0].osHandleStorage = new OsHandle();
handleStorage.fragmentStorageData[0].residency = new ResidencyData();
handleStorage.fragmentStorageData[0].freeTheFragment = true;
handleStorage.fragmentStorageData[0].osHandleStorage->gmm = new MockGmm();
handleStorage.fragmentCount = 1;
FragmentStorage fragment = {};
fragment.driverAllocation = true;
fragment.fragmentCpuPointer = ptr;
fragment.fragmentSize = size;
fragment.osInternalStorage = handleStorage.fragmentStorageData[0].osHandleStorage;
fragment.osInternalStorage->gpuPtr = gpuAdress;
memoryManager->hostPtrManager.storeFragment(fragment);
auto allocation = memoryManager->createGraphicsAllocation(handleStorage, size, ptr);
EXPECT_EQ(ptr, allocation->getUnderlyingBuffer());
EXPECT_EQ(size, allocation->getUnderlyingBufferSize());
EXPECT_EQ(gpuAdress, allocation->getGpuAddress());
EXPECT_EQ(0ULL, allocation->allocationOffset);
memoryManager->freeGraphicsMemory(allocation);
}
HWTEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocationIsBeingCreatedNotAllignedToPageThenGraphicsAddressIsPopulatedFromProperFragmentAndOffsetisAssigned) {
SetUpMm<FamilyType>();
memoryManager->setForce32bitAllocations(true);
OsHandleStorage handleStorage = {};
D3DGPU_VIRTUAL_ADDRESS gpuAdress = MemoryConstants::pageSize * 1;
auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + MemoryConstants::pageSize);
auto size = MemoryConstants::pageSize * 2;
handleStorage.fragmentStorageData[0].cpuPtr = ptr;
handleStorage.fragmentStorageData[0].fragmentSize = size;
handleStorage.fragmentStorageData[0].osHandleStorage = new OsHandle();
handleStorage.fragmentStorageData[0].residency = new ResidencyData();
handleStorage.fragmentStorageData[0].freeTheFragment = true;
handleStorage.fragmentStorageData[0].osHandleStorage->gmm = new MockGmm();
handleStorage.fragmentCount = 1;
FragmentStorage fragment = {};
fragment.driverAllocation = true;
fragment.fragmentCpuPointer = ptr;
fragment.fragmentSize = size;
fragment.osInternalStorage = handleStorage.fragmentStorageData[0].osHandleStorage;
fragment.osInternalStorage->gpuPtr = gpuAdress;
memoryManager->hostPtrManager.storeFragment(fragment);
auto offset = 80;
auto allocationPtr = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) + offset);
auto allocation = memoryManager->createGraphicsAllocation(handleStorage, size, allocationPtr);
EXPECT_EQ(allocationPtr, allocation->getUnderlyingBuffer());
EXPECT_EQ(size, allocation->getUnderlyingBufferSize());
EXPECT_EQ(gpuAdress + offset, allocation->getGpuAddress()); // getGpuAddress returns gpuAddress + allocationOffset
EXPECT_EQ(offset, allocation->allocationOffset);
memoryManager->freeGraphicsMemory(allocation);
}
HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAllocationsResidentWhenMakeResidentFails) {
SetUpMm<FamilyType>();
WddmAllocation allocation1, allocation2, allocation3, allocation4;