diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs index cfbb7f68c..38d8cbf4a 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/BuildSettings.cs @@ -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; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs index 37b8fdac7..ad0739137 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs @@ -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); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs index 0bc655865..bf73e1aca 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs @@ -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); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/LockFreeWorkerPool.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/LockFreeWorkerPool.cs index 1198f5a52..77327e256 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/LockFreeWorkerPool.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/LockFreeWorkerPool.cs @@ -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 : 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 : IDisposable { _taskAvailable[threadIndex].WaitOne(); } } -#if ENABLE_THREAD_PROFILING +#if SPINE_ENABLE_THREAD_PROFILING Profiler.EndThreadProfiling(); #endif } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/SkeletonUpdateSystem.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/SkeletonUpdateSystem.cs index ef8fe9e66..67196d638 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/SkeletonUpdateSystem.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Threading/SkeletonUpdateSystem.cs @@ -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 /// Perform Update at all SkeletonRenderers asynchronously. 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 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. 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 { /// Perform LateUpdate at all SkeletonRenderers asynchronously. static Action 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 } diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index 9ce95f1c6..45617d57e 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -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",