September 5, 2014 10:18 am

Introducing Win2D: GPU accelerated 2D graphics programming in the Windows Runtime

This blog was written by Shawn Hargreaves, Principal Dev Lead at Microsoft.

Today I’d like to share some information about work we are doing to make hardware accelerated 2D graphics APIs available to C# developers.

Win2D is a Windows Runtime API we’re working on to expose the power of hardware accelerated Direct2D graphics to Universal App (Windows 8.1 and Windows Phone 8.1) developers – very much a work in progress. The Windows Runtime supports several major programming languages (including C# and C++) to allow developers to leverage their existing skills and assets, provide a thoughtful and consistent API surface and be deeply integrated into the developer tool chain. Today, building a Windows Store app using DirectX requires native C++ and DirectX APIs that have been made available to the Windows Runtime. This model is more complex than the usual Windows or Windows Phone app because it provides flexibility and access to system resources at the expense of simplicity. As a result we have received consistent requests from the developer community for access to DirectX through C#, graphics solutions similar to System.Drawing, XNA and SharpDX. These solutions have different audiences, ranging from developers of line of business apps to 2D and 3D game developers. System.Drawing provides immediate mode 2D rendering in GDI+ through .NET but is not hardware accelerated and is unable to keep up performance-wise for today’s graphics needs. Win2D is our attempt to give developers more of what they’re asking for.

Win2D’s design makes it easier for a C#/C++ developer to use the full capabilities of the Direct2D API without it feeling like a walled garden. These APIs can be used with XAML to produce beautiful graphics apps with rich UI. The API is in the early stages of development and we have a minimal set of 2D drawing functionality already implemented. By no means is the API in its current state a complete representation of Direct2D in Windows Runtime. We believe that releasing the API early, even if it does not have all the Direct2D features, is useful. As a developer and potential user of the API you get the chance to influence the API design early and ultimately help build the best C#/C++ Windows Runtime 2D immediate mode rendering API.

Get your hands on Win2D here: https://github.com/Microsoft/Win2D

It may be useful to understand some of our design principles as you explore Win2D and start to formulate your feedback:

Principle #1: Our design philosophy states anything that is possible with the Win2D should also be possible with the underlying DirectX API. This means that no new “feature work” will be added to Win2D that is not already present in the native API. This keeps us honest about the role of the Win2D work as a means to expose the existing functionality to a broader set of developers.

Principle #2: Our second design philosophy is to provide a surface area that is much easier to use without being a sandbox. This means that a C# developer can access native DirectX APIs when need be or can accommodate already existing DirectX code in a Windows Store app.

Principle #3: Our third design philosophy is to share our code and progress with the open source community. Most of the interesting choices are made in the design of the Windows Runtime Direct2D APIs and not in their implementation. For this reason, we want to engage early with the developer community and gather feedback iteratively. We will share our feature backlog with the community to provide insight into upcoming features and their order. If you would like to see a feature light up early, we want to know about it.

If you want to write your next 2D game, data visualization app, image filter or anything else under the sun that requires 2D immediate mode rendering in C#/C++, we’d love to hear what you think of Win2D. As of today you can begin to combine your rendered content using Win2D with flexible user interface framework offered by XAML. This interop is now made seamless instead of requiring native C++ (and access to smart pointers and the C++ component extensions).

You can follow the progress of the project and learn more about it on its blog: http://blogs.msdn.com/b/win2d/

 

Updated November 7, 2014 11:26 pm

Join the conversation

  1. The fatal flaw in this introduction for us and our data visualization application is the requirement that it be used by a Windows Store app. Why isn’t this app-style agnostic and available to desktop devs too?

  2. Yes, always wonderful to see all the innovation on the Windows dev platform going into Metro/Modern/Store apps when us desktop application developers (who are responsible for making Windows into the cash cow it is today) are still using 22-year-old MFC because WPF was a fail. We need XAML+native code+D2D for the desktop world.

  3. I would love to use this on the desktop. Any plans to make it available there? Glad to hear you are still working at MS Shawn, your XNA blog was and still is very useful!

  4. Please, implement ability of software rendering to a bitmap on windows phone! This is available in desktop Direct2D, but for some strange reason not for phone. There are many cases when software rendering in background without loading the GPU is a must have. In my case this is custom map tiles rendering on the phone.

  5. Do these Windows store apps still need to have a license? I didn’t mind the license if was just once, but the thing is basically NagWare, constantly begging to be done again! Please have them stop this, it has driven so many developers away!!!

  6. thank you Shawn Hargreaves. for the hardware api for c#,, but ?

    2 years ago i try this and the overhead between directx and c# is to big.. compare to opengl c#
    so i did this for xna bare metal move the math into the shader pipeline , CG , glsl,hlsl all vorking out of the box
    and from the old kit
    you now the Effect World,View,Projection is 64bytes transfere per matrix to the graphics card every frame times 3 = 192 bytes transfere just for the math and every thing the developer might use as well + that

    now xna bare metal is a
    16bit depthbuffer and 16bit normal compressed into an 8888bit texture rendertarget
    16bit vector3float for rotate,scale,translate = 18 bytes transfere per frame
    the view 18 bytes transfere and the projection 8 bytes transfere , for projection2D there is only 2 bytes transfere
    all running on gpu

    the frustrum is allso sorted out by the gpu, we offload a small 8888bit texture with info (ModelID , LevelOfDetail(value=1,2,3) , alpha , Collision_Hit_Info = value 1,2,3)

    and this give the speed of 17 times faster than the current XNA,MonoXNA
    so i have abstracted the GPU all the way up Managed world inside these VM = Microsoft ,Mono , Dalvik , Apple Swift

    the content pipeline is replaced by the new .Net c# API from Autodesk Maya ,3DSMAX two convert models

    the size of xna is reduce by 70% compare two your old kit

    this will give you some hint before release of what you at microsoft need two do
    and remember to optimize the driver for vertex processing like nvidia has done on the K1 Jetsons = AndroidTV the new C-64

    Shawn use the power that is written here or Microsoft will never get the developers back again..

    and for you two understand as a company,, when you create an API(Microsoft,AMD,EA) The mantle,, you have created an exlusive gamen kit for the elite and gave an 10 years old framework directx two your indie developer,, AND KILLED XNA ,,what do you think here

    ANTITRUST..

    and it is comming from all the people that have invested jobs and moeny into platform all the way back from the tom miller times
    for us it is about 750.000 dollars, that was the price for us to pay,, and now the last payment has been done,, so will will rise again..

    and then if you accuse someone of been a hacker, and these 3 hoppyist gamemakers, strike luck on your platform, do not block them
    but pacth them on the back,, and help them to bring there game to the more revenue that is the role of an platform holder
    and the platform holder does not compete with there indie developers, Microsoft you have all the dollars you need,, but what you do not have is market share
    you need to sell devices.. en d of that

    and when you kill your ownblood you are doomed, and that was the failure of converting all there new users on mobile into a joystick

    a beta is comming from our beta testers, soon than you might know,, it will strike so hard that you will learn..

    this is my destiny to release this,what is yours destiny

    Best Regards
    Michael Hansen

  7. Metro is neat and all, but for a lot of us it’s nothing but a meager toy that we’re not interested in playing with. All my serious app development has been and will continue to be for desktop.

    Can this be ported to desktop as well?

  8. I must admit that I laughed when I read this post.
    Either the author is kept completely in the dark by Microsoft or he pretends that he does not know that WPF exists. System.Drawing is mentioned like it is what we have today and are still using Windows Forms.
    I know you do not care at Microsoft but what we need is not a Win2D for Metro/Modern/Store. We need improvements for the rendering in WPF. It is amazing how much energy is put into other areas then the desktop.

    • @Morten Kristiansen WPF has always had similar way of fast enough drawing which is called DrawingContext. On the other side, WinRT UI API lacks such kind of API, having only very high-level Shapes and very low-level unmanaged DirectX (2D/3D). So its understandable that MS decided to fill this gap, creating some middle level API similar to DrawingContext. Of course, DrawingContext is still “retained mode” compared to Win2D’s “immediate mode”, but its still quite fast and should satisfy most desktop application requirements.
      To add more, its not a big secret that WinRT components can be used within desktop applications. While you can’t get a CoreWindow in WPF (around which Win2D revolves), there are nice DirectX interop abilities in both WPF and Win2D, so you will probably be able to make Win2D and WPF friends.

  9. I have already begun switching my 2D XNA project to Win2D! WHAT!?! This is A-MAZE-ING! Plus the UI options will be super helpful. I am looking forward to new features that will help streamline my game.

    • Isaac, how difficult has the transformation been from XNA to Win2D? I have an entire framework built on XNA, and I really am getting tired of rewriting my framework/engines to suit the next “new” thing. XNA was great and I sure do miss it.