Author Topic: Odd slowdown  (Read 6351 times)

Offline gausen

  • Newbies
  • *
  • Posts: 19
  • Karma: +2/-0
Odd slowdown
« on: November 10, 2015, 02:15:53 PM »
Hi all.

This thread serves the only purpose of pointing out a performance issue I'm experiencing in latest versions of FBA. This is not really a bug and I'm not asking for a fix either.

I've been using FBA a lot since it excels at performance and emulation quality. I mostly play CPS1, CPS2, CPS3 and NeoGeo games. I'm currently using version 0.2.97.34 on a win10x86 tablet (z3740 cpu) and it does run quite well (with full resolution and softfx's). All of the following versions had a slower performance. I'm just curious about what changes may have reduced the blazing fast performance.

Best regards.
« Last Edit: November 10, 2015, 02:17:52 PM by gausen »

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1091
  • Karma: +59/-1
  • Helper
Re: Odd slowdown
« Reply #1 on: November 10, 2015, 02:40:28 PM »
There was a huge performance decrease on sh2 emulator (cps3) i had to fix on libretro-fba, i think it was introduced in 0.2.97.35 . I didn't see any performance decrease in cps1/2 and neogeo games. And i'm mostly running fba on a raspberry pi.

I had to do something like this in sh2.cpp :
Code: [Select]
int Sh2Run(int cycles)
{
#if defined FBA_DEBUG
if (!DebugCPU_SH2Initted) bprintf(PRINT_ERROR, _T("Sh2Run called without init\n"));
#endif

sh2->sh2_icount = cycles;
sh2->sh2_cycles_to_run = cycles;

do
{
#if defined USE_SPEEDHACKS
if ( pSh2Ext->suspend ) {
sh2->sh2_total_cycles += cycles;
sh2->sh2_icount = 0;
break;
}
UINT16 opcode;
#else
if (!pSh2Ext->suspend) {
UINT16 opcode;
#endif

if (sh2->delay) {
//opcode = cpu_readop16(WORD_XOR_BE((UINT32)(sh2->delay & AM)));
opcode = cpu_readop16(sh2->delay & AM);
change_pc(sh2->pc & AM);
sh2->delay = 0;
} else {
//opcode = cpu_readop16(WORD_XOR_BE((UINT32)(sh2->pc & AM)));
opcode = cpu_readop16(sh2->pc & AM);
sh2->pc += 2;
}

sh2->ppc = sh2->pc;

switch (opcode & ( 15 << 12))
{
case  0<<12: op0000(opcode); break;
case  1<<12: op0001(opcode); break;
case  2<<12: op0010(opcode); break;
case  3<<12: op0011(opcode); break;
case  4<<12: op0100(opcode); break;
case  5<<12: op0101(opcode); break;
case  6<<12: op0110(opcode); break;
case  7<<12: op0111(opcode); break;
case  8<<12: op1000(opcode); break;
case  9<<12: op1001(opcode); break;
case 10<<12: op1010(opcode); break;
case 11<<12: op1011(opcode); break;
case 12<<12: op1100(opcode); break;
case 13<<12: op1101(opcode); break;
case 14<<12: op1110(opcode); break;
default: op1111(opcode); break;
}
#if !defined USE_SPEEDHACKS
            }
#endif
#endif

if(sh2->test_irq && !sh2->delay)
{
CHECK_PENDING_IRQ(/*"mame_sh2_execute"*/);
sh2->test_irq = 0;
}

sh2->sh2_total_cycles++;
sh2->sh2_icount--;

// timer check

{
unsigned int cy = sh2_GetTotalCycles();


if (sh2->dma_timer_active[0])
if ((cy - sh2->dma_timer_base[0]) >= sh2->dma_timer_cycles[0])
sh2_dmac_callback(0);

if (sh2->dma_timer_active[1])
if ((cy - sh2->dma_timer_base[1]) >= sh2->dma_timer_cycles[1])
sh2_dmac_callback(1);

if ( sh2->timer_active )
if ((cy - sh2->timer_base) >= sh2->timer_cycles)
sh2_timer_callback();
}


} while( sh2->sh2_icount > 0 );

sh2->cycle_counts += cycles - (UINT32)sh2->sh2_icount;

sh2->sh2_cycles_to_run = sh2->sh2_icount;

return cycles - sh2->sh2_icount;
}

Offline gausen

  • Newbies
  • *
  • Posts: 19
  • Karma: +2/-0
Re: Odd slowdown
« Reply #2 on: November 10, 2015, 03:58:52 PM »
Thank you barbudreadmon for pointing this up. I forgot to mention that the slowdown happened with CPS3 only. Will try to get all the tools in place for attempting fixing it following your modifications.

Offline gausen

  • Newbies
  • *
  • Posts: 19
  • Karma: +2/-0
Re: Odd slowdown
« Reply #3 on: November 10, 2015, 06:23:59 PM »
Worked perfectly. Thank you barbudreadmon.

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Odd slowdown
« Reply #4 on: November 10, 2015, 11:03:56 PM »
While this code speeds up cps3 games on slower processors, it breaks kaneko supernova & some psikyo sh2 games due to irq and timers getting skipped.  I will look into making a version of this speedhack that gets selectively enabled by cps3 so compiling with -DUSE_SPEEDHACKS doesn't break games on other systems.

best regards,
- dink

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Odd slowdown
« Reply #5 on: November 10, 2015, 11:36:25 PM »
Here is a better version of the cps3 speedhack for the sh-2 cpu.  cps3 games will toggle it on - and other systems like kaneko supernova & psikyo sh* will leave it off, to prevent game breakage.  Unzip the attached zip in /src/ and it will create an updated cpu/sh2_intf.h, cpu/sh2/sh2.cpp, burn/drv/cps3/cps3run.cpp.

Please test it out and share your findings, as this code will probably be in the next version of FBA.

best regards,
- dink

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1091
  • Karma: +59/-1
  • Helper
Re: Odd slowdown
« Reply #6 on: November 11, 2015, 02:31:48 AM »
Thank you dink, actually i knew this speedhack breaked a few games, that's why i made it a compile option to enable on slow processor in libretro-fba (kaneko supernova & psyikyo sh* would not run at full speed without the hack on rpi anyway).

Offline gausen

  • Newbies
  • *
  • Posts: 19
  • Karma: +2/-0
Re: Odd slowdown
« Reply #7 on: November 11, 2015, 05:57:29 AM »
Thank you Dink, compiling now. Will be awesome to have this in future versions of FBA.

Edit: I've just tried it. CPS3 is working perfectly. Thanks again Dink.
« Last Edit: November 11, 2015, 06:34:58 AM by gausen »

Offline Gab75

  • FBNeo Contributor
  • *****
  • Posts: 1481
  • Karma: +33/-0
  • All games deserve to be emulated, more or less! :P
Re: Odd slowdown
« Reply #8 on: November 14, 2015, 05:56:06 PM »
While this code speeds up cps3 games on slower processors, it breaks kaneko supernova & some psikyo sh2 games due to irq and timers getting skipped.  I will look into making a version of this speedhack that gets selectively enabled by cps3 so compiling with -DUSE_SPEEDHACKS doesn't break games on other systems.

A good implementation (for a next FBA release) could be to add the chance to select both SH2 codes...
e.g. through two options in Misc/Options menu: SH2 fast core - SH2 accurate core.

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Odd slowdown
« Reply #9 on: November 14, 2015, 06:13:26 PM »
Gab75, for cps3 games it really makes no difference.  using the fast method, it simply skips the timer(timers internal to sh2 cpu) checks when the cpu is told to idle (from the speed-hack).  Since the cps3 games don't use the timers(during idle) anyways its not going to make a difference either way.  On the other hand, if you want to implement this.. by all means, go ahead :)

best regards,
- dink

Offline Gab75

  • FBNeo Contributor
  • *****
  • Posts: 1481
  • Karma: +33/-0
  • All games deserve to be emulated, more or less! :P
Re: Odd slowdown
« Reply #10 on: November 15, 2015, 01:27:34 AM »
Gab75, for cps3 games it really makes no difference.  using the fast method, it simply skips the timer(timers internal to sh2 cpu) checks when the cpu is told to idle (from the speed-hack).  Since the cps3 games don't use the timers(during idle) anyways its not going to make a difference either way.  On the other hand, if you want to implement this.. by all means, go ahead :)

You're clearly more skilled than me, so if you say that there're not real advantages... the game isn't worth the candle!  ;)


Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1091
  • Karma: +59/-1
  • Helper
Re: Odd slowdown
« Reply #11 on: October 23, 2016, 05:29:08 AM »
Sorry for bumping this, but do you have a list of the games that would break with this speedhack ? I want to add it on every games that won't break, because it seems some games would run a lot faster without breaking with this hack, and i would like those game to run at full speed on raspberry (at the moment, most psikyo will run around 50-55 fps). I think Cyvern is one of the games that would break, any other ?

Edit : after trying every game from psikyosh, psikyo4, and suprnova drivers, i didn't find any game having issues with this speedhack except cyvern (no bg music + sound out of sync), you remember another one ?
Edit2 : Seems some other suprnova games will randomly trigger the "no bg music + sound out of sync" issue with the speedhack.
« Last Edit: October 23, 2016, 06:58:54 AM by barbudreadmon »

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Odd slowdown
« Reply #12 on: October 23, 2016, 08:34:39 AM »
Yea you found it, suprnova games highly rely on the internal timers of the sh2 cpu, and the speedhack bypasses those most of the time.  I think sol divide in psikyosh also might have trouble with it.
most other sh2 games don't use the timers for some reason. (or uses them in a very low resolution mode)

best regards,
- dink

Online barbudreadmon

  • Administrator
  • *****
  • Posts: 1091
  • Karma: +59/-1
  • Helper
Re: Odd slowdown
« Reply #13 on: October 23, 2016, 02:43:30 PM »
Yea you found it, suprnova games highly rely on the internal timers of the sh2 cpu, and the speedhack bypasses those most of the time.  I think sol divide in psikyosh also might have trouble with it.
most other sh2 games don't use the timers for some reason. (or uses them in a very low resolution mode)

best regards,
- dink
Thanks for your answer.

Issues in Sol Divide would be the same as on Kaneko, which means sound issues ?

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Odd slowdown
« Reply #14 on: October 23, 2016, 04:47:17 PM »
Thanks for your answer.

Issues in Sol Divide would be the same as on Kaneko, which means sound issues ?

My memory is a little bit fuzzy, but I think so :)