mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Prefer unique_ptr instead of raw pointer nv12 ults
Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com> Related-To: NEO-4692
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
ef07bbd041
commit
dbe3ef21c1
@ -2771,7 +2771,7 @@ cl_int CL_API_CALL clEnqueueReadImage(cl_command_queue commandQueue,
|
||||
TRACING_EXIT(clEnqueueReadImage, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
if (IsPackedYuvImage(&pImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(origin, region);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
TRACING_EXIT(clEnqueueReadImage, &retVal);
|
||||
@ -2844,7 +2844,7 @@ cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue commandQueue,
|
||||
TRACING_EXIT(clEnqueueWriteImage, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
if (IsPackedYuvImage(&pImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(origin, region);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
TRACING_EXIT(clEnqueueWriteImage, &retVal);
|
||||
@ -2971,14 +2971,14 @@ cl_int CL_API_CALL clEnqueueCopyImage(cl_command_queue commandQueue,
|
||||
TRACING_EXIT(clEnqueueCopyImage, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
if (IsPackedYuvImage(&pSrcImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pSrcImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(srcOrigin, region);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
TRACING_EXIT(clEnqueueCopyImage, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
if (IsPackedYuvImage(&pDstImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pDstImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(dstOrigin, region);
|
||||
|
||||
if (retVal != CL_SUCCESS) {
|
||||
@ -3054,7 +3054,7 @@ cl_int CL_API_CALL clEnqueueCopyImageToBuffer(cl_command_queue commandQueue,
|
||||
WithCastToInternal(dstBuffer, &pDstBuffer));
|
||||
|
||||
if (CL_SUCCESS == retVal) {
|
||||
if (IsPackedYuvImage(&pSrcImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pSrcImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(srcOrigin, region);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
TRACING_EXIT(clEnqueueCopyImageToBuffer, &retVal);
|
||||
@ -3119,7 +3119,7 @@ cl_int CL_API_CALL clEnqueueCopyBufferToImage(cl_command_queue commandQueue,
|
||||
WithCastToInternal(dstImage, &pDstImage));
|
||||
|
||||
if (CL_SUCCESS == retVal) {
|
||||
if (IsPackedYuvImage(&pDstImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pDstImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(dstOrigin, region);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
TRACING_EXIT(clEnqueueCopyBufferToImage, &retVal);
|
||||
@ -3264,7 +3264,7 @@ void *CL_API_CALL clEnqueueMapImage(cl_command_queue commandQueue,
|
||||
retVal = CL_INVALID_OPERATION;
|
||||
break;
|
||||
}
|
||||
if (IsPackedYuvImage(&pImage->getImageFormat())) {
|
||||
if (isPackedYuvImage(&pImage->getImageFormat())) {
|
||||
retVal = validateYuvOperation(origin, region);
|
||||
if (retVal != CL_SUCCESS) {
|
||||
break;
|
||||
|
@ -168,10 +168,10 @@ ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags
|
||||
}
|
||||
|
||||
ArrayRef<const ClSurfaceFormatInfo> SurfaceFormats::surfaceFormats(cl_mem_flags flags, const cl_image_format *imageFormat, bool supportsOcl20Features) noexcept {
|
||||
if (NEO::IsNV12Image(imageFormat)) {
|
||||
if (NEO::isNV12Image(imageFormat)) {
|
||||
return planarYuv();
|
||||
}
|
||||
else if (IsPackedYuvImage(imageFormat)) {
|
||||
else if (isPackedYuvImage(imageFormat)) {
|
||||
return packedYuv();
|
||||
}
|
||||
else if (Image::isDepthFormat(*imageFormat)) {
|
||||
|
@ -148,7 +148,7 @@ cl_int validateYuvOperation(const size_t *origin, const size_t *region) {
|
||||
return ((origin[0] % 2 == 0) && (region[0] % 2 == 0)) ? CL_SUCCESS : CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
bool IsPackedYuvImage(const cl_image_format *imageFormat) {
|
||||
bool isPackedYuvImage(const cl_image_format *imageFormat) {
|
||||
auto channelOrder = imageFormat->image_channel_order;
|
||||
return (channelOrder == CL_YUYV_INTEL) ||
|
||||
(channelOrder == CL_UYVY_INTEL) ||
|
||||
@ -156,7 +156,7 @@ bool IsPackedYuvImage(const cl_image_format *imageFormat) {
|
||||
(channelOrder == CL_VYUY_INTEL);
|
||||
}
|
||||
|
||||
bool IsNV12Image(const cl_image_format *imageFormat) {
|
||||
bool isNV12Image(const cl_image_format *imageFormat) {
|
||||
return imageFormat->image_channel_order == CL_NV12_INTEL;
|
||||
}
|
||||
} // namespace NEO
|
||||
|
@ -85,6 +85,6 @@ bool areNotNullptr(T t, RT... rt) {
|
||||
}
|
||||
|
||||
cl_int validateYuvOperation(const size_t *origin, const size_t *region);
|
||||
bool IsPackedYuvImage(const cl_image_format *imageFormat);
|
||||
bool IsNV12Image(const cl_image_format *imageFormat);
|
||||
bool isPackedYuvImage(const cl_image_format *imageFormat);
|
||||
bool isNV12Image(const cl_image_format *imageFormat);
|
||||
} // namespace NEO
|
||||
|
@ -180,7 +180,7 @@ Image *Image::create(Context *context,
|
||||
imageWidth = parentImage->getImageDesc().image_width;
|
||||
imageHeight = parentImage->getImageDesc().image_height;
|
||||
imageDepth = 1;
|
||||
if (IsNV12Image(&parentImage->getImageFormat())) {
|
||||
if (isNV12Image(&parentImage->getImageFormat())) {
|
||||
if (imageDesc->image_depth == 1) { // UV Plane
|
||||
imageWidth /= 2;
|
||||
imageHeight /= 2;
|
||||
@ -212,7 +212,7 @@ Image *Image::create(Context *context,
|
||||
hostPtrMinSize = hostPtrSlicePitch * imageDepth;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
if (IsNV12Image(&surfaceFormat->OCLImageFormat)) {
|
||||
if (isNV12Image(&surfaceFormat->OCLImageFormat)) {
|
||||
hostPtrMinSize = hostPtrRowPitch * imageHeight + hostPtrRowPitch * imageHeight / 2;
|
||||
} else {
|
||||
hostPtrMinSize = hostPtrRowPitch * imageHeight;
|
||||
@ -466,7 +466,7 @@ Image *Image::create(Context *context,
|
||||
if (!isCpuTransferPreferrred) {
|
||||
auto cmdQ = context->getSpecialQueue(rootDeviceIndex);
|
||||
|
||||
if (IsNV12Image(&image->getImageFormat())) {
|
||||
if (isNV12Image(&image->getImageFormat())) {
|
||||
errcodeRet = image->writeNV12Planes(hostPtr, hostPtrRowPitch, rootDeviceIndex);
|
||||
} else {
|
||||
errcodeRet = cmdQ->enqueueWriteImage(image, CL_TRUE, ©Origin[0], ©Region[0],
|
||||
@ -588,12 +588,12 @@ cl_int Image::validate(Context *context,
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
if (parentImage && !IsNV12Image(&parentImage->getImageFormat())) { // Image 2d from image 2d
|
||||
if (parentImage && !isNV12Image(&parentImage->getImageFormat())) { // Image 2d from image 2d
|
||||
if (!parentImage->hasSameDescriptor(*imageDesc) || !parentImage->hasValidParentImageFormat(surfaceFormat->OCLImageFormat)) {
|
||||
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
|
||||
}
|
||||
}
|
||||
if (!(parentImage && IsNV12Image(&parentImage->getImageFormat())) &&
|
||||
if (!(parentImage && isNV12Image(&parentImage->getImageFormat())) &&
|
||||
(imageDesc->image_width == 0 || imageDesc->image_height == 0)) {
|
||||
return CL_INVALID_IMAGE_DESCRIPTOR;
|
||||
}
|
||||
@ -713,9 +713,9 @@ cl_int Image::validatePackedYUV(const MemoryProperties &memoryProperties, const
|
||||
}
|
||||
|
||||
cl_int Image::validateImageTraits(Context *context, const MemoryProperties &memoryProperties, const cl_image_format *imageFormat, const cl_image_desc *imageDesc, const void *hostPtr) {
|
||||
if (IsNV12Image(imageFormat))
|
||||
if (isNV12Image(imageFormat))
|
||||
return validatePlanarYUV(context, memoryProperties, imageDesc, hostPtr);
|
||||
else if (IsPackedYuvImage(imageFormat))
|
||||
else if (isPackedYuvImage(imageFormat))
|
||||
return validatePackedYUV(memoryProperties, imageDesc);
|
||||
|
||||
return CL_SUCCESS;
|
||||
@ -1418,7 +1418,7 @@ bool Image::isValidDepthStencilFormat(const cl_image_format *imageFormat) {
|
||||
bool Image::isValidYUVFormat(const cl_image_format *imageFormat) {
|
||||
auto dataType = imageFormat->image_channel_data_type;
|
||||
|
||||
bool isValidOrder = IsNV12Image(imageFormat) || IsPackedYuvImage(imageFormat);
|
||||
bool isValidOrder = isNV12Image(imageFormat) || isPackedYuvImage(imageFormat);
|
||||
|
||||
bool isValidDataType = (dataType == CL_UNORM_INT8);
|
||||
|
||||
|
@ -45,7 +45,7 @@ void ImageHw<GfxFamily>::setImageArg(void *memory, bool setAsMediaBlockImage, ui
|
||||
imgInfo.qPitch = qPitch;
|
||||
imgInfo.surfaceFormat = &getSurfaceFormatInfo().surfaceFormat;
|
||||
|
||||
setImageSurfaceState<GfxFamily>(surfaceState, imgInfo, graphicsAllocation->getDefaultGmm(), *gmmHelper, cubeFaceIndex, graphicsAllocation->getGpuAddress(), surfaceOffsets, IsNV12Image(&this->getImageFormat()));
|
||||
setImageSurfaceState<GfxFamily>(surfaceState, imgInfo, graphicsAllocation->getDefaultGmm(), *gmmHelper, cubeFaceIndex, graphicsAllocation->getGpuAddress(), surfaceOffsets, isNV12Image(&this->getImageFormat()));
|
||||
|
||||
if (getImageDesc().image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) {
|
||||
// image1d_buffer is image1d created from buffer. The length of buffer could be larger
|
||||
@ -171,7 +171,7 @@ void ImageHw<GfxFamily>::setMediaImageArg(void *memory, uint32_t rootDeviceIndex
|
||||
reinterpret_cast<void *>(&state),
|
||||
gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE));
|
||||
|
||||
if (IsNV12Image(&this->getImageFormat())) {
|
||||
if (isNV12Image(&this->getImageFormat())) {
|
||||
state.setInterleaveChroma(true);
|
||||
state.setYOffsetForUCb(this->surfaceOffsets.yOffsetForUVplane);
|
||||
}
|
||||
|
@ -94,10 +94,9 @@ class Nv12ImageTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(Nv12ImageTest, WhenImageIsCreatedThenIsNv12ImageIsTrue) {
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
EXPECT_TRUE(IsNV12Image(&image->getImageFormat()));
|
||||
delete image;
|
||||
EXPECT_TRUE(isNV12Image(&image->getImageFormat()));
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, GivenValidImageWhenValidatingThenSuccessIsReturned) {
|
||||
@ -138,83 +137,65 @@ TEST_F(Nv12ImageTest, GivenInvalidImageFlagWhenValidatingThenInvalidValueErrorIs
|
||||
TEST_F(Nv12ImageTest, GivenYPlaneWhenValidatingThenSuccessIsReturned) {
|
||||
REQUIRE_IMAGES_OR_SKIP(&context);
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
imageDesc.mem_object = image;
|
||||
imageDesc.mem_object = image.get();
|
||||
imageDesc.image_depth = 0; // Plane Y of NV12 image
|
||||
|
||||
validateImageWithFlags(CL_MEM_READ_WRITE);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, GivenUVPlaneWhenValidatingThenSuccessIsReturned) {
|
||||
REQUIRE_IMAGES_OR_SKIP(&context);
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
imageDesc.mem_object = image;
|
||||
imageDesc.mem_object = image.get();
|
||||
imageDesc.image_depth = 1; // Plane UV of NV12 image
|
||||
|
||||
validateImageWithFlags(CL_MEM_READ_WRITE);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, GivenInvalidImageDepthWhenValidatingThenInvalidImageDescriptorErrorIsReturned) {
|
||||
REQUIRE_IMAGES_OR_SKIP(&context);
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
imageDesc.mem_object = image;
|
||||
imageDesc.mem_object = image.get();
|
||||
imageDesc.image_depth = 3; // Invalid Plane of NV12 image
|
||||
|
||||
validateImageWithFlags(CL_MEM_READ_WRITE);
|
||||
EXPECT_EQ(CL_INVALID_IMAGE_DESCRIPTOR, retVal);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, given2DImageWhenPassedToValidateImageTraitsThenValidateReturnsSuccess) {
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
imageDesc.mem_object = image;
|
||||
imageDesc.mem_object = image.get();
|
||||
imageDesc.image_depth = 0;
|
||||
|
||||
retVal = Image::validateImageTraits(
|
||||
&context, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
|
||||
&imageFormat, &imageDesc, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, given1DImageWhenPassedAsParentImageThenValidateImageTraitsReturnsSuccess) {
|
||||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D;
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
imageDesc.mem_object = image;
|
||||
imageDesc.mem_object = image.get();
|
||||
imageDesc.image_depth = 0;
|
||||
|
||||
retVal = Image::validateImageTraits(
|
||||
&context, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
|
||||
&imageFormat, &imageDesc, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, givenBufferWhenPassedAsNV12ParentImageThenValidateImageTraitsReturnsInvalidDesriptor) {
|
||||
@ -230,44 +211,33 @@ TEST_F(Nv12ImageTest, givenBufferWhenPassedAsNV12ParentImageThenValidateImageTra
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, WhenImageIsCreatedThenOffsetsAreZero) {
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
auto rowPitch = image->getHostPtrRowPitch();
|
||||
EXPECT_NE(0u, rowPitch);
|
||||
|
||||
SurfaceOffsets surfaceOffsets;
|
||||
image->getSurfaceOffsets(surfaceOffsets);
|
||||
|
||||
EXPECT_EQ(0u, surfaceOffsets.offset);
|
||||
EXPECT_EQ(0u, surfaceOffsets.xOffset);
|
||||
EXPECT_EQ(0u, surfaceOffsets.yOffset);
|
||||
EXPECT_NE(0u, surfaceOffsets.yOffsetForUVplane);
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, WhenCreatingYPlaneImageThenDimensionsAreSetCorrectly) {
|
||||
|
||||
// Create Parent NV12 image
|
||||
auto imageNV12 = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> imageNV12{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, imageNV12);
|
||||
|
||||
imageDesc.mem_object = imageNV12;
|
||||
|
||||
imageDesc.mem_object = imageNV12.get();
|
||||
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
||||
imageFormat.image_channel_order = CL_R;
|
||||
|
||||
imageDesc.image_width = 0;
|
||||
imageDesc.image_height = 0;
|
||||
imageDesc.image_depth = 0;
|
||||
|
||||
// Create NV12 Y Plane image
|
||||
auto imageYPlane = createImageWithFlags(CL_MEM_READ_WRITE);
|
||||
|
||||
std::unique_ptr<Image> imageYPlane{createImageWithFlags(CL_MEM_READ_WRITE)};
|
||||
ASSERT_NE(nullptr, imageYPlane);
|
||||
EXPECT_EQ(true, imageYPlane->isImageFromImage());
|
||||
EXPECT_EQ(imageNV12->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()),
|
||||
@ -281,38 +251,29 @@ TEST_F(Nv12ImageTest, WhenCreatingYPlaneImageThenDimensionsAreSetCorrectly) {
|
||||
EXPECT_EQ(parentDimensions.image_width, planeDimensions.image_width);
|
||||
EXPECT_EQ(0u, planeDimensions.image_depth);
|
||||
EXPECT_NE(0u, planeDimensions.image_row_pitch);
|
||||
|
||||
EXPECT_EQ(parentDimensions.image_slice_pitch, planeDimensions.image_slice_pitch);
|
||||
EXPECT_EQ(parentDimensions.image_type, planeDimensions.image_type);
|
||||
EXPECT_EQ(parentDimensions.image_array_size, planeDimensions.image_array_size);
|
||||
|
||||
computeExpectedOffsets(imageYPlane);
|
||||
computeExpectedOffsets(imageNV12);
|
||||
|
||||
delete imageYPlane;
|
||||
delete imageNV12;
|
||||
computeExpectedOffsets(imageYPlane.get());
|
||||
computeExpectedOffsets(imageNV12.get());
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, WhenCreatingUVPlaneImageThenDimensionsAreSetCorrectly) {
|
||||
// Create Parent NV12 image
|
||||
auto imageNV12 = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> imageNV12{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, imageNV12);
|
||||
|
||||
imageDesc.mem_object = imageNV12;
|
||||
|
||||
imageDesc.mem_object = imageNV12.get();
|
||||
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
||||
imageFormat.image_channel_order = CL_R;
|
||||
|
||||
imageDesc.image_width = 0;
|
||||
imageDesc.image_height = 0;
|
||||
imageDesc.image_depth = 1; // UV plane
|
||||
|
||||
// Create NV12 UV Plane image
|
||||
auto imageUVPlane = createImageWithFlags(CL_MEM_READ_WRITE);
|
||||
|
||||
std::unique_ptr<Image> imageUVPlane{createImageWithFlags(CL_MEM_READ_WRITE)};
|
||||
ASSERT_NE(nullptr, imageUVPlane);
|
||||
|
||||
EXPECT_EQ(true, imageUVPlane->isImageFromImage());
|
||||
EXPECT_EQ(imageNV12->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()),
|
||||
imageUVPlane->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
||||
@ -331,38 +292,30 @@ TEST_F(Nv12ImageTest, WhenCreatingUVPlaneImageThenDimensionsAreSetCorrectly) {
|
||||
EXPECT_EQ(parentDimensions.image_type, planeDimensions.image_type);
|
||||
EXPECT_EQ(parentDimensions.image_array_size, planeDimensions.image_array_size);
|
||||
|
||||
computeExpectedOffsets(imageUVPlane);
|
||||
computeExpectedOffsets(imageNV12);
|
||||
|
||||
delete imageUVPlane;
|
||||
delete imageNV12;
|
||||
computeExpectedOffsets(imageUVPlane.get());
|
||||
computeExpectedOffsets(imageNV12.get());
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, GivenOffsetOfUVPlaneWhenCreatingUVPlaneImageThenDimensionsAreSetCorrectly) {
|
||||
|
||||
// This size returns offset of UV plane, and 0 yOffset
|
||||
imageDesc.image_height = 64; // Valid values multiple of 4
|
||||
imageDesc.image_width = 64; // Valid values multiple of 4
|
||||
|
||||
// Create Parent NV12 image
|
||||
auto imageNV12 = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> imageNV12{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, imageNV12);
|
||||
|
||||
imageDesc.mem_object = imageNV12;
|
||||
|
||||
imageDesc.mem_object = imageNV12.get();
|
||||
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
||||
imageFormat.image_channel_order = CL_R;
|
||||
|
||||
imageDesc.image_width = 0;
|
||||
imageDesc.image_height = 0;
|
||||
imageDesc.image_depth = 1; // UV plane
|
||||
|
||||
// Create NV12 UV Plane image
|
||||
auto imageUVPlane = createImageWithFlags(CL_MEM_READ_WRITE);
|
||||
std::unique_ptr<Image> imageUVPlane{createImageWithFlags(CL_MEM_READ_WRITE)};
|
||||
|
||||
ASSERT_NE(nullptr, imageUVPlane);
|
||||
|
||||
EXPECT_EQ(true, imageUVPlane->isImageFromImage());
|
||||
EXPECT_EQ(imageNV12->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()),
|
||||
imageUVPlane->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
||||
@ -376,51 +329,39 @@ TEST_F(Nv12ImageTest, GivenOffsetOfUVPlaneWhenCreatingUVPlaneImageThenDimensions
|
||||
EXPECT_EQ(0u, planeDimensions.image_depth);
|
||||
EXPECT_EQ(parentDimensions.image_row_pitch, planeDimensions.image_row_pitch);
|
||||
EXPECT_NE(0u, planeDimensions.image_row_pitch);
|
||||
|
||||
EXPECT_EQ(parentDimensions.image_slice_pitch, planeDimensions.image_slice_pitch);
|
||||
EXPECT_EQ(parentDimensions.image_type, planeDimensions.image_type);
|
||||
EXPECT_EQ(parentDimensions.image_array_size, planeDimensions.image_array_size);
|
||||
|
||||
computeExpectedOffsets(imageUVPlane);
|
||||
computeExpectedOffsets(imageNV12);
|
||||
|
||||
delete imageUVPlane;
|
||||
delete imageNV12;
|
||||
computeExpectedOffsets(imageUVPlane.get());
|
||||
computeExpectedOffsets(imageNV12.get());
|
||||
}
|
||||
|
||||
HWTEST_F(Nv12ImageTest, WhenCreatingParentImageThenPlanesAreWritten) {
|
||||
KernelBinaryHelper kbHelper(KernelBinaryHelper::BUILT_INS_WITH_IMAGES);
|
||||
|
||||
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
|
||||
char hostPtr[16 * 16 * 16];
|
||||
|
||||
auto contextWithMockCmdQ = new MockContext(device.get(), true);
|
||||
auto cmdQ = new MockCommandQueueHw<FamilyType>(contextWithMockCmdQ, device.get(), 0);
|
||||
|
||||
contextWithMockCmdQ->overrideSpecialQueueAndDecrementRefCount(cmdQ, device->getRootDeviceIndex());
|
||||
|
||||
// Create Parent NV12 image
|
||||
cl_mem_flags flags = CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL | CL_MEM_USE_HOST_PTR;
|
||||
auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
|
||||
auto imageNV12 = Image::create(contextWithMockCmdQ,
|
||||
MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),
|
||||
flags, 0, surfaceFormat, &imageDesc, hostPtr, retVal);
|
||||
std::unique_ptr<Image> imageNV12{Image::create(contextWithMockCmdQ,
|
||||
MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),
|
||||
flags, 0, surfaceFormat, &imageDesc, hostPtr, retVal)};
|
||||
|
||||
EXPECT_EQ(imageNV12->isTiledAllocation() ? 2u : 0u, cmdQ->EnqueueWriteImageCounter);
|
||||
|
||||
ASSERT_NE(nullptr, imageNV12);
|
||||
contextWithMockCmdQ->release();
|
||||
delete imageNV12;
|
||||
}
|
||||
|
||||
HWTEST_F(Nv12ImageTest, WhenSettingImageArgThenSurfaceStateIsCorrect) {
|
||||
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
|
||||
|
||||
RENDER_SURFACE_STATE surfaceState;
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
SurfaceOffsets surfaceOffsets;
|
||||
@ -433,8 +374,6 @@ HWTEST_F(Nv12ImageTest, WhenSettingImageArgThenSurfaceStateIsCorrect) {
|
||||
|
||||
// NV 12 image has correct alpha channel == one
|
||||
EXPECT_EQ(RENDER_SURFACE_STATE::SHADER_CHANNEL_SELECT_ONE, surfaceState.getShaderChannelSelectAlpha());
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
HWTEST_F(Nv12ImageTest, givenNv12ImageArrayAndImageArraySizeIsZeroWhenCallingSetImageArgThenDoNotProgramSurfaceArray) {
|
||||
@ -456,34 +395,26 @@ HWTEST_F(Nv12ImageTest, givenNv12ImageArrayAndImageArraySizeIsZeroWhenCallingSet
|
||||
|
||||
HWTEST_F(Nv12ImageTest, WhenSettingImageArgUvPlaneImageThenOffsetSurfaceBaseAddressAndCorrectTileModeAreSet) {
|
||||
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
|
||||
|
||||
RENDER_SURFACE_STATE surfaceState;
|
||||
|
||||
// Create Parent NV12 image
|
||||
auto imageNV12 = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> imageNV12{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, imageNV12);
|
||||
|
||||
imageDesc.mem_object = imageNV12;
|
||||
|
||||
imageDesc.mem_object = imageNV12.get();
|
||||
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
||||
imageFormat.image_channel_order = CL_R;
|
||||
|
||||
imageDesc.image_width = 0;
|
||||
imageDesc.image_height = 0;
|
||||
imageDesc.image_depth = 1; // UV plane
|
||||
|
||||
// Create NV12 UV Plane image
|
||||
auto imageUVPlane = createImageWithFlags(CL_MEM_READ_WRITE);
|
||||
std::unique_ptr<Image> imageUVPlane{createImageWithFlags(CL_MEM_READ_WRITE)};
|
||||
|
||||
ASSERT_NE(nullptr, imageUVPlane);
|
||||
|
||||
EXPECT_EQ(imageNV12->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()),
|
||||
imageUVPlane->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex()));
|
||||
|
||||
SurfaceOffsets surfaceOffsets;
|
||||
imageUVPlane->getSurfaceOffsets(surfaceOffsets);
|
||||
|
||||
imageUVPlane->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
|
||||
|
||||
EXPECT_EQ(imageUVPlane->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getGpuAddress() + surfaceOffsets.offset, surfaceState.getSurfaceBaseAddress());
|
||||
@ -494,18 +425,13 @@ HWTEST_F(Nv12ImageTest, WhenSettingImageArgUvPlaneImageThenOffsetSurfaceBaseAddr
|
||||
}
|
||||
|
||||
EXPECT_EQ(tileMode, surfaceState.getTileMode());
|
||||
|
||||
delete imageUVPlane;
|
||||
delete imageNV12;
|
||||
}
|
||||
|
||||
HWTEST_F(Nv12ImageTest, WhenSettingMediaImageArgThenSurfaceStateIsCorrect) {
|
||||
using MEDIA_SURFACE_STATE = typename FamilyType::MEDIA_SURFACE_STATE;
|
||||
|
||||
MEDIA_SURFACE_STATE surfaceState;
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
SurfaceOffsets surfaceOffsets;
|
||||
@ -517,22 +443,16 @@ HWTEST_F(Nv12ImageTest, WhenSettingMediaImageArgThenSurfaceStateIsCorrect) {
|
||||
EXPECT_EQ(surfaceOffsets.yOffsetForUVplane, surfaceState.getYOffsetForUCb());
|
||||
EXPECT_EQ(image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getGpuAddress() + surfaceOffsets.offset,
|
||||
surfaceState.getSurfaceBaseAddress());
|
||||
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, WhenRedescribingThenNV12ImageAndUVPlaneImageHaveCorrectOffsets) {
|
||||
|
||||
auto image = createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL);
|
||||
|
||||
std::unique_ptr<Image> image{createImageWithFlags(CL_MEM_READ_ONLY | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)};
|
||||
ASSERT_NE(nullptr, image);
|
||||
|
||||
auto imageRedescribed = image->redescribe();
|
||||
|
||||
std::unique_ptr<Image> imageRedescribed{image->redescribe()};
|
||||
ASSERT_NE(nullptr, imageRedescribed);
|
||||
|
||||
SurfaceOffsets imageOffsets, redescribedOffsets;
|
||||
|
||||
image->getSurfaceOffsets(imageOffsets);
|
||||
imageRedescribed->getSurfaceOffsets(redescribedOffsets);
|
||||
|
||||
@ -540,23 +460,18 @@ TEST_F(Nv12ImageTest, WhenRedescribingThenNV12ImageAndUVPlaneImageHaveCorrectOff
|
||||
EXPECT_EQ(imageOffsets.yOffset, redescribedOffsets.yOffset);
|
||||
EXPECT_EQ(imageOffsets.yOffsetForUVplane, redescribedOffsets.yOffsetForUVplane);
|
||||
|
||||
delete imageRedescribed;
|
||||
|
||||
imageDesc.mem_object = image;
|
||||
|
||||
imageDesc.mem_object = image.get();
|
||||
imageFormat.image_channel_data_type = CL_UNORM_INT8;
|
||||
imageFormat.image_channel_order = CL_R;
|
||||
|
||||
imageDesc.image_width = 0;
|
||||
imageDesc.image_height = 0;
|
||||
imageDesc.image_depth = 1; // UV plane
|
||||
|
||||
// Create NV12 UV Plane image
|
||||
auto imageUVPlane = createImageWithFlags(CL_MEM_READ_WRITE);
|
||||
|
||||
std::unique_ptr<Image> imageUVPlane{createImageWithFlags(CL_MEM_READ_WRITE)};
|
||||
ASSERT_NE(nullptr, imageUVPlane);
|
||||
|
||||
imageRedescribed = imageUVPlane->redescribe();
|
||||
imageRedescribed.reset(imageUVPlane->redescribe());
|
||||
ASSERT_NE(nullptr, imageRedescribed);
|
||||
|
||||
imageUVPlane->getSurfaceOffsets(imageOffsets);
|
||||
@ -565,10 +480,6 @@ TEST_F(Nv12ImageTest, WhenRedescribingThenNV12ImageAndUVPlaneImageHaveCorrectOff
|
||||
EXPECT_EQ(imageOffsets.xOffset, redescribedOffsets.xOffset);
|
||||
EXPECT_EQ(imageOffsets.yOffset, redescribedOffsets.yOffset);
|
||||
EXPECT_EQ(imageOffsets.yOffsetForUVplane, redescribedOffsets.yOffsetForUVplane);
|
||||
|
||||
delete imageRedescribed;
|
||||
delete imageUVPlane;
|
||||
delete image;
|
||||
}
|
||||
|
||||
TEST_F(Nv12ImageTest, GivenInvalidImageHeightWhenValidatingPlanarYuvThenInvalidImageSizeErrorIsReturned) {
|
||||
|
@ -85,7 +85,7 @@ TEST_P(PackedYuvImageTest, GivenValidPackedYuvImageFormatAndDescriptorWhenCreati
|
||||
nullptr,
|
||||
retVal);
|
||||
ASSERT_NE(nullptr, image);
|
||||
EXPECT_TRUE(IsPackedYuvImage(&image->getImageFormat()));
|
||||
EXPECT_TRUE(isPackedYuvImage(&image->getImageFormat()));
|
||||
delete image;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user