Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deviceUUID filter with DXVK_FILTER_DEVICE_UUID #2408

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Next Next commit
Add deviceUUID filter with DXVK_FILTER_DEVICE_UUID
  • Loading branch information
meladath committed Dec 22, 2021
commit fb9329032a276dd1160f9bb12e1cc37837104371
21 changes: 21 additions & 0 deletions src/dxvk/dxvk_device_filter.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#include "dxvk_device_filter.h"

std::string convertUUID(const uint8_t* uuid) {
meladath marked this conversation as resolved.
Show resolved Hide resolved
std::ostringstream convert;
for (int a = 0; a < 16; a++) {
convert << static_cast<int>(uuid[a]);
}
std::string key_string = convert.str();
return key_string;
}

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);
}


Expand Down Expand Up @@ -36,5 +48,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;
}

}
15 changes: 13 additions & 2 deletions src/dxvk/dxvk_device_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace dxvk {
*/
enum class DxvkDeviceFilterFlag {
MatchDeviceName = 0,
SkipCpuDevices = 1,
MatchDeviceUUID = 1,
SkipCpuDevices = 2,
};

using DxvkDeviceFilterFlags = Flags<DxvkDeviceFilterFlag>;
Expand Down Expand Up @@ -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;

};

}
}
2 changes: 2 additions & 0 deletions src/dxvk/dxvk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ namespace dxvk {
for (uint32_t i = 0; i < numAdapters; i++) {
if (filter.testAdapter(deviceProperties[i]))
result.push_back(new DxvkAdapter(m_vki, adapters[i]));
if(!filter.testCreatedAdapter(result.back()->devicePropertiesExt()))
result.pop_back();
}

std::stable_sort(result.begin(), result.end(),
Expand Down