diff --git a/opencl/source/os_interface/windows/d3d10_11_sharing_functions.cpp b/opencl/source/os_interface/windows/d3d10_11_sharing_functions.cpp index 31b5c28830..74994618bd 100644 --- a/opencl/source/os_interface/windows/d3d10_11_sharing_functions.cpp +++ b/opencl/source/os_interface/windows/d3d10_11_sharing_functions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -211,8 +211,9 @@ void D3DSharingFunctions::createTexture3d(D3DTexture3d **texture, D3DTextur } template -void D3DSharingFunctions::checkFormatSupport(DXGI_FORMAT format, UINT *pFormat) { - d3dDevice->CheckFormatSupport(format, pFormat); +bool D3DSharingFunctions::checkFormatSupport(DXGI_FORMAT format, UINT *pFormat) { + auto errorCode = d3dDevice->CheckFormatSupport(format, pFormat); + return errorCode == S_OK; } template @@ -230,11 +231,12 @@ std::vector &D3DSharingFunctions::retrieveTextureFormats(cl_me cached_formats.reserve(arrayCount(DXGIFormats)); for (auto DXGIFormat : DXGIFormats) { UINT format = 0; - checkFormatSupport(DXGIFormat, &format); - if (memObjectFormatSupport(imageType, format)) { - cached_formats.push_back(DXGIFormat); - if (D3DSharing::isFormatWithPlane1(DXGIFormat)) { - planarFormats.push_back(DXGIFormat); + if (checkFormatSupport(DXGIFormat, &format)) { + if (memObjectFormatSupport(imageType, format)) { + cached_formats.push_back(DXGIFormat); + if (D3DSharing::isFormatWithPlane1(DXGIFormat)) { + planarFormats.push_back(DXGIFormat); + } } } } diff --git a/opencl/source/os_interface/windows/d3d9_sharing_functions.cpp b/opencl/source/os_interface/windows/d3d9_sharing_functions.cpp index 07516d1cfa..9fe6740bf3 100644 --- a/opencl/source/os_interface/windows/d3d9_sharing_functions.cpp +++ b/opencl/source/os_interface/windows/d3d9_sharing_functions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -56,7 +56,8 @@ void D3DSharingFunctions::createTexture3d(D3DTexture3d **t } template <> -void D3DSharingFunctions::checkFormatSupport(DXGI_FORMAT format, UINT *pFormat) { +bool D3DSharingFunctions::checkFormatSupport(DXGI_FORMAT format, UINT *pFormat) { + return false; } template <> diff --git a/opencl/source/os_interface/windows/d3d_sharing_functions.h b/opencl/source/os_interface/windows/d3d_sharing_functions.h index 28da4dde18..e973f0d660 100644 --- a/opencl/source/os_interface/windows/d3d_sharing_functions.h +++ b/opencl/source/os_interface/windows/d3d_sharing_functions.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -117,7 +117,7 @@ class D3DSharingFunctions : public SharingFunctions { MOCKABLE_VIRTUAL void getRenderTargetData(D3DTexture2d *renderTarget, D3DTexture2d *dstSurface); MOCKABLE_VIRTUAL void updateSurface(D3DTexture2d *src, D3DTexture2d *dst); MOCKABLE_VIRTUAL void updateDevice(D3DResource *resource); - MOCKABLE_VIRTUAL void checkFormatSupport(DXGI_FORMAT format, UINT *pFormat); + MOCKABLE_VIRTUAL bool checkFormatSupport(DXGI_FORMAT format, UINT *pFormat); MOCKABLE_VIRTUAL bool memObjectFormatSupport(cl_mem_object_type object, UINT format); GetDxgiDescFcn getDxgiDescFcn = nullptr; @@ -169,14 +169,18 @@ static inline cl_int getSupportedDXTextureFormats(cl_context context, cl_mem_obj return CL_INVALID_CONTEXT; } - auto supported_formats = pSharing->retrieveTextureFormats(imageType, plane); + size_t numberOfFormats = 0; + if (plane <= 1) { + auto supported_formats = pSharing->retrieveTextureFormats(imageType, plane); + numberOfFormats = supported_formats.size(); - if (formats != nullptr) { - memcpy_s(formats, sizeof(DXGI_FORMAT) * numEntries, supported_formats.data(), sizeof(DXGI_FORMAT) * std::min(static_cast(numEntries), supported_formats.size())); + if (formats != nullptr) { + memcpy_s(formats, sizeof(DXGI_FORMAT) * numEntries, supported_formats.data(), sizeof(DXGI_FORMAT) * std::min(static_cast(numEntries), numberOfFormats)); + } } if (numImageFormats) { - *numImageFormats = static_cast(supported_formats.size()); + *numImageFormats = static_cast(numberOfFormats); } return CL_SUCCESS; } diff --git a/opencl/test/unit_test/d3d_sharing/cl_dx_sharing_tests.cpp b/opencl/test/unit_test/d3d_sharing/cl_dx_sharing_tests.cpp index 52c970135a..e58a66052d 100644 --- a/opencl/test/unit_test/d3d_sharing/cl_dx_sharing_tests.cpp +++ b/opencl/test/unit_test/d3d_sharing/cl_dx_sharing_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -158,6 +158,9 @@ struct clIntelSharingFormatQueryDX1X : public PlatformFixture, public ::testing: mockSharingFcns = new NiceMock>(); context->setSharingFunctions(mockSharingFcns); + auto checkFormat = [](DXGI_FORMAT format, UINT *pFormat) -> bool { *pFormat = D3D11_FORMAT_SUPPORT_BUFFER | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D; return true; }; + ON_CALL(*mockSharingFcns, checkFormatSupport(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(checkFormat)); + availableFormats = ArrayRef(DXGIformats); retrievedFormats.assign(availableFormats.size(), DXGI_FORMAT_UNKNOWN); } @@ -265,11 +268,7 @@ TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestedDX11Textu ASSERT_EQ(memcmp(&retrievedFormats[0], &formatsRetrievedForTheSecondTime[0], numImageFormats * sizeof(DXGI_FORMAT)), 0); } -TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestingDX11TextureFormatsForPlane1ThenPlanarFormatsAeReturned) { - - auto checkFormat = [](DXGI_FORMAT format, UINT *pFormat) -> void { *pFormat = D3D11_FORMAT_SUPPORT_TEXTURE2D; }; - - ON_CALL(*mockSharingFcns, checkFormatSupport(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(checkFormat)); +TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestingDX11TextureFormatsForPlane1ThenPlanarFormatsAreReturned) { ON_CALL(*mockSharingFcns, memObjectFormatSupport(::testing::_, ::testing::_)).WillByDefault(::testing::Return(true)); retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 1, @@ -285,3 +284,19 @@ TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestingDX11Text EXPECT_NE(found, retrievedFormats.end()); } } + +TEST_F(clIntelSharingFormatQueryDX11, givenValidParametersWhenRequestingDX11TextureFormatsForPlane2AndAboveThenZeroFormatsIsReturned) { + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 2, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); + + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(0, numImageFormats); + + retVal = clGetSupportedD3D11TextureFormatsINTEL(context, CL_MEM_READ_WRITE, CL_MEM_OBJECT_IMAGE2D, 3, + static_cast(retrievedFormats.size()), + &retrievedFormats[0], &numImageFormats); + + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(0, numImageFormats); +} diff --git a/opencl/test/unit_test/d3d_sharing/d3d_tests_part2.cpp b/opencl/test/unit_test/d3d_sharing/d3d_tests_part2.cpp index d741cb3516..33203612b8 100644 --- a/opencl/test/unit_test/d3d_sharing/d3d_tests_part2.cpp +++ b/opencl/test/unit_test/d3d_sharing/d3d_tests_part2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -536,6 +536,65 @@ TYPED_TEST_P(D3DTests, givenSharedObjectAndNTHandleAndAllocationFailedWhen3dCrea EXPECT_EQ(retCode, CL_OUT_OF_HOST_MEMORY); } +TYPED_TEST_P(D3DTests, givenFormatNotSupportedByDxWhenGettingSupportedFormatsThenOnlySupportedFormatsAreReturned) { + std::vector unsupportedDXGIformats = { + DXGI_FORMAT_BC6H_TYPELESS, + DXGI_FORMAT_BC6H_UF16, + DXGI_FORMAT_BC6H_SF16, + DXGI_FORMAT_BC7_TYPELESS, + DXGI_FORMAT_BC7_UNORM, + DXGI_FORMAT_BC7_UNORM_SRGB, + DXGI_FORMAT_AYUV, + DXGI_FORMAT_Y410, + DXGI_FORMAT_Y416, + DXGI_FORMAT_420_OPAQUE, + DXGI_FORMAT_YUY2, + DXGI_FORMAT_Y210, + DXGI_FORMAT_Y216, + DXGI_FORMAT_NV11, + DXGI_FORMAT_AI44, + DXGI_FORMAT_IA44, + DXGI_FORMAT_P8, + DXGI_FORMAT_A8P8, + DXGI_FORMAT_B4G4R4A4_UNORM, + DXGI_FORMAT_P208, + DXGI_FORMAT_V208, + DXGI_FORMAT_V408, + DXGI_FORMAT_FORCE_UINT}; + + auto checkFormat = [&](DXGI_FORMAT format, UINT *pFormat) -> bool { + auto iter = std::find(unsupportedDXGIformats.begin(), unsupportedDXGIformats.end(), format); + if (iter != unsupportedDXGIformats.end()) { + return false; + } + *pFormat = D3D11_FORMAT_SUPPORT_BUFFER | D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURE3D; + return true; + }; + + ON_CALL(*mockSharingFcns, checkFormatSupport(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(checkFormat)); + ON_CALL(*mockSharingFcns, memObjectFormatSupport(::testing::_, ::testing::_)).WillByDefault(::testing::Return(true)); + + std::vector formats; + cl_uint numTextureFormats = 0; + auto retVal = getSupportedDXTextureFormats(context, CL_MEM_OBJECT_IMAGE3D, 0, 0, nullptr, &numTextureFormats); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_NE(0u, numTextureFormats); + + formats.resize(numTextureFormats); + retVal = getSupportedDXTextureFormats(context, CL_MEM_OBJECT_IMAGE3D, 0, static_cast(formats.size()), formats.data(), &numTextureFormats); + + EXPECT_EQ(CL_SUCCESS, retVal); + + bool foundUnsupported = false; + for (auto format : formats) { + auto iter = std::find(unsupportedDXGIformats.begin(), unsupportedDXGIformats.end(), format); + if (iter != unsupportedDXGIformats.end()) { + foundUnsupported = true; + } + } + EXPECT_FALSE(foundUnsupported); +} + REGISTER_TYPED_TEST_CASE_P(D3DTests, givenSharedResourceBufferAndInteropUserSyncEnabledWhenReleaseIsCalledThenDontDoExplicitFinish, givenNonSharedResourceBufferAndInteropUserSyncDisabledWhenReleaseIsCalledThenDoExplicitFinishTwice, @@ -558,7 +617,8 @@ REGISTER_TYPED_TEST_CASE_P(D3DTests, givenSharedObjectFromInvalidContextWhen3dCreatedThenReturnCorrectCode, givenSharedObjectFromInvalidContextAndNTHandleWhen3dCreatedThenReturnCorrectCode, givenSharedObjectAndAlocationFailedWhen3dCreatedThenReturnCorrectCode, - givenSharedObjectAndNTHandleAndAllocationFailedWhen3dCreatedThenReturnCorrectCode); + givenSharedObjectAndNTHandleAndAllocationFailedWhen3dCreatedThenReturnCorrectCode, + givenFormatNotSupportedByDxWhenGettingSupportedFormatsThenOnlySupportedFormatsAreReturned); INSTANTIATE_TYPED_TEST_CASE_P(D3DSharingTests, D3DTests, D3DTypes); diff --git a/opencl/test/unit_test/mocks/mock_d3d_objects.h b/opencl/test/unit_test/mocks/mock_d3d_objects.h index c65d198919..68e03dc249 100644 --- a/opencl/test/unit_test/mocks/mock_d3d_objects.h +++ b/opencl/test/unit_test/mocks/mock_d3d_objects.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -56,7 +56,7 @@ class MockD3DSharingFunctions : public D3DSharingFunctions { MOCK_METHOD2_T(getRenderTargetData, void(D3DTexture2d *renderTarget, D3DTexture2d *dstSurface)); MOCK_METHOD2_T(updateSurface, void(D3DTexture2d *src, D3DTexture2d *dst)); MOCK_METHOD1_T(updateDevice, void(D3DResource *resource)); - MOCK_METHOD2_T(checkFormatSupport, void(DXGI_FORMAT format, UINT *pFormat)); + MOCK_METHOD2_T(checkFormatSupport, bool(DXGI_FORMAT format, UINT *pFormat)); MOCK_METHOD2_T(memObjectFormatSupport, bool(cl_mem_object_type object, UINT format)); std::vector> *getTrackedResourcesVector() { return &this->trackedResources; }