variable numthread in compute shader?

Hi all. I need to change numthread variable with respect to different systems.(graphics cards)
numthreads[8,8,1]

How can I do that?
Thanks in advance

As far as I know we currently have no compute shader multiple variant compilation, like in general shaders (Unity - Manual: Declaring and using shader keywords in HLSL).
However similar behaviour can be achieved with compute shader kernels, where you can write multiple compute programs.

For example:

#pragma kernel CSMainLowEnd
#pragma kernel CSMainHighEnd

void MyFunction(uint3 id) { ...}

[numthreads(8,8,1)]
void CSMainLowEnd (uint3 id : SV_DispatchThreadID) { MyFunction(id); }

[numthreads(16,16,1)]
void CSMainHighEnd (uint3 id : SV_DispatchThreadID) { MyFunction(id); }

And then you can dispatch the CSMainLowEnd or CSMainHighEnd depending on you requirements.

5 Likes