This is my first try to contribute anything useful to Mesa, so please bear with me. This is not finished, but I'd like feedback to make sure the code's quality and style is in line with what is expected in Mesa.