How is Shader.FindPassTagValue intended to be used?

I’m trying to generate a shader variant collection by logging the variants in a built player, but having difficulty parsing the PassType. A line in the log looks something like:

Uploaded shader variant to the GPU driver: Hidden/Internal-GUITexture, pass: <Unnamed Pass 0>, stage: vertex, keywords <no keywords>

Or:

Uploaded shader variant to the GPU driver: Hidden/Universal Render Pipeline/ScreenSpaceAmbientOcclusion, pass: SSAO_Occlusion, stage: vertex, keywords <no keywords>

I’m able to parse the log for the shader and keywords, but not certain how to handle the PassType. According to the documentation, this should be the “LightMode” tag? For unnamed passes I’m parsing the indices and then doing something like:

var passIndex = //some logic to parse the index
var lightModeTag = new ShaderTagId("LightMode");
var tagValue = shader.FindPassTagValue(passIndex, lightModeTag);

For named passes:

var tmpMaterial = new Material(shader);
var passIndex = tmpMaterial.FindPass(passName);
var lightModeTag = new ShaderTagId("LightMode");
var tagValue = shader.FindPassTagValue(passIndex, lightModeTag);

Both of these already feel pretty wrong, and it’s also not clear to me what the returned ‘tagValue’ is supposed to represent, or how to transform it in a manner that matches what I’m seeing in other shader variant collections I’m using for reference. Any pointers would be much appreciated, cheers!

For a bit more context, when I log the output I can get something like this:

Where some of the names map directly to the Unity PassTypes …

… but not all. ‘UniversalForward’ for example I guess should map to ‘ScriptableRenderPipeline’, as well as some others. Is there an exhaustive list of these so that I can reliably automate this? Or something else that I’m missing or otherwise not going about the right way? Thanks!

EDIT: Also, is the format of my logs correct? My understanding is that I should be looking for the pattern 'Compiled shader: … ’ rather than ‘Uploaded shader …’. I’ve tried clearing and disabling the DXCache, but the output is the same - maybe this was changed / reworded?

Hi!
Typed passes come from the builtin render pipeline. URP (and all SRPs) indeed use ScriptableRenderPipeline pass type.

Yes. We sometimes change the log messaging :slight_smile: It’s not like it’s public API.

1 Like

Thank you! Apologies if this is obvious, I’m still a bit unsure on the details on some of these when A/B-ing against a pre-existing ShaderVariantCollection generated in the editor vs the ones I’m trying to generate from the logs. For example, in the log the CameraMotionVectors comes out as:

Uploaded shader variant to the GPU driver: Hidden/Universal Render Pipeline/CameraMotionVectors, pass: Camera Motion Vectors ...

… and in the ShaderVariantCollection generated playing through the editor, I can see it should be passType 0:

image

ObjectMotionVectors in the log:

Uploaded shader variant to the GPU driver: Hidden/Universal Render Pipeline/ObjectMotionVectors, pass: Object Motion Vectors ...

… and in the ShaderVariantCollection generated playing through the editor, I can see it should be passType 12:

image

Is the right approach to build up a mapping of these for the built-in URP shaders and any custom shaders? Or are you saying that for SRPs this field can be ignored (or always set to the ScriptableRenderPipeline PassType)?

It should always be either ScriptableRenderPipeline pass type or ScriptableRenderPipelineDefaultUnlit pass type for URP.

Which one of the two?

The API for PassType.ScriptableRenderPipelineDefaultUnlit says “Custom scriptable pipeline when lightmode is set to default unlit or no light mode is set.”

Which precise setting does this refer to that can be default or unset, and where can I find it in the user interface?

It refers to the LightMode tag in the shader. There’s no user interface associated with it.