Commit b749435e authored by Antonio Caggiano's avatar Antonio Caggiano 🦀
Browse files

gpu: Select default driver



Improve default driver selection by checking the available DRM devices
instead of the supported device names list.
Signed-off-by: Antonio Caggiano's avatarAntonio Caggiano <antonio.caggiano@collabora.com>
parent 0bc44951
Pipeline #296751 passed with stages
in 4 minutes and 2 seconds
......@@ -27,6 +27,12 @@ public:
/// @return A new driver supporting a specific DRM device, nullptr if not supported
static std::unique_ptr<Driver> create(DrmDevice &&drm_device);
/// @return The name of a default selected PPS driver
static std::string default_driver_name();
/// @return The name of a driver based on the request, otherwise the default driver name
static std::string find_driver_name(const char *requested_name);
Driver() = default;
virtual ~Driver() = default;
......
......@@ -8,18 +8,22 @@
*/
#include "pps/gpu/driver.h"
#include "pps/gpu/panfrost/panfrost_driver.h"
#include "pps/gpu/intel/intel_driver.h"
#include <iterator>
#include <sstream>
#include <pps/pds.h>
#include <pps/algorithm.h>
#include "pps/gpu/intel/intel_driver.h"
#include "pps/gpu/panfrost/panfrost_driver.h"
namespace pps::gpu
{
const std::vector<std::string> &Driver::supported_device_names()
{
static std::vector<std::string> supported_device_names = {
PanfrostDriver::get_name(),
IntelDriver::get_name()};
PanfrostDriver::get_name(), IntelDriver::get_name()};
return supported_device_names;
}
......@@ -29,8 +33,7 @@ std::unique_ptr<Driver> Driver::create(DrmDevice &&drm_device)
if (drm_device.name == PanfrostDriver::get_name()) {
driver = std::make_unique<PanfrostDriver>();
}
else if (drm_device.name == IntelDriver::get_name()) {
} else if (drm_device.name == IntelDriver::get_name()) {
driver = std::make_unique<IntelDriver>();
}
......@@ -43,4 +46,40 @@ std::unique_ptr<Driver> Driver::create(DrmDevice &&drm_device)
return driver;
}
std::string Driver::default_driver_name()
{
auto supported_devices = gpu::Driver::supported_device_names();
auto devices = gpu::DrmDevice::create_all();
for (auto &device : devices) {
if (CONTAINS(supported_devices, device.name)) {
PPS_LOG_IMPORTANT("Driver selected: %s", device.name.c_str());
return device.name;
}
}
PPS_LOG_FATAL("Failed to find any driver");
}
std::string Driver::find_driver_name(const char *requested)
{
auto supported_devices = gpu::Driver::supported_device_names();
auto devices = gpu::DrmDevice::create_all();
for (auto &device : devices) {
if (device.name == requested) {
PPS_LOG_IMPORTANT("Driver selected: %s", device.name.c_str());
return device.name;
}
}
std::ostringstream drivers_os;
std::copy(supported_devices.begin(),
supported_devices.end() - 1,
std::ostream_iterator<std::string>(drivers_os, ", "));
drivers_os << supported_devices.back();
PPS_LOG_ERROR(
"Device '%s' not found (supported drivers: %s)", requested, drivers_os.str().c_str());
return default_driver_name();
}
} // namespace pps::gpu
......@@ -8,10 +8,8 @@
*/
#include <cstdlib>
#include <iterator>
#include <sstream>
#include "pps/gpu/gpu_datasource.h"
#include <pps/gpu/gpu_datasource.h>
int main(int argc, const char **argv)
{
......@@ -22,28 +20,9 @@ int main(int argc, const char **argv)
args.backends = perfetto::kSystemBackend;
perfetto::Tracing::Initialize(args);
auto supported_devices = gpu::Driver::supported_device_names();
std::string device_name = supported_devices.front();
if (argc > 1) {
for (auto &supported_device : supported_devices) {
if (supported_device == argv[1]) {
device_name = supported_device;
break;
}
}
if (device_name != argv[1]) {
std::ostringstream drivers_os;
copy(supported_devices.begin(), supported_devices.end() - 1, std::ostream_iterator<std::string>(drivers_os, ", "));
drivers_os << supported_devices.back();
PPS_LOG_ERROR("Driver '%s' isn't supported, using '%s' instead (supported drivers: %s)", argv[1], device_name.c_str(), drivers_os.str().c_str());
}
} else {
PPS_LOG("Using '%s' driver", device_name.c_str());
}
gpu::GpuDataSource::RegisterDataSource(device_name);
std::string driver_name =
(argc > 1) ? gpu::Driver::find_driver_name(argv[1]) : gpu::Driver::default_driver_name();
gpu::GpuDataSource::RegisterDataSource(driver_name);
while (true) {
gpu::GpuDataSource::Trace(gpu::GpuDataSource::trace_callback);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment