GPU Ray tracing: "kernel at index(0) is invalid"

I have been following this tutorial/blog thing: GPU Ray Tracing in Unity – Part 1 – Three Eyed Games

I’m stuck on the ‘reflections’ section, I think I have coded (more like ‘copied’, let’s be realistic) everything that I need to, but when I press play, I get:
.

“RayTracingShader.compute: Kernel at index (0) is invalid
UnityEngine.ComputeShader:Dispatch(Int32, Int32, Int32, Int32)”
.

There’s more, but here’s what I don’t understand:
Why does it say the kernel is invalid?

Why does it say Dispatch(int32, int32, int32, int32) where the actual dispatch looks like: “RayTracingShader.Dispatch(0, threadGroupsX, threadGroupsY, 1);”

Have I just left something out and didn’t notice?
.

I’m just starting to learn how to use computes shaders and I don’t really understand it, any help would be greatly appreciated.

I found the problem, I had done nothing wrong, I just missed ONE SEMICOLON! This hurts a lot.

4 Answers

4

This error happens most often when there is a compile error in the target kernel (usually the first one at index 0, since most compute shaders only have one kernel).

Sadly Unity appears to only report these compile errors once, and they might get cleared in the console. There should be a list of error in the inspector when selecting the shader. You can also try modifying the shader and get the error logged again, or try to fix it through guessing and luck.

I face the same issue, I tried this and it worked for me:

  • Exit unity
  • Goto library folder and delete “ScriptableAssemblies” and “ShaderCache” folder
  • Reopen Unity to let it rebuild above 2 folders

Hope it will help

194569-image-2022-03-31-222159211.png

Not sure if you tried this.

But first look at the Compute Shader in the Unity Editor and it may have a list of problems.

I had this same problem following the same blog and my fix was that unlike C#, in HLSL functions need to be made before you call them, and my Sphere() function was put after my Trace() function which called it. Hope this might have anyone with this issue.

P.S. Make sure you’re not using a URP(Universal Pipe Rendering) Project and if all else false sometimes just copying your asset folder to a new project works(this little trick has fixed the majority of my bugs in Unity).

Disable this checkbox
“projectSetting/editor/shaderCompilation/cachingPreprocessor”

That will fix the problem.

Disabling cachingPreprocessor didn't work for me, I restarted Unity. Also my functions are before the kernel. Rather selected the shader in the editor and said it had errors in the inspector On Unity 2020.3.28