Raspberry Pi 4 - gpu acceleration for chromium-browser

Hi there,

I’ve been trying to get chromium-browser to run with GPU acceleration on a Raspberry Pi 4 using this as the base repo: https://github.com/balena-io-playground/x11-window-manager

My start.sh looks like this:

#!/bin/bash

# Remove the X server lock file so ours starts cleanly
rm /tmp/.X0-lock &>/dev/null || true

# Set the display to use
export DISPLAY=:0

# Set the DBUS address for sending around system messages
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

# start desktop manager
echo "STARTING X"
sleep 2
startx &
sleep 20

# Hide the cursor
unclutter -display :0 -idle 0.1 &

# Start Flask
python3 -u app/main.py &

sleep 10

# Launch chromium browser in fullscreen on that page
SCREEN_SCALE="${SCREEN_SCALE:-default 1.0}"
chromium-browser --app=http://localhost:8080 --start-fullscreen --no-sandbox --user-data-dir --kiosk --force-device-scale-factor=$SCREEN_SCALE --no-user-gesture-required

# For debugging
echo "Chromium browser exited unexpectedly."
free -h
echo "End of pi.sh ..."

and my Dockerfile.raspberrypi4-64 looks like this:

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM balenalib/raspberrypi3:buster

# use `install_packages` if you need to install dependencies,
# for instance if you need git, just uncomment the line below.
RUN install_packages \
  g++ python3-pip python3-setuptools python3-dev build-essential \
  chromium-browser \
  rpi-chromium-mods \
  lsb-release xserver-xorg \
  xinit lxsession desktop-file-utils \
  raspberrypi-ui-mods rpd-icons \
  gtk2-engines-clearlookspix \
  matchbox-keyboard \
  unclutter \
  # Support for Accuview gTouch 21.5" touchscreen
  xserver-xorg-input-evdev \
  xinput

# disable lxpolkit popup warning
RUN mv /usr/bin/lxpolkit /usr/bin/lxpolkit.bak

# Set wallpaper
COPY /conf/desktop-items-0.conf /root/.config/pcmanfm/LXDE-pi/

# Autohide panel
COPY /conf/panel /root/.config/lxpanel/LXDE-pi/panels/

# Hide panel completely
COPY /conf/autostart /etc/xdg/lxsession/LXDE-pi/
COPY /conf/autostart /root/.config/lxsession/LXDE-pi/

# Disable screen from turning it off
RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
  && echo "" >> /etc/X11/xinit/xserverrc \
  && echo 'exec /usr/bin/X -s 0 dpms -nolisten tcp "$@"' >> /etc/X11/xinit/xserverrc

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV 1

COPY ./requirements.txt /code/requirements.txt
RUN pip3 install -Ur /code/requirements.txt

COPY . /code/
WORKDIR /code/

# pi4.sh will run when container starts up on the device
CMD ["bash","scripts/pi4.sh"]

I’ve set RESIN_HOST_CONFIG_gpu_mem to 396

Any hints?

Cheers, Simon.

Hi @sighmon. What are the issues you re facing? Did you try out the base repo as is? Gradually building up changes on top of that repo, could help you identify the issue here.

@mikesimos I’m trying to play a 1080p video in an html5 video tag, but it doesn’t play smoothly and the CPU is pegged, so seems that the GPU isn’t being used for video decoding at all.

Video spec: 1080p, h264, 30fps.

Hi @sighmon I don’t think anyone has tried this yet, but I believe one needs to pass specific flags to chromium to use the gpu on some arm devices. What I would suggest trying is passing the flags listed in https://lb.raspberrypi.org/forums/viewtopic.php?t=199543 to see if that enables the gpu.

Hi,
are there any news for chromium support? For me the problem here ist webgl. It´s listet in chrome://gpu with “hardware accelerated but at reduced performance”

My chrome Flags are:
su -c "chromium --app=chrome://gpu --unlimited-storage --window-size=1920,1080 --noerrdialogs --disable-session-crashed-bubble --disable-infobars --disable-restore-session-state --ignore-gpu-blacklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --disable-gpu-compositing" viewer

Hi @danielboe,

Just to check, have you tried the patches Shaun described in his previous post, here: https://lb.raspberrypi.org/forums/viewtopic.php?t=199543 ? I note that the message you’ve pasted is “hardware accelerated but at reduced performance”, which unfortunately doesn’t mean a lot to us. So it sounds like the GPU is enabled and being used, is there anything in particular you’re seeing that exhibits a non-GPU issue?

Best regards,

Heds

For me it´s not working. Web GL is not showing up here: https://get.webgl.org/
Also I don´t get a good HD Video Playback (still interlace). In Videos it looks the same than with software rendering for chromium. So I do´t think the video driver is working as it should.
Here is my GPU Plot with stretch on RPI 4 1GB:

Hi, as I mentioned on the other related thread can you please check the same with an updated latest Raspbian installation so that this could be narrowed down more?
Thanks,
Zahari

Hi,
after installing libgles2-mesa libsdl2-dev on raspbian the GPU Acceleration shows the same as on Balena image but WebGL is working fine! I made a screenshot for Commission. All from scratch with raspbian buster light image.

Edit: Also interessting: with the flag “–disable-gpu-compositing” I get a better video playback with less tearing (but it has still some) but I lose about 25% performance in webgl (aquarium test from webglsamples.org)

Edit2: I also enabled the fake KMS via raspi-config “raspi-config -> Advanced Options -> GL Driver -> GL (fake KM”

Thank you very much for the extra info, this gives us something to work upon and investigate. I’m going to raise this internally as it looks like it requires some in-depth analysis and we’ll need to determine the best way to go about specifying this.

Best regards,

Heds

@hedss nice! If you need more feedback from me, let me know

hey @danielboe
so from my experiments, I found that one needs to get the chromium-browser from the raspbian source since it has additional patches specific to the pi. see the repo here you also need to have gpu_mem=128 also, proper permissions and preferably use the balenalib/rpi-raspbian base image. Can try to start working from this one if it helps: I’m able to get ~60fps for webgl rendering (using this website). you might also need to adjust the flags based on your content

let us know how it turns out.
Cheers!
Rahul

Hi, your repo helps me a lot! Do you use the raspberry pi 4?

hey, yes i’ve tested this on Pi 3B, 3b+ and 4B

Strange, with your container I get a good performance at all but webgl, also your link, is not working. Also there are massive problems with tearing for hd videos but it’s the same with native raspbian and also there are a lot of people talking about this with Pi4. Btw the omxplayer delivers perfekt hd performance also in Pi4.

How much memory have you set for the gpu?
Can you please clarify which link is not working?

Hi,
I tested this webgl link from you https://akirodic.com/p/jellyfish/

Video memory was tested with 128 and 192 MB set

hey,
that is strange! I am using the same repo and the same url
also regarding videos, are those h.264 encoded? those are gpu accelerated

thanks

Hi, I would like to push this thread again because I think it´s still a big problem. I tried chromium again and I still get no good support for webgl and hd video playback. Is there any solution or image where I can get this features? Because I think RPI4 is more then capable to do so

As a non-root user, how can I launch chromium-browser with Broadcom GPU enabled?

Example run as pi user:
su - pi -c "DISPLAY=:0.0 chromium-browser"
The GL_RENDERER: Google SwiftShader base on chrome://gpu

So far, I only able to get Broadcom GPU enabled when run chromium with root user and --no-sandbox flags.
DISPLAY=:0.0 chromium-browser --no-sandbox
GL_VENDOR: Broadcom
GL_RENDERER: V3D 4.2

Anyone have any idea ? thanks