根据这篇 ms 博客文章 http://blogs.msdn.com/b/nativeconcurrency/archive/2012/07/02/interop-with-direct3d-textures-in-c-amp.aspx
您可以直接从 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.
我从 dx 设备创建了一个 amp 设备描述符,我得到了一个指向后备缓冲区的指针,然后尝试从中创建一个 amp 纹理,但我发现后备缓冲区的纹理描述符 bindFlags 只是 D3D11_BIND_RENDER_TARGET 并且我至少需要 D3D11_BIND_UNORDERED_ACCESS 或 D3D11_BIND_SHADER_RESOURCE 才能使 Concurrency::graphics::direct3d::make_texture 正常运行。
如果我设置 bindflags,我可以很容易地制作任何其他 d3d 纹理并将其连接到 amp,但是对于设置在后台缓冲区上的标志,我无法连接它们。
其中有以下标记为 Microsoft 社区贡献者的回答
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.
所以,一方面,它(从 c++AMP 写入后备缓冲区)被用作互操作的示例,另一方面,它被解释为不可能...?
我目前的要求只是在 C++AMP 中生成一个光线追踪图像,并在 d3d 显示器上显示该图像,而无需每帧从显卡复制数据。我意识到我可以只生成我自己的纹理,然后用它渲染一个四边形,但直接写入后台缓冲区会更简单,如果可以的话,这就是我想做的。
也许这里有人可以解释是否可以完成以及需要哪些步骤才能完成,或者解释说不,这确实无法完成。
在此先感谢您对此主题的任何帮助。
[编辑] 我现在找到了这个信息 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;
实际上我之前确实尝试过,但是对 CreateSwapChainForCoreWindow 的调用失败了 TestDxAmp.exe 中 0x75251D4D 处的第一次机会异常:Microsoft C++ 异常:Platform::InvalidArgumentException ^ 在内存位置 0x0328E484。 HRESULT:0x80070057 参数不正确。
这不是很有用。
最佳答案
我认为原来的论坛帖子可能具有误导性。对于纹理和缓冲区互操作,AMP 互操作需要无序访问绑定(bind)。 AMP 建立在 DX/DirectCompute 之上,因此这适用于英特尔链接中所述的两种情况。
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
我不是 DX 专家,但从下面的帖子看来,您可以配置交换链以支持无人机。
关于c++ - 从 C++AMP 写入 DX11 后备缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26033016/