sony / flutter-embedded-linux

Embedded Linux embedding for Flutter
BSD 3-Clause "New" or "Revised" License
1.22k stars 129 forks source link

[Feature Request] Specify DRM connector to use for DRM backend #424

Closed barribarrier closed 2 months ago

barribarrier commented 2 months ago

Hello,

First of all, thank you for the continued development and maintenance of the flutter-embedded-linux project. I’ve been using the Wayland backend and have been very happy with it.

Now, I’m planning to switch to the DRM backend and have a feature request regarding this. Currently, the very first DRM connector is automatically selected https://github.com/sony/flutter-embedded-linux/blob/63b57ca74991ce6782736a1adb8b63928797272f/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc#L110

In my specific use case, this behavior is not ideal because I need to specify a particular DRM connector, such as HDMI-A-1, rather than the default eDP-1.

Would it be possible to add a feature that allows users to specify which DRM connector should be used for rendering? Maybe a new environment variable FLUTTER_DRM_CONNECTOR just like the current FLUTTER_DRM_DEVICE. My knowledge in C is very limited, so implementing this change myself is challenging.

Just for reference, how MPV does it: https://mpv.io/manual/stable/#video-output-drivers-drm-connector

HidenoriMatsubayashi commented 2 months ago

Would it be possible to add a feature that allows users to specify which DRM connector should be used for rendering? Maybe a new environment variable FLUTTER_DRM_CONNECTOR just like the current FLUTTER_DRM_DEVICE.

Yes. Thanks for the proposal.

My knowledge in C is very limited, so implementing this change myself is challenging.

I can review your change :)

barribarrier commented 2 months ago

Sorry for tagging again. Deleted my previous comment and reposting with personal information removed

@HidenoriMatsubayashi Thanks. I'll try doing it.

But, I'm having a problem running the DRM backend on my host PC. I switch to console (CTRL+ALT+Fx) to run the binary but it results in a segmentation fault. I've attached the valgrind log below.

My flutter-elinux is on 3.24.3 branch. I'm on Ubuntu 24.04 (x64) I have only 1 monitor connected.

The example app binary is built with this command:

flutter-elinux build elinux --target-backend-type gbm --debug

How I ran it:

FLUTTER_LOG_LEVELS=TRACE ./example --bundle=./

Crash log:

==331207== Memcheck, a memory error detector
==331207== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==331207== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==331207== Command: ./sample --bundle=./
==331207== 
[WARNING][CreateRenderSurface(158)] FLUTTER_DRM_DEVICE is not set, use /dev/dri/card0
[INFO][ConfigureDisplay(77)] resolution: 3440x1440
[DEBUG][FindEncoder(129)] Using encoder id 94
[ERROR][CreateGbmSurface(205)] Failed to create the gbm surface.
[ERROR][CreateRenderSurface(168)] Failed to create the native window (/dev/dri/card0).
==331207== Warning: invalid file descriptor -100 in syscall close()
==331207== Warning: invalid file descriptor -100 in syscall close()
../../flutter/third_party/dart/runtime/vm/virtual_memory_posix.cc: 69: error: mmap failed: 22 (Invalid argument)
version=3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "linux_x64"
pid=331207, thread=331207, isolate_group=vm-isolate(0xb461260), isolate=vm-isolate(0xb469590)
os=linux, arch=x64, comp=no, sim=no
isolate_instructions=9463c20, vm_instructions=9463c20
fp=1ffeffbf50, sp=1ffeffbe20, pc=922a84c
  pc 0x000000000922a84c fp 0x0000001ffeffbf50 /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so+0x493784c
-- End of DumpStackTrace
=== Crash occurred when compiling unknown function in unoptimized JIT mode in unknown pass
=== Flow Graph not available
==331207== 
==331207== Process terminating with default action of signal 6 (SIGABRT)
==331207==    at 0x9ECCB1C: __pthread_kill_implementation (pthread_kill.c:44)
==331207==    by 0x9ECCB1C: __pthread_kill_internal (pthread_kill.c:78)
==331207==    by 0x9ECCB1C: pthread_kill@@GLIBC_2.34 (pthread_kill.c:89)
==331207==    by 0x9E7326D: raise (raise.c:26)
==331207==    by 0x9E568FE: abort (abort.c:79)
==331207==    by 0x90B08A5: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x92B99E7: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x92B9831: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x92D7A04: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x92D86D2: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x92D8D51: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x92CC164: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x91A88BC: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207==    by 0x91CD3B7: ??? (in /home/ad/Documents/example/build/elinux/x64/debug/bundle/lib/libflutter_engine.so)
==331207== 
==331207== HEAP SUMMARY:
==331207==     in use at exit: 809,477 bytes in 7,999 blocks
==331207==   total heap usage: 42,226 allocs, 34,227 frees, 5,587,869 bytes allocated
==331207== 
==331207== LEAK SUMMARY:
==331207==    definitely lost: 112 bytes in 1 blocks
==331207==    indirectly lost: 0 bytes in 0 blocks
==331207==      possibly lost: 8,016 bytes in 11 blocks
==331207==    still reachable: 799,333 bytes in 7,966 blocks
==331207==                       of which reachable via heuristic:
==331207==                         newarray           : 136,552 bytes in 315 blocks
==331207==         suppressed: 0 bytes in 0 blocks
==331207== Rerun with --leak-check=full to see details of leaked memory
==331207== 
==331207== For lists of detected and suppressed errors, rerun with: -s
==331207== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

I ran mpv --vo=drm 1.mkv and it successfully ran and rendered MPV using DRM. Is there something else I have to do?

barribarrier commented 2 months ago

weston --backend=drm works too. Looking at wetson, mpv sources, I can't detect any obvious issue with gbm surface creation.

These errors are weird:

==331207== Warning: invalid file descriptor -100 in syscall close()
==331207== Warning: invalid file descriptor -100 in syscall close()
../../flutter/third_party/dart/runtime/vm/virtual_memory_posix.cc: 69: error: mmap failed: 22 (Invalid argument)
barribarrier commented 2 months ago

Found the issue here: https://forums.developer.nvidia.com/t/gbm-surface-create-fails-if-flags-0/279951 Setting flags to 0 works. No more segmentation fault.