Python app using software OpenGL rendering

I am running a pyglet app on a raspberry pi5 that runs at around 60fps on RaspberryPi OS. However, when I port it to balena cloud, containerized, it runs at about 7-10fps. I am using Xvfb and X11vnc to render the gui.

My current theory is that OpenGL is rendering in software rendering mode:

root@608f2de:/app# glxinfo | grep renderer
    GLX_MESA_copy_sub_buffer, GLX_MESA_query_renderer, GLX_MESA_swap_control, 
    GLX_MESA_query_renderer, GLX_OML_swap_method, GLX_SGIS_multisample, 
Extended renderer info (GLX_MESA_query_renderer):
OpenGL renderer string: llvmpipe (LLVM 15.0.6, 128 bits)

I have the following configuration settings

Force HDMI hotplug: true
RESIN_HOST_CONFIG_gpu_mem=512
RESIN_HOST_CONFIG_dtoverlay=“vc4-kms-v3d”
RESIN_HOST_CONFIG_dtparam=“audio=on”,“i2c_arm=on”,“spi=on”,“audio=on”

  application:
    build: application/
    container_name: application_app
    privileged: true
    depends_on:
      - mongodb-seed
    network_mode: 'host'
    environment:
      - MONGO_URI=mongodb://localhost:27017
      - UDEV=1
      - DISPLAY=:99
      - LIBGL_ALWAYS_SOFTWARE=0  # Ensure hardware rendering is preferred
      - MESA_LOADER_DRIVER_OVERRIDE=v3d
      - DRI_PRIME=1
    cap_add:
      - "SYS_RAWIO"
      - "SYS_ADMIN"
    labels:
      io.balena.features.kernel-modules: "1"
      io.balena.features.firmware: "1"
      io.balena.features.supervisor-api: "1"
    devices:
      - "/dev/dri:/dev/dri"  # Direct Rendering Infrastructure (GPU access)
      - "/dev/vcsm:/dev/vcsm"  # Broadcom GPU memory interface (if applicable)
      - "/dev/gpiomem:/dev/gpiomem"
      - "/dev/spidev0.0:/dev/spidev0.0"
      - "/dev/spidev0.1:/dev/spidev0.1"
      - "/dev/snd:/dev/snd"       
    volumes:
      - application_media:/data/application-media
      - application_config:/data/application-config
    restart: unless-stopped
# Use a base image for your device
FROM balenalib/raspberrypi5-debian:bookworm

# Install nece# # Add Bookworm repository and install necessary packages
RUN echo "deb [signed-by=/usr/share/keyrings/raspberrypi-archive-keyring.gpg] http://archive.raspberrypi.org/debian/ bookworm main" > /etc/apt/sources.list.d/raspi.list && \
    curl -fsSL https://archive.raspberrypi.org/debian/raspberrypi.gpg.key | gpg --dearmor -o /usr/share/keyrings/raspberrypi-archive-keyring.gpg && \
    apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    cmake git pkg-config \
    #pyglet
    libgtk2.0-0 libgdk-pixbuf2.0-0 \
    libebur128-dev libtag1-dev libavformat-dev libavcodec-dev libswresample-dev libavutil-dev libfmt-dev libinih-dev \
    python3-pip python3-venv python3-dev liblgpio1 \
    libgl1-mesa-glx libglu1-mesa \
    # Not sure if needed 
    libgl1-mesa-dri libgles2-mesa libx11-6 mesa-utils mesa-vulkan-drivers\
    ffmpeg swig sox libsox3 mediainfo \
    xvfb x11vnc xauth \
    alsa-utils libasound2 pciutils \
    vlc libvlc-dev \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Ensure /app directory exists
RUN mkdir -p /app

# Set the working directory
WORKDIR /app

# Copy application files
COPY . /app

# Clone and build rsgain
RUN git clone https://github.com/complexlogic/rsgain.git && \
    cd rsgain && \
    mkdir build && cd build && \
    cmake .. -DCMAKE_BUILD_TYPE=Release && make && make install

# Use the virtual environment for the application
ENV VIRTUAL_ENV=/application-venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Copy only requirements file and create virtual environment
COPY requirements-pi.txt /app/requirements-pi.txt
RUN python3 -m venv $VIRTUAL_ENV && \
    . ${VIRTUAL_ENV}/bin/activate && \
    pip install -r /app/requirements-pi.txt

# Setup ALSA
RUN echo 'drivers = alsa' > ~/.alsoftrc
COPY application/util/docker/asound.conf /etc/

# Environment variables
ENV DISPLAY=:99
ENV SCREEN=0
ENV RESOLUTION=1920x1080x24

# Expose VNC port
EXPOSE 5900

RUN chmod +x application/util/docker/docker-start.sh

# Set the entrypoint
CMD ["/util/docker/docker-start.sh"]

Any help would be greatly appreciated

Hello @tomas first of all welcome to the balena community!

I’m going to ask internally at the balena team.

In the meantime, could you please confirm what version of the Raspberry Pi OS you used to run around 60fps and the version of balenaOS to run at 10fps (aprox).

Thanks

Hello @tomas

a colleague mentioned if. you could try the same device, same GPU config, but with browser block showing something like WebGL Aquarium

this may help decide whether the problem is with the GPU config or in the container.

Let us know the results! Thanks!