Compute Shader 'undeclared identifier' for functions and variables defined in include files.

Recently upgraded a project from 2019.3.0f6 to 2021.3.3f1, and now get many compute shader compile errors for ‘undeclared identifier’ for functions and variables defined in include files.

For example:
In file Assets/Shaders/SomeInclude.cginc:

int tableLength;
float CalculateSomething()
{
    ...
    return someFloat;
}

Then in a compute shader file:

#pragma kernel _main
#include "Assets/Shaders/SomeInclude.cginc"
[numthreads(16, 1, 1)]
void _main(uint3 id : SV_DispatchThreadID)
{
    if (id.x < tableLength)  <-- This line sometimes causes 'undeclared identifier' compile error
    {...}
   
    float someValue = CalculateSomething(); <-- This line sometimes causes 'undeclared identifier' compile error

There are many compute shaders in the project, most using includes for commonly defined functions and variables. Yet only some files get the compile errors.

Does anyone know what causes some included functions and variables to be undefined?
More generally, is there information available about the shader compiler and what it is doing? Like documentation somewhere, or some output logs from it’s compiles with a little more verbose information.

Disabling caching preprocessor results in no compiler errors. Edit->Project Settings:
8167322--1062698--upload_2022-5-30_11-25-23.png

I found this thread with details on the new shader compiler pre-processor. Something about how defines are done across include files must be causing the compile errors: New shader preprocessor

Might be related to the issue I’m currently having #include_with_pragmas not working properly with compute

1 Like

@coastalbytes it would be great if you could file a bug report. Thanks! :slight_smile:

2 Likes

Sounds good. I’ll try to nail down concise repro steps.

1 Like