Re: Fixed Framerate

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Robert Dunlop [MS MVP] (rdunlop_at_mvps.org)
Date: 01/30/05


Date: Sat, 29 Jan 2005 20:01:36 -0800


"Teis Draiby" <teisREMOVE-THIS@draiby.com> wrote in message
news:u$NZvdmBFHA.3524@TK2MSFTNGP15.phx.gbl...
> For my (windowed) application that has a lot other tings to do than 3D, I
> could set a 'PresentationInterval.Two'-value to make D3D only process
> every
> second frame and still maintain a 36 fps framerate on a standard monitor.
> Thus saving processing time for the rest of the app.

Note that presentation intervals of two or higher require that the driver
support this. If it is supported that could work, as long as you flag
SwapChain.Present not to wait or you may be spinning for an extra frame
(meaning over 50% of time spent spinning in driver assuming your app could
render every refresh to begin with). An alternative would be to throttle
the framerate yourself by calling Present() no earlier than 1/36th of a
second after the last successful call to Present, and using a presentation
interval of one.

> But if this MSDN quote
> applies to the use of SwapChain.Present() it is not possible (if
> windowed):
> MSDN:
> "For a windowed swap chain, this value must be PresentInterval.Default
> (0).
> For a full-screen swap chain, it can be PresentInterval.Default or the
> value
> that corresponds exactly to one of the flags enumerated in Present."

Searching MSDN, the only place I seem to find this is in archived copies of
the managed DX documents (which unfortunately had a bit of catching up to
do). Here's the current docs for PresentationInterval:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/e/presentinterval/presentinterval.asp?frame=true

Note in the description of Immediate: "This option is always available for
both windowed and full-screen swap chains."

> Seems like a 'waste' of a good opportunity to cut 3D processing time.
> Maybe I got the concepts wrong...

In addition to using the DoNotWait flag, a bit of re-ordering can help
matters here. Two things to take into account:

1. After EndScene() has been called, there will be some period of time
before Present() can succeed, even with a presentation interval of
Immediate. EndScene() simply tells D3D you are done sending commands, but
the GPU may still be rendering primitives you uploaded between BeginScene()
and EndScene().

2. After Present() returns successfully, on the other hand, the GPU is
ready to start rendering the next frame.

Thus you can squeeze in other non-D3D processing between EndScene() and
Present. Performing other tasks during this time helps increase performance
because the CPU can be doing other things while the GPU finishes up. So
instead of:

Render()
   (i.e. BeginScene Render EndScene Present)
DoAppStuff

instead try:

Render()
  (just: BeginScene Render EndScene)
DoAppStuff
Present()

-- 
Robert Dunlop
The X-Zone
http://www.directxzone.org/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not 
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation 
with Microsoft. 


Relevant Pages

  • Re: Tearing in Direct3D with TFT/LCD-Display
    ... render a frame faster then the monitor refresh. ... In short if you run at 60hz, you will need to have a scene that can render ... > Enabled and disabled VSYNC for Direct3D (and yes, ... > // Get the owner window ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: "Direct3D9: (ERROR) :Error trying to lock driver surface" error when using VMR9
    ... I have to use a separate render loop (not presenting in AP's ... This error comes out even when not using the texture! ... while the 3d render engine doesnt ask for a frame: ... texture from the buffer and signal a new texture in the buffer ...
    (microsoft.public.win32.programmer.directx.video)
  • Play Video without Blank while Rendering.
    ... How to Play Video Files without Black Frames, ... i am using DirectShow to play video files in VB6 ... i could render 2 files together and switch one by one, ... capturing last frame of previous video and show it till we render Next ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: my opengl progs - ZX & nonZX themed
    ... It takes ages for them to render one frame! ... Modern computer outlets are boring and cheap. ... expensive in meanings of time and really cheap in meanings of electric ...
    (comp.sys.sinclair)
  • Re: "Direct3D9: (ERROR) :Error trying to lock driver surface" error when using VMR9
    ... I have to use a separate render loop (not presenting in AP's ... I've tried using double buffering (rendering with a texture, ... while the 3d render engine doesnt ask for a frame: ...
    (microsoft.public.win32.programmer.directx.video)