This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/TDA2PXEVM: [QT] how to create texture image by eglCreateImageKHR() under QT OpenGL

Part Number: TDA2PXEVM


Tool/software: Linux

Hi:

  we are working on VisionSDK and now succeed to run the QT.

we have an surround view application based on QT, as you known that visionSDK don't support RGB rendering that

we should to create texture image by eglCreateImageKHR(), here we need to pass the EGLDisplay,

so we call 

EGLNativeDisplayType gbm_allocator_get_native_display ()
{
   if(fd == -1) {
       fd = drmOpen("omapdrm", NULL);
   }
   if(fd > 0 && dev == NULL) {
       dev = gbm_create_device(fd);
       odev = omap_device_new(fd);
   }

   return (EGLNativeDisplayType)dev;
}

but got error

[AVMS][11455497]OverlayDraw::load_obj_file. max_x=1.72,max_y=3.43,max_z=0.00
[AVMS][11455497]OverlayDraw::pre_load_radar_data. file 'avm_qt_app_res/data/radar_single.obj' cost 24 ms
loaded module : gbm_pvr.so
found valid GBM backend : gbm_pvr.so
PVR:(Error): [  956->  956] <              gbm_pvr_create_device():645|ERROR> Failed to create DBM device: No such device [0, ]
 EGL: ERROR: eglCreateImageKHR failed !!!
texture img create ok 
No decoration plugins available. Running with no decorations.

and also we try to reuse the EGLDisplay from the QT OpenGL, see 

seem a bug in QT which the EGLDisplay handler is NULL.

and the weston log is :

root@dra7xx-evm:/opt/vision_sdk# cat /var/log/weston.log                                                                                                        
Date: 2018-09-17 UTC
[09:22:46.509] weston 1.9.0
               http://wayland.freedesktop.org
               Bug reports to: bugs.freedesktop.org/enter_bug.cgi
               Build: 1.8.93-2-gb05cdb8 configure.ac: bump to version 1.9.0 for the official release (2015-09-21 18:11:26 -0700)
[09:22:46.510] OS: Linux, 4.4.84, #2 SMP PREEMPT Fri Apr 19 02:29:04 PDT 2019, armv7l
[09:22:46.517] Using config file '/etc//weston.ini'
[09:22:46.529] Loading module '/usr/lib/weston/drm-backend.so'
[09:22:46.553] Output repaint window is 7 ms maximum.
[09:22:46.553] initializing drm backend
[09:22:46.555] using /dev/dri/card0
[09:22:46.556] Loading module '/usr/lib/weston/gl-renderer.so'
loaded module : gbm_pvr.so
found valid GBM backend : gbm_pvr.so
[09:22:46.621] warning: either no EGL_EXT_platform_base support or specific platform support; falling back to eglGetDisplay.
[09:22:46.632] warning: EGL_EXT_buffer_age not supported. Performance could be affected.
[09:22:46.632] Retrieving EGL client extension string failed.
[09:22:46.633] warning: no input devices on entering Weston. Possible causes:
        - no permissions to read /dev/input/event*
        - seats misconfigured (Weston backend option 'seat', udev device property ID_SEAT)
[09:22:46.633] failed to create input devices
[09:22:46.663] EGL version: 1.4 build 1.14@3699939 (MAIN)
[09:22:46.664] EGL vendor: Imagination Technologies
[09:22:46.664] EGL client APIs: OpenGL_ES 
[09:22:46.664] EGL extensions: EGL_IMG_client_api_ogl EGL_KHR_image
               EGL_KHR_image_base EGL_KHR_gl_texture_2D_image
               EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image
               EGL_KHR_vg_parent_image EGL_IMG_cl_image EGL_KHR_fence_sync
               EGL_IMG_context_priority EGL_IMG_hibernate_process
               EGL_IMG_image_plane_attribs EGL_KHR_surfaceless_context
               EGL_KHR_wait_sync EGL_KHR_create_context
               EGL_WL_bind_wayland_display EGL_EXT_image_dma_buf_import
[09:22:46.664] GL version: OpenGL ES 2.0 build 1.14@3699939 (MAIN)
[09:22:46.664] GLSL version: OpenGL ES GLSL ES 1.00 build 1.14@3699939 (MAIN)
[09:22:46.664] GL vendor: Imagination Technologies
[09:22:46.664] GL renderer: PowerVR SGX 544MP
[09:22:46.664] GL extensions: GL_OES_rgb8_rgba8 GL_OES_depth24
               GL_OES_vertex_half_float GL_OES_texture_float
               GL_OES_texture_half_float GL_OES_element_index_uint
               GL_OES_mapbuffer GL_OES_fragment_precision_high
               GL_OES_compressed_ETC1_RGB8_texture GL_OES_EGL_image
               GL_OES_EGL_image_external GL_OES_required_internalformat
               GL_OES_depth_texture GL_OES_get_program_binary
               GL_OES_packed_depth_stencil GL_OES_standard_derivatives
               GL_OES_vertex_array_object GL_OES_egl_sync GL_OES_texture_npot
               GL_OES_surfaceless_context GL_EXT_discard_framebuffer
               GL_EXT_blend_minmax GL_EXT_multi_draw_arrays
               GL_EXT_multisampled_render_to_texture GL_EXT_shader_texture_lod
               GL_EXT_texture_format_BGRA8888 GL_EXT_occlusion_query_boolean
               GL_EXT_texture_rg GL_EXT_draw_buffers
               GL_EXT_shader_framebuffer_fetch GL_IMG_shader_binary
               GL_IMG_texture_compression_pvrtc
               GL_IMG_texture_compression_pvrtc2 GL_IMG_texture_npot
               GL_IMG_texture_format_BGRA8888 GL_IMG_read_format
               GL_IMG_program_binary GL_IMG_uniform_buffer_object
               GL_IMG_multisampled_render_to_texture GL_KHR_debug
[09:22:46.664] GL ES 2 renderer features:
               read-back format: RGBA
               wl_shm sub-image to texture: no
               EGL Wayland extension: yes
[09:22:46.664] Chosen EGL config details:
               RGBA bits: 8 8 8 8
               swap interval range: 1 - 1
[09:22:46.664] cursor buffers unavailable, using gl cursors
[09:22:46.664] Failed to initialize backlight
[09:22:46.664] Output Virtual-1, (connector 24, crtc 26)
               mode 1280x720@60.0, preferred, current
[09:22:46.664] Compositor capabilities:
               arbitrary surface rotation: yes
               screen capture uses y-flip: yes
               presentation clock: CLOCK_MONOTONIC, id 1
[09:22:46.666] Loading module '/usr/lib/weston/desktop-shell.so'
[09:22:46.669] launching '/usr/libexec/weston-desktop-shell'
[09:22:46.804] Warning: computed repaint delay is insane: -8734 msec
[09:33:10.433] queueing pageflip failed: Invalid argument
[09:56:50.917] queueing pageflip failed: Invalid argument
[12:33:34.385] queueing pageflip failed: Invalid argument

  • Hi,

    What is the version of vision-sdk? Is it v3.04 or greater version with vDRM? If it is with vDRM support, you can refer this commit on kmscube.

    This change on kmsube application was made to execute kmscube on vDRM. omapdrm can not be used here.

    You also need to add this statement in /etc/powervr.ini

    [name of QT app]
    DbmDriverName=vdrm

    Please try with this?

    Ram
  • Hi Ram:

    Ramprasad said:
    What is the version of vision-sdk? Is it v3.04 or greater version with vDRM? If it is with vDRM support, you can refer this commit on kmscube

      VisionSDK3.05, vdrm is enable, and the qt application output can show on hdmi.

    Ramprasad said:
    You also need to add this statement in /etc/powervr.ini

     already configured 

  • Hi:

    should these simple code work?(compare with kmscube.c)

    #include <stdlib.h>
    #include <assert.h>
    
    #include <fcntl.h>
    #include <unistd.h>
    
    #include <EGL/egl.h>
    #include <EGL/eglext.h>
    
    #include <gbm.h>
    
    
    int main( void )
    {
        assert( eglBindAPI( EGL_OPENGL_API ) == EGL_TRUE );
    
        int fd = open("/dev/dri/card0", O_RDWR);
        struct gbm_device * gbm = gbm_create_device( fd );
    
        EGLDisplay dpy = eglGetDisplay( gbm );
        eglInitialize( dpy , NULL , NULL );
    
        EGLConfig config;
        EGLint n_of_configs;
        assert( eglGetConfigs( dpy , &config , 1 , &n_of_configs ) == EGL_TRUE );
    
        EGLSurface srf = eglCreatePbufferSurface( dpy , config , NULL );
        assert( srf != EGL_NO_SURFACE );
    
        EGLContext ctx = eglCreateContext( dpy , config , EGL_NO_CONTEXT , NULL );
        assert( ctx != EGL_NO_CONTEXT );
    
        assert( eglMakeCurrent( dpy , srf , srf , ctx ) == EGL_TRUE );
    
        eglDestroySurface( dpy , srf );
        eglDestroyContext( dpy , ctx );
        eglTerminate( dpy );
    
        gbm_device_destroy( gbm );
        close( fd );
    
        return EXIT_SUCCESS;
    }

  • Hi ,

    What is the issue you are seeing now with this modification?

    Thanks

    Ram

  • Hi Ram:

      I'm now integrate the kmscube code to my project, if any issue will update the post.

    Thanks.

  • Hi ram:

      please have look the error log

    sample code

    void Test2Setupegl()
    {
    		drmEventContext evctx = {
    			.version = DRM_EVENT_CONTEXT_VERSION,
    			.page_flip_handler = page_flip_handler,
    	};
    	struct gbm_bo *bo;
    	struct drm_fb *fb;
    		int ret = init_drm();
    	if (ret) {
    		printf("failed to initialize DRM\n");
    		return ret;
    	}
    	printf("### Primary display => ConnectorId = %d, Resolution = %dx%d\n",
    			drm.connector_id[DISP_ID], drm.mode[DISP_ID]->hdisplay,
    			drm.mode[DISP_ID]->vdisplay);
    
    
    
    	ret = init_gbm();
    	if (ret) {
    		printf("failed to initialize GBM\n");
    		return ret;
    	}
    
    	ret = init_gl();
    	if (ret) {
    		printf("failed to initialize EGL\n");
    		return ret;
    	}
    	
    	
    	
    	
    }

    ### Display [0]: CRTC = 26, Connector = 24, format = 0x34325258
            Mode chosen [1280x720] : Clock => 57061, Vertical refresh => 60, Type => 72
            Horizontal => 1280, 1292, 1295, 1301, 0
            Vertical => 720, 727, 728, 731, 0
    ### Primary display => ConnectorId = 24, Resolution = 1280x720
    loaded module : gbm_pvr.so
    found valid GBM backend : gbm_pvr.so
    PVR:(Error): [ 1135-> 1135] <           gbm_pvr_bo_create_common():260|ERROR> Failed to allocate DBM buffer: Cannot allocate memory [0, ]
    PVR:(Error): [ 1135-> 1135] <      gbm_pvr_surface_create_common():448|ERROR> GBM=0x281838: cannot allocate GBM buffer[0] [0, ]

  • Hi ram:

      You're right, i will go next, if any issue will update it.

  • Hello Ram:

      The source code from git://git.ti.com/glsdk/kmscube.git is working well, but when i try to create texture img by eglCreateImageKHR() 

    got the egl error (0x300c), please help check the log 

    ### Display [0]: CRTC = 26, Connector = 24, format = 0x34325258
            Mode chosen [1280x720] : Clock => 57061, Vertical refresh => 60, Type => 72
            Horizontal => 1280, 1292, 1295, 1301, 0
            Vertical => 720, 727, 728, 731, 0
    ### Primary display => ConnectorId = 24, Resolution = 1280x720
    loaded module : gbm_pvr.so
    found valid GBM backend : gbm_pvr.so
    Using display 0x2 with EGL version 1.4
    EGL Version "1.4 build 1.14@3699939 (MAIN)"
    EGL Vendor "Imagination Technologies"
    EGL Extensions "EGL_IMG_client_api_ogl EGL_KHR_image EGL_KHR_image_base EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_vg_parent_image EGL_IMG_cl_image EGL_KHR_fence_sync EGL_IMG_context_priority EGL_IMG_hibernate_process EGL_IMG_image_plane_attribs EGL_KHR_surfaceless_context EGL_KHR_wait_sync EGL_KHR_create_context EGL_WL_bind_wayland_display EGL_EXT_image_dma_buf_import"
    dma fd 0x11 
    width  1280  
    height  720 
    EGLWindowDisplay 0x2 
     EGL: after eglCreateImageKHR() eglError (0x300c)
     EGL: ERROR: eglCreateImageKHR failed !!!
    No decoration plugins available. Running with no decorations.
    max texture 8 

    here is my sample code :

    1. malloc the memory from linux (is that ok?)
    2. convert memory addr to dma fd
    3. create texture image
     devBufFD = open("/dev/vmemexp", O_RDWR | O_CLOEXEC);
    	 SetupEGLEnv();
    	 
    	 uint8_t *testData=(uint8_t *)malloc(1280*720);
    	 if(!testData){
    		 printf("No memory  \n");
    		 return;
    	 }
    	 uint32_t dmaFd;
    
    	ExportDmaBuf(testData,1280*720,&dmaFd);
    	GLuint outTex;
    	CreateYUVTextureImg(1280,720,dmaFd,&outTex);

    void CreateYUVTextureImg(int width, int height, int dmaBufFd, GLuint *outTexIndex)
    {
        EGLint attr[32];
        int attrIdx;
        PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
        PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
    
        attrIdx = 0;
    
        attr[attrIdx++] = EGL_LINUX_DRM_FOURCC_EXT;
        attr[attrIdx++] = FOURCC_STR("NV12");
    
        attr[attrIdx++] = EGL_WIDTH;
        attr[attrIdx++] = width;
        printf("width  %d  \n",width);
    
        attr[attrIdx++] = EGL_HEIGHT;
        attr[attrIdx++] = height;
         printf("height  %d \n", height);
    
        attr[attrIdx++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
        attr[attrIdx++] = width;
       // printf("pitch %d  \n",pProp->pitch[0]);
    
        attr[attrIdx++] = EGL_DMA_BUF_PLANE1_PITCH_EXT;
        attr[attrIdx++] =width;// pProp->pitch[0];
        //printf("pitch %d  \n",pProp->pitch[0]);
    
        attr[attrIdx++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
        attr[attrIdx++] = 0;
    
        attr[attrIdx++] = EGL_DMA_BUF_PLANE1_OFFSET_EXT;
        attr[attrIdx++] = 0;
    
        attr[attrIdx++] = EGL_DMA_BUF_PLANE0_FD_EXT;
        attr[attrIdx++] = dmaBufFd;
    
        attr[attrIdx++] = EGL_DMA_BUF_PLANE1_FD_EXT;
        attr[attrIdx++] = dmaBufFd;
    
        attr[attrIdx++] = EGL_NONE;
    
        eglCreateImageKHR =
            (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
        glEGLImageTargetTexture2DOES =
            (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
    
      printf("EGLWindowDisplay %p \n",gl.display);
       EGLImageKHR textImg = eglCreateImageKHR(
                                    gl.display,
                                    EGL_NO_CONTEXT,
                                    EGL_LINUX_DMA_BUF_EXT,
                                    NULL,
                                    attr
                                  );
    
        System_eglCheckEglError("eglCreateImageKHR", EGL_TRUE);
        if (textImg == EGL_NO_IMAGE_KHR) {
            printf(" EGL: ERROR: eglCreateImageKHR failed !!!\n");
            return -1;
        }
    
        glGenTextures(1, outTexIndex);
        System_eglCheckGlError("glGenTextures");
    
        glBindTexture(GL_TEXTURE_EXTERNAL_OES, *outTexIndex);
        System_eglCheckGlError("glBindTexture");
    
        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        System_eglCheckGlError("glTexParameteri");
    
        glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)textImg);
        System_eglCheckGlError("glEGLImageTargetTexture2DOES");	
    	
    	
    }

  • Hi ,

    Error 0x300c means EGL_BAD_PARAMETER. Your attribute parameters seem correct.

    But 

    uint8_t *testData=(uint8_t *)malloc(1280*720);
    this should have been
    uint8_t *testData=(uint8_t *)malloc(1280*720*1.5);
    I am not sure if error is due to this.

    Can you try with this change?

    Thanks
    Ramprasad
  • Hi Ram:

      you're correct.

      mark it as resolved.