Jump to content
  • Advertisement
Sign in to follow this  
Tank202

Compute shader values

This topic is 1434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement

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

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!