swr/rast: Refactor to improve code sharing.