1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 19:24:10 +01:00

[dxvk] Add device filter

When setting DXVK_FILTER_DEVICE_NAME, only devices with a
matching device name will be reported to the application.
This commit is contained in:
Philip Rebohle 2018-08-27 14:22:14 +02:00
parent 5f42950650
commit 34152a01a5
5 changed files with 98 additions and 2 deletions

View File

@ -0,0 +1,30 @@
#include "dxvk_device_filter.h"
namespace dxvk {
DxvkDeviceFilter::DxvkDeviceFilter() {
m_matchDeviceName = env::getEnvVar(L"DXVK_FILTER_DEVICE_NAME");
if (m_matchDeviceName.size() != 0)
m_flags.set(DxvkDeviceFilterFlag::MatchDeviceName);
}
DxvkDeviceFilter::~DxvkDeviceFilter() {
}
bool DxvkDeviceFilter::testAdapter(
const Rc<DxvkAdapter>& adapter) const {
const auto& deviceProps = adapter->deviceProperties();
if (m_flags.test(DxvkDeviceFilterFlag::MatchDeviceName)) {
if (deviceProps.deviceName != m_matchDeviceName)
return false;
}
return true;
}
}

View File

@ -0,0 +1,53 @@
#pragma once
#include "dxvk_adapter.h"
namespace dxvk {
/**
* \brief Device filter flags
*
* The device filter flags specify which device
* properties are considered when testing adapters.
* If no flags are set, all devices pass the test.
*/
enum class DxvkDeviceFilterFlag {
MatchDeviceName = 0,
};
using DxvkDeviceFilterFlags = Flags<DxvkDeviceFilterFlag>;
/**
* \brief DXVK device filter
*
* Used to select specific Vulkan devices to use
* with DXVK. This may be useful for games which
* do not offer an option to select the correct
* device.
*/
class DxvkDeviceFilter {
public:
DxvkDeviceFilter();
~DxvkDeviceFilter();
/**
* \brief Tests an adapter
*
* \param [in] adapter Adapter handle
* \returns \c true if the test passes
*/
bool testAdapter(
const Rc<DxvkAdapter>& adapter) const;
private:
DxvkDeviceFilterFlags m_flags;
std::string m_matchDeviceName;
};
}

View File

@ -88,6 +88,8 @@ namespace dxvk {
std::vector<Rc<DxvkAdapter>> DxvkInstance::queryAdapters() { std::vector<Rc<DxvkAdapter>> DxvkInstance::queryAdapters() {
DxvkDeviceFilter filter;
uint32_t numAdapters = 0; uint32_t numAdapters = 0;
if (m_vki->vkEnumeratePhysicalDevices(m_vki->instance(), &numAdapters, nullptr) != VK_SUCCESS) if (m_vki->vkEnumeratePhysicalDevices(m_vki->instance(), &numAdapters, nullptr) != VK_SUCCESS)
throw DxvkError("DxvkInstance::enumAdapters: Failed to enumerate adapters"); throw DxvkError("DxvkInstance::enumAdapters: Failed to enumerate adapters");
@ -97,8 +99,12 @@ namespace dxvk {
throw DxvkError("DxvkInstance::enumAdapters: Failed to enumerate adapters"); throw DxvkError("DxvkInstance::enumAdapters: Failed to enumerate adapters");
std::vector<Rc<DxvkAdapter>> result; std::vector<Rc<DxvkAdapter>> result;
for (uint32_t i = 0; i < numAdapters; i++) for (uint32_t i = 0; i < numAdapters; i++) {
result.push_back(new DxvkAdapter(this, adapters[i])); Rc<DxvkAdapter> adapter = new DxvkAdapter(this, adapters[i]);
if (filter.testAdapter(adapter))
result.push_back(adapter);
}
std::sort(result.begin(), result.end(), std::sort(result.begin(), result.end(),
[this] (const Rc<DxvkAdapter>& a, const Rc<DxvkAdapter>& b) -> bool { [this] (const Rc<DxvkAdapter>& a, const Rc<DxvkAdapter>& b) -> bool {
@ -106,6 +112,11 @@ namespace dxvk {
&& b->deviceProperties().deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; && b->deviceProperties().deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
}); });
if (result.size() == 0) {
Logger::warn("DXVK: No adapters found. Please check your "
"device filter settings and Vulkan setup.");
}
return result; return result;
} }

View File

@ -4,6 +4,7 @@
#include "dxvk_adapter.h" #include "dxvk_adapter.h"
#include "dxvk_device.h" #include "dxvk_device.h"
#include "dxvk_device_filter.h"
#include "dxvk_openvr.h" #include "dxvk_openvr.h"
namespace dxvk { namespace dxvk {

View File

@ -41,6 +41,7 @@ dxvk_src = files([
'dxvk_data.cpp', 'dxvk_data.cpp',
'dxvk_descriptor.cpp', 'dxvk_descriptor.cpp',
'dxvk_device.cpp', 'dxvk_device.cpp',
'dxvk_device_filter.cpp',
'dxvk_extensions.cpp', 'dxvk_extensions.cpp',
'dxvk_event.cpp', 'dxvk_event.cpp',
'dxvk_event_tracker.cpp', 'dxvk_event_tracker.cpp',