diff --git a/runtime/os_interface/debug_variables_base.inl b/runtime/os_interface/debug_variables_base.inl index 55ede4a033..51b50b0e84 100644 --- a/runtime/os_interface/debug_variables_base.inl +++ b/runtime/os_interface/debug_variables_base.inl @@ -99,6 +99,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableVaLibCalls, true, "Enable cl-va sharing lib c 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(bool, EnableFormatQuery, false, "Enable sharing format querying") 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") DECLARE_DEBUG_VARIABLE(int32_t, EnableLocalMemory, -1, "-1: default behavior, 0: disabled, 1: enabled, Allows allocating graphics memory in Local Memory") DECLARE_DEBUG_VARIABLE(int32_t, EnableStatelessToStatefulBufferOffsetOpt, -1, "-1: dont override, 0: disable, 1: enable, Enables buffer-offset improvement of the stateless to stateful optimization") diff --git a/runtime/os_interface/windows/api_win.cpp b/runtime/os_interface/windows/api_win.cpp index 434bf7a510..8e65f0dc09 100644 --- a/runtime/os_interface/windows/api_win.cpp +++ b/runtime/os_interface/windows/api_win.cpp @@ -723,12 +723,12 @@ cl_int CL_API_CALL clGetSupportedDX9MediaSurfaceFormatsINTEL(cl_context context, return CL_SUCCESS; } -cl_int CL_API_CALL clGetSupportedDX10TextureFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, - cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) { +cl_int CL_API_CALL clGetSupportedD3D10TextureFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, + cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) { return getSupportedDXTextureFormats(context, imageType, numEntries, formats, numImageFormats); } -cl_int CL_API_CALL clGetSupportedDX11TextureFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, - cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) { +cl_int CL_API_CALL clGetSupportedD3D11TextureFormatsINTEL(cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, + cl_uint numEntries, DXGI_FORMAT *formats, cl_uint *numImageFormats) { return getSupportedDXTextureFormats(context, imageType, numEntries, formats, numImageFormats); } diff --git a/runtime/platform/extensions.h b/runtime/platform/extensions.h index e4a123b7a6..8279b7899e 100644 --- a/runtime/platform/extensions.h +++ b/runtime/platform/extensions.h @@ -12,7 +12,9 @@ #include namespace NEO { - +namespace Extensions { +constexpr const char *const sharingFormatQuery = "cl_intel_sharing_format_query "; +} extern const char *deviceExtensionsList; std::string getExtensionsList(const HardwareInfo &hwInfo); diff --git a/runtime/sharings/d3d/cl_d3d_api.h b/runtime/sharings/d3d/cl_d3d_api.h index 0ba18f320a..dfffa112c2 100644 --- a/runtime/sharings/d3d/cl_d3d_api.h +++ b/runtime/sharings/d3d/cl_d3d_api.h @@ -187,7 +187,7 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetSupportedDX9MediaSurfaceFormatsINTEL D3DFORMAT *dx9Formats, cl_uint *numImageFormats) CL_API_SUFFIX__VERSION_1_2; -extern CL_API_ENTRY cl_int CL_API_CALL clGetSupportedDX10TextureFormatsINTEL( +extern CL_API_ENTRY cl_int CL_API_CALL clGetSupportedD3D10TextureFormatsINTEL( cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, @@ -195,7 +195,7 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetSupportedDX10TextureFormatsINTEL( DXGI_FORMAT *dx10Formats, cl_uint *numImageFormats) CL_API_SUFFIX__VERSION_1_2; -extern CL_API_ENTRY cl_int CL_API_CALL clGetSupportedDX11TextureFormatsINTEL( +extern CL_API_ENTRY cl_int CL_API_CALL clGetSupportedD3D11TextureFormatsINTEL( cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, diff --git a/runtime/sharings/d3d/enable_d3d.cpp b/runtime/sharings/d3d/enable_d3d.cpp index 271c2b1bc0..8b9ed665b3 100644 --- a/runtime/sharings/d3d/enable_d3d.cpp +++ b/runtime/sharings/d3d/enable_d3d.cpp @@ -145,14 +145,26 @@ void D3DSharingBuilderFactory::fillGlobalDispatchTable() } void *D3DSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { + if (DebugManager.flags.EnableFormatQuery.get() && + functionName == "clGetSupportedDX9MediaSurfaceFormatsINTEL") { + return ((void *)(clGetSupportedDX9MediaSurfaceFormatsINTEL)); + } return nullptr; } void *D3DSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { + if (DebugManager.flags.EnableFormatQuery.get() && + functionName == "clGetSupportedD3D10TextureFormatsINTEL") { + return ((void *)(clGetSupportedD3D10TextureFormatsINTEL)); + } return nullptr; } void *D3DSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { + if (DebugManager.flags.EnableFormatQuery.get() && + functionName == "clGetSupportedD3D11TextureFormatsINTEL") { + return ((void *)(clGetSupportedD3D11TextureFormatsINTEL)); + } return nullptr; } static SharingFactory::RegisterSharing, D3DSharingFunctions> D3D9Sharing; diff --git a/runtime/sharings/gl/CMakeLists.txt b/runtime/sharings/gl/CMakeLists.txt index 15f78e0416..a90cf5c334 100644 --- a/runtime/sharings/gl/CMakeLists.txt +++ b/runtime/sharings/gl/CMakeLists.txt @@ -1,12 +1,14 @@ # -# Copyright (C) 2017-2018 Intel Corporation +# Copyright (C) 2017-2019 Intel Corporation # # SPDX-License-Identifier: MIT # if(WIN32) set(RUNTIME_SRCS_SHARINGS_GL + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_intel.h ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.h ${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.h diff --git a/runtime/sharings/gl/cl_gl_api.cpp b/runtime/sharings/gl/cl_gl_api.cpp index f57cf66c56..877033c836 100644 --- a/runtime/sharings/gl/cl_gl_api.cpp +++ b/runtime/sharings/gl/cl_gl_api.cpp @@ -314,3 +314,24 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties retVal = CL_INVALID_VALUE; return retVal; } + +cl_int CL_API_CALL clGetSupportedGLTextureFormatsINTEL( + cl_context context, + cl_mem_flags flags, + cl_mem_object_type imageType, + cl_uint numEntries, + cl_GLint *glFormats, + cl_uint *numImageFormats) { + + if (numImageFormats) { + *numImageFormats = 0; + } + + Context *pContext = castToObjectOrAbort(context); + auto pSharing = pContext->getSharing(); + if (!pSharing) { + return CL_INVALID_CONTEXT; + } + + return pSharing->getSupportedFormats(flags, imageType, numEntries, reinterpret_cast(glFormats), numImageFormats); +} diff --git a/runtime/sharings/gl/cl_gl_api_intel.h b/runtime/sharings/gl/cl_gl_api_intel.h new file mode 100644 index 0000000000..953cb8221f --- /dev/null +++ b/runtime/sharings/gl/cl_gl_api_intel.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "CL/cl_gl.h" + +extern cl_int CL_API_CALL clGetSupportedGLTextureFormatsINTEL( + cl_context context, + cl_mem_flags flags, + cl_mem_object_type imageType, + cl_uint numEntries, + cl_GLint *glFormats, + cl_uint *numImageFormats); diff --git a/runtime/sharings/gl/win_enable_gl.cpp b/runtime/sharings/gl/win_enable_gl.cpp index 0d54268521..db03424525 100644 --- a/runtime/sharings/gl/win_enable_gl.cpp +++ b/runtime/sharings/gl/win_enable_gl.cpp @@ -8,6 +8,7 @@ #include "runtime/context/context.h" #include "runtime/context/context.inl" #include "runtime/os_interface/debug_settings_manager.h" +#include "runtime/sharings/gl/cl_gl_api_intel.h" #include "runtime/sharings/gl/enable_gl.h" #include "runtime/sharings/gl/gl_sharing.h" #include "runtime/sharings/sharing_factory.h" @@ -98,7 +99,14 @@ std::string GlSharingBuilderFactory::getExtensions() { return ""; } -void *GlSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { return nullptr; } +void *GlSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { + if (DebugManager.flags.EnableFormatQuery.get() && + functionName == "clGetSupportedGLTextureFormatsINTEL") { + return ((void *)(clGetSupportedGLTextureFormatsINTEL)); + } + + return nullptr; +} static SharingFactory::RegisterSharing glSharing; } // namespace NEO diff --git a/runtime/sharings/sharing_factory.cpp b/runtime/sharings/sharing_factory.cpp index 68d231c1d8..a1da81c4d8 100644 --- a/runtime/sharings/sharing_factory.cpp +++ b/runtime/sharings/sharing_factory.cpp @@ -7,6 +7,9 @@ #include "sharing_factory.h" +#include "runtime/os_interface/debug_settings_manager.h" +#include "runtime/platform/extensions.h" + namespace NEO { std::unique_ptr SharingFactory::build() { @@ -23,10 +26,17 @@ std::unique_ptr SharingFactory::build() { std::string SharingFactory::getExtensions() { std::string res; + bool sharingAvailable = false; + for (auto &builder : sharingContextBuilder) { if (builder == nullptr) continue; res += builder->getExtensions(); + sharingAvailable = true; + } + + if (DebugManager.flags.EnableFormatQuery.get() && sharingAvailable) { + res += Extensions::sharingFormatQuery; } return res; diff --git a/runtime/sharings/va/cl_va_api.cpp b/runtime/sharings/va/cl_va_api.cpp index 88da881b48..03ff30e755 100644 --- a/runtime/sharings/va/cl_va_api.cpp +++ b/runtime/sharings/va/cl_va_api.cpp @@ -131,7 +131,7 @@ clEnqueueReleaseVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue, return status; } -cl_int clGetSupportedVA_APIMediaSurfaceFormatsINTEL( +cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL( cl_context context, cl_mem_flags flags, cl_mem_object_type imageType, diff --git a/runtime/sharings/va/cl_va_api.h b/runtime/sharings/va/cl_va_api.h index 0da2a37388..2887878516 100644 --- a/runtime/sharings/va/cl_va_api.h +++ b/runtime/sharings/va/cl_va_api.h @@ -11,7 +11,7 @@ cl_int CL_API_CALL clGetSupportedVA_APIMediaSurfaceFormatsINTEL( cl_context context, cl_mem_flags flags, - cl_mem_object_type image_type, - cl_uint num_entries, - VAImageFormat *va_api_formats, - cl_uint *num_image_formats); + cl_mem_object_type imageType, + cl_uint numEntries, + VAImageFormat *vaApiFormats, + cl_uint *numImageFormats); diff --git a/runtime/sharings/va/enable_va.cpp b/runtime/sharings/va/enable_va.cpp index 0ec6a27e15..9022835f49 100644 --- a/runtime/sharings/va/enable_va.cpp +++ b/runtime/sharings/va/enable_va.cpp @@ -14,6 +14,7 @@ #include "runtime/context/context.inl" #include "runtime/sharings/sharing_factory.h" #include "runtime/sharings/sharing_factory.inl" +#include "runtime/sharings/va/cl_va_api.h" #include "runtime/sharings/va/va_sharing.h" #include @@ -81,6 +82,9 @@ void *VaSharingBuilderFactory::getExtensionFunctionAddress(const std::string &fu 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; } diff --git a/unit_tests/d3d_sharing/cl_dx_sharing_tests.cpp b/unit_tests/d3d_sharing/cl_dx_sharing_tests.cpp index 0b9e69073c..d418328593 100644 --- a/unit_tests/d3d_sharing/cl_dx_sharing_tests.cpp +++ b/unit_tests/d3d_sharing/cl_dx_sharing_tests.cpp @@ -170,16 +170,16 @@ typedef clIntelSharingFormatQueryDX1X clIntelSharingForma typedef clIntelSharingFormatQueryDX1X clIntelSharingFormatQueryDX11; TEST_F(clIntelSharingFormatQueryDX10, givenInvalidContextWhenDX10TextureFormatsRequestedThenInvalidContextError) { - retVal = clGetSupportedDX10TextureFormatsINTEL(NULL, CL_MEM_READ_WRITE, 0, - static_cast(retrievedFormats.size()), - &retrievedFormats[0], &numImageFormats); + retVal = clGetSupportedD3D10TextureFormatsINTEL(NULL, CL_MEM_READ_WRITE, 0, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); EXPECT_EQ(CL_INVALID_CONTEXT, retVal); } TEST_F(clIntelSharingFormatQueryDX10, givenValidParametersWhenRequestedDX10TextureFormatsThenTheResultIsASubsetOfKnownFormats) { - retVal = clGetSupportedDX10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, - static_cast(retrievedFormats.size()), - &retrievedFormats[0], &numImageFormats); + retVal = clGetSupportedD3D10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); for (cl_uint i = 0; i < numImageFormats; ++i) { EXPECT_NE(std::find(availableFormats.begin(), @@ -190,43 +190,43 @@ TEST_F(clIntelSharingFormatQueryDX10, givenValidParametersWhenRequestedDX10Textu } TEST_F(clIntelSharingFormatQueryDX10, givenValidParametersWhenRequestedDX10TextureFormatsTwiceThenTheResultsAreTheSame) { - retVal = clGetSupportedDX10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, - static_cast(retrievedFormats.size()), - &retrievedFormats[0], &numImageFormats); + retVal = clGetSupportedD3D10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); std::vector formatsRetrievedForTheSecondTime(availableFormats.size()); cl_uint anotherNumImageFormats; - retVal = clGetSupportedDX10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, - static_cast(formatsRetrievedForTheSecondTime.size()), - &formatsRetrievedForTheSecondTime[0], &anotherNumImageFormats); + retVal = clGetSupportedD3D10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + static_cast(formatsRetrievedForTheSecondTime.size()), + &formatsRetrievedForTheSecondTime[0], &anotherNumImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); ASSERT_EQ(numImageFormats, anotherNumImageFormats); ASSERT_EQ(memcmp(&retrievedFormats[0], &formatsRetrievedForTheSecondTime[0], numImageFormats * sizeof(DXGI_FORMAT)), 0); } TEST_F(clIntelSharingFormatQueryDX10, givenNullFormatsWhenRequestedDX10TextureFormatsThenNumImageFormatsIsSane) { - retVal = clGetSupportedDX10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, nullptr, &numImageFormats); + retVal = clGetSupportedD3D10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, nullptr, &numImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); ASSERT_LE(0U, numImageFormats); ASSERT_LE(numImageFormats, static_cast(availableFormats.size())); } TEST_F(clIntelSharingFormatQueryDX10, givenNullPointersWhenRequestedDX10TextureFormatsThenCLSuccessIsReturned) { - retVal = clGetSupportedDX10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, static_cast(retrievedFormats.size()), nullptr, nullptr); + retVal = clGetSupportedD3D10TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, static_cast(retrievedFormats.size()), nullptr, nullptr); ASSERT_EQ(retVal, CL_SUCCESS); } TEST_F(clIntelSharingFormatQueryDX11, givenInvalidContextWhenDX11TextureFormatsRequestedThenInvalidContextError) { - retVal = clGetSupportedDX11TextureFormatsINTEL(nullptr, CL_MEM_READ_WRITE, 0, - static_cast(retrievedFormats.size()), - &retrievedFormats[0], &numImageFormats); + retVal = clGetSupportedD3D11TextureFormatsINTEL(nullptr, CL_MEM_READ_WRITE, 0, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); EXPECT_EQ(CL_INVALID_CONTEXT, retVal); } TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestedDX11TextureFormatsThenTheResultIsASubsetOfKnownFormats) { - retVal = clGetSupportedDX11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, - static_cast(retrievedFormats.size()), - &retrievedFormats[0], &numImageFormats); + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); for (cl_uint i = 0; i < numImageFormats; ++i) { EXPECT_NE(std::find(availableFormats.begin(), @@ -237,28 +237,28 @@ TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestedDX11Textu } TEST_F(clIntelSharingFormatQueryDX11, givenNullFormatsWhenRequestedDX11TextureFormatsThenNumImageFormatsIsSane) { - retVal = clGetSupportedDX11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, nullptr, &numImageFormats); + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, nullptr, &numImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); ASSERT_LE(0U, numImageFormats); ASSERT_LE(numImageFormats, static_cast(availableFormats.size())); } TEST_F(clIntelSharingFormatQueryDX11, givenNullPointersWhenRequestedDX11TextureFormatsThenCLSuccessIsReturned) { - retVal = clGetSupportedDX11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, static_cast(retrievedFormats.size()), nullptr, nullptr); + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, static_cast(retrievedFormats.size()), nullptr, nullptr); ASSERT_EQ(retVal, CL_SUCCESS); } TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestedDX11TextureFormatsTwiceThenTheResultsAreTheSame) { - retVal = clGetSupportedDX11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, - static_cast(retrievedFormats.size()), - &retrievedFormats[0], &numImageFormats); + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); std::vector formatsRetrievedForTheSecondTime(availableFormats.size()); cl_uint anotherNumImageFormats; - retVal = clGetSupportedDX11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, - static_cast(formatsRetrievedForTheSecondTime.size()), - &formatsRetrievedForTheSecondTime[0], &anotherNumImageFormats); + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + static_cast(formatsRetrievedForTheSecondTime.size()), + &formatsRetrievedForTheSecondTime[0], &anotherNumImageFormats); ASSERT_EQ(retVal, CL_SUCCESS); ASSERT_EQ(numImageFormats, anotherNumImageFormats); ASSERT_EQ(memcmp(&retrievedFormats[0], &formatsRetrievedForTheSecondTime[0], numImageFormats * sizeof(DXGI_FORMAT)), 0); -} \ No newline at end of file +} diff --git a/unit_tests/d3d_sharing/d3d_tests_part1.cpp b/unit_tests/d3d_sharing/d3d_tests_part1.cpp index f5eb125457..bc0542870c 100644 --- a/unit_tests/d3d_sharing/d3d_tests_part1.cpp +++ b/unit_tests/d3d_sharing/d3d_tests_part1.cpp @@ -20,6 +20,7 @@ #include "unit_tests/fixtures/d3d_test_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_buffer.h" +#include "unit_tests/mocks/mock_sharing_factory.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -727,4 +728,18 @@ TEST(D3D11, givenD3D11BuilderWhenGettingExtensionsThenCorrectExtensionsListIsRet EXPECT_THAT(builderFactory->getExtensions(), testing::HasSubstr(std::string("cl_intel_d3d11_nv12_media_sharing"))); } +TEST(D3DSharingFactory, givenEnabledFormatQueryAndFactoryWithD3DSharingsWhenGettingExtensionFunctionAddressThenFormatQueryFunctionsAreReturned) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableFormatQuery.set(true); + SharingFactoryMock sharingFactory; + + auto function = sharingFactory.getExtensionFunctionAddress("clGetSupportedDX9MediaSurfaceFormatsINTEL"); + EXPECT_EQ(reinterpret_cast(clGetSupportedDX9MediaSurfaceFormatsINTEL), function); + + function = sharingFactory.getExtensionFunctionAddress("clGetSupportedD3D10TextureFormatsINTEL"); + EXPECT_EQ(reinterpret_cast(clGetSupportedD3D10TextureFormatsINTEL), function); + + function = sharingFactory.getExtensionFunctionAddress("clGetSupportedD3D11TextureFormatsINTEL"); + EXPECT_EQ(reinterpret_cast(clGetSupportedD3D11TextureFormatsINTEL), function); +} } // namespace NEO diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 4ca63ce404..57e0fe6c43 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -63,6 +63,7 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_program.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_program.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_sampler.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_sharing_factory.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_sip.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_sip.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_source_level_debugger.h diff --git a/unit_tests/mocks/gl/mock_gl_sharing.h b/unit_tests/mocks/gl/mock_gl_sharing.h index 0c6af00b06..4f6b1ec8d5 100644 --- a/unit_tests/mocks/gl/mock_gl_sharing.h +++ b/unit_tests/mocks/gl/mock_gl_sharing.h @@ -106,6 +106,7 @@ class GlSharingFunctionsMock : public GLSharingFunctions { using GLSharingFunctions::GLContextHandle; using GLSharingFunctions::GLDeviceHandle; + using GLSharingFunctions::getSupportedFormats; using GLSharingFunctions::pfnGlArbSyncObjectCleanup; using GLSharingFunctions::pfnGlArbSyncObjectSetup; using GLSharingFunctions::pfnGlArbSyncObjectSignal; diff --git a/unit_tests/mocks/mock_sharing_factory.h b/unit_tests/mocks/mock_sharing_factory.h new file mode 100644 index 0000000000..ce2c6a066a --- /dev/null +++ b/unit_tests/mocks/mock_sharing_factory.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/sharings/sharing_factory.h" + +class SharingFactoryMock : public NEO::SharingFactory { + public: + using NEO::SharingFactory::sharings; + + SharingFactoryMock() = default; + ~SharingFactoryMock() = default; +}; diff --git a/unit_tests/sharings/gl/gl_sharing_tests.cpp b/unit_tests/sharings/gl/gl_sharing_tests.cpp index 16c0f90e32..de6fbcb940 100644 --- a/unit_tests/sharings/gl/gl_sharing_tests.cpp +++ b/unit_tests/sharings/gl/gl_sharing_tests.cpp @@ -14,6 +14,7 @@ #include "runtime/mem_obj/image.h" #include "runtime/os_interface/os_interface.h" #include "runtime/platform/platform.h" +#include "runtime/sharings/gl/cl_gl_api_intel.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" #include "runtime/sharings/gl/gl_buffer.h" #include "runtime/sharings/gl/gl_sync_event.h" @@ -1288,3 +1289,28 @@ TEST_F(glSharingTests, givenClGLBufferWhenCreatedThenSharedBufferAllocatoinTypeI ASSERT_NE(nullptr, buffer->getGraphicsAllocation()); EXPECT_EQ(GraphicsAllocation::AllocationType::SHARED_BUFFER, buffer->getGraphicsAllocation()->getAllocationType()); } + +using clGetSupportedGLTextureFormatsINTELTests = glSharingTests; + +TEST_F(clGetSupportedGLTextureFormatsINTELTests, givenContextWithoutGlSharingWhenGettingFormatsThenInvalidContextErrorIsReturned) { + MockContext context; + + auto retVal = clGetSupportedGLTextureFormatsINTEL(&context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 0, nullptr, nullptr); + EXPECT_EQ(CL_INVALID_CONTEXT, retVal); +} + +TEST_F(clGetSupportedGLTextureFormatsINTELTests, givenValidInputsWhenGettingFormatsThenSuccesAndValidFormatsAreReturned) { + cl_uint numFormats = 0; + cl_GLint glFormats[2] = {}; + auto glFormatsCount = static_cast(arrayCount(glFormats)); + + auto retVal = clGetSupportedGLTextureFormatsINTEL(&context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, + glFormatsCount, glFormats, &numFormats); + EXPECT_EQ(CL_SUCCESS, retVal); + + EXPECT_NE(0u, numFormats); + + for (uint32_t i = 0; i < glFormatsCount; i++) { + EXPECT_NE(GlSharing::gLToCLFormats.end(), GlSharing::gLToCLFormats.find(glFormats[i])); + } +} diff --git a/unit_tests/sharings/sharing_factory_tests.cpp b/unit_tests/sharings/sharing_factory_tests.cpp index 00e0d405e8..da3f4340e3 100644 --- a/unit_tests/sharings/sharing_factory_tests.cpp +++ b/unit_tests/sharings/sharing_factory_tests.cpp @@ -9,12 +9,15 @@ #include "runtime/context/context.h" #include "runtime/device/device.h" #include "runtime/helpers/string.h" +#include "runtime/platform/extensions.h" #include "runtime/platform/platform.h" #include "runtime/sharings/sharing.h" #include "runtime/sharings/sharing_factory.h" #include "unit_tests/fixtures/memory_management_fixture.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_sharing_factory.h" #include "gtest/gtest.h" @@ -235,3 +238,39 @@ TEST(Context, givenMockSharingBuilderWhenContextWithInvalidPropertiesThenContext context.reset(Context::create(validProperties, deviceVector, nullptr, nullptr, retVal)); EXPECT_NE(nullptr, context.get()); }; + +TEST(SharingFactoryTests, givenDisabledFormatQueryAndFactoryWithSharingWhenAskedForExtensionThenFormatQueryExtensionIsNotReturned) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableFormatQuery.set(false); + + SharingFactoryStateRestore stateRestore; + stateRestore.clearCurrentState(); + stateRestore.registerSharing(SharingType::CLGL_SHARING); + + auto extensionsList = sharingFactory.getExtensions(); + EXPECT_THAT(extensionsList, ::testing::Not(::testing::HasSubstr(Extensions::sharingFormatQuery))); +} + +TEST(SharingFactoryTests, givenEnabledFormatQueryAndFactoryWithSharingWhenAskedForExtensionThenFormatQueryExtensionIsReturned) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableFormatQuery.set(true); + + SharingFactoryStateRestore stateRestore; + stateRestore.clearCurrentState(); + stateRestore.registerSharing(SharingType::CLGL_SHARING); + + auto extensionsList = sharingFactory.getExtensions(); + EXPECT_THAT(extensionsList, ::testing::HasSubstr(Extensions::sharingFormatQuery)); +} + +TEST(SharingFactoryTests, givenEnabledFormatQueryAndFactoryWithNoSharingsWhenAskedForExtensionThenNoExtensionIsReturned) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableFormatQuery.set(true); + + SharingFactoryStateRestore sharingFactory; + + sharingFactory.clearCurrentState(); + + auto extensionsList = sharingFactory.getExtensions(); + EXPECT_THAT(extensionsList, ::testing::Not(::testing::HasSubstr(Extensions::sharingFormatQuery))); +} diff --git a/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp b/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp index 9e3b8753a4..c40ac301c6 100644 --- a/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp +++ b/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp @@ -5,7 +5,9 @@ * */ +#include "runtime/sharings/va/cl_va_api.h" #include "unit_tests/api/cl_api_tests.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" using namespace NEO; @@ -32,4 +34,12 @@ TEST_F(clGetExtensionFunctionAddressTests, clGetDeviceIDsFromVA_APIMediaAdapterI auto retVal = clGetExtensionFunctionAddress("clGetDeviceIDsFromVA_APIMediaAdapterINTEL"); EXPECT_EQ(retVal, reinterpret_cast(clGetDeviceIDsFromVA_APIMediaAdapterINTEL)); } + +TEST_F(clGetExtensionFunctionAddressTests, givenEnabledFormatQueryWhenGettingFuncionAddressThenCorrectAddressIsReturned) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableFormatQuery.set(true); + + auto retVal = clGetExtensionFunctionAddress("clGetSupportedVA_APIMediaSurfaceFormatsINTEL"); + EXPECT_EQ(retVal, reinterpret_cast(clGetSupportedVA_APIMediaSurfaceFormatsINTEL)); +} } // namespace ULT diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index af4d329f6d..5e5b960233 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -109,3 +109,4 @@ EnableCacheFlushAfterWalker = 0 EnableHostPtrTracking = 1 DisableDcFlushInEpilogue = 0 OverrideInvalidEngineWithDefault = 0 +EnableFormatQuery = 0