mesa: Define helper function to get the number of texture layers.