mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
Validate and create image using MemoryProperties instead of flags.
Related-To: NEO-3147 Change-Id: I6c1f4383ec4ae1c35399f26ed953f1f20c203cf3 Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com>
This commit is contained in:
@@ -737,8 +737,7 @@ cl_mem CL_API_CALL clCreateImage(cl_context context,
|
||||
cl_int *errcodeRet) {
|
||||
TRACING_ENTER(clCreateImage, &context, &flags, &imageFormat, &imageDesc, &hostPtr, &errcodeRet);
|
||||
|
||||
Context *pContext = nullptr;
|
||||
auto retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
||||
API_ENTER(&retVal);
|
||||
DBG_LOG_INPUTS("cl_context", context,
|
||||
@@ -753,25 +752,15 @@ cl_mem CL_API_CALL clCreateImage(cl_context context,
|
||||
"hostPtr", hostPtr);
|
||||
|
||||
cl_mem image = nullptr;
|
||||
do {
|
||||
/* Are there some invalid flag bits? */
|
||||
if (!MemObjHelper::validateMemoryPropertiesForImage(flags, imageDesc->mem_object)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
bool isHostPtrUsed = (hostPtr != nullptr);
|
||||
bool areHostPtrFlagsUsed = isValueSet(flags, CL_MEM_COPY_HOST_PTR) || isValueSet(flags, CL_MEM_USE_HOST_PTR);
|
||||
if (isHostPtrUsed != areHostPtrFlagsUsed) {
|
||||
retVal = CL_INVALID_HOST_PTR;
|
||||
break;
|
||||
}
|
||||
image = Image::validateAndCreateImage(pContext, flags, imageFormat, imageDesc, hostPtr, retVal);
|
||||
Context *pContext = nullptr;
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
|
||||
} while (false);
|
||||
|
||||
if (errcodeRet) {
|
||||
*errcodeRet = retVal;
|
||||
if (retVal == CL_SUCCESS) {
|
||||
MemoryProperties propertiesStruct(flags);
|
||||
image = Image::validateAndCreateImage(pContext, propertiesStruct, imageFormat, imageDesc, hostPtr, retVal);
|
||||
}
|
||||
|
||||
ErrorCodeHelper err(errcodeRet, retVal);
|
||||
DBG_LOG_INPUTS("image", image);
|
||||
TRACING_EXIT(clCreateImage, &image);
|
||||
return image;
|
||||
@@ -787,8 +776,10 @@ cl_mem CL_API_CALL clCreateImage2D(cl_context context,
|
||||
void *hostPtr,
|
||||
cl_int *errcodeRet) {
|
||||
TRACING_ENTER(clCreateImage2D, &context, &flags, &imageFormat, &imageWidth, &imageHeight, &imageRowPitch, &hostPtr, &errcodeRet);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
|
||||
DBG_LOG_INPUTS("context", context,
|
||||
"flags", flags,
|
||||
"imageFormat", imageFormat,
|
||||
@@ -796,9 +787,6 @@ cl_mem CL_API_CALL clCreateImage2D(cl_context context,
|
||||
"imageHeight", imageHeight,
|
||||
"imageRowPitch", imageRowPitch,
|
||||
"hostPtr", hostPtr);
|
||||
Context *pContext = nullptr;
|
||||
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
|
||||
cl_mem image2D = nullptr;
|
||||
cl_image_desc imageDesc;
|
||||
@@ -809,11 +797,15 @@ cl_mem CL_API_CALL clCreateImage2D(cl_context context,
|
||||
imageDesc.image_row_pitch = imageRowPitch;
|
||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
|
||||
image2D = Image::validateAndCreateImage(pContext, flags, imageFormat, &imageDesc, hostPtr, retVal);
|
||||
Context *pContext = nullptr;
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
|
||||
if (errcodeRet) {
|
||||
*errcodeRet = retVal;
|
||||
if (retVal == CL_SUCCESS) {
|
||||
MemoryProperties propertiesStruct(flags);
|
||||
image2D = Image::validateAndCreateImage(pContext, propertiesStruct, imageFormat, &imageDesc, hostPtr, retVal);
|
||||
}
|
||||
|
||||
ErrorCodeHelper err(errcodeRet, retVal);
|
||||
DBG_LOG_INPUTS("image 2D", image2D);
|
||||
TRACING_EXIT(clCreateImage2D, &image2D);
|
||||
return image2D;
|
||||
@@ -831,8 +823,10 @@ cl_mem CL_API_CALL clCreateImage3D(cl_context context,
|
||||
void *hostPtr,
|
||||
cl_int *errcodeRet) {
|
||||
TRACING_ENTER(clCreateImage3D, &context, &flags, &imageFormat, &imageWidth, &imageHeight, &imageDepth, &imageRowPitch, &imageSlicePitch, &hostPtr, &errcodeRet);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
|
||||
DBG_LOG_INPUTS("context", context,
|
||||
"flags", flags,
|
||||
"imageFormat", imageFormat,
|
||||
@@ -843,10 +837,6 @@ cl_mem CL_API_CALL clCreateImage3D(cl_context context,
|
||||
"imageSlicePitch", imageSlicePitch,
|
||||
"hostPtr", hostPtr);
|
||||
|
||||
Context *pContext = nullptr;
|
||||
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
|
||||
cl_mem image3D = nullptr;
|
||||
cl_image_desc imageDesc;
|
||||
memset(&imageDesc, 0, sizeof(cl_image_desc));
|
||||
@@ -858,11 +848,15 @@ cl_mem CL_API_CALL clCreateImage3D(cl_context context,
|
||||
imageDesc.image_slice_pitch = imageSlicePitch;
|
||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
|
||||
image3D = Image::validateAndCreateImage(pContext, flags, imageFormat, &imageDesc, hostPtr, retVal);
|
||||
Context *pContext = nullptr;
|
||||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
|
||||
if (errcodeRet) {
|
||||
*errcodeRet = retVal;
|
||||
if (retVal == CL_SUCCESS) {
|
||||
MemoryProperties propertiesStruct(flags);
|
||||
image3D = Image::validateAndCreateImage(pContext, propertiesStruct, imageFormat, &imageDesc, hostPtr, retVal);
|
||||
}
|
||||
|
||||
ErrorCodeHelper err(errcodeRet, retVal);
|
||||
DBG_LOG_INPUTS("image 3D", image3D);
|
||||
TRACING_EXIT(clCreateImage3D, &image3D);
|
||||
return image3D;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace NEO {
|
||||
ImageFuncs imageFactory[IGFX_MAX_CORE] = {};
|
||||
|
||||
Image::Image(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_image_format imageFormat,
|
||||
@@ -52,7 +52,7 @@ Image::Image(Context *context,
|
||||
const SurfaceOffsets *surfaceOffsets)
|
||||
: MemObj(context,
|
||||
imageDesc.image_type,
|
||||
flags,
|
||||
properties,
|
||||
size,
|
||||
graphicsAllocation->getUnderlyingBuffer(),
|
||||
hostPtr,
|
||||
@@ -108,7 +108,7 @@ void Image::transferData(void *dest, size_t destRowPitch, size_t destSlicePitch,
|
||||
Image::~Image() = default;
|
||||
|
||||
Image *Image::create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
const SurfaceFormatInfo *surfaceFormat,
|
||||
const cl_image_desc *imageDesc,
|
||||
const void *hostPtr,
|
||||
@@ -132,7 +132,7 @@ Image *Image::create(Context *context,
|
||||
ImageInfo imgInfo = {0};
|
||||
void *hostPtrToSet = nullptr;
|
||||
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR)) {
|
||||
hostPtrToSet = const_cast<void *>(hostPtr);
|
||||
}
|
||||
|
||||
@@ -181,8 +181,8 @@ Image *Image::create(Context *context,
|
||||
|
||||
auto hostPtrRowPitch = imageDesc->image_row_pitch ? imageDesc->image_row_pitch : imageWidth * surfaceFormat->ImageElementSizeInBytes;
|
||||
auto hostPtrSlicePitch = imageDesc->image_slice_pitch ? imageDesc->image_slice_pitch : hostPtrRowPitch * imageHeight;
|
||||
auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc) && !MemObjHelper::isLinearStorageForced(flags);
|
||||
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, flags,
|
||||
auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc) && !MemObjHelper::isLinearStorageForced(properties);
|
||||
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, properties,
|
||||
context->peekContextType(), true);
|
||||
|
||||
switch (imageDesc->image_type) {
|
||||
@@ -247,10 +247,10 @@ Image *Image::create(Context *context,
|
||||
isTilingAllowed = parentImage->allowTiling();
|
||||
} else {
|
||||
errcodeRet = CL_OUT_OF_HOST_MEMORY;
|
||||
if (flags & CL_MEM_USE_HOST_PTR) {
|
||||
if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR)) {
|
||||
|
||||
if (!context->isSharedContext) {
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(imgInfo, false, flags);
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(imgInfo, false, properties);
|
||||
|
||||
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr);
|
||||
|
||||
@@ -274,7 +274,7 @@ Image *Image::create(Context *context,
|
||||
mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr);
|
||||
}
|
||||
} else {
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(imgInfo, true, flags);
|
||||
AllocationProperties allocProperties = MemObjHelper::getAllocationProperties(imgInfo, true, properties);
|
||||
memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties);
|
||||
|
||||
if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
|
||||
@@ -282,7 +282,7 @@ Image *Image::create(Context *context,
|
||||
}
|
||||
}
|
||||
}
|
||||
transferNeeded |= !!(flags & CL_MEM_COPY_HOST_PTR);
|
||||
transferNeeded |= isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR);
|
||||
|
||||
if (!memory) {
|
||||
break;
|
||||
@@ -291,7 +291,10 @@ Image *Image::create(Context *context,
|
||||
if (parentBuffer == nullptr) {
|
||||
memory->setAllocationType(GraphicsAllocation::AllocationType::IMAGE);
|
||||
}
|
||||
memory->setMemObjectsAllocationWithWritableFlags(!(flags & (CL_MEM_READ_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)));
|
||||
|
||||
memory->setMemObjectsAllocationWithWritableFlags(!isValueSet(properties.flags, CL_MEM_READ_ONLY) &&
|
||||
!isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY) &&
|
||||
!isValueSet(properties.flags, CL_MEM_HOST_NO_ACCESS));
|
||||
|
||||
DBG_LOG(LogMemoryObject, __FUNCTION__, "hostPtr:", hostPtr, "size:", memory->getUnderlyingBufferSize(), "memoryStorage:", memory->getUnderlyingBuffer(), "GPU address:", std::hex, memory->getGpuAddress());
|
||||
|
||||
@@ -307,7 +310,7 @@ Image *Image::create(Context *context,
|
||||
parentImage->incRefInternal();
|
||||
}
|
||||
|
||||
image = createImageHw(context, flags, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat,
|
||||
image = createImageHw(context, properties, imgInfo.size, hostPtrToSet, surfaceFormat->OCLImageFormat,
|
||||
imageDescriptor, zeroCopy, memory, false, isTilingAllowed, 0, 0, surfaceFormat);
|
||||
|
||||
if (imageDesc->image_type != CL_MEM_OBJECT_IMAGE1D_ARRAY && imageDesc->image_type != CL_MEM_OBJECT_IMAGE2D_ARRAY) {
|
||||
@@ -377,7 +380,7 @@ Image *Image::create(Context *context,
|
||||
return image;
|
||||
}
|
||||
|
||||
Image *Image::createImageHw(Context *context, cl_mem_flags flags, size_t size, void *hostPtr,
|
||||
Image *Image::createImageHw(Context *context, const MemoryProperties &properties, size_t size, void *hostPtr,
|
||||
const cl_image_format &imageFormat, const cl_image_desc &imageDesc,
|
||||
bool zeroCopy, GraphicsAllocation *graphicsAllocation,
|
||||
bool isObjectRedescribed, bool createTiledImage, uint32_t baseMipLevel, uint32_t mipCount,
|
||||
@@ -387,7 +390,7 @@ Image *Image::createImageHw(Context *context, cl_mem_flags flags, size_t size, v
|
||||
|
||||
auto funcCreate = imageFactory[hwInfo.platform.eRenderCoreFamily].createImageFunction;
|
||||
DEBUG_BREAK_IF(nullptr == funcCreate);
|
||||
auto image = funcCreate(context, flags, size, hostPtr, imageFormat, imageDesc,
|
||||
auto image = funcCreate(context, properties, size, hostPtr, imageFormat, imageDesc,
|
||||
zeroCopy, graphicsAllocation, isObjectRedescribed, createTiledImage, baseMipLevel, mipCount, surfaceFormatInfo, nullptr);
|
||||
DEBUG_BREAK_IF(nullptr == image);
|
||||
image->createFunction = funcCreate;
|
||||
@@ -413,7 +416,7 @@ Image *Image::createSharedImage(Context *context, SharingHandler *sharingHandler
|
||||
}
|
||||
|
||||
cl_int Image::validate(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
const SurfaceFormatInfo *surfaceFormat,
|
||||
const cl_image_desc *imageDesc,
|
||||
const void *hostPtr) {
|
||||
@@ -448,7 +451,7 @@ cl_int Image::validate(Context *context,
|
||||
((parentBuffer->getFlags() & CL_MEM_USE_HOST_PTR) && (reinterpret_cast<uint64_t>(parentBuffer->getHostPtr()) % (*baseAddressAlignment))) ||
|
||||
(minimumBufferSize > parentBuffer->getSize())) {
|
||||
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
|
||||
} else if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) {
|
||||
} else if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) || isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR)) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
@@ -483,7 +486,7 @@ cl_int Image::validate(Context *context,
|
||||
return CL_INVALID_IMAGE_DESCRIPTOR;
|
||||
}
|
||||
|
||||
return validateImageTraits(context, flags, &surfaceFormat->OCLImageFormat, imageDesc, hostPtr);
|
||||
return validateImageTraits(context, properties.flags, &surfaceFormat->OCLImageFormat, imageDesc, hostPtr);
|
||||
}
|
||||
|
||||
cl_int Image::validateImageFormat(const cl_image_format *imageFormat) {
|
||||
@@ -1010,32 +1013,42 @@ bool Image::isDepthFormat(const cl_image_format &imageFormat) {
|
||||
}
|
||||
|
||||
Image *Image::validateAndCreateImage(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
const cl_image_format *imageFormat,
|
||||
const cl_image_desc *imageDesc,
|
||||
const void *hostPtr,
|
||||
cl_int &errcodeRet) {
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
|
||||
if (!MemObjHelper::validateMemoryPropertiesForImage(properties, imageDesc->mem_object)) {
|
||||
errcodeRet = CL_INVALID_VALUE;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool isHostPtrUsed = (hostPtr != nullptr);
|
||||
bool areHostPtrFlagsUsed = isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR) || isValueSet(properties.flags, CL_MEM_USE_HOST_PTR);
|
||||
if (isHostPtrUsed != areHostPtrFlagsUsed) {
|
||||
errcodeRet = CL_INVALID_HOST_PTR;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!context->getDevice(0)->getDeviceInfo().imageSupport) {
|
||||
errcodeRet = CL_INVALID_OPERATION;
|
||||
return nullptr;
|
||||
}
|
||||
Image *image = nullptr;
|
||||
do {
|
||||
errcodeRet = Image::validateImageFormat(imageFormat);
|
||||
if (CL_SUCCESS != errcodeRet) {
|
||||
break;
|
||||
}
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, imageFormat);
|
||||
errcodeRet = Image::validate(context, flags, surfaceFormat, imageDesc, hostPtr);
|
||||
if (CL_SUCCESS != errcodeRet) {
|
||||
break;
|
||||
}
|
||||
image = Image::create(context, flags, surfaceFormat, imageDesc, hostPtr, errcodeRet);
|
||||
} while (false);
|
||||
return image;
|
||||
|
||||
errcodeRet = Image::validateImageFormat(imageFormat);
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto surfaceFormat = Image::getSurfaceFormatFromTable(properties.flags, imageFormat);
|
||||
|
||||
errcodeRet = Image::validate(context, properties, surfaceFormat, imageDesc, hostPtr);
|
||||
if (errcodeRet != CL_SUCCESS) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Image::create(context, properties, surfaceFormat, imageDesc, hostPtr, errcodeRet);
|
||||
}
|
||||
|
||||
bool Image::isValidSingleChannelFormat(const cl_image_format *imageFormat) {
|
||||
|
||||
@@ -25,7 +25,7 @@ struct SurfaceOffsets {
|
||||
};
|
||||
|
||||
typedef Image *(*ImageCreatFunc)(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
const cl_image_format &imageFormat,
|
||||
@@ -51,20 +51,20 @@ class Image : public MemObj {
|
||||
~Image() override;
|
||||
|
||||
static Image *create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
const SurfaceFormatInfo *surfaceFormat,
|
||||
const cl_image_desc *imageDesc,
|
||||
const void *hostPtr,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static Image *validateAndCreateImage(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
const cl_image_format *imageFormat,
|
||||
const cl_image_desc *imageDesc,
|
||||
const void *hostPtr,
|
||||
cl_int &errcodeRet);
|
||||
|
||||
static Image *createImageHw(Context *context, cl_mem_flags flags, size_t size, void *hostPtr,
|
||||
static Image *createImageHw(Context *context, const MemoryProperties &properties, size_t size, void *hostPtr,
|
||||
const cl_image_format &imageFormat, const cl_image_desc &imageDesc,
|
||||
bool zeroCopy, GraphicsAllocation *graphicsAllocation,
|
||||
bool isObjectRedescribed, bool createTiledImage, uint32_t baseMipLevel, uint32_t mipCount, const SurfaceFormatInfo *surfaceFormatInfo = nullptr);
|
||||
@@ -74,7 +74,7 @@ class Image : public MemObj {
|
||||
cl_mem_flags flags, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount);
|
||||
|
||||
static cl_int validate(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
const SurfaceFormatInfo *surfaceFormat,
|
||||
const cl_image_desc *imageDesc,
|
||||
const void *hostPtr);
|
||||
@@ -183,7 +183,7 @@ class Image : public MemObj {
|
||||
|
||||
protected:
|
||||
Image(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_image_format imageFormat,
|
||||
@@ -238,7 +238,7 @@ class ImageHw : public Image {
|
||||
|
||||
public:
|
||||
ImageHw(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
const cl_image_format &imageFormat,
|
||||
@@ -251,7 +251,7 @@ class ImageHw : public Image {
|
||||
uint32_t mipCount,
|
||||
const SurfaceFormatInfo &surfaceFormatInfo,
|
||||
const SurfaceOffsets *surfaceOffsets = nullptr)
|
||||
: Image(context, flags, size, hostPtr, imageFormat, imageDesc,
|
||||
: Image(context, properties, size, hostPtr, imageFormat, imageDesc,
|
||||
zeroCopy, graphicsAllocation, isObjectRedescribed, createTiledImage, baseMipLevel, mipCount, surfaceFormatInfo, surfaceOffsets) {
|
||||
if (getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D ||
|
||||
getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER ||
|
||||
@@ -275,7 +275,7 @@ class ImageHw : public Image {
|
||||
void transformImage2dArrayTo3d(void *memory) override;
|
||||
void transformImage3dTo2dArray(void *memory) override;
|
||||
static Image *create(Context *context,
|
||||
cl_mem_flags flags,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
const cl_image_format &imageFormat,
|
||||
@@ -290,7 +290,7 @@ class ImageHw : public Image {
|
||||
const SurfaceOffsets *surfaceOffsets) {
|
||||
UNRECOVERABLE_IF(surfaceFormatInfo == nullptr);
|
||||
auto image = new ImageHw<GfxFamily>(context,
|
||||
flags,
|
||||
properties,
|
||||
size,
|
||||
hostPtr,
|
||||
imageFormat,
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace NEO {
|
||||
|
||||
MemObj::MemObj(Context *context,
|
||||
cl_mem_object_type memObjectType,
|
||||
MemoryProperties properties,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
|
||||
@@ -38,7 +38,7 @@ class MemObj : public BaseObject<_cl_mem> {
|
||||
|
||||
MemObj(Context *context,
|
||||
cl_mem_object_type memObjectType,
|
||||
MemoryProperties properties,
|
||||
const MemoryProperties &properties,
|
||||
size_t size,
|
||||
void *memoryStorage,
|
||||
void *hostPtr,
|
||||
|
||||
@@ -31,7 +31,7 @@ bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properti
|
||||
return true;
|
||||
}
|
||||
|
||||
void MemObjHelper::fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties) {
|
||||
void MemObjHelper::fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryProperties &memoryProperties) {
|
||||
fillCachePolicyInProperties(allocationProperties,
|
||||
isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE),
|
||||
isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY),
|
||||
|
||||
@@ -95,13 +95,13 @@ class MemObjHelper {
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
static AllocationProperties getAllocationProperties(ImageInfo &imgInfo, bool allocateMemory, MemoryProperties memoryProperties) {
|
||||
static AllocationProperties getAllocationProperties(ImageInfo &imgInfo, bool allocateMemory, const MemoryProperties &memoryProperties) {
|
||||
AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE};
|
||||
fillPoliciesInProperties(allocationProperties, memoryProperties);
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
static void fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties);
|
||||
static void fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryProperties &memoryProperties);
|
||||
|
||||
static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly,
|
||||
bool deviceOnlyVisibilty) {
|
||||
|
||||
@@ -136,11 +136,14 @@ TEST_F(Image2dFromBufferTest, InvalidHostPtrAlignment) {
|
||||
imageDesc.mem_object = origBuffer;
|
||||
}
|
||||
|
||||
TEST_F(Image2dFromBufferTest, InvalidFlags) {
|
||||
cl_mem_flags flags = CL_MEM_USE_HOST_PTR;
|
||||
auto surfaceFormat = (SurfaceFormatInfo *)Image::getSurfaceFormatFromTable(flags, &imageFormat);
|
||||
retVal = Image::validate(&context, flags, surfaceFormat, &imageDesc, reinterpret_cast<void *>(0x12345));
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
TEST_F(Image2dFromBufferTest, givenInvalidFlagsWhenValidateIsCalledThenReturnError) {
|
||||
cl_mem_flags flags[] = {CL_MEM_USE_HOST_PTR, CL_MEM_COPY_HOST_PTR};
|
||||
|
||||
for (auto flag : flags) {
|
||||
const auto surfaceFormat = Image::getSurfaceFormatFromTable(flag, &imageFormat);
|
||||
retVal = Image::validate(&context, flag, surfaceFormat, &imageDesc, reinterpret_cast<void *>(0x12345));
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Image2dFromBufferTest, givenOneChannel8BitColorsNoRowPitchSpecifiedAndTooLargeImageWhenValidatingSurfaceFormatThenReturnError) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "runtime/helpers/convert_color.h"
|
||||
#include "runtime/helpers/surface_formats.h"
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "unit_tests/fixtures/image_fixture.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "unit_tests/mocks/mock_graphics_allocation.h"
|
||||
|
||||
@@ -662,17 +663,6 @@ TEST(ImageFormat, givenNullptrImageFormatWhenValidateImageFormatIsCalledThenRetu
|
||||
EXPECT_EQ(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, retVal);
|
||||
}
|
||||
|
||||
TEST(validateAndCreateImage, givenErrorCodeWhenValidateAndCreateImageIsCalledThenReturnsError) {
|
||||
cl_image_format imageFormat;
|
||||
cl_int retVal = CL_INVALID_VALUE;
|
||||
Image *image;
|
||||
imageFormat.image_channel_order = 0;
|
||||
imageFormat.image_channel_data_type = 0;
|
||||
image = Image::validateAndCreateImage(nullptr, 0, &imageFormat, nullptr, nullptr, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
}
|
||||
|
||||
TEST(validateAndCreateImage, givenInvalidImageFormatWhenValidateAndCreateImageIsCalledThenReturnsInvalidDescriptorError) {
|
||||
MockContext context;
|
||||
cl_image_format imageFormat;
|
||||
@@ -680,7 +670,7 @@ TEST(validateAndCreateImage, givenInvalidImageFormatWhenValidateAndCreateImageIs
|
||||
Image *image;
|
||||
imageFormat.image_channel_order = 0;
|
||||
imageFormat.image_channel_data_type = 0;
|
||||
image = Image::validateAndCreateImage(&context, 0, &imageFormat, nullptr, nullptr, retVal);
|
||||
image = Image::validateAndCreateImage(&context, 0, &imageFormat, &Image1dDefaults::imageDesc, nullptr, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
EXPECT_EQ(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, retVal);
|
||||
}
|
||||
@@ -690,7 +680,7 @@ TEST(validateAndCreateImage, givenNotSupportedImageFormatWhenValidateAndCreateIm
|
||||
cl_image_format imageFormat = {CL_INTENSITY, CL_UNORM_INT8};
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
Image *image;
|
||||
image = Image::validateAndCreateImage(&context, CL_MEM_READ_WRITE, &imageFormat, nullptr, nullptr, retVal);
|
||||
image = Image::validateAndCreateImage(&context, CL_MEM_READ_WRITE, &imageFormat, &Image1dDefaults::imageDesc, nullptr, retVal);
|
||||
EXPECT_EQ(nullptr, image);
|
||||
EXPECT_EQ(CL_IMAGE_FORMAT_NOT_SUPPORTED, retVal);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user