Modifications to cl_intel_va_api_media_sharing

Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2021-01-19 15:58:32 +01:00
committed by Compute-Runtime-Automation
parent 72e002a3ca
commit 4c27d46de3
9 changed files with 332 additions and 58 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -141,6 +141,7 @@ cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
cl_context context,
cl_mem_flags flags,
cl_mem_object_type imageType,
cl_uint plane,
cl_uint numEntries,
VAImageFormat *vaApiFormats,
cl_uint *numImageFormats) {
@ -155,5 +156,5 @@ cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
return CL_INVALID_CONTEXT;
}
return pSharing->getSupportedFormats(flags, imageType, numEntries, vaApiFormats, numImageFormats);
return pSharing->getSupportedFormats(flags, imageType, plane, numEntries, vaApiFormats, numImageFormats);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
* Copyright (C) 2019-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -12,6 +12,7 @@ cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
cl_context context,
cl_mem_flags flags,
cl_mem_object_type imageType,
cl_uint plane,
cl_uint numEntries,
VAImageFormat *vaApiFormats,
cl_uint *numImageFormats);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -76,15 +76,16 @@ void VASharingFunctions::initFunctions() {
}
void VASharingFunctions::querySupportedVaImageFormats(VADisplay vaDisplay) {
UNRECOVERABLE_IF(supportedFormats.size() != 0);
int maxFormats = this->maxNumImageFormats(vaDisplay);
if (maxFormats > 0) {
std::unique_ptr<VAImageFormat[]> allVaFormats(new VAImageFormat[maxFormats]);
this->queryImageFormats(vaDisplay, allVaFormats.get(), &maxFormats);
for (int i = 0; i < maxFormats; i++) {
if (VASurface::isSupportedFourCC(allVaFormats[i].fourcc)) {
supportedFormats.emplace_back(allVaFormats[i]);
if (VASurface::isSupportedFourCCTwoPlaneFormat(allVaFormats[i].fourcc)) {
supported2PlaneFormats.emplace_back(allVaFormats[i]);
} else if (VASurface::isSupportedFourCCThreePlaneFormat(allVaFormats[i].fourcc)) {
supported3PlaneFormats.emplace_back(allVaFormats[i]);
}
}
}
@ -92,6 +93,7 @@ void VASharingFunctions::querySupportedVaImageFormats(VADisplay vaDisplay) {
cl_int VASharingFunctions::getSupportedFormats(cl_mem_flags flags,
cl_mem_object_type imageType,
cl_uint plane,
cl_uint numEntries,
VAImageFormat *formats,
cl_uint *numImageFormats) {
@ -104,12 +106,26 @@ cl_int VASharingFunctions::getSupportedFormats(cl_mem_flags flags,
}
if (numImageFormats != nullptr) {
*numImageFormats = static_cast<cl_uint>(supportedFormats.size());
if (plane == 2) {
*numImageFormats = static_cast<cl_uint>(supported3PlaneFormats.size());
} else if (plane < 2) {
*numImageFormats = static_cast<cl_uint>(supported2PlaneFormats.size() + supported3PlaneFormats.size());
}
}
if (formats != nullptr && supportedFormats.size() > 0) {
uint32_t elementsToCopy = std::min(numEntries, static_cast<uint32_t>(supportedFormats.size()));
memcpy_s(formats, elementsToCopy * sizeof(VAImageFormat), &supportedFormats[0], elementsToCopy * sizeof(VAImageFormat));
if (plane == 2) {
if (formats != nullptr && supported3PlaneFormats.size() > 0) {
uint32_t elementsToCopy = std::min(numEntries, static_cast<uint32_t>(supported3PlaneFormats.size()));
memcpy_s(formats, elementsToCopy * sizeof(VAImageFormat), &supported3PlaneFormats[0], elementsToCopy * sizeof(VAImageFormat));
}
} else if (plane < 2) {
if (formats != nullptr && (supported2PlaneFormats.size() > 0 || supported3PlaneFormats.size() > 0)) {
uint32_t elementsToCopy = std::min(numEntries, static_cast<uint32_t>(supported2PlaneFormats.size() + supported3PlaneFormats.size()));
std::vector<VAImageFormat> tmp_formats;
tmp_formats.insert(tmp_formats.end(), supported2PlaneFormats.begin(), supported2PlaneFormats.end());
tmp_formats.insert(tmp_formats.end(), supported3PlaneFormats.begin(), supported3PlaneFormats.end());
memcpy_s(formats, elementsToCopy * sizeof(VAImageFormat), &tmp_formats[0], elementsToCopy * sizeof(VAImageFormat));
}
}
return CL_SUCCESS;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -71,6 +71,7 @@ class VASharingFunctions : public SharingFunctions {
cl_int getSupportedFormats(cl_mem_flags flags,
cl_mem_object_type imageType,
cl_uint plane,
cl_uint numEntries,
VAImageFormat *formats,
cl_uint *numImageFormats);
@ -94,6 +95,7 @@ class VASharingFunctions : public SharingFunctions {
VAQueryImageFormatsPFN vaQueryImageFormatsPFN;
VAMaxNumImageFormatsPFN vaMaxNumImageFormatsPFN;
std::vector<VAImageFormat> supportedFormats;
std::vector<VAImageFormat> supported2PlaneFormats;
std::vector<VAImageFormat> supported3PlaneFormats;
};
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -210,11 +210,20 @@ const ClSurfaceFormatInfo *VASurface::getExtendedSurfaceFormatInfo(uint32_t form
return nullptr;
}
bool VASurface::isSupportedFourCC(int fourcc) {
bool VASurface::isSupportedFourCCTwoPlaneFormat(int fourcc) {
if ((fourcc == VA_FOURCC_NV12) ||
(DebugManager.flags.EnableExtendedVaFormats.get() && fourcc == VA_FOURCC_P010)) {
(fourcc == VA_FOURCC_P010) ||
(fourcc == VA_FOURCC_P016)) {
return true;
}
return false;
}
bool VASurface::isSupportedFourCCThreePlaneFormat(int fourcc) {
if (DebugManager.flags.EnableExtendedVaFormats.get() && fourcc == VA_FOURCC_RGBP) {
return true;
}
return false;
}
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -25,7 +25,8 @@ class VASurface : VASharing {
static bool validate(cl_mem_flags flags, cl_uint plane);
static const ClSurfaceFormatInfo *getExtendedSurfaceFormatInfo(uint32_t formatFourCC);
static bool isSupportedFourCC(int fourcc);
static bool isSupportedFourCCTwoPlaneFormat(int fourcc);
static bool isSupportedFourCCThreePlaneFormat(int fourcc);
protected:
VASurface(VASharingFunctions *sharingFunctions, VAImageID imageId,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -17,7 +17,8 @@ namespace NEO {
class VASharingFunctionsMock : public VASharingFunctions {
public:
using VASharingFunctions::supportedFormats;
using VASharingFunctions::supported2PlaneFormats;
using VASharingFunctions::supported3PlaneFormats;
VAImage mockVaImage = {};
int32_t derivedImageFormatFourCC = VA_FOURCC_NV12;
@ -115,7 +116,7 @@ class VASharingFunctionsMock : public VASharingFunctions {
return queryImageFormatsReturnStatus;
}
if (numFormats) {
*numFormats = 2;
*numFormats = 4;
}
if (formatList) {
@ -124,14 +125,22 @@ class VASharingFunctionsMock : public VASharingFunctions {
formatList[0].byte_order = VA_LSB_FIRST;
formatList[1].fourcc = VA_FOURCC_P010;
formatList[1].bits_per_pixel = 24;
formatList[1].bits_per_pixel = 10;
formatList[1].byte_order = VA_LSB_FIRST;
formatList[2].fourcc = VA_FOURCC_P016;
formatList[2].bits_per_pixel = 16;
formatList[2].byte_order = VA_LSB_FIRST;
formatList[3].fourcc = VA_FOURCC_RGBP;
formatList[3].bits_per_pixel = 8;
formatList[3].byte_order = VA_LSB_FIRST;
}
return VA_STATUS_SUCCESS;
}
int maxNumImageFormats(VADisplay vaDisplay) override {
return 2;
return 4;
}
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -188,13 +188,19 @@ TEST(VASharingFunctions, givenEnabledExtendedVaFormatsWhenQueryingSupportedForma
sharingFunctions.querySupportedVaImageFormats(VADisplay(1));
EXPECT_EQ(2u, sharingFunctions.supportedFormats.size());
EXPECT_EQ(3u, sharingFunctions.supported2PlaneFormats.size());
EXPECT_EQ(1u, sharingFunctions.supported3PlaneFormats.size());
size_t allFormatsFound = 0;
for (const auto &supportedFormat : sharingFunctions.supportedFormats) {
if (supportedFormat.fourcc == VA_FOURCC_NV12 || supportedFormat.fourcc == VA_FOURCC_P010) {
for (const auto &supported2PlaneFormat : sharingFunctions.supported2PlaneFormats) {
if (supported2PlaneFormat.fourcc == VA_FOURCC_NV12 || supported2PlaneFormat.fourcc == VA_FOURCC_P010 || supported2PlaneFormat.fourcc == VA_FOURCC_P016) {
allFormatsFound++;
}
}
EXPECT_EQ(2u, allFormatsFound);
for (const auto &supported3PlaneFormat : sharingFunctions.supported3PlaneFormats) {
if (supported3PlaneFormat.fourcc == VA_FOURCC_RGBP) {
allFormatsFound++;
}
}
EXPECT_EQ(4u, allFormatsFound);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -785,22 +785,31 @@ TEST_F(ApiVaSharingTests, givenSupportedImageTypeWhenGettingSupportedVAApiFormat
VAImageFormat vaApiFormats[10] = {};
cl_uint numImageFormats = 0;
VAImageFormat supportedFormat = {VA_FOURCC_NV12, VA_LSB_FIRST, 8, 0, 0, 0, 0, 0};
std::vector<std::unique_ptr<VAImageFormat>> supportedFormats;
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_NV12, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_P010, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_P016, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));
for (auto flag : flags) {
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
&context,
flag,
image_type,
arrayCount(vaApiFormats),
vaApiFormats,
&numImageFormats);
for (auto plane : {0, 1}) {
EXPECT_EQ(CL_SUCCESS, result);
EXPECT_EQ(1u, numImageFormats);
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
&context,
flag,
image_type,
plane,
arrayCount(vaApiFormats),
vaApiFormats,
&numImageFormats);
EXPECT_EQ(supportedFormat.fourcc, vaApiFormats[0].fourcc);
EXPECT_EQ(CL_SUCCESS, result);
EXPECT_EQ(3u, numImageFormats);
int i = 0;
for (auto &format : supportedFormats) {
EXPECT_EQ(format->fourcc, vaApiFormats[i++].fourcc);
}
}
}
}
@ -809,16 +818,20 @@ TEST_F(ApiVaSharingTests, givenZeroNumEntriesWhenGettingSupportedVAApiFormatsThe
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 0;
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
&context,
flags,
image_type,
0,
nullptr,
&numImageFormats);
for (auto plane : {0, 1}) {
EXPECT_EQ(CL_SUCCESS, result);
EXPECT_EQ(1u, numImageFormats);
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
&context,
flags,
image_type,
plane,
0,
nullptr,
&numImageFormats);
EXPECT_EQ(CL_SUCCESS, result);
EXPECT_EQ(3u, numImageFormats);
}
}
TEST_F(ApiVaSharingTests, givenNullNumImageFormatsWhenGettingSupportedVAApiFormatsThenNumFormatsIsNotDereferenced) {
@ -830,6 +843,7 @@ TEST_F(ApiVaSharingTests, givenNullNumImageFormatsWhenGettingSupportedVAApiForma
flags,
image_type,
0,
0,
nullptr,
nullptr);
@ -846,6 +860,7 @@ TEST_F(ApiVaSharingTests, givenInvalidImageTypeWhenGettingSupportedVAApiFormatsT
&context,
flags,
image_type,
0,
arrayCount(vaApiFormats),
vaApiFormats,
&numImageFormats);
@ -864,6 +879,7 @@ TEST_F(ApiVaSharingTests, givenInvalidFlagsWhenGettingSupportedVAApiFormatsThenI
&context,
flags,
image_type,
0,
arrayCount(vaApiFormats),
vaApiFormats,
&numImageFormats);
@ -883,6 +899,7 @@ TEST_F(ApiVaSharingTests, givenInvalidContextWhenGettingSupportedVAApiFormatsThe
&contextWihtoutVASharing,
flags,
image_type,
0,
arrayCount(vaApiFormats),
vaApiFormats,
&numImageFormats);
@ -906,10 +923,10 @@ TEST(VaSurface, givenInValidPlaneOrFlagsWhenValidatingInputsThenTrueIsReturned)
}
TEST(VaSurface, givenNotSupportedVaFormatsWhenCheckingIfSupportedThenFalseIsReturned) {
EXPECT_FALSE(VASurface::isSupportedFourCC(VA_FOURCC_NV11));
EXPECT_FALSE(VASurface::isSupportedFourCCTwoPlaneFormat(VA_FOURCC_NV11));
DebugManagerStateRestore restore;
DebugManager.flags.EnableExtendedVaFormats.set(true);
EXPECT_FALSE(VASurface::isSupportedFourCC(VA_FOURCC_NV11));
EXPECT_FALSE(VASurface::isSupportedFourCCThreePlaneFormat(VA_FOURCC_NV11));
EXPECT_EQ(nullptr, VASurface::getExtendedSurfaceFormatInfo(VA_FOURCC_NV11));
}
@ -919,13 +936,14 @@ TEST(VaSharingFunctions, givenErrorReturnedFromVaLibWhenQuerySupportedVaImageFor
sharingFunctions.querySupportedVaImageFormats(VADisplay(1));
EXPECT_EQ(0u, sharingFunctions.supportedFormats.size());
EXPECT_EQ(0u, sharingFunctions.supported2PlaneFormats.size());
EXPECT_EQ(0u, sharingFunctions.supported3PlaneFormats.size());
}
TEST(VaSharingFunctions, givenNoSupportedFormatsWhenQuerySupportedVaImageFormatsThenSupportedFormatsAreNotSet) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(0u, sharingFunctions.supportedFormats.size());
EXPECT_EQ(0u, sharingFunctions.supported2PlaneFormats.size());
EXPECT_EQ(0u, sharingFunctions.supported3PlaneFormats.size());
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 0;
@ -934,6 +952,7 @@ TEST(VaSharingFunctions, givenNoSupportedFormatsWhenQuerySupportedVaImageFormats
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
10,
vaApiFormats,
&numImageFormats);
@ -944,11 +963,11 @@ TEST(VaSharingFunctions, givenNoSupportedFormatsWhenQuerySupportedVaImageFormats
TEST(VaSharingFunctions, givenNumEntriesLowerThanSupportedFormatsWhenGettingSupportedFormatsThenOnlyNumEntiresAreReturned) {
VASharingFunctionsMock sharingFunctions;
VAImageFormat imageFormat = {VA_FOURCC_NV12, 1, 12};
sharingFunctions.supportedFormats.emplace_back(imageFormat);
imageFormat.fourcc = VA_FOURCC_NV21;
sharingFunctions.supportedFormats.emplace_back(imageFormat);
sharingFunctions.supported2PlaneFormats.emplace_back(imageFormat);
imageFormat.fourcc = VA_FOURCC_P010;
sharingFunctions.supported2PlaneFormats.emplace_back(imageFormat);
EXPECT_EQ(2u, sharingFunctions.supportedFormats.size());
EXPECT_EQ(2u, sharingFunctions.supported2PlaneFormats.size());
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
@ -958,6 +977,7 @@ TEST(VaSharingFunctions, givenNumEntriesLowerThanSupportedFormatsWhenGettingSupp
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
1,
vaApiFormats,
&numImageFormats);
@ -998,3 +1018,212 @@ TEST_F(VaSharingTests, givenInteropUserSyncIsNotSpecifiedDuringContextCreationWh
EXPECT_EQ(!specifyInteropUseSync, mockCommandQueue.finishCalled);
}
}
TEST_F(VaSharingTests, givenPlaneArgumentEquals2WithEmptySupported3PlaneFormatsVectorThentNoFormatIsReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 4;
VAImageFormat vaApiFormats[4] = {};
sharingFunctions.getSupportedFormats(
flags,
image_type,
2,
1,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(0u, vaApiFormats[0].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentGreaterThan2ThenNoFormatIsReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
VAImageFormat imageFormat = {VA_FOURCC_RGBP, 1, 12};
sharingFunctions.supported3PlaneFormats.emplace_back(imageFormat);
imageFormat = {VA_FOURCC_NV12, 1, 12};
sharingFunctions.supported2PlaneFormats.emplace_back(imageFormat);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 2;
VAImageFormat vaApiFormats[2] = {};
sharingFunctions.getSupportedFormats(
flags,
image_type,
3,
1,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(0u, vaApiFormats[0].fourcc);
EXPECT_EQ(0u, vaApiFormats[1].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentEquals2ThenOnlyRGBPFormatIsReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
VAImageFormat imageFormat = {VA_FOURCC_RGBP, 1, 12};
sharingFunctions.supported3PlaneFormats.emplace_back(imageFormat);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 1;
VAImageFormat vaApiFormats[3] = {};
sharingFunctions.getSupportedFormats(
flags,
image_type,
2,
1,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_RGBP), vaApiFormats[0].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithProperFormatsAndEmptySupportedFormatsVectorsThenNoFormatIsReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 1;
VAImageFormat vaApiFormats[3] = {};
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
1,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(0u, vaApiFormats[0].fourcc);
VAImageFormat imageFormat = {VA_FOURCC_NV12, 1, 12};
sharingFunctions.supported2PlaneFormats.emplace_back(imageFormat);
sharingFunctions.supported3PlaneFormats.emplace_back(imageFormat);
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
1,
nullptr,
&numImageFormats);
EXPECT_EQ(0u, vaApiFormats[0].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithProperFormatsAndSupportedFormatsVectorsThenAll2And3PlaneFormatsAreReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 4;
VAImageFormat vaApiFormats[4] = {};
sharingFunctions.supported2PlaneFormats.push_back(VAImageFormat{VA_FOURCC_NV12, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.supported2PlaneFormats.push_back(VAImageFormat{VA_FOURCC_P010, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.supported2PlaneFormats.push_back(VAImageFormat{VA_FOURCC_P016, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.supported3PlaneFormats.push_back(VAImageFormat{VA_FOURCC_RGBP, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
4,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_NV12), vaApiFormats[0].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_P010), vaApiFormats[1].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_P016), vaApiFormats[2].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_RGBP), vaApiFormats[3].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithProperFormatsAndOnly3PlaneSupportedFormatsVectorThen3PlaneFormatIsReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 4;
VAImageFormat vaApiFormats[4] = {};
sharingFunctions.supported3PlaneFormats.push_back(VAImageFormat{VA_FOURCC_RGBP, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
4,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_RGBP), vaApiFormats[0].fourcc);
EXPECT_EQ(0u, vaApiFormats[1].fourcc);
EXPECT_EQ(0u, vaApiFormats[2].fourcc);
EXPECT_EQ(0u, vaApiFormats[3].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithProperFormatsAndOnly2PlaneSupportedFormatsVectorThen2PlaneFormatsAreReturned) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 4;
VAImageFormat vaApiFormats[4] = {};
sharingFunctions.supported2PlaneFormats.push_back(VAImageFormat{VA_FOURCC_NV12, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.supported2PlaneFormats.push_back(VAImageFormat{VA_FOURCC_P010, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.supported2PlaneFormats.push_back(VAImageFormat{VA_FOURCC_P016, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
sharingFunctions.getSupportedFormats(
flags,
image_type,
0,
4,
vaApiFormats,
&numImageFormats);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_NV12), vaApiFormats[0].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_P010), vaApiFormats[1].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_P016), vaApiFormats[2].fourcc);
EXPECT_EQ(0u, vaApiFormats[3].fourcc);
}
TEST_F(VaSharingTests, givenPlaneArgumentEquals2WithoutNoProperFormatsThenReturn) {
VASharingFunctionsMock sharingFunctions;
EXPECT_EQ(sharingFunctions.supported2PlaneFormats.size(), 0u);
EXPECT_EQ(sharingFunctions.supported3PlaneFormats.size(), 0u);
cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 1;
sharingFunctions.supported3PlaneFormats.push_back(VAImageFormat{VA_FOURCC_RGBP, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
cl_int result = sharingFunctions.getSupportedFormats(
flags,
image_type,
2,
4,
nullptr,
&numImageFormats);
EXPECT_EQ(result, CL_SUCCESS);
}