diagnostics: improve driver printing

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2020-08-25 06:32:40 +01:00
parent 1f65d88858
commit 933f2cfe80

View File

@@ -3,9 +3,12 @@
#pragma once
#include <stddef.h>
#include <stdio.h>
#include <xcb/xcb.h>
#include "utils.h"
struct session;
struct backend_base;
@@ -19,8 +22,8 @@ struct backend_base;
/// also the generic modesetting driver.
/// This enum represents _both_ drivers.
enum driver {
DRIVER_AMDGPU = 1, // AMDGPU for DDX, radeonsi for OpenGL
DRIVER_RADEON = 2, // ATI for DDX, mesa r600 for OpenGL
DRIVER_AMDGPU = 1, // AMDGPU for DDX, radeonsi for OpenGL
DRIVER_RADEON = 2, // ATI for DDX, mesa r600 for OpenGL
DRIVER_FGLRX = 4,
DRIVER_NVIDIA = 8,
DRIVER_NOUVEAU = 16,
@@ -28,6 +31,10 @@ enum driver {
DRIVER_MODESETTING = 64,
};
static const char *driver_names[] = {
"AMDGPU", "Radeon", "fglrx", "NVIDIA", "nouveau", "Intel", "modesetting",
};
/// Return a list of all drivers currently in use by the X server.
/// Note, this is a best-effort test, so no guarantee all drivers will be detected.
enum driver detect_driver(xcb_connection_t *, struct backend_base *, xcb_window_t);
@@ -37,26 +44,19 @@ void apply_driver_workarounds(struct session *ps, enum driver);
// Print driver names to stdout, for diagnostics
static inline void print_drivers(enum driver drivers) {
if (drivers & DRIVER_AMDGPU) {
printf("AMDGPU, ");
const char *seen_drivers[ARR_SIZE(driver_names)];
int driver_count = 0;
for (size_t i = 0; i < ARR_SIZE(driver_names); i++) {
if (drivers & (1ul << i)) {
seen_drivers[driver_count++] = driver_names[i];
}
}
if (drivers & DRIVER_RADEON) {
printf("Radeon, ");
if (driver_count > 0) {
printf("%s", seen_drivers[0]);
for (int i = 1; i < driver_count; i++) {
printf(", %s", seen_drivers[i]);
}
}
if (drivers & DRIVER_FGLRX) {
printf("fglrx, ");
}
if (drivers & DRIVER_NVIDIA) {
printf("NVIDIA, ");
}
if (drivers & DRIVER_NOUVEAU) {
printf("nouveau, ");
}
if (drivers & DRIVER_INTEL) {
printf("Intel, ");
}
if (drivers & DRIVER_MODESETTING) {
printf("modesetting, ");
}
printf("\b\b \n");
printf("\n");
}