Shader Instructions 2-3 times more in 5.1

When comparing my shaders in 5.1 to the same shaders in 5.0 the instruction counts have more than doubled.

Default Lit shader in Unreal 5.0

Default Lit shader in 5.1:

I have stripped the static lighting functionality from my projects because I am only rendering with lumen at the moment so already I am trying to get the least amount of instructions possible.

Also SM 6 has more than their SM5 equivalents.

  • Is this a known issue?
  • Or is there a good clarification for this?

Cheers
Laurens 't Jong

1 Like

Hey, you can actually find information about this here: Unreal Engine 5.1 Release Notes | Unreal Engine 5.1 Documentation

Here are some information and quotes about it. Basically Epic has set the Default Shader Model for Unreal Engine to 6 instead of 5. Along with this they have resolved some other issues regarding the instruction count:

  • DirectX 12 with Shader Model 6 is Default on PC for New Projects
  • Set InstructionCount when compiling shaders with DXC, which fixes an issue where all compiles of SM6 shaders were reporting 0 instructions.
  • Fix an issue with ‘GetMaxNumInstructionsForShader’ that reported the incorrect instruction count for the given shader type. The function was not checking to see if the shader type in the pipeline was the same as the shader type we are asking for.

Note: The shader count has never been properly counted. If it was compared to the assembly code it would always differ somewhat. Although, this is something I haven’t been able to verify myself to be true or false.

1 Like

This makes a bit of sense, but. Having 90 instruction for an unlit shader Seems very high…

Also I might not really understand the amount of vertex instructions needed to render geometry, but again… 250 for a static mesh? compared to 108 for 5.0 shaders…

Is this really a more accurate representation? I’m really curious as to how these instructions are counted because this ofcourse is a black box looking at this in the platform stats tab.

Is there maybe a Unreal Dev that worked on this feature that can give a bit of insight into the accuracy of these stats?

Yeah, now that you say it… I launched the engine to check. Here are my stats from Unreal Engine 5.0.3 (Shading Model: Unlit):

Are you use forward shading?
If you are really interested this is a good video to watch: Shader Optimization – True Instruction Cost, Performance Tips // Tutorial - YouTube

I hope someone “in the know” can chime in on why the instruction count is so high?

1 Like

I’m using Deferred shading and realtime lighting only, this makes it possible to strip any baked lighting functionality from the shaders:

Render Settings

Shader Reduction Settings

26_Mobile_Shader_Permutation_Reduction_After

26_Shader_Permutation_Reduction_After

So I’m trying to get the least amount of possible shader instructions for the project that I’m setting up. And build it up from there depending on what I need. In UE 5.0 this resulted in a pretty complex shader to have only 200 instructions.

I am fine with more instructions if previous instruction counts where wrong. I guess all I need to know is:

  • If the instruction counts are accurate
  • If the increased amount of instructions for SM6 over SM5 is also accurate
  • How more instructions for SM6 are justified

Maybe @SebHillaire knows something about this?

1 Like

Actually you can’t compare SM5 instructions with SM6 instructions because they’re different compilers with different instruction sets ( DXBC vs DXIL ). What you could do is compare UE5.0 with SM6 and UE5.1 with SM6 which I did :). Enabling SM6 in UE5.0 involves about 5 engine modifications though but it’s possible. 5.1 does appear to have “more instructions”. Actual DXIL shaders from PIX report around 1200 instructions for some simple shaders so much more than the editor reports. But r.VelocityOutputPass has been changed from 0 to 1 which means basepass shaders are beefier due to adding velocity output instructions. If you do set it to 0 like in 5.0 you end up with identical instructions for BasePass pixel shaders :).

2 Likes

Jumping in as I posted this on another thread.

Basic material in 5.1 with nothing plugged in…

Exact same for 5.0…

Way more shader instructions but lower Shader count. It’s a little beyond my understanding, but man that’s a lot of instructions for something with no nodes plugged in.

1 Like

Hi,

I did a diff of the 5.0 and 5.1 base material code by going to Window->Shader Code->HLSL Code and found that the differences are likely related to refactoring of shader code for the new Strata tech that was added in 5.1. Further details can be found here:

Thanks,
Jon

2 Likes

This seems like an issue that should be fixed ASAP. The performance degradation is quite severe…

2 Likes

Frustrating that the shader count is this high even with Strata features disabled. Do we have any visibility on if optimization is planned for a hotfix? Hard to take an objective eye to my shader instruction counts when we’re not sure when saves might come.

2 Likes

Shader instruction count shouldn’t directly be affecting performance necessarily as static branching should account for this at cook time and dynamic branching at runtime (for example), although we appreciate for a long time this has been the only metric most users are able to go off. Are you seeing particular performance degradations? Have you profiled with other tools such as renderdoc to A/B test the timing of single material draw and to see if instruction count is the root cause of this or if there may be other factors at play?

We are planning an overhaul of this entire system currently though, particularly we want much better metrics than instruction count as it doesn’t really give a whole picture, but unfortunately this is a few engine versions away.

3 Likes