1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

Add an editor setting to configure number of threads for lightmap baking

This can be used to free some CPU cores when baking lightmaps.
When using fewer CPU cores, lightmap baking is slower but background
tasks aren't slowed down as much.
This commit is contained in:
Hugo Locurcio
2021-09-23 00:54:02 +02:00
parent cd2c2f8da4
commit 0e943939e2
3 changed files with 25 additions and 4 deletions

View File

@@ -36,6 +36,10 @@
#include "core/project_settings.h"
#include "modules/raycast/lightmap_raycaster.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif
Error LightmapperCPU::_layout_atlas(int p_max_size, Vector2i *r_atlas_size, int *r_atlas_slices) {
Vector2i atlas_size;
for (unsigned int i = 0; i < mesh_instances.size(); i++) {
@@ -205,7 +209,12 @@ Error LightmapperCPU::_layout_atlas(int p_max_size, Vector2i *r_atlas_size, int
void LightmapperCPU::_thread_func_callback(void *p_thread_data) {
ThreadData *thread_data = reinterpret_cast<ThreadData *>(p_thread_data);
thread_process_array(thread_data->count, thread_data->instance, &LightmapperCPU::_thread_func_wrapper, thread_data);
#ifdef TOOLS_ENABLED
const int num_threads = EDITOR_GET("editors/3d/lightmap_baking_number_of_cpu_threads");
#else
const int num_threads = 0;
#endif
thread_process_array(thread_data->count, thread_data->instance, &LightmapperCPU::_thread_func_wrapper, thread_data, num_threads);
}
void LightmapperCPU::_thread_func_wrapper(uint32_t p_idx, ThreadData *p_thread_data) {