diff --git a/opencl/source/mem_obj/image.cpp b/opencl/source/mem_obj/image.cpp index 478f90da81..4001938689 100644 --- a/opencl/source/mem_obj/image.cpp +++ b/opencl/source/mem_obj/image.cpp @@ -443,8 +443,8 @@ Image *Image::createImageHw(Context *context, const MemoryProperties &memoryProp Image *Image::createSharedImage(Context *context, SharingHandler *sharingHandler, const McsSurfaceInfo &mcsSurfaceInfo, GraphicsAllocation *graphicsAllocation, GraphicsAllocation *mcsAllocation, - cl_mem_flags flags, const ClSurfaceFormatInfo *surfaceFormat, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount) { - auto sharedImage = createImageHw(context, MemoryPropertiesParser::createMemoryProperties(flags, 0, 0), flags, 0, graphicsAllocation->getUnderlyingBufferSize(), + cl_mem_flags flags, cl_mem_flags_intel flagsIntel, const ClSurfaceFormatInfo *surfaceFormat, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount) { + auto sharedImage = createImageHw(context, MemoryPropertiesParser::createMemoryProperties(flags, 0, 0), flags, flagsIntel, graphicsAllocation->getUnderlyingBufferSize(), nullptr, surfaceFormat->OCLImageFormat, Image::convertDescriptor(imgInfo.imgDesc), false, graphicsAllocation, false, baseMipLevel, mipCount, surfaceFormat); sharedImage->setSharingHandler(sharingHandler); sharedImage->setMcsAllocation(mcsAllocation); diff --git a/opencl/source/mem_obj/image.h b/opencl/source/mem_obj/image.h index ded636a141..25fd9372cb 100644 --- a/opencl/source/mem_obj/image.h +++ b/opencl/source/mem_obj/image.h @@ -72,7 +72,7 @@ class Image : public MemObj { static Image *createSharedImage(Context *context, SharingHandler *sharingHandler, const McsSurfaceInfo &mcsSurfaceInfo, GraphicsAllocation *graphicsAllocation, GraphicsAllocation *mcsAllocation, - cl_mem_flags flags, const ClSurfaceFormatInfo *surfaceFormat, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount); + cl_mem_flags flags, cl_mem_flags_intel flagsIntel, const ClSurfaceFormatInfo *surfaceFormat, ImageInfo &imgInfo, uint32_t cubeFaceIndex, uint32_t baseMipLevel, uint32_t mipCount); static cl_int validate(Context *context, const MemoryProperties &memoryProperties, diff --git a/opencl/source/sharings/d3d/d3d_surface.cpp b/opencl/source/sharings/d3d/d3d_surface.cpp index 35ec16239c..a1dbec40f8 100644 --- a/opencl/source/sharings/d3d/d3d_surface.cpp +++ b/opencl/source/sharings/d3d/d3d_surface.cpp @@ -115,7 +115,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo auto surface = new D3DSurface(context, surfaceInfo, surfaceStaging, plane, imagePlane, adapterType, isSharedResource, lockable); - return Image::createSharedImage(context, surface, mcsSurfaceInfo, alloc, nullptr, flags, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); + return Image::createSharedImage(context, surface, mcsSurfaceInfo, alloc, nullptr, flags, 0, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); } void D3DSurface::synchronizeObject(UpdateData &updateData) { diff --git a/opencl/source/sharings/d3d/d3d_texture.cpp b/opencl/source/sharings/d3d/d3d_texture.cpp index 77ca15e7eb..d04bfd603f 100644 --- a/opencl/source/sharings/d3d/d3d_texture.cpp +++ b/opencl/source/sharings/d3d/d3d_texture.cpp @@ -102,7 +102,7 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ : true; } - return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); + return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, 0, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); } template @@ -167,7 +167,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ : true; } - return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); + return Image::createSharedImage(context, d3dTextureObj, mcsSurfaceInfo, alloc, nullptr, flags, 0, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); } template diff --git a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp index c30127da09..1416b0ed09 100644 --- a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp @@ -153,7 +153,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl : true; } - return Image::createSharedImage(context, glTexture, mcsSurfaceInfo, alloc, mcsAlloc, flags, &surfaceFormatInfo, imgInfo, cubeFaceIndex, + return Image::createSharedImage(context, glTexture, mcsSurfaceInfo, alloc, mcsAlloc, flags, 0, &surfaceFormatInfo, imgInfo, cubeFaceIndex, std::max(miplevel, 0), imgInfo.imgDesc.numMipLevels); } // namespace NEO diff --git a/opencl/source/sharings/unified/unified_image.cpp b/opencl/source/sharings/unified/unified_image.cpp index 1bf6cd30cd..d2dea5a473 100644 --- a/opencl/source/sharings/unified/unified_image.cpp +++ b/opencl/source/sharings/unified/unified_image.cpp @@ -50,7 +50,7 @@ Image *UnifiedImage::createSharedUnifiedImage(Context *context, cl_mem_flags fla const uint32_t sharedMipmapsCount = imageDesc->num_mip_levels; auto sharingHandler = new UnifiedImage(sharingFunctions, description.type); return Image::createSharedImage(context, sharingHandler, McsSurfaceInfo{}, graphicsAllocation, nullptr, - flags, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, baseMipmapIndex, sharedMipmapsCount); + flags, 0, clSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, baseMipmapIndex, sharedMipmapsCount); } } // namespace NEO diff --git a/opencl/source/sharings/va/CMakeLists.txt b/opencl/source/sharings/va/CMakeLists.txt index 1b9c4322a2..3f41963d9c 100644 --- a/opencl/source/sharings/va/CMakeLists.txt +++ b/opencl/source/sharings/va/CMakeLists.txt @@ -6,6 +6,7 @@ set(RUNTIME_SRCS_SHARINGS_VA ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_DIR_SUFFIX}/va_extension.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cl_va_api.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cl_va_api.h ${CMAKE_CURRENT_SOURCE_DIR}/va_sharing.cpp @@ -21,3 +22,5 @@ set_property(GLOBAL PROPERTY RUNTIME_SRCS_SHARINGS_VA ${RUNTIME_SRCS_SHARINGS_VA if(NEO__LIBVA_FOUND) target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_VA}) endif(NEO__LIBVA_FOUND) + +add_subdirectories() \ No newline at end of file diff --git a/opencl/source/sharings/va/cl_va_api.cpp b/opencl/source/sharings/va/cl_va_api.cpp index 8910c4137f..62ac3365d4 100644 --- a/opencl/source/sharings/va/cl_va_api.cpp +++ b/opencl/source/sharings/va/cl_va_api.cpp @@ -49,7 +49,7 @@ clCreateFromVA_APIMediaSurfaceINTEL(cl_context context, cl_mem_flags flags, VASu return nullptr; } - image = VASurface::createSharedVaSurface(pContext, pContext->getSharing(), flags, surface, plane, errcodeRet); + image = VASurface::createSharedVaSurface(pContext, pContext->getSharing(), flags, 0, surface, plane, errcodeRet); DBG_LOG_INPUTS("image", image); return image; } diff --git a/opencl/source/sharings/va/enable_va.cpp b/opencl/source/sharings/va/enable_va.cpp index 795d12524c..d47df21ec6 100644 --- a/opencl/source/sharings/va/enable_va.cpp +++ b/opencl/source/sharings/va/enable_va.cpp @@ -84,11 +84,11 @@ void *VaSharingBuilderFactory::getExtensionFunctionAddress(const std::string &fu RETURN_FUNC_PTR_IF_EXIST(clGetDeviceIDsFromVA_APIMediaAdapterINTEL); RETURN_FUNC_PTR_IF_EXIST(clEnqueueAcquireVA_APIMediaSurfacesINTEL); RETURN_FUNC_PTR_IF_EXIST(clEnqueueReleaseVA_APIMediaSurfacesINTEL); - if (DebugManager.flags.EnableFormatQuery.get()) { RETURN_FUNC_PTR_IF_EXIST(clGetSupportedVA_APIMediaSurfaceFormatsINTEL); } - return nullptr; + auto extraFunction = getExtensionFunctionAddressExtra(functionName); + return extraFunction; } static SharingFactory::RegisterSharing vaSharing; diff --git a/opencl/source/sharings/va/enable_va.h b/opencl/source/sharings/va/enable_va.h index 34a1e9773a..e90ca703d9 100644 --- a/opencl/source/sharings/va/enable_va.h +++ b/opencl/source/sharings/va/enable_va.h @@ -35,5 +35,6 @@ class VaSharingBuilderFactory : public SharingBuilderFactory { std::string getExtensions(DriverInfo *driverInfo) override; void fillGlobalDispatchTable() override; void *getExtensionFunctionAddress(const std::string &functionName) override; + virtual void *getExtensionFunctionAddressExtra(const std::string &functionName); }; } // namespace NEO diff --git a/opencl/source/sharings/va/va_extension.cpp b/opencl/source/sharings/va/va_extension.cpp new file mode 100644 index 0000000000..7c5352d0e8 --- /dev/null +++ b/opencl/source/sharings/va/va_extension.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#ifdef LIBVA + +#include "opencl/source/sharings/va/enable_va.h" + +#include + +namespace NEO { + +void *VaSharingBuilderFactory::getExtensionFunctionAddressExtra(const std::string &functionName) { + return nullptr; +} + +} // namespace NEO +#endif \ No newline at end of file diff --git a/opencl/source/sharings/va/va_surface.cpp b/opencl/source/sharings/va/va_surface.cpp index 1eda14bb27..d3dd7d1ed3 100644 --- a/opencl/source/sharings/va/va_surface.cpp +++ b/opencl/source/sharings/va/va_surface.cpp @@ -17,7 +17,7 @@ namespace NEO { Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sharingFunctions, - cl_mem_flags flags, VASurfaceID *surface, + cl_mem_flags flags, cl_mem_flags_intel flagsIntel, VASurfaceID *surface, cl_uint plane, cl_int *errcodeRet) { ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS); @@ -87,7 +87,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh auto vaSurface = new VASurface(sharingFunctions, imageId, plane, surface, context->getInteropUserSyncEnabled()); - auto image = Image::createSharedImage(context, vaSurface, mcsSurfaceInfo, alloc, nullptr, flags, imgSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); + auto image = Image::createSharedImage(context, vaSurface, mcsSurfaceInfo, alloc, nullptr, flags, flagsIntel, imgSurfaceFormat, imgInfo, __GMM_NO_CUBE_MAP, 0, 0); image->setMediaPlaneType(plane); return image; } diff --git a/opencl/source/sharings/va/va_surface.h b/opencl/source/sharings/va/va_surface.h index 76b62c59e4..0590d0cfe1 100644 --- a/opencl/source/sharings/va/va_surface.h +++ b/opencl/source/sharings/va/va_surface.h @@ -16,7 +16,7 @@ class Image; class VASurface : VASharing { public: static Image *createSharedVaSurface(Context *context, VASharingFunctions *sharingFunctions, - cl_mem_flags flags, VASurfaceID *surface, cl_uint plane, + cl_mem_flags flags, cl_mem_flags_intel flagsIntel, VASurfaceID *surface, cl_uint plane, cl_int *errcodeRet); void synchronizeObject(UpdateData &updateData) override; diff --git a/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp b/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp index 2f99d580b5..74160def3b 100644 --- a/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_set_arg_tests.cpp @@ -287,6 +287,7 @@ HWTEST_F(ImageSetArgTest, givenImageArraySizeGreaterThanOneButTypeIsNotImageArra allocation, nullptr, CL_MEM_READ_WRITE, + 0, &surfaceFormatInfo, imageInfo, 0, 0, 0)}; diff --git a/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp b/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp index a08667dc3f..22fcc04377 100644 --- a/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp @@ -110,6 +110,7 @@ TEST_P(CreateTiledImageTest, isTiledImageIsSetForSharedImages) { alloc, nullptr, CL_MEM_READ_WRITE, + 0, &surfaceFormat, info, 0, 0, 0); @@ -149,6 +150,7 @@ TEST_P(CreateNonTiledImageTest, isTiledImageIsNotSetForNonTiledSharedImage) { alloc, nullptr, CL_MEM_READ_WRITE, + 0, &surfaceFormat, info, 0, 0, 0); diff --git a/opencl/test/unit_test/sharings/va/CMakeLists.txt b/opencl/test/unit_test/sharings/va/CMakeLists.txt index f747f8b28a..b475b265ed 100644 --- a/opencl/test/unit_test/sharings/va/CMakeLists.txt +++ b/opencl/test/unit_test/sharings/va/CMakeLists.txt @@ -16,6 +16,7 @@ set(IGDRCL_SRCS_tests_sharings_va ${CMAKE_CURRENT_SOURCE_DIR}/va_base_object_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_linux_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_factory_tests.cpp ) set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_sharings_va ${IGDRCL_SRCS_tests_sharings_va}) @@ -23,3 +24,5 @@ if(NEO__LIBVA_FOUND) list(APPEND IGDRCL_SRCS_tests_sharings_va ${CMAKE_CURRENT_SOURCE_DIR}/va_sharing_enable_tests.cpp) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_sharings_va}) endif(NEO__LIBVA_FOUND) + +add_subdirectories() \ No newline at end of file diff --git a/opencl/test/unit_test/sharings/va/kernel_va_image_arg_tests.cpp b/opencl/test/unit_test/sharings/va/kernel_va_image_arg_tests.cpp index 1505609cc1..e7cfaf1a36 100644 --- a/opencl/test/unit_test/sharings/va/kernel_va_image_arg_tests.cpp +++ b/opencl/test/unit_test/sharings/va/kernel_va_image_arg_tests.cpp @@ -21,7 +21,7 @@ TEST_F(KernelImageArgTest, givenSharedImageWhenSetArgIsCalledThenReportSharedObj VASurfaceID vaSurfaceId = 0u; vaSharing.updateAcquiredHandle(1u); std::unique_ptr sharedImage(VASurface::createSharedVaSurface(context.get(), &vaSharing.sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 0, nullptr)); + CL_MEM_READ_WRITE, 0, &vaSurfaceId, 0, nullptr)); auto sharedMem = static_cast(sharedImage.get()); auto nonSharedMem = static_cast(image.get()); diff --git a/opencl/test/unit_test/sharings/va/va_sharing_factory_tests.cpp b/opencl/test/unit_test/sharings/va/va_sharing_factory_tests.cpp new file mode 100644 index 0000000000..714c654d64 --- /dev/null +++ b/opencl/test/unit_test/sharings/va/va_sharing_factory_tests.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "opencl/source/sharings/va/enable_va.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +class TestVaSharingBuilderFactory : public VaSharingBuilderFactory { + public: + void *getExtensionFunctionAddressExtra(const std::string &functionName) { + if (functionName == "someFunction") { + invocationCount++; + return reinterpret_cast(0x1234); + } + return nullptr; + } + uint32_t invocationCount = 0u; +}; + +TEST(SharingFactoryTests, givenVaFactoryWithSharingExtraWhenAskedThenAddressIsReturned) { + TestVaSharingBuilderFactory sharing; + + ASSERT_EQ(0u, sharing.invocationCount); + + auto ptr = sharing.getExtensionFunctionAddress("someFunction"); + EXPECT_NE(nullptr, ptr); + + EXPECT_EQ(1u, sharing.invocationCount); +} \ No newline at end of file diff --git a/opencl/test/unit_test/sharings/va/va_sharing_tests.cpp b/opencl/test/unit_test/sharings/va/va_sharing_tests.cpp index 8129b3cc9b..731c1a0cf8 100644 --- a/opencl/test/unit_test/sharings/va/va_sharing_tests.cpp +++ b/opencl/test/unit_test/sharings/va/va_sharing_tests.cpp @@ -180,7 +180,7 @@ TEST(VaSharingTest, givenVASharingFunctionsObjectWhenFunctionsAreCalledThenCalls TEST_F(VaSharingTests, givenMockVaWhenVaSurfaceIsCreatedThenMemObjectHasVaHandler) { auto vaSurface = VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode); + CL_MEM_READ_WRITE, 0, &vaSurfaceId, 0, &errCode); EXPECT_NE(nullptr, vaSurface); EXPECT_NE(nullptr, vaSurface->getGraphicsAllocation()); EXPECT_EQ(4096u, vaSurface->getGraphicsAllocation()->getUnderlyingBufferSize()); @@ -212,7 +212,7 @@ TEST_F(VaSharingTests, givenMockVaWhenVaSurfaceIsCreatedThenMemObjectHasVaHandle TEST_F(VaSharingTests, givenInvalidPlaneWhenVaSurfaceIsCreatedThenUnrecoverableIsCalled) { EXPECT_THROW(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 2, &errCode), + CL_MEM_READ_WRITE, 0, &vaSurfaceId, 2, &errCode), std::exception); } @@ -226,7 +226,7 @@ TEST_F(VaSharingTests, givenMockVaWhenVaSurfaceIsCreatedWithNotAlignedWidthAndHe vaSharing->sharingFunctions.derivedImageWidth = 256 + 16; vaSharing->sharingFunctions.derivedImageHeight = 512 + 16; auto vaSurface = VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 1, &errCode); + CL_MEM_READ_WRITE, 0, &vaSurfaceId, 1, &errCode); EXPECT_NE(nullptr, vaSurface); EXPECT_NE(nullptr, vaSurface->getGraphicsAllocation()); EXPECT_EQ(4096u, vaSurface->getGraphicsAllocation()->getUnderlyingBufferSize()); @@ -498,7 +498,7 @@ TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndP010FormatWhenCreatingSha vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_P010; auto vaSurface = std::unique_ptr(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode)); + CL_MEM_READ_WRITE, 0, &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().surfaceFormat.GMMSurfaceFormat); @@ -514,7 +514,7 @@ TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndP010FormatWhenCreatingSha vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_P010; auto vaSurface = std::unique_ptr(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 1, &errCode)); + CL_MEM_READ_WRITE, 0, &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().surfaceFormat.GMMSurfaceFormat); @@ -530,7 +530,7 @@ TEST_F(VaSharingTests, givenEnabledExtendedVaFormatsAndNV12FormatWhenCreatingSha vaSharing->sharingFunctions.derivedImageFormatFourCC = VA_FOURCC_NV12; auto vaSurface = std::unique_ptr(VASurface::createSharedVaSurface(&context, &vaSharing->sharingFunctions, - CL_MEM_READ_WRITE, &vaSurfaceId, 0, &errCode)); + CL_MEM_READ_WRITE, 0, &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().surfaceFormat.GMMSurfaceFormat);