diff --git a/runtime/gmm_helper/gmm.cpp b/runtime/gmm_helper/gmm.cpp index 4ea103a878..74af577f49 100644 --- a/runtime/gmm_helper/gmm.cpp +++ b/runtime/gmm_helper/gmm.cpp @@ -179,7 +179,7 @@ void Gmm::queryImageParams(ImageInfo &imgInfo) { imgInfo.offset = reqOffsetInfo.Render.Offset; } - if (imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_FORMAT_NV12) { + if (imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12 || imgInfo.surfaceFormat->GMMSurfaceFormat == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010) { GMM_REQ_OFFSET_INFO reqOffsetInfo = {}; reqOffsetInfo.ReqLock = 1; reqOffsetInfo.Slice = 1; diff --git a/runtime/helpers/surface_formats.cpp b/runtime/helpers/surface_formats.cpp index d2f0d1a706..d7f102afe8 100644 --- a/runtime/helpers/surface_formats.cpp +++ b/runtime/helpers/surface_formats.cpp @@ -182,7 +182,6 @@ const SurfaceFormatInfo SurfaceFormats::planarYuvSurfaceFormats[] = { {{CL_NV12_INTEL, CL_UNORM_INT8}, GMM_FORMAT_NV12, GFX3DSTATE_SURFACEFORMAT_NV12 , 0, 1, 1, 1} }; - #endif const SurfaceFormatInfo SurfaceFormats::readOnlyDepthSurfaceFormats[] = { diff --git a/runtime/os_interface/debug_variables_base.inl b/runtime/os_interface/debug_variables_base.inl index b9d79b8df2..2750e41c8c 100644 --- a/runtime/os_interface/debug_variables_base.inl +++ b/runtime/os_interface/debug_variables_base.inl @@ -96,6 +96,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableForcePin, true, "Enables early pinning for me DECLARE_DEBUG_VARIABLE(bool, EnableComputeWorkSizeND, true, "Enables diffrent algorithm to compute local work size") DECLARE_DEBUG_VARIABLE(bool, EnableComputeWorkSizeSquared, false, "Enables algorithm to compute the most squared work group as possible") DECLARE_DEBUG_VARIABLE(bool, EnableVaLibCalls, true, "Enable cl-va sharing lib calls") +DECLARE_DEBUG_VARIABLE(bool, EnableExtendedVaFormats, false, "Enable more formats in cl-va sharing") DECLARE_DEBUG_VARIABLE(bool, AddClGlSharing, false, "Add cl-gl extension") DECLARE_DEBUG_VARIABLE(bool, EnablePassInlineData, false, "Enable passing of inline data") 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") diff --git a/runtime/sharings/va/va_surface.cpp b/runtime/sharings/va/va_surface.cpp index 058e1e98a7..c28abafbc5 100644 --- a/runtime/sharings/va/va_surface.cpp +++ b/runtime/sharings/va/va_surface.cpp @@ -26,9 +26,8 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh VAImage vaImage = {}; cl_image_desc imgDesc = {}; cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; - cl_image_format imgFormat = {}; - const SurfaceFormatInfo *gmmSurfaceFormat = nullptr; - const SurfaceFormatInfo *imgSurfaceFormat = nullptr; + cl_channel_order channelOrder = CL_RG; + cl_channel_type channelType = CL_UNORM_INT8; ImageInfo imgInfo = {0}; VAImageID imageId = 0; McsSurfaceInfo mcsSurfaceInfo = {}; @@ -40,20 +39,27 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh imgDesc.image_width = vaImage.width; imgDesc.image_height = vaImage.height; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat); - imgInfo.surfaceFormat = gmmSurfaceFormat; if (plane == 0) { imgInfo.plane = GMM_PLANE_Y; - imgFormat = {CL_R, CL_UNORM_INT8}; + channelOrder = CL_R; } else if (plane == 1) { imgInfo.plane = GMM_PLANE_U; - imgFormat = {CL_RG, CL_UNORM_INT8}; + channelOrder = CL_RG; } else { UNRECOVERABLE_IF(true); } - imgSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat); + auto gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat); //vaImage.format.fourcc == VA_FOURCC_NV12 + + if (DebugManager.flags.EnableExtendedVaFormats.get() && vaImage.format.fourcc == VA_FOURCC_P010) { + channelType = CL_UNORM_INT16; + gmmSurfaceFormat = getExtendedSurfaceFormatInfo(vaImage.format.fourcc); + } + imgInfo.surfaceFormat = gmmSurfaceFormat; + + cl_image_format imgFormat = {channelOrder, channelType}; + auto imgSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &imgFormat); sharingFunctions->extGetSurfaceHandle(surface, &sharedHandle); AllocationProperties properties(false, imgInfo, GraphicsAllocation::AllocationType::SHARED_IMAGE); @@ -107,4 +113,18 @@ bool VASurface::validate(cl_mem_flags flags, cl_uint plane) { } return true; } + +const SurfaceFormatInfo *VASurface::getExtendedSurfaceFormatInfo(uint32_t formatFourCC) { + if (formatFourCC == VA_FOURCC_P010) { + static const SurfaceFormatInfo formatInfo = {{CL_NV12_INTEL, CL_UNORM_INT16}, + GMM_RESOURCE_FORMAT::GMM_FORMAT_P010, + static_cast(NUM_GFX3DSTATE_SURFACEFORMATS), // not used for plane images + 0, + 1, + 2, + 2}; + return &formatInfo; + } + return nullptr; +} } // namespace NEO diff --git a/runtime/sharings/va/va_surface.h b/runtime/sharings/va/va_surface.h index 7a57c35a59..139295a1bd 100644 --- a/runtime/sharings/va/va_surface.h +++ b/runtime/sharings/va/va_surface.h @@ -24,6 +24,7 @@ class VASurface : VASharing { void getMemObjectInfo(size_t ¶mValueSize, void *¶mValue) override; static bool validate(cl_mem_flags flags, cl_uint plane); + static const SurfaceFormatInfo *getExtendedSurfaceFormatInfo(uint32_t formatFourCC); protected: VASurface(VASharingFunctions *sharingFunctions, VAImageID imageId, diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 33b6c338f2..101694e3a7 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -272,6 +272,29 @@ TEST_F(GmmTests, givenTilableImageWhenEnableForceLinearImagesThenYTilingIsDisabl EXPECT_EQ(queryGmm->resourceParams.Flags.Info.TiledY, 0u); } +TEST_F(GmmTests, givenPlanarFormatsWhenQueryingImageParamsThenUVOffsetIsQueried) { + cl_image_desc imgDesc{}; + imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imgDesc.image_width = 4; + imgDesc.image_height = 4; + imgDesc.image_depth = 1; + + SurfaceFormatInfo surfaceFormatNV12 = {{CL_NV12_INTEL, CL_UNORM_INT8}, GMM_FORMAT_NV12, GFX3DSTATE_SURFACEFORMAT_NV12, 0, 1, 1, 1}; + SurfaceFormatInfo surfaceFormatP010 = {{CL_R, CL_UNORM_INT16}, GMM_FORMAT_P010, GFX3DSTATE_SURFACEFORMAT_NV12, 0, 1, 2, 2}; + + auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, &surfaceFormatNV12); + imgInfo.yOffsetForUVPlane = 0; + MockGmm::queryImgParams(imgInfo); + + EXPECT_NE(0u, imgInfo.yOffsetForUVPlane); + + imgInfo = MockGmm::initImgInfo(imgDesc, 0, &surfaceFormatP010); + imgInfo.yOffsetForUVPlane = 0; + + MockGmm::queryImgParams(imgInfo); + EXPECT_NE(0u, imgInfo.yOffsetForUVPlane); +} + TEST_F(GmmTests, givenTilingModeSetToTileYWhenHwSupportsTilingThenTileYFlagIsSet) { cl_image_desc imgDesc{}; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; diff --git a/unit_tests/mocks/mock_gmm_resource_info.cpp b/unit_tests/mocks/mock_gmm_resource_info.cpp index ee84fc708c..65153bfcdc 100644 --- a/unit_tests/mocks/mock_gmm_resource_info.cpp +++ b/unit_tests/mocks/mock_gmm_resource_info.cpp @@ -93,6 +93,10 @@ void MockGmmResourceInfo::setSurfaceFormat() { if (mockResourceCreateParams.Format == GMM_RESOURCE_FORMAT::GMM_FORMAT_P010) { tempSurface.GMMSurfaceFormat = GMM_RESOURCE_FORMAT::GMM_FORMAT_P010; + tempSurface.NumChannels = 1; + tempSurface.ImageElementSizeInBytes = 16; + tempSurface.PerChannelSizeInBytes = 16; + surfaceFormatInfo = &tempSurface; } diff --git a/unit_tests/sharings/va/va_sharing_tests.cpp b/unit_tests/sharings/va/va_sharing_tests.cpp index 0701a21daf..988fea13ee 100644 --- a/unit_tests/sharings/va/va_sharing_tests.cpp +++ b/unit_tests/sharings/va/va_sharing_tests.cpp @@ -7,10 +7,13 @@ #include "runtime/api/api.h" #include "runtime/device/device.h" +#include "runtime/gmm_helper/gmm.h" +#include "runtime/memory_manager/graphics_allocation.h" #include "runtime/platform/platform.h" #include "runtime/sharings/va/va_sharing.h" #include "runtime/sharings/va/va_surface.h" #include "unit_tests/fixtures/platform_fixture.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/libult/create_command_stream.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "unit_tests/mocks/mock_context.h" @@ -453,6 +456,54 @@ TEST_F(VaSharingTests, givenInValidPlatformWhenGetDeviceIdsFromVaApiMediaAdapter EXPECT_EQ(0u, devices); } +TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndP010FormatWhenCreatingSharedVaSurfaceForPlane0ThenCorrectFormatIsUsedByImageAndGMM) { + DebugManagerStateRestore restore; + DebugManager.flags.EnableExtendedVaFormats.set(true); + + vaSharing->sharingFunctions.derivedImageFormatBpp = 16; + vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_P010; + + auto vaSurface = std::unique_ptr(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, + CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode)); + EXPECT_EQ(static_cast(CL_UNORM_INT16), vaSurface->getImageFormat().image_channel_data_type); + EXPECT_EQ(static_cast(CL_R), vaSurface->getImageFormat().image_channel_order); + EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R16_UNORM, vaSurface->getSurfaceFormatInfo().GMMSurfaceFormat); + EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_P010, vaSurface->getGraphicsAllocation()->getDefaultGmm()->resourceParams.Format); + EXPECT_EQ(CL_SUCCESS, errCode); +} + +TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndP010FormatWhenCreatingSharedVaSurfaceForPlane1ThenCorrectFormatIsUsedByImageAndGMM) { + DebugManagerStateRestore restore; + DebugManager.flags.EnableExtendedVaFormats.set(true); + + vaSharing->sharingFunctions.derivedImageFormatBpp = 16; + vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_P010; + + auto vaSurface = std::unique_ptr(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, + CL_MEM_READ_WRITE, &vaSurfaceId, 1, &errCode)); + EXPECT_EQ(static_cast(CL_UNORM_INT16), vaSurface->getImageFormat().image_channel_data_type); + EXPECT_EQ(static_cast(CL_RG), vaSurface->getImageFormat().image_channel_order); + EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R16G16_UNORM, vaSurface->getSurfaceFormatInfo().GMMSurfaceFormat); + EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_P010, vaSurface->getGraphicsAllocation()->getDefaultGmm()->resourceParams.Format); + EXPECT_EQ(CL_SUCCESS, errCode); +} + +TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndNV12FormatWhenCreatingSharedVaSurfaceForPlane0ThenCorrectFormatIsUsedByImageAndGMM) { + DebugManagerStateRestore restore; + DebugManager.flags.EnableExtendedVaFormats.set(true); + + vaSharing->sharingFunctions.derivedImageFormatBpp = 12; + vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_NV12; + + auto vaSurface = std::unique_ptr(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, + CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode)); + EXPECT_EQ(static_cast(CL_UNORM_INT8), vaSurface->getImageFormat().image_channel_data_type); + EXPECT_EQ(static_cast(CL_R), vaSurface->getImageFormat().image_channel_order); + EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_R8_UNORM, vaSurface->getSurfaceFormatInfo().GMMSurfaceFormat); + EXPECT_EQ(GMM_RESOURCE_FORMAT::GMM_FORMAT_NV12, vaSurface->getGraphicsAllocation()->getDefaultGmm()->resourceParams.Format); + EXPECT_EQ(CL_SUCCESS, errCode); +} + TEST(VaSurface, givenValidPlaneAndFlagsWhenValidatingInputsThenTrueIsReturned) { for (cl_uint plane = 0; plane <= 1; plane++) { EXPECT_TRUE(VASurface::validate(CL_MEM_READ_ONLY, plane)); @@ -466,3 +517,8 @@ TEST(VaSurface, givenInValidPlaneOrFlagsWhenValidatingInputsThenTrueIsReturned) EXPECT_FALSE(VASurface::validate(CL_MEM_READ_ONLY, plane)); EXPECT_FALSE(VASurface::validate(CL_MEM_USE_HOST_PTR, 0)); } + +TEST(VaSurface, givenEnabledExtendedVaFormatsWhenGettingUnsupportedSurfaceFormatInfoThenNullptrIsReturned) { + auto formatInfo = VASurface::getExtendedSurfaceFormatInfo(VA_FOURCC_P016); + EXPECT_EQ(nullptr, formatInfo); +} diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index f01f773a10..0505c2b8a7 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -20,6 +20,7 @@ SetCommandStreamReceiver = -1 ForceOCLVersion = 0 Force32bitAddressing = 0 EnableVaLibCalls = 1 +EnableExtendedVaFormats = 0 EnableNV12 = 1 EnablePackedYuv = 1 EnableIntelVme = 1