Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an editor setting to configure the number of CPU threads used for lightmap baking #3335

Closed
Tracked by #56080
Calinou opened this issue Sep 22, 2021 · 5 comments
Closed
Tracked by #56080

Comments

@Calinou
Copy link
Member

Calinou commented Sep 22, 2021

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

The CPU lightmapper doesn't have a way to configure how many CPU threads are used. This is problematic when multitasking, since the lightmapper will make background applications or games run slowly or stutter heavily. System audio playback may even stop entirely on some machines when all CPU cores are used up.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add an editor setting to configure how many CPU threads should be used for lightmap baking. This way, the user can find a compromise between system responsiveness and lightmap baking speeds.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  • 0 (default) uses all CPU threads available.
  • Positive values specify a number of CPU threads to use.
  • Negative values subtract from the number of all CPU threads available.
Old percentage-based approach (no longer relevant)

I propose to use a percentage-based approach to choosing the number of CPU cores to use. This adapts well to varying configurations, including CPUs with dozens of threads available. CPUs with high logical core counts (>= 32) generally have worse single-thread performance and are used for multi-tasking more heavily, so freeing up more cores there with the same percentage setting makes sense.

The lower bound is clamped to 1, so there will always be at least 1 thread used even if the percentage is set to 0.0. This can be used to force the lightmapper to run on a single thread for troubleshooting purposes.

Example of CPU thread usage with the value 0.9 on common configurations:

1 logical CPU cores		1 threads
2 logical CPU cores		2 threads
3 logical CPU cores		3 threads
4 logical CPU cores		4 threads
6 logical CPU cores		5 threads
8 logical CPU cores		7 threads
12 logical CPU cores	11 threads
16 logical CPU cores	14 threads
20 logical CPU cores	18 threads
24 logical CPU cores	22 threads
32 logical CPU cores	29 threads
48 logical CPU cores	43 threads
64 logical CPU cores	58 threads
128 logical CPU cores	115 threads

If this enhancement will not be used often, can it be worked around with a few lines of script?

The number of CPU threads used for lightmap baking is currently hardcoded, so no.

Is there a reason why this should be core and not an add-on in the asset library?

See above.

@atirut-w
Copy link

Is using all of the cores for lightmapping really a problem? I have a 4 core Ryzen 3 1200 and baking lightmaps in Godot never caused any serious performance problem.

@Calinou
Copy link
Member Author

Calinou commented Sep 24, 2021

Is using all of the cores for lightmapping really a problem? I have a 4 core Ryzen 3 1200 and baking lightmaps in Godot never caused any serious performance problem.

It's a problem if you're looking to do something else remotely demanding while baking lightmaps in the background 🙂

@atirut-w
Copy link

remotely demanding

Does browsing the internet(Facebook, Reddit, Discord, Youtube, sometimes simultaneously) count?

@YuriSizov
Copy link
Contributor

YuriSizov commented Sep 24, 2021

Yes, it does, and the current setup fully loads my 5900X. PC is still somewhat usable, but not really in a practical sense.

You may have a bottleneck somewhere else so your CPU is not really doing as much as it could.

@akien-mga
Copy link
Member

Fixed by godotengine/godot#52952.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants