Jump to content

  • Log In with Google      Sign In   
  • Create Account


Compute shader values

  • You cannot reply to this topic
4 replies to this topic

#1 Tank202   Members   -  Reputation: 178

Like
0Likes
Like

Posted 17 August 2014 - 09:59 AM

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?



Sponsor:

#2 marcjulian   Members   -  Reputation: 256

Like
2Likes
Like

Posted 17 August 2014 - 11:46 AM

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.



#3 Tank202   Members   -  Reputation: 178

Like
0Likes
Like

Posted 18 August 2014 - 07:09 AM

Thanks for information. Looking forward to implement them.



#4 Tank202   Members   -  Reputation: 178

Like
0Likes
Like

Posted 18 August 2014 - 09:26 AM

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?



#5 Nik02   Crossbones+   -  Reputation: 2765

Like
0Likes
Like

Posted 18 August 2014 - 12:29 PM

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.


Niko Suni






PARTNERS