c++raspberry-piraspberry-pi4egl

DRM + GBM OpenGL rendering flickering R-PI 4


I am using GBM, DRM and EGL to render my scene to a HDMI display on my R-PI 4B. No X server is installed, and the R-PI boots into text mode before launching my application.

First my problem: I notice a lot of flickering throughout all of my rendering. So far I do not render much, I render a buch of text elements and a texture and I can see it flicker with my background without any changes to the texture or the other elements rendered.

I have attached a video here:

https://streamable.com/0pq3d0

It does not seem so bad in the video, but with the naked eye flickering is horrible (the black flashes).

For now I assume it has something to do with how I do my end_frame rendering:

    void graphics_device_drm::end_frame() {
        auto sync = eglCreateSyncKHR(_display, EGL_SYNC_FENCE_KHR, nullptr);
        glFlush();
        eglClientWaitSyncKHR(_display, sync, 0, EGL_FOREVER_KHR);
        eglDestroySyncKHR(_display, sync);

        eglSwapBuffers(_display, _surface);

        auto bo = gbm_surface_lock_front_buffer(_gbm_surface);
        const auto handle = gbm_bo_get_handle(bo).u32;
        const auto pitch = gbm_bo_get_stride(bo);

        uint32_t fb;
        drmModeAddFB(_device, _width, _height, 24, 32, pitch, handle, &fb);
        drmModeSetCrtc(_device, _crtc->crtc_id, fb, 0, 0, &_connector_id, 1, &_mode);

        if (_previous_bo) {
            drmModeRmFB(_device, _previous_fb);
            gbm_surface_release_buffer(_gbm_surface, _previous_bo);
        }

        _previous_bo = bo;
        _previous_fb = fb;
    }

It almost seems like it is using only one single buffer for rendering. I dont really understand the DRM and GBM methods, so I assume I am doing something wrong there. Any pointers would be appreciated.


Solution

  • As a matter of fact it apparently was not related to my code and an R-PI/driver issue. Nevertheless the following change in /boot/config.txt did the trick:

    # dtoverlay=vc4-fkms-v3d
    dtoverlay=vc4-kms-v3d-pi4
    

    The commented line (with fkms) was before and the other line was after. I assume for it to work you also need to have the latest Mesa libraries compiled which I anyway did before. No flickering whatsoever now!