[unity] Disabled thread profiling by default, the define can be enabled via Spine Preferences. See #2981.

This commit is contained in:
Harald Csaszar 2025-11-26 18:57:41 +01:00
parent 370c74edb4
commit e56e8cf734
6 changed files with 56 additions and 26 deletions

View File

@ -85,6 +85,7 @@ namespace Spine.Unity.Editor {
public static class SpineBuildEnvUtility {
public const string SPINE_ALLOW_UNSAFE_CODE = "SPINE_ALLOW_UNSAFE";
public const string SPINE_AUTO_UPGRADE_COMPONENTS_OFF = "SPINE_AUTO_UPGRADE_COMPONENTS_OFF";
public const string SPINE_ENABLE_THREAD_PROFILING = "SPINE_ENABLE_THREAD_PROFILING";
static bool IsInvalidGroup (BuildTargetGroup group) {
int gi = (int)group;

View File

@ -43,6 +43,10 @@
#define NEW_PREFERENCES_SETTINGS_PROVIDER
#endif
#if UNITY_2017_3_OR_NEWER
#define ALLOWS_CUSTOM_PROFILING
#endif
#if !SPINE_AUTO_UPGRADE_COMPONENTS_OFF
#define AUTO_UPGRADE_TO_43_COMPONENTS
#endif
@ -507,6 +511,20 @@ namespace Spine.Unity.Editor {
SpineEditorUtilities.BoolRuntimePropertiesField(
() => RuntimeSettings.UseThreadedAnimation, value => RuntimeSettings.UseThreadedAnimation = value,
new GUIContent("Threaded Animation", "Global setting for the equally named SkeletonAnimation and SkeletonGraphic Inspector parameter."));
#if ALLOWS_CUSTOM_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
bool threadProfilingEnabled = true;
#else
bool threadProfilingEnabled = false;
#endif
using (new GUILayout.HorizontalScope()) {
EditorGUILayout.PrefixLabel(new GUIContent("Thread Profiling",
"Enable profiling of Spine worker threads in the Unity Profiler. " +
"Enable only when needed, as it adds some overhead."));
EnableDisableDefineButtons(SpineBuildEnvUtility.SPINE_ENABLE_THREAD_PROFILING, threadProfilingEnabled);
}
#endif
}
GUILayout.Space(20);

View File

@ -47,6 +47,10 @@
#define HAS_ANY_UNSAFE_OPTIONS
#endif
#if UNITY_2017_3_OR_NEWER
#define ALLOWS_CUSTOM_PROFILING
#endif
#if !SPINE_AUTO_UPGRADE_COMPONENTS_OFF
#define AUTO_UPGRADE_TO_43_COMPONENTS
#endif
@ -347,9 +351,9 @@ namespace Spine.Unity.Editor {
SpineEditorUtilities.FloatPropertyField(settings.FindProperty("defaultScale"), new GUIContent("Default SkeletonData Scale", "The Default skeleton import scale for newly imported SkeletonDataAssets."), min: 0.0000001f);
SpineEditorUtilities.ShaderPropertyField(settings.FindProperty("defaultShader"), new GUIContent("Default Shader"), SpinePreferences.DEFAULT_DEFAULT_SHADER);
TextureWorkflowProperties textureProperties = new TextureWorkflowProperties(settings);
EditorGUILayout.Space();
using (new GUILayout.HorizontalScope()) {
EditorGUILayout.PrefixLabel("Switch Texture Workflow");
@ -517,6 +521,20 @@ namespace Spine.Unity.Editor {
SpineEditorUtilities.BoolRuntimePropertiesField(
() => RuntimeSettings.UseThreadedAnimation, value => RuntimeSettings.UseThreadedAnimation = value,
new GUIContent("Threaded Animation", "Global setting for the equally named SkeletonAnimation and SkeletonGraphic Inspector parameter."));
#if ALLOWS_CUSTOM_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
bool threadProfilingEnabled = true;
#else
bool threadProfilingEnabled = false;
#endif
using (new GUILayout.HorizontalScope()) {
EditorGUILayout.PrefixLabel(new GUIContent("Thread Profiling",
"Enable profiling of Spine worker threads in the Unity Profiler. " +
"Enable only when needed, as it adds some overhead."));
SpineEditorUtilities.EnableDisableDefineButtons(SpineBuildEnvUtility.SPINE_ENABLE_THREAD_PROFILING, threadProfilingEnabled);
}
#endif
}
GUILayout.Space(20);

View File

@ -27,14 +27,10 @@
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#if UNITY_2017_3_OR_NEWER
#define ENABLE_THREAD_PROFILING
#endif
using System;
using System.Collections.Generic;
using System.Threading;
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
using UnityEngine.Profiling;
#endif
@ -85,7 +81,7 @@ public class LockFreeWorkerPool<T> : IDisposable {
}
private void WorkerLoop (int threadIndex) {
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
Profiler.BeginThreadProfiling("Spine Threads", "Spine Thread " + threadIndex);
#endif
while (_running) {
@ -97,7 +93,7 @@ public class LockFreeWorkerPool<T> : IDisposable {
_taskAvailable[threadIndex].WaitOne();
}
}
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
Profiler.EndThreadProfiling();
#endif
}

View File

@ -33,9 +33,6 @@
#endif
#define READ_VOLATILE_ONCE
#if UNITY_2017_3_OR_NEWER
#define ENABLE_THREAD_PROFILING
#endif
#define DONT_WAIT_FOR_ALL_LATEUPDATE_TASKS // enabled improves performance a bit.
@ -54,7 +51,7 @@ using System.Collections.Generic;
using System.Threading;
using UnityEngine;
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
using UnityEngine.Profiling;
#endif
@ -287,7 +284,7 @@ namespace Spine.Unity {
genericSkeletonTasks[t] = new WorkerPoolTask();
}
}
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
if (profilerSamplerUpdate == null) {
profilerSamplerUpdate = new CustomSampler[numThreads];
}
@ -477,7 +474,7 @@ namespace Spine.Unity {
genericSkeletonTasks[t] = new WorkerPoolTask();
}
}
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
if (profilerSamplerLateUpdate == null) {
profilerSamplerLateUpdate = new CustomSampler[numThreads];
}
@ -647,14 +644,14 @@ namespace Spine.Unity {
}
}
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
CustomSampler[] profilerSamplerUpdate = null;
CustomSampler[] profilerSamplerLateUpdate = null;
#endif
/// <summary>Perform Update at all SkeletonRenderers asynchronously.</summary>
void UpdateSkeletonsAsync (SkeletonUpdateRange range, int threadIndex) {
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
if (profilerSamplerUpdate[threadIndex] == null) {
profilerSamplerUpdate[threadIndex] = CustomSampler.Create("Spine Update " + threadIndex);
}
@ -671,7 +668,7 @@ namespace Spine.Unity {
static Action<SkeletonUpdateRange, int> cachedUpdateSkeletonsAsyncImpl = UpdateSkeletonsAsyncImpl;
static void UpdateSkeletonsAsyncImpl (SkeletonUpdateRange range, int threadIndex) {
var instance = Instance;
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
instance.profilerSamplerUpdate[threadIndex].Begin();
#endif
float deltaTime = range.deltaTime;
@ -690,7 +687,7 @@ namespace Spine.Unity {
}
}
instance.updateDone[threadIndex].Set();
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
instance.profilerSamplerUpdate[threadIndex].End();
#endif
}
@ -700,7 +697,7 @@ namespace Spine.Unity {
/// main-thread callbacks.</summary>
void UpdateSkeletonsAsyncSplit (SkeletonUpdateRange range, int threadIndex) {
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
if (profilerSamplerUpdate[threadIndex] == null) {
profilerSamplerUpdate[threadIndex] = CustomSampler.Create("Spine Update " + threadIndex);
}
@ -727,7 +724,7 @@ namespace Spine.Unity {
var splitUpdateMethod = instance.splitUpdateMethod;
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
instance.profilerSamplerUpdate[threadIndex].Begin();
#endif
for (int r = start; r < end; ++r) {
@ -742,7 +739,7 @@ namespace Spine.Unity {
}
instance.updateDone[threadIndex].Set();
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
instance.profilerSamplerUpdate[threadIndex].End();
#endif
}
@ -782,7 +779,7 @@ namespace Spine.Unity {
/// <summary>Perform LateUpdate at all SkeletonRenderers asynchronously.</summary>
static Action<SkeletonUpdateRange, int> cachedLateUpdateSkeletonsAsyncImpl = LateUpdateSkeletonsAsyncImpl;
void LateUpdateSkeletonsAsync (SkeletonUpdateRange range, int threadIndex) {
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
if (profilerSamplerLateUpdate[threadIndex] == null) {
profilerSamplerLateUpdate[threadIndex] = CustomSampler.Create("Spine LateUpdate " + threadIndex);
}
@ -801,7 +798,7 @@ namespace Spine.Unity {
int end = range.rangeEndExclusive;
var instance = Instance;
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
instance.profilerSamplerLateUpdate[threadIndex].Begin();
#endif
#if DONT_WAIT_FOR_ALL_LATEUPDATE_TASKS
@ -821,7 +818,7 @@ namespace Spine.Unity {
#if !DONT_WAIT_FOR_ALL_LATEUPDATE_TASKS
instance.lateUpdateDone[threadIndex].Set(); // signal once after all work is done
#endif
#if ENABLE_THREAD_PROFILING
#if SPINE_ENABLE_THREAD_PROFILING
instance.profilerSamplerLateUpdate[threadIndex].End();
#endif
}

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-unity",
"displayName": "spine-unity Runtime",
"description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.",
"version": "4.3.30",
"version": "4.3.31",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",