Missing Landscape PSOPrecaching

During our ‘Hitch Hunt’ for our latest game released on 5.5.4 in September, we found PSO hitches related to Landscapes.

I looked at the 5.7 code, and it seems to still be there.

Here are the things I corrected to fix the issue :

1. Add missing code to skip 'Scene Proxy Creation’ when PSO are still pending :

Our game relies on delayed proxy creation when PSOs are not ready, the various landscape components are abiding by this setting, unlike other components, so we added the code needed.

FPrimitiveSceneProxy* ULandscapeMeshProxyComponent::CreateSceneProxy()
{
	if (GetStaticMesh() == nullptr
		|| GetStaticMesh()->IsCompiling()
		|| GetStaticMesh()->GetRenderData() == nullptr
		|| GetStaticMesh()->GetRenderData()->LODResources.Num() == 0
		|| GetStaticMesh()->GetRenderData()->LODResources[0].VertexBuffers.StaticMeshVertexBuffer.GetNumVertices() == 0)
	{
		return nullptr;
	}

	if ((LODGroupKey != 0) && (ComponentResolution == 0))
	{
		// this is an OLD HLOD not built with the new resolution/x/y/center information, which we need if LODGroups are used.
		UE_LOG(LogLandscape, Warning, TEXT("HLOD for Landscape needs to be rebuilt!  Landscape Mesh Proxy Component '%s' is using LODGroups but does not have the position and orientation information necessary to register it with the Landscape renderer.  This HLOD will not render until it is fixed."),
			*GetName());
		return nullptr;
	}


	// -BEGIN- Fix Landscape 'Too late' PSOs
	if (CheckPSOPrecachingAndBoostPriority(EPSOPrecachePriority::Highest) && GetPSOPrecacheProxyCreationStrategy() == EPSOPrecacheProxyCreationStrategy::DelayUntilPSOPrecached)
	{
		UE_LOG(LogLandscape, Verbose, TEXT("Skipping CreateSceneProxy for ULandscapeMeshProxyComponent %s (Its PSOs are still compiling)"), *GetFullName());
		return nullptr;
	}
	// -END- Fix Landscape 'Too late' PSOs

	return new FLandscapeMeshProxySceneProxy(this, LandscapeGuid, ProxyComponentBases, ProxyComponentCentersObjectSpace, ComponentXVectorObjectSpace, ComponentYVectorObjectSpace, GetComponentTransform(), ComponentResolution, ProxyLOD, LODGroupKey, ALandscapeProxy::ComputeLandscapeKey(GetWorld(), LODGroupKey, LandscapeGuid));
}

// Same logic in 'ULandscapeNaniteComponent::CreateSceneProxy()' and 'ULandscapeComponent::CreateSceneProxy()'

2. Moved precaching code from ‘PostLoad’ to expected ‘CollectPSOPrecacheData’

The ‘ULandscapeComponent’ is not following the expected ‘CollectPSOPrecacheData’ interface. Our fix was to move all of the PSO Precaching code present in ‘*ULandscapeComponent::*PostLoad()’ in a new ‘ULandscapeComponent::CollectPSOPrecacheData’ and added a call to ‘PrecachePSOs()’ at the end of ‘*ULandscapeComponent::*PostLoad()’.

[Attachment Removed]

Steps to Reproduce
Build a test map with a large amount of small landscape components. Then launch the game with ‘-clearPSODriverCache’ and pay attention to PSO hitches using the UnrealInsights or ‘r.PSOPrecache.Validation 2’

[Attachment Removed]

Hi - yes indeed. Landscape currently is not using the fallback and to be complete it should be supported and it isn’t that hard to do (as you’be shown in the code above). The main reason we haven’t done it yet is because popping of landscape can be visually pretty bad (no landscape components can leave a big hole in the map). The same for water (also doesn’t support the delayed creation). PSOs from these components are requested at high priority but if your world has streaming landscape and water proxies I guess it can happen that the PSO compilation is late - we haven’t ran into the issue locally because Fortnite doesn’t stream landscape components. Your changes make sense and will see if I can add them via an option to 5.8.

Kind regards,

Kenzo

[Attachment Removed]

Yeah, in our case we never noticed popping of landscape components streaming but sure did notice the hitches.

If popping can be an issue for some people, you could expose a separate PSO precache strategy for Landcapes and let users pick how to handle it. We did exactly this for SkeletalMeshes and additionally created a new strategy for them that ignore the delay and create the Scene Proxy if it’s a key meshes or if we waited more than x seconds.

[Attachment Removed]

yes - makes total sense. By default not hitching is the best solution for sure.

How come you needed this for skeletal meshes btw - do they spawn in randomly close by the player or do they just compile very slow? I am planning to add better fallback material support instead of just using world grid and thinking of supporting different types of fallback material per component type if needed. Not sure if that would help in your use case here.

I am very interested in hearing more things which went well and didn’t go well with PSO precaching for you because we didn’t a lot of feedback yet on shipped AAA titles using it. If you have the time and are interested then we can perhaps set up a quick sync somewhere in the beginning of the new year for this?

Kind regards,

Kenzo

[Attachment Removed]

Yes, that would be nice (for the meeting).

I was not the person that added the SkeletalMesh special handling, so I can only give a brief overview. Our characters are made up of many parts with various material effects that can be applied, slowing things down quite a bit for precaching. We didn’t want to have to wait too long for them to appear after they are dynamically spawned in the word. Additionally, while certain item like loot could be delayed, we just couldn’t wait at all for the main character or NPC appearing in cutscenes.

[Attachment Removed]

I created a pull request for the landscape PSO fix, with the ability of having them opt-out.

https://github.com/EpicGames/UnrealEngine/pull/14170

It’s my first pull request, so it’s hopefully done properly.

[Attachment Removed]

Thank you - [mention removed]​ will take care of the integrating after our winter break.

Regarding the chat, how about somewhere during the week of 5th or 12th of January - let me know what works for you and what timezone you are located. I am working from Belgium but can easily do a sync during my evening if you’re US based.

Kind regards and happy holidays,

Kenzo

[Attachment Removed]

Hi Sammy, I also wanted to ask if you have a small, shareable project on hand that hits the Landscape PSO precaching changes you made. If you don’t have one, that is totally fine, but it would help in speeding up the integration of the PR.

Cheers,

Tim

[Attachment Removed]

[mention removed]​ I unfortunately don’t, but we previously shared our build with some of your people to do some profiling, maybe this could be used? The pull request is slightly different than what we have internally, I added the opt-out functionality that I thought would be useful for people at large.

[mention removed]​ Regarding the meeting, I’m back the week of the 12th. I would like to include some additional people from our side that also took part in the PSO effort. We are in the -5 and -7 time zone, so I’m thinking late afternoon for you. If you can send me an email, I’ll loop in the extra people in the scheduling. Thank you.

[Attachment Removed]

Hi Sammy,

I’ll check internally to see if I can find the build you shared with us, which I can use to test and verify your changes. Kenzo will also reach out to you via email at some point this week to schedule a call when everyone is free. We look forward to speaking to you soon!

[Attachment Removed]

Hi,

Pls let us know what time works for you somewhere next week or the week after that when you are back. I am pretty flexible if it’s not a Friday evening my local time (I am located in Belgium) :slight_smile: (most other evenings work fine for me)

Kind regards,

Kenzo

[Attachment Removed]

It’s my understanding that people from Epic and Gearbox are planning a meeting for next week.

[Attachment Removed]

Hi Sammy,

Kenzo and I will not be attending the meeting next week, as that will likely focus on other items besides PSOs. We intended to have a small group of people from Epic and your side attend, so that we can focus on any feedback you have regarding PSOs. Please let me know if you are still interested in such a meeting, and I would be happy to arrange something.

[Attachment Removed]

Understood, then we are still interested in a PSO specific meeting. We can look at scheduling one after the one planned next week.

Thank you.

[Attachment Removed]

Sure, that sounds good. I can spin up an email thread where we can discuss details for a meeting time. Is the email attached to your EPS account a good one to reach you?

[Attachment Removed]

Perfect, and yes, it is the right email.

[Attachment Removed]

Ok, great! You should have received an email from me by now, but please let me know if you didn’t.

[Attachment Removed]