UsePass cannot reference passes within another shader's second subshader

Hey, we found a problem that UsePass cannot reference passes within another shader's second subshader. In our project, we use RenderPipeline tag to switch between the built-in render pipeline and our own custom render pipeline. However, if I use UsePass to reference a pass in another shader, it seems it only checks the first subshader in that shader, and if the first subshader does not contain the named pass, it won't check the second shader even if it's a compatible subshader (actually the first subshader's RenderPipeline tag does not match current globalRenderPipeline string, which is weird).

Shader/MyShader1
{
    SubShader
    {
        Tags
        {
            "RenderPipeline" = "CustomPipeline"
        }
    }

    SubShader
    {
        UsePass "Shader/MyShader2/MYPASS"
    }
}

Shader/MyShader2
{
    SubShader
    {
        Tags
        {
            "RenderPipeline" = "CustomPipeline"
        }
    }

    SubShader
    {
        Pass
        {
            name MyPass
        }
    }
}

In the above code, when set Shader.globalRenderPipeline = "", which should activate the second subshader, but MyShader1 cannot render correctly due to UsePass cannot pull in MYPASS within MyShader2's second subshader. If I delete the first subshader within MyShader2, or copy MyPass into the first subshader, MyShader1 can render correctly. How can I reference a pass in a specific subshader or am I missing something here?

I'm using Unity 2021.3.19f1 btw.

Any help will be appreciated.
Thank you!

Hi!
UsePass doesn’t (and shouldn’t) care about render pipelines.
Please report a bug - I think it should work.
Thanks!

Thank you for your reply!
I have sent a report containing a reproducible project (IN-41636). I hope you will take a look at it soon.

1 Like