mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Refactor Graphics Allocation paths for Images
Change-Id: Ifa3084b18cac95289bbceeaf3669dd31567fbd3e
This commit is contained in:
committed by
sys_ocldev
parent
3dca095ccf
commit
f6790c42cf
@@ -182,7 +182,6 @@ Image *Image::create(Context *context,
|
||||
bool zeroCopy = false;
|
||||
bool transferNeeded = false;
|
||||
bool imageRedescribed = false;
|
||||
bool copyRequired = false;
|
||||
if (((imageDesc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) || (imageDesc->image_type == CL_MEM_OBJECT_IMAGE2D)) && (parentBuffer != nullptr)) {
|
||||
isImageFromBuffer = true;
|
||||
imageRedescribed = true;
|
||||
@@ -211,32 +210,28 @@ Image *Image::create(Context *context,
|
||||
memory->gmm->queryImageParams(imgInfo);
|
||||
isTilingAllowed = parentImage->allowTiling();
|
||||
} else {
|
||||
gmm = new Gmm(imgInfo);
|
||||
|
||||
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
size_t pointerPassedSize = hostPtrRowPitch * imageHeight * imageDepth * imageCount;
|
||||
auto alignedSizePassedPointer = alignSizeWholePage(const_cast<void *>(hostPtr), pointerPassedSize);
|
||||
auto alignedSizeRequiredForAllocation = alignSizeWholePage(const_cast<void *>(hostPtr), imgInfo.size);
|
||||
|
||||
// Passed pointer doesn't have enough memory, copy is needed
|
||||
copyRequired = (alignedSizeRequiredForAllocation > alignedSizePassedPointer) |
|
||||
(imgInfo.rowPitch != hostPtrRowPitch) |
|
||||
(imgInfo.slicePitch != hostPtrSlicePitch) |
|
||||
((reinterpret_cast<uintptr_t>(hostPtr) & (MemoryConstants::cacheLineSize - 1)) != 0) |
|
||||
isTilingAllowed;
|
||||
|
||||
if (copyRequired && !context->isSharedContext) {
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, gmm);
|
||||
zeroCopy = false;
|
||||
transferNeeded = true;
|
||||
if (!context->isSharedContext) {
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, hostPtr);
|
||||
if (memory) {
|
||||
if (memory->getUnderlyingBuffer() != hostPtr) {
|
||||
zeroCopy = false;
|
||||
transferNeeded = true;
|
||||
} else {
|
||||
zeroCopy = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gmm = new Gmm(imgInfo);
|
||||
memory = memoryManager->allocateGraphicsMemory(imgInfo.size, hostPtr);
|
||||
memory->gmm = gmm;
|
||||
zeroCopy = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, gmm);
|
||||
memory = memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr);
|
||||
if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
|
||||
zeroCopy = true;
|
||||
}
|
||||
@@ -271,9 +266,6 @@ Image *Image::create(Context *context,
|
||||
}
|
||||
|
||||
if (!memory) {
|
||||
if (gmm) {
|
||||
delete gmm;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -665,6 +657,46 @@ const SurfaceFormatInfo &Image::getSurfaceFormatInfo() const {
|
||||
return surfaceFormatInfo;
|
||||
}
|
||||
|
||||
bool Image::isCopyRequired(ImageInfo &imgInfo, const void *hostPtr) {
|
||||
if (!hostPtr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t imageWidth = imgInfo.imgDesc->image_width;
|
||||
size_t imageHeight = 1;
|
||||
size_t imageDepth = 1;
|
||||
size_t imageCount = 1;
|
||||
|
||||
switch (imgInfo.imgDesc->image_type) {
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
imageDepth = imgInfo.imgDesc->image_depth;
|
||||
CPP_ATTRIBUTE_FALLTHROUGH;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
imageHeight = imgInfo.imgDesc->image_height;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
auto hostPtrRowPitch = imgInfo.imgDesc->image_row_pitch ? imgInfo.imgDesc->image_row_pitch : imageWidth * imgInfo.surfaceFormat->ImageElementSizeInBytes;
|
||||
auto hostPtrSlicePitch = imgInfo.imgDesc->image_slice_pitch ? imgInfo.imgDesc->image_slice_pitch : hostPtrRowPitch * imgInfo.imgDesc->image_height;
|
||||
auto isTilingAllowed = GmmHelper::allowTiling(*imgInfo.imgDesc);
|
||||
|
||||
size_t pointerPassedSize = hostPtrRowPitch * imageHeight * imageDepth * imageCount;
|
||||
auto alignedSizePassedPointer = alignSizeWholePage(const_cast<void *>(hostPtr), pointerPassedSize);
|
||||
auto alignedSizeRequiredForAllocation = alignSizeWholePage(const_cast<void *>(hostPtr), imgInfo.size);
|
||||
|
||||
// Passed pointer doesn't have enough memory, copy is needed
|
||||
bool copyRequired = (alignedSizeRequiredForAllocation > alignedSizePassedPointer) |
|
||||
(imgInfo.rowPitch != hostPtrRowPitch) |
|
||||
(imgInfo.slicePitch != hostPtrSlicePitch) |
|
||||
((reinterpret_cast<uintptr_t>(hostPtr) & (MemoryConstants::cacheLineSize - 1)) != 0) |
|
||||
isTilingAllowed;
|
||||
|
||||
return copyRequired;
|
||||
}
|
||||
|
||||
cl_int Image::getImageInfo(cl_image_info paramName,
|
||||
size_t paramValueSize,
|
||||
void *paramValue,
|
||||
|
||||
@@ -109,6 +109,8 @@ class Image : public MemObj {
|
||||
return (type == CL_MEM_OBJECT_IMAGE3D) || (type == CL_MEM_OBJECT_IMAGE1D_ARRAY) || (type == CL_MEM_OBJECT_IMAGE2D_ARRAY);
|
||||
}
|
||||
|
||||
static bool isCopyRequired(ImageInfo &imgInfo, const void *hostPtr);
|
||||
|
||||
cl_int getImageInfo(cl_image_info paramName,
|
||||
size_t paramValueSize,
|
||||
void *paramValue,
|
||||
|
||||
Reference in New Issue
Block a user