Giter Club home page Giter Club logo

Comments (5)

ijsf avatar ijsf commented on September 13, 2024 1

Excellent, thanks for merging 🏆

from sdl.

ijsf avatar ijsf commented on September 13, 2024

I've been trying to debug this problem and stepping through the KMSDRM and EGL code. Changing strides and such doesn't seem to have any effect at all.

However once thing I've noticed is that this platform (NVIDIA Tegra) reports having two displays, one of which seems to be a 640x480 display, possibly some internal or MIPI thing. If I look at the way the picture is garbled I'm beginning to suspect that somewhere in SDL the displays get mixed up and perhaps EGL is created using the dimensions of one screen while the GBM is using the other.

P.S. --fullscreen does not seem to be working:

ERROR: Could not lock front buffer on GBM surface
ERROR: eglSwapBuffers failed

from sdl.

ijsf avatar ijsf commented on September 13, 2024

I've finally found the problem on this particular platform, after testing between drm*, GBM and EGL call differences between a known working app (https://github.com/embtom/kmscube) and SDL.

There seem to be three different variants of the drmModeAddFB call: drmModeAddFB, drmModeAddFB2 and drmModeAddFB2WithModifiers. SDL uses the first variant as can be seen at https://github.com/libsdl-org/SDL/blob/release-2.30.x/src/video/kmsdrm/SDL_kmsdrmvideo.c#L360

When I replace that call with drmModeAddFB2WithModifiers instead and use the GBM bo modifiers, the test cases start working:

uint32_t format, strides[4] = {0}, handles[4] = {0}, offsets[4] = {0}, flags = 0;

w = KMSDRM_gbm_bo_get_width(bo);
h = KMSDRM_gbm_bo_get_height(bo);
format = KMSDRM_gbm_bo_get_format(bo);

uint64_t modifiers[4] = {0};
modifiers[0] = gbm_bo_get_modifier(bo);
const int num_planes = gbm_bo_get_plane_count(bo);
for (int i = 0; i < num_planes; i++) {
        strides[i] = gbm_bo_get_stride_for_plane(bo, i);
        handles[i] = gbm_bo_get_handle(bo).u32;
        offsets[i] = gbm_bo_get_offset(bo, i);
        modifiers[i] = modifiers[0];
}

if (modifiers[0]) {
        flags = DRM_MODE_FB_MODIFIERS;
}

ret = drmModeAddFB2WithModifiers(viddata->drm_fd, w, h, format, handles, strides, offsets, modifiers, &fb_info->fb_id, flags);

The GBM modifier seems to be set at 0x3000000000fe014 so I'm suspecting that the modifier must be used when creating the frame buffer. It doesn't seem that strange, as these modifiers come from GBM itself.

Swapping in the above code seems to fix the display issue, tested with release-2.30.x. If helpful I could open a PR for this issue.

(Inversely, when I changed kmscube to use drmModeAddFB2 or drmModeAddFB it showed the same display problem as SDL.)

🙊 I've also noticed that the fullscreen flag seems to be failing the test case, this seems to be due to the fullscreen logic causing a dirty surface and recreation at https://github.com/libsdl-org/SDL/blob/release-2.30.x/src/video/kmsdrm/SDL_kmsdrmopengles.c#L110 but I suspect something is not released properly as eglSwapBuffers will fail with GL_FALSE from that point on. Should probably keep this for a different issue, but just wanted to note it down for reference.

from sdl.

slouken avatar slouken commented on September 13, 2024

Sure, a PR would be helpful, thanks! Good sleuthing. :)

from sdl.

ijsf avatar ijsf commented on September 13, 2024

Great, a pull request was made in #10117. One thing to note is that drmModeAddFB2WithModifiers and the newer gbm* modifier API calls seems to be a newer calls so this might break backwards compatibility with old versions of those libraries.

from sdl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.