kosua20 / herebedragons

A basic 3D scene implemented with various engines, frameworks or APIs.
http://simonrodriguez.fr/dragon
MIT License
1.72k stars 78 forks source link

PS2 Optimisations #18

Open TheMrIron2 opened 6 years ago

TheMrIron2 commented 6 years ago

Some future ideas for more optimal circumstances on PS2:

Keep this project up, though. It's nice to see demos like this arise on the PS2. I recommend you check out the gsKit "hi-res" sample code for an idea of what you might be able to do - this seems like a relatively simple scene, and one programmer was able to get a rotating 3D teapot running at native 1920x1080, a 1920x1080 background texture and all with antialiasing at 60FPS. Would be cool to see some improvements here from code like that.

TheMrIron2 commented 6 years ago

Oh and a footnote; the emulator statistics are telling me that GPU is below 10% for the majority of the time, sometimes spiking to just under 15%, and the CPU load is in the 50% region for most of the time (~25% at lowest, ~60% at highest). The vector units are completely unused (perhaps you could use these for on-the-fly decompression or geometry?). Just thought I would mention the statistics in case it helps.

kosua20 commented 6 years ago

This was my first PS2 homebrew tentative, so I have surely missed some best practices and more complex techniques :-). I discovered the PS2 hardware during this project, so I didn't feel confident enough to immediately use the VUs and juggle with RAM/VRAM per-frame. I've stayed close to the basic examples available w/ gsKit and other resources on the web, there is clearly room for many improvements! Thank you for all these details and suggestions, and for your pull requests!

TheMrIron2 commented 6 years ago

No problem. I've been trying to get this demo running at a close to HD resolution (960x720 or 720x1080) single buffered but I haven't had the time to finish it. I'll submit another pull once I've done so!

TheMrIron2 commented 6 years ago

In the meantime, a note; by lowering the bit depth of images (textures etc.) and the framebuffer itself (ie. to 16-bit) you save a significant amount of memory. For example: 640x448x24 (24-bit): 6881280 640x448x16 (16-bit): 4587520

You can see you could probably get away with nicer textures and higher resolution by finding a sweet spot with colour/bit depth.

kosua20 commented 6 years ago

Thank you, that's great! I won't have the time to come back to this demo in the next few weeks, but I will try to see how I can better use the freed RAM/VRAM in order to improve the quality of the textures and the rendering resolution.

TheMrIron2 commented 6 years ago

No problem. I haven't had time to compile this and I think some of the code expects certain bit depths for different textures, so I think it'll require a bit of trial and error with a working ps2sdk to get it working correctly.

TheMrIron2 commented 6 years ago

Something I forgot to mention months ago and remembered when I saw this on my homepage; here's a fundamental thing about PS2 hardware design - the VRAM is not meant to be used for storing textures. The VRAM is purely for pixel data (eg. framebuffers). The 32MB of main RAM is main RAM, but the bus between it and the GPU is specifically designed to be able to zip textures from RAM to the GPU. So essentially, you could have many more textures at a higher resolution than what you could fit in 4MB. When/if you get the time I'd recommend looking into that so you could use stupidly large textures at high resolutions.

Dumb of me to overlook such a thing, but I digress 😅

Fewnity commented 4 months ago

A VU1 sample would be awesome! We need more VU1 sample in the ps2 scene