locked
C++ AMP and Direct2D

    Question

  • Is there a way to easily paint a buffer generated by C++ AMP code within the GPU on the screen without having to move the data into CPU memory?

    I tried creating a texture object from swap chain buffer but every time I try to write something there from AMP code, I get an error.

    Is it possible to create a bitmap or a brush that will be bound to a texture that AMP code will update?

    Sunday, March 17, 2013 4:59 AM

Answers

  • Jesse,

    I was trying to write to back buffer of the swap chain directly. As far as I understood, this can't be done, because usage flags that can be used when creating a back buffer texture are incompatible with ones that are needed by C++ AMP to manipulate the texture.

    I figured out another way: create a texture that can be used with C++ AMP, then create a IDXGSurface from that texture, then create a bitmap from that surface, then paint the bitmap on the D2D context. That works.

    However, in order to work with textures in C++ AMP you must create them on accelerator_view that is based on D3D device with DX11 feature set. Anything lower causes a fail when trying to create an accelerator_view. On the other hand, ARM based devices like Surface RT, only support DX9.3 feature set. So this method is unusable on these devices.

    I've tried the following method: create screen buffer in CPU RAM, map it to accelerator via array_view, run my C++ AMP code that generates the sceen buffer, then move the data back to CPU RAM by calling array_view.synchronize, create WICBitmap from the memory buffer, then create a D2D bitmap from WIC bitmap (this moves the data back to GPU where it just came from), then I can paint the bitmap on the D2D context. However because of all of the memory moving between CPU and GPU, this method yields only around 3 FPS on Surface RT...

    Monday, March 18, 2013 7:31 AM

All replies

  • Hi,

    What's the error did you get, and would you please provide us a reproduced codes?

    We can use C++ AMP in Windows Store App.
    http://msdn.microsoft.com/en-us/library/vstudio/jj856977.aspx

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 18, 2013 6:05 AM
    Moderator
  • Jesse,

    I was trying to write to back buffer of the swap chain directly. As far as I understood, this can't be done, because usage flags that can be used when creating a back buffer texture are incompatible with ones that are needed by C++ AMP to manipulate the texture.

    I figured out another way: create a texture that can be used with C++ AMP, then create a IDXGSurface from that texture, then create a bitmap from that surface, then paint the bitmap on the D2D context. That works.

    However, in order to work with textures in C++ AMP you must create them on accelerator_view that is based on D3D device with DX11 feature set. Anything lower causes a fail when trying to create an accelerator_view. On the other hand, ARM based devices like Surface RT, only support DX9.3 feature set. So this method is unusable on these devices.

    I've tried the following method: create screen buffer in CPU RAM, map it to accelerator via array_view, run my C++ AMP code that generates the sceen buffer, then move the data back to CPU RAM by calling array_view.synchronize, create WICBitmap from the memory buffer, then create a D2D bitmap from WIC bitmap (this moves the data back to GPU where it just came from), then I can paint the bitmap on the D2D context. However because of all of the memory moving between CPU and GPU, this method yields only around 3 FPS on Surface RT...

    Monday, March 18, 2013 7:31 AM