In the process of doing the reworks necessary for the remaining megadrivers changes, I found a lot of duplicated code. Here's a series trying to reduce the insanity, though note that there's a missing piece in patch 3/7. Tested on i965 and softpipe, touch-tested classic swrast too.