Search Unity

Bug Mesh Instancing + Shader Graph => Macro Redefinition Errors (in HDRP/URP)

Discussion in 'Shader Graph' started by colinleet, Dec 22, 2021.

  1. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    189
    I'm getting a persistent error that is automatically reintroduced to all of my shader graphs over the past couple months in URP and HDRP in 2021.2+ . After applying the shader graph to any shader material instance with "Enable GPU Instancing" turned on these two error are immediately introduced to the shader graphs for those materials:

    Macro Redefinition Error HDRP.jpg

    The error is identical when tested in URP and HDRP. Note: I've been doing most of this testing in HDRP in the latest release (2021.2.7f1).

    Since submitting this as a bug report (#1390079), I've found the same macro errors are reintroduced with every build (where it's used) regardless of if the shader is set to instance (in any material or mesh renderer material instance in the entire project) when it compiles shader variance which are meant to be set by a script -- Basically every conservable time that a instanced shader could be used! This is a massive issue for me.

    I've been finding the compilation errors have severe secondary effect which are also hard to diagnose. [Note: these to not always reoccurs every time the above error starts to show, but if you edit the shader property's after...]


    Some errors include 1) not being able to view the properties within the corrupted shader graphs,

    Unbroken Shader.jpg

    [edits from two weeks later in brackets]
    and 2) not being able to set those properties from scripts at times [particularly in one occurrence I had pictured here Unity] won't recognize the names of variables [after I] change them in [shader graph's editor] after a shader graph had become corrupted [I think, but didn't want to try to reproducer, as it was a bug that given me for a day or two of wondering why I couldn't set a shader property float]. [If you change variable names after already having a macro redefinition error? (I'm really not too sure how this. It's probably a freak accident side effect.) ].

    Broken Shader.jpg

    (Note for people who have access to bug report (#1390079): The first "no instanced" version has an additional property I first tried to add to the original (backed up zipped version) [which broke it], requiring me to re add all of the new properties/nodes in a new shader graph, and rewire them.

    Performing the following "shader reset" will not fix the secondary missing property's error pictured above -- [edited: my main point is I think I'm finding the bug at the top of this post] can make your shader graph's corrupted if you edit them after. I've only limitedly tested this.

    The only way I've found of removing the errors is to
    1) Simply reset the shader like this... This only works for a tiny bit before having to do it again.

    [Update from two days later, for some reason this simple reset method no longer works for me using the same version of Unity, and HDRP. I don't test in URP often.]

    [This is the best way I found after submitting my bug report.]

    How To Fix.jpg

    or [more drastically] 2) either restore a backup [e.g. unzip a uncorrupted version (with the editor closed)] of the uncorrupted shader graph(s), or 3) to remake them completely -- for every build cycle, or time it becomes corrupted [is instanced anywhere]. Reapplying the shader to any instanced material breaks it again.

    Both of the predefined tags causing errors were added in 2021.2 (release notes):
    • Graphics: Added: Added UNITY_PREV_MATRIX_M and UNITY_PREV_MATRIX_I_M shader macros to support instanced motion vector rendering.
    Anyone have any ideas for a permanent fix?

    Mostly making this as a FYI for the community...

    I submitted a bug report (#1390079).
     
    Last edited: Jan 3, 2022
  2. JarkkoUnity

    JarkkoUnity

    Unity Technologies

    Joined:
    Feb 1, 2021
    Posts:
    17
    Have you tried deleting project "Library" directory? We had similar issue (#1364927) that required this cleanup for some reason.
     
  3. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    189
    I attempted that a couple time with no luck. It removes the errors from the shader graphs just after the library is rebuilt, but they still become instantly corrupted as soon as the "Enable GPU Instancing" if ticked on in an materials where the shader is used.
     
  4. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    189
    Jarkko, I agree it looks similar to the issue you specified (#1364927) in it being a rogue warning issue, most of the time not doing much.

    I think I just ended up being squeezed between two really bad bugs, only one of which might possibly be related to the macros: the freak bug with inaccessible shader property names (mentioned above), and this much much much worse one I found out about two days later causing 98% of my headaches and random crashes from within SRP this month (and already has a fix in the works).