Search Unity

variable numthread in compute shader?

Discussion in 'Shaders' started by mahdiii, Apr 26, 2017.

  1. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
    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
     
  2. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    As far as I know we currently have no compute shader multiple variant compilation, like in general shaders (https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html).
    However similar behaviour can be achieved with compute shader kernels, where you can write multiple compute programs.

    For example:
    Code (csharp):
    1. #pragma kernel CSMainLowEnd
    2. #pragma kernel CSMainHighEnd
    3.  
    4. void MyFunction(uint3 id) { ...}
    5.  
    6. [numthreads(8,8,1)]
    7. void CSMainLowEnd (uint3 id : SV_DispatchThreadID) { MyFunction(id); }
    8.  
    9. [numthreads(16,16,1)]
    10. void CSMainHighEnd (uint3 id : SV_DispatchThreadID) { MyFunction(id); }
    And then you can dispatch the CSMainLowEnd or CSMainHighEnd depending on you requirements.
     
    Last edited: Apr 26, 2017