A perfunctory post about processors and Peter’s Penguins Puzzle
Buy one processor, get 48 free!
As well as an ARM processor, the Raspberry Pi’s system on a chip (SoC) also contains 48 extra processors optimised for the calculations involved in 3d graphics.
As an example of how to use these processors on the Raspberry Pi, Peter de Rivaz (an old and revoltingly clever friend of ours, who has been doing Raspberry Pi development work in his spare time) has written a charityware 3d physics puzzler, using them to draw dynamic clouds, shadows, water reflections, and lots and lots of penguins.
Visit penguinspuzzle.appspot.com for instructions on installing this game on the Raspian “wheezy” OS, or to play a WebGL version in your browser if you haven’t got a Pi yet.
The source code is freely available on github if you want to have a go at writing your own 3d game. If you do, let us know about it – we’d love to see what you come up with!
oh no I have just been playing this at work in the browser! It has the addictiveness of Angry Birds about and I just got out of Angry Birds re-hab…… Noooooooooo ;)
any specifics on what those other processors are called?
I presume it’s the GPU they are talking about…
indeed they are but its nice to know what they are, given that the number of component parts that make up the gpu are mentioned. I’d also like to mention that am not after a complete manual, just possibly a brief description on what each processor does and how they interact with each other. would make a nice article for the magpi :)
it *would* make a very nice article for the Magpi. Get on it!
As I understand it, each GPU core is a very limited computer that receives a small amount of data (usually enough info to process a single vertex or a single pixel), runs a program to perform some transformation on that data, then returns output. Most shader programs, for example, receive interpolated data about some point on a triangle, and they return the color that pixel needs to be onscreen (perhaps by doing lighting calculations, etc.)
The key is that there’s strength in numbers. 48 cores means that, at peak operation, the GPU can process 48 vertices (or 48 pixels or what have you) in parallel. The cores also have machine instructions that are designed to make 3D calculations (specifically linear algebra, trig and matrix transformations) more optimized than the ARM CPU.
Utilizing the cores requires one to compile a shader program. I’m fuzzy on the details here, but I *believe* this works by passing standard shader code as a string (in one of a handful of languages) to the GPU driver, which compiles it to run on the cores that GPU is utilizing. In order to support, say, the OpenGL ES 2.0 standard, the GPU simply needs to be able to compile that code to run on its own cores. Once the program is loaded, you feed the driver your data, which in turn feeds it to the cores in parallel and then does something (hopefully meaningful) with the result.
This is pretty general and applies to any GPU out there. I don’t know how the R-Pi’s pipeline works exactly, as it’s bound to have some edge cases that are quite different. I also couldn’t tell you how this works for movie decoding; certainly the GPU is doing something fancy to utilize its 48 cores for that purpose as well.
thanks for that.
so basically the ‘processors’ are just the cores for the gpu then.
Not all the cores are the same – there are two general purpose VPU’s, 12 QPU’s (for 3D)and a load of other dedicated processors for things like H264 encode/decode, ISP (camera) processing etc.
thanks for sharing the info! Just asking, is there a way to optimise the usage of the processors when using OpenGL shaders, say, using n fragment shaders and m vertex shaders?
No idea, but the 3D code is pretty optimised already, and probably does some stuff like that automagically- but I am not a 3D expert.
Hmmm … starting penguinspuzzle locks up my Raspi: the sea is still moving, but most lights on the Raspi are off, no keyboard/mouse reaction and no more SSH/ping …
Are you overclocked? Try disabling if you are.
This works the GPU pretty hard, so may show up limitations of your power supply. What memory split are you running?
I was overclocking, but not anymore. Still locking.
Memory split is 128 / 128 (because of omxplayer) … maybe too little RAM for the penguins?
Power supply should be OK: 7805. Current normally at 0.40A. With penguinspuzzle goes up for a few seconds, and then to 0.25A.
128M split is fine. Sounds like power supply to me. The current drops because the chip crashes after the voltage drops.
As an experiment, add:
If that fixes it, it is almost certainly power supply.
Even rebooting didn’t help (got stuck), so I rewrote the SD card, and … penguinspuzzle is running! Great game!
Hmmm … a long shot:
1) updated & upgrade Raspbian is stable
2) … then adding new firmware and/or penguinspuzzle halts the boot after the Rasp logo.
Peter de Rivaz
I am sorry to hear that. I think Dom is right and it is a problem with the power supply. I have just tested on mine and it works fine if I power it via a USB slot on my PC, but fails in the same way you describe if I power it from a mobile phone adapter.
I’ll add a note to the troubleshooting section.
Maybe it’s just me, when I play the game in the browser (Firefox 15) for OpenSuse 12.2, I see everything upside down and not at all like the screen shot above.
I’ve installed it on Raspbian, updated today to the very latest everything, and it refuses to run. Granted I’m runing (or trying to) in a VNC session, so that might not be helping. I’m in the basement and the HDMI is upstairs and I’m not connected to it.
In a terminal session, when I run the /usr/bin/X11/pengionspuzzle I get a brief pause, then an assertion fail at line 210 of penguinspuzzle.c. The assertion is “state->surface != ((EGLSurface)0)”.
I installed using “sudo apt-get update” followed by “sudo apt-get install penguinspuzzle”.
No errors or warnings during the install.
It needs a 128M or 192M memory split.
OpenGL won’t remote over VNC.
thanks. I’ll try that memory split – I’m 224/32 at the moment. I’ll have to get permission to use the HDMI as well I suspect!
Replying to self.
If I hit the Q key, the image reverses and I’ve got a penguin on top of the ice again! (In Firefox.)
penguinspuzzle: audio.c: 120: audioplay_create: Assertion `st->audio_render != (( void *)0)’ failed
Now, I know what the code means, what I don’t know is why the assertion is failing.
Any ideas what I should install and surely I’m not the only one with this problem…
Does /opt/vc/src/hello_pi/hello_audio work?
Hi Dom, hello_audio doesn’t build. I’m running the official wheezy.
/usr/bin/ld: cannot find -lilclient
Ooops. I tried “make” instead of “./rebuild.sh”
It builds now. Sorry.
However, same error when I run “hello_audio.bin”.
Probably got a mismatched set of firmware files.
sudo apt-get update && sudo apt-get upgrade
may fix it. If not, try rpi-udpate.
If not, try a clean raspbian/wheezy image.
And make sure you are on 128M or 192M memory split.
Got the same problem compiling the video.c file as the guys had with the audio ones. This worked OK in Squeeze, so what got lost? :-)
/usr/bin/ld: cannot find -lilclient
collect2: ld returned 1 exit status
make: *** [hello_video.bin] Error 1
It appears that memory split was the issue.
Thanks for your help.
Peter de Rivaz
I have just tested with some different memory splits.
On 224 split you get the error:
penguinspuzzle: penguinspuzzle.c:210: init_ogl: Assertion `state->surface != ((EGL_Surface)0)’ failed.
On 240 split you get the error:
penguinspuzzle: audio.c:120: audioplay_create: Assertion `st->audio_render != ((void *)0)’ failed.
Works on 192 and 128 split.
You can change the split to 192 by
sudo cp arm192_start.elf start.elf
I’ll add these notes to the Raspberry Pi section of the webpage – thanks for the testing!
William H. Bell
Other than particular applications, how close it the X driver which uses GPU acceleration?
Thanks and best regards, Will
I tried to run penguinzpuzzle and got this message:
error while loading shared libraries: libGLESv2.so: cannot open shared object file: No such file or directory
Peter de Rivaz
Which OS are you using?
The libGLESv2.so is a shared library file that should be found in the directory /opt/vc/lib
Do you have this file in that directory?
Do the normal 3d demos work for you?
Does “sudo penguinspuzzle” help?
Peter de Rivaz
libGLESv2.so should be present in /opt/vc/lib
The OS is told about the location of these libraries by the file /etc/ld.so.conf.d/00-vmcs.conf which should have a line saying /opt/vc/lib
You can test which libraries are known about by using
sudo ldconfig -v | more
This should mention that it is searching the /opt/vc/lib directory and should find the libGLESv2.so file
make sure /etc/ld.so.conf.d/ contains that contains /opt/vc/lib/
Did you spell it with an s, or with a z as in the comment I’m responding to here?
Sorry. I spelled with “s”. But it worked fine after I typed:
sudo apt-get update
I had to update the system for other process. And it makes the game run fine too.
I am running the Raspbian “wheezy” OS (dated: 2012-08-16)
Wow, webGL sure has advanced. At this rate, not only will you not need plug ins but all your games will be in browser!
Surely Liz, you could have put at least one extra ‘P’ in the original post’s title? There is a little two letter word that springs to mind. ;-)
The game’s great, though I’ve only played online so far.
Unfortunately I get the error:
* failed to open vchiq instance
Nevermind, still an excellent bit of work!
this look like opensource project, do you have tutorials how change project.
I missing something here or I’m just being plain thick (it does happen!), I just cannot find the link to the online version of the game. Can someone enlighten me please?
OK sussed it. It was bloomin’ IE8 not displaying the webpage correctly. I didn’t notice the yellow exclamation mark in the bottom left corner of Internet Explorer saying the page hadn’t loaded correctly. Open the page using Chrome and it works fine. Doh!
I love this game! I got through all the solved levels… addictive!
Now has anyone had any luck with the unsolved levels?
Hmmm… It’s a great game, and runs very well on my Pi! However, whenever I close it with the escape key, it files a random command from my history into the console (once it started X, REstarted X, and opened raspi-config without me typing anything!). This happens both with the terminal and LXTerminal.
Comments are closed