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

@@ -412,6 +412,28 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
return new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding);
}
void DrmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) {
DrmAllocation *drmMemory = static_cast<DrmAllocation *>(gfxAllocation);
FragmentStorage fragment = {};
fragment.driverAllocation = true;
fragment.fragmentCpuPointer = gfxAllocation->getUnderlyingBuffer();
fragment.fragmentSize = alignUp(gfxAllocation->getUnderlyingBufferSize(), MemoryConstants::pageSize);
fragment.osInternalStorage = new OsHandle();
fragment.osInternalStorage->bo = drmMemory->getBO();
hostPtrManager.storeFragment(fragment);
}
void DrmMemoryManager::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 DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) {
DrmAllocation *input;
input = static_cast<DrmAllocation *>(gfxAllocation);

View File

@@ -40,7 +40,8 @@ class DrmMemoryManager : public MemoryManager {
~DrmMemoryManager() override;
BufferObject *getPinBB() const;
void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override;
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
DrmAllocation *allocateGraphicsMemory(size_t size, size_t alignment) override {
return allocateGraphicsMemory(size, alignment, false, false);