From 642bdd122ea0a4d28756ca6375e72d5b5e81b855 Mon Sep 17 00:00:00 2001 From: Aravind Gopalakrishnan Date: Mon, 10 Mar 2025 18:29:17 +0000 Subject: [PATCH] feature: Add support for d3d11 texture handle types for import and export Related-To: NEO-14329 Signed-off-by: Aravind Gopalakrishnan --- .../device_imp_wddm/device_imp_wddm.cpp | 5 +++-- .../core/source/helpers/properties_parser.h | 5 +++-- .../device_wddm/test_device_exensions.cpp | 3 ++- .../unit_tests/sources/image/test_image.cpp | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/level_zero/core/source/device/device_imp_wddm/device_imp_wddm.cpp b/level_zero/core/source/device/device_imp_wddm/device_imp_wddm.cpp index 7599853bf0..8d3acf59da 100644 --- a/level_zero/core/source/device/device_imp_wddm/device_imp_wddm.cpp +++ b/level_zero/core/source/device/device_imp_wddm/device_imp_wddm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2024 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,7 +32,8 @@ ze_result_t DeviceImp::getExternalMemoryProperties(ze_device_external_memory_pro pExternalMemoryProperties->imageExportTypes = ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32; pExternalMemoryProperties->imageImportTypes = ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32 | ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_HEAP | - ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE; + ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE | + ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_TEXTURE; pExternalMemoryProperties->memoryAllocationExportTypes = ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32; pExternalMemoryProperties->memoryAllocationImportTypes = ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32 | ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_HEAP | diff --git a/level_zero/core/source/helpers/properties_parser.h b/level_zero/core/source/helpers/properties_parser.h index c143ebd5cb..2100d36f21 100644 --- a/level_zero/core/source/helpers/properties_parser.h +++ b/level_zero/core/source/helpers/properties_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2024 Intel Corporation + * Copyright (C) 2021-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -109,7 +109,8 @@ inline ze_result_t prepareL0StructuresLookupTable(StructuresLookupTable &lookupT const ze_external_memory_import_win32_handle_t *windowsExternalMemoryImportDesc = reinterpret_cast(extendedDesc); if ((windowsExternalMemoryImportDesc->flags == ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32) || (windowsExternalMemoryImportDesc->flags == ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_HEAP) || - (windowsExternalMemoryImportDesc->flags == ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE)) { + (windowsExternalMemoryImportDesc->flags == ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE) || + (windowsExternalMemoryImportDesc->flags == ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_TEXTURE)) { lookupTable.sharedHandleType.isSupportedHandle = true; lookupTable.sharedHandleType.isNTHandle = true; lookupTable.sharedHandleType.ntHandle = windowsExternalMemoryImportDesc->handle; diff --git a/level_zero/core/test/unit_tests/sources/device/device_wddm/test_device_exensions.cpp b/level_zero/core/test/unit_tests/sources/device/device_wddm/test_device_exensions.cpp index bf47fd9ab6..e7b797f0d5 100644 --- a/level_zero/core/test/unit_tests/sources/device/device_wddm/test_device_exensions.cpp +++ b/level_zero/core/test/unit_tests/sources/device/device_wddm/test_device_exensions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -57,6 +57,7 @@ TEST_F(DeviceExtensionTest, whenGetExternalMemoryPropertiesIsCalledThenSuccessIs EXPECT_TRUE(externalMemoryProperties.imageImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32); EXPECT_TRUE(externalMemoryProperties.imageImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_HEAP); EXPECT_TRUE(externalMemoryProperties.imageImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D12_RESOURCE); + EXPECT_TRUE(externalMemoryProperties.imageImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_TEXTURE); EXPECT_FALSE(externalMemoryProperties.imageImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF); EXPECT_TRUE(externalMemoryProperties.memoryAllocationExportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32); EXPECT_FALSE(externalMemoryProperties.memoryAllocationExportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_DMA_BUF); diff --git a/level_zero/core/test/unit_tests/sources/image/test_image.cpp b/level_zero/core/test/unit_tests/sources/image/test_image.cpp index d71b680f65..c2b497a725 100644 --- a/level_zero/core/test/unit_tests/sources/image/test_image.cpp +++ b/level_zero/core/test/unit_tests/sources/image/test_image.cpp @@ -733,6 +733,25 @@ HWTEST2_F(ImageCreateExternalMemoryTest, givenD3D12ResourceHandleWhenCreatingIma imageHW.reset(nullptr); } +HWTEST2_F(ImageCreateExternalMemoryTest, givenD3D11TextureHandleWhenCreatingImageThenSuccessIsReturned, MatchAny) { + ze_external_memory_import_win32_handle_t importNTHandle = {}; + importNTHandle.handle = &imageHandle; + importNTHandle.flags = ZE_EXTERNAL_MEMORY_TYPE_FLAG_D3D11_TEXTURE; + importNTHandle.stype = ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMPORT_WIN32; + desc.pNext = &importNTHandle; + + delete driverHandle->svmAllocsManager; + driverHandle->setMemoryManager(execEnv->memoryManager.get()); + driverHandle->svmAllocsManager = new NEO::SVMAllocsManager(execEnv->memoryManager.get(), false); + + auto imageHW = std::make_unique>>(); + auto ret = imageHW->initialize(device, &desc); + ASSERT_EQ(ZE_RESULT_SUCCESS, ret); + ASSERT_EQ(imageHW->getAllocation()->peekSharedHandle(), NEO::toOsHandle(importNTHandle.handle)); + + imageHW.reset(nullptr); +} + using ImageCreateWithMemoryManagerNTHandleMock = Test>; HWTEST2_F(ImageCreateWithMemoryManagerNTHandleMock, givenNTHandleWhenCreatingNV12ImageThenSuccessIsReturnedAndUVOffsetIsSet, MatchAny) {