Frage

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.)

War es hilfreich?

Lösung

Texture

So, as we discussed in comments, you can work with 2D textures:

concurrency::graphics::texture<float_4, 2> tex(1920, 1200);

Device, then accelerator

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);

Accelerator, then device

Alternatively, you can get pointers to ID3D11Device and ID3D11DeviceContext from your existingaccelerator_view object:


Finally, rendering

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top