Query and store supported VA ImageFormats
Related-To: NEO-612 Change-Id: Ibe8f9e9da0ba2f57ed89e96258cde155f5a5d527 Signed-off-by: Hoppe, Mateusz <mateusz.hoppe@intel.com>
This commit is contained in:
parent
e7f8bd0be4
commit
77e2bec9bf
|
@ -7,6 +7,7 @@
|
|||
set(RUNTIME_SRCS_SHARINGS_VA
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_va_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cl_va_api.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_defines.h
|
||||
|
|
|
@ -130,3 +130,24 @@ clEnqueueReleaseVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue,
|
|||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
cl_int clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
cl_context context,
|
||||
cl_mem_flags flags,
|
||||
cl_mem_object_type imageType,
|
||||
cl_uint numEntries,
|
||||
VAImageFormat *vaApiFormats,
|
||||
cl_uint *numImageFormats) {
|
||||
|
||||
if (numImageFormats) {
|
||||
*numImageFormats = 0;
|
||||
}
|
||||
|
||||
Context *pContext = castToObjectOrAbort<Context>(context);
|
||||
auto pSharing = pContext->getSharing<VASharingFunctions>();
|
||||
if (!pSharing) {
|
||||
return CL_INVALID_CONTEXT;
|
||||
}
|
||||
|
||||
return pSharing->getSupportedFormats(flags, imageType, numEntries, vaApiFormats, numImageFormats);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "CL/cl.h"
|
||||
#include "CL/cl_va_api_media_sharing_intel.h"
|
||||
|
||||
cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
cl_context context,
|
||||
cl_mem_flags flags,
|
||||
cl_mem_object_type image_type,
|
||||
cl_uint num_entries,
|
||||
VAImageFormat *va_api_formats,
|
||||
cl_uint *num_image_formats);
|
|
@ -45,6 +45,7 @@ bool VaSharingContextBuilder::finalizeProperties(Context &context, int32_t &errc
|
|||
errcodeRet = CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL;
|
||||
return false;
|
||||
}
|
||||
context.getSharing<VASharingFunctions>()->querySupportedVaImageFormats(contextData->vaDisplay);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2017-2018 Intel Corporation
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -16,3 +16,5 @@ typedef VAStatus (*VADestroyImagePFN)(VADisplay vaDisplay, VAImageID vaImageId);
|
|||
typedef VAStatus (*VAExtGetSurfaceHandlePFN)(VADisplay vaDisplay, VASurfaceID *vaSurface, unsigned int *handleId);
|
||||
typedef VAStatus (*VASyncSurfacePFN)(VADisplay vaDisplay, VASurfaceID vaSurface);
|
||||
typedef void *(*VAGetLibFuncPFN)(VADisplay vaDisplay, const char *func);
|
||||
typedef VAStatus (*VAQueryImageFormatsPFN)(VADisplay vaDisplay, VAImageFormat *formatList, int *numFormats);
|
||||
typedef int (*VAMaxNumImageFormatsPFN)(VADisplay vaDisplay);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "va_sharing_functions.h"
|
||||
|
||||
#include "runtime/os_interface/debug_settings_manager.h"
|
||||
#include "runtime/sharings/va/va_surface.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
|
@ -50,6 +51,9 @@ void VASharingFunctions::initFunctions() {
|
|||
vaSyncSurfacePFN = reinterpret_cast<VASyncSurfacePFN>(fdlsym(libHandle, "vaSyncSurface"));
|
||||
vaGetLibFuncPFN = reinterpret_cast<VAGetLibFuncPFN>(fdlsym(libHandle, "vaGetLibFunc"));
|
||||
vaExtGetSurfaceHandlePFN = reinterpret_cast<VAExtGetSurfaceHandlePFN>(getLibFunc("DdiMedia_ExtGetSurfaceHandle"));
|
||||
vaQueryImageFormatsPFN = reinterpret_cast<VAQueryImageFormatsPFN>(fdlsym(libHandle, "vaQueryImageFormats"));
|
||||
vaMaxNumImageFormatsPFN = reinterpret_cast<VAMaxNumImageFormatsPFN>(fdlsym(libHandle, "vaMaxNumImageFormats"));
|
||||
|
||||
} else {
|
||||
vaDisplayIsValidPFN = nullptr;
|
||||
vaDeriveImagePFN = nullptr;
|
||||
|
@ -57,7 +61,49 @@ void VASharingFunctions::initFunctions() {
|
|||
vaSyncSurfacePFN = nullptr;
|
||||
vaGetLibFuncPFN = nullptr;
|
||||
vaExtGetSurfaceHandlePFN = nullptr;
|
||||
vaQueryImageFormatsPFN = nullptr;
|
||||
vaMaxNumImageFormatsPFN = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cl_int VASharingFunctions::getSupportedFormats(cl_mem_flags flags,
|
||||
cl_mem_object_type imageType,
|
||||
cl_uint numEntries,
|
||||
VAImageFormat *formats,
|
||||
cl_uint *numImageFormats) {
|
||||
if (flags != CL_MEM_READ_ONLY && flags != CL_MEM_WRITE_ONLY && flags != CL_MEM_READ_WRITE) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (imageType != CL_MEM_OBJECT_IMAGE2D) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (numImageFormats != nullptr) {
|
||||
*numImageFormats = static_cast<cl_uint>(supportedFormats.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));
|
||||
}
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
} // namespace NEO
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <functional>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class VASharingFunctions : public SharingFunctions {
|
||||
public:
|
||||
VASharingFunctions(VADisplay vaDisplay);
|
||||
|
@ -42,6 +43,17 @@ class VASharingFunctions : public SharingFunctions {
|
|||
return vaSyncSurfacePFN(vaDisplay, vaSurface);
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL VAStatus queryImageFormats(VADisplay vaDisplay, VAImageFormat *formatList, int *numFormats) {
|
||||
return vaQueryImageFormatsPFN(vaDisplay, formatList, numFormats);
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL int maxNumImageFormats(VADisplay vaDisplay) {
|
||||
if (vaMaxNumImageFormatsPFN) {
|
||||
return vaMaxNumImageFormatsPFN(vaDisplay);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *getLibFunc(const char *func) {
|
||||
if (vaGetLibFuncPFN) {
|
||||
return vaGetLibFuncPFN(vaDisplay, func);
|
||||
|
@ -50,6 +62,14 @@ class VASharingFunctions : public SharingFunctions {
|
|||
}
|
||||
|
||||
void initFunctions();
|
||||
void querySupportedVaImageFormats(VADisplay vaDisplay);
|
||||
|
||||
cl_int getSupportedFormats(cl_mem_flags flags,
|
||||
cl_mem_object_type imageType,
|
||||
cl_uint numEntries,
|
||||
VAImageFormat *formats,
|
||||
cl_uint *numImageFormats);
|
||||
|
||||
static std::function<void *(const char *, int)> fdlopen;
|
||||
static std::function<void *(void *handle, const char *symbol)> fdlsym;
|
||||
static std::function<int(void *handle)> fdlclose;
|
||||
|
@ -65,5 +85,9 @@ class VASharingFunctions : public SharingFunctions {
|
|||
VASyncSurfacePFN vaSyncSurfacePFN;
|
||||
VAExtGetSurfaceHandlePFN vaExtGetSurfaceHandlePFN;
|
||||
VAGetLibFuncPFN vaGetLibFuncPFN;
|
||||
VAQueryImageFormatsPFN vaQueryImageFormatsPFN;
|
||||
VAMaxNumImageFormatsPFN vaMaxNumImageFormatsPFN;
|
||||
|
||||
std::vector<VAImageFormat> supportedFormats;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
|
|
@ -127,4 +127,12 @@ const SurfaceFormatInfo *VASurface::getExtendedSurfaceFormatInfo(uint32_t format
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool VASurface::isSupportedFourCC(int fourcc) {
|
||||
if ((fourcc == VA_FOURCC_NV12) ||
|
||||
(DebugManager.flags.EnableExtendedVaFormats.get() && fourcc == VA_FOURCC_P010)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace NEO
|
||||
|
|
|
@ -25,6 +25,7 @@ class VASurface : VASharing {
|
|||
|
||||
static bool validate(cl_mem_flags flags, cl_uint plane);
|
||||
static const SurfaceFormatInfo *getExtendedSurfaceFormatInfo(uint32_t formatFourCC);
|
||||
static bool isSupportedFourCC(int fourcc);
|
||||
|
||||
protected:
|
||||
VASurface(VASharingFunctions *sharingFunctions, VAImageID imageId,
|
||||
|
|
|
@ -13,11 +13,14 @@ namespace NEO {
|
|||
|
||||
class VASharingFunctionsMock : public VASharingFunctions {
|
||||
public:
|
||||
using VASharingFunctions::supportedFormats;
|
||||
|
||||
VAImage mockVaImage = {};
|
||||
int32_t derivedImageFormatFourCC = VA_FOURCC_NV12;
|
||||
int32_t derivedImageFormatBpp = 8;
|
||||
uint16_t derivedImageHeight = 256;
|
||||
uint16_t derivedImageWidth = 256;
|
||||
VAStatus queryImageFormatsReturnStatus = VA_STATUS_SUCCESS;
|
||||
|
||||
bool isValidDisplayCalled = false;
|
||||
bool deriveImageCalled = false;
|
||||
|
@ -68,6 +71,30 @@ class VASharingFunctionsMock : public VASharingFunctions {
|
|||
syncSurfaceCalled = true;
|
||||
return VA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
VAStatus queryImageFormats(VADisplay vaDisplay, VAImageFormat *formatList, int *numFormats) override {
|
||||
if (queryImageFormatsReturnStatus != VA_STATUS_SUCCESS) {
|
||||
return queryImageFormatsReturnStatus;
|
||||
}
|
||||
if (numFormats) {
|
||||
*numFormats = 2;
|
||||
}
|
||||
|
||||
if (formatList) {
|
||||
formatList[0].fourcc = VA_FOURCC_NV12;
|
||||
formatList[0].bits_per_pixel = 12;
|
||||
formatList[0].byte_order = VA_LSB_FIRST;
|
||||
|
||||
formatList[1].fourcc = VA_FOURCC_P010;
|
||||
formatList[1].bits_per_pixel = 24;
|
||||
formatList[1].byte_order = VA_LSB_FIRST;
|
||||
}
|
||||
return VA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
int maxNumImageFormats(VADisplay vaDisplay) override {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
|
||||
class MockVaSharing {
|
||||
|
|
|
@ -5,8 +5,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "runtime/helpers/array_count.h"
|
||||
#include "runtime/sharings/va/va_sharing_functions.h"
|
||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "unit_tests/helpers/variable_backup.h"
|
||||
#include "unit_tests/sharings/va/mock_va_sharing.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -145,3 +148,26 @@ TEST(VASharingFunctions, GivenFunctionsWhenLibvaLoadedThenDlcloseIsCalled) {
|
|||
}
|
||||
EXPECT_EQ(1u, closeCalls);
|
||||
}
|
||||
|
||||
TEST(VASharingFunctions, givenEnabledExtendedVaFormatsWhenQueryingSupportedFormatsThenAllSupportedFormatsAreStored) {
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.EnableExtendedVaFormats.set(true);
|
||||
|
||||
VASharingFunctionsMock sharingFunctions;
|
||||
|
||||
sharingFunctions.querySupportedVaImageFormats(VADisplay(1));
|
||||
|
||||
EXPECT_EQ(2u, sharingFunctions.supportedFormats.size());
|
||||
|
||||
size_t allFormatsFound = 0;
|
||||
uint32_t fourCCExpected[] = {VA_FOURCC_NV12, VA_FOURCC_P010};
|
||||
|
||||
for (size_t i = 0; i < sharingFunctions.supportedFormats.size(); i++) {
|
||||
for (size_t fourCCIndex = 0; fourCCIndex < arrayCount(fourCCExpected); fourCCIndex++) {
|
||||
if (sharingFunctions.supportedFormats[0].fourcc == fourCCExpected[fourCCIndex]) {
|
||||
allFormatsFound++;
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(2u, allFormatsFound);
|
||||
}
|
||||
|
|
|
@ -8,8 +8,10 @@
|
|||
#include "runtime/api/api.h"
|
||||
#include "runtime/device/device.h"
|
||||
#include "runtime/gmm_helper/gmm.h"
|
||||
#include "runtime/helpers/array_count.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include "runtime/platform/platform.h"
|
||||
#include "runtime/sharings/va/cl_va_api.h"
|
||||
#include "runtime/sharings/va/va_sharing.h"
|
||||
#include "runtime/sharings/va/va_surface.h"
|
||||
#include "unit_tests/fixtures/platform_fixture.h"
|
||||
|
@ -29,6 +31,7 @@ class VaSharingTests : public ::testing::Test, public PlatformFixture {
|
|||
PlatformFixture::SetUp();
|
||||
vaSharing = new MockVaSharing;
|
||||
context.setSharingFunctions(&vaSharing->sharingFunctions);
|
||||
vaSharing->sharingFunctions.querySupportedVaImageFormats(VADisplay(1));
|
||||
vaSharing->updateAcquiredHandle(sharingHandle);
|
||||
sharedImg = nullptr;
|
||||
sharedClMem = nullptr;
|
||||
|
@ -66,8 +69,10 @@ class VaSharingTests : public ::testing::Test, public PlatformFixture {
|
|||
unsigned int sharingHandle = 1u;
|
||||
};
|
||||
|
||||
TEST_F(VaSharingTests, givenVASharingFunctionsObjectWhenFunctionsAreCalledThenCallsAreRedirectedToVaFunctionPointers) {
|
||||
TEST(VaSharingTest, givenVASharingFunctionsObjectWhenFunctionsAreCalledThenCallsAreRedirectedToVaFunctionPointers) {
|
||||
unsigned int handle = 0u;
|
||||
VASurfaceID vaSurfaceId = 0u;
|
||||
VAImage vaImage = {};
|
||||
|
||||
class VASharingFunctionsGlobalFunctionPointersMock : public VASharingFunctions {
|
||||
public:
|
||||
|
@ -81,6 +86,8 @@ TEST_F(VaSharingTests, givenVASharingFunctionsObjectWhenFunctionsAreCalledThenCa
|
|||
bool vaSyncSurfaceCalled = false;
|
||||
bool vaGetLibFuncCalled = false;
|
||||
bool vaExtGetSurfaceHandleCalled = false;
|
||||
bool vaQueryImageFormatsCalled = false;
|
||||
bool vaMaxNumImageFormatsCalled = false;
|
||||
|
||||
void initMembers() {
|
||||
vaDisplayIsValidPFN = mockVaDisplayIsValid;
|
||||
|
@ -89,59 +96,84 @@ TEST_F(VaSharingTests, givenVASharingFunctionsObjectWhenFunctionsAreCalledThenCa
|
|||
vaSyncSurfacePFN = mockVaSyncSurface;
|
||||
vaGetLibFuncPFN = mockVaGetLibFunc;
|
||||
vaExtGetSurfaceHandlePFN = mockExtGetSurfaceHandle;
|
||||
vaQueryImageFormatsPFN = mockVaQueryImageFormats;
|
||||
vaMaxNumImageFormatsPFN = mockVaMaxNumImageFormats;
|
||||
}
|
||||
|
||||
static VASharingFunctionsGlobalFunctionPointersMock &getInstance() {
|
||||
static VASharingFunctionsGlobalFunctionPointersMock vaSharingFunctions;
|
||||
static VASharingFunctionsGlobalFunctionPointersMock *getInstance(bool release) {
|
||||
static VASharingFunctionsGlobalFunctionPointersMock *vaSharingFunctions = nullptr;
|
||||
if (!vaSharingFunctions) {
|
||||
vaSharingFunctions = new VASharingFunctionsGlobalFunctionPointersMock;
|
||||
} else if (release) {
|
||||
delete vaSharingFunctions;
|
||||
vaSharingFunctions = nullptr;
|
||||
}
|
||||
return vaSharingFunctions;
|
||||
}
|
||||
|
||||
static int mockVaDisplayIsValid(VADisplay vaDisplay) {
|
||||
getInstance().vaDisplayIsValidCalled = true;
|
||||
getInstance(false)->vaDisplayIsValidCalled = true;
|
||||
return 1;
|
||||
};
|
||||
|
||||
static VAStatus mockVaDeriveImage(VADisplay vaDisplay, VASurfaceID vaSurface, VAImage *vaImage) {
|
||||
getInstance().vaDeriveImageCalled = true;
|
||||
getInstance(false)->vaDeriveImageCalled = true;
|
||||
return VA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
static VAStatus mockVaDestroyImage(VADisplay vaDisplay, VAImageID vaImageId) {
|
||||
getInstance().vaDestroyImageCalled = true;
|
||||
getInstance(false)->vaDestroyImageCalled = true;
|
||||
return VA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
static VAStatus mockVaSyncSurface(VADisplay vaDisplay, VASurfaceID vaSurface) {
|
||||
getInstance().vaSyncSurfaceCalled = true;
|
||||
getInstance(false)->vaSyncSurfaceCalled = true;
|
||||
return VA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
static void *mockVaGetLibFunc(VADisplay vaDisplay, const char *func) {
|
||||
getInstance().vaGetLibFuncCalled = true;
|
||||
getInstance(false)->vaGetLibFuncCalled = true;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
static VAStatus mockExtGetSurfaceHandle(VADisplay vaDisplay, VASurfaceID *vaSurface, unsigned int *handleId) {
|
||||
getInstance().vaExtGetSurfaceHandleCalled = true;
|
||||
getInstance(false)->vaExtGetSurfaceHandleCalled = true;
|
||||
return VA_STATUS_SUCCESS;
|
||||
};
|
||||
|
||||
static VAStatus mockVaQueryImageFormats(VADisplay vaDisplay, VAImageFormat *formatList, int *numFormats) {
|
||||
getInstance(false)->vaQueryImageFormatsCalled = true;
|
||||
return VA_STATUS_SUCCESS;
|
||||
};
|
||||
auto &vaSharingFunctions = VASharingFunctionsGlobalFunctionPointersMock::getInstance();
|
||||
EXPECT_TRUE(vaSharingFunctions.isValidVaDisplay());
|
||||
EXPECT_EQ(0, vaSharingFunctions.deriveImage(vaSurfaceId, &vaImage));
|
||||
EXPECT_EQ(0, vaSharingFunctions.destroyImage(vaImage.image_id));
|
||||
EXPECT_EQ(0, vaSharingFunctions.syncSurface(vaSurfaceId));
|
||||
EXPECT_TRUE(nullptr == vaSharingFunctions.getLibFunc("funcName"));
|
||||
EXPECT_EQ(0, vaSharingFunctions.extGetSurfaceHandle(&vaSurfaceId, &handle));
|
||||
|
||||
static int mockVaMaxNumImageFormats(VADisplay vaDisplay) {
|
||||
getInstance(false)->vaMaxNumImageFormatsCalled = true;
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
auto vaSharingFunctions = VASharingFunctionsGlobalFunctionPointersMock::getInstance(false);
|
||||
EXPECT_TRUE(vaSharingFunctions->isValidVaDisplay());
|
||||
EXPECT_EQ(0, vaSharingFunctions->deriveImage(vaSurfaceId, &vaImage));
|
||||
EXPECT_EQ(0, vaSharingFunctions->destroyImage(vaImage.image_id));
|
||||
EXPECT_EQ(0, vaSharingFunctions->syncSurface(vaSurfaceId));
|
||||
EXPECT_TRUE(nullptr == vaSharingFunctions->getLibFunc("funcName"));
|
||||
EXPECT_EQ(0, vaSharingFunctions->extGetSurfaceHandle(&vaSurfaceId, &handle));
|
||||
int numFormats = 0;
|
||||
EXPECT_EQ(0, vaSharingFunctions->queryImageFormats(VADisplay(1), nullptr, &numFormats));
|
||||
EXPECT_EQ(0, vaSharingFunctions->maxNumImageFormats(VADisplay(1)));
|
||||
|
||||
EXPECT_EQ(0u, handle);
|
||||
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance().vaDisplayIsValidCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance().vaDeriveImageCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance().vaDestroyImageCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance().vaSyncSurfaceCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance().vaGetLibFuncCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance().vaExtGetSurfaceHandleCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaDisplayIsValidCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaDeriveImageCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaDestroyImageCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaSyncSurfaceCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaGetLibFuncCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaExtGetSurfaceHandleCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaQueryImageFormatsCalled);
|
||||
EXPECT_TRUE(VASharingFunctionsGlobalFunctionPointersMock::getInstance(false)->vaMaxNumImageFormatsCalled);
|
||||
|
||||
VASharingFunctionsGlobalFunctionPointersMock::getInstance(true);
|
||||
}
|
||||
|
||||
TEST_F(VaSharingTests, givenMockVaWhenVaSurfaceIsCreatedThenMemObjectHasVaHandler) {
|
||||
|
@ -504,6 +536,120 @@ TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndNV12FormatWhenCreatingSha
|
|||
EXPECT_EQ(CL_SUCCESS, errCode);
|
||||
}
|
||||
|
||||
using ApiVaSharingTests = VaSharingTests;
|
||||
|
||||
TEST_F(ApiVaSharingTests, givenSupportedImageTypeWhenGettingSupportedVAApiFormatsThenCorrectListIsReturned) {
|
||||
cl_mem_flags flags[] = {CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY, CL_MEM_READ_WRITE};
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
VAImageFormat vaApiFormats[10] = {};
|
||||
cl_uint numImageFormats = 0;
|
||||
|
||||
VAImageFormat supportedFormat = {VA_FOURCC_NV12, VA_LSB_FIRST, 8, 0, 0, 0, 0, 0};
|
||||
|
||||
for (size_t i = 0; i < arrayCount(flags); i++) {
|
||||
|
||||
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
&context,
|
||||
flags[i],
|
||||
image_type,
|
||||
arrayCount(vaApiFormats),
|
||||
vaApiFormats,
|
||||
&numImageFormats);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, result);
|
||||
EXPECT_EQ(1u, numImageFormats);
|
||||
|
||||
EXPECT_EQ(supportedFormat.fourcc, vaApiFormats[0].fourcc);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ApiVaSharingTests, givenZeroNumEntriesWhenGettingSupportedVAApiFormatsThenNumFormatsIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
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);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, result);
|
||||
EXPECT_EQ(1u, numImageFormats);
|
||||
}
|
||||
|
||||
TEST_F(ApiVaSharingTests, givenNullNumImageFormatsWhenGettingSupportedVAApiFormatsThenNumFormatsIsNotDereferenced) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
|
||||
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
&context,
|
||||
flags,
|
||||
image_type,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(ApiVaSharingTests, givenInvalidImageTypeWhenGettingSupportedVAApiFormatsThenIvalidValueErrorIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE3D;
|
||||
VAImageFormat vaApiFormats[10] = {};
|
||||
cl_uint numImageFormats = 0;
|
||||
|
||||
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
&context,
|
||||
flags,
|
||||
image_type,
|
||||
arrayCount(vaApiFormats),
|
||||
vaApiFormats,
|
||||
&numImageFormats);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_VALUE, result);
|
||||
EXPECT_EQ(0u, numImageFormats);
|
||||
}
|
||||
|
||||
TEST_F(ApiVaSharingTests, givenInvalidFlagsWhenGettingSupportedVAApiFormatsThenIvalidValueErrorIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_NO_ACCESS_INTEL;
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
VAImageFormat vaApiFormats[10] = {};
|
||||
cl_uint numImageFormats = 0;
|
||||
|
||||
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
&context,
|
||||
flags,
|
||||
image_type,
|
||||
arrayCount(vaApiFormats),
|
||||
vaApiFormats,
|
||||
&numImageFormats);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_VALUE, result);
|
||||
EXPECT_EQ(0u, numImageFormats);
|
||||
}
|
||||
|
||||
TEST_F(ApiVaSharingTests, givenInvalidContextWhenGettingSupportedVAApiFormatsThenIvalidContextErrorIsReturned) {
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
VAImageFormat vaApiFormats[10] = {};
|
||||
cl_uint numImageFormats = 0;
|
||||
|
||||
MockContext contextWihtoutVASharing;
|
||||
cl_int result = clGetSupportedVA_APIMediaSurfaceFormatsINTEL(
|
||||
&contextWihtoutVASharing,
|
||||
flags,
|
||||
image_type,
|
||||
arrayCount(vaApiFormats),
|
||||
vaApiFormats,
|
||||
&numImageFormats);
|
||||
|
||||
EXPECT_EQ(CL_INVALID_CONTEXT, result);
|
||||
EXPECT_EQ(0u, numImageFormats);
|
||||
}
|
||||
|
||||
TEST(VaSurface, givenValidPlaneAndFlagsWhenValidatingInputsThenTrueIsReturned) {
|
||||
for (cl_uint plane = 0; plane <= 1; plane++) {
|
||||
EXPECT_TRUE(VASurface::validate(CL_MEM_READ_ONLY, plane));
|
||||
|
@ -522,3 +668,66 @@ TEST(VaSurface, givenEnabledExtendedVaFormatsWhenGettingUnsupportedSurfaceFormat
|
|||
auto formatInfo = VASurface::getExtendedSurfaceFormatInfo(VA_FOURCC_P016);
|
||||
EXPECT_EQ(nullptr, formatInfo);
|
||||
}
|
||||
|
||||
TEST(VaSurface, givenNotSupportedVaFormatsWhenCheckingIfSupportedThenFalseIsReturned) {
|
||||
EXPECT_FALSE(VASurface::isSupportedFourCC(VA_FOURCC_NV11));
|
||||
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.EnableExtendedVaFormats.set(true);
|
||||
EXPECT_FALSE(VASurface::isSupportedFourCC(VA_FOURCC_P016));
|
||||
}
|
||||
|
||||
TEST(VaSharingFunctions, givenErrorReturnedFromVaLibWhenQuerySupportedVaImageFormatsThenSupportedFormatsAreNotSet) {
|
||||
VASharingFunctionsMock sharingFunctions;
|
||||
sharingFunctions.queryImageFormatsReturnStatus = VA_STATUS_ERROR_INVALID_VALUE;
|
||||
|
||||
sharingFunctions.querySupportedVaImageFormats(VADisplay(1));
|
||||
|
||||
EXPECT_EQ(0u, sharingFunctions.supportedFormats.size());
|
||||
}
|
||||
|
||||
TEST(VaSharingFunctions, givenNoSupportedFormatsWhenQuerySupportedVaImageFormatsThenSupportedFormatsAreNotSet) {
|
||||
VASharingFunctionsMock sharingFunctions;
|
||||
EXPECT_EQ(0u, sharingFunctions.supportedFormats.size());
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
cl_uint numImageFormats = 0;
|
||||
VAImageFormat vaApiFormats[10] = {};
|
||||
|
||||
sharingFunctions.getSupportedFormats(
|
||||
flags,
|
||||
image_type,
|
||||
10,
|
||||
vaApiFormats,
|
||||
&numImageFormats);
|
||||
|
||||
EXPECT_EQ(0u, numImageFormats);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
EXPECT_EQ(2u, sharingFunctions.supportedFormats.size());
|
||||
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
cl_mem_object_type image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
cl_uint numImageFormats = 0;
|
||||
VAImageFormat vaApiFormats[3] = {};
|
||||
|
||||
sharingFunctions.getSupportedFormats(
|
||||
flags,
|
||||
image_type,
|
||||
1,
|
||||
vaApiFormats,
|
||||
&numImageFormats);
|
||||
|
||||
EXPECT_EQ(2u, numImageFormats);
|
||||
EXPECT_EQ(static_cast<uint32_t>(VA_FOURCC_NV12), vaApiFormats[0].fourcc);
|
||||
EXPECT_EQ(0u, vaApiFormats[1].fourcc);
|
||||
EXPECT_EQ(0u, vaApiFormats[2].fourcc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue