![]() |
![]() |
![]() |
![]() |
![]() |
Grandia Optimizations
Posted on 2012-01-09 23:06:36 |
I added the missing VU instructions that were needed by Valkyrie Profile 2 and also fixed a problem happening because of I wasn't flushing recompiled blocks spanning a memory area that was being rewritten on by the game code. I couldn't get something to display right away because there was a lot of weird black sprites being drawn on the screen... Probably because they are used to clean some render targets or something like that. But after deactivating the black sprites I was able to see the main character being rendered without too many glitches.
The main issue was now that there wasn't any level in the background... I have no idea what happened there, but there's simply no level being displayed (and probably loaded). The character also seems to be falling down in the void for a moment, hence the trails you see in the screen shot. But, I didn't let that bother me too much because I first wanted to find out why most of the triangles were being generated with a black color (for the clouds in the main menu for example). I tried to analyze the VU program that was generating the commands to draw the triangles and found out that it was modulating all the input colors of the geometry with some kind of global ambient color. So, I tried to see where that color was being set in the game code and found a function that is supposed to compute that ambient color value, but I found out soon after that it was never called. I looked around, but I couldn't find anything that would give the correct result. So, I kinda gave up on Valkyrie Profile 2 for the moment and decided to try Grandia 2 instead which is a bit simpler. There wasn't any major hurdles to get that game running to the point where you can run around in the field. The biggest problem was again the video decoding parts that aren't working at all in this game. I had to patch them out to be able to see the interesting parts of the game... Even then, I had to let the emulator run overnight to get to the first part of the game since the intro movie is unskippable and quite long. The 3D stuff pretty much worked without any change in the GS handler code which was a bit surprising. I also took the time to fix some problems in my LIBMC emulation that was preventing the game to load and save data to the memory card. The game doesn't run perfectly as there's still weird texture mapping bugs happening when you play for a bit too long but it's not crashing or anything like that. Seeing that this game was working pretty well, I decided to dive into some optimization related matters to make it work faster. I tackled a few bottlenecks already, one being the need to call a memory read or write routine 4 or 2 times (for quad and double words respectively) in the recompiled code which I could remove by adding memory access routines that can manipulate bigger data sizes. This optimization gave a little boost of 2 fps in Grandia 2, which isn't much, but still nice to have. I also found out that I could start the execution of a VU microprogram immediately in the MSCAL/MACALF/MSCNT VPU operations to save some time (around 1 or 2 fps). The last thing I did was to get rid of this strange recompiled block addressing scheme I put in place early on in the development of the emulator and replace it with a much simpler 2-level table addressing scheme. This also gave a small fps boost, but not as much as the other 2 optimizations. The next thing I want to change is the way I emulate the pipeline delays for the Q and MACflags registers. When looking at the recompiled VU code, I saw that there was a register pipeline check generated at every instruction, even for NOPs or blocks that don't even use those registers, which doesn't make much sense since nothing related to them needs to be computed. I'm sure there's a smarter way to deal with this. I don't know if that's going to give a huge fps increment, but I have good hopes that it should help since the VU microprogram execution seems to take a lot of time according to my profiler. Updates coming soon (or not so soon...) |