Skip to main content
gamedev.net
🔒 Locked

Performance problem with D3d::Present()

Started by jiayi411 Mar 18, 2011 at 11:27 AM 4 replies 3.2k views
Original Post
jiayi411
jiayi411
I'm having a weired problem, it's related to Direct3dDevice9::Present(...).
the app's frame rate is changed slightly while moving mouse, but it's drawing the same objects and have the same render states changes,
i have profiling my app, i found that the frame rate is dropped only because the Present(...) functions takes more time,so why this happened, is there something else except render states that influence the performance?
This only occurred when drawing alpha blend objects.

Thanks in advance.






Erik Rufelt
Erik Rufelt
Do you draw anything at the mouse position or similar, so that something in your scene moves when you move the mouse?
If so, that's not very strange, as depth-testing and pixel-culling etc. can be changed.

Also, what framerates do you have?
If you go from 60 to 50, then that's a problem.
If you go from 600 to 500 it's only somewhat surprising.
If you go from 6000 to 5000 that is to be expected.

Moving the mouse sends messages to the window's message queue etc. which often adds an extremely small slowdown that shouldn't be noticeable when actually playing the game, but if you measure microseconds it can certainly show up.
jiayi411
jiayi411
Thank you Erik Rufeit.
Forget the mouse position, it's only used to rotate the camera.
I use vertical sync, so my top frame rate is 60.
when the camera changed a little bit, the frame rate will be changed a little bit. and this happened only in a particular position.
I thought it might related to depth-testing or pixel-culling, but it will drop from 60 to 45, is that possible?
Hodgman
Hodgman
60fps is 16.6ms -- If you're usually running close to 16.6, but drawing a little bit extra pushes that up to 16.7, then you will miss the VBlank, which means VSync has to wait for the next one -- this wait time will be spent inside "present" (this is a flaw with DX9 - present is always slow if you have VSync enabled and miss the VBlank period).

This will result in a sudden drop in performance. 45fps is half way between 30 and 60, which indicates it's possible that you're just over 16.6 -- it could be that every 2nd frame is missing the VBlank and dropping to 30 (and then 45 is the average some frames being 30 and others being 60).

Turn off Vsync and measure performance again.
jiayi411
jiayi411

60fps is 16.6ms -- If you're usually running close to 16.6, but drawing a little bit extra pushes that up to 16.7, then you will miss the VBlank, which means VSync has to wait for the next one -- this wait time will be spent inside "present" (this is a flaw with DX9 - present is always slow if you have VSync enabled and miss the VBlank period).

This will result in a sudden drop in performance. 45fps is half way between 30 and 60, which indicates it's possible that you're just over 16.6 -- it could be that every 2nd frame is missing the VBlank and dropping to 30 (and then 45 is the average some frames being 30 and others being 60).

Turn off Vsync and measure performance again.


Thank you for your answer, i learned from it.
I turned off vsync and the problem is the same. the frame rate is not from 60 to 40 in suddenly, but dropping little by little.
I'm wondering if the alpha blend cost most of the render time, so when more alpha blend object rendered, more times will be cost?
Zoner
Zoner
Alpha blending is typically twice as slow as when it is disabled, though the exact amount depends on what hardware you are running on.

In addition you should expect using an alpha test (or clip, or texkill from the olden days) won't save you anything at all, as the pixel shader has to execute first and its usually the bottleneck.
http://www.gearboxsoftware.com/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.