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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug "Unable to unroll loop" for *any* URP Lit Shader Graph when HDRP and URP are Active Targets

Discussion in 'Shaders' started by colinleet, Oct 19, 2022.

  1. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    169
    I'm playing around with trying to add support for URP to my currently HDRP project in the hopes of adding a low overhead render mode / and support for Quest2 port later; I know this is going to be a complex task so I started by testing how stable shader graph is when using both of the SRP's as active targets.

    I'm encountering a routine bug using the shared shader graph setup shown below with all lit shaders, unlit shaders seem to work fine. The HDRP shaders are compiling well, but when any lit URP forward rendering variant for the same shaders start to be compiled it's exploding to like an insane 98,304 shader variants (usually exactly):

    Out of controll forward URP variants.jpg

    I haven't let the compiling process complete so far since...
    I don't want to wait 2 hrs for it to compile 1 shader... * 20ish shaders... yuck.

    I'm using the most recent stable release version 2021.3.11f1, with HDRP 12.1.7, and URP 12.1.7.

    After I tell it to cancel the build, the shaders which go up to around 10k variants are all showing these waning's & errors (the loop iterations shown can change, as well as how many errors I get for line 306):

    Shader Errors.jpg
    Here is the code causing the "unable to unroll a loop":
    Erroring Loop From Lighting hlsl.jpg

    When googling the the above error I found this rough explanation of what might be happening here:

    https://forum.unity.com/threads/com...e-loops-causes-unable-to-unroll-error.441897/

    It's suggest was that I add a pargma to exclude some d3d11_9x and d3d9 renderers with the shaders; however this thread pre-dates shader graph, and from the erroring code above's stack trace it doesn't look like any of my node-setups are what are at fault -- it's from the base Lighting.hlsl script as it's iterating through lights...

    Does anyone have any ideas what might be happening here? Or even if there might be a potential fix?

    Here is an very simple lit particle shader graph which is showing the same errors:

    https://forum.unity.com/attachments/particle-lit-shader-example-zip.1137002/
     

    Attached Files:

    Last edited: Nov 3, 2022
    KevinVriens likes this.
  2. KevinVriens

    KevinVriens

    Joined:
    May 10, 2022
    Posts:
    1
    Running into the same problem here. Did you make any progress @colinleet ?
     
    Scribblets likes this.
  3. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    169
    I tried it out in Unity version 2022.1.20f1 with the 13 version of HDRP and URP the next day and encountered the same bug. This time I was testing in the demo environment so I could bug report it... Ended up sending this as the body of the report if anyone else wants the details. I have not heard anything back yet.

    "
    1. What happened

    When trying to compile the HDRP sample project with the URP package also installed,
    any shaders graphs targeting URP Lit shaders require tens of thousands of shader variants unnecessarily.

    E.g. In this project under Assets/URP Testing Assets/URP Lit Color Shader
    has just a simple color node with no exposed properties. This shader should
    just have just a few variants if any, as it has no exposed variables.

    Note I've also added a URP RenderPipelineAsset to the quality settings for this project in case that was needed to make the URP shaders compile.
    (I have no idea if this step was actually needed or not).

    2. How can we reproduce it using the example you attached

    Download the project and build for Windows.

    After about 10 min of compiling the normal HDRP shaders (on 24 threads),
    the editor will eventually start to compile the "URP Lit Color Shader's Forwards Lit variants...

    The number of listed needed variants will be around 25,000 when it should be in the single digits.

    3. Now cancel the compilation after any number of the 25k have finished.

    The problem seems to be rooted in the Lighting.hlsl : line 306.
    Numerous errors will be on the "URP Lit Color Shader" if it's selected.

    The errors are shown in the following link.

    I have a more detailed forum post I wrote about this yesterday when I originally encountered a 3x worse case of this in the 2021.3.11f1
    on different more complex shader graphs when I was trying to when I added URP as an additional "Active Target".

    https://forum.unity.com/threads/una...when-hdrp-and-urp-are-active-targets.1350341/ [this page]

    I forwarded my main project (what I used in the forum post) to 2022.1.20f1 with the 13 version of HDRP and URP today and encountered the same problem but with half as many shader variants needing to be generated (around 50k instead of 100k).
    " (spelling corrected)
     
    Scribblets likes this.
  4. colinleet

    colinleet

    Joined:
    Nov 20, 2019
    Posts:
    169