Draw call ordering / sorting debugging.
Steps to Reproduce
Hi there!
After upgrading our UE4.27 project to 5.3, it was found that the draw-call ordering for some of our meshes in the Opaque pass had changed!
Unfortunately now the Sky-material+mesh now renders before the fore-ground floor material+mesh.
Because of that the expensive sky pixel shaders are now working alot harder since more pixels now pass the depth test with this new draw call ordering seen. In UE5 that results in rendering the sky before the floor.
What determines the Draw call ordering In UE5? Specifically for the opaque pass in this situation, but also interested about the transparent pass.
I would like to dig into more why this ordering has changed for the worse for us here.
FMeshDrawCommandSortKey sounds like it might have something to do with it?
If some-one could point me to the area of the engine code in the forward desktop and mobile forward renderer in UE5.3 that would be a great help.
Additionally, any suggestions of how to affect the sorting order?
[Image Removed]
Many thanks
Hi Morton,
We tried reproducing the issue here taking a template with sky from 4.27 then migrating to 5.3.2 and observed that the sky rendered last as part of the opaque base pass using the mobile forward rendering path. Do you a repro project or additional details you can share for us to better diagnose?
Best regards.
Hi Morton,
In 5.3, the base passes are sorted first and foremost by BlendMode being Masked or not, and then by Vertex/Pixel shader hash. As such it is possible that a non standard sky could be rendered early depending on setting. However, meshes recognized as being sky materials (Setting the “Is Sky” advanced material setting) should result in sky getting dispatched after base pass opaques and may resolve the issue you are encountering.
Best regards.
Hi Morton,
Looking at the revision history, it states that the change was intended to improve front to back sorting of meshes using the same PSO. We’ll follow up further with the dev team regarding this case and whether or not we can make the bit distribution tweakable.
Did tagging the material as ‘Is Sky’ change the behaviour on your end?
Best regards.
I didn’t end up trying the “Is Sky” bool, instead reverted back to UE4 depth precision for this sorting logic.
Thanks for the update Morton, that should be a fairly straightforward divergence to maintain. What is the size of the sky mesh relative to other objects in the scene?
Best regards.
The two objects are quite close together (Floor and Sky)
The floor is more a large disk shaped platform and the sky is a localized Sphere encompassing the circular floor disk.
The origin of the sky is likely quite similar to the floor as well as the mesh bounds for both.
Still, it might point towards UE5 being too conservative now, or right on the limit.
Hi Morton,
Indeed, with less bits, UE5 would have less depth bins. Does an IsSky material or a help resolve this?
Best regards.
Hi Stéphane,
Our renderer has many many customizations in it, It might be quite difficult for us to create a reproduction project/ case for you. The draw calls shown above are actually custom meshes, (Not using the standard skybox).
Would you be able to give me any insight into what determines the order of the draw calls?
Maybe just for the opaque pass as a start.
Many thanks
If I am able to reproduce in vanilla with our meshes and subsituted materials I will also let you know.
Looks like GetMobileBasePassSortKey_ByState was changed in UE5 and is now sorting depth less accurately.
I wonder what the reason for the change is?