Friday, 7 January 2011

N64 Emulator updates

I have already made quite a few improvements to my mupen64 port since the video.

About half an hour after making it, I fixed almost all the missing screens/skies and the clipped mario by adjusting the Z buffer range (previous range was 0..1, now it is -1..1).

I then improved N64 gfx combiners emulation (combiners are sort of early primitive pixel shaders). I use 360 pixel shaders to emulate them. At first it was really slow because I used many switches and loops in it and it seems doing that in a pixel shader isn't such a good idea. I got everything back to playable speeds by using mainly 3 techniques:
  • a color lookup table to emulate combiner 'source' (ie vertex color/texture color/constant/...)
  • a math formula that handles all the possible cases for the combiner operation (ie mul/add/sub/...)
  • having different pixel shaders (one fast that can only do simple things, one intermediate, and one slow that emulates everything) and switching between then when needed.
So now gfx emulation is quite fast but the emu still runs slowly when it emulates floating point intensive scenes like the mario head demo at the begininng of SM64 so I start looking at how mupen64 emulates floating point operations, I quickly discovered that the whole floating point unit was running in interpreter mode, oops!
A few #define later the emu was up to 50% faster.

Next I had an idea: why not try to get the X360 GPU to render my current frame in background instead of actively waiting for it to finish rendering.
Usually you do this:

/* resolve (and clear) */
Xe_Resolve(xe);
/* wait for render finish */
Xe_Sync(xe);

Now I do this:

/* resolve (and clear) */
Xe_Resolve(xe);
/* begin rendering in background */
Xe_Execute(xe);

and then I call Xe_Sync() at the last time right before beginning my next frame
I got a huge speed boost with this, Super Mario 64 now runs at around 100fps ingame !

8 comments:

  1. congratulations and pretty smart stuff :)
    this means other games will work ok too?

    ReplyDelete
  2. you are reanimating the scene! amazing stuff :D

    ReplyDelete
  3. Sounds great :) cant wait to try this on the 360 :)

    ReplyDelete
  4. GliGli the new homebrew/emulator master like XPort?

    Really possible !! :> !

    I really aprreciate your hard work for us :) !!
    Now i know, to don't sell my Jasper JTAG :P

    Big THX and Good Luck in other project's !

    Free60 4EVER !!!

    ReplyDelete
  5. Amazing work!!! Much appreciated!!

    ReplyDelete
  6. thank you for developing this !

    drop us a line on the progress ;)

    ReplyDelete
  7. I'm happy now lol I was delivered a MS points card code and it was genuine! Check out http://freemspointsforever.com - See more at: http://freemspointsforever.com/#sthash.lh6mE8Gz.dpuf

    ReplyDelete