Jump to content
  • Advertisement
Sign in to follow this  

Performance in Compute: Dispatch vs. Wasted Threads

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

Bear with me, this may be a long one.

I'm still perfecting a compute shader to generate custom mip-map values. My current problem is whether or not to have thousands of wasted threads, or multiple dispatch calls.

Here is a sample of how I'm setting up the number of threads in a thread group. This has no wasted threads, so long as my mip-level is at least 32x32.

#define sizeMip32_x 32
#define sizeMip32_y 32

[numthreads(sizeMip32_x, sizeMip32_y, 1)]
void CS32( uint3 DispatchThreadID : SV_DispatchThreadID )

The problem arises after start generating 16x16 and below.

On the one hand I could specify separate shaders for each level below 16x16, such as this:

#define sizeMip16_x 16
#define sizeMip16_y 16

[numthreads(sizeMip16_x, sizeMip16_y, 1)]
void CS16( uint3 DispatchThreadID : SV_DispatchThreadID )


... continue to 1x1

All of these shaders would be compiled at the same time. I would then use logic in C++ to determine which to call, based on the dimensions of the mip-level. That is approach one.

The second approach is to use logic in the shader, coupled with memory barriers, to generate the mip hierarchy from high resolution down to 1x1.
this would only require the 32x32 shader and 1 dispatch call but will invoke (rough estimate for base level of 512x512) about 200,000 threads which add no value. (256x256 threads mip-level 1 ... to 1x1).

This is because, in the first iteration, each thread will be utilized in calculating the next level. It will sample each pixel in the 4 pixels underlying the mip-level pixel and write the maximum value it finds. The second mip-level calculated will still run all 256x256 threads but will duplicate the work of the 4 adjacent threads (at each level) due to the nature of the algorithm.

So, given all of this, would it be better to have separate shaders and multiple dispatch calls or waste hundreds of thousands of threads in a single dispatch?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!