HUGE Performance Spike When Culling (HDRP) Something to do with loading textures

I am, and have been experiencing performance spikes in my HDRP Project.

OUTLINE OF ISSUE:
-I have a first person player controller.
-I have a world in which there are assets (some i made myself, others off the store, these have textures, but no fancy shaders, (Mostly HDRP/Lit))
-You can walk around this world (there is a terrain, with trees, foliage, grass)
-Camera clipping plane far is set very low (i assumed this would help with the performance, about 100 meters)
-I disabled all post processing to gather all of the following data, along with light sources which cast shadows (the sun)

When i look around with the mouse look, a large performance spike happens, not all of the time, and there is no set interval at which this happens. This can happen in play mode multiple times, there does not seem to be a limit, past which it stops happening. Sometimes these spikes happen after one another, I could move my mouse for 3 seconds before the first one happens, then another can happen a second later, but not always.
To me, this seems to be random

MY CURRENT UNDERSTANDING OF THE ISSUE
I went to the profiler and here is one such spike:

This seems to be something to do with the culling that HDRP does.
NOTE: I have disabled occlusion culling in order to rule that out as a possible cause, and i set it to false on the main camera
This lead me to believe that it is an issue with the frustum culling, which would make sense, considering that the spike only happens when the mouse moves.

IT IS ALSO CONNECTED TO TEXTURES


As seen here, there is a long list of textures which are being read during each of the spikes.

Here is a video, which illustrates how each time a spike happens, its the exact same “HDRenderPipeline.PrepareAndCullCamera()” which ends up reading a bunch of textures.
You may also see how each time the spike occurs, it is with a different set of textures (I assume that this is due to which direction i currently looked, which lead to different textures being needed)
The Video:

Disabling every asset and walking around in just the terrain, with the trees, grass and foliage removes the spikes. But i dont believe that ALL my assets have a problem, though when i look, its always a different asset… and some of these i made myself, they have 3 maps, Albedo, Normal and Mask, with a HDRP/Lit shader.

There seems to be a fundamental problem with just loading in a new texture, and i have looked everywhere to try narrow this down but i seem to be the only one with this specific problem.

A test to illustrate how i can replicate this:
I walked around in the game world, without moving my mouse, and the spike did happen once… this is most likely due to me walking sideways, so the camera frustum would have had encountered a new asset, but not as many things as when i looked around.
I the picked up an item into the players hand, which caused a spike, due to the fact that the item “bolt cutter” was not previously on screen.

To me this all boils down to somehow not being able to asynchronously load in a new texture for an asset which was just viewed for the first time.

CURRENT CONCLUSION
Unfortunately i ignored this issue for a while, so i dont know when it began or what i changed at that time.

Right now i dont know my next step forward, ive looked everywhere to see if anyone had the same problem, i even asked chatgpt to help out, but nothing seems to work, except for disabling most of the assets.
I want to reiterate that i dont believe this is a problem with the assets themselves, as i have made a few myself, and before my problem began, they were already in the scene at that point, yet they now show up in my profiler sometimes, along with the other assets.

I expect this to probably be something on my part, maybe i check a box by accident that i shouldnt have, or i previously made an “optimisation” attempt which had other implications that i was not aware of.

I have looked into texture streaming, maybe that could help, but from the limited time ive tried it, it did not seem to fix the issues which i was having.

I hope to get some help on this because i feel totally lost that the moment

Here are some additional screenshots, all of the same event:



Hi WishboneGames! :wave:

I was reading through your post and ready to ask if you’ve tried setting up mipmap streaming on your textures here! I’m not 100% certain it will completely fix this issue but I think it will.

It looks like you’re seeing this issue in Unity 2022.3, in Play Mode. I would suggest checking you have everything set up for texture streaming as in the docs, then also make sure you have enabled “Load texture data on demand” before you see any improvement:

(this shows the “Load texture data on demand” option but you also need to enable the other options detailed on that page)

If you don’t enable this option the Editor will stall while it loads texture data.

Check that option out and let us know what you find. Also feel free to ask more if that’s not clear - I’m happy to try and help more!

2 Likes

Thank you so much for your answer, especially because it was so fast. I set up everything to do with texture streaming… and YEA, it works, i no longer have these huge spikes due to the textures being accessed. Even when i pick up that item which i said caused the spike, nothing, smooth as butter.
I really appreciate your response.
Though if you dont mind, i have a few questions:

-In the debug mode for texture streaming, some of my models are completely invisible, im not sure if this means that they are not working properly with streaming? And also some of my materials in this mode have no special color (red, green or blue), they just display their own albedo… does this mean that its working?
An example of a car before:


After:

Example of building before:

After:

-And now i have another thing to work out. Im new to this site so im not sure if im supposed to just make a new thread about this or not.
Im getting smaller, much less noticeable spikes on Seamphore.waitforsignal:


To my understanding this is just waiting for another part of rendering to finish in order to move on, any way i can check what its waiting on?

-And finally, I dont completely understand the distinction between texture streaming and virtual textures, what does this checkbox do?

Starting at the end:

Checkout this manual page for some more information on this one:

I’m not a graphics programmer but can give you a quick summary from my understanding - texture streaming will load in lower resolution versions of individual textures, and can improve performance and memory use. It means that you need to set all your textures up and manage how much memory is used yourself. For example, if you’re aiming to release your game on mobile devices with a limited amount of memory you will need to make sure that a suitable version of your textures fits in memory.

Virtual texturing aims to automatically combine textures in your scene and manage the memory use of them to give a consistent result in game. That said, the manual page for it says “This feature is experimental and not ready for production use” and has done since 2021.3. I would suggest asking a separate question tagged with some of the graphics tags to get more information if you want to know about that!

I’m not sure exactly what your setup is - this manual page might be useful to help work out what’s going on:

It does say that “If you use the MainTexture API to set a main texture, the texture won’t display in the Debug Draw Mode.” so maybe it’s related to that? There’s also a separate link to how to debug/analyze this in HDRP, and you mention HDRP above so maybe that’s relevant? (Again, asking a question with graphics tags might help you here!)

These seem like they might be because either we’re waiting for the render thread or the GPU. You can view the render thread in the Timeline view in the profiler that might help you work out which of these was the case.

Hope these help - happy to try and field more questions if it’s useful!

1 Like

Thank yoo so much for your reply, sorry for not seeing this sooner. Ill be reading through that other doc soon.
Meanwhile I have been experiencing problems due to enabling “Load texture data on demand”, which prevents me being able to see anything in my builds.
Id really appreciate if you could give this a look, im totally lost right now.

In summary of the post:

“Graphics.CopyTexture could not find source D3D11 texture object. Maybe it is a RenderTexture that is not created yet?”

I get this error every time i start the project up, with the before mentioned setting = True.
And all my builds since have been pitch black, with only emissive materials displaying as white.

Heres the post:

@peter_hall sorry to jump in here, but I didn’t want to create a whole new topic while you’re already talking about texture streaming here.

For the texture streaming (MIP streaming) to work, must it be enabled manually on each and every texture? Or it is a global thing will will automatically ignore textures (like terrain) where it should not apply?

I want to enable MIP streaming, but we have 1000+ textures scattered in many places and I need to know what the per texture effort will be to switch to this.

Hey again @WishboneGames - I see Bart has replied to your other thread there. Sounds like it’s a bug here; sorry to hear about that. Hopefully we’ll be able to get it fixed soon!

@mgeorgedeveloper - you only need to enable the texture streaming settings on the textures where it’s appropriate. For example; you can start by enabling it on (say) 10 textures today and do more tomorrow - you don’t need to do them all in one go. You can also use the Textures view in the Project Auditor package (GitHub - Unity-Technologies/ProjectAuditor: Project Auditor is an experimental static analysis tool for Unity Projects.) to show which packages have MipMaps enabled and which still need to be changed.

1 Like

I use better build report and just select all the textures in the build and hit the toggle :stuck_out_tongue:

That said you do want to adjust priority for important objects and such.

1 Like