i965: Pull 3D texture layout code out into a helper function.