Cherry-pick from ced2911's dx9 work

I merged what seemed to make sense from https://github.com/unknownbrackets/ppsspp/compare/xbox-4716 . Unfortunately there are a couple of large re-tabbings so the diffs aren't pretty, but the d3d stuff is pretty rough anyway.