diff --git a/CMakeLists.txt b/CMakeLists.txt index fbea0e8c52..93e3b1de78 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 dxcore.lib") + set(CMAKE_CXX_STANDARD_LIBRARIES "onecore.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 169bfb8e86..524a9d4683 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_dxcore_factory.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/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 ed7979ad8b..a717689f8e 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_dxcore_factory.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/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 5911527d30..3c3ddcb695 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_dxcore_factory.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/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 8454c1995d..dbcb8fa1ba 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_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/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/wddm_calls.cpp ) 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 deleted file mode 100644 index 70fffe7ef6..0000000000 --- a/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h +++ /dev/null @@ -1,252 +0,0 @@ -/* - * 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_dxcore_factory.cpp b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp similarity index 56% rename from opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp rename to opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp index 7df5998399..e32d63c02a 100644 --- a/opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.cpp +++ b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp @@ -5,12 +5,16 @@ * */ -#include "opencl/test/unit_test/os_interface/windows/ult_dxcore_factory.h" +#include "opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h" namespace NEO { -HRESULT WINAPI ULTDXCoreCreateAdapterFactory(REFIID riid, void **ppFactory) { - *reinterpret_cast(ppFactory) = new UltDXCoreAdapterFactory; +HRESULT WINAPI ULTCreateDXGIFactory(REFIID riid, void **ppFactory) { + + UltIDXGIFactory1 *factory = new UltIDXGIFactory1; + + *(UltIDXGIFactory1 **)ppFactory = factory; + return S_OK; } @@ -18,7 +22,7 @@ void WINAPI ULTGetSystemInfo(SYSTEM_INFO *pSystemInfo) { pSystemInfo->lpMaximumApplicationAddress = is32bit ? (LPVOID)MemoryConstants::max32BitAppAddress : (LPVOID)MemoryConstants::max64BitAppAddress; } -const char *UltDxCoreAdapter::description = "Intel"; +const wchar_t *UltIDXGIAdapter1::description = L"Intel"; extern uint32_t numRootDevicesToEnum = 1; 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 new file mode 100644 index 0000000000..ee97af6312 --- /dev/null +++ b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2017-2021 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 932ce7ddb2..49c0c321b3 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_dxcore_factory.h" +#include "opencl/test/unit_test/os_interface/windows/ult_dxgi_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(&UltDxCoreAdapter::description); - descriptionBackup = "Virtual Render"; + VariableBackup descriptionBackup(&UltIDXGIAdapter1::description); + descriptionBackup = L"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("0x1234"); // Existing device Id + DebugManager.flags.ForceDeviceId.set("1234"); // 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 6a893da5e6..3489a7940c 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_calls.cpp @@ -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_dxcore_factory.h" +#include "opencl/test/unit_test/os_interface/windows/ult_dxgi_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::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory() { - return ULTDXCoreCreateAdapterFactory; +Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() { + return ULTCreateDXGIFactory; } Wddm::GetSystemInfoFcn getGetSystemInfo() { diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index f042ac9b64..fb2b2ddec4 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -37,19 +37,15 @@ #include "gmm_client_context.h" #include "gmm_memory.h" -// clang-format off -#include -#include #include -// clang-format on namespace NEO { -extern Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory(); +extern Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory(); extern Wddm::GetSystemInfoFcn getGetSystemInfo(); extern Wddm::VirtualAllocFcn getVirtualAlloc(); extern Wddm::VirtualFreeFcn getVirtualFree(); -Wddm::DXCoreCreateAdapterFactoryFcn Wddm::dXCoreCreateAdapterFactory = getDXCoreCreateAdapterFactory(); +Wddm::CreateDXGIFactoryFcn Wddm::createDxgiFactory = getCreateDxgiFactory(); Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo(); Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc(); Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree(); @@ -295,12 +291,6 @@ std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &os return std::make_unique(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment, std::move(umKmDataTranslator)); } -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; @@ -312,9 +302,13 @@ std::vector> OSInterface::discoverDevices(ExecutionE return hwDeviceIds; } - IDXCoreAdapterFactory *adapterFactory = nullptr; - HRESULT hr = Wddm::dXCoreCreateAdapterFactory(__uuidof(IDXCoreAdapterFactory), (void **)(&adapterFactory)); - if ((hr != S_OK) || (adapterFactory == nullptr)) { + 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)) { return hwDeviceIds; } @@ -324,86 +318,43 @@ std::vector> OSInterface::discoverDevices(ExecutionE } do { - 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; + 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)); + } } } - 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; + // Release all the non-Intel adapters + pAdapter->Release(); + pAdapter = nullptr; if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) { break; } } - adapterList->Release(); if (hwDeviceIds.empty()) { break; } } while (hwDeviceIds.size() < numRootDevices); - adapterFactory->Release(); + if (pFactory != nullptr) { + pFactory->Release(); + pFactory = nullptr; + } return hwDeviceIds; } diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 135037016a..2ad2f70d27 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -43,7 +43,7 @@ enum class HeapIndex : uint32_t; class Wddm { public: - typedef HRESULT(WINAPI *DXCoreCreateAdapterFactoryFcn)(REFIID riid, void **ppFactory); + typedef HRESULT(WINAPI *CreateDXGIFactoryFcn)(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); @@ -157,7 +157,7 @@ class Wddm { void setGmmInputArg(void *args); WddmVersion getWddmVersion(); - static DXCoreCreateAdapterFactoryFcn dXCoreCreateAdapterFactory; + static CreateDXGIFactoryFcn createDxgiFactory; 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 aba91750b7..3d4bcc7e5b 100644 --- a/shared/source/os_interface/windows/wddm/wddm_calls.cpp +++ b/shared/source/os_interface/windows/wddm/wddm_calls.cpp @@ -7,12 +7,11 @@ #include "shared/source/os_interface/windows/wddm/wddm.h" -#include #include namespace NEO { -Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory() { - return DXCoreCreateAdapterFactory; +Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() { + return CreateDXGIFactory; } Wddm::GetSystemInfoFcn getGetSystemInfo() { diff --git a/shared/test/unit_test/CMakeLists.txt b/shared/test/unit_test/CMakeLists.txt index 860726825b..a9963ef2d7 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_dxcore_factory.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/wddm_calls.cpp ${NEO_SOURCE_DIR}/opencl/test/unit_test/os_interface/windows/wddm_create.cpp )