guide: libsdl, dosbox, vice with hw acceleration

Post Reply
riq
Posts: 25
Joined: Fri Feb 14, 2020 9:18 pm
languages_spoken: english
Has thanked: 4 times
Been thanked: 7 times
Contact:

guide: libsdl, dosbox, vice with hw acceleration

Post by riq » Mon May 11, 2020 7:31 am

Hi,

Here is a detailed guide that explains how to have libSDL + GLES2 (hardware accelerated), and some popular emulators that uses SDL like DOSBox and VICE on Odroid C4.
https://gitlab.com/ricardoquesada/odroi ... /kmsdrm.md

Let me know of you it doesn't work for you.

Thanks @tobetter for the help.
These users thanked the author riq for the post (total 2):
tobetter (Mon May 11, 2020 7:37 am) • odroid (Mon May 11, 2020 10:05 am)

User avatar
tobetter
Posts: 5101
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 160 times
Been thanked: 493 times
Contact:

Re: guide: libsdl, dosbox, vice with hw acceleration

Post by tobetter » Mon May 11, 2020 7:39 am

Did you make any chance on the SDL code? Or just run as-is after compiling?
I also wonder if the SDL can run on top of Wayland as well.

riq
Posts: 25
Joined: Fri Feb 14, 2020 9:18 pm
languages_spoken: english
Has thanked: 4 times
Been thanked: 7 times
Contact:

Re: guide: libsdl, dosbox, vice with hw acceleration

Post by riq » Mon May 11, 2020 8:26 am

I used an unmodified version of SDL (compiled as described on the guide), and works Ok using KMS/DRM backend.

When SDL is using GLES2 hardware accelerated, it doesn't work using Wayland backend. Tested on Weston.
It doesn't crash, it seems that EGL is initialized correctly, but it fails to create a new window.

When SDL is compiled without hw-accel, then it works Ok using Wayland backend.

User avatar
meveric
Posts: 11019
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 344 times
Contact:

Re: guide: libsdl, dosbox, vice with hw acceleration

Post by meveric » Tue May 12, 2020 12:08 am

be careful with DOSBox though.
DOSBox does no know GLESv2 it only knows OpenGL.
It runs due to the fact that the default simply uses Surface or Overlay as a backend without the need of OpenGL support.
If you switch in the config to OpenGL it will probably fail, due to the fact that OpenGL is not part of the SDL2 package.
This also means DOSBox doesn't run on Hardware Acceleration, it uses SDL2, nothing more.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
AreaScout
Posts: 1334
Joined: Sun Jul 07, 2013 3:05 am
languages_spoken: german, english
ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
N1, Go, VU5A, Show2, CloudShell2,
H2, N2, VU7A, VuShell, Go2, C4
Has thanked: 54 times
Been thanked: 182 times
Contact:

Re: guide: libsdl, dosbox, vice with hw acceleration

Post by AreaScout » Tue May 12, 2020 1:34 am

    Looks great, but I doubt that it will run on GBM (but I pray it does), are you sure SDL2 doesn't choose Wayland here, it would also be cool to show the first lines from the command line to prove that the right renderer is chosen

    RG

    riq
    Posts: 25
    Joined: Fri Feb 14, 2020 9:18 pm
    languages_spoken: english
    Has thanked: 4 times
    Been thanked: 7 times
    Contact:

    Re: guide: libsdl, dosbox, vice with hw acceleration

    Post by riq » Tue May 12, 2020 2:29 am

    thanks @meveric, guide updated.

    @AreaScout: Not sure I got your question correctly, but I confirm that when I run `testgles2` in Weston, it was using the Wayland backend (I debugged it).
    But it doesn't work. I couldn't go much deeper than knowing that EGL was correctly initialize. But besides that, I don't know what's happening (didn't have time).
    That's for Wayland.

    KMS/DRM works without any problem (hw-accel).

    User avatar
    tobetter
    Posts: 5101
    Joined: Mon Feb 25, 2013 10:55 am
    languages_spoken: Korean, English
    ODROIDs: X, X2, U2, U3, XU3, C1
    Location: Paju, South Korea
    Has thanked: 160 times
    Been thanked: 493 times
    Contact:

    Re: guide: libsdl, dosbox, vice with hw acceleration

    Post by tobetter » Tue May 12, 2020 3:01 am

    I've rebuilt the modified SDL with '--enable-video-kmsdrm --disable-video-opengl --enable-video-wayland', and it looks sort of working.

    Code: Select all

    $ SDL_VIDEODRIVER=wayland ./testdisplayinfo
    INFO: Using video target 'wayland'.
    INFO: See 1 displays.
    INFO: 0: "2369M" (1920x1080, (0, 0)), 1 modes.
    ERROR:     DPI: failed to query (That operation is not supported)
    INFO: CURRENT: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1080 refresh=60
    INFO: DESKTOP: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1080 refresh=60
    INFO:     MODE 0: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1080 refresh=60
    INFO:
    
    Two SDL2 test apps running on Gnome Desktop.
    Screenshot from 2020-05-12 02-58-23.png
    Screenshot from 2020-05-12 02-58-23.png (818.77 KiB) Viewed 433 times

    riq
    Posts: 25
    Joined: Fri Feb 14, 2020 9:18 pm
    languages_spoken: english
    Has thanked: 4 times
    Been thanked: 7 times
    Contact:

    Re: guide: libsdl, dosbox, vice with hw acceleration

    Post by riq » Tue May 12, 2020 3:26 am

    nice! (I should double-check everything again). And ft it keeps non-working, I should try it on gnome+wayland instead of Weston.

    User avatar
    AreaScout
    Posts: 1334
    Joined: Sun Jul 07, 2013 3:05 am
    languages_spoken: german, english
    ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
    N1, Go, VU5A, Show2, CloudShell2,
    H2, N2, VU7A, VuShell, Go2, C4
    Has thanked: 54 times
    Been thanked: 182 times
    Contact:

    Re: guide: libsdl, dosbox, vice with hw acceleration

    Post by AreaScout » Tue May 12, 2020 6:00 am

      @riq

      No I was under the impression that SDL2 was choosing Wayland video driver internally instead of GBM KMS/DRM, if that is working the C4 could jump some ranks up on my favorite sbc board hit list, but how ? KMS/DRM backend is highly interfering with libdrm but there is no supported HW backend for meson in libdrm ?? So I am curious ...

      RG

      riq
      Posts: 25
      Joined: Fri Feb 14, 2020 9:18 pm
      languages_spoken: english
      Has thanked: 4 times
      Been thanked: 7 times
      Contact:

      Re: guide: libsdl, dosbox, vice with hw acceleration

      Post by riq » Tue May 12, 2020 7:19 am

      @AreaScout

      This is my understanding (probably @tobetter knows better):

      I'm using the mali-bifrost-wayland-driver for hw-accel in KMS/DRM. But the name could be misleading. This driver installs the "libmali.so" driver, which offers an implementation of: EGL, GLES2 and GBM (among other things). So buffers and rendering are done by this library.
      This driver could be used by Wayland as well by KMS/DRM.
      When using SDL2 with KMS/DRM the rendering is deletaged to this libmali.so, but the scanout is done by KMS/DRM (which I think uses the meson driver).

      Does it makes sense?

      User avatar
      AreaScout
      Posts: 1334
      Joined: Sun Jul 07, 2013 3:05 am
      languages_spoken: german, english
      ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
      N1, Go, VU5A, Show2, CloudShell2,
      H2, N2, VU7A, VuShell, Go2, C4
      Has thanked: 54 times
      Been thanked: 182 times
      Contact:

      Re: guide: libsdl, dosbox, vice with hw acceleration

      Post by AreaScout » Tue May 12, 2020 12:46 pm

      riq wrote:
      Tue May 12, 2020 7:19 am
      @AreaScout

      This is my understanding (probably @tobetter knows better):

      I'm using the mali-bifrost-wayland-driver for hw-accel in KMS/DRM. But the name could be misleading. This driver installs the "libmali.so" driver, which offers an implementation of: EGL, GLES2 and GBM (among other things). So buffers and rendering are done by this library.
      This driver could be used by Wayland as well by KMS/DRM.
      When using SDL2 with KMS/DRM the rendering is deletaged to this libmali.so, but the scanout is done by KMS/DRM (which I think uses the meson driver).

      Does it makes sense?
      Well your explanation is mostly right but SDL2 KMS/DRM backend is using the libdrm API to talk to the kernel DRM driver, upstream libdrm does not have support for Amlogic meson other then the build system with the same name and here are the supported GPU vendors https://cgit.freedesktop.org/mesa/drm/tree/

      Samsung Exynos, Intel, Texas Instrument, Radeon, Nvidia, Raspberry etc. but no Amlogic, Rockchip has it's own implementation of libdrm and is hosted here https://github.com/rockchip-linux/libdrm-rockchip, so either there is a custom libdrm used or SDL2 is using Wayland or SDL2 is falling back to mesa software rasterizer and that's why I asked for the gles render string that you get when you start the testgles2 tool

      RG

      User avatar
      AreaScout
      Posts: 1334
      Joined: Sun Jul 07, 2013 3:05 am
      languages_spoken: german, english
      ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
      N1, Go, VU5A, Show2, CloudShell2,
      H2, N2, VU7A, VuShell, Go2, C4
      Has thanked: 54 times
      Been thanked: 182 times
      Contact:

      Re: guide: libsdl, dosbox, vice with hw acceleration

      Post by AreaScout » Tue May 12, 2020 7:28 pm

        @riq

        Ok today I got finally my C4 board, I tested your tutorial but there are mesa libraries installed and so it fails on KMSDRM and wayland, so I fixed the symbolic links manually to point to libmali.so instead of mesa and now the testgles2 example works hardware accelerated, I was a little surprised that it works because I don't know exactly how and what route it takes internally, but I will find out. Also the permissions on /dev/dri/card0 was wrong and I got a permission denied error.

        RG

        riq
        Posts: 25
        Joined: Fri Feb 14, 2020 9:18 pm
        languages_spoken: english
        Has thanked: 4 times
        Been thanked: 7 times
        Contact:

        Re: guide: libsdl, dosbox, vice with hw acceleration

        Post by riq » Tue May 12, 2020 11:54 pm

        @AreaScout what ubuntu image did you install? the instructions that I wrote are based on the "ubuntu-minimal" image.

        User avatar
        AreaScout
        Posts: 1334
        Joined: Sun Jul 07, 2013 3:05 am
        languages_spoken: german, english
        ODROIDs: X2, U3, XU3, C2, HiFi Shield, XU4, XU4Q,
        N1, Go, VU5A, Show2, CloudShell2,
        H2, N2, VU7A, VuShell, Go2, C4
        Has thanked: 54 times
        Been thanked: 182 times
        Contact:

        Re: guide: libsdl, dosbox, vice with hw acceleration

        Post by AreaScout » Wed May 13, 2020 12:17 am

          @riq

          No I was installing Windows 10 image :P Of course it was that one http://ppa.linuxfactory.or.kr/images/ra ... 421.img.xz

          RG

          User avatar
          tobetter
          Posts: 5101
          Joined: Mon Feb 25, 2013 10:55 am
          languages_spoken: Korean, English
          ODROIDs: X, X2, U2, U3, XU3, C1
          Location: Paju, South Korea
          Has thanked: 160 times
          Been thanked: 493 times
          Contact:

          Re: guide: libsdl, dosbox, vice with hw acceleration

          Post by tobetter » Wed May 13, 2020 12:19 am

          I've made a test package libsdl2-2.0-0 which has my patches to run on ODROID-C4/N2, I've tested with a couple of simple test apps on terminal using 'KMSDRM' display driver and Gnome Desktop using 'wayland'. On Gnome Desktop, SDL app will just run using 'wayland' without SDL_VIDEODRIVER=wayland.

          Code: Select all

          $ sudo apt update
          $ sudo apt install libsdl2-2.0-0 libsdl2-dev
          $ dpkg -l | grep sdl
          ii  libsdl2-2.0-0:arm64                        2.0.10+dfsg1-3+202005122340~focal          arm64        Simple DirectMedia Layer
          ii  libsdl2-dev:arm64                          2.0.10+dfsg1-3+202005122340~focal          arm64        Simple DirectMedia Layer development files
          
          These users thanked the author tobetter for the post:
          riq (Wed May 13, 2020 1:01 am)

          riq
          Posts: 25
          Joined: Fri Feb 14, 2020 9:18 pm
          languages_spoken: english
          Has thanked: 4 times
          Been thanked: 7 times
          Contact:

          Re: guide: libsdl, dosbox, vice with hw acceleration

          Post by riq » Wed May 13, 2020 4:44 am

          tobetter@ thanks for creating the compiled libs!

          I've just tried both on C4 and N2 using the minimal ubuntu image.

          On N2:

          On N2 + Wayland it works Ok.
          On N2 + KMSDRM it works Ok with a few "nits":

          "testdisplayinfo" reports only one mode in KMSDRM:

          Code: Select all

          INFO: Using video target 'KMSDRM'.
          INFO: See 1 displays.
          INFO: 0: "0" (1920x1200, (0, 0)), 1 modes.
          ERROR:     DPI: failed to query (That operation is not supported)
          INFO: CURRENT: fmt=SDL_PIXELFORMAT_ARGB8888 w=1920 h=1200 refresh=60
          INFO: DESKTOP: fmt=SDL_PIXELFORMAT_ARGB8888 w=1920 h=1200 refresh=60
          INFO:     MODE 0: fmt=SDL_PIXELFORMAT_ARGB8888 w=1920 h=1200 refresh=60
          INFO: 
          
          On Wayland, it reports all the modes:

          Code: Select all

          INFO: Using video target 'wayland'.
          INFO: See 1 displays.
          INFO: 0: "S2719DGF" (1920x1200, (0, 0)), 20 modes.
          ERROR:     DPI: failed to query (That operation is not supported)
          INFO: CURRENT: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1200 refresh=59
          INFO: DESKTOP: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1200 refresh=59
          INFO:     MODE 0: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1200 refresh=59
          INFO:     MODE 1: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1080 refresh=60
          INFO:     MODE 2: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1080 refresh=59
          INFO:     MODE 3: fmt=SDL_PIXELFORMAT_RGB888 w=1920 h=1080 refresh=50
          INFO:     MODE 4: fmt=SDL_PIXELFORMAT_RGB888 w=1680 h=1050 refresh=59
          INFO:     MODE 5: fmt=SDL_PIXELFORMAT_RGB888 w=1600 h=1200 refresh=60
          INFO:     MODE 6: fmt=SDL_PIXELFORMAT_RGB888 w=1280 h=1024 refresh=75
          INFO:     MODE 7: fmt=SDL_PIXELFORMAT_RGB888 w=1280 h=1024 refresh=60
          INFO:     MODE 8: fmt=SDL_PIXELFORMAT_RGB888 w=1280 h=800 refresh=59
          INFO:     MODE 9: fmt=SDL_PIXELFORMAT_RGB888 w=1280 h=720 refresh=60
          INFO:     MODE 10: fmt=SDL_PIXELFORMAT_RGB888 w=1280 h=720 refresh=59
          INFO:     MODE 11: fmt=SDL_PIXELFORMAT_RGB888 w=1280 h=720 refresh=50
          INFO:     MODE 12: fmt=SDL_PIXELFORMAT_RGB888 w=1152 h=864 refresh=75
          INFO:     MODE 13: fmt=SDL_PIXELFORMAT_RGB888 w=1024 h=768 refresh=75
          INFO:     MODE 14: fmt=SDL_PIXELFORMAT_RGB888 w=1024 h=768 refresh=60
          INFO:     MODE 15: fmt=SDL_PIXELFORMAT_RGB888 w=800 h=600 refresh=75
          INFO:     MODE 16: fmt=SDL_PIXELFORMAT_RGB888 w=800 h=600 refresh=60
          INFO:     MODE 17: fmt=SDL_PIXELFORMAT_RGB888 w=720 h=576 refresh=50
          INFO:     MODE 18: fmt=SDL_PIXELFORMAT_RGB888 w=720 h=480 refresh=59
          INFO:     MODE 19: fmt=SDL_PIXELFORMAT_RGB888 w=640 h=480 refresh=75
          INFO: 
          
          And "testgles2", on KMSDRM runs limited by vsync, but on Wayland it runs at max speed.
          I haven't seen these behaviors when I compiled libsdl myself.

          On C4:

          On Wayland: It works Ok.
          On KMSDRM I got:
          ERROR: Couldn't initialize SDL: No available video device

          I tried
          - upgrading to 5.7
          - starting from scratch with a clean image
          - reinstalling mali-wayland-dkms + reboot

          But I'm still getting that error.

          My wild guess is that it not using libmali.so. I don't understand who/how decides which library should be loaded in runtime.
          If you could give any pointers, I might be able to debug the issue. Thanks.

          UPDATE:
          It would be great to add libdrm-dev, libgbm-dev, libegl-dev, libgles-dev as dependencies for libsdl2-dev.

          User avatar
          tobetter
          Posts: 5101
          Joined: Mon Feb 25, 2013 10:55 am
          languages_spoken: Korean, English
          ODROIDs: X, X2, U2, U3, XU3, C1
          Location: Paju, South Korea
          Has thanked: 160 times
          Been thanked: 493 times
          Contact:

          Re: guide: libsdl, dosbox, vice with hw acceleration

          Post by tobetter » Wed May 13, 2020 8:04 am

          @riq, I've updated two packages, 'mali-bifrost-wayland-driver' and 'libsdl2-2.0-0'. I also faced the same issue on ODROID-C4 after a new installation and observed something different behaves installing the packages between Netboot Installer and preinstalled image. Anyway, after updating the two packages, KMSDRM issue on ODROID-C4 would be resolved. :lol:
          These users thanked the author tobetter for the post:
          riq (Wed May 13, 2020 8:22 am)

          riq
          Posts: 25
          Joined: Fri Feb 14, 2020 9:18 pm
          languages_spoken: english
          Has thanked: 4 times
          Been thanked: 7 times
          Contact:

          Re: guide: libsdl, dosbox, vice with hw acceleration

          Post by riq » Wed May 13, 2020 8:22 am

          thanks!.
          I confirm that it works Ok both on N2 and C4; and both on Wayland and KMSDRM (with the limitation that on KMSDRM only one mode seems to be available).
          These users thanked the author riq for the post:
          tobetter (Wed May 13, 2020 8:28 am)

          User avatar
          tobetter
          Posts: 5101
          Joined: Mon Feb 25, 2013 10:55 am
          languages_spoken: Korean, English
          ODROIDs: X, X2, U2, U3, XU3, C1
          Location: Paju, South Korea
          Has thanked: 160 times
          Been thanked: 493 times
          Contact:

          Re: guide: libsdl, dosbox, vice with hw acceleration

          Post by tobetter » Wed May 13, 2020 8:28 am

          riq wrote:thanks!.
          I confirm that it works Ok both on N2 and C4; and both on Wayland and KMSDRM (with the limitation that on KMSDRM only one mode seems to be available).
          Very quick...Thank you for the testing...then...what's next? LoL

          "Tapatalk wishes you to have fun with ODROID"


          riq
          Posts: 25
          Joined: Fri Feb 14, 2020 9:18 pm
          languages_spoken: english
          Has thanked: 4 times
          Been thanked: 7 times
          Contact:

          Re: guide: libsdl, dosbox, vice with hw acceleration

          Post by riq » Fri May 15, 2020 11:37 pm

          tobetter wrote:
          Wed May 13, 2020 8:28 am
          Very quick...Thank you for the testing...then...what's next? LoL
          since you asked :)
          Perhaps you know how to fix it (or if you don't, you might know where I can file a bug), and is drm-atomic.

          On N2, it seems that the Android_explict_sync[1] extension is not present, so you cannot run "kmscube -A" (atomic + android sync extension).
          On C4, that extension is present, but when you run "kmscube -A" after a few seconds, it will abort saying there was a bug with a fence.

          Ideally, both N2 and C4 should have the Android-explicit-sync extension.
          And ideally, "kmscube -A" should run fine.

          This is because, in a future, (and assuming I have time), I'd like to add drmAtomic to SDL (currently it is using "legacy").

          [1]: https://www.khronos.org/registry/EGL/ex ... e_sync.txt

          Post Reply

          Return to “Ubuntu”

          Who is online

          Users browsing this forum: No registered users and 2 guests