in library/src/AdapterEnumeration.cpp [16:100]
void AdapterEnumeration::EnumerateAdapters(const DeviceFilter& filter, bool includeIntegrated, bool includeDetachable)
{
// Log our enumeration parameters
LOG(
L"Enumerating DirectX adapters using parameters: {{ filter:{}, includeIntegrated:{}, includeDetachable:{} }}",
DeviceFilterName(filter),
includeIntegrated,
includeDetachable
);
// Clear our adapter lists and our set of unique adapters
this->adapterLists.clear();
this->uniqueAdapters.clear();
#define ENUMERATE_ADAPTERS(attribute)\
{\
GUID attributes[]{ attribute };\
this->adapterLists.push_back(nullptr); \
auto error = CheckHresult(this->adapterFactory->CreateAdapterList(_countof(attributes), attributes, this->adapterLists.back().put()));\
if (error) { \
throw error.Wrap(L"IDXCoreAdapterFactory::CreateAdapterList() failed for attribute " + wstring(L#attribute));\
}\
}
// Enumerate adapters that support Direct3D 11
if (filter != DeviceFilter::ComputeOnly && filter != DeviceFilter::DisplayAndCompute) {
ENUMERATE_ADAPTERS(DXCORE_ADAPTER_ATTRIBUTE_D3D11_GRAPHICS);
}
// Enumerate adapters that support Direct3D 12
if (filter != DeviceFilter::ComputeOnly) {
ENUMERATE_ADAPTERS(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS);
}
// Enumerate adapters that support Direct3D 12 Core
if (filter != DeviceFilter::DisplayOnly) {
ENUMERATE_ADAPTERS(DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE);
}
#undef ENUMERATE_ADAPTERS
// Process each of the enumerated adapters and apply our filtering criteria
for (auto const& adapters : this->adapterLists)
{
const uint32_t count = adapters->GetAdapterCount();
for (uint32_t index = 0; index < count; ++index)
{
// Extract the details for the current adapter
com_ptr<IDXCoreAdapter> adapter;
auto error = CheckHresult(adapters->GetAdapter(index, adapter.put()));
if (error) {
throw error.Wrap(L"IDXCoreAdapterList::GetAdapter() failed for index " + std::to_wstring(index));
}
Adapter details = this->ExtractAdapterDetails(adapter);
// Ignore software devices
if (!details.IsHardware) {
continue;
}
// If the adapter does not match our filter mode then ignore it
if ((filter == DeviceFilter::DisplayOnly && details.SupportsCompute) ||
(filter == DeviceFilter::ComputeOnly && details.SupportsDisplay) ||
(filter == DeviceFilter::DisplayAndCompute && (!details.SupportsDisplay || !details.SupportsCompute))) {
continue;
}
// If the adapter is integrated and we are not including integrated devices then ignore it
if (details.IsIntegrated && !includeIntegrated) {
continue;
}
// If the adapter is detachable and we are not including detachable devices then ignore it
if (details.IsDetachable && !includeDetachable) {
continue;
}
// Add the adapter to our set of unique adapters
this->uniqueAdapters.insert(std::make_pair(details.InstanceLuid, details));
}
}
// Log the list of unique adapter LUIDs
LOG(L"Enumerated DirectX adapters with LUIDs: {}", FMT(ObjectHelpers::GetMappingKeys(this->uniqueAdapters)));
}