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

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):

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):


Here is the code causing the “unable to unroll a loop”:

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

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/

8523797–1137002–Particle Lit Shader Example.zip (7.51 KB)

Running into the same problem here. Did you make any progress @colinleet ?

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).

  1. 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.

  1. 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”.

"Unable to unroll loop" for *any* URP Lit Shader Graph when HDRP and URP are Active Targets [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)

Unity got back to me and confirmed this was a bug, anyone struggling with this please upvote it!