1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-12 13:08:50 +01:00

[dxgi] Only enumerate outputs which belong to the adapter or associated iGPU

This commit is contained in:
Paul Gofman 2022-05-30 16:16:50 -05:00 committed by Philip Rebohle
parent 242ac20752
commit 83a294285e
7 changed files with 183 additions and 14 deletions

View File

@ -149,7 +149,30 @@ namespace dxvk {
if (ppOutput == nullptr)
return E_INVALIDARG;
HMONITOR monitor = wsi::enumMonitors(Output);
const auto& deviceId = m_adapter->devicePropertiesExt().vk11;
std::array<const LUID*, 2> adapterLUIDs = { };
uint32_t numLUIDs = 0;
if (m_adapter->isLinkedToDGPU())
return DXGI_ERROR_NOT_FOUND;
if (deviceId.deviceLUIDValid)
adapterLUIDs[numLUIDs++] = reinterpret_cast<const LUID*>(deviceId.deviceLUID);
auto linkedAdapter = m_adapter->linkedIGPUAdapter();
/* If either LUID is not valid enumerate all monitors. */
if (numLUIDs && linkedAdapter != nullptr) {
const auto& deviceId = linkedAdapter->devicePropertiesExt().vk11;
if (deviceId.deviceLUIDValid)
adapterLUIDs[numLUIDs++] = reinterpret_cast<const LUID*>(deviceId.deviceLUID);
else
numLUIDs = 0;
}
HMONITOR monitor = wsi::enumMonitors(adapterLUIDs.data(), numLUIDs, Output);
if (monitor == nullptr)
return DXGI_ERROR_NOT_FOUND;

View File

@ -275,6 +275,33 @@ namespace dxvk {
*/
bool isUnifiedMemoryArchitecture() const;
/**
* \brief Registers a relationship with another GPU
*
* Used for display enumeration purposes.
* \param [in] dgpu Dedicated GPU adatper
*/
void linkToDGPU(Rc<DxvkAdapter> dgpu) {
dgpu->m_linkedIGPUAdapter = this;
m_linkedToDGPU = true;
}
/**
* \brief Retrieves linked integrated GPU
* \returns Integrated GPU adapter
*/
Rc<DxvkAdapter> linkedIGPUAdapter() const {
return m_linkedIGPUAdapter;
}
/**
* \brief Checks whether the GPU is linked
* \returns \c true if the GPU is linked
*/
bool isLinkedToDGPU() const {
return m_linkedToDGPU;
}
private:
Rc<vk::InstanceFn> m_vki;
@ -287,6 +314,9 @@ namespace dxvk {
bool m_hasMemoryBudget;
Rc<DxvkAdapter> m_linkedIGPUAdapter;
bool m_linkedToDGPU = false;
std::vector<VkQueueFamilyProperties> m_queueFamilies;
std::array<std::atomic<uint64_t>, VK_MAX_MEMORY_HEAPS> m_memoryAllocated = { };

View File

@ -252,9 +252,18 @@ namespace dxvk {
DxvkDeviceFilter filter(filterFlags);
std::vector<Rc<DxvkAdapter>> result;
uint32_t numDGPU = 0;
uint32_t numIGPU = 0;
for (uint32_t i = 0; i < numAdapters; i++) {
if (filter.testAdapter(deviceProperties[i]))
if (filter.testAdapter(deviceProperties[i])) {
result.push_back(new DxvkAdapter(m_vki, adapters[i]));
if (deviceProperties[i].deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
numDGPU += 1;
else if (deviceProperties[i].deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
numIGPU += 1;
}
}
std::stable_sort(result.begin(), result.end(),
@ -276,9 +285,11 @@ namespace dxvk {
return aRank < bRank;
});
if (result.size() == 0) {
if (result.empty()) {
Logger::warn("DXVK: No adapters found. Please check your "
"device filter settings and Vulkan setup.");
} else if (numDGPU == 1 && numIGPU == 1) {
result[1]->linkToDGPU(result[0]);
}
return result;

View File

@ -22,6 +22,10 @@ namespace dxvk::wsi {
: nullptr;
}
HMONITOR enumMonitors(const LUID *adapterLUID[], uint32_t numLUIDs, uint32_t index) {
return enumMonitors(index);
}
bool getDisplayName(
HMONITOR hMonitor,
WCHAR (&Name)[32]) {

View File

@ -23,6 +23,10 @@ namespace dxvk::wsi {
: nullptr;
}
HMONITOR enumMonitors(const LUID *adapterLUID[], uint32_t numLUIDs, uint32_t index) {
return enumMonitors(index);
}
bool getDisplayName(
HMONITOR hMonitor,
WCHAR (&Name)[32]) {

View File

@ -1,9 +1,11 @@
#include "../wsi_monitor.h"
#include "../../util/util_string.h"
#include "../../util/log/log.h"
#include "../../util/util_string.h"
#include <cstring>
#include <set>
#include <setupapi.h>
#include <ntddvdeo.h>
@ -16,6 +18,7 @@ namespace dxvk::wsi {
}
struct MonitorEnumInfo {
const WCHAR *gdiDeviceName;
UINT iMonitorId;
HMONITOR oMonitor;
};
@ -27,17 +30,26 @@ namespace dxvk::wsi {
LPARAM lp) {
auto data = reinterpret_cast<MonitorEnumInfo*>(lp);
if (data->iMonitorId--)
return TRUE; /* continue */
if (data->gdiDeviceName)
{
MONITORINFOEXW monitorInfo;
monitorInfo.cbSize = sizeof(monitorInfo);
GetMonitorInfoW(hmon, (MONITORINFO *)&monitorInfo);
if (wcscmp(data->gdiDeviceName, monitorInfo.szDevice))
return TRUE;
}
if (data->iMonitorId--)
return TRUE;
data->oMonitor = hmon;
return FALSE; /* stop */
return FALSE;
}
HMONITOR enumMonitors(uint32_t index) {
MonitorEnumInfo info;
info.iMonitorId = index;
info.oMonitor = nullptr;
info.gdiDeviceName = nullptr;
::EnumDisplayMonitors(
nullptr, nullptr, &MonitorEnumProc,
@ -46,6 +58,81 @@ namespace dxvk::wsi {
return info.oMonitor;
}
HMONITOR enumMonitors(const LUID *adapterLUID[], uint32_t numLUIDs, uint32_t index) {
if (!numLUIDs)
return enumMonitors(index);
std::vector<DISPLAYCONFIG_PATH_INFO> paths;
std::vector<DISPLAYCONFIG_MODE_INFO> modes;
std::set<std::pair<uint32_t, uint32_t>> sources;
UINT32 pathCount = 0;
UINT32 modeCount = 0;
LONG result;
do {
if ((result = GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &pathCount, &modeCount))) {
Logger::err(str::format("GetDisplayConfigBufferSizes failed, result ", result));
return enumMonitors(index);
}
paths.resize(pathCount);
modes.resize(modeCount);
result = QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS,
&pathCount, paths.data(), &modeCount, modes.data(), nullptr);
} while (result == ERROR_INSUFFICIENT_BUFFER);
if (result) {
Logger::err(str::format("QueryDisplayConfig failed, result ", result));
return enumMonitors(index);
}
paths.resize(pathCount);
modes.resize(modeCount);
MonitorEnumInfo info;
info.iMonitorId = index;
info.oMonitor = nullptr;
for (const auto &path : paths) {
uint32_t i;
for (i = 0; i < numLUIDs; ++i) {
if (!std::memcmp(&path.sourceInfo.adapterId, adapterLUID[i], sizeof(path.sourceInfo.adapterId)))
break;
}
if (i == numLUIDs)
continue;
/* Mirrored displays appear as multiple paths with the same
* GDI device name, that comes as single dxgi output. */
if (!sources.insert(std::pair<uint32_t, uint32_t>(i, path.sourceInfo.id)).second)
continue;
DISPLAYCONFIG_SOURCE_DEVICE_NAME deviceName = { };
deviceName.header.adapterId = path.sourceInfo.adapterId;
deviceName.header.id = path.sourceInfo.id;
deviceName.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME;
deviceName.header.size = sizeof(deviceName);
if ((result = DisplayConfigGetDeviceInfo(&deviceName.header))) {
Logger::err(str::format("DisplayConfigGetDeviceInfo failed, result ", result));
return enumMonitors(index);
}
info.gdiDeviceName = deviceName.viewGdiDeviceName;
::EnumDisplayMonitors(
nullptr, nullptr, &MonitorEnumProc,
reinterpret_cast<LPARAM>(&info));
if (info.oMonitor != nullptr)
return info.oMonitor;
}
return nullptr;
}
bool getDisplayName(
HMONITOR hMonitor,

View File

@ -43,6 +43,16 @@ namespace dxvk::wsi {
*/
HMONITOR enumMonitors(uint32_t index);
/**
* \brief Enumerators monitors on the system
* \param [in] adapterLUID array of adapters' LUIDs
* \param [in] numLUIDs adapterLUID array size (0 for all monitors)
* \param [in] index Monitor index within enumeration
*
* \returns The monitor of given index
*/
HMONITOR enumMonitors(const LUID *adapterLUID[], uint32_t numLUIDs, uint32_t index);
/**
* \brief Get the GDI name of a HMONITOR
*