#include <unistd.h>
#include "egl_dri2.h"
-#include "egl_dri2_fallbacks.h"
#include "loader.h"
+#include "util/debug.h"
static __DRIimage*
device_alloc_image(struct dri2_egl_display *dri2_dpy,
attrib_list);
}
-static EGLBoolean
-device_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
-{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- static const struct {
- const char *format_name;
- int rgba_shifts[4];
- unsigned int rgba_sizes[4];
- } visuals[] = {
- { "A2RGB10", { 20, 10, 0, 30 }, { 10, 10, 10, 2 } },
- { "X2RGB10", { 20, 10, 0, -1 }, { 10, 10, 10, 0 } },
- { "ARGB8888", { 16, 8, 0, 24 }, { 8, 8, 8, 8 } },
- { "RGB888", { 16, 8, 0, -1 }, { 8, 8, 8, 0 } },
- { "RGB565", { 11, 5, 0, -1 }, { 5, 6, 5, 0 } },
- };
- unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
- unsigned int config_count = 0;
-
- for (unsigned i = 0; dri2_dpy->driver_configs[i] != NULL; i++) {
- for (unsigned j = 0; j < ARRAY_SIZE(visuals); j++) {
- struct dri2_egl_config *dri2_conf;
-
- dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
- config_count + 1, EGL_PBUFFER_BIT, NULL,
- visuals[j].rgba_shifts, visuals[j].rgba_sizes);
-
- if (dri2_conf) {
- if (dri2_conf->base.ConfigID == config_count + 1)
- config_count++;
- format_count[j]++;
- }
- }
- }
-
- for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) {
- if (!format_count[i]) {
- _eglLog(_EGL_DEBUG, "No DRI config supports native format %s",
- visuals[i].format_name);
- }
- }
-
- return (config_count != 0);
-}
-
static const struct dri2_egl_display_vtbl dri2_device_display_vtbl = {
- .create_pixmap_surface = dri2_fallback_create_pixmap_surface,
.create_pbuffer_surface = dri2_device_create_pbuffer_surface,
.destroy_surface = device_destroy_surface,
.create_image = dri2_create_image_khr,
- .swap_buffers_region = dri2_fallback_swap_buffers_region,
- .post_sub_buffer = dri2_fallback_post_sub_buffer,
- .copy_buffers = dri2_fallback_copy_buffers,
- .query_buffer_age = dri2_fallback_query_buffer_age,
- .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image,
- .get_sync_values = dri2_fallback_get_sync_values,
.get_dri_drawable = dri2_surface_get_dri_drawable,
};
device_probe_device(_EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy = disp->DriverData;
+ bool request_software = env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
- if (disp->Options.ForceSoftware)
+ if (request_software)
_eglLog(_EGL_WARNING, "Not allowed to force software rendering when "
"API explicitly selects a hardware device.");
dri2_dpy->fd = device_get_fd(disp, disp->Device);
if (!dri2_dpy->driver_name)
goto err_name;
+ /* When doing software rendering, some times user still want to explicitly
+ * choose the render node device since cross node import doesn't work between
+ * vgem/virtio_gpu yet. It would be nice to have a new EXTENSION for this.
+ * For now, just fallback to kms_swrast. */
+ if (disp->Options.ForceSoftware && !request_software &&
+ (strcmp(dri2_dpy->driver_name, "vgem") == 0 ||
+ strcmp(dri2_dpy->driver_name, "virtio_gpu") == 0)) {
+ free(dri2_dpy->driver_name);
+ _eglLog(_EGL_WARNING, "NEEDS EXTENSION: falling back to kms_swrast");
+ dri2_dpy->driver_name = strdup("kms_swrast");
+ }
+
if (!dri2_load_driver_dri3(disp))
goto err_load;
dri2_setup_screen(disp);
- if (!device_add_configs_for_visuals(drv, disp)) {
+ if (!dri2_add_pbuffer_configs_for_visuals(drv, disp)) {
err = "DRI2: failed to add configs";
goto cleanup;
}