1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

[Linux/BSD] Offload RenderingDevice creation test to subprocess.

(cherry picked from commit 6ed12bfc5d)
This commit is contained in:
Pāvels Nadtočajevs
2025-03-04 10:39:04 +02:00
committed by Rémi Verschelde
parent f045c4c283
commit 14d7775217
11 changed files with 149 additions and 50 deletions

View File

@@ -60,25 +60,23 @@ typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display *, GLXFBConfig, GLX
// To prevent shadowing warnings
#undef glGetString
struct vendor {
const char *glxvendor = nullptr;
int priority = 0;
};
int silent_error_handler(Display *display, XErrorEvent *error) {
static char message[1024];
XGetErrorText(display, error->error_code, message, sizeof(message));
print_verbose(vformat("XServer error: %s"
"\n Major opcode of failed request: %d"
"\n Serial number of failed request: %d"
"\n Current serial number in output stream: %d",
String::utf8(message), (uint64_t)error->request_code, (uint64_t)error->minor_code, (uint64_t)error->serial));
vendor vendormap[] = {
{ "Advanced Micro Devices, Inc.", 30 },
{ "AMD", 30 },
{ "NVIDIA Corporation", 30 },
{ "X.Org", 30 },
{ "Intel Open Source Technology Center", 20 },
{ "Intel", 20 },
{ "nouveau", 10 },
{ "Mesa Project", 0 },
{ nullptr, 0 }
};
quick_exit(1);
return 0;
}
// Runs inside a child. Exiting will not quit the engine.
void create_context() {
void DetectPrimeX11::create_context() {
XSetErrorHandler(&silent_error_handler);
Display *x11_display = XOpenDisplay(nullptr);
Window x11_window;
GLXContext glx_context;
@@ -137,20 +135,7 @@ void create_context() {
XFree(vi);
}
int silent_error_handler(Display *display, XErrorEvent *error) {
static char message[1024];
XGetErrorText(display, error->error_code, message, sizeof(message));
print_verbose(vformat("XServer error: %s"
"\n Major opcode of failed request: %d"
"\n Serial number of failed request: %d"
"\n Current serial number in output stream: %d",
String::utf8(message), (uint64_t)error->request_code, (uint64_t)error->minor_code, (uint64_t)error->serial));
quick_exit(1);
return 0;
}
int detect_prime() {
int DetectPrimeX11::detect_prime() {
pid_t p;
int priorities[2] = {};
String vendors[2];
@@ -202,7 +187,6 @@ int detect_prime() {
// cleaning up these processes, and fork() makes a copy
// of all globals.
CoreGlobals::leak_reporting_enabled = false;
XSetErrorHandler(&silent_error_handler);
char string[201];
@@ -253,7 +237,7 @@ int detect_prime() {
}
for (int i = 1; i >= 0; --i) {
vendor *v = vendormap;
const Vendor *v = vendor_map;
while (v->glxvendor) {
if (v->glxvendor == vendors[i]) {
priorities[i] = v->priority;