Browse Source

kmsdrm: fixed creating GBM surfaces on NVIDIA cards

(cherry picked from commit fc1c0618ded275a745852c7c4a6db374bfef9927)
Sam Lantinga 2 months ago
parent
commit
180b454d61
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/video/kmsdrm/SDL_kmsdrmvideo.c

+ 8 - 3
src/video/kmsdrm/SDL_kmsdrmvideo.c

@@ -1368,9 +1368,14 @@ bool KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
     windata->gs = KMSDRM_gbm_surface_create(viddata->gbm_dev,
     windata->gs = KMSDRM_gbm_surface_create(viddata->gbm_dev,
                                             dispdata->mode.hdisplay, dispdata->mode.vdisplay,
                                             dispdata->mode.hdisplay, dispdata->mode.vdisplay,
                                             surface_fmt, surface_flags);
                                             surface_fmt, surface_flags);
-
+    if (!windata->gs && errno == ENOSYS) {
+        // Try again without the scanout flags, needed on NVIDIA drivers
+        windata->gs = KMSDRM_gbm_surface_create(viddata->gbm_dev,
+                                                dispdata->mode.hdisplay, dispdata->mode.vdisplay,
+                                                surface_fmt, 0);
+    }
     if (!windata->gs) {
     if (!windata->gs) {
-        return SDL_SetError("Could not create GBM surface");
+        return SDL_SetError("Could not create GBM surface: %s", strerror(errno));
     }
     }
 
 
     /* We can't get the EGL context yet because SDL_CreateRenderer has not been called,
     /* We can't get the EGL context yet because SDL_CreateRenderer has not been called,
@@ -1731,7 +1736,7 @@ bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
         /* Create the window surfaces with the size we have just chosen.
         /* Create the window surfaces with the size we have just chosen.
            Needs the window driverdata in place. */
            Needs the window driverdata in place. */
         if (!KMSDRM_CreateSurfaces(_this, window)) {
         if (!KMSDRM_CreateSurfaces(_this, window)) {
-            return SDL_SetError("Can't create GBM/EGL surfaces on window creation.");
+            return false;
         }
         }
     } // NON-Vulkan block ends.
     } // NON-Vulkan block ends.