Jump to content
  • Advertisement
Sign in to follow this  
Quat

Compute Shader and Out of Bounds

This topic is 2587 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

Let's say you have a compute shader, where you have a DispatchThreadID that is out of bounds of a RWTexture2D you are writing to? Is the behavior defined?

To explain, I have written a blur compute shader that I will be using to blur a render target that matches my client area screen dimensions. For my horizontal blur pass, each thread group is 1x256, and I dispatch enough to cover a row. However, this means I always have extra threads at the end. For example, if the client width is 600 pixels, then I process 3 (1x256) thread groups per row. But then I have 768-600=168 threads not doing anything, but in the compute shader they still execute:

blurredOutputRW[uint2(dispatchThreadID.x, dispatchThreadID.y)] = blurColor;

My blur is actually working as expected, so I am assuming that indexing out of bounds results in a no-op. But can anyone confirm?

Share this post


Link to post
Share on other sites
Advertisement
I have not seen anything in the documentation that defines the behavior when you write to an out-of-bounds index on a resource. I would guess that the index is range-checked to prevent memory overflow, but personally I don't think I would rely on that unless I saw it somewhere in writing. Otherwise you might get unexpected behavior (or even driver crashes) on certain hardware/driver combinations. Personally I've always just used an if statement to prevent writes from extraneous threads in thread group.

Share this post


Link to post
Share on other sites
Unfortunately I can't give any more concrete answer than MJP, but can offer some additional side data. Reads are well defined to return zero when addressing a resource area out of bounds. In addition, for Append buffers they will also discard objects which are appended when the buffer is already full. These two things make me 99.999% sure that your assumption is correct, but it still isn't 100%...

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!