Page 1 of 1

[posila] [2.0.13] Some nuclear item glow sprites cause large draw call counts and negatively impact FPS

Posted: Thu Oct 31, 2024 5:24 pm
by PJB3005
I decided to run Factorio under RenderDoc on a whim while discussing texture atlassing with friends, and noticed that a belt of nuclear fuel (the train kind) in my base was causing a large amount of draw calls.

I don't know the internals of the engine obviously, but it appears that the world-space “glow” effect on certain items (such as uranium fuel cells) forces the game to be unable to sprite batch, and therefore causes the game to produce tons of draw calls, which negatively affects FPS. It seems that the “glow" effect sprite is put into a different atlas than the normal item one, which forces the game to constantly flip between them.

This notably does not happen for the U-235 item, which despite glowing seems to use its normal item sprite to calculate the glow and therefore doesn't need to access a different texture. I didn't exhaustively test every item but it happens with Uranium fuel cells and Nuclear fuel at least.

I attached a test scenario that just has a ton of these items on belts. Uranium fuel cells absolutely tank FPS when a lot is in view, U-235 is fine. RenderDoc captures are gigabytes so I'll leave those out.

Re: [posila] [2.0.13] Some nuclear item glow sprites cause large draw call counts and negatively impact FPS

Posted: Tue Nov 05, 2024 7:13 pm
by posila
Thanks for the report.
Good catch, fixed for 2.0.16

Re: [posila] [2.0.13] Some nuclear item glow sprites cause large draw call counts and negatively impact FPS

Posted: Sat Nov 09, 2024 7:43 am
by zebez
So this still happens with mods like https://mods.factorio.com/mod/science-pack-glow-reborn

Is there a way to fix it from the modding side?
20241109084053_1.jpg
20241109084053_1.jpg (1.6 MiB) Viewed 377 times

Re: [posila] [2.0.13] Some nuclear item glow sprites cause large draw call counts and negatively impact FPS

Posted: Sat Nov 09, 2024 9:06 am
by posila
zebez wrote: Sat Nov 09, 2024 7:43 amSo this still happens with mods like https://mods.factorio.com/mod/science-pack-glow-reborn

Code: Select all

flags = { "light" }
The mod should remove light flag (remove entire flags property, to be exact) from the light layers and keep just draw_as_light = true

In 1.1, draw_as_light sprites were rendered in separate queue to different render target (light map), so it was beneficial to sort them to separate atlas from regular sprites, hence "light" flag. In 2.0, both regular sprites and draw_as_light sprites are mixed in the same queue and rendered to both regular render target and the light map, and the flag just modifies how they are blended to the render targets, so layers of one thing should be ideally organized to the same atlas to allow sprite batching.

Re: [posila] [2.0.13] Some nuclear item glow sprites cause large draw call counts and negatively impact FPS

Posted: Sat Nov 09, 2024 1:19 pm
by zebez
That worked wonderfully, thank you!