Friday, January 27, 2012

Ducks and Dogs

Not a feature update today, more of a thought-of-the-day(tm):
I spent quite a few hours the other day trying to work out how a specific texture in my project was apparently being point sampled while others using the same sampler states were being tri-linear filtered as they should have been.  I tried using Pix to determine just what state the GPU was in but without much success - Pix doesn't seem to like my project very much.
This led on to much poking around and experimental changes looking for more evidence that might point to the underlying problem.  It turned out in the end however to be nothing to do with samplers or really DirectX at all – there was a bug elsewhere in the C++ code that generates the texture co-ordinates for the geometry in question which was causing it to make them offset massively from the origin, which in turn led to a catastrophic loss of precision in the GPU interpolators creating the point sampled effect I was seeing.
Usually having stupid (u,v) values causes texture wriggling or shimmering either of which would have given the game away immediately but in this particular case it happened to make the texture look perfectly stable but point sampled.
The moral?  Try to avoid myopia when tracking down bugs – just because it looks like a duck and quacks like a duck doesn't necessarily mean it really is a duck - it might just be a dog.