Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Bounding Box with Compute Shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

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

#1 0x23   Members   -  Reputation: 110

Like
0Likes
Like

Posted 01 August 2013 - 06:51 AM

Hello everybody,

 

I have a huge mesh on the GPU and want to compute its bounding box in a compute shader.

The implementation will be straight foreward with the  InterlockedMin/Max functions. My question is

how do I return the result (the bounding box) which consists of 6 float values to the CPU ?

 

Thank you in advance ;)

 



Sponsor:

#2 MJP   Moderators   -  Reputation: 11590

Like
5Likes
Like

Posted 01 August 2013 - 01:35 PM

To read back results on the CPU you have to create two buffers of the same size. The first you create with D3D11_USAGE_DEFAULT and you use that as the output of your compute shader. For the other buffer you create D3D11_USAGE_STAGING and CPU read access. Then after you run your compute shader, you use CopyResource to copy the data from the GPU buffer to the staging buffer. You can then call Map on the staging buffer to read its contents. Just be aware that doing this will cause the CPU flush its command buffers and wait around while the GPU finishes executing commands, which will kill parallelism and hurt performance. You can alleviate this by waiting as long as possible after calling CopyResource but before calling Map.

Also just so you're aware, while global atomics are the most straightforward way to do this they're definitely not the fastest. Running a multi-pass parallel reduction is likely to be much faster.


Edited by MJP, 02 August 2013 - 12:13 PM.


#3 Jason Z   Crossbones+   -  Reputation: 5164

Like
0Likes
Like

Posted 02 August 2013 - 06:37 AM

Also keep in mind that D3D 11.2 (which is currently restricted to Win8.1...) allows you to skip the staging resource and get access to the data directly.  That simplifies the process considerably, but the jury is still out regarding what kind of performance impact there is - if any at all.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS