Saturday, March 21, 2009

What is microVU?

Well earlier today on the pcsx2 forums someone asked this question, and I guess I could go further into detail here as well as give a nice overview on PCSX2 and the Sony Playstation 2 (it should be an interesting way to kick-start this blog).

Well as I mentioned in my first post, the main project I work on is a PS2 emulator called "PCSX2".
For those of you unfamiliar with emulation, it's basically the idea to mimic or 'emulate' one system on another system.
In the case of PCSX2, we are emulating the Playstation 2 system on a PC. So basically it lets you play ps2 games on your PC! :)

The ps2 is a powerful beast, and I don't think much people understand how difficult properly emulating the system is. Its not uncommon for people to belittle the project or to flame it with hateful remarks (but I guess I can talk about that in another post :p)

Basically to make an emulator, you need to have a solid understanding of how the system you're emulating works at a low level. In the case of the ps2, it has multiple different processors and units that need to be emulated correctly, and it also has to be programed in a way so that the components can sync and 'talk' to each other nicely.

The PS2's main component is the Emotion Engine (EE), this is the 'heart' of the system which also includes 2 co-processors: COP1 (FPU), and COP2 (VU0 in macro-mode).
In terms of PCSX2, we currently use dynamic recompilers to emulate the EE.
A 'dynamic recompiler' is an emulation approach in contrast to an 'interpreter' (which is generally alot slower and easier to code).

The idea of a recompiler is to take the ps2's native language or 'instructions' and to translate it into something your PC understands. After it translates alot of instructions, it saves them in memory in 'blocks'. A block is basically a bunch of instructions that have been translated.
Later on when a game wants to 'read' an instruction, the recompiler would look-up a compatible block, and start 'executing' that block of code.

This approach is alot faster than an interpreter because it only has to translate the code once, and then can read the saved translated code as much times as needed.
An interpreter however doesn't 'save' any translated code, but instead just calls a function whenever an opcode needs to be executed (the overhead for the function calling, as well as the lack of optimizations that can be made, are some of the reasons interpreters are so slow).

Well to get back to what I was saying, PCSX2 currently uses recompilers for its EE emulation (it also has interpreters for the EE, but they're really slow). Our current implementation of the EE recompiler is really a mess quite-frankly. Most of the pcsx2 team agrees we need a complete rewrite of the recompilers eventually, and hopefully next-time around it'll be cleaner and faster :)

To get back to describing the PS2, in addition to the EE, it also has 2 Vertex Unit Processors (VU0 and VU1), a Graphic Synthesizer (GS), various DMA units (vif, sif, gif, ...), 2 Sound Processing Units (SPUs), an Input/Output unit (IOP), a MPEG-decoding unit (IPU), and various other components I didn't mention.
Emulating all these units is alot of work, and syncing them so they work 'together' is ridiculously complex (many of pcsx2's problems is incorrectly syncing these units).

Well now I guess I can finally get to the original question: "What is microVU?"
microVU is what I named the new VU recompilers I'm working on.
Currently PCSX2 uses the VU recompilers named "Super VU" a.k.a. "zerorecs", but they're incorrect when it comes to properly following the VU's pipeline rules, also they're coded in a way that makes them un-threadable.
The goal for microVU is to properly emulate the VU's pipeline and possibly be even faster than Super VU. Additionally, microVU is coded with threading in mind, and eventually it should be threadable which would enable big speed-gains for quad-core CPU users, and possibly nice speed-gains for dual-core users as well.

Since this post is already a Wall of Text, I guess I'll stop here for now, and possibly go over some more stuff in future posts :p

7 comments:

  1. Means that this will beneficial to quad core, good work on this, cottonvibes!

    ReplyDelete
  2. Wish you luck :)
    I can't overclock my Q6600 more than it is already :)

    ReplyDelete
  3. GO cottonvibes!
    can't wait to test pcsx2 using the new microvu!

    ReplyDelete
  4. great stuff, good luck on the project

    ReplyDelete
  5. What percentage of the PCSX2 processor load would you say that the current VU emulation component takes up on average?

    ReplyDelete
  6. if it is consist of recompilers, why it doesn't takes time to load? I mean like java; java programs take time to compile everytime it runs.

    ReplyDelete
  7. This is very helpful. I recommend every pcsx2 distribution include this article. Can help user understand a bit those cryptic message when emulator crashed ^_^
    Thanks for your great effort on pcsx2.

    ReplyDelete