Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to benchmark various ways to draw 2D lines and have a snag. A D3D10Device that I draw with (and flush) doesn't appear to block, so I can't accurately measure frame rate (or time to render 1 frame).

Here's some code

    // Inside my custom render context - at end of setting up draw calls
    public void Dispose()


            // Vertex buffer contains LineList with 200k vertices
            _direct3D10Image._d3d10Device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_direct3D10Image._d3d10Buffer, 32, 0));

            int targetWidth = _direct3D10Image._renderTargetTexture2D.Description.Width;
            int targetHeight = _direct3D10Image._renderTargetTexture2D.Description.Height;
            _direct3D10Image._d3d10Device.OutputMerger.SetTargets(_direct3D10Image.DepthStencilView, _direct3D10Image.RenderTargetView);
            _direct3D10Image._d3d10Device.Rasterizer.SetViewports(new SharpDX.Direct3D10.Viewport(0, 0, targetWidth, targetHeight, 0.0f, 1.0f));
            _direct3D10Image._d3d10Device.ClearRenderTargetView(_direct3D10Image.RenderTargetView, _direct3D10Image.ClearColor);
            _direct3D10Image._d3d10Device.ClearDepthStencilView(_direct3D10Image.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            // Shader is generating geometry based on line-list to render a 2D plot
            for (int i = 0; i < _direct3D10Image._technique.Description.PassCount; i++)
                    (int)(_linesCount * 2),

        // Flush doesn't appear to block - how to get meaningful time to draw out of SharpDX?

Now if I time the setup of draw calls and the Dispose method above, it reports 15ms to draw. However, there appears to be a significant lag between start of draw and the screen actually presenting.

How can I measure the time to present (or is it possible to make D3D10Device.Flush() blocking?)

share|improve this question
up vote 1 down vote accepted

Accurately measuring the performance of graphics API (D3D or OpenGL) calls isn't always a matter of timing the CPU-side code, because some of those CPU-side calls you're making could dispatch work to the GPU and block (or not) and the timing you get doesn't really account for that in a useful fashion.

This guide discusses some techniques for profiling D3D which are applicable (since you're just using a wrapper). You'll need to adapt them if you aren't using D3D9 but it's not that difficult as most of the discussion is conceptual: why profiling is hard, how correctly profiler the CPU aspect, and how to control driver optimizations and use the query APIs to get information about GPU-side performance.

share|improve this answer

Ok - I think I figured out what was going on.

My laptop has two graphics cards, an integrated Intel GPU and an nVidia 650GM. At the time when I saw lag after render I was using Integrated (possibly software emulation?). Anyway with nVidia enabled there is no delay in presenting, its pretty much instant (and a lot faster to boot!)

So I'm getting pretty accurate frame times measuring start of drawing instructions to _d3d10Device.Flush()

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.