Skip to content

Commit 4733e51

Browse files
Extended format support in VA sharing
- enabled with Debug Variable - allow P010 surface sharing Related-To: NEO-3049 Change-Id: I837d9f2e31a4ea2a9cf763430021929222cf3001 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 445ee08 commit 4733e51

File tree

9 files changed

+115
-10
lines changed

9 files changed

+115
-10
lines changed

runtime/gmm_helper/gmm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void Gmm::queryImageParams(ImageInfo &imgInfo) {
179179
imgInfo.offset = reqOffsetInfo.Render.Offset;
180180
}
181181

182-
if (imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_FORMAT_NV12) {
182+
if (imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12 || imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010) {
183183
GMM_REQ_OFFSET_INFO reqOffsetInfo = {};
184184
reqOffsetInfo.ReqLock = 1;
185185
reqOffsetInfo.Slice = 1;

runtime/helpers/surface_formats.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ const SurfaceFormatInfo SurfaceFormats::planarYuvSurfaceFormats[] = {
182182
{{CL_NV12_INTEL, CL_UNORM_INT8}, GMM_FORMAT_NV12, GFX3DSTATE_SURFACEFORMAT_NV12 , 0, 1, 1, 1}
183183
};
184184

185-
186185
#endif
187186

188187
const SurfaceFormatInfo SurfaceFormats::readOnlyDepthSurfaceFormats[] = {

runtime/os_interface/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableForcePin, true, "Enables early pinning for me
9696
DECLARE_DEBUG_VARIABLE(bool, EnableComputeWorkSizeND, true, "Enables diffrent algorithm to compute local work size")
9797
DECLARE_DEBUG_VARIABLE(bool, EnableComputeWorkSizeSquared, false, "Enables algorithm to compute the most squared work group as possible")
9898
DECLARE_DEBUG_VARIABLE(bool, EnableVaLibCalls, true, "Enable cl-va sharing lib calls")
99+
DECLARE_DEBUG_VARIABLE(bool, EnableExtendedVaFormats, false, "Enable more formats in cl-va sharing")
99100
DECLARE_DEBUG_VARIABLE(bool, AddClGlSharing, false, "Add cl-gl extension")
100101
DECLARE_DEBUG_VARIABLE(bool, EnablePassInlineData, false, "Enable passing of inline data")
101102
DECLARE_DEBUG_VARIABLE(int32_t, EnableCacheFlushAfterWalker, 0, "-1: platform behavior, 0: disabled, 1: enabled. Adds dedicated cache flush command after WALKER command when surfaces used by kernel require to flush the cache")

runtime/sharings/va/va_surface.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
2626
VAImage vaImage = {};
2727
cl_image_desc imgDesc = {};
2828
cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8};
29-
cl_image_format imgFormat = {};
30-
const SurfaceFormatInfo *gmmSurfaceFormat = nullptr;
31-
const SurfaceFormatInfo *imgSurfaceFormat = nullptr;
29+
cl_channel_order channelOrder = CL_RG;
30+
cl_channel_type channelType = CL_UNORM_INT8;
3231
ImageInfo imgInfo = {0};
3332
VAImageID imageId = 0;
3433
McsSurfaceInfo mcsSurfaceInfo = {};
@@ -40,20 +39,27 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh
4039
imgDesc.image_width = vaImage.width;
4140
imgDesc.image_height = vaImage.height;
4241
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
43-
gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat);
44-
imgInfo.surfaceFormat = gmmSurfaceFormat;
4542

4643
if (plane == 0) {
4744
imgInfo.plane = GMM_PLANE_Y;
48-
imgFormat = {CL_R, CL_UNORM_INT8};
45+
channelOrder = CL_R;
4946
} else if (plane == 1) {
5047
imgInfo.plane = GMM_PLANE_U;
51-
imgFormat = {CL_RG, CL_UNORM_INT8};
48+
channelOrder = CL_RG;
5249
} else {
5350
UNRECOVERABLE_IF(true);
5451
}
5552

56-
imgSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat);
53+
auto gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat); //vaImage.format.fourcc == VA_FOURCC_NV12
54+
55+
if (DebugManager.flags.EnableExtendedVaFormats.get() && vaImage.format.fourcc == VA_FOURCC_P010) {
56+
channelType = CL_UNORM_INT16;
57+
gmmSurfaceFormat = getExtendedSurfaceFormatInfo(vaImage.format.fourcc);
58+
}
59+
imgInfo.surfaceFormat = gmmSurfaceFormat;
60+
61+
cl_image_format imgFormat = {channelOrder, channelType};
62+
auto imgSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat);
5763

5864
sharingFunctions->extGetSurfaceHandle(surface, &sharedHandle);
5965
AllocationProperties properties(false, imgInfo, GraphicsAllocation::AllocationType::SHARED_IMAGE);
@@ -107,4 +113,18 @@ bool VASurface::validate(cl_mem_flags flags, cl_uint plane) {
107113
}
108114
return true;
109115
}
116+
117+
const SurfaceFormatInfo *VASurface::getExtendedSurfaceFormatInfo(uint32_t formatFourCC) {
118+
if (formatFourCC == VA_FOURCC_P010) {
119+
static const SurfaceFormatInfo formatInfo = {{CL_NV12_INTEL, CL_UNORM_INT16},
120+
GMM_RESOURCE_FORMAT::GMM_FORMAT_P010,
121+
static_cast<GFX3DSTATE_SURFACEFORMAT>(NUM_GFX3DSTATE_SURFACEFORMATS), // not used for plane images
122+
0,
123+
1,
124+
2,
125+
2};
126+
return &formatInfo;
127+
}
128+
return nullptr;
129+
}
110130
} // namespace NEO

runtime/sharings/va/va_surface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class VASurface : VASharing {
2424
void getMemObjectInfo(size_t &paramValueSize, void *&paramValue) override;
2525

2626
static bool validate(cl_mem_flags flags, cl_uint plane);
27+
static const SurfaceFormatInfo *getExtendedSurfaceFormatInfo(uint32_t formatFourCC);
2728

2829
protected:
2930
VASurface(VASharingFunctions *sharingFunctions, VAImageID imageId,

unit_tests/gmm_helper/gmm_helper_tests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,29 @@ TEST_F(GmmTests, givenTilableImageWhenEnableForceLinearImagesThenYTilingIsDisabl
272272
EXPECT_EQ(queryGmm->resourceParams.Flags.Info.TiledY, 0u);
273273
}
274274

275+
TEST_F(GmmTests, givenPlanarFormatsWhenQueryingImageParamsThenUVOffsetIsQueried) {
276+
cl_image_desc imgDesc{};
277+
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
278+
imgDesc.image_width = 4;
279+
imgDesc.image_height = 4;
280+
imgDesc.image_depth = 1;
281+
282+
SurfaceFormatInfo surfaceFormatNV12 = {{CL_NV12_INTEL, CL_UNORM_INT8}, GMM_FORMAT_NV12, GFX3DSTATE_SURFACEFORMAT_NV12, 0, 1, 1, 1};
283+
SurfaceFormatInfo surfaceFormatP010 = {{CL_R, CL_UNORM_INT16}, GMM_FORMAT_P010, GFX3DSTATE_SURFACEFORMAT_NV12, 0, 1, 2, 2};
284+
285+
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, &surfaceFormatNV12);
286+
imgInfo.yOffsetForUVPlane = 0;
287+
MockGmm::queryImgParams(imgInfo);
288+
289+
EXPECT_NE(0u, imgInfo.yOffsetForUVPlane);
290+
291+
imgInfo = MockGmm::initImgInfo(imgDesc, 0, &surfaceFormatP010);
292+
imgInfo.yOffsetForUVPlane = 0;
293+
294+
MockGmm::queryImgParams(imgInfo);
295+
EXPECT_NE(0u, imgInfo.yOffsetForUVPlane);
296+
}
297+
275298
TEST_F(GmmTests, givenTilingModeSetToTileYWhenHwSupportsTilingThenTileYFlagIsSet) {
276299
cl_image_desc imgDesc{};
277300
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;

unit_tests/mocks/mock_gmm_resource_info.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ void MockGmmResourceInfo::setSurfaceFormat() {
9393

9494
if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010) {
9595
tempSurface.GMMSurfaceFormat = GMM_RESOURCE_FORMAT::GMM_FORMAT_P010;
96+
tempSurface.NumChannels = 1;
97+
tempSurface.ImageElementSizeInBytes = 16;
98+
tempSurface.PerChannelSizeInBytes = 16;
99+
96100
surfaceFormatInfo = &tempSurface;
97101
}
98102

unit_tests/sharings/va/va_sharing_tests.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
#include "runtime/api/api.h"
99
#include "runtime/device/device.h"
10+
#include "runtime/gmm_helper/gmm.h"
11+
#include "runtime/memory_manager/graphics_allocation.h"
1012
#include "runtime/platform/platform.h"
1113
#include "runtime/sharings/va/va_sharing.h"
1214
#include "runtime/sharings/va/va_surface.h"
1315
#include "unit_tests/fixtures/platform_fixture.h"
16+
#include "unit_tests/helpers/debug_manager_state_restore.h"
1417
#include "unit_tests/libult/create_command_stream.h"
1518
#include "unit_tests/libult/ult_command_stream_receiver.h"
1619
#include "unit_tests/mocks/mock_context.h"
@@ -453,6 +456,54 @@ TEST_F(VaSharingTests, givenInValidPlatformWhenGetDeviceIdsFromVaApiMediaAdapter
453456
EXPECT_EQ(0u, devices);
454457
}
455458

459+
TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndP010FormatWhenCreatingSharedVaSurfaceForPlane0ThenCorrectFormatIsUsedByImageAndGMM) {
460+
DebugManagerStateRestore restore;
461+
DebugManager.flags.EnableExtendedVaFormats.set(true);
462+
463+
vaSharing->sharingFunctions.derivedImageFormatBpp = 16;
464+
vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_P010;
465+
466+
auto vaSurface = std::unique_ptr<Image>(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions,
467+
CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode));
468+
EXPECT_EQ(static_cast<cl_channel_type>(CL_UNORM_INT16), vaSurface->getImageFormat().image_channel_data_type);
469+
EXPECT_EQ(static_cast<cl_channel_order>(CL_R), vaSurface->getImageFormat().image_channel_order);
470+
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R16_UNORM, vaSurface->getSurfaceFormatInfo().GMMSurfaceFormat);
471+
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_P010, vaSurface->getGraphicsAllocation()->getDefaultGmm()->resourceParams.Format);
472+
EXPECT_EQ(CL_SUCCESS, errCode);
473+
}
474+
475+
TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndP010FormatWhenCreatingSharedVaSurfaceForPlane1ThenCorrectFormatIsUsedByImageAndGMM) {
476+
DebugManagerStateRestore restore;
477+
DebugManager.flags.EnableExtendedVaFormats.set(true);
478+
479+
vaSharing->sharingFunctions.derivedImageFormatBpp = 16;
480+
vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_P010;
481+
482+
auto vaSurface = std::unique_ptr<Image>(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions,
483+
CL_MEM_READ_WRITE, &vaSurfaceId, 1, &errCode));
484+
EXPECT_EQ(static_cast<cl_channel_type>(CL_UNORM_INT16), vaSurface->getImageFormat().image_channel_data_type);
485+
EXPECT_EQ(static_cast<cl_channel_order>(CL_RG), vaSurface->getImageFormat().image_channel_order);
486+
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R16G16_UNORM, vaSurface->getSurfaceFormatInfo().GMMSurfaceFormat);
487+
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_P010, vaSurface->getGraphicsAllocation()->getDefaultGmm()->resourceParams.Format);
488+
EXPECT_EQ(CL_SUCCESS, errCode);
489+
}
490+
491+
TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndNV12FormatWhenCreatingSharedVaSurfaceForPlane0ThenCorrectFormatIsUsedByImageAndGMM) {
492+
DebugManagerStateRestore restore;
493+
DebugManager.flags.EnableExtendedVaFormats.set(true);
494+
495+
vaSharing->sharingFunctions.derivedImageFormatBpp = 12;
496+
vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_NV12;
497+
498+
auto vaSurface = std::unique_ptr<Image>(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions,
499+
CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode));
500+
EXPECT_EQ(static_cast<cl_channel_type>(CL_UNORM_INT8), vaSurface->getImageFormat().image_channel_data_type);
501+
EXPECT_EQ(static_cast<cl_channel_order>(CL_R), vaSurface->getImageFormat().image_channel_order);
502+
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R8_UNORM, vaSurface->getSurfaceFormatInfo().GMMSurfaceFormat);
503+
EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12, vaSurface->getGraphicsAllocation()->getDefaultGmm()->resourceParams.Format);
504+
EXPECT_EQ(CL_SUCCESS, errCode);
505+
}
506+
456507
TEST(VaSurface, givenValidPlaneAndFlagsWhenValidatingInputsThenTrueIsReturned) {
457508
for (cl_uint plane = 0; plane <= 1; plane++) {
458509
EXPECT_TRUE(VASurface::validate(CL_MEM_READ_ONLY, plane));
@@ -466,3 +517,8 @@ TEST(VaSurface, givenInValidPlaneOrFlagsWhenValidatingInputsThenTrueIsReturned)
466517
EXPECT_FALSE(VASurface::validate(CL_MEM_READ_ONLY, plane));
467518
EXPECT_FALSE(VASurface::validate(CL_MEM_USE_HOST_PTR, 0));
468519
}
520+
521+
TEST(VaSurface, givenEnabledExtendedVaFormatsWhenGettingUnsupportedSurfaceFormatInfoThenNullptrIsReturned) {
522+
auto formatInfo = VASurface::getExtendedSurfaceFormatInfo(VA_FOURCC_P016);
523+
EXPECT_EQ(nullptr, formatInfo);
524+
}

unit_tests/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SetCommandStreamReceiver = -1
2020
ForceOCLVersion = 0
2121
Force32bitAddressing = 0
2222
EnableVaLibCalls = 1
23+
EnableExtendedVaFormats = 0
2324
EnableNV12 = 1
2425
EnablePackedYuv = 1
2526
EnableIntelVme = 1

0 commit comments

Comments
 (0)