pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
923 stars 152 forks source link

Document/Choose video drivers on rasPI (2301) #1177

Open GalacticEmperor1 opened 1 year ago

GalacticEmperor1 commented 1 year ago

Issue №2301 opened by robertpfeiffer at 2020-11-05 10:30:07

After trying out the SDL2 renderer-based version of @mcpalmer1980's game, which might be the largest pygame._sdl2 based code base out there, and some of my own games that use renderer via SCALED mode, I found that there are many configurations that don't result in hardware-accelerated rendering. GLX instead of EGL results in slow openGL via llvmpipe, OpenGL ES with the RPI driver is the fastest, but supports fewer features than mesa.

I built my own SDL2 from source, linked against evdev and enabled rpi video backend, which means it bypasses X11 for rendering and can talk to the input peripherals without X11.

Old To Do list - [ ] benchmark X11, fbdev and kmsdrm on x86 and arm, compare - [ ] make sure pi wheels link against SDL2 built with EGL, evdev, and rpi support - [ ] investigate behaviour of X11/mesa on Ubuntu 20.04 - [ ] investigate behaviour of X11/mesa on raspberry pi OS - [ ] test some popular PyOpenGL based games on rasPI - [ ] Document SDL_HINT_RENDER_DRIVER on rasPI - [ ] Document SDL_HINT_VIDEO_X11_FORCE_EGL (I can't find the docs online, but it's a thing in SDL2 2.0.12) - [ ] Document SDL_VIDEODRIVER=rpi (bypasses X11, no QUIT events) - [ ] make piwheels default to rpi driver, and EGL with fullscreen SCALED, OpenGL, and pygame._sdl2 Renderer?

Comments

*ankith26 commented at 2020-11-05 10:36:55*

Don’t know much about the technical details here, but I can confirm that mcpalmers FlyBoy runs really slowly on the Pi. So slow that it makes sense to start using spf(seconds per frame) and not FPS to measure the speed.


*illume commented at 2020-11-05 11:27:03*

There's an open issue in SDL bug tracker for this. Also there are some relevant video driver updates.

Note, we don't publish wheels for ARM. pygame comes installed with raspberry pi, and there are 'piwheels' made ones. 'manylinux2014' supports ARM wheels. 99% of users on raspberry pi do not pip install pygame, but 1000s of users do.

The built in SDL2 is patched by raspberry Pi people, and they are open to good patches.

Why are these notes relevant? because fixing this 'properly' in SDL could take a long time to get through to users.


*robertpfeiffer commented at 2020-11-05 17:52:51*

There's an open issue in SDL bug tracker for this. Also there are some relevant video driver updates.

Yes. X11/mesa drivers have seen a lot of development, especially on Pi 4.


*robertpfeiffer commented at 2021-01-11 16:42:09*

Mesa drivers are a lot better now, but most improvements are with X11/GLX on the Pi 4. EGL is a mixed bag.

MyreMylar commented 5 months ago

wayland & x11 are now the two drivers in play on raspberry Pi, rpi no longer exists. Wayland is the native driver now on Raspberry Pi OS Desktop.

x11 is the current pygame-ce default so it runs a bit slower. You can switch to wayland with:

os.environ['SDL_VIDEODRIVER'] = 'wayland'

and in my testing on a raspberry Pi 5 pygame programs run about 10% faster under wayland fullscreen or windowed. If possible we should probably set wayland as the default driver on Pis at some point soon.

I'm not sure there is much specific to document here for raspberry pi as the wayland stuff is fairly linux generic. Do you agree @robertpfeiffer ?

robertpfeiffer commented 5 months ago

I agree, with one wrinke. Mesa drivers with OpenGL do what you want them to do with wayland and X11. KMSDRM does what rpi used to do on the console. On the pi 4 and 5, and on newer SDL versions and recent-ish debian with recent-ish Mesa, there is no reason to use rpi driver or to refer to it, and there is no reason to do anything wonky with drivers on the desktop. KMSDRM works basically the same on x86 Ubuntu as on a Pi 4 with raspberry Pi OS.

MyreMylar commented 5 months ago

Yeah, I think I was missing the kmsdrm part of the picture on a 'desktop-free' installation.

It sounds like you still need to build a special version of SDL 2 to enable the kmsdrm driver, but the documentation is... not really there so I could have that wrong. I guess I could order another SD card to put a Lite Version of Raspberry Pi OS on to test the issues specifically related to that.

robertpfeiffer commented 5 months ago

The "building with kmsdrm" part might need some docs still. KMSDRM is not all you need. You might also need to link SDL against libinput or evdev to get keyboard and joystick input. Otherwise you have KMSDRM and no way to quit your game.

Especially because there is no window manager that draws an [X] on the frame and sends a pygame.QUIT event...

MyreMylar commented 5 months ago

Yeah, I think that is the area that people are coming unstuck on - ksmdrm driver, with Raspberry PI OS lite, and building SDL2 with pygame to work with both (recent versions of everything).

Maybe it needs a full tutorial treatment.