Changing win dev discovery to DXCoreAdapterFactory

Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
This commit is contained in:
Jaroslaw Chodor 2021-04-30 00:55:12 +02:00 committed by Compute-Runtime-Automation
parent 9799f15286
commit 83143c4318
14 changed files with 363 additions and 257 deletions

View File

@ -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()

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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<UltDXCoreAdapterFactory **>(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;

View File

@ -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 <cwchar>
#include <dxcore.h>
#include <dxgi.h>
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<bool *>(propertyData) = true;
break;
case DXCoreAdapterProperty::DriverDescription:
memcpy_s(propertyData, bufferSize, description, requiredSize);
break;
case DXCoreAdapterProperty::InstanceLuid:
reinterpret_cast<LUID *>(propertyData)->HighPart = 0x1234;
reinterpret_cast<LUID *>(propertyData)->LowPart = 0;
break;
case DXCoreAdapterProperty::HardwareID: {
DXCoreHardwareID ret = {};
ret.deviceID = 0x1234;
*reinterpret_cast<DXCoreHardwareID *>(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<UltDxCoreAdapter **>(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<const GUID *> filterAttributesCopy;
REFIID riid;
void **ppvAdapterList;
};
std::vector<CreateAdapterListArgs> 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<const GUID *>{filterAttributes, filterAttributes + numAttributes},
riid, ppvAdapterList});
*reinterpret_cast<UltDXCoreAdapterList **>(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

View File

@ -1,192 +0,0 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/constants.h"
#include <cwchar>
#include <dxgi.h>
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

View File

@ -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<const wchar_t *> descriptionBackup(&UltIDXGIAdapter1::description);
descriptionBackup = L"Virtual Render";
VariableBackup<const char *> 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());
}
}

View File

@ -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<LPVOID>(virtualAllocAddress);
}
Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() {
return ULTCreateDXGIFactory;
Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory() {
return ULTDXCoreCreateAdapterFactory;
}
Wddm::GetSystemInfoFcn getGetSystemInfo() {

View File

@ -35,15 +35,19 @@
#include "gmm_memory.h"
// clang-format off
#include <initguid.h>
#include <dxcore.h>
#include <dxgi.h>
// 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<HwDeviceId> createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &os
return std::make_unique<HwDeviceId>(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<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) {
std::vector<std::unique_ptr<HwDeviceId>> hwDeviceIds;
@ -275,13 +285,9 @@ std::vector<std::unique_ptr<HwDeviceId>> 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<std::unique_ptr<HwDeviceId>> 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<char, 512> 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;
}

View File

@ -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;

View File

@ -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 <dxcore.h>
#include <dxgi.h>
namespace NEO {
Wddm::CreateDXGIFactoryFcn getCreateDxgiFactory() {
return CreateDXGIFactory;
Wddm::DXCoreCreateAdapterFactoryFcn getDXCoreCreateAdapterFactory() {
return DXCoreCreateAdapterFactory;
}
Wddm::GetSystemInfoFcn getGetSystemInfo() {

View File

@ -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
)