Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'General Graphics' started by coastalbytes, May 30, 2022.

  1. coastalbytes

    coastalbytes

    Joined:
    May 31, 2021
    Posts:
    7
    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:
    Code (hlsl):
    1.  
    2. int tableLength;
    3. float CalculateSomething()
    4. {
    5.     ...
    6.     return someFloat;
    7. }
    8.  
    9.  
    Then in a compute shader file:
    Code (hlsl):
    1. #pragma kernel _main
    2. #include "Assets/Shaders/SomeInclude.cginc"
    3. [numthreads(16, 1, 1)]
    4. void _main(uint3 id : SV_DispatchThreadID)
    5. {
    6.     if (id.x < tableLength)  <-- This line sometimes causes 'undeclared identifier' compile error
    7.     {...}
    8.    
    9.     float someValue = CalculateSomething(); <-- This line sometimes causes 'undeclared identifier' compile error
    10.  
    11.  
    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.
     
  2. coastalbytes

    coastalbytes

    Joined:
    May 31, 2021
    Posts:
    7
    Disabling caching preprocessor results in no compiler errors. Edit->Project Settings:
    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: https://forum.unity.com/threads/new-shader-preprocessor.790328/
     
  3. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,864
    @coastalbytes it would be great if you could file a bug report. Thanks! :)
     
    kkjusdoit and coastalbytes like this.
  5. coastalbytes

    coastalbytes

    Joined:
    May 31, 2021
    Posts:
    7
    Sounds good. I'll try to nail down concise repro steps.
     
    aleksandrk likes this.