Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Direct3d vertex buffer usage type, performance and c++amp?

I'm new to direct3d and graphics programming in general, the program I'm writing changes vertices once per frame after applying non trivial computation per frame, according to this Direct3d programming tips

I should use dynamic buffers for such task, but it says that it's performance is expectable, searching the web I found Fastest way to update vertex buffer

Scroll down to Xoofx answer(Designer of Sharpdx) according to him updating a subresource is better than using dynamic buffers and as far as I know updating a subresource is used only with default buffers.

Which usage should I go with and what is (staging) ?

If I decide to use C++ AMP to do the computation (I understand that it uses the gpu as a processor) is there any way to set the buffer usage to default and still access it through the cpu using C++ AMP?

like image 450
ψευδή ηχώ Avatar asked Apr 07 '26 11:04

ψευδή ηχώ


1 Answers

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));
like image 169
Ade Miller Avatar answered Apr 12 '26 06:04

Ade Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!