Unity-Technologies / ProjectAuditor

Project Auditor is an experimental static analysis tool for Unity Projects.
Other
795 stars 64 forks source link

Shader variant `Player.log` parsing does not correctly parse unnamed passes (Unity 2021.2.14+) #159

Closed cabauman closed 1 year ago

cabauman commented 1 year ago

Describe the bug Shader variant Player.log parsing does not correctly parse unnamed passes, starting with Unity 2021.2.14 (I did a binary search of Unity downloads today to narrow it down). Changes to the format seems to be a recurring theme, but unfortunately this time it was introduced in a patch release, so the UNITY_2021_3_OR_NEWER scripting define symbol won't cut it this time in the special case handling. This new format also applies to the latest LTS at the time of writing (2021.3.16). The pass new format is of the form pass: <Unnamed Pass 0>.

I also noticed a difference in Editor.log: The pass name is an empty string rather than Pass 0

Snippets from Unity 2021.2.13 logs

Editor.log

Compiling shader "Hidden/BlitCopy" pass "Pass 0" (vp)
    1 / 1 variants left after stripping, processed in 0.00 seconds
    starting compilation...

Player.log

Compiled shader: Hidden/InternalClear, pass: unnamed, stage: vertex, keywords <no keywords>
Compiled shader: Hidden/InternalClear, pass: unnamed, stage: pixel, keywords <no keywords>
Compiled shader: Hidden/Internal-GUITexture, pass: unnamed, stage: vertex, keywords <no keywords>
Compiled shader: Hidden/Internal-GUITexture, pass: unnamed, stage: pixel, keywords <no keywords>
Compiled shader: Sprites/Default, pass: unnamed, stage: vertex, keywords <no keywords>
Compiled shader: Sprites/Default, pass: unnamed, stage: pixel, keywords <no keywords>
Compiled shader: Hidden/BlitCopy, pass: unnamed, stage: vertex, keywords <no keywords>
Compiled shader: Hidden/BlitCopy, pass: unnamed, stage: pixel, keywords <no keywords>

Snippet from Unity 2021.2.14 logs

Editor.log

Compiling shader "Hidden/BlitCopy" pass "" (vp)
    1 / 1 variants left after stripping, processed in 0.00 seconds
    starting compilation...

Player.log

Compiled shader: Hidden/InternalClear, pass: <Unnamed Pass 7>, stage: vertex, keywords <no keywords>
Compiled shader: Hidden/InternalClear, pass: <Unnamed Pass 7>, stage: pixel, keywords <no keywords>
Compiled shader: Hidden/Internal-GUITexture, pass: <Unnamed Pass 0>, stage: vertex, keywords <no keywords>
Compiled shader: Hidden/Internal-GUITexture, pass: <Unnamed Pass 0>, stage: pixel, keywords <no keywords>
Compiled shader: Sprites/Default, pass: <Unnamed Pass 0>, stage: vertex, keywords <no keywords>
Compiled shader: Sprites/Default, pass: <Unnamed Pass 0>, stage: pixel, keywords <no keywords>
Compiled shader: Hidden/BlitCopy, pass: <Unnamed Pass 0>, stage: vertex, keywords <no keywords>
Compiled shader: Hidden/BlitCopy, pass: <Unnamed Pass 0>, stage: pixel, keywords <no keywords>

To Reproduce

  1. Create a new project in Unity 2021.2.14 or later in the 2021 series. I've been doing my testing using the 3D (URP) Core template.
  2. Follow the steps outlined in the Variants documentation.
  3. Observe the missing compiled shaders. If you export a shader variant collection and use it in shader stripping, you'll notice pink textures when running the exe.

Expected behavior Should correctly parse unnamed passes

Screenshots If applicable, add screenshots to help explain your problem.

Information (please complete the following information):

Additional context Add any other context about the problem here.

When I get some time, I'll look into contributing a fix in the ShaderModule code.