Sign in to follow this  
Tank202

Compute shader values

Recommended Posts

Tank202    184

Hello,

 

I wanted to know how to return compute shader results back to CPU so that I can use it for application logics level computations. I have running compute shader on DirectX11 but I don't know how to convert results from unordered access view to my base structure on CPU. How do I do that?

Share this post


Link to post
Share on other sites
marcjulian    959

Once you've written your computation results to a buffer (or texture) you can Map() the buffer/texture and read back the results.

Note that for some resource types (depending on the creation flags) you may first need to copy your results to a staging resource and then Map() this intermediate resource.

 

This link (even though for DX10) contains some pointers to related topics: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205132(v=vs.85).aspx

 

One thing to keep in mind: If you read back the results in the same frame as the computation happens you will probably introduce stalls in your CPU-GPU communication which can lead to performance problems. So wait at least a frame before reading back data. Even better would be to issue a query after your Dispatch() call and then asynchronously ask DirectX if the query is finished so you know your computation you did before is finished as well.

Share this post


Link to post
Share on other sites
Tank202    184

On the other hand I see that you can specify wether directx should wait for result of compute shader or not... So maybe problematic result reading is not necessary?

Share this post


Link to post
Share on other sites
Nik02    4348

You can either wait, or accept the fact that the results may not yet be ready by the time you try to read them.

 

If you choose not to wait, the methods can return an error, and you don't get the actual results any faster.

 

If you can cope with a frame of latency, it is best to use a double buffer; that is, map and copy one buffer while the GPU is filling the other, and then swap the two for the next frame (or dispatch). This works with more buffers too, but additional buffers cause additional latency to the results.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this