BlitterStudio / amiberry

Optimized Amiga emulator for Linux/macOS
https://amiberry.com
GNU General Public License v3.0
660 stars 89 forks source link

Video problems on RPi4 when PLATFORM=pi64-dispmanx is chosen #816

Closed boras-pl closed 3 years ago

boras-pl commented 3 years ago

Describe the bug Amiberry can not show video properly when I compile it with pi64-dispmanx option. There is no problem when dispmanx is not used.

To Reproduce

make -j4 PLATFORM=pi64-dispmanx
./amiberry

Symptoms

Desktop (please complete the following information): RPi4, RaspiOS buster lite 64-bit, KMSDRM, SDL2 compiled from git head. All revisions are the same as in https://github.com/midwan/amiberry/issues/814

I would like to take this opportunity to ask you what is the difference between rpi64 and rpi64-dispmanx options? I know what DispmanX is, and off-course SDL2 too. However, looking at the code it looks like SDL2 is still needed for some graphics operations. Is the DispmanX specific code needed for graphics drawing only? Is there any advantage to using DispmanX API? Is it faster for RPI4, especially?

Love Amiberry? Please consider supporting our collective: šŸ‘‰ https://opencollective.com/amiberry/donate

solskogen commented 3 years ago

Can you post your /boot/config.txt?

boras-pl commented 3 years ago
disable_overscan=1
hdmi_force_hotplug=1
hdmi_group=1
hdmi_mode=31
sdtv_mode=2
dtparam=i2c_arm=on
dtparam=audio=on
max_framebuffers=2
arm_64bit=1
[all]
dtoverlay=vc4-fkms-v3d
hdmi_enable_4kp60=1
dtparam=i2c_arm=on
enable_uart=1
solskogen commented 3 years ago

That looks pretty okay. How do you compile SDL2?

midwan commented 3 years ago

I noticed this line hdmi_enable_4kp60=1 in the config file. Are you using a 4k resolution? I'm not sure Dispmanx can handle that...

boras-pl commented 3 years ago

This is my initial environment:

sudo apt update
sudo apt
sudo apt full-upgrade
sudo raspi-config
#CEA Mode 31 1920x1080 50Hz 16:9
#Underscan disabled
#G2 GL (Fake KMS)
#Compositor xcompmgr disabled

reboot
sudo raspi-config
sudo apt update
sudo apt install kmscube

sudo apt-get install libfreetype6-dev libgl1-mesa-dev libgles2-mesa-dev libdrm-dev libgbm-dev libudev-dev libasound2-dev liblzma-dev libjpeg-dev libtiff-dev libwebp-dev git build-essential
wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz
wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz
git clone https://github.com/libsdl-org/SDL.git
cd SDL/
./configure --enable-video-kmsdrm --enable-video-opengl --enable-video-opengles --disable-video-wayland --disable-video-rpi --disable-video-x11 --disable-video-vivante --disable-video-cocoa --disable-video-directfb --disable-video-vulkan
--disable-directx
make -j4
sudo make install
ls -la /usr/local/lib/
cd ..
tar xf SDL2_image-2.0.5.tar.gz
tar xf SDL2_ttf-2.0.15.tar.gz
cd SDL2_image-2.0.5
./configure
make -j4
sudo make install
cd ..
cd SDL2_ttf-2.0.15
./configure
make -j4
sudo make install
cd ..
sudo apt-get install gir1.2-ibus-1.0 libdbus-1-dev libegl1-mesa-dev libibus-1.0-5 libibus-1.0-dev libice-dev libsm-dev libsndio-dev libwayland-bin libwayland-dev libxi-dev libxinerama-dev libxkbcommon-dev libxrandr-dev libxss-dev libxt-de
v libxv-dev x11proto-randr-dev x11proto-scrnsaver-dev x11proto-video-dev x11proto-xinerama-dev
sudo apt install libflac-dev libmpeg2-4-dev libmpg123-dev libxml2-dev
git clone https://github.com/midwan/amiberry.git amiberry_4.1.2
cd amiberry_4.1.2/
git checkout v4.1.2
make -j4 PLATFORM=pi64
cd ..
git clone https://github.com/midwan/amiberry.git amiberry_3.3
cd amiberry_3.3/
git checkout v3.3
make -j4 PLATFORM=pi64

Then I was experimenting a little bit, so I probably had --disable-video-opengl while experienced the problem. And of course PLATFORM pi64-dispmanx instead of above. Now I recompiled SDL with --enable-video-opengl and I have video on the StateOfTheArt demo but very slow. I still need to press F12 to show Amiberry GUI after startup.

solskogen commented 3 years ago

Can you try the guide on the wiki https://github.com/midwan/amiberry/wiki/Compile-SDL2-for-KMSDRM for compiling SDL? (also, try us at Discord)

On Mon, May 24, 2021 at 3:07 PM boras-pl @.***> wrote:

This is my initial environment:

sudo apt update sudo apt sudo apt full-upgrade sudo raspi-config

CEA Mode 31 1920x1080 50Hz 16:9

Underscan disabled

G2 GL (Fake KMS)

Compositor xcompmgr disabled

reboot sudo raspi-config sudo apt update sudo apt install kmscube

sudo apt-get install libfreetype6-dev libgl1-mesa-dev libgles2-mesa-dev libdrm-dev libgbm-dev libudev-dev libasound2-dev liblzma-dev libjpeg-dev libtiff-dev libwebp-dev git build-essential wget https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.5.tar.gz wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.tar.gz git clone https://github.com/libsdl-org/SDL.git cd SDL/ ./configure --enable-video-kmsdrm --enable-video-opengl --enable-video-opengles --disable-video-wayland --disable-video-rpi --disable-video-x11 --disable-video-vivante --disable-video-cocoa --disable-video-directfb --disable-video-vulkan --disable-directx make -j4 sudo make install ls -la /usr/local/lib/ cd .. tar xf SDL2_image-2.0.5.tar.gz tar xf SDL2_ttf-2.0.15.tar.gz cd SDL2_image-2.0.5 ./configure make -j4 sudo make install cd .. cd SDL2_ttf-2.0.15 ./configure make -j4 sudo make install cd .. sudo apt-get install gir1.2-ibus-1.0 libdbus-1-dev libegl1-mesa-dev libibus-1.0-5 libibus-1.0-dev libice-dev libsm-dev libsndio-dev libwayland-bin libwayland-dev libxi-dev libxinerama-dev libxkbcommon-dev libxrandr-dev libxss-dev libxt-de v libxv-dev x11proto-randr-dev x11proto-scrnsaver-dev x11proto-video-dev x11proto-xinerama-dev sudo apt install libflac-dev libmpeg2-4-dev libmpg123-dev libxml2-dev git clone https://github.com/midwan/amiberry.git amiberry_4.1.2 cd amiberry_4.1.2/ git checkout v4.1.2 make -j4 PLATFORM=pi64 cd .. git clone https://github.com/midwan/amiberry.git amiberry_3.3 cd amiberry_3.3/ git checkout v3.3 make -j4 PLATFORM=pi64

Then I was experimenting a little bit, so I probably had --disable-video-opengl while experienced the problem. And of course PLATFORM pi64-dispmanx instead of above. Now I recompiled SDL with --enable-video-opengl and I have video on the StateOfTheArt demo but very slow. I still need to press F12 to show Amiberry GUI after startup.

ā€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/midwan/amiberry/issues/816#issuecomment-847030255, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHY72FQW2AOCG425BXASLTTPJFRNANCNFSM45NCPSGA .

boras-pl commented 3 years ago
  1. hdmi_enable_4kp60=0 does not change anything. The demo is slow, and Amiberry lacks of GUI until I press F12 twice.

  2. I know this guide. Almost all of my commands are in accordance with the guide, with some negligible exceptions, e.g.: ./configure --enable-video-kmsdrm --disable-video-rpi adds some unwanted backends like vulkan and wayland, that's why I intentionally disabled it. Anyway it does not matter. I suspect the problem is somewhere in Broadcom firmware than in your code.

    • I'm just curious if DispmanX API is worh of investigation, as the pure SDL2 variant works fine. So it is not so critical issue.
    • Maybe this is a specific case for RPi4 64 bit only? I just wonder what happens here.
solskogen commented 3 years ago

I've just tried with the same setup as you (64bit lite Raspberry Pi OS, and SDL compiled from git) - and I have no problems whatsoever. The demos runs fine, and I do not need to press F12 twice to get to the GUI.

On Mon, May 24, 2021 at 4:11 PM boras-pl @.***> wrote:

1.

hdmi_enable_4kp60=0 does not change anything. The demo is slow, and Amiberry lacks of GUI until I press F12 twice. 2.

I know this guide. Almost all of my commands are in accordance with the guide, with some negligible exceptions, e.g.: ./configure --enable-video-kmsdrm --disable-video-rpi adds some unwanted backends like vulkan and wayland, that's why I intentionally disabled it. Anyway it does not matter. I suspect the problem is somewhere in Broadcom firmware than in your code.

  • I'm just curious if DispmanX API is worh of investigation, as the pure SDL2 variant works fine. So it is not so critical issue.
  • Maybe this is a specific case for RPi4 64 bit only? I just wonder what happens here.

ā€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/midwan/amiberry/issues/816#issuecomment-847069819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHY72ENK336KAYQ5VGNTIDTPJNB7ANCNFSM45NCPSGA .

solskogen commented 3 years ago

I found the culprit.

With your config.txt I got the same problem. Until I commented out hdmi_group=1

solskogen commented 3 years ago

If you really need hdmi_group=1 try with hdmi_mode=16 instead of 31

boras-pl commented 3 years ago

I prefer CEA modes due to 50Hz. Thanks this I have smooth scrolling in PAL emulation. If DispmanX works good in 60Hz only, it's not a problem for me. I'll stay with my current settings and pure SDL builds. Thanks for your support.

solskogen commented 3 years ago

You'll still get 50Hz in Amiberry :)

On Mon, May 24, 2021 at 4:56 PM boras-pl @.***> wrote:

I prefer CEA modes due to 50Hz. Thanks this I have smooth scrolling in PAL emulation. If DispmanX works good in 60Hz only, it's not a problem for me. I'll stay with my current settings and pure SDL builds. Thanks for your support.

ā€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/midwan/amiberry/issues/816#issuecomment-847097941, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHY72GURXE6RJIHLWUK7LTTPJSIRANCNFSM45NCPSGA .

boras-pl commented 3 years ago

Unfortunately not. When a 60Hz mode is chosen in config.txt my display reports 60Hz while working Amiberry either for Windows or Fullscreen mode. Scrolls are juderred then.

midwan commented 3 years ago

Dispmanx works fine under 50Hz also, not just 60Hz. But of course, it's experimental under 64-bit platforms so there may be issues there that are outside our control with Amiberry.

boras-pl commented 3 years ago

I've checked the latest 32-bit distro - 2021-05-07-raspios-buster-armhf-lite.zip and compiled everything from scratch. Here are results for PLATFORM=rpi4 Unfortunately it works as bad as 64-bit. Even worse, 1080p@60Hz is affected as well. 50 Hz (hdmi_group=1, hdmi_mode=31) is unusable - everything blinks and performance is very bad https://www.dropbox.com/s/qakfr2xchcqfwdm/1622326397932.mp4?dl=0 60 Hz (hdmi_group=2, hdmi_mode=82) is similar to this what I observed in RaspiOS 64-bit https://www.dropbox.com/s/8knf7txxae7l8dp/1622326299508.mp4?dl=0

PLATFORM=rpi4-sdl2 works ok.

My environment:

pi@raspberrypi:~ $ cat /boot/config.txt | grep -v '^ *#' | sed -r '/^\s*$/d'
disable_overscan=1
hdmi_group=2
hdmi_mode=82
dtparam=audio=on
[pi4]
dtoverlay=vc4-fkms-v3d
max_framebuffers=2
[all]
dtoverlay=vc4-fkms-v3d
gpu_mem=256
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.17-v7l+ #1421 SMP Thu May 27 14:00:13 BST 2021 armv7l GNU/Linux
pi@raspberrypi:~ $ vcgencmd version
May 27 2021 14:02:15 
Copyright (c) 2012 Broadcom
version 7d9a298cda813f747b51fe17e1e417e7bf5ca94d (clean) (release) (start)
pi@raspberrypi:~ $ vcgencmd get_config int
arm_freq=1500
audio_pwm_mode=514
config_hdmi_boost=5
core_freq=500
core_freq_min=200
disable_commandline_tags=2
disable_l2cache=1
disable_overscan=1
display_hdmi_rotate=-1
display_lcd_rotate=-1
dvfs=2
enable_gic=1
force_eeprom_read=1
force_pwm_open=1
framebuffer_ignore_alpha=1
framebuffer_swap=1
gpu_freq=500
gpu_freq_min=250
init_uart_clock=0x2dc6c00
lcd_framerate=60
mask_gpu_interrupt0=1024
mask_gpu_interrupt1=0x10000
max_framebuffers=2
over_voltage_avs=-36250
pause_burst_frames=1
program_serial_random=1
total_mem=4096
hdmi_force_cec_address:0=65535
hdmi_force_cec_address:1=65535
hdmi_group:0=2
hdmi_mode:0=82
hdmi_pixel_freq_limit:0=0x11e1a300
hdmi_pixel_freq_limit:1=0x11e1a300
boras-pl commented 3 years ago

I am not so familiar with this technology, however there are some open issues in RPi4 that may or may not affect this issue https://github.com/raspberrypi/firmware/issues/1154. Has this ever worked on this platform? As I remember dispmanx worked fine on RPi3 that was borrowed by me long time ago, but I can't recall anything about RPi4.

midwan commented 3 years ago

I've been testing it on my RPI4 and Pi400 for quite a long time now, and I haven't run into this issue. Maybe it's a difference in configuration or setup, I'm not sure... But I've tested it both under 64-bit Manjaro and RPI OS on the Pi4.

boras-pl commented 3 years ago

I checked a little bit older RaspiOS link with older kernel - 5.4.83-v7l+ This time I neither touched anything (except of overscan) in raspi-config nor upgraded any packages. I followed your wiki step by step. I installed all packages from the 'Minimal requirements' section. I recompiled SDL2 from head, ttf and image packages as previously. I needed to install some missing packages that weren't mentioned in wiki (please consider updating wiki if I didn't messed anything):

and some needed by ./amiberry runtime:

Instead of compiling Amiberry, I decided to check your release link

Results:

Conclusions:

To be honest, I don't need this working for anything, and probably most people do not use dispmanx in KMSDRM. Even the Recalbox project uses the SDL2 variant - link. I'm just interested in what happens here. In such cases I always recall a meme about debugging of negligible bugs: picture

boras-pl commented 3 years ago

Some time ago I was dealing with HDMI timings to get a perfect synchronization with Amiga PAL emulation and 50Hz on my display. This settings ensure that scrolls are smooth as much as possible:

hdmi_group=2
hdmi_mode=87
hdmi_timings=1920 0 538 46 152 1080 0 3 5 32 0 0 0 50 0 148500000 3

I thought, "Why not give it a try this time?" And guess what? It works :) I worked the problem around again. The issue must be a trifle in synchronization between Amiga 50Hz and display 50Hz. Something what is sensitive to subtle timing differencies.

midwan commented 3 years ago

@boras-pl it might be related to your monitor's refresh rate also? VSync will match that exactly, and if for example it was not exactly 50Hz, you'd lose 1 in every 2 frames. Just a theory, of course :)