Sign in to follow this  
Quat

Compute Shader and Out of Bounds

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
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

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