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

Author Topic: window.display() getting stuck at some positions  (Read 3763 times)

0 Members and 1 Guest are viewing this topic.

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
window.display() getting stuck at some positions
« on: March 22, 2015, 12:43:31 pm »
Hi all,

I'm rendering a rather simple scene with some sprites and customized shaders. I'm using a View as a camera to scroll around the level.

For some reason, at some positions of the view, calling window.display() takes up to few seconds! I used counters to check and its not like I render more sprites or anything during those stuck frames. the exact same scene rendered 5 pixels to the left and it gets stuck. I move a few pixels to the right and its back to normal with FPS at 200+.

I tried everything - removing some of the sprites, changing the view, counting times... nothing! at some magic positions window.display just takes seconds to execute with no apparent reason. :(

How do I even tackle this problem? do you think its maybe a problem with my graphic card? (Radeon HD 6500, never had any problems with it before).

Any idea or help will be appreciated!
thanks.  ;)


zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: window.display() getting stuck at some positions
« Reply #2 on: March 22, 2015, 12:49:17 pm »
I can't post the code, sorry.
I can post only selected parts of it like the init part or the shaders. will that help? what part will help?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window.display() getting stuck at some positions
« Reply #3 on: March 22, 2015, 02:11:09 pm »
No one said to post your code, you need to post a complete and minimal example that shows the problem. So start by stripping out everything that doesn't cause the problem. Once you identified the problem post that code.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: window.display() getting stuck at some positions
« Reply #4 on: March 22, 2015, 03:20:55 pm »
The game is written with wrapper layer to SFML, customized sprite entity, and shaders. I can't reproduce it with simple sfml code. I tried.

believe me when I say - I really don't have any minimal example to post. If I had I put it.
but everything works super fast and it get stuck on window.display(), which as far as I know should only flip buffers. and as I said it only happens at certain spots, moving the view as much as 5 pixels from those spots and everything works great.

I disabled everything but the renderings (like physics etc.), but its still a lot of code.
I did notice that it only happens when using my shader.

so maybe let me rephrase the question:
1. what does window.display() actually do besides flipping buffers?  I checked the code and looks like eventually all it does is glCopyTexSubImage2D() so I don't see how it can get stuck? is there some magic inside I'm missing?
2. did you ever encountered a problem similar to this in the past?
3. how can I debug that function?
4. which steps should I do to figure out the problem?

thanks.

EDIT:
I debugged it to this point:
void WglContext::display()
{
    if (m_deviceContext && m_context)
        SwapBuffers(m_deviceContext);
}
 
in WglContext.cpp. SwapBuffers is what taking so long, but the debugger can't find the SwapBuffers() symbol. trying to figure out why..
« Last Edit: March 22, 2015, 03:35:12 pm by TheNess »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window.display() getting stuck at some positions
« Reply #5 on: March 22, 2015, 03:54:44 pm »
If you can't reproduce it with pure SFML code then the chance it is a problem with SFML is highly unlikely. Chances are much greater you are doing something in your own code wrong. And you can't 'debug' SwapBuffers because that is an OpenGL function (implemented in the GPU driver). So also check that your drivers are up to date.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: window.display() getting stuck at some positions
« Reply #6 on: March 22, 2015, 04:25:39 pm »
I disabled everything but the renderings (like physics etc.), but its still a lot of code.
Well, then instead of only disabling stuff, why not also reduce stuff? It doesn't have to be all or nothing. If you can't separate out sections of your rendering for testing purposes, you have more problems to worry about than something getting stuck every now and then.

1. what does window.display() actually do besides flipping buffers?  I checked the code and looks like eventually all it does is glCopyTexSubImage2D() so I don't see how it can get stuck? is there some magic inside I'm missing?
sf::Window::display() doesn't call glCopyTexSubImage2D(), sf::RenderTexture::display() does. Pick one and stick to it. If your window variable really calls glCopyTexSubImage2D(), then I suggest perhaps renaming it to renderTexture or similar so you don't confuse yourself any longer...

2. did you ever encountered a problem similar to this in the past?
No. And it is impossible that we encountered such a problem, because what you describe - "window.display() getting stuck" - isn't even the actual problem, it's what you think the cause of the problem is. There is a difference.

3. how can I debug that function?
You don't have to debug that function, you have to debug your own code. That function does what it's supposed to. Looking for the cause of a problem deep inside library code that functions properly is just a waste of time.

4. which steps should I do to figure out the problem?
Like zsbzsb and I have already said, reduce your code down to an example. The fact that you don't even consider the possibility of reducing your code to something that is reproducible in an example is preventing you from solving your own problem. Without such code, we can't do anything else for you but guess as well.

in WglContext.cpp. SwapBuffers is what taking so long, but the debugger can't find the SwapBuffers() symbol. trying to figure out why..
If this is your methodology of finding performance bottlenecks, you really need read a bit more on proper profiling techniques. Yes, it is true that a lot of time is probably spent in SwapBuffers() in your application, but that doesn't mean that you have to be able to look inside of it. SwapBuffers() is an operating system function that swaps the back and front framebuffers, so you obviously won't be able to debug inside of it.

If you had read a bit more about it, you might have probably seen that it is allowed to block if the OpenGL command queue is full, meaning the GPU needs more time to finish off all the operations you told it to perform. What are these operations? Everything you did, up to 3 frames ago. GPUs tend to run 3 frames behind the CPU, and if it starts to lag even further behind, SwapBuffers() will have to block.

How can your OpenGL command queue become so full? Easy: You just did too much "OpenGL stuff". If you keep track of how much "stuff" you are actually doing during your rendering, then you will know whether to expect framerate drops or not. You can't expect the GPU to render a frame with 100000000 commands in the same time as it does 10000 commands. The key to understanding why it takes so long is to understand what you are doing.

There is no "magic", the more work there is, the longer it takes. It's that simple. SFML doesn't create any extra work, OpenGL doesn't either. Only you control how much work is being produced.

The first step to solving this problem is to understand your own code. Show us that you do by reconstructing it in a minimal example and you might even solve the problem yourself while doing it.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
I read some about SwapBuffers() and saw it was GL func.

If you can't reproduce it with pure SFML code then the chance it is a problem with SFML is highly unlikely. Chances are much greater you are doing something in your own code wrong. And you can't 'debug' SwapBuffers because that is an OpenGL function (implemented in the GPU driver). So also check that your drivers are up to date.

dude stop being so defensive. I never once said it was an SFML bug nor have I implied it. I KNOW its my bug but since its effect happens in SFML part I need help solving it. all you did was trying to "prove me wrong" instead of actually helping. next time I will include in the question title "THIS IS MY BUG NOT SFML" to get some help around here.  :-\

...If you had read a bit more about it, you might have probably seen that it is allowed to block if the OpenGL command queue is full, meaning the GPU needs more time to finish off all the operations you told it to perform. What are these operations? Everything you did, up to 3 frames ago. GPUs tend to run 3 frames behind the CPU, and if it starts to lag even further behind, SwapBuffers() will have to block...

thank you this was actually very useful. I did read a little about SwapBuffers but I missed that part.


zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: window.display() getting stuck at some positions
« Reply #8 on: March 22, 2015, 05:39:22 pm »
dude stop being so defensive. I never once said it was an SFML bug nor have I implied it. I KNOW its my bug but since its effect happens in SFML part I need help solving it. all you did was trying to "prove me wrong" instead of actually helping.

Chill out dude, I'm not being defensive, just stating facts. And when you go spelunking into other libraries code using a debugger you are implying you think there may be something wrong. That is the way most people will take it. Heck, you were even trying to debug the SwapBuffers function. As for not helping, I already told you what to do which is to provide a complete and minimal code example that shows the problem. Otherwise we can't do much but discuss what could be causing what.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

TheNess

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: window.display() getting stuck at some positions
« Reply #9 on: March 22, 2015, 05:53:14 pm »
if you see debugging a function as a personal assault on your code, then yeah, you are kind of defensive mate.
thanks anyway
« Last Edit: March 22, 2015, 07:02:44 pm by TheNess »

 

anything