SFML, SDL2 or OpenGL ES use in Torizon Images with Vivante

Hello,

I am using the wayland-base-vivante image to build a Docker image with OpenCV and SFML. However, the dependencies for SFML are not being resolved, and when I try to install them, I encounter errors related to compatibility with some iMX GPU drivers.

I also tried to compile the SDL2 library with the wayland image using both the tags “3” and “old-stable-rc” versions, but without success.

My objective is to run a C++ code that generates a simple HUD with lines, circles, triangles, and rotation transforms using camera images, and then saves the output as an MP4 file.

Could you please advise on how to resolve these issues?

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello!

For graphics acceleration on Torizon, Toradex recommends utilizing OpenGL ES with Wayland as the graphics backend. This setup is particularly suitable for i.MX 8 Series modules and BSP 5.0 onwards. Here are the supported graphics backends:

  • Wayland: Preferred for i.MX 8 Series modules and BSP 5.0 onwards.
  • X11: Supported only on pre-i.MX 8 Series modules with older BSPs.

For your project, I suggest using the OpenGL ES approach, as it is officially supported. You can start with the wayland-base-vivante image as shown below:

FROM torizon/wayland-base-vivante:2

For camera image processing, integrating OpenCV with OpenGL ES is a viable option. Toradex provides examples that demonstrate combining OpenCV for image processing with Wayland for display output.

Instead of using SFML or SDL2, consider the following recommendations:

  1. OpenGL ES: Use it directly for your HUD graphics.
  2. OpenCV: Employ it for camera image processing.
  3. GStreamer: Utilize it for video output and MP4 saving.

To validate graphics performance, Toradex uses the glmark2 benchmark to test OpenGL ES capabilities.

If you need more specific details about implementing any of these components, feel free to ask. Let me know which aspect you’d like to focus on first.

Best regards,
Toradex AI Assistant

Greetings @AhaUhu,

Could you please provide more details about your setup. Specifically the following information would be very helpful:

  • How are you building your docker image?
    • Your full Dockerfile, if you can share it would be nice.
  • What are the error messages you see?
  • What Toradex module is this for, and what version of Torizon OS is running on that module?

Best Regards,
Jeremias

Hello, @jeremias.tx !
I’m using a imx8mp in a Mallow carrier board, however, i compiled in my laptop. I’ve used this command to build:

docker build -t luccasparentex/vpugeneric:v1 --build-arg IMAGE_ARCH=arm64 .

And I’ve received this errors:

 => ERROR [stage-1 13/18] RUN apt-get install -y libsdl2-dev                                                                     14.9s
------
 > [stage-1 13/18] RUN apt-get install -y libsdl2-dev:
0.533 Reading package lists...
12.54 Building dependency tree...
13.90 Reading state information...
14.44 Some packages could not be installed. This may mean that you have
14.44 requested an impossible situation or if you are using the unstable
14.44 distribution that some required packages have not yet been created
14.44 or been moved out of Incoming.
14.44 The following information may help to resolve the situation:
14.44 
14.44 The following packages have unmet dependencies:
14.89  libsdl2-dev : Depends: libegl-dev
14.89                Depends: libgbm-dev
14.89                Depends: libgl-dev
14.89                Depends: libgles-dev
14.91 E: Unable to correct problems, you have held broken packages.
------

 1 warning found (use docker --debug to expand):
 - StageNameCasing: Stage name 'Base' should be lowercase (line 22)
Dockerfile:234
--------------------
 232 |         build-essential
 233 |     
 234 | >>> RUN apt-get install -y libsdl2-dev
 235 |     
 236 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get install -y libsdl2-dev" did not complete successfully: exit code: 100

And when I try to install the dependencies:

=> ERROR [stage-1 13/17] RUN apt-get update && apt-get install -y     libgl-dev     libegl-dev                                  39.0s
------
 > [stage-1 13/17] RUN apt-get update && apt-get install -y     libgl-dev     libegl-dev:
1.365 Hit:1 http://deb.debian.org/debian bookworm InRelease
1.369 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
1.386 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
1.409 Hit:4 http://snapshot.debian.org/archive/debian/20220209T031931Z bookworm InRelease
2.509 Hit:5 https://feeds1.toradex.com/debian/snapshots/20241004T164707Z testing InRelease
2.509 Hit:6 https://feeds.toradex.com/debian/snapshots/20230328T143626Z testing InRelease
6.732 Get:7 http://deb.debian.org/debian-security bookworm-security/main arm64 Packages [253 kB]
12.09 Fetched 357 kB in 11s (31.8 kB/s)
12.09 Reading package lists...
24.36 Reading package lists...
36.74 Building dependency tree...
38.13 Reading state information...
38.50 Some packages could not be installed. This may mean that you have
38.50 requested an impossible situation or if you are using the unstable
38.50 distribution that some required packages have not yet been created
38.50 or been moved out of Incoming.
38.50 The following information may help to resolve the situation:
38.50 
38.50 The following packages have unmet dependencies:
38.96  imx-gpu-viv-wayland : Conflicts: libegl1
38.96                        Conflicts: libgbm1
38.96                        Conflicts: libgl1
38.97 E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
------

 1 warning found (use docker --debug to expand):
 - StageNameCasing: Stage name 'Base' should be lowercase (line 22)
Dockerfile:236
--------------------
 235 |     
 236 | >>> RUN apt-get update && apt-get install -y \
 237 | >>>     libgl-dev \
 238 | >>>     libegl-dev
 239 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y     libgl-dev     libegl-dev" did not complete successfully: exit code: 100

And when I try to use SFML:

=> ERROR [stage-1 13/15] RUN apt-get update && apt-get install -y     libsfml-dev                                               39.6s
------
 > [stage-1 13/15] RUN apt-get update && apt-get install -y     libsfml-dev:
1.343 Hit:1 http://deb.debian.org/debian bookworm InRelease
1.348 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
1.374 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
1.402 Hit:4 http://snapshot.debian.org/archive/debian/20220209T031931Z bookworm InRelease
2.315 Hit:5 https://feeds1.toradex.com/debian/snapshots/20241004T164707Z testing InRelease
2.556 Hit:6 https://feeds.toradex.com/debian/snapshots/20230328T143626Z testing InRelease
6.626 Get:7 http://deb.debian.org/debian-security bookworm-security/main arm64 Packages [253 kB]
11.93 Fetched 357 kB in 11s (32.3 kB/s)
11.93 Reading package lists...
24.82 Reading package lists...
37.28 Building dependency tree...
38.66 Reading state information...
39.10 Some packages could not be installed. This may mean that you have
39.10 requested an impossible situation or if you are using the unstable
39.10 distribution that some required packages have not yet been created
39.10 or been moved out of Incoming.
39.10 The following information may help to resolve the situation:
39.10 
39.10 The following packages have unmet dependencies:
39.58  libsfml-dev : Depends: libgl1-mesa-dev or
39.58                         libgl-dev
39.60 E: Unable to correct problems, you have held broken packages.
------

 1 warning found (use docker --debug to expand):
 - StageNameCasing: Stage name 'Base' should be lowercase (line 22)
Dockerfile:244
--------------------
 243 |     
 244 | >>> RUN apt-get update && apt-get install -y \
 245 | >>>     libsfml-dev
 246 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y     libsfml-dev" did not complete successfully: exit code: 100

And the dependencies:

=> ERROR [stage-1 13/16] RUN apt-get update && apt-get install -y libgl-dev || libgl1-mesa-dev                                  40.9s
------
 > [stage-1 13/16] RUN apt-get update && apt-get install -y libgl-dev || libgl1-mesa-dev:
1.372 Hit:1 http://deb.debian.org/debian bookworm InRelease
1.376 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
1.394 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
1.416 Hit:4 http://snapshot.debian.org/archive/debian/20220209T031931Z bookworm InRelease
2.323 Hit:5 https://feeds1.toradex.com/debian/snapshots/20241004T164707Z testing InRelease
2.347 Hit:6 https://feeds.toradex.com/debian/snapshots/20230328T143626Z testing InRelease
6.715 Get:7 http://deb.debian.org/debian-security bookworm-security/main arm64 Packages [253 kB]
12.05 Fetched 357 kB in 11s (31.8 kB/s)
12.05 Reading package lists...
24.77 Reading package lists...
37.88 Building dependency tree...
39.56 Reading state information...
40.10 Some packages could not be installed. This may mean that you have
40.10 requested an impossible situation or if you are using the unstable
40.10 distribution that some required packages have not yet been created
40.10 or been moved out of Incoming.
40.10 The following information may help to resolve the situation:
40.10 
40.10 The following packages have unmet dependencies:
40.81  imx-gpu-viv-wayland : Conflicts: libgl1
40.83 E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
40.84 /bin/sh: 1: libgl1-mesa-dev: not found
------

 1 warning found (use docker --debug to expand):
 - StageNameCasing: Stage name 'Base' should be lowercase (line 22)
Dockerfile:244
--------------------
 242 |     #    && rm -rf /var/lib/apt/lists/*
 243 |     
 244 | >>> RUN apt-get update && apt-get install -y libgl-dev || libgl1-mesa-dev
 245 |         
 246 |     RUN apt-get update && apt-get install -y \
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y libgl-dev || libgl1-mesa-dev" did not complete successfully: exit code: 127

I’m trying to do a Head Up Display overlaid on a camera image, and the Torizon OS version is 6.7.0

I’ve tried to do this with weston-vivante:3 image and qt6-wayland-examples-vivante. Same problems

Dockerfile (8.6 KB)

After some testing I found the following.

First of all, I can confirm the issue myself. I was able to narrow down the issue to just the following:

ARG BASE_VERSION=3

##
# Board architecture
# arm or arm64
##
ARG IMAGE_ARCH=

##
# Board GPU vendor prefix
##
ARG GPU=

##
# SoM
##
#ARG MACHINE=verdin-imx8mm
ARG MACHINE=verdin-imx8mp
#ARG MACHINE=apalis-imx8

# BUILD ------------------------------------------------------------------------
FROM --platform=linux/${IMAGE_ARCH} \
    torizon/wayland-base-vivante:${BASE_VERSION} AS Base

ARG IMAGE_ARCH
ARG GPU
ARG MACHINE

RUN apt-get update && apt-get install -y \
    libsdl2-dev

Just simply trying to install libsdl2-dev causes the issue you reported. As you suspected this is due to dependency conflicts with the package that provides the libraries for the i.MX vivante GPU. At the moment it’s hard to say if this can be changed/adjusted in a way that does not break something else.

I did however try the torizon/wayland-base-imx8:4 container image. This is the equivalent container image, but meant for Torizon OS 7.X instead of 6.X. With this container image I was able to install both libsdl2-dev and libsfml-dev without error. That said, I noticed in your Dockerfile you’re also trying to enable the VPU acceleration. We have not yet done the work for enabling VPU acceleration in the Torizon OS 7.X containers.

So you could move to Torizon OS 7.X and use torizon/wayland-base-imx8:4, then you can install the packages you want to use. But, then you may have to wait some time before we have VPU acceleration ready on this version.

Is both GPU and VPU acceleration absolutely vital for your system?

Best Regards,
Jeremias

Thank you for the detailed investigation.

The goal of our project is to generate a HUD overlay on top of an image and save it as a video. We are targeting something between 30 and 60 FPS, with resolutions ranging from HD to Full HD. Additionally, we are receiving the image from a USB camera via MJPEG, so we are still evaluating whether faster encoding/decoding or GPU-accelerated graphics for the HUD would bring more benefit to the system.

Considering this, both GPU and VPU acceleration are important to us, although at this moment we are analyzing which one has a greater impact on overall performance.

Considering this, both GPU and VPU acceleration are important to us, although at this moment we are analyzing which one has a greater impact on overall performance.

Of course, I understand it would be most ideal to have VPU and GPU for your use-case. Though the current situation would require some work to achieve both.

  • Torizon OS 6.X we have GPU and the VPU, but there’s that dependency issue with trying to install libsdl2-dev and libsfml-dev.
    • Are you already locked-in to using these libraries/frameworks for your software?
    • I’m consulting with the team about the dependency issues, but there’s no timeline yet for if/when this would get looked at by the team.
  • Torizon OS 7.X has GPU but, VPU still needs some work. However, here it seems the dependency issues with the packages is no longer present.

Best Regards,
Jeremias

In my current project, I used SFML for overlaying graphics on top of video frames. When I encountered the dependency issue, SDL2 was the first alternative I considered. However, I’m open to exploring other solutions if it allows me to fully leverage the available hardware acceleration features (VPU/GPU).

Would using one of the standard Linux distributions provided by Toradex instead of Torizon help avoid this issue?

Please let me know if you have any recommendations or workarounds that could help me move forward.

To be clear, you are free to use whatever graphics libraries/frameworks you like. With regards to GUI frameworks we have the following documentation: GUI Documentation Overview | Toradex Developer Center

In our VSCode extension we also offer the following code templates: GitHub - torizon/vscode-torizon-templates: VS Code Torizon Integrated Development Environment Templates

Would using one of the standard Linux distributions provided by Toradex instead of Torizon help avoid this issue?

Other than Torizon we have a Yocto reference image available: Embedded Linux Options | Toradex Developer Center

Though if you want to add additional libraries/packages to this image, that would require use and knowledge of the Yocto build system.

Best Regards,
Jeremias