JoeTaicoon
JoeTaicoon

Reputation: 1567

Write to DX11 backbuffer from C++AMP

According to this ms blog post http://blogs.msdn.com/b/nativeconcurrency/archive/2012/07/02/interop-with-direct3d-textures-in-c-amp.aspx

You can write directly to the backbuffer from C++AMP.

Using Interop, you can get the texture object of the back buffer associated with the window using the IDXGISwapChain and update it directly in the C++ AMP kernel.

I created an amp device descriptor from the dx device and I got a pointer to the backbuffer and then tried to make an amp texture from it, but I found that the texture descriptor bindFlags, of the backbuffer, were only D3D11_BIND_RENDER_TARGET and I needed at least D3D11_BIND_UNORDERED_ACCESS or D3D11_BIND_SHADER_RESOURCE in order for Concurrency::graphics::direct3d::make_texture to function.

I can easily enough make any other d3d texture and connect that to amp, if I set the bindflags, but for the flags set on the backbuffer, I cannot connect them.

Then I find this post http://social.msdn.microsoft.com/Forums/vstudio/en-US/15aa1186-210b-4ba7-89b0-b74f742d6830/c-amp-and-direct2d

which has the following marked an an answer by a Microsoft community contributor

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.

So, on one hand, it (writing to backbuffer from c++AMP) is used an an example of interop and on the other hand it is explained to not be possible...?

My current requirement is just to generate a raytraced image in C++AMP and show that on a d3d display without copying data back from the graphics card every frame. I realize that I could just generate my own texture and then render a quad with that, but it would be simpler writing directly to the backbuffer, and if it can be done, that is what I would like to do.

Perhaps someone here can explain if it can be done and what steps are required to accomplish this, or alternatively explain that no, this truly cannot be done.

Thanks in advance for any help on this topic.

[EDIT] I now found this info https://software.intel.com/en-us/articles/microsoft-directcompute-on-intel-ivy-bridge-processor-graphics

// this qualifies the back buffer for being the target of compute shader writes sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_UNORDERED_ACCESS | DXGI_USAGE_SHADER_INPUT;

I actually did try that previously, but the call to CreateSwapChainForCoreWindow fails with First-chance exception at 0x75251D4D in TestDxAmp.exe: Microsoft C++ exception: Platform::InvalidArgumentException ^ at memory location 0x0328E484. HRESULT:0x80070057 The parameter is incorrect.

Which is not being very informative.

Upvotes: 1

Views: 768

Answers (1)

Ade Miller
Ade Miller

Reputation: 13743

I think the original forum post is maybe misleading. For both texture and buffer interop the unordered access binding is required for AMP interop. AMP is built on top of DX/DirectCompute so this applies in both cases as noted in the Intel link.

your program can create an arrayassociated with an existing Direct3D buffer using the make_array()function.

template<typename T, int N>

array<T,N> make_array(const extent& ext, IUnknown* buffer); 

The Direct3D buffer must implement the ID3D11Bufferinterface. It must support raw views (D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS) and allow SHADER_RESOURCE and UNORDERED_ACCESS binding. The buffer itself must be of the correct size, the size of the extent multiplied by the size of the buffer type. The following code uses make_arrayto create an array using the accelerator_view, dxView, which was created in the previous section: HRESULT hr = S_OK;

-- C++ AMP Book

I'm not a DX expert but from the following post it looks like you can configure the swap chain to support UAVs.

Sobel Filter Compute Shader

Upvotes: 0

Related Questions