Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF DrawingVisual performance on some machines
    primarykey
    data
    text
    <p>I am developing an application which needs to draw around 70k rectangles in form of a grid (one grid 40x250 and one 250x250). Not all rectangles will be visible on a screen at the time.</p> <p>After reading <a href="http://msdn.microsoft.com/en-us/magazine/dd483292.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/dd483292.aspx</a> I created simple control (inherits from FrameworkElement, parts are listed below) which uses DrawingVisual descant to create one column of rectangles.</p> <pre class="lang-cs prettyprint-override"><code>// Removing items after collection change private void RemoveItems(IList oldItems) { foreach (var oldItem in oldItems) { var visualChild = _visuals.FirstOrDefault(v =&gt; v.Data == oldItem); if (visualChild != null) { _visuals.Remove(visualChild); RemoveVisualChild(visualChild); } _translateTransform.X -= 8; } } // Adding items after collection change private void AddItems(IList newItems) { foreach (var newItem in newItems) { var newArray = (byte[]) newItem; var visual = CreateVisual(newArray); _visuals.Add(visual); AddVisualChild(visual); _col++; } } // Creating visual element private StripeVisual CreateVisual(byte[] data) { var result = new StripeVisual { Data = data, Transform = _translateTransform }; using (var dc = result.RenderOpen()) { for (int i = 0; i &lt; data.Length; i++) { dc.DrawRectangle(_brushes[data[i]], _strokePen, new Rect(_col * 8, i * 20, 8, 20)); } } return result; } </code></pre> <p>All brushes are frozen (members of <code>Brushes</code> class) and <code>_strokePen</code> is frozen. New vertical stripe is added to collection every 200ms.</p> <p>Program has been run on 3 computers:</p> <ol> <li>Notebook: i7-2670QM, GeForce GT 540M/Intel HD Graphics 3000, 4GB RAM, Win7 x64, DirectX11,</li> <li>PC: Core2Duo E7400, Radeon HD 4800, 3GB RAM, Win7 x64, DirectX11,</li> <li>PC: i3 3,07GHz, Inter HD Graphics, 3.3GB RAM, Win7 x86, DirectX11.</li> </ol> <p>The problem is that on my first computer program runs smoothly and without big impact on CPU (usage between 1-10%). On both second and third computers programs performance is unacceptable: with about 30x100 grid it takes up to 50% of processor and everything runs very slow. Program runs slowly even when only small part of grid is visible.</p> <p>It looks like program is using software rendering (rendering thread is using 50% of processor), but <code>RenderCapability.Tier >> 16</code> returns 2, and <code>RenderOption.ProcessRenderMode</code> is set to <code>Default</code>. Also there is no key in <code>[HKCU/Software/Microsoft/Avalon.Graphics]</code> that would disable hardware acceleration.</p> <p>Is it possible to run this application smoothly listed computers? What else can I do to maximize performance of this program?</p> <h1>Update</h1> <p>Setting <code>DrawingVisual.CacheMode = new BitmapCache();</code> helped a lot. Does it mean that CPU&lt;=>GPU communication was the bottleneck?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload