patriciogonzalezvivo / glslViewer

Console-based GLSL Sandbox for 2D/3D shaders
BSD 3-Clause "New" or "Revised" License
4.7k stars 351 forks source link

Support for GL (Full KMS) or GL (Fake KMS) on RaspberryPi #135

Closed evanmtp closed 3 years ago

evanmtp commented 5 years ago

When attempting to run glslViewer on a Raspberry Pi 3 B+ running Raspbian 9 (stretch), it throws the following error:

glslViewer: src/app.cpp:493: glm::ivec2 getScreenSize(): Assertion `success >= 0' failed.
Aborted

At least one other user experienced this issue back in 2017, as reported here: https://www.raspberrypi.org/forums/viewtopic.php?t=179373

patriciogonzalezvivo commented 5 years ago

What version of GlslViewer are you running? It's compiled by source? are you in master?

evanmtp commented 5 years ago

This result came from GlslViewer version 1.5, which I installed via

sudo apt-get install glslviewer

I also tried building it from source, but make threw an error - seemed to be unhappy about the use of abs in main.cpp, if I remember correctly... I can post the output in a second.

patriciogonzalezvivo commented 5 years ago

Seams you are running an old version. I have to get in touch w the people of Raspbian. In the mid time I can help you to compile by source. Just send me the error message.

evanmtp commented 5 years ago

Amazing, thank you! Here's what I get in the console after cloning the repo and running make in ~/glslViewer:

pi@raspberrypi:~/glslViewer $ make
Platform Raspbian GNU/Linux 9 (stretch)
src/window.o
g++ -Wall -O3 -std=c++11 -fpermissive -DGLM_FORCE_CXX98 -DPLATFORM_RPI -Isrc/ -Iinclude/ -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -g -c src/window.cpp -o src/window.o -Wno-deprecated-declarations
src/main.o
g++ -Wall -O3 -std=c++11 -fpermissive -DGLM_FORCE_CXX98 -DPLATFORM_RPI -Isrc/ -Iinclude/ -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -g -c src/main.cpp -o src/main.o -Wno-deprecated-declarations
src/sandbox.o
g++ -Wall -O3 -std=c++11 -fpermissive -DGLM_FORCE_CXX98 -DPLATFORM_RPI -Isrc/ -Iinclude/ -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -g -c src/sandbox.cpp -o src/sandbox.o -Wno-deprecated-declarations
src/sandbox.cpp: In member function ‘void Sandbox::onMouseDrag(float, float, int)’:
src/sandbox.cpp:1004:22: error: call of overloaded ‘abs(float&)’ is ambiguous
         if (abs(vel_x) < 50.0 && abs(vel_y) < 50.0) {
                      ^
In file included from /usr/include/c++/6/cstdlib:75:0,
                 from /usr/include/c++/6/ext/string_conversions.h:41,
                 from /usr/include/c++/6/bits/basic_string.h:5417,
                 from /usr/include/c++/6/string:52,
                 from src/gl/shader.h:3,
                 from src/sandbox.h:3,
                 from src/sandbox.cpp:1:
/usr/include/stdlib.h:735:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/include/c++/6/ext/string_conversions.h:41:0,
                 from /usr/include/c++/6/bits/basic_string.h:5417,
                 from /usr/include/c++/6/string:52,
                 from src/gl/shader.h:3,
                 from src/sandbox.h:3,
                 from src/sandbox.cpp:1:
/usr/include/c++/6/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^~~
/usr/include/c++/6/cstdlib:172:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^~~
src/sandbox.cpp:1004:43: error: call of overloaded ‘abs(float&)’ is ambiguous
         if (abs(vel_x) < 50.0 && abs(vel_y) < 50.0) {
                                           ^
In file included from /usr/include/c++/6/cstdlib:75:0,
                 from /usr/include/c++/6/ext/string_conversions.h:41,
                 from /usr/include/c++/6/bits/basic_string.h:5417,
                 from /usr/include/c++/6/string:52,
                 from src/gl/shader.h:3,
                 from src/sandbox.h:3,
                 from src/sandbox.cpp:1:
/usr/include/stdlib.h:735:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/include/c++/6/ext/string_conversions.h:41:0,
                 from /usr/include/c++/6/bits/basic_string.h:5417,
                 from /usr/include/c++/6/string:52,
                 from src/gl/shader.h:3,
                 from src/sandbox.h:3,
                 from src/sandbox.cpp:1:
/usr/include/c++/6/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^~~
/usr/include/c++/6/cstdlib:172:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^~~
Makefile:60: recipe for target 'src/sandbox.o' failed
make: *** [src/sandbox.o] Error 1

Edit: as you can see, turns out the issue was in sandbox.cpp, not main.cpp.

patriciogonzalezvivo commented 5 years ago

Oh wow... that's weird... abs() it's pretty standard. can you do make clean and then make again

evanmtp commented 5 years ago

Yes, it does seem strange. I'm afraid that even after make clean I'm getting the same errors.

Not sure if it's a clue, but I see that it's complaining that abs() is overloaded:

src/sandbox.cpp:1004:22: error: call of overloaded ‘abs(float&)’ is ambiguous

evanmtp commented 5 years ago

I looked into this a bit more, and the issue seems to be with the GL driver, as set in raspi-config. When the driver is set to GL (Full KMS), glslViewer fails to launch with the error I posted above. When it's set to GL (Fake KMS), glslViewer fails to launch with the following error: * failed to add service - already in use?. Using the Legacy driver, glslViewer launches succesfully.

raspi_gl_config
markusobi commented 5 years ago

@patriciogonzalezvivo Will there be support for GL (Full KMS) or GL (Fake KMS) ?

patriciogonzalezvivo commented 5 years ago

Not for the moment.

willstall commented 5 years ago

https://www.raspberrypi.org/forums/viewtopic.php?t=222264

Just leaving this thread in case it helps at all.

patriciogonzalezvivo commented 5 years ago

I just finish implementing a GBM/DRM for raspberry pi, wonder if this issue is solve by compiling the lastest master version using:

make DRIVERS=gbm

More information here: https://github.com/patriciogonzalezvivo/glslViewer/wiki/Compiling-GlslViewer

patriciogonzalezvivo commented 4 years ago

@evanmtp do you mind confirming that this solve the issue? I would like to close it

evanmtp commented 4 years ago

I would love to, but unfortunately don't have access to my Pi at the moment. Next time I have it on hand, I'll give it a try. Thanks for the patch!

wraybowling commented 4 years ago

I'm putting a Pi Zero through the paces. I can so far confirm that I got the success >= 0' error when building 809ea22f4bd4a94f1d29a4d4311087a3b3e9757e on Raspbian Stretch. Switching to the Legacy driver via raspi-config works.

markusobi commented 4 years ago

I tried compiling and running on a Raspberry Pi 3B+ with GL (Fake KMS) OpenGL. I got several compile errors regarding missing header files so I installed the following packages: sudo apt install libgbm-dev libdrm-dev libegl-dev libgles2-mesa-dev

I compiled via make DRIVER=gbm. It did compile, but crashed at runtime:

$ ./bin/glslViewer
Unable to get DRM resources
Unable to get DRM resources
Failed to create EGL surface! Error: A NativeWindowType argument does not refer to a valid native window.
Segmentation fault

I noticed that the makefile defines -DPLATFORM_RPI4 when compiling with DRIVER=gbm, so I tried again with -DPLATFORM_RPI instead, but this had the same result.

patriciogonzalezvivo commented 4 years ago

I think you forgot to read this and make sure on your /boot/config.txt you have the following lines present and uncommented:

dtoverlay=vc4-fkms-v3d
max_framebuffers=2
hdmi_force_hotplug=1
markusobi commented 4 years ago

I think you forgot to read this and make sure on your /boot/config.txt you have the following lines present and uncommented:

dtoverlay=vc4-fkms-v3d
max_framebuffers=2
hdmi_force_hotplug=1

I did add this to /boot/config.txt (I discovered the compile instructions just before writing my above post). My goal is to make a fully configurable video source with a raspberry pi. I already got the resolution change (without reboot) going using xrandr, but xrandr needs the vc4-fkms-v3d driver. I also want to use the awesome glslViewer, which I currently only got to work with the legacy driver on the raspberry pi. I have quite some experience in C++ - if there is anything that I can do to help (i.e. providing information or debugging), let me know.

patriciogonzalezvivo commented 3 years ago

By reading your last message seams you are trying to run GlslViewer from a X11 windows manager. is that right?

markusobi commented 3 years ago

By reading your last message seams you are trying to run GlslViewer from a X11 windows manager. is that right?

Well yes, but isn't X11 the default window manager on raspberry pi? I'm using the default setup from raspbian, which is LXDE+OpenBox+X11 from what I've read. All I changed was graphics driver to vc4-fkms-v3d (Fake KMS graphics driver). Is the glslViewer that works with the legacy driver bypassing X11?

patriciogonzalezvivo commented 3 years ago

There is two ways to compile GlslViewer for Raspberry Pi. For X11 or with out X11. The first one use GLFW drivers. That libs takes care of everything. For non-X11 there is legacy (pre RaspberryPi 4 or legacy) both ways runs GlslViewer directly from the console. If X11 is running that produce the error message you were describing.

Here you can find more documentation about it: https://github.com/patriciogonzalezvivo/glslViewer/wiki/Compiling

I'm going to close this issue. I have tried it on Rpi4 and Rpi3 with and without X11 and the three versions seams to compile and work correctly.

If you have other issues or questions you can open this issue again or create a new one. All the best!

Patricio

VinaiRachakonda commented 3 years ago

Hi! Apologies for opening up an old issue. I recently tried all the compilation methods on my Rpi 4 and I get the same error as above. Any help would be greatly appreciated.

$ ./bin/glslViewer
Unable to get DRM resources
Unable to get DRM resources
Failed to create EGL surface! Error: A NativeWindowType argument does not refer to a valid native window.
Segmentation fault
patriciogonzalezvivo commented 3 years ago

Hi @VinaiRachakonda, do you mind sharing a bit of context? Like:

Thanks

VinaiRachakonda commented 3 years ago

Hi @patriciogonzalezvivo

I am on a Raspberry Pi 4 with Raspbian GNU/Linux 10 installed.

I am running glslViewer from the console directly with the fake kms driver installed. I am not quite sure how to use glslViewer from a window manager.

VinaiRachakonda commented 3 years ago

Hi just wanted to update this. I read this issue #198 and I better understand the terms. I currently compiled with fakekms drivers and now ran glslViewer in headless mode. Now when I try to run the ./bin/ I get the following

Unable to get DRM resources
Unable to get DRM resources
* failed to add service - already in use.

In fact, when I compile with glfw and run with X11 I get the same error as well. Any ideas on what to do? I have added all necessary config variables per the compilation instructions.

Thank you for your time!

VinaiRachakonda commented 3 years ago

For reference, I am running glslViewer with the Openframe project