Author Topic: coinop getting slow after a while  (Read 13130 times)

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #15 on: March 11, 2020, 04:23:12 AM »
I too had this problem. As I found out, it is what Pieter once mentioned, that the GPU cannot keep up.
The "Worlds" theme from CoinOPS has a ton of artworks and animations that causes high GPU load.
I tested on my laptop with an NVIDIA NVS5200. By default it uses the integrated Intel HD graphics and GPU usage reaches 100% when video starts to play. Then it starts to slow down.
After manually set it to use the NVS5200, GPU usage is still high but hovers around 93%. No slow down this time but the machine runs hot!

I then switched to the Animatic and the RAW theme. Those use a lot less GPU, about 30--60%, and no slow down. But the machine still gets hot after a while.

So I got curious why it requires so much GPU power to play some 640x480 video. I downloaded the code and started to read it...I've been writing C++ for many years but am totally new to this GUI/SDL thing. It took me a while to learn/realize this "render loop" concept that might be the "Hello World" equivalent for game developers. So basically, the program has such a loop:
  • Take user input
  • Determine what happens, how each GUI element moves/changes etc.
  • Wipe the screen clean then redraw everything.
  • Repeat.
That "redraw everything" part indeed includes everything, like the background image, logos on the wheel, texts, and of course the next video frame. Every single GUI element gets redrawn no matter it changes or not.
That sure sounds like a lot of GPU operations. But I'm still not sure whether it explains why it uses so much GPU power that a recent year laptop with a dedicated graphics card can barely handle it. It might not be a fair comparison, but even an old machine with integrated graphics should play those videos with ease.
Any thoughts?
« Last Edit: March 13, 2020, 05:30:27 AM by walknight »

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #16 on: March 12, 2020, 07:03:36 AM »
Today I played more with CoinOPS' Worlds layout.
I commented out pretty much everything, then started to enable them one by one to figure out which is which and their impact on GPU usage.
I found video is not the primary cause of high GPU usage. Rather it's those large pictures. For example, a full screen background image with varying alpha values will cause a rather significant increase on GPU load. This seems to make sense as that large picture needs to be redrawn in each frame.

So I spent some time to tweak the theme, trying to retain the essential effects but get rid of large images that only add a minor artistic feel. The result is satisfactory. I'm finally able to run it smoothly on an integrated Intel HD5000.

I do have one question. The following code is to show a full screen background that covers pretty much everything when switching collections.
This has a high GPU usage as the image is large. But I have to have this, otherwise some underneath "parts" will show when switching collections.
I guess for this image, its alpha must be 0 when I stay inside a collection, and only shows up when switching from one collection to another.
So my question is, does the program still draw an object if its alpha is pure 0? If that's the case, is it possible to add that feature (skip if alpha is 0)?

Code: [Select]
    <image src="images/Promo.png" alpha="1" x="0" y="0" height="1080" width="1920" layer="16">
        <onMenuExit menuIndex="1">
            <set duration="0.2">
                <animate type="alpha" to="1"/>
            </set>
        </onMenuExit>
        <onMenuEnter menuIndex="1">
            <set duration="0.4">
                <animate type="alpha" to="0"/>
            </set>
        </onMenuEnter>
        <onHighlightEnter menuIndex="0">
            <set duration="0.25">
                <animate type="alpha" to="1"/>
            </set>
        </onHighlightEnter>
    </image>

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #17 on: March 13, 2020, 04:49:23 AM »
Update:
It seems I can no longer post code in a reply. The post just disappears...
Anyway just want to report that I added a single line like

if alpha is 0 then return.

and that dropped my GPU usage from 100% to 40%!
I briefly played around and did not notice anything wrong.
If this indeed works, it means we can run this fancy theme on many cheap and old hardware. Very excited about it!

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: coinop getting slow after a while
« Reply #18 on: March 13, 2020, 06:08:56 AM »
I’ll add it to the code. Did you add it to sdl.cpp?

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #19 on: March 13, 2020, 01:51:56 PM »
Yes SDL::renderCopy.

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: coinop getting slow after a while
« Reply #20 on: March 13, 2020, 03:08:35 PM »
Does this version solve the issue as well? It includes the other recent fixes, like the one for zero delay encoders.

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #21 on: March 13, 2020, 11:19:34 PM »
Yep it worked. Thanks!

I forgot to mention that I made another change the other day. I dropped the frame rate to 30 fps when the menu is in idle state.
That helped to cut the GPU usage in half without noticeable degradation.

In RetroFE.cpp:
Code: [Select]
-            double sleepTime = 1000.0/60.0 - deltaTime*1000;
+
+            int fps = (state == RETROFE_IDLE ? 30 : 60);
+            double sleepTime = 1000.0/fps - deltaTime*1000;

Maybe make it a configurable option for people with older hardware?
« Last Edit: March 13, 2020, 11:26:35 PM by walknight »

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: coinop getting slow after a while
« Reply #22 on: March 13, 2020, 11:28:36 PM »
Sure, I’ll make FPS programmable with a default of 60.

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: coinop getting slow after a while
« Reply #23 on: March 15, 2020, 09:41:56 AM »
Give this a try; the parameters are fps and fpsIdle, and both default to 60. Let me know if you encounter any problems.

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #24 on: March 15, 2020, 11:06:40 PM »
Tested good. Thanks!

BTW Pieter can you share your Windows build command line? I'm using VS2019 but my executable is a little bit larger than yours. Speed-wise it's about the same though.

Also I saw you worked on the rpi build a while back. I'm interested in building this for the Rockchip RK3328 which is used in the AtGames Legend Ultimate cab. Could you give me any pointers on setting up the cross compiler?



Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: coinop getting slow after a while
« Reply #25 on: March 16, 2020, 10:48:27 AM »
Tested good. Thanks!

BTW Pieter can you share your Windows build command line? I'm using VS2019 but my executable is a little bit larger than yours. Speed-wise it's about the same though.

Also I saw you worked on the rpi build a while back. I'm interested in building this for the Rockchip RK3328 which is used in the AtGames Legend Ultimate cab. Could you give me any pointers on setting up the cross compiler?

My Windows build command isn't any different from what the README describes to be honest. Perhaps it's because I still use VS2017 for my builds or are you compiling for 64 bits in stead?

I've never done cross compiling of RetroFE to be honest; I compiled my Pi executable directly on the Pi using the standard Linux compile instructions.

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #26 on: March 16, 2020, 03:26:08 PM »
I see. I'm completely new to cross compiling too so looks like lots to learn.

batodan1911

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: coinop getting slow after a while
« Reply #27 on: March 19, 2020, 02:37:39 PM »
did u find a way to fix slow vids ?

Pieter Hulshoff

  • Administrator
  • Hero Member
  • *****
  • Posts: 1534
  • Karma: +46/-14
    • View Profile
    • Towel 42
Re: coinop getting slow after a while
« Reply #28 on: March 19, 2020, 02:38:39 PM »
Yes, just grab the latest build from http://retrofe.nl/SMF/index.php?topic=7.msg3865#msg3865
Consider setting fps and fpsIdle to 30 in your settings.conf file.

walknight

  • Newbie
  • *
  • Posts: 24
  • Karma: +4/-1
    • View Profile
Re: coinop getting slow after a while
« Reply #29 on: March 19, 2020, 06:51:43 PM »
In addition to the code changes, attached is a modified version of the Worlds theme with minimal usage of large sized (size on screen not file size) pictures.
As mentioned before large pictures are the primary cause of high GPU usage.
Just make a backup of your layouts/Worlds folder and extract the zip on top of it.
In the layout.xml file you can find my comments regarding what does what.

I've also derived a theme from this for the Arcade1UP cab (5:4 ratio) if anyone is interested.
« Last Edit: March 19, 2020, 07:00:24 PM by walknight »