Search Unity

Compute shader object can not find kernel, unity exception!

Discussion in 'Shaders' started by kaiyum, Mar 10, 2017.

  1. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    So the shader code is here: http://pastebin.com/Tbgu7UvH

    And the script is here: http://pastebin.com/r19BV1Rh

    If I try to find the only kernel that I have, I get this:

    Code (CSharp):
    1. Kernel 'CSMain' not found
    2. UnityEngine.ComputeShader:FindKernel(String)
    3. Controller:Start() (at Assets/Controller.cs:10)
    and

    Code (CSharp):
    1. UnityException: FindKernel failed
    2. Controller.Start () (at Assets/Controller.cs:10)
    If I try to Dispatch directly by index such as this:

    Code (CSharp):
    1. shader.Dispatch(0, 1, 1, 1);
    Then I receive this error:

    Code (CSharp):
    1. Kernel index (0) out of range
    2. UnityEngine.ComputeShader:Dispatch(Int32, Int32, Int32, Int32)
    Bug report submitted already: https://fogbugz.unity3d.com/default.asp?889614_6t75kdr4bstq1f83
     
  2. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    The fact that you can't find a kernel usually means it didn't compile correctly. Select your shader and you should see list of errors in inspector.
    I see this for your shader (in Unity 5.5):
    Code (CSharp):
    1. Shader error in 'NewComputeShader.compute': Program 'CSMain', error X4505: Sum of temp registers and indexable temp registers exceeds limit of 4096 (on d3d11)
     
  3. kaiyum

    kaiyum

    Joined:
    Nov 25, 2012
    Posts:
    686
    Sorry for delayed response, I took the code to another PC in office and yes, this error suddenly popped up. I guess its my home PC's driver issue. I did a lot of modifications to the shader later on, a bit painful it was and now it compiles and finds kernel anyway.
    Nonetheless, if a shader is not successfully compiled, unity should throw some meaningful error messages upon FindKernel() sothat I can understand, what is going on. :(

    Do any of you guys use any tool to debug compute shaders apart from playing with debug buffers? Deving compute shader is so painful :(:(
     
  4. Michal_

    Michal_

    Joined:
    Jan 14, 2015
    Posts:
    365
    The error is from DirectX compiler. It is strange you can't see it. Drivers shouldn't matter. It should be HW independent. Maybe this is a Unity bug.

    There are several shader debuggers. Mostly annotated assembly debugging. RenderDoc is integrated in Unity so that's by far the easiest method. Popular alternatives are Visual Studio graphics debugger and NVidia NSight but you need standalone build for those and that gets old quickly. Don't forget to use "#pragma enable_d3d11_debug_symbols".
    Btw. the shaders are heavily optimized and there's currently no easy way how to disable optimizations.