Saturday, July 3, 2010

Empty buffers in PIX... or so it seems.

One of the most powerful tools in the DirectX SDK toolbox is PIX. In the early stages of 3D development it will be an indispensable help in pinpointing rendering issues... and the moment you got those nailed, PIX turns into an awesome performance analysis tool to help you achieve those truly interactive frame rates.

In this post I'd like to focus on a single particular pitfall that I repeatedly run into (because well, I'm thick). All of this is actually properly documented inside the PIX help... but no proper caffeine-laden milestone-dreading developer ever takes the time to read the manuals, right?

Let's say we are working on the scene depicted below. It features some simple geometric shapes and a basic stencil shadow implementation.


Now pretend we spot a tiny error in the shadowing in the above image. Suspecting a small issue in the stencil buffer, we fire up PIX and take a look at the Stencil Channel in the Render Tab.



Black void? That's rather surprising, as we do have shadows showing up in the scene, so something must be working right in the stencil algorithm. So why don't we see anything in this buffer?

The trick here is the range displayed in the PIX Render Tab. By default, it tries to depict the full (0.000 to 1.000) range of the buffer values. Even with multiple overlapping shadows, stencil values will typically be really low (in this case, only the first couple of values out of a full 24 bits range).

The solution is the double slider control in the upper right of the Render Tab: the top and bottom sliders can be used to modify the minimum and maximum value of the visualization. Simply grab the bottom slider and drag it nearly all the way to the left to have the values show up.



And behold, there are our stencil shadows! Same thing goes for the depth buffer, with the caveat that in a typical setup the values in our depth buffer will be really high. You now have to tweak the top slider until you get the proper minimum level for things to show up.


Luckily PIX is clever enough to remember the slider settings for each buffer individually, so once you have them set to the proper levels you can freely switch buffers without having to constantly fiddle with the settings.

So now, let the debugging commence!

No comments:

Post a Comment