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

Darkstalkers Chronicle: Add specializations and speedhacks to get it kinda playable #12443

Merged
merged 18 commits into from
Oct 27, 2019

Conversation

hrydgard
Copy link
Owner

@hrydgard hrydgard commented Oct 23, 2019

Darkstalkers Chronicles is a game that does bad things. Specifically it uses the PSP CPU to draw on top of GPU rendered graphics, which PPSSPP's hardware rendering can't normally handle.

This pull request is:

  • A compat setting that forces software rendering on for this game
  • Optimizations to the software rasterizer, specifically for rectangular draws (which avoids triangle interpolation math).
  • A hack to identify a specific stretch blit in Darkstalkers and replace it with a hardware stretch at the end

Together, it's enough to get Darkstalkers playable at a good speed on PC and kinda playable-ish on high powered mobile devices. And looking sharper than on the real PSP due to avoiding the extra stretch to 480x272. Fixes #6647 .

NOTE: This currently doesn't work on OpenGL, but will soon. Works fine on all backends now!

Plenty more can be done to optimize the software rasterizer for this game and in general.

@hrydgard hrydgard added Software Rasterizer GE emulation Backend-independent GPU issues labels Oct 23, 2019
@hrydgard hrydgard added this to the v1.10.0 milestone Oct 23, 2019
@LunaMoo
Copy link
Collaborator

LunaMoo commented Oct 24, 2019

It would be good if this hack also grayed out UI options not available for software renderer, so people wouldn't waste time changing their settings/post process effects and then wonder why none of this stuff does anything:3. Either way nice work.

I guess this does more than optimizing software rendering, intentional or not it also fixed frameskipping which wasn't really working for this game in the past for software renderer and that should make it playable at much wider range of devices.

Personally I had a plan to create some functions/dividing the awfuly large function this game uses to make it easier to hack around in hardware renderer, but first I was annoyed by some users and when I got back at it, I couldn't save function hashes reliably, maybe for the better since this way works well and improvements to software renderer are always nice to see, with some effects working only there:).

@hrydgard
Copy link
Owner Author

hrydgard commented Oct 24, 2019

Yeah, I think this way is strictly better than hooking into the game - the software rendering specializations are universal (although of course not all games might hit exactly these paths), and I've managed to keep the other hacks very isolated and thus unlikely to risk anything else. Plus, it's really neat to see the resolution adjust to the game's 384x224 instead of an awkward stretch to 480x272, and then stretch again - it looks great.

I don't know why frameskipping would be affected, but good news I guess.

Yes, disabling the unused settings should be done. Additionally, I think I consider it a bug that post-processing doesn't work with the software renderer, it wouldn't be that hard to do, just a bit of plumbing. I'll file a separate issue for that.

Anyway, before I merge this I'm gonna get it to full speed on a few more of my mobile devices. Pretty sure that's reachable with not too much work.

@hrydgard
Copy link
Owner Author

Fixed this to work on OpenGL ES, and curiously, this runs quite a bit better on OpenGL than on Vulkan on my S8+. Since it spends nearly all effort doing software rendering, this has to be a texture upload speed difference or something like that... very strange.

@hrydgard
Copy link
Owner Author

hrydgard commented Oct 25, 2019

Turns out that the lovely stretch hack doesn't work if the game shows a save/load dialog (or, any other drawing happening after it). One way to fix that specific case would be to turn off the stretch hack if a dialog is visible, and one way to fix it in general, but with a one-frame glitch, would be to turn off the stretch hack the next frame if a draw happens after the stretch in the current frame. Even better would be to replay the stretch if a draw happens after.

All this though is getting really close to the edge of what I find acceptable to do for a single game .. but the stretch hack really improves the experience a lot. Grr.

Oh and the vulkan/gl difference disappared, don't know what's going on there. maybe just mobile power management.

The in-game "wide/normal" setting also seems broken, don't know what's up with that. "Wallpapers" are thus broken too.

@hrydgard hrydgard marked this pull request as ready for review October 25, 2019 22:36
@hrydgard
Copy link
Owner Author

hrydgard commented Oct 25, 2019

This is admittedly less than pretty, but takes a long-unplayable game and brings it with pretty much perfect graphics (better than the PSP due to avoiding a stretch) to Android devices (well, and all other platforms of course).

The save/load dialog fix is especially ugly - we need to go back to normal rendering when a dialog is up, and return to our special stretch mode after but then we also need to clear the buffer, otherwise the save dialog briefly shows up whenever the stretch doesn't happen, like between matches.

Still looking into disabling the irrelevant settings, and finding nicer solutions to the hacks described above.

@LunaMoo
Copy link
Collaborator

LunaMoo commented Oct 26, 2019

Not sure if last commit affects performance, as this was without it, but made a quick test on Redmi Note 7:
Screenshot_2019-10-26-23-10-39-168_org ppsspp ppssppluna
Without much action it goes to around 46fps, either way since this also fixes frameskipping, it's easily playable at constant 30fps on very mediocre non-gaming phone.

Some notes:
"Press Start" menu is a bit more demanding, and video intro becomes laggy with frameskip despite running 60 fps otherwise, but meh it doesn't matter, this game doesn't have story or anything anyway, it's just a generic fighter.
Normal non-wide mode cuts the fps to ~ 12 ~ about 1/3 of wide mode and has broken frameskip, so not recommended to use outside of modern PC's which could brute force through it even before optimizations:).

~ some better screenshots as I forgot to set screen scaling filter to nearest before:
Screenshot_2019-10-27-02-24-57-728_org ppsspp ppssppluna
Screenshot_2019-10-27-02-33-04-281_org ppsspp ppssppluna
ignore the 60fps on the second screenshot, I fooled around with animation speed for a bit, ofc playing in slowmo makes it far less demanding.

@i30817
Copy link

i30817 commented Oct 26, 2019

Maybe it would be better to hack the game itself rather than the emulator. If you investigated code locations maybe someone that knows how to do this stuff would fix it in a romhacking.net patch.

@LunaMoo
Copy link
Collaborator

LunaMoo commented Oct 27, 2019

Nah.
This game ~ weirdly positive reviews aside ~ was never popular on PSP - a platform which had many better fighting games with actual story, multiplayer and graphics made for PSP or at least scaled down from more powerful consoles. Darkstalkers - a game without a story will not be appealing to fanboys with multiplayer removed and a stretched blurry graphics when they could just get the original dreamcast version, that didn't suffered from neither of that and certainly had less input lag as well since all the shoddy PSP ports of old Capcom are infamous for noticeable input lag even on real hardware.

If nobody cared to reprogram how this game renders it's graphics before this PR, it will certainly not change now after Henrik not only worked on performance, but also improved how the game looks, restoring Dreamcast quality at least to wide-screen mode:].

@i30817
Copy link

i30817 commented Oct 27, 2019

I was more thinking that 'no one cares' because no one has the skills or the interest. If hrydgard has the skills or can point the correct code locations out to another hacker, that might as well happen instead of a emulator hack, because of raised interest and pre-packaged information.

@LunaMoo
Copy link
Collaborator

LunaMoo commented Oct 27, 2019

If you need info from someone else, you can't do shit as it takes a few minutes with debugging tools to understand everything.
There's no info from here that could help with reprogramming the game itself, it's software rendering optimization and a hack which replaces a software stretch with a hardware one in specific conditions. It doesn't do anything to the bothersome graphics that would have to be done differently, it leaves it all to software renderer where it just works.

@hrydgard
Copy link
Owner Author

@LunaMoo you might wanna test again, the last commit actually has a substantial effect on speed.

Still, yeah, avoid non-wide mode for now. I may do a specialized fix for that later, but for now, meh.

This is safe so I'm gonna merge this as-is, and clean up the presentation workarounds a little bit later.

@hrydgard hrydgard merged commit b4438c5 into master Oct 27, 2019
@LunaMoo
Copy link
Collaborator

LunaMoo commented Oct 27, 2019

Yeah it did, on my phone fps rises above 50 fps frequently now and never drops under 40 during fight at least.

A pity those optimizations don't do much to more complex games / 3D graphics, in Macross or Misshitsu No Sacrifice where mipmap effects only works in software I'm not sure if it even gained a single fps outside of some simple screens. Either way still nice to see work on software renderer:).

@hrydgard
Copy link
Owner Author

hrydgard commented Oct 27, 2019

Hm, my 2 1/2 year old S8+ consistently does 60fps now, I guess it's faster than I give it credit for in raw CPU at least. But yeah, that's still quite an improvement.

And yes, the software renderer performance boost is very specific - other 2D games may benefit a bit, but only if they are lucky and render in a similar way (PSX ports are the most likely to hit this path).

@unknownbrackets
Copy link
Collaborator

Haven't really had time to look at this. I had started on some of a softgpu jit a little while ago, but if the plan it to start adding game specific hacks I'm going to abandon that since obviously it would just be an unfun way to break all the hacks.

-[Unknown]

@hrydgard
Copy link
Owner Author

@unknownbrackets It should be noted that the only actual hack here is just the presentation of the low resolution game buffer, where we bypass a stretch that ruins the image quality. This is clearly gated by a compat ini flag. The rest is just specialization of a specific couple of sets of state (rectangular textured draws with a specific blend mode etc), making it run way faster.

@hrydgard
Copy link
Owner Author

Also this game is a bit of a special case due to CPU drawing on top of GPU polygons - this way seemed like the least of all evils, and I have no plans to go further in this direction. If a jit is added, this will stay a little oddity in the non jit software rendering path, or be removed (though it's nice to support non jit devices).

@LunaMoo
Copy link
Collaborator

LunaMoo commented Oct 28, 2019

Small update on test from redmi note 7, because I never play games on my phone I didn't thought about such possibility, but probably my battery was low when I was testing last time, sorry for misleading results as I get 60fps now with battery at 90%.

Heck even GOW runs pretty well between 55-60 with lots of action when previously when I tested it, I was getting like ~20fps.

@unknownbrackets
Copy link
Collaborator

Got it, well, in theory a jit path will give many of these speed boosts much more generically (though not the rectangle detection, although some games draw a series of rectangles with triangles.) Also, I wonder if we want any threading of DrawSprite.

About battery, yeah. That's why I added the battery warning stuff. No one seems to expect that playing with low battery / automatic battery saver on would have any significant impact to performance.

-[Unknown]

@hrydgard
Copy link
Owner Author

hrydgard commented Oct 30, 2019

DrawSprite could be threaded but in this game no draw (except on the title screen) is bigger than 32x32, most are 16x16, so the way the triangle threading works, that's probably barely worth it due to sync overhead, and even less so given that the per-pixel cost is much lower in drawsprite.

ULUS10005 = true

[DarkStalkersPresentHack]
# Darkstalkers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently these lists are missing ULJM05005?

-[Unknown]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, guess I missed this one since it's called Vampire Chronicles in certain regions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GE emulation Backend-independent GPU issues Software Rasterizer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Darkstalkers Chronicles problem - characters not visible on select screen
4 participants