wyskoj / midis2jam2

🎶 A remaster of MIDIJam, a 3D MIDI file visualizer.
https://midis2jam2.xyz
GNU General Public License v3.0
162 stars 21 forks source link

Improve performance in multiple areas #115

Closed VGMRUS closed 6 months ago

VGMRUS commented 2 years ago

Describe the bug A clear and concise description of what the bug is. The enhanced shadows REALLY need some optimization, specially with high amounts of instruments showing up at once.

I have a RX580 4gb (and ryzen 3700x), and it is struggling to get to 60fps and sometimes even 30fps and with enough instruments not even 15fps with the shadows at low (doesn't change the performance much with medium and high shadows).

If I put the enhanced shadows on OFF it runs 144fps easily, so these shadows are really slowing down the performance and they should be optimized

IDK if it's because this RX580 is a AMD card and amd card windows drivers are NOTORIOUS for bad OpenGL performance compared with nvidia or even intel, if midis2jam2 is using OpenGL that could be a factor and adding vulkan support would fix it

Offending MIDI file Upload the MIDI file that causes the bug here. Any midi with more than 10-20 instruments or more showing up at once really, compare the performance on the same midi with shadows off vs shadows on low/medium/high)

Expected behavior A clear and concise description of what you expected to happen. The drop of FPS shouldn't be as big just from shadows on an rx580 mid end card, this card should be more than enough to run midis2jam2 at more than 60fps all the time

System Provide your OS, and computer specs if applicable. windows 10 21H2, 2x8gb of ddr4 2666mhz, ryzen 3700x, rx 580 4gb

wyskoj commented 2 years ago

Open Task Manager and start a MIDI file. Does your GPU show any usage? Here's what mine looks like (the last column is GPU usage): image

wyskoj commented 2 years ago

As far as "optimization" goes, there's not much I can do. I don't manage any of the rendering and graphics component of the application. That's all on jMonkeyEngine and I just use that to create the graphics. My guess is with a graphics card that nice and you are getting shitty performance, it's just not being utilized since it's AMD.

VGMRUS commented 2 years ago

Not that high gpus usage actually: the first sixth midijam wasn't open, after that it was I've just noticed the instrument that decrease the fps the most are the pianos, 2-4 or more pianos really decrease the performance max total cpu usage I've seen is 8%, when looking at the per thread cpu usage it uses like 2 threads at max usage in each thread at like 50%-60% usage max on each of those threads imagen Cheers

VGMRUS commented 2 years ago

Here in this scene you can see how it only makes 20fps with shadows on low Here's the midi if you want to compare: Back to the Future II Round 2-1 SNES Official.zip imagen

wyskoj commented 2 years ago

Can you also open that file again, press F3, and take a screenshot please?

wyskoj commented 2 years ago

I'm testing it out now and I notice I'm getting only about 30-45 fps myself, so you are right with regard to the frame drop. I will spend some time trying to find the root cause of it.

VGMRUS commented 2 years ago

Sure imagen

wyskoj commented 1 year ago

I've determined the root cause of this slow down is a combination of both many on-screen objects and my event collection system. During the past month or so, I've been doing an entire refactor of the event collection system. My initial implementation that has been used up to this point is pretty naïve and causes lagging when scaled up (many instruments). So it is a contributing factor to the reason why this MIDI file slows down (particularly, the pitch bend control for each instrument is taking a considerable amount of frame time).

I still have some work to do until it is entirely refactored, but I am close. I have changed the logic of almost every instrument to use this new method. So here is what remains that needs to be refactored:

This new system I'm developing also supports seeking (jumping around the file) so this is also related to #98.

Hopefully when I have the event collection refactored, it will only be a factor of the performance of the graphics card (or at least a less significant factor).

wyskoj commented 1 year ago

I also just found out that the SSAOFilter (screen space ambient occlusion) was adding a lot of extra overhead! Gonna try to tweak this to improve its perfomance.

wyskoj commented 6 months ago

At this point I've entirely refactored the event collection system. Performance, as it relates to the computation of animation—not necessarily rendering, although that has been optimized and is configurable—has been significantly optimized.

wyskoj commented 6 months ago

Here in this scene you can see how it only makes 20fps with shadows on low

This MIDI file runs at a smooth 60 FPS now!