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

This subforum contains all the issues which we already resolved.
PJB3005
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Oct 15, 2016 11:13 am
Contact:

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

Post 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.
Attachments
Game screenshot with perf debug options
Game screenshot with perf debug options
factorio_Q67wzUgXB2.jpg (754.23 KiB) Viewed 770 times
factorio-current.log
log file
(17.53 KiB) Downloaded 7 times
Screenshot of RenderDoc showing that it fails to batch the item drawing.
Screenshot of RenderDoc showing that it fails to batch the item drawing.
qrenderdoc_Yx1jHExCmk.png (292.24 KiB) Viewed 770 times
the batch cruncher.zip
Test scenario
(1.96 MiB) Downloaded 10 times

posila
Factorio Staff
Factorio Staff
Posts: 5324
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

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

Post by posila »

Thanks for the report.
Good catch, fixed for 2.0.16

User avatar
zebez
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sun Jul 03, 2016 9:53 am
Contact:

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

Post 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 301 times

posila
Factorio Staff
Factorio Staff
Posts: 5324
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

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

Post by posila »

zebez wrote:
Sat Nov 09, 2024 7:43 am
So 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.

User avatar
zebez
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sun Jul 03, 2016 9:53 am
Contact:

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

Post by zebez »

That worked wonderfully, thank you!

Post Reply

Return to “Resolved Problems and Bugs”