Add synchronization for VA sharing in multi-thread scenarios

Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek
2021-03-12 13:21:52 +00:00
committed by Compute-Runtime-Automation
parent 07b651ccb8
commit 0f2683074d
4 changed files with 10 additions and 2 deletions

View File

@ -10,6 +10,7 @@
#include "opencl/source/sharings/va/va_sharing_defines.h"
#include <functional>
#include <mutex>
#include <vector>
namespace NEO {
@ -82,6 +83,8 @@ class VASharingFunctions : public SharingFunctions {
static bool isVaLibraryAvailable();
std::mutex mutex;
protected:
void *libHandle = nullptr;
VADisplay vaDisplay = nullptr;

View File

@ -41,6 +41,8 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
size_t imageOffset = 0;
size_t imagePitch = 0;
std::unique_lock<std::mutex> lock(sharingFunctions->mutex);
vaStatus = sharingFunctions->exportSurfaceHandle(*surface,
VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
VA_EXPORT_SURFACE_READ_WRITE | VA_EXPORT_SURFACE_SEPARATE_LAYERS,
@ -118,6 +120,8 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
memoryManager->closeSharedHandle(sharedHandle);
lock.unlock();
imgDesc.image_row_pitch = imgInfo.rowPitch;
imgDesc.image_slice_pitch = 0u;
imgInfo.slicePitch = 0u;

View File

@ -17,6 +17,7 @@ namespace NEO {
class VASharingFunctionsMock : public VASharingFunctions {
public:
using VASharingFunctions::mutex;
using VASharingFunctions::supported2PlaneFormats;
using VASharingFunctions::supported3PlaneFormats;

View File

@ -215,7 +215,7 @@ TEST_F(VaSharingTests, givenMockVaWithExportSurfaceHandlerWhenVaSurfaceIsCreated
auto vaHandler = static_cast<VASharing *>(handler);
EXPECT_EQ(vaHandler->peekFunctionsHandler(), &vaSharing->sharingFunctions);
auto sharingFunctions = vaSharing->sharingFunctions;
auto &sharingFunctions = vaSharing->sharingFunctions;
EXPECT_FALSE(sharingFunctions.deriveImageCalled);
EXPECT_FALSE(sharingFunctions.destroyImageCalled);
@ -731,7 +731,7 @@ TEST_F(VaSharingTests, givenMockVaWithExportSurfaceHandlerAndRGBPWhenVaSurfaceIs
auto vaHandler = static_cast<VASharing *>(handler);
EXPECT_EQ(vaHandler->peekFunctionsHandler(), &vaSharing->sharingFunctions);
auto sharingFunctions = vaSharing->sharingFunctions;
auto &sharingFunctions = vaSharing->sharingFunctions;
EXPECT_FALSE(sharingFunctions.deriveImageCalled);
EXPECT_FALSE(sharingFunctions.destroyImageCalled);