diff --git a/src/dxvk/dxvk_device_filter.cpp b/src/dxvk/dxvk_device_filter.cpp index 23d18248..4fcddf4d 100644 --- a/src/dxvk/dxvk_device_filter.cpp +++ b/src/dxvk/dxvk_device_filter.cpp @@ -1,13 +1,24 @@ #include "dxvk_device_filter.h" +std::string convertUUID(const uint8_t uuid[VK_UUID_SIZE]) { + std::ostringstream stream; + for (unsigned int i = 0; i < VK_UUID_SIZE; i++) { + stream << static_cast(uuid[i]); + } + return stream.str(); +} + namespace dxvk { DxvkDeviceFilter::DxvkDeviceFilter(DxvkDeviceFilterFlags flags) : m_flags(flags) { m_matchDeviceName = env::getEnvVar("DXVK_FILTER_DEVICE_NAME"); + m_matchDeviceUUID = env::getEnvVar("DXVK_FILTER_DEVICE_UUID"); if (m_matchDeviceName.size() != 0) m_flags.set(DxvkDeviceFilterFlag::MatchDeviceName); + if (m_matchDeviceUUID.size() != 0) + m_flags.set(DxvkDeviceFilterFlag::MatchDeviceUUID); } @@ -39,5 +50,14 @@ namespace dxvk { return true; } + + bool DxvkDeviceFilter::testCreatedAdapter(const DxvkDeviceInfo& deviceInfo) const { + if (m_flags.test(DxvkDeviceFilterFlag::MatchDeviceUUID)) { + if (convertUUID(deviceInfo.coreDeviceId.deviceUUID).find(m_matchDeviceUUID) == std::string::npos) + return false; + } + + return true; + } } diff --git a/src/dxvk/dxvk_device_filter.h b/src/dxvk/dxvk_device_filter.h index 7b411e6a..ffc19ab8 100644 --- a/src/dxvk/dxvk_device_filter.h +++ b/src/dxvk/dxvk_device_filter.h @@ -13,7 +13,8 @@ namespace dxvk { */ enum class DxvkDeviceFilterFlag { MatchDeviceName = 0, - SkipCpuDevices = 1, + MatchDeviceUUID = 1, + SkipCpuDevices = 2, }; using DxvkDeviceFilterFlags = Flags; @@ -42,13 +43,23 @@ namespace dxvk { */ bool testAdapter( const VkPhysicalDeviceProperties& properties) const; + + /** + * \brief Tests a created adapter + * + * \param [in] properties Adapter properties + * \returns \c true if the test passes + */ + bool testCreatedAdapter( + const DxvkDeviceInfo& deviceInfo) const; private: DxvkDeviceFilterFlags m_flags; std::string m_matchDeviceName; + std::string m_matchDeviceUUID; }; -} \ No newline at end of file +} diff --git a/src/dxvk/dxvk_instance.cpp b/src/dxvk/dxvk_instance.cpp index bc204d3a..78d2be76 100644 --- a/src/dxvk/dxvk_instance.cpp +++ b/src/dxvk/dxvk_instance.cpp @@ -258,9 +258,11 @@ namespace dxvk { 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 (!filter.testCreatedAdapter(result.back()->devicePropertiesExt())) { + result.pop_back(); + } else { if (deviceProperties[i].deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) numDGPU += 1; else if (deviceProperties[i].deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)