diff --git a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp index 622c90884d..5259977a7b 100644 --- a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp +++ b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.cpp @@ -24,6 +24,6 @@ void WINAPI ULTGetSystemInfo(SYSTEM_INFO *pSystemInfo) { const wchar_t *UltIDXGIAdapter1::description = L"Intel"; -extern uint32_t numRootDevicesToEnum = 0; +extern uint32_t numRootDevicesToEnum = 1; } // 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 index e5bcc0cb82..cbfff4398a 100644 --- a/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h +++ b/opencl/test/unit_test/os_interface/windows/ult_dxgi_factory.h @@ -7,7 +7,6 @@ #pragma once -#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/helpers/constants.h" #include @@ -100,13 +99,7 @@ class UltIDXGIFactory1 : public IDXGIFactory1 { HRESULT STDMETHODCALLTYPE EnumAdapters1( UINT Adapter, IDXGIAdapter1 **ppAdapter) { - UINT numRootDevices = 1u; - if (numRootDevicesToEnum > 0u) { - numRootDevices = numRootDevicesToEnum; - } else if (DebugManager.flags.CreateMultipleRootDevices.get()) { - numRootDevices = static_cast(DebugManager.flags.CreateMultipleRootDevices.get()); - } - if (Adapter >= numRootDevices) { + if (Adapter >= numRootDevicesToEnum) { *(IDXGIAdapter1 **)ppAdapter = nullptr; return DXGI_ERROR_NOT_FOUND; } 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 1ca6968085..6642909013 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -115,6 +115,30 @@ TEST(WddmDiscoverDevices, WhenMultipleRootDevicesAreAvailableThenAllAreDiscovere EXPECT_EQ(numRootDevicesToEnum, hwDeviceIds.size()); } +TEST(WddmDiscoverDevices, givenMultipleRootDevicesExposedWhenCreateMultipleRootDevicesFlagIsSetToLowerValueThenDiscoverOnlySpecifiedNumberOfDevices) { + DebugManagerStateRestore restorer{}; + VariableBackup backup{&numRootDevicesToEnum}; + numRootDevicesToEnum = 3u; + uint32_t requestedNumRootDevices = 2u; + + DebugManager.flags.CreateMultipleRootDevices.set(requestedNumRootDevices); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); + EXPECT_EQ(requestedNumRootDevices, hwDeviceIds.size()); +} + +TEST(WddmDiscoverDevices, givenMultipleRootDevicesExposedWhenCreateMultipleRootDevicesFlagIsSetToGreaterValueThenDiscoverSpecifiedNumberOfDevices) { + DebugManagerStateRestore restorer{}; + VariableBackup backup{&numRootDevicesToEnum}; + numRootDevicesToEnum = 3u; + uint32_t requestedNumRootDevices = 4u; + + DebugManager.flags.CreateMultipleRootDevices.set(requestedNumRootDevices); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); + EXPECT_EQ(requestedNumRootDevices, hwDeviceIds.size()); +} + TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsVirtualRenderThenAdapterIsDiscovered) { VariableBackup descriptionBackup(&UltIDXGIAdapter1::description); descriptionBackup = L"Virtual Render"; diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 9299f3f989..391f778aa6 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -262,58 +262,55 @@ std::vector> OSInterface::discoverDevices(ExecutionE IDXGIFactory1 *pFactory = nullptr; IDXGIAdapter1 *pAdapter = nullptr; - DWORD iDevNum = 0; HRESULT hr = Wddm::createDxgiFactory(__uuidof(IDXGIFactory), (void **)(&pFactory)); if ((hr != S_OK) || (pFactory == nullptr)) { return hwDeviceIds; } - 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)); - } - } - } - // Release all the non-Intel adapters - pAdapter->Release(); - pAdapter = nullptr; + size_t numRootDevices = 0u; + if (DebugManager.flags.CreateMultipleRootDevices.get()) { + numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get(); } - if (pAdapter != nullptr) { - pAdapter->Release(); - pAdapter = nullptr; - } + 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)); + } + } + } + // Release all the non-Intel adapters + pAdapter->Release(); + pAdapter = nullptr; + if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) { + break; + } + } + if (hwDeviceIds.empty()) { + break; + } + } while (hwDeviceIds.size() < numRootDevices); + if (pFactory != nullptr) { pFactory->Release(); pFactory = nullptr; } - size_t numRootDevices = 1u; - if (DebugManager.flags.CreateMultipleRootDevices.get()) { - numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get(); - } - if (hwDeviceIds.empty()) { - return hwDeviceIds; - } - - while (hwDeviceIds.size() < numRootDevices) { - hwDeviceIds.push_back(std::make_unique(hwDeviceIds[0]->getAdapter(), hwDeviceIds[0]->getAdapterLuid(), osEnvironment)); - } - return hwDeviceIds; }