- Home /
GPU Ray tracing: "kernel at index(0) is invalid"
I have been following this tutorial/blog thing: http://three-eyed-games.com/2018/05/03/gpu-ray-tracing-in-unity-part-1/
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.
Answer by ThisLove · Jul 04, 2021 at 12:10 AM
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).
Answer by Plumiferox · Jul 23, 2021 at 02:24 PM
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
Answer by lgarczyn · Mar 08 at 10:22 AM
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.
Answer by ThinhHB · Mar 31 at 03:24 PM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613035506im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Compute Shader and mipmaps auto-generation 0 Answers
How do you see the results of compute shaders in the debugger? 1 Answer
Pass ComputeBuffer to another ComputeShader 0 Answers
Use compute shader to convert RenderTexture to Vector4 array 1 Answer
Graphics.CopyTexture copies wrong mip on Windows 10 build 1 Answer