HostPtr allocation with life time of image object for CL_MEM_USE_HOST_PTR

Related-To: NEO-3231

Change-Id: I4869e55b3c4b5217c83cc0b53d8c9f8c14b524b2
Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir
2019-06-06 23:21:08 +02:00
committed by sys_ocldev
parent b86d8f060b
commit 8998f89886
5 changed files with 65 additions and 47 deletions

View File

@@ -116,6 +116,7 @@ Image *Image::create(Context *context,
UNRECOVERABLE_IF(surfaceFormat == nullptr);
Image *image = nullptr;
GraphicsAllocation *memory = nullptr;
GraphicsAllocation *mapAllocation = nullptr;
MemoryManager *memoryManager = context->getMemoryManager();
Buffer *parentBuffer = castToObject<Buffer>(imageDesc->mem_object);
Image *parentImage = castToObject<Image>(imageDesc->mem_object);
@@ -184,6 +185,32 @@ Image *Image::create(Context *context,
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, flags,
context->peekContextType(), true);
switch (imageDesc->image_type) {
case CL_MEM_OBJECT_IMAGE3D:
hostPtrMinSize = hostPtrSlicePitch * imageDepth;
break;
case CL_MEM_OBJECT_IMAGE2D:
if (IsNV12Image(&surfaceFormat->OCLImageFormat)) {
hostPtrMinSize = hostPtrRowPitch * imageHeight + hostPtrRowPitch * imageHeight / 2;
} else {
hostPtrMinSize = hostPtrRowPitch * imageHeight;
}
hostPtrSlicePitch = 0;
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
hostPtrMinSize = hostPtrSlicePitch * imageCount;
break;
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
hostPtrMinSize = hostPtrRowPitch;
hostPtrSlicePitch = 0;
break;
default:
DEBUG_BREAK_IF("Unsupported cl_image_type");
break;
}
bool zeroCopy = false;
bool transferNeeded = false;
if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) {
@@ -241,7 +268,11 @@ Image *Image::create(Context *context,
memory->setDefaultGmm(gmm);
zeroCopy = true;
}
if (memory) {
AllocationProperties properties{false, hostPtrMinSize, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR};
properties.flags.flushL3RequiredForRead = properties.flags.flushL3RequiredForWrite = true;
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr);
}
} else {
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(imgInfo, true, flags);
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
@@ -253,32 +284,6 @@ Image *Image::create(Context *context,
}
transferNeeded |= !!(flags & CL_MEM_COPY_HOST_PTR);
switch (imageDesc->image_type) {
case CL_MEM_OBJECT_IMAGE3D:
hostPtrMinSize = hostPtrSlicePitch * imageDepth;
break;
case CL_MEM_OBJECT_IMAGE2D:
if (IsNV12Image(&surfaceFormat->OCLImageFormat)) {
hostPtrMinSize = hostPtrRowPitch * imageHeight + hostPtrRowPitch * imageHeight / 2;
} else {
hostPtrMinSize = hostPtrRowPitch * imageHeight;
}
hostPtrSlicePitch = 0;
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
hostPtrMinSize = hostPtrSlicePitch * imageCount;
break;
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
hostPtrMinSize = hostPtrRowPitch;
hostPtrSlicePitch = 0;
break;
default:
DEBUG_BREAK_IF("Unsupported cl_image_type");
break;
}
if (!memory) {
break;
}
@@ -359,6 +364,8 @@ Image *Image::create(Context *context,
}
}
image->mapAllocation = mapAllocation;
if (errcodeRet != CL_SUCCESS) {
image->release();
image = nullptr;