Fix image 2d validation

check image sizes only for image without parent mem object

Change-Id: I73189f1c73653f609c6e4d7dcb7a85d06a2f858a
This commit is contained in:
Mateusz Jablonski
2018-04-10 09:19:27 +02:00
parent a9b0a4868c
commit 1843b23692
2 changed files with 36 additions and 5 deletions

View File

@ -455,15 +455,13 @@ cl_int Image::validate(Context *context,
if (!parentImage->hasSameDescriptor(*imageDesc) || !parentImage->hasValidParentImageFormat(surfaceFormat->OCLImageFormat)) {
retVal = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
}
} else if (imageDesc->image_width == 0 ||
imageDesc->image_height == 0) {
}
if (!imageDesc->mem_object && (imageDesc->image_width == 0 ||
imageDesc->image_height == 0)) {
retVal = CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
default:
if (parentImage) {
retVal = CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
}
if (hostPtr == nullptr) {

View File

@ -892,3 +892,36 @@ TEST(ImageFormatValidatorTest, givenValidParentChannelOrderAndChannelOrderWhenFo
imageFormat.image_channel_order = CL_sBGRA;
EXPECT_FALSE(image.hasValidParentImageFormat(imageFormat));
};
TEST(ImageValidatorTest, givenInvalidImage2dSizesWithoutParentObjectWhenValidateImageThenReturnsError) {
MockContext context;
cl_image_desc descriptor;
void *dummyPtr = reinterpret_cast<void *>(0x17);
SurfaceFormatInfo surfaceFormat;
descriptor.image_type = CL_MEM_OBJECT_IMAGE2D;
descriptor.image_row_pitch = 0;
descriptor.image_height = 1;
descriptor.image_width = 0;
descriptor.mem_object = nullptr;
EXPECT_EQ(CL_INVALID_IMAGE_DESCRIPTOR, Image::validate(&context, 0, &surfaceFormat, &descriptor, dummyPtr));
descriptor.image_height = 0;
descriptor.image_width = 1;
EXPECT_EQ(CL_INVALID_IMAGE_DESCRIPTOR, Image::validate(&context, 0, &surfaceFormat, &descriptor, dummyPtr));
};
TEST(ImageValidatorTest, givenNV12Image2dAsParentImageWhenValidateImageZeroSizedThenReturnsSuccess) {
NullImage image;
cl_image_desc descriptor;
MockContext context;
void *dummyPtr = reinterpret_cast<void *>(0x17);
SurfaceFormatInfo surfaceFormat;
image.imageFormat.image_channel_order = CL_NV12_INTEL;
descriptor.image_type = CL_MEM_OBJECT_IMAGE2D;
descriptor.image_height = 0;
descriptor.image_width = 0;
descriptor.image_row_pitch = 0;
descriptor.mem_object = &image;
EXPECT_EQ(CL_SUCCESS, Image::validate(&context, 0, &surfaceFormat, &descriptor, dummyPtr));
};