Skip to content

[performance] Add opt-in SDL display backend - #60

Draft
sayhiben wants to merge 2 commits into
cuneytozseker:mainfrom
sayhiben:codex/performance-sdl-kms-backend
Draft

[performance] Add opt-in SDL display backend#60
sayhiben wants to merge 2 commits into
cuneytozseker:mainfrom
sayhiben:codex/performance-sdl-kms-backend

Conversation

@sayhiben

@sayhiben sayhiben commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add an opt-in SDL output backend without changing the default framebuffer path.
  • Add DISPLAY_OUTPUT_BACKEND=framebuffer|sdl|auto and DISPLAY_SDL_DRIVER.
  • Choose the SDL video driver before pygame initializes.
  • Fall back to the framebuffer path if the requested SDL display cannot open.
  • Document/install the Mesa EGL/GBM runtime needed for KMSDRM on the Waveshare KMS setup.

Independence

This PR now targets main directly and contains only the SDL/KMS backend and runtime-requirement docs. Benchmark-script changes remain isolated in #54.

What Changed After Bring-Up

The original KMSDRM failure was not an app rendering issue. The device had /dev/dri/card0 and SDL's KMSDRM driver, but did not have the Mesa EGL/GLES runtime installed. SDL failed with:

[Terminal] SDL display backend unavailable, falling back to framebuffer: EGL not initialized

Installing these packages fixed KMSDRM display creation on the test device:

sudo apt install libegl1 libegl-mesa0 libgles2 libgl1-mesa-dri

The Waveshare provisioning script now installs those runtime packages, and the app fallback message now points at them when KMSDRM/EGL setup is incomplete.

Measurement / Experiment Result

Measured on the Pi using #54's benchmark script in a temporary checkout, with an opt-in run:

DISPLAY_OUTPUT_BACKEND=sdl DISPLAY_SDL_DRIVER=kmsdrm   python3 scripts/benchmark_render.py --samples 5 ...

The app now opens SDL KMSDRM successfully:

/dev/dri/card0
/dev/dri/renderD128
card0-DPI-1 connected, 720x720
[Terminal] Using SDL display driver: KMSDRM

Before SDL/KMS, after the optimized framebuffer PR:

terminal_render_display_no_stream: n=3 avg=40.1ms fps=24.9
terminal_render_display_stream_active_client: n=3 avg=43.6ms fps=23.0
typing_render_chars: n=1 chars=114 avg=4842.3ms cps=23.5

With SDL/KMS:

terminal_render_display_no_stream: n=5 avg=24.5ms fps=40.8
terminal_render_display_stream_no_clients: n=5 avg=24.8ms fps=40.3
terminal_render_display_stream_active_client: n=5 avg=28.3ms fps=35.4
typing_render_chars: n=1 chars=114 avg=3772.4ms cps=30.2

Conclusion: this is a real win on the KMS-backed Waveshare device once the Mesa EGL runtime is installed. Keep framebuffer as the default for broad compatibility, but KMSDRM is now a working opt-in path and a good candidate for targeted KMS display profiles.

Validation

  • python3 -m py_compile config.py display/terminal.py
  • bash -n scripts/setup-waveshare-4dpi-720.sh
  • Local opt-in DISPLAY_OUTPUT_BACKEND=sdl DISPLAY_SDL_DRIVER=dummy smoke test.
  • Pi SDL/KMS benchmark above; tinyprogrammer.service was restarted successfully afterward.

@sayhiben
sayhiben force-pushed the codex/performance-sdl-kms-backend branch from 4252a0e to 1794b0f Compare May 18, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant