Tracking the internal allocation when creating a buffer

This fix prevents the creation of a buffer from the pointer
obtained from clEnqueueMapBuffer

Change-Id: I203f2d5263eeb02fe0d73bc9db159438af3cf1fc
This commit is contained in:
Koska, Andrzej
2018-05-08 10:00:23 +02:00
committed by sys_ocldev
parent c46f716d6c
commit fe56c57318
16 changed files with 233 additions and 11 deletions

View File

@@ -110,6 +110,26 @@ GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedH
return graphicsAllocation;
}
void OsAgnosticMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) {
FragmentStorage fragment = {};
fragment.driverAllocation = true;
fragment.fragmentCpuPointer = gfxAllocation->getUnderlyingBuffer();
fragment.fragmentSize = alignUp(gfxAllocation->getUnderlyingBufferSize(), MemoryConstants::pageSize);
fragment.osInternalStorage = new OsHandle();
hostPtrManager.storeFragment(fragment);
}
void OsAgnosticMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) {
auto buffer = gfxAllocation->getUnderlyingBuffer();
auto fragment = hostPtrManager.getFragment(buffer);
if (fragment && fragment->driverAllocation) {
OsHandle *osStorageToRelease = fragment->osInternalStorage;
if (hostPtrManager.releaseHostPtr(buffer)) {
delete osStorageToRelease;
}
}
}
void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) {
if (gfxAllocation == nullptr)
return;
@@ -166,7 +186,7 @@ MemoryManager::AllocationStatus OsAgnosticMemoryManager::populateOsHandles(OsHan
handleStorage.fragmentStorageData[i].osHandleStorage = new OsHandle();
handleStorage.fragmentStorageData[i].residency = new ResidencyData();
FragmentStorage newFragment;
FragmentStorage newFragment = {};
newFragment.fragmentCpuPointer = const_cast<void *>(handleStorage.fragmentStorageData[i].cpuPtr);
newFragment.fragmentSize = handleStorage.fragmentStorageData[i].fragmentSize;
newFragment.osInternalStorage = handleStorage.fragmentStorageData[i].osHandleStorage;