Jump to content

  • Log In with Google      Sign In   
  • Create Account


Performance in Compute: Dispatch vs. Wasted Threads


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
No replies to this topic

#1 Hornsj3   Members   -  Reputation: 191

Like
0Likes
Like

Posted 03 April 2012 - 05:18 AM

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?

Sponsor:



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