Physics Thread Affinity and Main‑Thread Render Synchronization in SourceEngine
0 reputation · 31 Jul 2023, 10:34 UTC
0 reputation · 31 Jul 2023, 10:34 UTC
Determine whether the physics simulation thread in SourceEngine can be reconfigured to run on a separate core set while maintaining the existing synchronization point where the main thread issues rendering commands after the physics update.
The engine currently confines physics to a single worker thread, and documentation does not expose any mechanism to change its affinity or to enable multiple physics workers. Changing this affinity could affect the deterministic ordering of entity updates that are batched after the previous frame’s render completes, potentially introducing race conditions or frame‑time variability.
33775 reputation · 31 Jul 2023, 12:46 UTC
In the stock SourceEngine build, there is no exposed console variable or configuration file that can change the affinity of the physics worker thread or enable multiple physics workers. The physics simulation runs on a single worker that is created during engine initialization. To move it to another core set or split it across cores you must modify the source code that creates the thread and optionally the synchronization primitives that enforce the render‑after‑physics ordering.
SetThreadAffinityMask on Windows or pthread_setaffinity_np on Linux) does not alter the logical ordering, but it can affect cache locality and cross‑core wake‑ups, potentially introducing jitter.top -H on Linux, Process Explorer on Windows) while a physics‑heavy map is running. Note the thread name or ID that shows the highest CPU usage during the physics tick.std::thread, CreateThread, or pthread_create that correspond to the physics worker. Add a log line or breakpoint at that point to confirm the thread’s entry point.taskset -p on Linux or start /affinity on Windows to force the physics thread onto a desired core set. Verify that the main thread still waits on the same completion event before rendering.To give a more precise recommendation, could you tell us which SourceEngine branch you are working with (e.g., 2013 SDK, 2016 SDK, 2020 SDK, or a custom fork) and whether the engine uses Havok, the legacy VPhysics implementation, or a third‑party physics library? The exact physics backend can influence how the worker is created and synchronized.
| Main Thread | Physics Worker | Render Submission |
|---|---|---|
Runs game logic, waits on PhysicsSync | Executes physics tick, signals PhysicsSync | Submits draw calls after PhysicsSync |
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.