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.

Penguins Puzzle screengrab

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!

 

46 comments

Avatar

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 ;)

Avatar

any specifics on what those other processors are called?

Avatar

I presume it’s the GPU they are talking about…

Avatar

Exactly. :)

Avatar

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 :)

Avatar

it *would* make a very nice article for the Magpi. Get on it!

Avatar

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.

Avatar

thanks for that.

so basically the ‘processors’ are just the cores for the gpu then.

Avatar

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.

Avatar

James,
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?

Avatar

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.

Avatar

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 …

Avatar

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?

Avatar

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.

Avatar

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:
arm_freq=500
gpu_freq=150
If that fixes it, it is almost certainly power supply.

Avatar

Even rebooting didn’t help (got stuck), so I rewrote the SD card, and … penguinspuzzle is running! Great game!

Avatar

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.

Avatar

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.

Avatar

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.

Cheers,
Norm.

Avatar

It needs a 128M or 192M memory split.
OpenGL won’t remote over VNC.

Avatar

Hi Dom,

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!

Cheers,
Norm.

Avatar

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.)

Cheers,
Norm.

Avatar

Oh dear:

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…

Avatar

Does /opt/vc/src/hello_pi/hello_audio work?

Avatar

Hi Dom, hello_audio doesn’t build. I’m running the official wheezy.
/usr/bin/ld: cannot find -lilclient

Avatar

Ooops. I tried “make” instead of “./rebuild.sh”
It builds now. Sorry.

However, same error when I run “hello_audio.bin”.

Avatar

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.

Avatar

And make sure you are on 128M or 192M memory split.

Avatar

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

Avatar

It appears that memory split was the issue.

Thanks for your help.

Avatar

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
cd /boot
sudo cp arm192_start.elf start.elf
sudo reboot

I’ll add these notes to the Raspberry Pi section of the webpage – thanks for the testing!

Avatar

Other than particular applications, how close it the X driver which uses GPU acceleration?
Thanks and best regards, Will

Avatar

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

Avatar

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?
e.g. /opt/vc/src/hello_pi/hello_triangle/hello_triangle.bin?

Does “sudo penguinspuzzle” help?

Avatar

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

Avatar

Possibilities:
make sure /etc/ld.so.conf.d/ contains that contains /opt/vc/lib/
sudo ldconfig
LD_LIBRARY_PATH=/opt/vc/lib penguinspuzzle

Avatar

Did you spell it with an s, or with a z as in the comment I’m responding to here?

Avatar

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)

Avatar

Wow, webGL sure has advanced. At this rate, not only will you not need plug ins but all your games will be in browser!

Avatar

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.

Avatar

Unfortunately I get the error:
* failed to open vchiq instance

Nevermind, still an excellent bit of work!

Avatar

Excellent project.

this look like opensource project, do you have tutorials how change project.

http://www.instalki-download.pl

Avatar

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?

Thanks,

Thicky Kev

Avatar

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!

Avatar

I love this game! I got through all the solved levels… addictive!

Now has anyone had any luck with the unsolved levels?

Avatar

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.

Leave a Comment

Comments are closed