mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 00:24:58 +08:00
Setting the GpuAddress from a fragment in createGraphicsAllocation
Change-Id: I4d60aceea96dfbe50b2af4a1fbaada6a150ddd35
This commit is contained in:
committed by
sys_ocldev
parent
815151cb94
commit
3548876263
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user