Page 1 of 1

Fixing Fighting Vipers 2 attract mode slowdown

PostPosted: Sun Jan 23, 2022 5:53 am
by gm_matthew
When running Fighting Vipers 2 in Supermodel, the game suffers from slowdown during attract mode unless the PowerPC is set to 100 MHz or higher; after a bit of digging I've managed to find what's causing it.

Every few frames, the subroutine 0x5655C is called which does some kind of processing in a loop; not sure exactly what it does. At the end of the loop is a call to the subroutine 0xA49C which checks how many microseconds have passed since the start of the frame; if more than 16584 microseconds have passed, it exits the loop and postpones further processing until the next frame. At this point the game hasn't yet written any data to ping pong RAM (0x8E000000) so it needs to do that before time runs out otherwise the frame is skipped and slowdown occurs.

The real Model 3 runs at a refresh rate of ~57.524 Hz, which gives a total of 17384 microseconds per frame. This means that after the game exits the processing loop, 800 microseconds are left to copy data to ping pong RAM and perform any other procedures required to render the current frame. But Supermodel runs the emulated Model 3 at 60 Hz, which gives 16666 microseconds per frame; this leaves a mere 82 microseconds to finish the frame! Running the PowerPC any lower than 100 MHz results in slowdown because it can't finish processing the frames in time.

The best way to fix this I can think of is to set frameCycles = ppcCycles / 57.524 within RunMainBoardFrame(), which effectively runs the PowerPC about 4% faster than specified in the config file. I tried this and the Fighting Vipers 2 attract mode now runs smoothly even with the PowerPC set to just 50 MHz. Supermodel itself still runs at 60 Hz and audio playback is unaffected.

As a side note, I would expect this change to make Virtua Striker 2 run 4% faster because of the increase in timer frequency.

Re: Fixing Fighting Vipers 2 attract mode slowdown

PostPosted: Sun Jan 23, 2022 8:16 am
by Ian
I'm pretty sure we can change

Code: Select all
   unsigned frameCycles   = ppcCycles / 60;


to

Code: Select all
   unsigned frameCycles   = ppcCycles / 57.524


without any other issues. Actually I am surprised it wasn't already set to that. I know i had it set to that in some of my experimental builds. Maybe in the early days it wasn't known exactly what refresh rate the model 3 worked at, but Bart confirmed with h/w testing that it is 57.5. I think we can still run supermodel at 60 though. 57 is an unplayable jerk fest on a 60hz screen.

From what we worked out with regards to timing is that during boot up sequence there is a timing routine that polls the status register, until it flips at 66% of the time after IRQ2. This timing routine seems to be control when the frame writes happen. But your findings are great, Bart had LONG since wondered about fighting vipers :) In older builds half of the textures were never uploaded for the character models in the attract sequence.

Re: Fixing Fighting Vipers 2 attract mode slowdown

PostPosted: Mon Jan 24, 2022 4:25 am
by model123
Hello developer

Will the video be 57.5fps in the future?

I'm playing with RTSS limiting the frame rate to 58fps because the GPU is old and the driver can't limit the frame rate.
I don't have it right now, but I expect it to look great with a variable refresh rate (VRR)

Google Translation

Re: Fixing Fighting Vipers 2 attract mode slowdown

PostPosted: Mon Jan 24, 2022 12:15 pm
by gm_matthew
model123 wrote:Hello developer

Will the video be 57.5fps in the future?

I'm playing with RTSS limiting the frame rate to 58fps because the GPU is old and the driver can't limit the frame rate.
I don't have it right now, but I expect it to look great with a variable refresh rate (VRR)

Google Translation


I’m hoping to create an option for Supermodel to run at 57.5 fps at some point in the future.

Re: Fixing Fighting Vipers 2 attract mode slowdown

PostPosted: Mon Jan 24, 2022 4:09 pm
by Ian
I actually experimented with this a bit, replaced the SuperSleep function with the high resolution timer functions
With v-sync it actually swaps the buffer at exactly the same point in time every frame, so stuff is smooth. So whatever happens frame swaps are 16.666ms apart. Worst case you drop a frame or two so it's (16.66ms * N frames).
I tried disabling v-sync, and getting the frame rate to be exactly 60 (which should be butter smooth on a 60hz display). But it wasn't. I tried calling the SwapBuffers with v-sync disabled at the same point in time every frame, but still didn't get consistently smooth graphics. In the old days the OS itself was singled buffered, but today everything on windows essentially gets rendered into a direct3d window, and then presented by the window manager. At some point graphics in the window manager are updated and presented to the user. Maybe this is happening at slightly different points in time every frame depending on the load of the system, I've actually no idea. But I couldn't get smooth graphics with v-sync disabled, even when I was targeting the native refresh rate of my monitor (60hz).

So yeah I dunno. Maybe needs a bit more research. Or maybe my implementation just sucked. But you can buy screens with up to 320hz so running something at 57.5hz should not be a problem. Or these nvidia g-sync displays.

Re: Fixing Fighting Vipers 2 attract mode slowdown

PostPosted: Mon Jan 24, 2022 9:05 pm
by Bart
This is a great find, Matthew! You've really been on a tear lately digging into these games!