Resource Management

Download Alpha and Omega v2.
Binaries as Win32 Installer (5 MB)
Download Alpha and Omega v2.
Source as Visual Studio 2010 Solution (31 MB)

In the last post we've discussed multithreaded resource loading. This time we'll handle simple resource management, so no difficult threading issues :). Ahhh... it's nice talking about easy things for a while. The goal is to be smart about resources and especially resources allocated on the video card.

Debugging games is a whole lot easier in a managed language, but still it not as easy as debugging your run-of-the-mill desktop application. The data we need to debug is partially allocated on the video card and most of the data cannot be made sense of without visualization. The complexity of most algorithms is high enough for bugs to show only once in a while, and recreating bugs to see where they're coming from is a pain in the ass. We often create debug views that shows information about the 3D-scene that otherwise would have been hidden from the end-user. Just look at these pretty debug views for the game Rage to test virtual textures:


Another personal annoyance is debugging shaders. Shaders are little compiled programs that are send to the video-card usually with the goal of visualizing data, but we can't just set a break-point and look at the variables. It is very annoying to come across a situation where you suspect the shader is messing things up but you don't want to rebuild your whole game just to try it with a slightly modified shader. For DirectX 10+ it is possible to use awesome-looking debugging tools for debugging video-card related resources. Just look at it! Isn't it beautiful?!

Okay, back to reality. XNA 4.0 uses DirectX 9.0 so we can't make use of these state of the art debugging tools :'(. I'm so disappointed, I was really excited about trying this out. Our goal for today is to create a rudimentary tool for debugging resources on the video card.


Since we have created a resource manager in the last post it isn't so difficult to apply some MVC-principles to hook up a separate GUI for showing all the resources. For now we'll stick to textures and shaders and will later extend it to contain 3D models and render targets. For shaders we'll add an option to replace the current loaded shader with one loaded from the hard disk. When a new shader is selected it will automatically compile it and start using it.

To test proper management of resources we've enabled the previous 2 examples so we can switch from one example to another. This helps in checking if the resources are indeed properly handled. For the new breakout-example I've added a shader for liquid simulation. The ball(s) now leave a colored trail corresponding to the last block that it broke.


Whoohoo, so many pictures! We even included moving pictures! This totally makes up for the wall of text from last time.

Multithreaded Renderloop - 43D Sphere