Applying http://lists.freedesktop.org/archives/mesa-dev/2012-December/031345.html