Search code examples
hlsldirectx-10directcompute

directcompute hlsl numthreads?


Since you already define the thread groups to be executed when dispaching a compute shader, what do the numbers inside the shader file signify? example: [numthreads(1, 1, 1)]


Solution

  • Did some more digging, by official definition when dispatching you define thread groups while the numthreads statement defines the threads so basically they can be taken as extra dimensions. For example when i dispatch 2,2,1 to a function with 3,1,1 it spawns

    enter code here
    0, 0, 0 - 0, 0, 0
    0, 0, 0 - 1, 0, 0
    0, 0, 0 - 2, 0, 0
    
    1, 0, 0 - 0, 0, 0
    1, 0, 0 - 1, 0, 0
    1, 0, 0 - 2, 0, 0
    
    0, 1, 0 - 0, 0, 0
    0, 1, 0 - 1, 0, 0
    0, 1, 0 - 2, 0, 0
    
    1, 1, 0 - 0, 0, 0
    1, 1, 0 - 1, 0, 0
    1, 1, 0 - 2, 0, 0
    

    so 2*2*1*3*1*1 = 12 threads total