0
\$\begingroup\$

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()
    {
        {
            _vertexBufferStream.Close();

            _direct3D10Image._d3d10Buffer.Unmap();

            // 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++)
            {
                _direct3D10Image._pass.Apply();
                _direct3D10Image._d3d10Device.Draw(
                    (int)(_linesCount * 2),
                    0);
            }
        }

        // Flush doesn't appear to block - how to get meaningful time to draw out of SharpDX?
        _direct3D10Image._d3d10Device.Flush();
        _direct3D10Image._dx10ImageSource.InvalidateD3DImage();
    }

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?)

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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()

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .