AMD memory bug with DMABUF and eglCreateImage with V4L2 capture
Creating EGLImages from DMABUFs vended by the V4L2 capture API using eglCreateImage() fails with EGL_BAD_ALLOC. The problem is the AMD Mesa implementation incorrectly interprets the size of the DMABUF, thinking it's larger than it actually is. On Intel, this works perfectly as expected so it's definitely an AMD bug. The only way to get it to work is to lie to eglCreateImageKHR() by dividing one of the image dimensions by 2 (e.g. height/2). This isn't really a workaround because then the image will appear stretched when rendered by the OpenGL ES shader since half of one dimension is missing.
I've tested this on both Mesa 23 and 24, on three devices including a Steam Deck and it fails on all of them. Using the height/2 workaround, EGLImage creation succeeds on all three devices but part of the image is obviously missing.
This bug is apparently a year old: #6131 (closed)
EGLint attr[] = {
EGL_WIDTH, width, // width of capture device frame
EGL_HEIGHT, height, // height of capture device frame
EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_YUYV, // smaller pixel formats like DRM_FORMAT_GR88 are wrong, but will prevent the error
EGL_DMA_BUF_PLANE0_FD_EXT, dmabuf_fd,
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
EGL_DMA_BUF_PLANE0_PITCH_EXT, width*2,
EGL_NONE
};
EGLImageKHR elgimg = eglCreateImageKHR(egldisp, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
// Fails with EGL_BAD_ALLOC