Reputation: 5101
I have a concurrency::array
(C++ AMP) of colors on device holding colors for each pixel.
I would like to feed this array to Direct3D so it would be used as a buffer to display in a window without having to copy the data to the host.
I also tried using concurrency::direct3d::make_array
, which associates an ID3D11Buffer
with an accelerator_view
, but I don't know how to then take this array and feed it to the Direct3D as the source of an image displayed in a window.
Alternatively, I could convert this data into a texture.
So the basic question is: Given a chunk of color information for each pixel located on a device, how to feed them to Direct3D to be used as a screen buffer of sorts? (This chunk just happens to be computed by C++ AMP.)
Upvotes: 2
Views: 450
Reputation: 13003
So, as we discussed in comments, you can work with 2D textures:
concurrency::graphics::texture<float_4, 2> tex(1920, 1200);
Then, to proceed with DirectX 11, you must have ID3D11Device
and ID3D11DeviceContext
. It is better to create ID3D11Device
and ID3D11DeviceContext
by hand, and then create accelerator_view
object based on your device. Example code from Julia2D sample:
accelerator_view av=concurrency::direct3d::create_accelerator_view(g_pd3dDevice);
texture<unorm4, 2> tex = make_texture<unorm4, 2>(av, pTexture);
Alternatively, you can get pointers to ID3D11Device
and ID3D11DeviceContext
from your existingaccelerator_view
object:
you use concurrency::direct3d::get_device()
function:
IUnknown* unknown = concurrency::direct3d::get_device(accelerator);
on returned IUnknown
object, you call IUnknown::QueryInterface
to cast it to ID3D11Device
ID3D11Device* device = 0;
unknown->QueryInterface(__uuidof(ID3D11Device), &device));
then you get ID3D11DeviceContext
calling ID3D11Device::GetImmediateContext
:
ID3D11DeviceContext* context = 0;
device->GetImmediateContext(context);
With ID3D11Device
and ID3D11DeviceContext
you can proceed to rendering (example with DirectXTK):
SpriteBatch* spriteBatch(new SpriteBatch(context));
spriteBatch->Begin();
spriteBatch->Draw(texture, XMFLOAT2(x, y));
spriteBatch->End();
Also, I've found this two samples involved C++Amp/DirectX interop, that can be useful for you: one, two.
Hope, it helps.
Upvotes: 3