raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming
http://www.raylib.com
zlib License
21.65k stars 2.19k forks source link

[core] Failed to initialize Graphic Device on RPI4 native mode #2259

Closed enigma42 closed 2 years ago

enigma42 commented 2 years ago

Hi .. new to raylib. want to use it as a replacement for OpenVG. Built both 4.0 and 4.1-dev branches, SRC and EXAMPLES without issues. but examples cannot find graphics card ... thought I followed the install here

 https://github.com/raysan5/raylib/wiki/Working-on-Raspberry-Pi

Hardware: RPi4 800x400 LCD Touchscreen display

Software: fresh install of RPI4 (Raspberry Pi OS Lite) running headless (no HDMI) set static ip enabled SSH server in config.txt, commented out #dtoverlay=vc4-fkms-v3d (can't get display to work without doing this)

performed following sudo apt-get install libdrm-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev git clone https://github.com/raysan5/raylib.git cd raylib/src make PLATFORM=PLATFORM_DRM cd ~/raylib/examples make PLATFORM=PLATFORM_DRM

Tried running an example and got this error

pi@raspberrypi:~/raylib-master/examples/shapes $ ./shapes_basic_shapes INFO: Initializing raylib 4.0 INFO: Supported raylib modules: INFO: > rcore:..... loaded (mandatory) INFO: > rlgl:...... loaded (mandatory) INFO: > rshapes:... loaded (optional) INFO: > rtextures:. loaded (optional) INFO: > rtext:..... loaded (optional) INFO: > rmodels:... loaded (optional) INFO: > raudio:.... loaded (optional) INFO: DISPLAY: No graphic card set, trying platform-gpu-card INFO: DISPLAY: Failed to open platform-gpu-card, trying card1 INFO: DISPLAY: Failed to open graphic card1, trying card0 WARNING: DISPLAY: Failed to open graphic card FATAL: Failed to initialize Graphic Device

What did I do wrong??

Thanks in advance ...

enigma42 commented 2 years ago

An update... I went back to buster-lite release (May 7 2021) and it works ... must be something in bullseye (Oct 30 2021) ...

MikeGodinez commented 2 years ago

Unrelated: there s a | in rcore.c line 6583 that should almost certainly be a || .

My environment: Rpi3 Rpi OS 11 Bullseye Lite HDMI monitor, mirrored to small TFT screen connected on 40-pin header [1].

It looks like if I use PLATFORM_DRM, as suggested by [2], then rcore.c looks for stuff in the /dev/dri folder, and this folder only appears when /boot/config.txt contains a line with dtoverlay=vc4-fkms-v3d . [3] (Is it different with Rpi OS Buster on an Rpi4 ?)

Aside: after putting that line into /boot/config.txt , I got a different error: WARNING: DISPLAY: Failed to find a suitable DRM connector mode . Was probably something to do with the TFT screen configuration. In utils.c, I raised logTypeLevel to LOG_TRACE, and found I had only two DRM modes: 1920x320@59fps, and 480x320@59fps, and rcore.c will only accept a DRM mode with every number (width, height, framerate) equal or higher than the values passed to InitWindow() and SetTargetFPS(). Furthermore, SetTargetFPS() has to be called before InitWindow(), otherwise it default to 60fps and doesn't work for me, but the example core_basic_window.c calls SetTargetFPS() after.

[1] https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi/easy-install-2 [2] https://github.com/raysan5/raylib/issues/2229 [3] https://raspberrypi.stackexchange.com/questions/116507/open-dev-dri-card0-no-such-file-or-directory-on-rpi4

raysan5 commented 2 years ago

@MikeGodinez Thanks for pointing the bug, just reviewed it.

Thanks for investigating this issue. It seems the framerate shouldn't be considered for the display. PLATFORM_DRM code was contributed by an user some time ago and it probably needs some review.

Rasmushauschild commented 2 years ago

I'm getting a similar error as @enigma42 when trying to run any example on RPI4 with a composite display connected:

INFO: Initializing raylib 4.1-dev
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: No graphic card set, trying platform-gpu-card
WARNING: DISPLAY: No suitable DRM connector found
FATAL: Failed to initialize Graphic Device

I've tested both full Raspbian and Raspbian Lite with the same result. It works just fine with HDMI in both cases though - Is this an issue specifically with the RPI4?

raysan5 commented 2 years ago

I tried running latest RPI OS Bullseye on RPI Zero W with Full KMS driver and raylib compiled as PLATFORM_DRM.

I'm using the HDMI output and it seems the display is correctly detected but it fails on GBM framebuffer swap.

Here it is the related issue: https://github.com/raysan5/raylib/issues/2439

Crydsch commented 2 years ago

Hey, I have an RPI4 and a TFT display similar to @MikeGodinez mounted on the GPIO pins and I can reproduce this bug.

Hardware: RPI4 B 3.5" 480x320 TFT Touchscreen Display (MPI3501,ILI9486)

Software: Raspberry PI OS Lite Bullseye (64bit) configured hostname, ssh server in raspi-imager running headless (only display on gpio pins and access via ssh) installed packages libdrm-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev

Initially I had the same error messages.

It seems these displays on GPIO communicate with drivers such as ILI9486. I found no way to directly render to it. You have to install the driver for your specific display. This seems to "hijack" the HDMI connectors and render to them using the GPU, then use
frame buffer copy to transfer the pixeldata to the display. This was all configured when installing the correct driver.

My working /boot/config.txt after the driver installation ``` # ... [pi4] # Enable DRM VC4 V3D driver on top of the dispmanx display stack dtoverlay=vc4-fkms-v3d max_framebuffers=2 [all] hdmi_force_hotplug=1 dtparam=i2c_arm=on dtparam=spi=on enable_uart=1 dtoverlay=tft35a:rotate=90 hdmi_group=2 hdmi_mode=1 hdmi_mode=87 hdmi_cvt 480 320 60 6 0 0 0 hdmi_drive=2 ```

You can check your DRM connectors and see this connector change with modetest. sudo apt install libdrm-test modetest -c -c to just show connectors

This showed connected HDMI ports on my device (even though there is nothing connected). The modes list a 480x320 resolution, which is exactly my TFT display.

The next problem was the mode selection

INFO: DISPLAY: No graphic card set, trying platform-gpu-card
TRACE: DISPLAY: Connectors found: 1
TRACE: DISPLAY: Connector index 0
TRACE: DISPLAY: Connector modes detected: 1
TRACE: DISPLAY: DRM mode connected
TRACE: DISPLAY: Searching exact connector mode for 480x320@60, selecting an interlaced mode is allowed: no
TRACE: DISPLAY: DRM Mode 0 480x320@59 progressive
TRACE: DISPLAY: No DRM exact matching mode found
TRACE: DISPLAY: Searching nearest connector mode for 480x320@60, selecting an interlaced mode is allowed: no
TRACE: DISPLAY: DRM mode: 0 480x320@59 progressive
TRACE: DISPLAY: DRM mode is too small
TRACE: DISPLAY: Searching exact connector mode for 480x320@60, selecting an interlaced mode is allowed: yes
TRACE: DISPLAY: DRM Mode 0 480x320@59 progressive
TRACE: DISPLAY: No DRM exact matching mode found
TRACE: DISPLAY: Searching nearest connector mode for 480x320@60, selecting an interlaced mode is allowed: yes
TRACE: DISPLAY: DRM mode: 0 480x320@59 progressive
TRACE: DISPLAY: DRM mode is too small
WARNING: DISPLAY: Failed to find a suitable DRM connector mode
FATAL: Failed to initialize Graphic Device

This can be fixed by putting SetTargetFPS(59); before InitWindow(480, 320, "...");. And then it worked!

So the first problem seems hardware specific and requires correct drivers. The second problem is the drm mode selection which as said before should be less strict. And finally the SetTargetFPS and InitWindow ordering needs to be reviewed.

konsumer commented 2 years ago

I am getting same error on a RG351V with demo compiled with PLATFORM_DRM, but I'm not sure how to figure out what capabilities the mali DRM driver is missing that raylib needs.

I am testing on ArkOS, which is (sort of loosely) based on ubuntu-eoan distro.

I did this to install libdrm-test:

sudo -s
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 605C66F00D6C9793
printf "\ndeb http://ftp.us.debian.org/debian bullseye main\n" >> /etc/apt/sources.list
apt update
apt install libdrm-tests

I couldn't get drminfo to compile, due to huge differences with libc6, but I can try to figure it out, if the info would be helpful.

modetest -c

trying to open device 'i915'...failed
trying to open device 'amdgpu'...failed
trying to open device 'radeon'...failed
trying to open device 'nouveau'...failed
trying to open device 'vmwgfx'...failed
trying to open device 'omapdrm'...failed
trying to open device 'exynos'...failed
trying to open device 'tilcdc'...failed
trying to open device 'msm'...failed
trying to open device 'sti'...failed
trying to open device 'tegra'...failed
trying to open device 'imx-drm'...failed
trying to open device 'rockchip'...done
Connectors:
id  encoder status      name        size (mm)   modes   encoders
66  65  connected   DSI-1           52x70       1   65
  modes:
    index name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot
  #0 640x480 60.00 640 744 746 850 480 493 495 500 25500 flags: nhsync, nvsync; type: preferred
  props:
    1 EDID:
        flags: immutable blob
        blobs:

        value:
    2 DPMS:
        flags: enum
        enums: On=0 Standby=1 Suspend=2 Off=3
        value: 0
    49 brightness:
        flags: range
        values: 0 100
        value: 50
    50 contrast:
        flags: range
        values: 0 100
        value: 50
    53 saturation:
        flags: range
        values: 0 100
        value: 50
    54 hue:
        flags: range
        values: 0 100
        value: 50
konsumer commented 2 years ago

Note: I ended up getting it compiled fine for ArkOS on RG351V, in a docker. Main issue was the screensize! core_basic_window runs great at 640x480. Just had to kill emulationstation and run it.

aistico-jhr commented 1 year ago

I had the same issue. The application built with latest raylib for RPi 3B+ was giving the error most of the time. After some bootups the graphics worked, but most of the time not (perhaps failed on 90% of the bootups). I was able to fix this by reverting to the older fkms.

in /boot/config.txt change the line

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d

to

# Enable DRM VC4 V3D driver
dtoverlay=vc4-fkms-v3d

Now the graphics initializes fine every time. I'll try to compare dmesg logs to gain better understanding of the issue.