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

Author Topic: Performance on Drawing Lightened Scene  (Read 8416 times)

0 Members and 1 Guest are viewing this topic.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Performance on Drawing Lightened Scene
« on: May 25, 2016, 12:35:15 pm »
Hi, I'm aware of the existence of LTBL ^^
Atm I'm working on the overall performance of my RPG - its current bottleneck is my lighting implementation. That's why I cut it out to a minimal example. The code can be found on https://github.com/cgloeckner/sfml-lighting-test

On my laptop (Intel i7, GeForce GT 540M using NVIDIA binary driver 352.63 @ Ubuntu wily - btw other drivers cause major problems) the example code runs with
  • ~90 FPS for 20 Edges + 1 Light
  • ~80 FPS for 100 Edges + 1 Light
  • ~30 FPS for 100 Edges + 5 Lights
  • ~10 FPS for 1000 Edges + 5 Lights
I guess this is an issue related to my implementation. Got anybody an idea how I can find the bottleneck?

About the code: I seperated "light", "shadow" and "fog" layers because of my rendering order:
  • floor tiles
  • light layer (might colorize the floor)
  • objects (so they are not colorized by the lights)
  • shadow layer (hides objects behind obstacles
  • wall tiles (if I render those before the shadows, no walls will be visible)
  • fog layer (hides walls that are far away from light sources)
Maybe there even are ways to improve this :)

Thanks in advance!! :)
« Last Edit: May 25, 2016, 12:37:58 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #1 on: May 25, 2016, 12:47:28 pm »
Quote
Got anybody an idea how I can find the bottleneck?
Use a profiler. If it reveals that the bottleneck is on the OpenGL side (which is likely), then I'm pretty sure you can find an OpenGL profiler to go further.
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Performance on Drawing Lightened Scene
« Reply #2 on: May 25, 2016, 01:14:28 pm »
Use a profiler.
Good point! Unfortunately I don't have much experience reading profiler output :S

I added some of the top lines from the output to the spoiler btw. I just understand that the Vector::operator- and my getFarPoint() and update() use most of the time. :-[ What should I be able to read from this?

(click to show/hide)
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #3 on: May 25, 2016, 01:25:37 pm »
Good point! Unfortunately I don't have much experience reading profiler output :S

Then you might love this: https://github.com/jrfonseca/gprof2dot It's really an intuitive visualisation I think. There're also some nice tips'n'tricks on compiler's option.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #4 on: May 25, 2016, 02:16:26 pm »
First, you should let the profiler run for more than 30 ms (typically a few seconds minimum). The longer it runs, the more samples it collects, and the more accurate it is.

Then there's nothing more complicated than what you've read: the 3 first entries take all the time, at equal part.
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Performance on Drawing Lightened Scene
« Reply #5 on: May 25, 2016, 02:40:18 pm »
First, you should let the profiler run for more than 30 ms (typically a few seconds minimum). The longer it runs, the more samples it collects, and the more accurate it is.

Then there's nothing more complicated than what you've read: the 3 first entries take all the time, at equal part.

I re-ran it with lots of edges and lights (for ~30s, because of the low framerate) and for few edges and lights (for 6-7s).

lots of edges and lights
(click to show/hide)

few edges and lights
(click to show/hide)

Based on those results I can only come to the conclusion, that the update() method is the bottleneck (lol, cpt. obvious xD). How to go more into detail?
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #6 on: May 25, 2016, 02:47:43 pm »
Do you run a debug or an optimized build of your application? It's strange that sf::Vector2 operators take so much time. They should even be inlined in optimized builds, an not appear at all in the profiler's output.
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Performance on Drawing Lightened Scene
« Reply #7 on: May 25, 2016, 02:54:22 pm »
Do you run a debug or an optimized build of your application? It's strange that sf::Vector2 operators take so much time. They should even be inlined in optimized builds, an not appear at all in the profiler's output.
I was using
g++ -o main main.cpp lighting.cpp -I./ -lsfml-system -lsfml-window -lsfml-graphics -std=c++11 -g -pg
 
for building, so it's a typical debug one I think.
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #8 on: May 25, 2016, 03:59:57 pm »
There's no point measuring performances with a debug build.
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Performance on Drawing Lightened Scene
« Reply #9 on: May 25, 2016, 04:08:18 pm »
Profiling an optimized build results doesn't give me a hint neither :S
(click to show/hide)

/EDIT: Less aggressive optimization ... ok could be "getFarPoint" ... but ... well ... ^^
(click to show/hide)
« Last Edit: May 25, 2016, 04:12:30 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #10 on: May 25, 2016, 04:13:20 pm »
You can subdivide big functions into several smaller ones if you want to get more detailed profiler results.
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Performance on Drawing Lightened Scene
« Reply #11 on: May 25, 2016, 04:23:56 pm »
You can subdivide big functions into several smaller ones if you want to get more detailed profiler results.

This gives me (with less aggressive optimization):
(click to show/hide)

So to say: getFarPoint() is my bottleneck?
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #12 on: May 25, 2016, 04:31:18 pm »
For sure ;)
Laurent Gomila - SFML developer

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Performance on Drawing Lightened Scene
« Reply #13 on: May 25, 2016, 04:35:44 pm »
For sure ;)
Ok but why? The code is:
sf::Vector2f getFarPoint(sf::Vector2f const& origin, sf::Vector2f const & pos, sf::FloatRect const& box) {
        // calculate normalized direction
        auto direction = pos - origin;
        auto norm = std::sqrt(direction.x * direction.x + direction.y * direction.y);
        direction /= norm;
        // calculate suitable distance
        auto dist = box.width * box.height;
        // create far point
        return pos + dist * direction;
}
I'd assume the calculation of the square root as most expensive .. floating point division could be expensive, too ... could. I don't know how to optimize at this point? Any ideas? :)
« Last Edit: May 25, 2016, 04:38:42 pm by Glocke »
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Performance on Drawing Lightened Scene
« Reply #14 on: May 25, 2016, 05:30:21 pm »
Well it's not the implementation itself, it's more the algorithm that calls it way too much. I'd say you should focus on optimizing your algorithm rather than the code itself.
Laurent Gomila - SFML developer

 

anything