Sunday, 8 March 2015

Dr. Glitschen's top 5 event at GDC 2015

 GDC 2015 came at end also this year. I Didn't manage to be there, maybe next year. As always most of the videogame industry tech programmers attended and a a lot of promising announcement were done, this is my top five list of the ones worth of mention. Enjoy!

#5 nVidia shield

Nvidia did it again. After the overpriced portable android console, the came up with this console like android device that should be halfway between a android TV box like many other (nexus Tv, fire TV) and a console. Powered by Tegra X1 Gpu, they claim that their GPU is 2.5 faster than a xbox 360 and to demonstrate that they showed a very choppy and low quality demo of borderland. To be fair there was also a quite impressive port of crysis 3, but still looked like a downgrade to the old gen version. It will come with a streaming service that will be able to stream most of PC games form their cloud, the target price is 200$. Personally I think that if you want to break in the console market you need to show some muscle and not came up with a very underpowered system compared to the competitor at a price that is indeed lower, but still a considerable amount of money. I do think that and android based console (a proper one) will have some chance. 

#4 valve and HTC presented their VR technology

Valve also jumped on VR ship, we already knew they were working on a cross vendor sdk. The VIVE (that's the name of the device) comes with tracking device to locate the viewer position and two nunchack-like controller to handle the problem of user interaction. There was a little confusion and disappointment for some misleading suggestion made by HTC about a new Half life game that had to withdraw later on. People that tried it swear that is the best VR headset available, but right now there are so many out there I've lost the count. I'm sure steam core  audience will be the perfect customer for VR and they probably did a good move, It is just I'm bit warm about all this VR thing.

#3 Epic presentation

After last year big announcement (unreal 4 open source and available to everybody for a 20$/month subscription) , coming up with a totally free subscription system was the natural evolution. Now you can subscribe to their website, link you account to their github and you can start to hack in their code!
There was a quiete impressive realtime demo (at least they claim so), a boy and his kite, that shows a 16kmx16km area with graphics details that are beyond imagination.  There was also a discussion about the future of the entertainment industry in general, not only videogames but also cinema, and how VR will change our way to watch a movie, bit unrealistic to my point of view. Let's see if this time they can dethrone unity as mobile engine of choice.

#2 SIMD at insomniac games

This year the GDC was a bit weak on the technical slides especially about graphics, the most interesting stuff were by  imagination technology aimed to push their ray cast api for their mobile GPU. This talk by Andreas Fredriksson one of most interesting, and I am a long time fan of Mike Acton & co and their doctrine about data oriented programming and this talk about how to do modern simd programming use intrinsics just enforces once more that they are right.

#1 Vulkan presentation.

Khronos group and Graham Sellers finally unveils the long awaited OpenGL successor, Vulkan. After almost 25 years OpenGL could be replaced. It is cross vendor standard and I think most of them will soon  provide Vulkan implementation since it should be easier to write drive and maintain them and also we have come to a time in which we need to squeeze more horse power from our videocard using software because adding raw processing power became each generation more difficult. Vulkan itself is not a very new concept, people familiar with console API know what I mean, it is based on the same principle mantle and ps4 graphic library is based on: a low level access to the graphic hardware. So low level that you can directly write your command buffer. The real news is about SPIR-V, a new binary standard for GPU intermediate language that should simplify shader compilation process at a point that it should be  even possible to have a C++ front end for it. Can you Imagine writing shaders in c++ ? full slides here

Sunday, 25 January 2015

Experiment #2 : c++11 multithreaded raytracer

Hello everyone! A few weeks ago I got a read at The C++ Programming Language 4th Edition in order to refresh my knowledge about c++11 , since I'm not using it at work. I was particularly curious about the built-in threading support. I thought that features like packaged task and lambda function, plus applying concept from functional programming paradigm should make relatively easy to make truly cross platform multi-thraded applications. Of course you have less control over it, thing such as lightweight thread or mutex and even set affinity or thread pools, so If you are looking for maximum performance probably they are not optimal. Keep in mind that most of efficiency of a multithreaded application depends on how you design your application...less read-write data is shared across thread means less lock/mutex and less waiting time for you thread to acquire the resource it need. I decided to make a little multithreaded test application and since I've a passion for graphic programmer I decided to go for a multithreaded simple raytracer application, also because is a kind of problem that can be easily it features the following:
  • colored planes and sphere
  • multiple coloured lights
  • shadows
That's it! no specular, no reflections, no texure and no anti-aliasig. They are actually very easy to implement and maybe I will extend the demo in future, but for now I preferred to keep the code lines at minimum in order to be better readable in this post. The ray test routines are word of wisdom from real time collision detection by Christer Ericson.
our simple raytracer output

At first, I implemented a single thead version. To convert in multithread I had literally to had 20 lines more of  code. basically I had to decide what to feed to each thread, my option was to divide the screen in in 2 rows and and a number of columns equal to the half of the number of cores the host cpu has and to feed each portion of screen to a thread. This is not optimal since there can be portions of the screen that are "easy" to compute while other ones require more work. So our bottleneck here is the thread that have to do more raycast than others. A better strategy would be having a pool of thread, and assign each of them a job a fairly little portion of the screen that our main thread will keep feeding them until they are finished. This would have required more work and the use of std::thread , std::packaged_task and std::promise and std::future. My program simply run the code assign a color to the screen buffer in a lambda function, which is given as argument to std::async. We then store an array of futures and we keep  checking whether or not all threads are finished. We don't need any thread synchronization mechanism since most shared structure the thread uses are read only and the only one you write to (the color buffer) is written in separate location by each thread. 
this is the code:

you can find instead the single thread version here

I deliberately used only POD structure with a data oriented approach, so don't criticize my class design.
How does it perform?
Creating a thread have its cost, also the speed depends on how the code is written and on the CPU architecture. Even if you don't have race condition an synchronization issues, your algorithm could spent most of the time fetching and writing data from RAM that is very slow compared to cache.
This is an histogram of the perfomance of single thread vs multithread algorithm tested on my cpu, an AMD FX-8320, an 8 core cpu.
when the data to process became significant we reach a peak of 5x faster than a a single threaded option, not bad at all!



Monday, 12 January 2015

Experiment #1: simple c++/html5 cross platform 2d engine

Some time ago, when I read that epic ported citadel demo on html5 , I decided to have an in depth  look on how they did that and give it a try. The company I was working for, playerthree  make also html5 web enabled games, so for me the possibility to write a game for the web and for native mobile device in c++ seems just a dream.
Epic were using emscripten, a cross compiler from c++ to javascript  that promise that everything that can be compiled by CLANG, it can be ported in javascript. In fact the main principle behind this tool is that bitcode generate by llvm can be easily translate  in some sort of assembler virtual machine running on javascript. In particular , it uses a javascript language subset known as asmjs. It sounds like this solution would bloat a lot of code by translate object  files in some sort of ASCII version of compiled assembly code but turn out that since asmjs can be easily mapped to machine code, javascript engine can perform ahead of time compilation (AOT) and gain a massive performance gain. The asmjs guys declare that there is only a 2x performance slowdown when compared to  native code on some javascript engine.
The whole toolbox you need for emscripten can be directly installed and configured using EMSDK . Once installed you only need to recompile your project using emcc command, the same way you'd compile your application with a normal compiler.
So, back to us I decided to write a small 2d engine to see if I was able to compile with emscripten, it support the following features:
  • Sprite batching
  • Texture atlas (Texture Packer and glideros format)
  • Interpolators
  • Timed callbacks
  • font support (glideros format)
  • touch input
  • OpenGL 2.0
  • basic memory management 
  • basic containers
  • audio (only on windows at the moment)
it support windows, iOS and Android, plus html thanks to emscripten, it doesn't depend on many library, just glfw for rendering window management and input on windows side and libpng.
On top of that I did a game, during a gamejam organized by playerthree to test if a full game could be done... and it worked. The web version even run on iOS8 and chrome mobile browsers!




in "the only way is up" you have to make your way from the bottom of the ocean to the surface. Simply move your mouse/finger to make the character strafe. You can play the web version here.
All the game design, graphics and audio were made by Gravy,  playerthree creative director and co-founder.  
If you are interested, I've made the engine and the game code available on github. Apology for the game code since is something made during an 8 hour long jam, and if you have any question , feel free to ask.

Sunday, 4 January 2015

Greetings

Hello everyone and welcome to Dr. Glitschen's blog. 
Please allow me to introduce myself: I'm a professional video game programmer living in UK for almost 4 years now. English is not my native language so I hope you will excuse me if sometimes I make some mistakes. 
My principal interest are new technologies, programming, playing videogames and board games, cooking, sleep and 80's stuff in general. Sometimes I'm lazy. The idea to have a blog came to me at least a couple of years ago, but as I just told you, I'm lazy :D. With the beginning of 2015 among with a new job, I thought that this was the right moment to do it and , of course , I'm already a few days late :D I will talk mainly about programming ideas, graphic programming and c++ in general, but I don't exclude it will evolve in something different in future and I'll try to post often and keep the blog updated. Hope you will enjoy the ride and you will participate numerously and actively in my post. Oh, I almost forgot... happy 2015!