From 83143c4318ea54851249facdd69effd64eedd40c Mon Sep 17 00:00:00 2001 From: Jaroslaw Chodor Date: Fri, 30 Apr 2021 00:55:12 +0200 Subject: [PATCH] Changing win dev discovery to DXCoreAdapterFactory Signed-off-by: Jaroslaw Chodor --- CMakeLists.txt | 2 +- .../core/test/unit_tests/CMakeLists.txt | 2 +- .../test/unit_tests/CMakeLists.txt | 2 +- .../tools/test/unit_tests/CMakeLists.txt | 2 +- opencl/test/unit_test/libult/CMakeLists.txt | 4 +- ...xgi_factory.cpp => ult_dxcore_factory.cpp} | 14 +- .../os_interface/windows/ult_dxcore_factory.h | 252 ++++++++++++++++++ .../os_interface/windows/ult_dxgi_factory.h | 192 ------------- .../os_interface/windows/wddm20_tests.cpp | 10 +- .../os_interface/windows/wddm_calls.cpp | 8 +- .../source/os_interface/windows/wddm/wddm.cpp | 119 ++++++--- .../source/os_interface/windows/wddm/wddm.h | 4 +- .../os_interface/windows/wddm/wddm_calls.cpp | 7 +- shared/test/unit_test/CMakeLists.txt | 2 +- 14 files changed, 363 insertions(+), 257 deletions(-) rename opencl/test/unit_test/os_interface/windows/{ult_dxgi_factory.cpp => ult_dxcore_factory.cpp} (50%) create mode 100644 opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h delete mode 100644 opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 93e3b1de78..fbea0e8c52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -698,7 +698,7 @@ if(MSVC) set(LINKER_FLAGS "${LINKER_FLAGS} legacy_stdio_float_rounding.obj") # Support for WUD - set(CMAKE_CXX_STANDARD_LIBRARIES "onecore.lib") + set(CMAKE_CXX_STANDARD_LIBRARIES "onecore.lib dxcore.lib") foreach(IT kernel32.lib;user32.lib;gdi32.lib;advapi32.lib;ole32.lib;) set(LINKER_FLAGS "${LINKER_FLAGS} /NODEFAULTLIB:${IT}") endforeach() diff --git a/level_zero/core/test/unit_tests/CMakeLists.txt b/level_zero/core/test/unit_tests/CMakeLists.txt index 524a9d4683..169bfb8e86 100644 --- a/level_zero/core/test/unit_tests/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/CMakeLists.txt @@ -65,7 +65,7 @@ else() ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp + ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp ) diff --git a/level_zero/experimental/test/unit_tests/CMakeLists.txt b/level_zero/experimental/test/unit_tests/CMakeLists.txt index a717689f8e..ed7979ad8b 100644 --- a/level_zero/experimental/test/unit_tests/CMakeLists.txt +++ b/level_zero/experimental/test/unit_tests/CMakeLists.txt @@ -76,7 +76,7 @@ else() ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp + ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp ) diff --git a/level_zero/tools/test/unit_tests/CMakeLists.txt b/level_zero/tools/test/unit_tests/CMakeLists.txt index 3c3ddcb695..5911527d30 100644 --- a/level_zero/tools/test/unit_tests/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/CMakeLists.txt @@ -62,7 +62,7 @@ else() ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp - ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp + ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp ${COMPUTE_RUNTIME_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp ) diff --git a/opencl/test/unit_test/libult/CMakeLists.txt b/opencl/test/unit_test/libult/CMakeLists.txt index dbcb8fa1ba..8454c1995d 100644 --- a/opencl/test/unit_test/libult/CMakeLists.txt +++ b/opencl/test/unit_test/libult/CMakeLists.txt @@ -139,8 +139,8 @@ set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp ) diff --git a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp b/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp similarity index 50% rename from opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp rename to opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp index 5259977a7b..7df5998399 100644 --- a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp +++ b/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp @@ -1,20 +1,16 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include "opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h" +#include "opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h" namespace NEO { -HRESULT WINAPI ULTCreateDXGIFactory(REFIID riid, void **ppFactory) { - - UltIDXGIFactory1 *factory = new UltIDXGIFactory1; - - *(UltIDXGIFactory1 **)ppFactory = factory; - +HRESULT WINAPI ULTDXCoreCreateAdapterFactory(REFIID riid, void **ppFactory) { + *reinterpret_cast(ppFactory) = new UltDXCoreAdapterFactory; return S_OK; } @@ -22,7 +18,7 @@ void WINAPI ULTGetSystemInfo(SYSTEM_INFO *pSystemInfo) { pSystemInfo->lpMaximumApplicationAddress = is32bit ? (LPVOID)MemoryConstants::max32BitAppAddress : (LPVOID)MemoryConstants::max64BitAppAddress; } -const wchar_t *UltIDXGIAdapter1::description = L"Intel"; +const char *UltDxCoreAdapter::description = "Intel"; extern uint32_t numRootDevicesToEnum = 1; diff --git a/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h b/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h new file mode 100644 index 0000000000..70fffe7ef6 --- /dev/null +++ b/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h @@ -0,0 +1,252 @@ +/* + * Copyright (C) 2017-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/helpers/constants.h" +#include "shared/source/helpers/debug_helpers.h" + +#include +#include +#include + +namespace NEO { +static constexpr auto error = 1; + +class UltDxCoreAdapter : public IDXCoreAdapter { + public: + const static char *description; + bool STDMETHODCALLTYPE IsValid() override { + return true; + } + + bool STDMETHODCALLTYPE IsAttributeSupported(REFGUID attributeGUID) override { + UNRECOVERABLE_IF(true); + return false; + } + + bool STDMETHODCALLTYPE IsPropertySupported(DXCoreAdapterProperty property) override { + UNRECOVERABLE_IF(true); + return false; + } + + HRESULT STDMETHODCALLTYPE GetProperty(DXCoreAdapterProperty property, size_t bufferSize, + _Out_writes_bytes_(bufferSize) void *propertyData) override { + size_t requiredSize; + GetPropertySize(property, &requiredSize); + if (bufferSize < requiredSize) { + return error; + } + switch (property) { + default: + UNRECOVERABLE_IF(true); + return error; + case DXCoreAdapterProperty::IsHardware: + *reinterpret_cast(propertyData) = true; + break; + case DXCoreAdapterProperty::DriverDescription: + memcpy_s(propertyData, bufferSize, description, requiredSize); + break; + case DXCoreAdapterProperty::InstanceLuid: + reinterpret_cast(propertyData)->HighPart = 0x1234; + reinterpret_cast(propertyData)->LowPart = 0; + break; + case DXCoreAdapterProperty::HardwareID: { + DXCoreHardwareID ret = {}; + ret.deviceID = 0x1234; + *reinterpret_cast(propertyData) = ret; + } break; + } + + return S_OK; + } + + HRESULT STDMETHODCALLTYPE GetPropertySize(DXCoreAdapterProperty property, _Out_ size_t *bufferSize) override { + switch (property) { + default: + UNRECOVERABLE_IF(true); + return error; + case DXCoreAdapterProperty::IsHardware: + *bufferSize = sizeof(bool); + break; + case DXCoreAdapterProperty::DriverDescription: + *bufferSize = strlen(description) + 1; + break; + case DXCoreAdapterProperty::InstanceLuid: + *bufferSize = sizeof(LUID); + break; + case DXCoreAdapterProperty::HardwareID: + *bufferSize = sizeof(DXCoreHardwareID); + break; + } + + return S_OK; + } + + bool STDMETHODCALLTYPE IsQueryStateSupported(DXCoreAdapterState property) override { + UNRECOVERABLE_IF(true); + return error; + } + + HRESULT STDMETHODCALLTYPE QueryState(DXCoreAdapterState state, size_t inputStateDetailsSize, + _In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails, + size_t outputBufferSize, _Out_writes_bytes_(outputBufferSize) void *outputBuffer) override { + UNRECOVERABLE_IF(true); + return error; + } + + bool STDMETHODCALLTYPE IsSetStateSupported(DXCoreAdapterState property) override { + UNRECOVERABLE_IF(true); + return false; + } + + HRESULT STDMETHODCALLTYPE SetState(DXCoreAdapterState state, size_t inputStateDetailsSize, + _In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails, + size_t inputDataSize, _In_reads_bytes_(inputDataSize) const void *inputData) override { + UNRECOVERABLE_IF(true); + return error; + } + + HRESULT STDMETHODCALLTYPE GetFactory(REFIID riid, _COM_Outptr_ void **ppvFactory) override { + UNRECOVERABLE_IF(true); + return error; + } + + // IUnknown + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) override { + UNRECOVERABLE_IF(true); + return error; + } + + ULONG STDMETHODCALLTYPE AddRef(void) override { + UNRECOVERABLE_IF(true); + return 0; + } + + ULONG STDMETHODCALLTYPE Release(void) override { + // this must be the last instruction + delete this; + return 0; + } +}; + +extern uint32_t numRootDevicesToEnum; +class UltDXCoreAdapterList : public IDXCoreAdapterList { + public: + HRESULT STDMETHODCALLTYPE GetAdapter(uint32_t index, REFIID riid, _COM_Outptr_ void **ppvAdapter) override { + *reinterpret_cast(ppvAdapter) = new UltDxCoreAdapter; + return S_OK; + } + uint32_t STDMETHODCALLTYPE GetAdapterCount() override { + return numRootDevicesToEnum; + } + + bool STDMETHODCALLTYPE IsStale() override { + return false; + } + + HRESULT STDMETHODCALLTYPE GetFactory(REFIID riid, _COM_Outptr_ void **ppvFactory) override { + UNRECOVERABLE_IF(true); + return error; + } + + HRESULT STDMETHODCALLTYPE Sort(uint32_t numPreferences, _In_reads_(numPreferences) const DXCoreAdapterPreference *preferences) override { + UNRECOVERABLE_IF(true); + return error; + } + + bool STDMETHODCALLTYPE IsAdapterPreferenceSupported(DXCoreAdapterPreference preference) override { + UNRECOVERABLE_IF(true); + return false; + } + + // IUnknown + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) override { + UNRECOVERABLE_IF(true); + return error; + } + + ULONG STDMETHODCALLTYPE AddRef(void) override { + UNRECOVERABLE_IF(true); + return 0; + } + + ULONG STDMETHODCALLTYPE Release(void) override { + // this must be the last instruction + delete this; + return 0; + } +}; + +extern uint32_t numRootDevicesToEnum; +class UltDXCoreAdapterFactory : public IDXCoreAdapterFactory { + public: + struct CreateAdapterListArgs { + uint32_t numAttributes; + const GUID *filterAttributesPtr; + std::vector filterAttributesCopy; + REFIID riid; + void **ppvAdapterList; + }; + + std::vector argsOfCreateAdapterListRequests; + + HRESULT STDMETHODCALLTYPE CreateAdapterList(uint32_t numAttributes, _In_reads_(numAttributes) const GUID *filterAttributes, + REFIID riid, _COM_Outptr_ void **ppvAdapterList) override { + argsOfCreateAdapterListRequests.push_back({numAttributes, + filterAttributes, + std::vector{filterAttributes, filterAttributes + numAttributes}, + riid, ppvAdapterList}); + + *reinterpret_cast(ppvAdapterList) = new UltDXCoreAdapterList; + return S_OK; + } + + HRESULT STDMETHODCALLTYPE GetAdapterByLuid(const LUID &adapterLUID, REFIID riid, _COM_Outptr_ void **ppvAdapter) override { + UNRECOVERABLE_IF(true); + return error; + } + + bool STDMETHODCALLTYPE IsNotificationTypeSupported(DXCoreNotificationType notificationType) override { + UNRECOVERABLE_IF(true); + return false; + } + + HRESULT STDMETHODCALLTYPE RegisterEventNotification(_In_ IUnknown *dxCoreObject, DXCoreNotificationType notificationType, + _In_ PFN_DXCORE_NOTIFICATION_CALLBACK callbackFunction, + _In_opt_ void *callbackContext, _Out_ uint32_t *eventCookie) override { + UNRECOVERABLE_IF(true); + return error; + } + + HRESULT STDMETHODCALLTYPE UnregisterEventNotification(uint32_t eventCookie) override { + UNRECOVERABLE_IF(true); + return error; + } + + // IUnknown + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) override { + UNRECOVERABLE_IF(true); + return error; + } + + ULONG STDMETHODCALLTYPE AddRef(void) override { + UNRECOVERABLE_IF(true); + return 0; + } + + ULONG STDMETHODCALLTYPE Release(void) override { + // this must be the last instruction + delete this; + return 0; + } +}; + +HRESULT WINAPI ULTDXCoreCreateAdapterFactory(REFIID riid, void **ppFactory); +void WINAPI ULTGetSystemInfo(SYSTEM_INFO *pSystemInfo); + +} // namespace NEO diff --git a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h deleted file mode 100644 index cbfff4398a..0000000000 --- a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2017-2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "shared/source/helpers/constants.h" - -#include -#include - -namespace NEO { -class UltIDXGIAdapter1 : public IDXGIAdapter1 { - public: - const static wchar_t *description; - // IDXGIAdapter1 - HRESULT STDMETHODCALLTYPE GetDesc1( - _Out_ DXGI_ADAPTER_DESC1 *pDesc) { - - if (pDesc == nullptr) { - return S_FALSE; - } - swprintf(pDesc->Description, 128, description); - pDesc->AdapterLuid.HighPart = 0x1234; - pDesc->DeviceId = 0x1234; - return S_OK; - } - - // IDXGIAdapter - HRESULT STDMETHODCALLTYPE EnumOutputs( - UINT Output, - IDXGIOutput **ppOutput) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetDesc( - DXGI_ADAPTER_DESC *pDesc) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE CheckInterfaceSupport( - _In_ REFGUID InterfaceName, - _Out_ LARGE_INTEGER *pUMDVersion) { - return S_OK; - } - - // IDXGIObject - HRESULT STDMETHODCALLTYPE SetPrivateData( - _In_ REFGUID Name, - UINT DataSize, - const void *pData) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( - _In_ REFGUID Name, - _In_opt_ const IUnknown *pUnknown) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetPrivateData( - _In_ REFGUID Name, - _Inout_ UINT *pDataSize, - _Out_writes_bytes_(*pDataSize) void *pData) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetParent( - _In_ REFIID riid, - _COM_Outptr_ void **ppParent) { - return S_OK; - } - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface( - REFIID riid, - void __RPC_FAR *__RPC_FAR *ppvObject) { - - return S_OK; - } - - ULONG STDMETHODCALLTYPE AddRef(void) { - return 0; - } - - ULONG STDMETHODCALLTYPE Release(void) { - // this must be the last instruction - delete this; - return 0; - } -}; - -extern uint32_t numRootDevicesToEnum; -class UltIDXGIFactory1 : public IDXGIFactory1 { - public: - HRESULT STDMETHODCALLTYPE EnumAdapters1( - UINT Adapter, - IDXGIAdapter1 **ppAdapter) { - if (Adapter >= numRootDevicesToEnum) { - *(IDXGIAdapter1 **)ppAdapter = nullptr; - return DXGI_ERROR_NOT_FOUND; - } - *(IDXGIAdapter1 **)ppAdapter = new UltIDXGIAdapter1; - return S_OK; - } - - BOOL STDMETHODCALLTYPE IsCurrent(void) { - return 0; - } - - HRESULT STDMETHODCALLTYPE EnumAdapters( - UINT Adapter, - IDXGIAdapter **ppAdapter) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE MakeWindowAssociation( - HWND WindowHandle, - UINT Flags) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetWindowAssociation( - _Out_ HWND *pWindowHandle) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE CreateSwapChain( - _In_ IUnknown *pDevice, - _In_ DXGI_SWAP_CHAIN_DESC *pDesc, - IDXGISwapChain **ppSwapChain) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( - HMODULE Module, - IDXGIAdapter **ppAdapter) { - return S_OK; - } - - // IDXGIObject - HRESULT STDMETHODCALLTYPE SetPrivateData( - _In_ REFGUID Name, - UINT DataSize, - const void *pData) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE SetPrivateDataInterface( - _In_ REFGUID Name, - _In_opt_ const IUnknown *pUnknown) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetPrivateData( - _In_ REFGUID Name, - _Inout_ UINT *pDataSize, - _Out_writes_bytes_(*pDataSize) void *pData) { - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetParent( - _In_ REFIID riid, - _COM_Outptr_ void **ppParent) { - return S_OK; - } - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface( - REFIID riid, - void __RPC_FAR *__RPC_FAR *ppvObject) { - - return S_OK; - } - - ULONG STDMETHODCALLTYPE AddRef(void) { - return 0; - } - - ULONG STDMETHODCALLTYPE Release(void) { - // this must be the last instruction - delete this; - return 0; - } -}; -HRESULT WINAPI ULTCreateDXGIFactory(REFIID riid, void **ppFactory); -void WINAPI ULTGetSystemInfo(SYSTEM_INFO *pSystemInfo); - -} // namespace NEO diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index fb8fb4a4e7..44a2100899 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -32,7 +32,7 @@ #include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/mocks/mock_wddm_residency_logger.h" #include "opencl/test/unit_test/os_interface/windows/mock_wddm_allocation.h" -#include "opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h" +#include "opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h" #include "opencl/test/unit_test/os_interface/windows/wddm_fixture.h" #include "gtest/gtest.h" @@ -141,8 +141,8 @@ TEST(WddmDiscoverDevices, givenMultipleRootDevicesExposedWhenCreateMultipleRootD } TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsVirtualRenderThenAdapterIsDiscovered) { - VariableBackup descriptionBackup(&UltIDXGIAdapter1::description); - descriptionBackup = L"Virtual Render"; + VariableBackup descriptionBackup(&UltDxCoreAdapter::description); + descriptionBackup = "Virtual Render"; ExecutionEnvironment executionEnvironment; auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); @@ -1196,7 +1196,7 @@ TEST(WddmGfxPartitionTests, givenInternalFrontWindowHeapWhenAllocatingSmallOrBig TEST_F(Wddm20Tests, givenWddmWhenDiscoverDevicesAndForceDeviceIdIsTheSameAsTheExistingDeviceThenReturnTheAdapter) { DebugManagerStateRestore stateRestore; - DebugManager.flags.ForceDeviceId.set("1234"); // Existing device Id + DebugManager.flags.ForceDeviceId.set("0x1234"); // Existing device Id ExecutionEnvironment executionEnvironment; auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(1u, hwDeviceIds.size()); @@ -1552,4 +1552,4 @@ TEST_F(WddmTestWithMockGdiDll, givenValidInputwhenSettingAllocationPriorityThenT EXPECT_TRUE(wddm->setAllocationPriority(handles, 2, DXGI_RESOURCE_PRIORITY_NORMAL)); EXPECT_EQ(DXGI_RESOURCE_PRIORITY_NORMAL, getLastPriorityFcn()); -} \ No newline at end of file +} diff --git a/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp b/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp index 923e7aebac..6a893da5e6 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,7 +8,7 @@ #include "shared/source/memory_manager/host_ptr_defines.h" #include "opencl/test/unit_test/mocks/mock_wddm.h" -#include "opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h" +#include "opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h" namespace NEO { @@ -20,8 +20,8 @@ LPVOID WINAPI ULTVirtualAlloc(LPVOID inPtr, SIZE_T size, DWORD flags, DWORD type return reinterpret_cast(virtualAllocAddress); } -Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() { - return ULTCreateDXGIFactory; +Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory() { + return ULTDXCoreCreateAdapterFactory; } Wddm::GetSystemInfoFcn getGetSystemInfo() { diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 4c54d61826..89f0174f9a 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -35,15 +35,19 @@ #include "gmm_memory.h" +// clang-format off +#include +#include #include +// clang-format on namespace NEO { -extern Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory(); +extern Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory(); extern Wddm::GetSystemInfoFcn getGetSystemInfo(); extern Wddm::VirtualAllocFcn getVirtualAlloc(); extern Wddm::VirtualFreeFcn getVirtualFree(); -Wddm::CreateDXGIFactoryFcn Wddm::createDxgiFactory = getCreateDxgiFactory(); +Wddm::DXCoreCreateAdapterFactoryFcn Wddm::dXCoreCreateAdapterFactory = getDXCoreCreateAdapterFactory(); Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo(); Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc(); Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree(); @@ -264,6 +268,12 @@ std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &os return std::make_unique(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment); } +inline bool canUseAdapterBasedOnDriverDesc(const char *driverDescription) { + return (strstr(driverDescription, "Intel") != nullptr) || + (strstr(driverDescription, "Citrix") != nullptr) || + (strstr(driverDescription, "Virtual Render") != nullptr); +} + std::vector> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) { std::vector> hwDeviceIds; @@ -275,13 +285,9 @@ std::vector> OSInterface::discoverDevices(ExecutionE return hwDeviceIds; } - DXGI_ADAPTER_DESC1 OpenAdapterDesc = {{0}}; - - IDXGIFactory1 *pFactory = nullptr; - IDXGIAdapter1 *pAdapter = nullptr; - - HRESULT hr = Wddm::createDxgiFactory(__uuidof(IDXGIFactory), (void **)(&pFactory)); - if ((hr != S_OK) || (pFactory == nullptr)) { + IDXCoreAdapterFactory *adapterFactory = nullptr; + HRESULT hr = Wddm::dXCoreCreateAdapterFactory(__uuidof(IDXCoreAdapterFactory), (void **)(&adapterFactory)); + if ((hr != S_OK) || (adapterFactory == nullptr)) { return hwDeviceIds; } @@ -291,43 +297,86 @@ std::vector> OSInterface::discoverDevices(ExecutionE } do { - DWORD iDevNum = 0; - while (pFactory->EnumAdapters1(iDevNum++, &pAdapter) != DXGI_ERROR_NOT_FOUND) { - hr = pAdapter->GetDesc1(&OpenAdapterDesc); - if (hr == S_OK) { - bool createHwDeviceId = false; - // Check for adapters that include either "Intel" or "Citrix" (which may - // be virtualizing one of our adapters) in the description - if ((wcsstr(OpenAdapterDesc.Description, L"Intel") != 0) || - (wcsstr(OpenAdapterDesc.Description, L"Citrix") != 0) || - (wcsstr(OpenAdapterDesc.Description, L"Virtual Render") != 0)) { - char deviceId[16]; - sprintf_s(deviceId, "%X", OpenAdapterDesc.DeviceId); - createHwDeviceId = (DebugManager.flags.ForceDeviceId.get() == "unk") || (DebugManager.flags.ForceDeviceId.get() == deviceId); - } - if (createHwDeviceId) { - auto hwDeviceId = createHwDeviceIdFromAdapterLuid(*osEnvironment, OpenAdapterDesc.AdapterLuid); - if (hwDeviceId) { - hwDeviceIds.push_back(std::move(hwDeviceId)); - } + GUID attributes[]{DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE}; + IDXCoreAdapterList *adapterList = nullptr; + hr = adapterFactory->CreateAdapterList(1, attributes, __uuidof(IDXCoreAdapterList), (void **)(&adapterList)); + if ((hr != S_OK) || (adapterList == nullptr)) { + DEBUG_BREAK_IF(true); + return hwDeviceIds; + } + + auto adapterCount = adapterList->GetAdapterCount(); + IDXCoreAdapter *adapter = nullptr; + for (uint32_t i = 0; i < adapterCount; ++i) { + hr = adapterList->GetAdapter(i, __uuidof(IDXCoreAdapter), (void **)&adapter); + if (S_OK != hr) { + DEBUG_BREAK_IF(true); + continue; + } + + bool isHardware = false; + hr = adapter->GetProperty(DXCoreAdapterProperty::IsHardware, &isHardware); + DEBUG_BREAK_IF(S_OK != hr); + + if ((S_OK != hr) || (false == isHardware)) { + adapter->Release(); + adapter = nullptr; + continue; + } + + static constexpr uint32_t maxDriverDescriptionSize = 512; + StackVec driverDescription; + + size_t driverDescSize = 0; + hr = adapter->GetPropertySize(DXCoreAdapterProperty::DriverDescription, &driverDescSize); + DEBUG_BREAK_IF(S_OK != hr); + driverDescription.resize(driverDescSize); + hr = adapter->GetProperty(DXCoreAdapterProperty::DriverDescription, driverDescription.size(), driverDescription.data()); + DEBUG_BREAK_IF(S_OK != hr); + if ((hr != S_OK) || (false == canUseAdapterBasedOnDriverDesc(driverDescription.data()))) { + adapter->Release(); + adapter = nullptr; + continue; + } + if (DebugManager.flags.ForceDeviceId.get() != "unk") { + DXCoreHardwareID hwId = {}; + adapter->GetProperty(DXCoreAdapterProperty::HardwareID, sizeof(hwId), &hwId); + DEBUG_BREAK_IF(S_OK == hr); + char *endptr = nullptr; + auto reqDeviceId = strtoul(DebugManager.flags.ForceDeviceId.get().c_str(), &endptr, 0); + if (reqDeviceId != hwId.deviceID) { + adapter->Release(); + adapter = nullptr; + continue; } } - // Release all the non-Intel adapters - pAdapter->Release(); - pAdapter = nullptr; + LUID luid = {}; + hr = adapter->GetProperty(DXCoreAdapterProperty::InstanceLuid, &luid); + if (hr != S_OK) { + DEBUG_BREAK_IF(true); + adapter->Release(); + adapter = nullptr; + continue; + } + + auto hwDeviceId = createHwDeviceIdFromAdapterLuid(*osEnvironment, luid); + if (hwDeviceId) { + hwDeviceIds.push_back(std::move(hwDeviceId)); + } + + adapter->Release(); + adapter = nullptr; if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) { break; } } + adapterList->Release(); if (hwDeviceIds.empty()) { break; } } while (hwDeviceIds.size() < numRootDevices); - if (pFactory != nullptr) { - pFactory->Release(); - pFactory = nullptr; - } + adapterFactory->Release(); return hwDeviceIds; } diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 0410dd0663..9f1e69854f 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -44,7 +44,7 @@ enum class HeapIndex : uint32_t; class Wddm { public: - typedef HRESULT(WINAPI *CreateDXGIFactoryFcn)(REFIID riid, void **ppFactory); + typedef HRESULT(WINAPI *DXCoreCreateAdapterFactoryFcn)(REFIID riid, void **ppFactory); typedef void(WINAPI *GetSystemInfoFcn)(SYSTEM_INFO *pSystemInfo); typedef BOOL(WINAPI *VirtualFreeFcn)(LPVOID ptr, SIZE_T size, DWORD flags); typedef LPVOID(WINAPI *VirtualAllocFcn)(LPVOID inPtr, SIZE_T size, DWORD flags, DWORD type); @@ -155,7 +155,7 @@ class Wddm { void setGmmInputArg(void *args); WddmVersion getWddmVersion(); - static CreateDXGIFactoryFcn createDxgiFactory; + static DXCoreCreateAdapterFactoryFcn dXCoreCreateAdapterFactory; uint32_t getRequestedEUCount() const; diff --git a/shared/source/os_interface/windows/wddm/wddm_calls.cpp b/shared/source/os_interface/windows/wddm/wddm_calls.cpp index c8f3c023e9..aba91750b7 100644 --- a/shared/source/os_interface/windows/wddm/wddm_calls.cpp +++ b/shared/source/os_interface/windows/wddm/wddm_calls.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,11 +7,12 @@ #include "shared/source/os_interface/windows/wddm/wddm.h" +#include #include namespace NEO { -Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() { - return CreateDXGIFactory; +Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory() { + return DXCoreCreateAdapterFactory; } Wddm::GetSystemInfoFcn getGetSystemInfo() { diff --git a/shared/test/unit_test/CMakeLists.txt b/shared/test/unit_test/CMakeLists.txt index a9963ef2d7..860726825b 100644 --- a/shared/test/unit_test/CMakeLists.txt +++ b/shared/test/unit_test/CMakeLists.txt @@ -83,7 +83,7 @@ if(NOT SKIP_UNIT_TESTS) ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/create_wddm_memory_manager.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/options.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/sys_calls.cpp - ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp + ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp )