Replace cpuPtrAllocated flag with driverAllocatedCpuPointer.

Change-Id: Ic0ce165d0e583701e1128595a3d9dabd0a61a84b
This commit is contained in:
Mrozek, Michal
2018-10-30 14:44:41 +01:00
committed by sys_ocldev
parent 7ece16ee7a
commit 200228b506
7 changed files with 22 additions and 35 deletions

View File

@@ -53,7 +53,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
Gmm *gmm = nullptr;
uint64_t allocationOffset = 0u;
int residencyTaskCount[maxOsContextCount] = {ObjectNotResident, ObjectNotResident, ObjectNotResident, ObjectNotResident};
bool cpuPtrAllocated = false; // flag indicating if cpuPtr is driver-allocated
void *driverAllocatedCpuPointer = nullptr;
DevicesBitfield devicesBitfield = 0;
bool flushL3Required = false;

View File

@@ -35,14 +35,14 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size,
MemoryAllocation *memoryAllocation = nullptr;
if (fakeBigAllocations && size > bigAllocation) {
memoryAllocation = new MemoryAllocation(true, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), size, counter, MemoryPool::System4KBPages);
memoryAllocation = new MemoryAllocation(nullptr, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), size, counter, MemoryPool::System4KBPages);
counter++;
memoryAllocation->uncacheable = uncacheable;
return memoryAllocation;
}
auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
if (ptr != nullptr) {
memoryAllocation = new MemoryAllocation(true, ptr, reinterpret_cast<uint64_t>(ptr), size, counter, MemoryPool::System4KBPages);
memoryAllocation = new MemoryAllocation(ptr, ptr, reinterpret_cast<uint64_t>(ptr), size, counter, MemoryPool::System4KBPages);
if (!memoryAllocation) {
alignedFreeWrapper(ptr);
return nullptr;
@@ -58,7 +58,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHost
auto alignedPtr = alignDown(reinterpret_cast<char *>(cpuPtr), MemoryConstants::pageSize);
auto offsetInPage = reinterpret_cast<char *>(cpuPtr) - alignedPtr;
memoryAllocation = new MemoryAllocation(false, cpuPtr, reinterpret_cast<uint64_t>(alignedPtr), size, counter, MemoryPool::System4KBPages);
memoryAllocation = new MemoryAllocation(nullptr, cpuPtr, reinterpret_cast<uint64_t>(alignedPtr), size, counter, MemoryPool::System4KBPages);
memoryAllocation->allocationOffset = offsetInPage;
memoryAllocation->uncacheable = false;
@@ -83,7 +83,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
return nullptr;
}
uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr) & MemoryConstants::pageMask);
MemoryAllocation *memAlloc = new MemoryAllocation(false, const_cast<void *>(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing);
MemoryAllocation *memAlloc = new MemoryAllocation(nullptr, const_cast<void *>(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing);
memAlloc->is32BitAllocation = true;
memAlloc->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase());
memAlloc->sizeToFree = allocationSize;
@@ -109,18 +109,17 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
MemoryAllocation *memoryAllocation = nullptr;
if (ptrAlloc != nullptr) {
memoryAllocation = new MemoryAllocation(true, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing);
memoryAllocation = new MemoryAllocation(freeCpuPointer ? ptrAlloc : nullptr, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing);
memoryAllocation->is32BitAllocation = true;
memoryAllocation->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase());
memoryAllocation->sizeToFree = allocationSize;
memoryAllocation->cpuPtrAllocated = freeCpuPointer;
}
counter++;
return memoryAllocation;
}
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) {
auto graphicsAllocation = new MemoryAllocation(false, reinterpret_cast<void *>(1), 1, 4096u, static_cast<uint64_t>(handle), MemoryPool::SystemCpuInaccessible);
auto graphicsAllocation = new MemoryAllocation(nullptr, reinterpret_cast<void *>(1), 1, 4096u, static_cast<uint64_t>(handle), MemoryPool::SystemCpuInaccessible);
graphicsAllocation->setSharedHandle(handle);
graphicsAllocation->is32BitAllocation = requireSpecificBitness;
return graphicsAllocation;
@@ -166,15 +165,12 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo
return;
}
void *ptr = gfxAllocation->getUnderlyingBuffer();
if (gfxAllocation->is32BitAllocation) {
auto gpuAddressToFree = gfxAllocation->getGpuAddress() & ~MemoryConstants::pageMask;
allocator32Bit->free(gpuAddressToFree, static_cast<MemoryAllocation *>(gfxAllocation)->sizeToFree);
}
if (gfxAllocation->cpuPtrAllocated) {
alignedFreeWrapper(ptr);
}
alignedFreeWrapper(gfxAllocation->driverAllocatedCpuPointer);
delete gfxAllocation;
}
@@ -191,7 +187,7 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() {
}
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
auto allocation = new MemoryAllocation(false, const_cast<void *>(hostPtr), reinterpret_cast<uint64_t>(hostPtr), hostPtrSize, counter++, MemoryPool::System4KBPages);
auto allocation = new MemoryAllocation(nullptr, const_cast<void *>(hostPtr), reinterpret_cast<uint64_t>(hostPtr), hostPtrSize, counter++, MemoryPool::System4KBPages);
allocation->fragmentsStorage = handleStorage;
return allocation;
}
@@ -231,7 +227,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(Imag
} else {
auto ptr = allocateSystemMemory(alignUp(imgInfo.size, MemoryConstants::pageSize), MemoryConstants::pageSize);
if (ptr != nullptr) {
alloc = new MemoryAllocation(true, ptr, reinterpret_cast<uint64_t>(ptr), imgInfo.size, counter, MemoryPool::SystemCpuInaccessible);
alloc = new MemoryAllocation(ptr, ptr, reinterpret_cast<uint64_t>(ptr), imgInfo.size, counter, MemoryPool::SystemCpuInaccessible);
counter++;
}
}

View File

@@ -21,9 +21,9 @@ class MemoryAllocation : public GraphicsAllocation {
void setSharedHandle(osHandle handle) { this->sharedHandle = handle; }
MemoryAllocation(bool cpuPtrAllocated, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize),
id(count) {
this->cpuPtrAllocated = cpuPtrAllocated;
MemoryAllocation(void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize),
id(count) {
this->driverAllocatedCpuPointer = driverAllocatedCpuPointer;
overrideMemoryPool(pool);
}

View File

@@ -117,7 +117,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_
}
auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, nullptr, MemoryPool::System4KBPages, getOsContextCount());
wddmAllocation->cpuPtrAllocated = true;
wddmAllocation->driverAllocatedCpuPointer = pSysMem;
gmm = new Gmm(pSysMem, sizeAligned, uncacheable);
@@ -191,7 +191,6 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
size_t sizeAligned = size;
void *pSysMem = nullptr;
size_t offset = 0;
bool cpuPtrAllocated = false;
if (ptr) {
ptrAligned = alignDown(ptr, MemoryConstants::allocationAlignment);
@@ -204,11 +203,10 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
return nullptr;
}
ptrAligned = pSysMem;
cpuPtrAllocated = true;
}
auto wddmAllocation = new WddmAllocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), nullptr, MemoryPool::System4KBPagesWith32BitGpuAddressing, getOsContextCount());
wddmAllocation->cpuPtrAllocated = cpuPtrAllocated;
wddmAllocation->driverAllocatedCpuPointer = pSysMem;
wddmAllocation->is32BitAllocation = true;
wddmAllocation->allocationOffset = offset;
@@ -333,22 +331,18 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
}
if (input->peekSharedHandle() == false &&
input->cpuPtrAllocated == false &&
input->driverAllocatedCpuPointer == nullptr &&
input->fragmentsStorage.fragmentCount > 0) {
cleanGraphicsMemoryCreatedFromHostPtr(gfxAllocation);
} else {
D3DKMT_HANDLE *allocationHandles = nullptr;
uint32_t allocationCount = 0;
D3DKMT_HANDLE resourceHandle = 0;
void *cpuPtr = nullptr;
if (input->peekSharedHandle()) {
resourceHandle = input->resourceHandle;
} else {
allocationHandles = &input->handle;
allocationCount = 1;
if (input->cpuPtrAllocated) {
cpuPtr = input->getAlignedCpuPtr();
}
}
if (input->isLocked()) {
unlockResource(input);
@@ -356,7 +350,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
}
auto status = tryDeferDeletions(allocationHandles, allocationCount, resourceHandle);
DEBUG_BREAK_IF(!status);
alignedFreeWrapper(cpuPtr);
alignedFreeWrapper(input->driverAllocatedCpuPointer);
}
wddm->releaseReservedAddress(input->getReservedAddress());
delete gfxAllocation;