Skip to content

Conversation

smix8
Copy link
Contributor

@smix8 smix8 commented Sep 22, 2025

Adds NoiseTextureGenerator singleton to facilitate the baking of noise textures using existing threads from the WorkerThreadPool when available.

Previously each single NoiseTexture2D/3D created its own dedicated Thread, which was neither efficient or performant.

This fresh thread creation made it more or less performance impossible to use noise textures at runtime when not hidden behind a loading screen. The thread-spawn alone would cause stutters to no end on all platforms with a higher thread-spawn costs like Windows. Having so many additional threads running next to the actual WorkerThreadPool max thread count caused a lot of thread congestion when many noise textures were used.

This PR removes the dedicated Thread from NoiseTexture2D/3D and makes them use WorkerThreadPool threads to bake noise images. Because this requires additional bookkeeping and thread synchronization work a new NoiseTextureGenerator singleton was added.

Note that there is no elegant hook option with the main loop to do thread synchronization for optional modules like the noise module. To solve this I decided to piggyback on the RenderingServer frame_pre_draw signal for thread synchronization. The reason I did not pick a SceneTree signal for this (like some other resources and nodes do) is because not every main loop is always a SceneTree, so those signals might not be available at all.

Using the frame_pre_draw signal also allows to sync all the noise bakes that users kicked off in script and that might have been finished quickly by the time the RenderingServer starts its own sync and frame thing. This gives less window to run into issues with async baked noise textures being already baked so the duplicated bake attempts get blocked. Keeping the wait window small is important because all the noise resources have this awkward implementation of using the deferred queue for auto updates that users can't really stop from triggering.

Note that this largely copies the bake logic of the navigation mesh generator, except for the new signal and deferred quirks that are specific to the noise module and resources.

@smix8 smix8 requested review from a team as code owners September 22, 2025 01:29
@smix8 smix8 force-pushed the noise_gen branch 2 times, most recently from 72f0183 to efe0ee2 Compare September 22, 2025 01:35
Adds NoiseTextureGenerator singleton to facilitate the baking of noise textures using the WorkerThreadPool.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants