Add support for createInternalGraphicsAllocation in DRM

Change-Id: I84090dfc4774506dee993e9c0c78c336367c43fd
This commit is contained in:
Mrozek, Michal
2018-02-28 15:12:10 +01:00
committed by sys_ocldev
parent 9e9876cd17
commit 0b8234117b
4 changed files with 115 additions and 13 deletions

View File

@@ -40,7 +40,8 @@ class Drm;
enum StorageAllocatorType {
MMAP_ALLOCATOR,
BIT32_ALLOCATOR,
BIT32_ALLOCATOR_EXTERNAL,
BIT32_ALLOCATOR_INTERNAL,
MALLOC_ALLOCATOR,
EXTERNAL_ALLOCATOR,
UNKNOWN_ALLOCATOR

View File

@@ -124,7 +124,12 @@ uint32_t DrmMemoryManager::unreference(OCLRT::BufferObject *bo, bool synchronous
if (allocatorType == MMAP_ALLOCATOR) {
munmapFunction(address, unmapSize);
} else {
allocator32Bit->free(address, unmapSize);
if (allocatorType == BIT32_ALLOCATOR_EXTERNAL) {
allocator32Bit->free(address, unmapSize);
} else {
UNRECOVERABLE_IF(allocatorType != BIT32_ALLOCATOR_INTERNAL)
internal32bitAllocator->free(address, unmapSize);
}
}
} else {
@@ -247,11 +252,14 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &
}
DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) {
auto allocatorToUse = memoryType == MemoryType::EXTERNAL_ALLOCATION ? allocator32Bit.get() : internal32bitAllocator.get();
auto allocationType = memoryType == MemoryType::EXTERNAL_ALLOCATION ? BIT32_ALLOCATOR_EXTERNAL : BIT32_ALLOCATOR_INTERNAL;
if (ptr) {
uintptr_t inputPtr = (uintptr_t)ptr;
auto allocationSize = alignSizeWholePage((void *)ptr, size);
auto realAllocationSize = allocationSize;
auto gpuVirtualAddress = allocator32Bit->allocate(realAllocationSize);
auto gpuVirtualAddress = allocatorToUse->allocate(realAllocationSize);
if (!gpuVirtualAddress) {
return nullptr;
}
@@ -260,7 +268,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *
BufferObject *bo = allocUserptr(alignedUserPointer, allocationSize, 0, true);
if (!bo) {
allocator32Bit->free(gpuVirtualAddress, realAllocationSize);
allocatorToUse->free(gpuVirtualAddress, realAllocationSize);
return nullptr;
}
@@ -269,18 +277,19 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *
bo->address = gpuVirtualAddress;
uintptr_t offset = (uintptr_t)bo->address;
bo->softPin((uint64_t)offset);
bo->setAllocationType(allocationType);
auto drmAllocation = new DrmAllocation(bo, (void *)ptr, (uint64_t)ptrOffset(gpuVirtualAddress, inputPointerOffset), allocationSize);
drmAllocation->is32BitAllocation = true;
drmAllocation->gpuBaseAddress = allocator32Bit->getBase();
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
return drmAllocation;
}
size_t alignedAllocationSize = alignUp(size, MemoryConstants::pageSize);
auto allocationSize = alignedAllocationSize;
auto res = allocator32Bit->allocate(allocationSize);
auto res = allocatorToUse->allocate(allocationSize);
if (!res) {
if (device && device->getProgramCount() == 0) {
if (memoryType == MemoryType::EXTERNAL_ALLOCATION && device && device->getProgramCount() == 0) {
this->force32bitAllocations = false;
device->setForce32BitAddressing(false);
return (DrmAllocation *)createGraphicsAllocationWithRequiredBitness(size, ptr);
@@ -292,19 +301,25 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *
BufferObject *bo = allocUserptr(reinterpret_cast<uintptr_t>(res), alignedAllocationSize, 0, true);
if (!bo) {
allocator32Bit->free(res, allocationSize);
allocatorToUse->free(res, allocationSize);
return nullptr;
}
bo->isAllocated = true;
bo->setUnmapSize(allocationSize);
bo->setAllocationType(allocationType);
auto drmAllocation = new DrmAllocation(bo, res, alignedAllocationSize);
drmAllocation->is32BitAllocation = true;
drmAllocation->gpuBaseAddress = allocator32Bit->getBase();
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
return drmAllocation;
}
GraphicsAllocation *DrmMemoryManager::createInternalGraphicsAllocation(const void *ptr, size_t allocationSize) {
return allocate32BitGraphicsMemory(allocationSize, const_cast<void *>(ptr), MemoryType::INTERNAL_ALLOCATION);
}
BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle) {
BufferObject *bo = nullptr;
@@ -326,7 +341,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si
if (requireSpecificBitness && this->force32bitAllocations) {
gpuRange = this->allocator32Bit->allocate(size);
storageType = BIT32_ALLOCATOR;
storageType = BIT32_ALLOCATOR_EXTERNAL;
} else {
gpuRange = mmapFunction(nullptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
storageType = MMAP_ALLOCATOR;

View File

@@ -53,6 +53,7 @@ class DrmMemoryManager : public MemoryManager {
DrmAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) override;
GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override;
DrmAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) override;
GraphicsAllocation *createInternalGraphicsAllocation(const void *ptr, size_t allocationSize) override;
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) override;
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; }