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

Author Topic: RenderWindow lags occasionally for up to 100ms  (Read 5387 times)

0 Members and 1 Guest are viewing this topic.

jerrymk

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
RenderWindow lags occasionally for up to 100ms
« on: April 09, 2021, 10:33:55 am »
UPDATE!!
Turned out I was using in built Intel graphics, changing it to dedicated graphics card kinda solved it... taking around 5ms, let me know if this is normal (for something like GeForce 840M low end graphics card) it now goes like 60 fps on 800*600 and 1920*1080, 25 fps on 1920*2160.

Now displaying takes 5 times the time it draws... more reasonable, but I'd like more if possible (It's just a few triangles (1000), and only one draw call... maybe my graphics card is just REALLY BAD)

Main profiler - new loop: 1
Main profiler - poll events: 13
Main profiler - graphene movement test: 6
Main profiler - graphene spawn element: 242
Spawn layout generator: 2
       Generate layout: 303
                                        Triangles: 1016
                  Draw: 1601
               Display: 174618
5fps

This is the timings of each part of game loop using sf::Clock.
poll event took 13us
generating vertex array with my own function with 1016 triangles took 303us
drawing a single vertex array to the renderwindow took 1601us

However window->display() took up to 174ms, well over 20ms most of the cycles.

Here is a sample of time window->display() took for a few cycles:
(click to show/hide)

As you can see, there is a few cycles that displayed very fast.

I tried vsync, framerate limit...

Here is the code for window displaying:
void renderUI() {
                LayoutGenerator layoutGenerator(this);
                layoutGenerator.generateLayout(_rootElement, Vector2f(0, 0), Vector2f((float)_window->getSize().x, (float)_window->getSize().y));
                _window->draw(layoutGenerator.getVertexArray()->getBuffer(), layoutGenerator.getVertexArray()->getSize(), sf::Triangles);
                _window->display();
        }

Edit:
And the slowness is worse when maximized to 1920*1080, 90% of the cycles take over 100ms to do window display, while 5-10% is less than 2ms
Data above is on 800*600

And window.clear does not solve it, I don't think I need it anyways

Update:
The context settings was ContextSettings(0, 0, 4, 0, 4, 0, false); (anti-aliasing level 4)
And turn it down to 0(no aa)@800*600 made it go 30fps on average (30ms window.display time)
full screen 1920*1080 with no aa is still 100ms+
Although without aa 800*600 feels much smoother (mainly because of less stutter, not faster framerates), but still really bad. How can I fix it? I already turned off multi threading on my graphics driver.

« Last Edit: April 09, 2021, 10:50:52 am by jerrymk »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: RenderWindow lags occasionally for up to 100ms
« Reply #1 on: April 09, 2021, 11:06:11 am »
Since you didn't provide a complete and minimal example, who knows what you're rendering exactly, or how you calculate your timings and whether that runs okay. ;)

The initial time list, seems very weird and I'd nearly claim the calculation is wrong. I at least have never seen such irregular jumps between 10fps and 400fps and anything in between.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/