softgpu: Apply optimizations to states generically #16486
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This moves the flat state optimizations to typically happen earlier on, and adds fog to them.
Triangles can and do benefit from these, and I'm considering doing more things here. Specifically, I think it might make sense to do some heuristics and precompute texture data in a buffer. When linear is used, we end up sampling a ton, so getting rid of the gather would really help even if it was a mostly 1:1 draw. There are also annoying cases where games texture a large draw from a single texel to get a solid color, which would be helped greatly by that (Valkyria Chronicles 3 is a good example.)
Other things too, for example alpha checking while doing the above might allow disabling alpha test often, which would help given how often games pointlessly enable it.
Anyway, this usually helps a couple percent but isn't consistent - some runs it's flat, not sure why. At least doesn't make anything worse, and I think it'll make other optimizations easier as noted.
The DenseHashMap change helped some microbenchmarks (headless --bench runs), but didn't seem to help FPS much. But it seemed to help an issue where sometimes optimizing and looking up a new cache key was quite slow.
At first I tried adding a new state when optimizing the current one, but that caused a lot of churn and seemed slower sometimes. So I decided better to just make all optimizations reversible.
-[Unknown]