简体   繁体   English

eglCreateImageKHR 返回 EGL_BAD_ATTRIBUTE 错误

[英]eglCreateImageKHR returning EGL_BAD_ATTRIBUTE error

I have implemented hardware decoding on Linux using VAAPI via FFmpeg.我已经通过 FFmpeg 使用 VAAPI 在 Linux 上实现了硬件解码。 Since I have an OpenGL application, I am converting the decoded VAAPI surfaces to OpenGL textures using vaCopySurfaceGLX.因为我有一个 OpenGL 应用程序,所以我使用 vaCopySurfaceGLX 将解码的 VAAPI 表面转换为 OpenGL 纹理。 This is working fine except that there is a copy (on the GPU) that is made.这工作正常,只是有一个副本(在 GPU 上)。 I was told that I could directly use the VAAPI surface as OpenGL textures using EGL.有人告诉我,我可以使用 EGL 直接将 VAAPI 表面用作 OpenGL 纹理。 I have looked at some examples (mainly Kodi source code) but I'm not able to create the EGLImageKHR.我查看了一些示例(主要是 Kodi 源代码),但我无法创建 EGLImageKHR。 The function eglCreateImageKHR returns 0, and when I check for errors, I get a EGL_BAD_ATTRIBUTE error but I don't understand why.函数 eglCreateImageKHR 返回 0,当我检查错误时,我收到一个 EGL_BAD_ATTRIBUTE 错误,但我不明白为什么。

Below is how I'm converting the VAAPI surface.下面是我如何转换 VAAPI 表面。

During initialization, I set up EGL this way:在初始化期间,我以这种方式设置 EGL:

// currentDisplay comes from call to glXGetCurrentDisplay() and is also used when getting the VADisplay like this: vaGetDisplay(currentDisplay)     

EGLint major, minor;
_eglDisplay = eglGetDisplay(currentDisplay);
eglInitialize(_eglDisplay, &major, &minor);
eglBindAPI(EGL_OPENGL_API);

Then later, to create my EGL image, this is what I do:然后,为了创建我的 EGL 图像,我是这样做的:

// _vaapiContext.vaDisplay comes from vaGetDisplay(currentDisplay)
// surface is the VASurfaceID of the surface I want to use in OpenGL
vaDeriveImage(_vaapiContext.vaDisplay, surface, &_vaapiContext.vaImage);

VABufferInfo buf_info;
memset(&buf_info, 0, sizeof(buf_info));
buf_info.mem_type = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
vaAcquireBufferHandle(_vaapiContext.vaDisplay, _vaapiContext.vaImage.buf, &buf_info);
EGLint attribs[] = {
    EGL_WIDTH, _vaapiContext.vaImage.width,
    EGL_HEIGHT, _vaapiContext.vaImage.height,
    EGL_LINUX_DRM_FOURCC_EXT, fourcc_code('R', '8', ' ', ' '),
    EGL_DMA_BUF_PLANE0_FD_EXT, buf_info.handle,
    EGL_DMA_BUF_PLANE0_OFFSET_EXT, _vaapiContext.vaImage.offsets[0],
    EGL_DMA_BUF_PLANE0_PITCH_EXT, _vaapiContext.vaImage.pitches[0],
    EGL_NONE
};

EGLImageKHR eglImage = eglCreateImageKHR(_eglDisplay, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attribs);

Looking at what could cause this error in the following document https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_image_dma_buf_import.txt , I also tried to add the following options which should not matter since my format is not planar查看以下文档https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_image_dma_buf_import.txt 中可能导致此错误的原因,我还尝试添加以下选项,这些选项应该无关紧要,因为我的格式不是平面

EGL_YUV_COLOR_SPACE_HINT_EXT, EGL_ITU_REC601_EXT,
EGL_SAMPLE_RANGE_HINT_EXT, EGL_YUV_FULL_RANGE_EXT,
EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT, EGL_YUV_CHROMA_SITING_0_EXT,
EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT, EGL_YUV_CHROMA_SITING_0_EXT

The code that I'm using is similar to all the examples I've seen so I'm not sure what the error is.我使用的代码与我见过的所有示例相似,所以我不确定错误是什么。

Note that I have removed all the error checks for this post.请注意,我已经删除了这篇文章的所有错误检查。 All the calls above are successful except for eglCreateImageKHR.除了 eglCreateImageKHR 之外,上面的所有调用都成功了。

After turning the egl log level to debug, I was able to get more information about the error and pinpointed where in the egl source code this error happened.将 egl 日志级别转为调试后,我能够获得有关错误的更多信息,并指出该错误发生在 egl 源代码中的何处。 It turns out that the format fourcc_code('R', '8', ' ', ' ') was not supported because my mesa version was too old.原来是不支持格式fourcc_code('R', '8', ' ', ' ') 因为我的mesa版本太旧了。 You need to have mesa 11.0.0 or above installed.您需要安装 mesa 11.0.0 或更高版本。 After recompiling mesa (I'm running Ubuntu 15.04) and installing the 11.0.0 version, I'm finally getting an EGL image.重新编译 mesa(我运行的是 Ubuntu 15.04)并安装 11.0.0 版本后,我终于得到了一个 EGL 映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM