Win2D 0.0.19 – CanvasAnimatedControl improvements, new Win10 sample

Win2D version 0.0.19 is now available on NuGet and GitHub. Our team was still at partial capacity, so there aren’t a lot of big feature items, but we have a new release today nonetheless.

What’s new:

  • Optimizations in CanvasAnimatedControl for CPU utilization
  • Fixed a synchronization issue in CanvasBitmap load/save functions
  • Add a cool new webcam integration sample to ExampleGallery, CameraEffectExample, available to run on Windows 10
  • Documentation improvements
  • Infrastructure improvements for Win2D’s samples
  • A new helper in ExampleGallery for getting correct threading behavior of CanvasAnimatedControl
  • Pull request #81 from contributor nllsotools. (Thanks!)

Comments (9)

  1. juanpablogc says:

    Looks great, I think this is the team that shows and explains best the implementations they do. Thanks for your work I will take a look after I finish some projects

  2. P. Venkman says:

    As part of a Game engine, I created functionality that renders Tiles on a CanvasAnimatedControl. I used the CanvasBitmap for each of the tiles. There is one large bitmap, which is loaded once upon initialization and contains all tile images and move the frame over the one I need. The Tile Object knows which Bitmap and which Frame it should use and a TextureManager handles the drawing upon request. The pre-loaded bitmaps (just one for now) are stored in a Dictionary for easy retrieval.

    Each tile is rendered on screen with a Vector2 representing their position. Then I add a velocity Vector2 to get the tiles moving in a direction. Using a loop, I noticed that for 1,000 tiles everything runs smooth. But once I go to 5,000 a performance impact can be noticed (movement begins to stutter noticeably).

    I will be needing about 20,000 tiles to be rendered on (visible) screen at any one time. These tiles will be moving along the screen in any direction. What would be the best approach to accomplish this?

  3. What hardware are you running this on, what is the screen resolution, and how big are these sprites?

    Do you know how to tell if your workload is CPU or GPU limited?

    We have a backlog item (…/Backlog) to add a dedicated sprite rendering feature which we believe will be able to reduce CPU overhead for drawing very large numbers of sprites.  But that would only help if you are in fact CPU limited, so the first step is to understand more about the details of your situation.

  4. P. Venkman says:

    The CPU is a Intel 5Y10 CPU and seems to be about 25 – 30% utilized during execution of the test App. The resolution is 1920×1080 (Intel HD 5300 graphics card). I'll try running it on a more powerful machine, just in case… but CPU seems low enough. It's not the most powerful machine in the world, but still. In terms of rendering, I used the example code provided with the CanvasBitmap. I use the overloaded DrawImage that takes a rectangle to grab the right frame from the bitmap.

    Each Tile size doesn't seem to make any difference (I set it to 10×10 and 50×50 with the same result). VS Profiler shows the Render method is where most time/effort is being spent.

    Function Name Inclusive Samples Exclusive Samples

    Test.Game.Windows.exe 20,982 0 100.00 0.00

    dynamicClass.IL_STUB_WinRTtoCLR 18,095 0 86.24 0.00

    Test.Game.Objects.GameStatePlay.Render 18,093 137 86.23 0.65

    Test.Game.Objects.TileBase.DrawFrame 17,869 52 85.16 0.25

    Test.Game.TextureManager.DrawFrame 17,817 169 84.92 0.81

    [] 17,255 154 82.24 0.73

    [Microsoft.Graphics.Canvas.dll] 15,028 14,381 71.62 68.54

    StubHelpers::InterfaceMarshaler__ConvertToNative 1,377 1,377 6.56 6.56

    dynamicClass.IL_STUB_WinRTtoCLR 2,866 0 13.66 0.00

  5. How are you measuring this CPU usage?  That's a dual core CPU with 4 hardware threads, so if you're using a display that just totals CPU load across all threads, 25% could actually mean you are pegging one of the threads at 100%.  Or if your measurement looks only at actual cores, that would indicate you have a decent amount of CPU spare.

    1080p resolution is a lot of pixels to be animating on a notebook GPU, but the fact that changing tile size makes no difference suggests you probably aren't GPU limited.  To be sure, could you try running your test at a lower resolution?  (dock it in a smaller pane so it only covers say 25% of the screen)

  6. P. Venkman says:

    I ran one (very smooth) test with 1,000 bitmaps resulting in 1 core being 25-30% busy. And subsequently a test with 10,000 bitmaps that noticeably jitters (moving about 1 millimeter per movement), resulting in one core being about 50-60% busy. At 100,000 one core in the CPU was almost pegged and others rather busy. During the last test, the movement becomes slow and stepped (one move is several millimeters in length). When adding the canvas inside a smaller panel, I noticed no difference in CPU utilization overall.

  7. Does the framerate change when you reduce the panel size with 10,000 bitmaps?  (if you are GPU limited, this would not alter CPU usage but should boost overall perf)

    It is important to understand whether your bottleneck is CPU or GPU, because this determines possible remedies.  If you are GPU bound, drawing at a lower resolution is likely the best option, but if you are CPU bound there may not be much you can do other than wait for possible future sprite batch feature in Win2D  (or draw fewer bitmaps, of course).

  8. P. Venkman says:

    Drawing fewer bitmaps isn't an option in order to achieve what I want to do with the framework, but I'll try the lower resolutions some more. I do appreciate all the help! May I suggest adding an example to the collection regarding the use of many (moving) bitmap tiles? It has been an interesting exercise and I'd like to see how others would approach this code.

    Count me as a vote in favor of the Sprite Batch feature. I think there would be a lot of usage scenarios helped by this feature. Especially games. I'll add some more updates if I find out more.

  9. > May I suggest adding an example to the collection regarding the use of many (moving) bitmap tiles?

    The Particle System example is very close to that…

Skip to main content