wined3d: Implement the state merger and start to use it.