Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irjit: Add ini option to precompile functions #10514

Merged
merged 4 commits into from Jan 8, 2018

Conversation

unknownbrackets
Copy link
Collaborator

@unknownbrackets unknownbrackets commented Jan 7, 2018

This uses an xxhash of the original code to validate before actually linking emuhacks. We'd need to do the same for any jit cache, because games don't call icache invalidation before executing blocks the first time consistently.

This also allows testing IR passes on all blocks at once.

With the hashing, this seems to work just as well in all games as without. Spikes in jitc while loading are mostly gone though, replaced by small bumps from the hash validation.

Some things we could do:

  1. Add a "safe mode" (possibly a game id hack, as much as I hate those) for some games that confuse the jit. It could revalidate the hash each time. This would be a lot slower, but maybe needed for Tony Hawk and Jit emuhacks detected by games (Metal Gear Solid: Peace Walker demo) #3365? Have not validated assumption that this would beat interp in speed, though - might be worse.... could be a dev option to validate if emuhacks vs jit bugs are the problem.

  2. Cache the instructions to a file / reload. Would need to version and think about lifecycle though (e.g. new build with irjit fix, new ops, etc.)

  3. Reuse previously invalidated blocks if the hash matches. Currently, they never get used again.

  4. More aggressively use optimization passes, since they wouldn't cause ingame hitching at least.

  5. Either hook this up to jit backends with IR, or port (in theory the same should be doable there - just have to watch the codepool cap and the branch prediction order.)

The preload time, on desktop, is usually 200ms to at most ~750ms (after 64-bit IR.) On mobile it's surely slower, but I didn't really measure yet.

This is still off by default.

-[Unknown]

This doesn't actually do any preloading yet, it just adds an API.
This can take a second, but cuts down on jitc spikes throughout runtime.
Note: bits of the game will still be recompiled as games change code.

This is basically the same operation as loading from cache, without the
cache yet.
Invalidation may result in multiple matching blocks, prefer any that is
currently valid.
These will be changed before executing anyway.
@hrydgard
Copy link
Owner

hrydgard commented Jan 8, 2018

This is pretty cool. I guess for the moment the most interesting use case is as you say to run irjit on a whole game immediately to compute bloat stats etc... then when we convert to native code it gets more interesting, I guess, to reduce the jit cpu cost, and eventually later maybe jit everything? Though wonder if that's worth it..

@hrydgard hrydgard merged commit 6224260 into hrydgard:master Jan 8, 2018
@unknownbrackets unknownbrackets deleted the irjit branch January 9, 2018 00:07
@unknownbrackets
Copy link
Collaborator Author

Right.

But, for example, in RPGs you may have a character that uses a special magic attack - suddenly loading a bunch of new code, rendering complicated effects, uploading new textures, etc. Some of the spikes in jitc, while only during loading, are not small - and seem worse on WX exclusive, too. Caching or preloading jit might help keep those frames within, or at least closer to, the budget.

But we'll have to benchmark whether it's really worth it, yeah.

-[Unknown]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants