angle uses this path in vaapi, i get a sigsegv on my 4090 every time. not sure if this is a regression or not.
this is a reproducer
// crash: glXBindTexImageEXT on a linear DRI3 dma-buf (modifier 0).
// build: cc -O1 -o crash crash.c $(pkg-config --libs --cflags gl x11 x11-xcb xcb-dri3 gbm)
#include <GL/gl.h>
#define GLX_GLXEXT_PROTOTYPES 1
#include <GL/glx.h>
#include <GL/glxext.h>
#include <X11/Xlib-xcb.h>
#include <gbm.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <xcb/dri3.h>
#define W 64
#define H 64
static int xerr;
static int onerr(Display *d, XErrorEvent *e) { xerr = e->error_code; return 0; }
int main(int argc, char **argv) {
// argv[1]: "linear" (crashes) or "mod" (server-advertised tiled, works).
const char *mode = argc > 1 ? argv[1] : "linear";
int use_mod = strstr(mode, "mod") != NULL;
setbuf(stdout, NULL);
Display *dpy = XOpenDisplay(NULL);
XSetErrorHandler(onerr); // record, do not abort
if (!dpy) return puts("no display"), 1;
int scr = DefaultScreen(dpy);
Window win = RootWindow(dpy, scr);
int attrs[] = {GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_BIND_TO_TEXTURE_RGB_EXT, True,
GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, None};
int ncfg = 0;
GLXFBConfig *cfg = glXChooseFBConfig(dpy, scr, attrs, &ncfg);
if (!ncfg) return puts("no fbconfig"), 1;
XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, cfg[0]);
// A GLXWindow is required: making the context current to a plain X window makes the
// driver bind with no valid drawable and memcpy from NULL even for good buffers.
XSetWindowAttributes swa = {.colormap =
XCreateColormap(dpy, win, vi->visual, AllocNone)};
Window gw = XCreateWindow(dpy, win, 0, 0, W, H, 0, vi->depth, InputOutput,
vi->visual, CWColormap, &swa);
GLXWindow glxwin = glXCreateWindow(dpy, cfg[0], gw, NULL);
GLXContext ctx = glXCreateNewContext(dpy, cfg[0], GLX_RGBA_TYPE, NULL, True);
glXMakeContextCurrent(dpy, glxwin, glxwin, ctx);
glXMakeContextCurrent(dpy, glxwin, glxwin, ctx);
xcb_connection_t *xcb = XGetXCBConnection(dpy);
xcb_generic_error_t *err = NULL;
int flags = use_mod ? GBM_BO_USE_RENDERING : GBM_BO_USE_LINEAR | GBM_BO_USE_WRITE;
int fd_gpu = open("/dev/dri/renderD128", O_RDWR | O_CLOEXEC);
struct gbm_device *gdev = gbm_create_device(fd_gpu);
struct gbm_bo *bo;
if (use_mod) {
xcb_dri3_get_supported_modifiers_reply_t *m =
xcb_dri3_get_supported_modifiers_reply(xcb,
xcb_dri3_get_supported_modifiers(xcb, win, vi->depth, 32), &err);
if (!m || err) return puts("no modifiers"), 1;
bo = gbm_bo_create_with_modifiers(gdev, W, H, GBM_FORMAT_XRGB8888,
xcb_dri3_get_supported_modifiers_screen_modifiers(m),
m->num_screen_modifiers);
} else {
bo = gbm_bo_create(gdev, W, H, GBM_FORMAT_XRGB8888, flags);
}
if (!bo) return puts("gbm_bo_create failed"), 1;
uint32_t stride;
void *map;
uint32_t *px = gbm_bo_map(bo, 0, 0, W, H, GBM_BO_TRANSFER_WRITE, &stride, &map);
if (px) { // tiled buffers are not CPU-mappable
for (int i = 0; i < W * H; i++) px[i] = 0x00ff0000;
gbm_bo_unmap(bo, map);
}
int fd = gbm_bo_get_fd(bo);
printf("buffer modifier=0x%llx pitch=%u\n",
(unsigned long long)gbm_bo_get_modifier(bo), gbm_bo_get_stride(bo));
// Explicit import with the buffer's own modifier and a correct size; the legacy
// request has no modifier field and fails or binds wrong for tiled buffers.
Pixmap pm = xcb_generate_id(xcb);
uint32_t pitch = gbm_bo_get_stride(bo);
off_t size = lseek(fd, 0, SEEK_END);
xcb_dri3_pixmap_from_buffers(xcb, pm, win, 1, W, H, pitch, 0, 0, 0, 0, 0, 0, 0,
vi->depth, 32, gbm_bo_get_modifier(bo), &fd);
XSync(dpy, False);
printf("imported pixmap=0x%lx size=%jd pitch=%u\n", (unsigned long)pm, (intmax_t)size, pitch);
int pattrs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, None};
GLXPixmap gp = glXCreatePixmap(dpy, cfg[0], pm, pattrs);
XSync(dpy, False);
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
printf("binding...\n");
xerr = 0;
glXBindTexImageEXT(dpy, gp, GLX_FRONT_EXT, NULL);
static unsigned char got[W * H * 4]; // full texture: glGetTexImage writes W*H*4
XSync(dpy, False);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, got);
int c = (H / 2 * W + W / 2) * 4;
printf("X error %d, GL error 0x%x, center RGBA = %d %d %d %d\n",
xerr, glGetError(), got[c], got[c+1], got[c+2], got[c+3]);
return 0;
}