Trying to profile/optimize my game (2DRenderer + 2DLights) could use some advice

Hey guys, I've been working on my game for about 6 months now, using the 2DRenderer with 2D Lights.

A couple months ago I was getting around 250fps when playing the game. Testing it now, I'm getting 90-110 fps. I can't think of anything I've added/changed that would be causing the low framerate. I'm trying to profile the game, but having difficulty figuring out what exactly I can do about the things that are taking high percentage of CPU/GPU.

I'm running a standalone Development Build of the game with the Profiler attached.

[Above] In-game screenshot - not too much going on. I'm using the 2D lights system with point-lights, and the Player has a normalmap. Theres some foreground images, and theres a rain particle effect. I'm only getting 103 fps.

[Above] Profiler showing CPU usage.
The top highlighted line says ParticleSystem.WaitForPreMapping, and it is taking 36.9% CPU time. I googled ParticleSystem.WaitForPreMapping as well as ParticleSystem.ScheduleGeometryJobs and coudln't find any information. The only particles that are currently active is the Rain particle effect. Probably around 300 or 400 active particles. There must be something weird going on to cause this 36.9% CPU usage, but without knowing what WaitForPreMapping is, I have no idea what to do.

I also highlighted the Render 2D Lighting CPU-usage which is only taking 5.1%. I don't have any other information/reference point to compare that to, but it seems pretty good.

[Above] Profiler showing GPU usage.
Couple things that I don't understand here. For one, the GPU Usage graph is showing the entire thing as "Other". And then there is the Render 2D Lighting -> RenderTexture.SetActive entry that is using 88.8% of the GPU. So now I know what is taking the majority of the GPU usage, but I don't know what I can do about it. Is this normal? Did I configure something wrong with my project? I try to google to figure it out but I can't find any information.

[Above] Rendering Info
Wanted to include this info in case it matters. 295 batches/draw calls seems like an awful lot, especially considering I use Texture Atlases, and have a good rendering strategy that should minimize batching. The game I'm working on is a sequel to a game I made using LibGDX, and I'm using the same rendering strategy with Texture Atlases. In that game I had around 60 draw calls. I really wish there was more information on how the 2D lighting system works so I would know if I need to set things up differently.

Would really appreciate any advice on what I could check or change to improve my FPS. I feel sort of helpless in my situation since I can't find any information on what the ParticleSystem.WaitForPreMapping is, or whats going on with the RenderTexture.SetActive for the 2D Lighting.

Thanks!! :]

You are in a good spot. I am sitting here with "Gfx.WaitForPresentOnGfxThread" with %89.4. 28ms on main thread. Draw calls are almost same though.

Sorry, but how exactly am I in a good spot? I'm getting under 100fps on my reasonably high-end computer. I was getting 250fps a couple months ago, and without changing much on my end, I'm now only getting 100fps. I can't make optimizations because I don't know what the profiler is showing me. Just because your project is doing worse doesn't mean mine is in a good spot :eyes:

Well, that's why I said good spot. I am on 25-30~ fps. Sorry to bother though, just to let you know 2D Renderer is still experimental, not even preview. it's experimental. But again, it is getting some performance fixes in upcoming versions but I don't know to what extent.

100fps for what I am doing is not an acceptable framerate. Going from 250fps down to 100fps for an unknown reason also doesn't make much sense, but I can't troubleshoot the issue when I don't know what the profiler is telling me. I'm aware its experimental, but that doesn't mean that I can't get more information or give feedback - thats why I'm here posting on the "2D Experimental Preview" forum looking for advice.

Maybe it would help if I asked some direct questions:

1) What is going on with RenderTexture.SetActive in the Render 2D Lighting section of the GPU profiler? Are there any configurations I can do to reduce it? Is that being called based on the number of lights, or based on the number of sprites that have lighting applied to them, or some combination of both?

2) Does ParticleSystem.WaitForPreMapping have anything to do with the 2D Renderer, or is it purely Particle System related, and I should instead ask about it on the Particle System section of the forum?

Thanks for any help!

If you do frame debug, you will see that 2drenderer creates and renders lights buffer per layer it is affecting it. I think this is set on the light itself.. this is a huge cost, at least on my side. Could explain the render texture cost you have too.


Hey castor, thanks for replying! Definitely going to test this out - seriously appreciate the info. I suppose I could combine some of my layers and just use "order in layer" instead? Have you tried that?

I have not tried the order in layer, but feel free to let us know of your finding. It was pretty shocking to me when I found out that it was rendering light buffer per layers. I could understand why it does what it does but at the same time, I was thinking, well, this is not very practical.... also understood why Unity asked us to "reduce" the size of the light buffer as it is going to be magnitude worse if there are many layers.

I was using layers to do some other stuffs like culling and game play related things, and then had all my lights affecting the all layers and found the 2dRenderer was rendering lightbuffers for ALL of them. which was pointless because it was drawing the same looking light buffers again and again...