Your program can create a C++ AMP array associated 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 ID3D11Buffer
interface. 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 get_buffer()
function supports the reverse operation, getting a Direct3D buffer interface from
an array. As when getting a device, the returned IUnknown
must be queried for the desired interface.
HRESULT hr = S_OK;
array<int, 1> arr(1024);
CComPtr<ID3D11Buffer> buffer;
IUnknown* unkBuf = get_buffer(arr);
hr = unkBuf->QueryInterface(__uuidof(ID3D11Buffer), reinterpret_cast<LPVOID*>(&buffer));