Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Need some help optimizing rendering speed.  (Read 5988 times)

0 Members and 3 Guests are viewing this topic.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Need some help optimizing rendering speed.
« on: October 14, 2015, 07:47:58 pm »
So i created a class on my own to attempt to reduce batch calls to optimize speed of my application. This is the class:
(click to show/hide)

I noticed that i don't gain any speed by doing this since i already separate most of my textures when drawing them. It seems that to gain speed i should reduce draw calls since i quite rarely swap texture in comparison to calling draw.
What can i do to optimize my rendering? This is my rendering code. Replace renderList.add() with app.draw(), and that's what i started with before i made the class:
(click to show/hide)

Just interested in how you're supposed to do the rendering because what i have i've mostly come up with on my own.
« Last Edit: October 14, 2015, 07:51:06 pm by Voroz »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Need some help optimizing rendering speed.
« Reply #1 on: October 14, 2015, 08:56:20 pm »
Did you measure a performance issue or are you just prematurely optimizing things?

To reduce draw calls you can batch all the quads into one vertex array, ehich can be drawn with one call.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Need some help optimizing rendering speed.
« Reply #2 on: October 14, 2015, 08:56:49 pm »
Are you achieving poor performance , Can we know the fps or render time ?.
What are your pc specifications?

And i think you can profile the code to know where is the bottleneck (if any). (This task is simple on visual studio, this IDE have several tools for this).


I would like a spanish/latin community...
Problems building for Android? Look here

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #3 on: October 14, 2015, 09:43:20 pm »
Well i guess i might be optimizing things a bit early. Just wanted to test if i could do something with the rendering to increase performance.

I have about 800-900 fps when not doing anything special in my game, and i get 200 fps as the lowest when i shoot many bullets. This is because every bullet has a small light effect from LTBL1, and that thing eats up all my frames! :(

But i think i went and optimized the wrong way since i do alot of draw calls but not much batching. I draw very many RectangleShapes. 454 of them actually. If i remove all those draw calls i gain 70 something fps. Could i see that kind of performance increase if i do what you said and "batch all the quads into one vertex array".

Edit: oh, and i have a gtx 570, and an i7 3770k processor oc'd to 4,5 ghz.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Need some help optimizing rendering speed.
« Reply #4 on: October 14, 2015, 09:45:53 pm »
Probably.

Also keep in mind that FPS is non-linear. It's normal to get a fast drop in the higher FPS area, that alone does not implicate that it will also fall as fast in the lower regions.
Additionally, all your FPS measurements are useless if you're running things in debug mode.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #5 on: October 14, 2015, 09:53:25 pm »
Probably.

Also keep in mind that FPS is non-linear. It's normal to get a fast drop in the higher FPS area, that alone does not implicate that it will also fall as fast in the lower regions.
Additionally, all your FPS measurements are useless if you're running things in debug mode.
I've been using release mode when testing. Ok i guess it's not so bad then if you don't lose frames as fast when you have lower fps. I'll look into how to make much fewers draw calls thanks :).

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Need some help optimizing rendering speed.
« Reply #6 on: October 14, 2015, 10:15:53 pm »
If you are using LTBL1 this could help

You can increase the performance by calling few times lightsystem->RenderLights()

You don't need to call it every frame.

i create this:

       // This class you can define how each frame you will call a function.
        template < typename TYPE >
        class updatePerTicks
        {  
            private :
                        unsigned int ticks ;
            public :
                    unsigned int max_ticks ;

                        updatePerTicks( unsigned int toReachTicks ) : ticks( 0 )  
                        {
                       max_ticks = toReachTicks ;
                        }

                    void operator()( void(*f)( TYPE *something ) , TYPE *param1 )
                        {
                                if( ++ticks == max_ticks )
                                        {  
                                           ticks = 0 ;
                                           f( param1 ) ;
                                        }
                        }

                        void updateTicks( void(*f)( TYPE *something ) , TYPE *param1 ) // Another access for operator() function.
                        {
                                if( ++ticks == max_ticks )
                                        {  
                                           ticks = 0 ;
                                           f( param1 ) ;
                                        }                      
                        }
        };


 


instead of doing this:

    lightsystem->RenderLights() ;
 

i do this:


// put this where you want
auto renderLightsFunc = []( ltbl::LightSystem *ls ){ ls->RenderLights() ; } ;

updatePerTicks< LightSystem > renderLights( 4 ) ; // we set to every 4 frame .. can be  10 / 20 any positive number. Higher fps you can use higher value and will be smooth
// end of "put this"

// we replace  lightsystem->RenderLights() with this:

renderLights( renderLightsFunc , &myLightSystem ) ;

/* if you want you can directly modify the amount of "ticks"
renderLights.max_ticks = myPositiveValue ;
*/


 


Note: You cannot use this method with
lightsystem->RenderLightTexture() ;
this method is needed to be called at least one per frame
« Last Edit: October 14, 2015, 10:24:28 pm by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #7 on: October 14, 2015, 10:33:50 pm »
wont that make it so lights are lagging behind moving objects though?, and not moving as smoothly. I can see that it might work for lights that aren't moving, but that's not the case on my lights.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Need some help optimizing rendering speed.
« Reply #8 on: October 14, 2015, 10:49:57 pm »
wont that make it so lights are lagging behind moving objects though?, and not moving as smoothly. I can see that it might work for lights that aren't moving, but that's not the case on my lights.


Nope, as i said depend of your fps , if you achieve 700 fps you can set to 30 for example and will run very smooth with a significant performace.

By the way.. setting this to a slow value 4~7 are smooth values for apps that run at 60 fps.

Test with differents values, and say if you performance improve and if your lights are lagging.


AFAIK several games has performance options on shadows,lights,anti-aliasing,smothness etc that the user can ajust ; more graphics power = more work for the computer, if an user can manage this settings will be better for the user.
« Last Edit: October 14, 2015, 11:08:28 pm by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #9 on: October 14, 2015, 11:16:08 pm »
But there's no point of those extra fps if your fps is already high. And if your fps isn't high then you can't do it anymore. Sure you can get extreme pointless fps by limiting draw calls but you'll need atleast 60 per second, which is the same you'd get if you actually have 60 fps. So really it seems useless :).

edit: if i wasn't clear enough what i mean is that you automatically limit draw calls by getting lower fps, and when your fps is high you don't need to limit them.
« Last Edit: October 14, 2015, 11:19:05 pm by Voroz »

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #10 on: October 14, 2015, 11:23:55 pm »
I didn't see the part where you recommended to set it to 4-7 for 60 fps apps. Well that will ofcourse give better performance, but lights will only update at 8-15 fps. I don't think i want to make that sacrifice, atleast not now. Maybe if i really need to sometime i might concider making it run slightly slower.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Need some help optimizing rendering speed.
« Reply #11 on: October 14, 2015, 11:33:59 pm »
I didn't see the part where you recommended to set it to 4-7 for 60 fps apps. Well that will ofcourse give better performance, but lights will only update at 8-15 fps. I don't think i want to make that sacrifice, atleast not now. Maybe if i really need to sometime i might concider making it run slightly slower.

You are here asking for performance solutions, i give you one.

It's true, its your fps are high you don't need to limit them. But is a good solution.

Can appear that 8-15 fps can be slow but the eyes isn't too fast to distinguish. I said those value because i already tested them.

For exmaple, supose that you finish your game. A user with a super-pc will be glad to run the game in ultra-high graphics (only set the value to 1). But if the user had a poor computer probably with this options he can gain a 25-40% of performance al only loosing 3-10% of smothness.

It's an ajustable solution with a short implementation. i think this is a better solution than remake the LTBL sytem, isn't it?
« Last Edit: October 14, 2015, 11:36:23 pm by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #12 on: October 14, 2015, 11:36:00 pm »
I tried updating every 4 frames and it made the entire shader blink. epilepsy! (yes i only did it for ls.RenderLights(), not the texture.)

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Need some help optimizing rendering speed.
« Reply #13 on: October 14, 2015, 11:39:42 pm »
I tried updating every 4 frames and it made the entire shader blink. epilepsy! (yes i only did it for ls.RenderLights(), not the texture.)


Really? can you post images.

As i said, i tested this solutions several (severals ) times with moving lights with the mouse (very fast movements ), having on screen 300 + bigs  dynamic lights. And never blinking at worst only being "slow".

If you don't believe me i can give you examples (executables) of my tests.

Note: i have ltbl 1.5
« Last Edit: October 14, 2015, 11:42:53 pm by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Need some help optimizing rendering speed.
« Reply #14 on: October 14, 2015, 11:42:11 pm »
You are here asking for performance solutions, i give you one.
True, but i was actually mostly looking to optimize the rendering part without making the rendering slower..

I could easily make the app run in 5000 fps but only render 1 time per second, but i don't think that would be better. It's kind of the same thing here but only with the lights. It would be a good solution though ofcourse as a lower graphics option.

 

anything