locked
Questions about combining XAML/c# with DirectX

    Question

  • Hi,

    For an astronomy app where you render the skymap on only one screen, and the remaining screens/pages are just regular modern UI style coded in c#, are these three methods listed here the correct way to combine c# xaml with DirectX rendering?

    http://blogs.msdn.com/b/windowsappdev/archive/2012/03/15/combining-xaml-and-directx.aspx

    1. SurfaceImageSource

    2. VirtualSurfaceImageSource

    3. SwapChainBackgroundPanel

    Basically I only need to render the one screen and I think it will be a full screen using Direct3D.

    So I was thinking scenario #2 and 3 were the best option, maybe with the #3 being best.

    Is this correct?

    Also can someone please explain this part?

    "we impose a couple restrictions on the SwapChainBackgroundPanel: it must be the root XAML element of your app, and a few inherited XAML properties,"

    Does this apply to the entire app, or just the page I want to render using DirectX? Each page has it's own XAML so I'm kind of confused about what is meant by the root element.

    Tuesday, May 28, 2013 12:50 AM

Answers

  • Hi Sal,

    Your choice really does come down to your rendering needs.  If your imagery is fairly still, then the SurfaceImageSource would be easier (by far) I'm sure.  I'm sort of an astronomy buff, and a fan of programs like Starry Night.  If your thinking that sort of panning/zooming, with text, ecliptic guides and such... I'm sticking with the SwapChainBackgroundBuffer.

    I read the "impossible" post, and believe there is a flaw in the logic that the SwapChainBackgroundBuffer is the root element... it is the root, but of a Page.  Swap the page, the SwapChainBackgroundBuffer gets no signals... I still think its doable if you are so inclined.

    I went searching, and I found this post:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/298a7076-51b9-4482-8e1c-1f06ffc98350

    It's Direct2D, but the important part is there is some incomplete sample code of someone who is doing just that... Multiple pages with one having a SwapChainBackgroundBuffer.

    Hope this helps,

    Jim

    • Marked as answer by Sal_S Thursday, May 30, 2013 3:05 AM
    Thursday, May 30, 2013 2:57 AM

All replies

  • Hi Sal,

    I can only comment on the SwapChainBackgroundPanel, as I have a game that uses it.  I picked it because my app was predominantly DirectX (a game), with XAML elements.

    Here's my take on "we impose a couple restrictions on the SwapChainBackgroundPanel: it must be the root XAML element of your app, and a few inherited XAML properties,":

    There’s an online sample called “XAML DirectX 3D shooting game sample (Visual C++)” that uses a SwapChainBackgroundBuffer.

    If you look at the file “MainPage.xaml”, you’ll see that the only child of the Page is a SwapChainBackgroundPanel, (so what that really means in my eyes is that the panel must be the direct child of the page.)  The page will then send a “60fps-ish” tick to the panel telling it when to update, which is when you draw the 3D.  All the XAML elements (which are children of the SwapChainBackgroundPanel) are drawn over the top... always.

    The part about “a few inherited XAML properties” would include “not specifying a height and width”, and using the inherited page height and width (the whole screen).

    As far as your question about if the panel applies to the entire app or just the page, I can only guess that it means for the page, since the SwapChainBackgroundPanel is a XAML element on the page, but I’ve never tried to show an alternate page in my game, and instead just have multiple XAML panels I overlay that are all typically in the Visibility::Collapsed state.  (Not strongly recommending this method, my alternate page UI needs were small.)

    Good luck,

    Jim

    Tuesday, May 28, 2013 8:51 AM
  • thank you for your reply.  I guess my next question is, does this approach (swapchainbackgroundpanel) work for an application that is predominantly XAML and multiple pages, with only one part that is DirectX?  

    I just want to be sure I'm using the correct approach in my app, before spending time coding.

    Tuesday, May 28, 2013 10:51 PM
  • Hi again Sal,

    Ok, I know this is not answering your lingering question about multiple pages, but this page gives a great short description to further your hunt on which of the 3 types of DX surfaces you want (from your original question.)

    http://msdn.microsoft.com/en-us/magazine/jj991975.aspx

    I think that if nothing else, this will completely rule out SurfaceImageSource from your options, as the author states this is for "relatively static content", which would lead me to rephrase that as "slow zoom and pan speed for a star field".

    Also, if a better answer does not pop up on the multiple pages question, I'd vote for trying your plan.  The SwapChainBackgroundBuffer gets it's time to process from the XAML page, so it would be my guess that as long as the page is not showing, your going to be ok.

    I'm hoping someone answers your question.  I'd really like to know the answer to that to.

    Jim

    Wednesday, May 29, 2013 7:42 AM
  • I would actually go in the opposite direction from HeadRoach! My WinRT app uses a SwapChainBackgroundPanel and works fine but if I had to do it over again I would probably start with a SurfaceImageSource. Why? Because in the WinPRT (WinPhone8) version of my app I used WP8's DrawingSurface control for D3D content instead of DrawingSurfaceBackgroundGrid control and it had plenty of performance for my app.

    I imagine an astronomy app would be similar to mine, where there isn't high speed animation going on (like in a game) but rather interactive rendering (panning and zooming with fingers/mouse) of largely static content. Interactive rendering doesn't need to be nearly as fast as animation.

    Wednesday, May 29, 2013 4:09 PM
  • Hi again Sal,

    Ok, I know this is not answering your lingering question about multiple pages, but this page gives a great short description to further your hunt on which of the 3 types of DX surfaces you want (from your original question.)

    http://msdn.microsoft.com/en-us/magazine/jj991975.aspx

    I think that if nothing else, this will completely rule out SurfaceImageSource from your options, as the author states this is for "relatively static content", which would lead me to rephrase that as "slow zoom and pan speed for a star field".

    Also, if a better answer does not pop up on the multiple pages question, I'd vote for trying your plan.  The SwapChainBackgroundBuffer gets it's time to process from the XAML page, so it would be my guess that as long as the page is not showing, your going to be ok.

    I'm hoping someone answers your question.  I'd really like to know the answer to that to.

    Jim

    Actually I posted the question on Stack Overflow and this is the response I got

    http://stackoverflow.com/questions/16805283/is-it-possible-to-add-single-full-screen-page-of-directx-to-a-xaml-c-windows-8/16813634#16813634

      

    "It's unfortunately impossible at the moment with SwapchainBackgroundPanel, because your root visual element must be the SwapChainBackgroundPanel. (and add your other UIElements, frames, widgets etc. on top). You can achieve this with SurfaceImageSource, but at the cost of much more memory bandwidth (and most ARM based devices lack decent memory bandwidth).

    Windows 8.1 leaked info and dumps of the 8.1 winmds seem to indicate that this is going to change soon however :)." 

      

    So it seems I'm back to square one.  I'm not sure which approach to take now.  I'm not exactly building a regular XAML app, and I'm not building a game, but something sort of in between.  Not sure what's the best approach.



    • Edited by Sal_S Wednesday, May 29, 2013 11:17 PM
    Wednesday, May 29, 2013 11:16 PM
  • I think your best option is the SwapChainBackgroundPanel.  It will give you the best performance on a full page.  You can have XAML controls that overlay your star map.

    Although I don't have direct experience with this, it appears that it is possible to navigate between your DirectX page and standard XAML pages, although you cannot use the usual navigation mechanism.  See Direct2D and XAML app with multiple pages.

    The SurfaceImageSource is more for a scenario which you have a page that is predominately XAML controls with an embedded window containing a DirectX window.

    Wednesday, May 29, 2013 11:32 PM
  • Hi again Sal,

    Ok, I know this is not answering your lingering question about multiple pages, but this page gives a great short description to further your hunt on which of the 3 types of DX surfaces you want (from your original question.)

    http://msdn.microsoft.com/en-us/magazine/jj991975.aspx

    I think that if nothing else, this will completely rule out SurfaceImageSource from your options, as the author states this is for "relatively static content", which would lead me to rephrase that as "slow zoom and pan speed for a star field".

    Also, if a better answer does not pop up on the multiple pages question, I'd vote for trying your plan.  The SwapChainBackgroundBuffer gets it's time to process from the XAML page, so it would be my guess that as long as the page is not showing, your going to be ok.

    I'm hoping someone answers your question.  I'd really like to know the answer to that to.

    Jim

    Actually I posted the question on Stack Overflow and this is the response I got

    http://stackoverflow.com/questions/16805283/is-it-possible-to-add-single-full-screen-page-of-directx-to-a-xaml-c-windows-8/16813634#16813634

      

    "It's unfortunately impossible at the moment with SwapchainBackgroundPanel, because your root visual element must be the SwapChainBackgroundPanel. (and add your other UIElements, frames, widgets etc. on top). You can achieve this with SurfaceImageSource, but at the cost of much more memory bandwidth (and most ARM based devices lack decent memory bandwidth).

    Windows 8.1 leaked info and dumps of the 8.1 winmds seem to indicate that this is going to change soon however :)." 

      So it seems I'm back to square one.  I'm not sure which approach to take now.  I'm not exactly building a regular XAML app, and I'm not building a game, but something sort of in between.  Not sure what's the best approach.

    I wouldn't worry about the performance. As I mentioned in my previous reply, even on a WinPhone8 device I get great full screen performance using something similar to SurfaceImageSource. And Win8 devices generally have superior CPU and graphics performance to WinPhone8 devices. You're basically rendering to a texture and that texture will be blitted to the screen during composition, which is highly optimized on GPUs.

    I would whip up a quick test app using SIS and see if it meets your performance needs. I think it will.

    Thursday, May 30, 2013 1:22 AM
  • I agree with henador that the performance of SurfaceImageSource may be 'good enough' and the interop is easier.

    If you start with SurfaceImageSource and decide that you need more performance, much of the DirectX code can be reused in a SwapChainBackgroundPanel implementation.

    Thursday, May 30, 2013 2:08 AM
  • Hi Sal,

    Your choice really does come down to your rendering needs.  If your imagery is fairly still, then the SurfaceImageSource would be easier (by far) I'm sure.  I'm sort of an astronomy buff, and a fan of programs like Starry Night.  If your thinking that sort of panning/zooming, with text, ecliptic guides and such... I'm sticking with the SwapChainBackgroundBuffer.

    I read the "impossible" post, and believe there is a flaw in the logic that the SwapChainBackgroundBuffer is the root element... it is the root, but of a Page.  Swap the page, the SwapChainBackgroundBuffer gets no signals... I still think its doable if you are so inclined.

    I went searching, and I found this post:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/298a7076-51b9-4482-8e1c-1f06ffc98350

    It's Direct2D, but the important part is there is some incomplete sample code of someone who is doing just that... Multiple pages with one having a SwapChainBackgroundBuffer.

    Hope this helps,

    Jim

    • Marked as answer by Sal_S Thursday, May 30, 2013 3:05 AM
    Thursday, May 30, 2013 2:57 AM
  • Thanks again for your help.  I will try it.
    Thursday, May 30, 2013 3:10 AM