Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions opencl/source/sharings/va/va_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ bool VASurface::isSupportedPackedFormat(uint32_t imageFourcc) {
return true;
case VA_FOURCC_Y210:
return true;
case VA_FOURCC_ARGB:
return true;
default:
return false;
}
Expand Down Expand Up @@ -157,6 +159,9 @@ void VASurface::applyPackedOptions(SharedSurfaceInfo &sharedSurfaceInfo) {
if (sharedSurfaceInfo.imageFourcc == VA_FOURCC_Y210) {
sharedSurfaceInfo.channelType = CL_UNORM_INT16;
sharedSurfaceInfo.channelOrder = CL_RGBA;
} else if (sharedSurfaceInfo.imageFourcc == VA_FOURCC_ARGB) {
sharedSurfaceInfo.channelType = CL_UNORM_INT8;
sharedSurfaceInfo.channelOrder = CL_RGBA;
} else {
sharedSurfaceInfo.channelType = CL_UNORM_INT8;
sharedSurfaceInfo.channelOrder = CL_YUYV_INTEL;
Expand Down Expand Up @@ -313,6 +318,17 @@ const ClSurfaceFormatInfo *VASurface::getExtendedSurfaceFormatInfo(uint32_t form
return &formatInfoY210;
}

if (formatFourCC == VA_FOURCC_ARGB) {
static const ClSurfaceFormatInfo formatInfoARGB = {{CL_RGBA, CL_UNORM_INT8},
{GMM_RESOURCE_FORMAT::GMM_FORMAT_R8G8B8A8_UNORM_TYPE,
static_cast<GFX3DSTATE_SURFACEFORMAT>(GFX3DSTATE_SURFACEFORMAT_R8G8B8A8_UNORM),
0,
4,
1,
4}};
return &formatInfoARGB;
}

return nullptr;
}

Expand Down
8 changes: 6 additions & 2 deletions opencl/test/unit_test/sharings/va/mock_va_sharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class VASharingFunctionsMock : public VASharingFunctions {
return queryImageFormatsReturnStatus;
}
if (numFormats) {
*numFormats = 6;
*numFormats = 7;
}

if (formatList) {
Expand All @@ -152,12 +152,16 @@ class VASharingFunctionsMock : public VASharingFunctions {
formatList[5].fourcc = VA_FOURCC_Y210;
formatList[5].bits_per_pixel = 32;
formatList[5].byte_order = VA_LSB_FIRST;

formatList[6].fourcc = VA_FOURCC_ARGB;
formatList[6].bits_per_pixel = 32;
formatList[6].byte_order = VA_LSB_FIRST;
}
return VA_STATUS_SUCCESS;
}

int maxNumImageFormats(VADisplay vaDisplay) override {
return 6;
return 7;
}
};

Expand Down
42 changes: 37 additions & 5 deletions opencl/test/unit_test/sharings/va/va_sharing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,13 @@ TEST_F(VaSharingTests, givenSupportedFourccFormatWhenIsSupportedPlanarFormatThen
TEST_F(VaSharingTests, givenSupportedPackedFormatWhenIsSupportedPlanarFormatThenFailIsReturned) {
EXPECT_FALSE(VASurface::isSupportedPlanarFormat(VA_FOURCC_YUY2));
EXPECT_FALSE(VASurface::isSupportedPlanarFormat(VA_FOURCC_Y210));
EXPECT_FALSE(VASurface::isSupportedPlanarFormat(VA_FOURCC_ARGB));
}

TEST_F(VaSharingTests, givenSupportedFourccFormatWhenIsSupportedPackedFormatThenSuccessIsReturned) {
EXPECT_TRUE(VASurface::isSupportedPackedFormat(VA_FOURCC_YUY2));
EXPECT_TRUE(VASurface::isSupportedPackedFormat(VA_FOURCC_Y210));
EXPECT_TRUE(VASurface::isSupportedPackedFormat(VA_FOURCC_ARGB));
}

TEST_F(VaSharingTests, givenSupportedPlanarFormatWhenIsSupportedPackedFormatThenFailIsReturned) {
Expand Down Expand Up @@ -445,6 +447,19 @@ TEST_F(VaSharingTests, givenValidY210SurfaceWhenGetSurfaceDescriptionWithDeriveI
EXPECT_EQ(static_cast<uint32_t>(vaSharing->sharingFunctions.derivedImageFormatFourCC), surfaceInfo.imageFourcc);
}

TEST_F(VaSharingTests, givenValidARGBSurfaceWhenGetSurfaceDescriptionWithDeriveImageThenCLSuccessIsReturnedAndDataAreSet) {
vaSharing->sharingFunctions.derivedImageFormatBpp = 32;
vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_ARGB;
vaSharing->sharingFunctions.derivedImageHeight = 24;
vaSharing->sharingFunctions.derivedImageWidth = 24;

SharedSurfaceInfo surfaceInfo{};
EXPECT_EQ(VA_STATUS_SUCCESS, VASurface::getSurfaceDescription(surfaceInfo, &vaSharing->sharingFunctions, &vaSurfaceId));
EXPECT_EQ(vaSharing->sharingFunctions.derivedImageHeight, surfaceInfo.imgInfo.imgDesc.imageWidth);
EXPECT_EQ(vaSharing->sharingFunctions.derivedImageWidth, surfaceInfo.imgInfo.imgDesc.imageHeight);
EXPECT_EQ(static_cast<uint32_t>(vaSharing->sharingFunctions.derivedImageFormatFourCC), surfaceInfo.imageFourcc);
}

TEST(VASurface, givenSupportedY210PackedFormatWhenCheckingIfSupportedThenSurfaceDescIsReturned) {
EXPECT_NE(nullptr, VASurface::getExtendedSurfaceFormatInfo(VA_FOURCC_Y210));
}
Expand Down Expand Up @@ -978,6 +993,20 @@ TEST_F(VaSharingTests, givenP016FormatWhenCreatingSharedVaSurfaceForPlane1ThenCo
EXPECT_EQ(CL_SUCCESS, errCode);
}

TEST_F(VaSharingTests, givenRGBAFormatWhenCreatingSharedVaSurfaceForPlane0ThenCorrectFormatIsUsedByImageAndGMM) {
vaSharing->sharingFunctions.derivedImageFormatBpp = 32;
vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_ARGB;

auto vaSurface = std::unique_ptr<Image>(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions,
CL_MEM_READ_WRITE, 0, &vaSurfaceId, 0, &errCode));
auto graphicsAllocation = vaSurface->getGraphicsAllocation(rootDeviceIndex);
EXPECT_EQ(static_cast<cl_channel_type>(CL_UNORM_INT8), vaSurface->getImageFormat().image_channel_data_type);
EXPECT_EQ(static_cast<cl_channel_order>(CL_RGBA), vaSurface->getImageFormat().image_channel_order);
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R8G8B8A8_UNORM_TYPE, vaSurface->getSurfaceFormatInfo().surfaceFormat.gmmSurfaceFormat);
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R8G8B8A8_UNORM_TYPE, graphicsAllocation->getDefaultGmm()->resourceParams.Format);
EXPECT_EQ(CL_SUCCESS, errCode);
}

TEST_F(VaSharingTests, givenInvalidSurfaceWhenCreatingSharedVaSurfaceThenNullptrReturnedAndErrIsSet) {
vaSharing->sharingFunctions.deriveImageReturnStatus = VA_STATUS_ERROR_OPERATION_FAILED;

Expand Down Expand Up @@ -1177,6 +1206,7 @@ TEST_F(ApiVaSharingTests, givenSupportedImageTypeWhenGettingSupportedVAApiFormat
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_P016, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_YUY2, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_Y210, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));
supportedFormats.push_back(std::make_unique<VAImageFormat>(VAImageFormat{VA_FOURCC_ARGB, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0}));

for (auto flag : flags) {

Expand All @@ -1192,7 +1222,7 @@ TEST_F(ApiVaSharingTests, givenSupportedImageTypeWhenGettingSupportedVAApiFormat
&numImageFormats);

EXPECT_EQ(CL_SUCCESS, result);
EXPECT_EQ(5u, numImageFormats);
EXPECT_EQ(6u, numImageFormats);
int i = 0;
for (auto &format : supportedFormats) {
EXPECT_EQ(format->fourcc, vaApiFormats[i++].fourcc);
Expand All @@ -1218,7 +1248,7 @@ TEST_F(ApiVaSharingTests, givenZeroNumEntriesWhenGettingSupportedVAApiFormatsThe
&numImageFormats);

EXPECT_EQ(CL_SUCCESS, result);
EXPECT_EQ(5u, numImageFormats);
EXPECT_EQ(6u, numImageFormats);
}
}

Expand Down Expand Up @@ -1522,20 +1552,21 @@ TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithProperFormatsAndSupportedF

cl_mem_flags flags = CL_MEM_READ_WRITE;
cl_mem_object_type imageType = CL_MEM_OBJECT_IMAGE2D;
cl_uint numImageFormats = 5;
VAImageFormat vaApiFormats[5] = {};
cl_uint numImageFormats = 6;
VAImageFormat vaApiFormats[6] = {};

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.supportedPackedFormats.push_back(VAImageFormat{VA_FOURCC_YUY2, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});
sharingFunctions.supportedPackedFormats.push_back(VAImageFormat{VA_FOURCC_ARGB, VA_LSB_FIRST, 0, 0, 0, 0, 0, 0});

sharingFunctions.getSupportedFormats(
flags,
imageType,
0,
5,
6,
vaApiFormats,
&numImageFormats);

Expand All @@ -1544,6 +1575,7 @@ TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithProperFormatsAndSupportedF
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_P016), vaApiFormats[2].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_RGBP), vaApiFormats[3].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_YUY2), vaApiFormats[4].fourcc);
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_ARGB), vaApiFormats[5].fourcc);
}

TEST_F(VaSharingTests, givenPlaneArgumentLessThan2WithPackedFormatsAndSupportedFormatsVectorsThenAllPackedFormatsAreReturned) {
Expand Down