diff --git a/Assets/Scripts/Modules/GameModule.Interop.cs b/Assets/Scripts/Modules/GameModule.Interop.cs index 022aafc..b74731f 100644 --- a/Assets/Scripts/Modules/GameModule.Interop.cs +++ b/Assets/Scripts/Modules/GameModule.Interop.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using AOT; using UnityEngine; +using UnityEngine.Profiling; public partial class GameModule : CallbackHandler { @@ -44,7 +45,9 @@ public partial class GameModule : CallbackHandler [MonoPInvokeCallback(typeof(GameSetEntityModelCallback))] private static void Callback_GameSetEntityModel(IntPtr target, int entityNum, string modelName) { + Profiler.BeginSample("GameSetEntityModel"); GetSelf(target).SetEntityModel(entityNum, modelName); + Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -53,7 +56,9 @@ public partial class GameModule : CallbackHandler [MonoPInvokeCallback(typeof(GameSetEntityTransformCallback))] private static void Callback_GameSetEntityTransform(IntPtr target, int entityNum, ref QVec3 origin, ref QVec3 angles) { + Profiler.BeginSample("GameSetEntityTransform"); GetSelf(target).SetEntityTransform(entityNum, origin, angles); + Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -62,7 +67,9 @@ public partial class GameModule : CallbackHandler [MonoPInvokeCallback(typeof(GameRemoveEntityCallback))] private static void Callback_GameRemoveEntity(IntPtr target, int entityNum) { + Profiler.BeginSample("GameRemoveEntity"); GetSelf(target).RemoveEntity(entityNum); + Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -71,7 +78,9 @@ public partial class GameModule : CallbackHandler [MonoPInvokeCallback(typeof(GameUpdateEntityAnimationCallback))] private static void Callback_GameUpdateEntityAnimation(IntPtr target, int entityNum, int pose1, int pose2, float blend) { + Profiler.BeginSample("GameUpdateEntityAnimation"); GetSelf(target).UpdateEntityAnimation(entityNum, pose1, pose2, blend); + Profiler.EndSample(); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -80,6 +89,8 @@ public partial class GameModule : CallbackHandler [MonoPInvokeCallback(typeof(GameSetEntitySkinCallback))] private static void Callback_GameSetEntitySkin(IntPtr target, int entityNum, int skinNum) { + Profiler.BeginSample("GameSetEntitySkin"); GetSelf(target).SetEntitySkin(entityNum, skinNum); + Profiler.EndSample(); } } diff --git a/Assets/Scripts/Modules/RenderModule.Interop.cs b/Assets/Scripts/Modules/RenderModule.Interop.cs index a14af10..10e61d6 100644 --- a/Assets/Scripts/Modules/RenderModule.Interop.cs +++ b/Assets/Scripts/Modules/RenderModule.Interop.cs @@ -2,6 +2,7 @@ using System.Runtime.InteropServices; using AOT; using UnityEngine; +using UnityEngine.Profiling; public partial class RenderModule: CallbackHandler { @@ -57,6 +58,8 @@ public partial class RenderModule: CallbackHandler return 0; } + Profiler.BeginSample("UploadAliasModel"); + if (header.numFrames > MaxAliasFrames) header.numFrames = MaxAliasFrames; @@ -83,11 +86,14 @@ public partial class RenderModule: CallbackHandler fbTextures[i] = header.fbTextures[i * 4].ToStructArray(4); } - return GetSelf(target).UploadAliasModel( + int result = GetSelf(target).UploadAliasModel( name, header, frameType, poseVertices, triangles.ToStructArray(header.numTriangles), stVerts.ToStructArray(header.numVerts), glTextures, fbTextures); + + Profiler.EndSample(); + return result; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -99,7 +105,10 @@ public partial class RenderModule: CallbackHandler if (model == null || model.type != QModelType.Brush) return -1; - return GetSelf(target).UploadBrushModel(model); + Profiler.BeginSample("UploadBrushModel"); + int result = GetSelf(target).UploadBrushModel(model); + Profiler.EndSample(); + return result; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -111,7 +120,10 @@ public partial class RenderModule: CallbackHandler if (model == null || model.type != QModelType.Brush) return -1; - return GetSelf(target).UploadWorldModel(model); + Profiler.BeginSample("UploadWorldModel"); + int result = GetSelf(target).UploadWorldModel(model); + Profiler.EndSample(); + return result; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -120,9 +132,14 @@ public partial class RenderModule: CallbackHandler [MonoPInvokeCallback(typeof(UploadTextureCallback))] private static bool Callback_UploadTexture(IntPtr target, QGLTexture texture, IntPtr data, ref uint texNum) { + Profiler.BeginSample("UploadTexture"); + byte[] dataBytes = new byte[texture.width * texture.height * 4]; // 32 bits per pixel Marshal.Copy(data, dataBytes, 0, dataBytes.Length); - return GetSelf(target).UploadTexture(texture, dataBytes, ref texNum); + bool result = GetSelf(target).UploadTexture(texture, dataBytes, ref texNum); + + Profiler.EndSample(); + return result; } private readonly byte[] lightmapBytes = new byte[QConstants.LightmapBlockWidth * QConstants.LightmapBlockHeight * 4]; // 32 bits per pixel @@ -133,10 +150,15 @@ public partial class RenderModule: CallbackHandler [MonoPInvokeCallback(typeof(UploadLightmapCallback))] private static bool Callback_UploadLightmap(IntPtr target, int lmap, IntPtr data) { + Profiler.BeginSample("UploadLightmap"); + // TODO: this is a fairly pointless additional data copy step; we could probably make this faster by wrapping the IntPtr directly into a NativeArray var self = GetSelf(target); Marshal.Copy(data, self.lightmapBytes, 0, self.lightmapBytes.Length); - return self.UploadLightmap(lmap, QConstants.LightmapBlockWidth, QConstants.LightmapBlockHeight, self.lightmapBytes); + bool result = self.UploadLightmap(lmap, QConstants.LightmapBlockWidth, QConstants.LightmapBlockHeight, self.lightmapBytes); + + Profiler.EndSample(); + return result; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -145,6 +167,8 @@ public partial class RenderModule: CallbackHandler [MonoPInvokeCallback(typeof(SetupViewCallback))] private static void Callback_SetupView(IntPtr target, ref QVec3 origin, ref QVec3 angles, ref QLeaf viewLeaf) { + Profiler.BeginSample("SetupView"); GetSelf(target).SetupView(origin, angles, viewLeaf); + Profiler.EndSample(); } }