| 1 |
/* |
| 2 |
* Copyright (C) 2018-2024 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
#include "shared/source/helpers/aligned_memory.h" |
| 10 |
#include "shared/source/os_interface/linux/i915.h" |
| 11 |
|
| 12 |
#include "opencl/source/sharings/va/va_sharing.h" |
| 13 |
|
| 14 |
#include "drm_fourcc.h" |
| 15 |
|
| 16 |
#include <va/va_drmcommon.h> |
| 17 |
|
| 18 |
namespace NEO { |
| 19 |
|
| 20 |
class VASharingFunctionsMock : public VASharingFunctions { |
| 21 |
public: |
| 22 |
using VASharingFunctions::mutex; |
| 23 |
using VASharingFunctions::supported2PlaneFormats; |
| 24 |
using VASharingFunctions::supported3PlaneFormats; |
| 25 |
using VASharingFunctions::supportedPackedFormats; |
| 26 |
|
| 27 |
VAImage mockVaImage = {}; |
| 28 |
int32_t derivedImageFormatFourCC = VA_FOURCC_NV12; |
| 29 |
int32_t derivedImageFormatBpp = 8; |
| 30 |
uint16_t derivedImageHeight = 256; |
| 31 |
uint16_t derivedImageWidth = 256; |
| 32 |
VAStatus queryImageFormatsReturnStatus = VA_STATUS_SUCCESS; |
| 33 |
VAStatus syncSurfaceReturnStatus = VA_STATUS_SUCCESS; |
| 34 |
VAStatus deriveImageReturnStatus = VA_STATUS_SUCCESS; |
| 35 |
|
| 36 |
bool isValidDisplayCalled = false; |
| 37 |
bool deriveImageCalled = false; |
| 38 |
bool destroyImageCalled = false; |
| 39 |
bool syncSurfaceCalled = false; |
| 40 |
bool extGetSurfaceHandleCalled = false; |
| 41 |
bool exportSurfaceHandleCalled = false; |
| 42 |
VASurfaceID syncedSurfaceID = 0; |
| 43 |
osHandle acquiredVaHandle = 0; |
| 44 |
|
| 45 |
bool haveExportSurfaceHandle = false; |
| 46 |
|
| 47 |
uint32_t receivedSurfaceMemType = 0; |
| 48 |
uint32_t receivedSurfaceFlags = 0; |
| 49 |
|
| 50 |
VADRMPRIMESurfaceDescriptor mockVaSurfaceDesc{ |
| 51 |
VA_FOURCC_NV12, |
| 52 |
256, |
| 53 |
256, |
| 54 |
1, |
| 55 |
{{8, 98304, I915_FORMAT_MOD_Y_TILED}, {}, {}, {}}, |
| 56 |
2, |
| 57 |
{ |
| 58 |
{DRM_FORMAT_R8, 1, {}, {0, 0, 0, 0}, {256, 0, 0, 0}}, |
| 59 |
{DRM_FORMAT_GR88, 1, {}, {65536, 0, 0, 0}, {256, 0, 0, 0}}, |
| 60 |
{0, 0, {}, {0, 0, 0, 0}, {0, 0, 0, 0}}, |
| 61 |
{0, 0, {}, {0, 0, 0, 0}, {0, 0, 0, 0}}, |
| 62 |
}}; |
| 63 |
|
| 64 |
VASharingFunctionsMock(VADisplay vaDisplay) : VASharingFunctions(vaDisplay) {} |
| 65 |
VASharingFunctionsMock() : VASharingFunctionsMock(nullptr){}; |
| 66 |
|
| 67 |
VAStatus deriveImage(VASurfaceID vaSurface, VAImage *vaImage) override { |
| 68 |
if (deriveImageReturnStatus != VA_STATUS_SUCCESS) { |
| 69 |
return deriveImageReturnStatus; |
| 70 |
} |
| 71 |
deriveImageCalled = true; |
| 72 |
uint32_t pitch; |
| 73 |
vaImage->height = derivedImageHeight; |
| 74 |
vaImage->width = derivedImageWidth; |
| 75 |
pitch = alignUp(derivedImageWidth, 128); |
| 76 |
vaImage->offsets[1] = alignUp(vaImage->height, 32) * pitch; |
| 77 |
vaImage->offsets[2] = vaImage->offsets[1] + 1; |
| 78 |
vaImage->pitches[0] = pitch; |
| 79 |
vaImage->pitches[1] = pitch; |
| 80 |
vaImage->pitches[2] = pitch; |
| 81 |
vaImage->format.fourcc = derivedImageFormatFourCC; |
| 82 |
vaImage->format.bits_per_pixel = derivedImageFormatBpp; |
| 83 |
mockVaImage.width = vaImage->width; |
| 84 |
mockVaImage.height = vaImage->height; |
| 85 |
return VA_STATUS_SUCCESS; |
| 86 |
} |
| 87 |
|
| 88 |
bool isValidVaDisplay() override { |
| 89 |
isValidDisplayCalled = true; |
| 90 |
return 1; |
| 91 |
} |
| 92 |
|
| 93 |
VAStatus destroyImage(VAImageID vaImageId) override { |
| 94 |
destroyImageCalled = true; |
| 95 |
return VA_STATUS_SUCCESS; |
| 96 |
} |
| 97 |
|
| 98 |
VAStatus extGetSurfaceHandle(VASurfaceID *vaSurface, unsigned int *handleId) override { |
| 99 |
extGetSurfaceHandleCalled = true; |
| 100 |
*handleId = acquiredVaHandle; |
| 101 |
return VA_STATUS_SUCCESS; |
| 102 |
} |
| 103 |
|
| 104 |
VAStatus exportSurfaceHandle(VASurfaceID vaSurface, uint32_t memType, uint32_t flags, void *descriptor) override { |
| 105 |
exportSurfaceHandleCalled = true; |
| 106 |
receivedSurfaceMemType = memType; |
| 107 |
receivedSurfaceFlags = flags; |
| 108 |
if (haveExportSurfaceHandle) { |
| 109 |
if (memType != VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2) { |
| 110 |
return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE; |
| 111 |
} |
| 112 |
*(static_cast<VADRMPRIMESurfaceDescriptor *>(descriptor)) = mockVaSurfaceDesc; |
| 113 |
return VA_STATUS_SUCCESS; |
| 114 |
} |
| 115 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 116 |
} |
| 117 |
|
| 118 |
VAStatus syncSurface(VASurfaceID vaSurface) override { |
| 119 |
syncSurfaceCalled = true; |
| 120 |
syncedSurfaceID = vaSurface; |
| 121 |
return syncSurfaceReturnStatus; |
| 122 |
} |
| 123 |
|
| 124 |
VAStatus queryImageFormats(VADisplay vaDisplay, VAImageFormat *formatList, int *numFormats) override { |
| 125 |
if (queryImageFormatsReturnStatus != VA_STATUS_SUCCESS) { |
| 126 |
return queryImageFormatsReturnStatus; |
| 127 |
} |
| 128 |
if (numFormats) { |
| 129 |
*numFormats = 7; |
| 130 |
} |
| 131 |
|
| 132 |
if (formatList) { |
| 133 |
formatList[0].fourcc = VA_FOURCC_NV12; |
| 134 |
formatList[0].bits_per_pixel = 12; |
| 135 |
formatList[0].byte_order = VA_LSB_FIRST; |
| 136 |
|
| 137 |
formatList[1].fourcc = VA_FOURCC_P010; |
| 138 |
formatList[1].bits_per_pixel = 10; |
| 139 |
formatList[1].byte_order = VA_LSB_FIRST; |
| 140 |
|
| 141 |
formatList[2].fourcc = VA_FOURCC_P016; |
| 142 |
formatList[2].bits_per_pixel = 16; |
| 143 |
formatList[2].byte_order = VA_LSB_FIRST; |
| 144 |
|
| 145 |
formatList[3].fourcc = VA_FOURCC_RGBP; |
| 146 |
formatList[3].bits_per_pixel = 8; |
| 147 |
formatList[3].byte_order = VA_LSB_FIRST; |
| 148 |
|
| 149 |
formatList[4].fourcc = VA_FOURCC_YUY2; |
| 150 |
formatList[4].bits_per_pixel = 16; |
| 151 |
formatList[4].byte_order = VA_LSB_FIRST; |
| 152 |
|
| 153 |
formatList[5].fourcc = VA_FOURCC_Y210; |
| 154 |
formatList[5].bits_per_pixel = 32; |
| 155 |
formatList[5].byte_order = VA_LSB_FIRST; |
| 156 |
|
| 157 |
formatList[6].fourcc = VA_FOURCC_ARGB; |
| 158 |
formatList[6].bits_per_pixel = 32; |
| 159 |
formatList[6].byte_order = VA_LSB_FIRST; |
| 160 |
} |
| 161 |
return VA_STATUS_SUCCESS; |
| 162 |
} |
| 163 |
|
| 164 |
int maxNumImageFormats(VADisplay vaDisplay) override { |
| 165 |
return 7; |
| 166 |
} |
| 167 |
}; |
| 168 |
|
| 169 |
class MockVaSharing { |
| 170 |
public: |
| 171 |
void updateAcquiredHandle() { |
| 172 |
sharingFunctions.acquiredVaHandle = sharingHandle; |
| 173 |
} |
| 174 |
void updateAcquiredHandle(unsigned int handle) { |
| 175 |
sharingHandle = handle; |
| 176 |
sharingFunctions.acquiredVaHandle = sharingHandle; |
| 177 |
} |
| 178 |
|
| 179 |
VASharingFunctionsMock sharingFunctions; |
| 180 |
osHandle sharingHandle = 0; |
| 181 |
}; |
| 182 |
} // namespace NEO |