1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/wddm/adapter_factory_dxgi.h"
#include "shared/source/helpers/debug_helpers.h"
#include <memory>
namespace NEO {
DxgiAdapterFactory::DxgiAdapterFactory(AdapterFactory::CreateAdapterFactoryFcn createAdapterFactoryFcn) : createAdapterFactoryFcn(createAdapterFactoryFcn) {
if (nullptr == createAdapterFactoryFcn) {
return;
}
HRESULT hr = createAdapterFactoryFcn(__uuidof(adapterFactory), (void **)(&adapterFactory));
if (hr != S_OK) {
adapterFactory = nullptr;
}
}
bool DxgiAdapterFactory::getAdapterDesc(uint32_t ordinal, AdapterDesc &outAdapter) {
if (ordinal >= getNumAdaptersInSnapshot()) {
DEBUG_BREAK_IF(true);
return false;
}
outAdapter = adaptersInSnapshot[ordinal];
return true;
}
bool DxgiAdapterFactory::createSnapshotOfAvailableAdapters() {
if (false == this->isSupported()) {
DEBUG_BREAK_IF(true);
return false;
}
destroyCurrentSnapshot();
uint32_t ordinal = 0;
IDXGIAdapter1 *adapter = nullptr;
while (adapterFactory->EnumAdapters1(ordinal++, &adapter) != DXGI_ERROR_NOT_FOUND) {
DXGI_ADAPTER_DESC1 adapterDesc = {{0}};
HRESULT hr = adapter->GetDesc1(&adapterDesc);
if (hr != S_OK) {
adapter->Release();
DEBUG_BREAK_IF(true);
continue;
}
adaptersInSnapshot.resize(adaptersInSnapshot.size() + 1);
auto &dstAdapterDesc = *adaptersInSnapshot.rbegin();
dstAdapterDesc.luid = adapterDesc.AdapterLuid;
dstAdapterDesc.deviceId = adapterDesc.DeviceId;
static constexpr auto driverDescMaxChars = sizeof(adapterDesc.Description) / sizeof(adapterDesc.Description[0]);
dstAdapterDesc.driverDescription.reserve(driverDescMaxChars);
for (auto wchar : std::wstring(std::wstring(adapterDesc.Description, adapterDesc.Description + driverDescMaxChars).c_str())) {
dstAdapterDesc.driverDescription.push_back(static_cast<char>(wchar));
}
adapter->Release();
}
return true;
}
} // namespace NEO
|