From 02274bcdfd2456fdef2e374caf82079d56fa24c9 Mon Sep 17 00:00:00 2001 From: smitdylan2001 Date: Mon, 12 Sep 2022 10:34:18 +0200 Subject: [PATCH] URP Performance Improvements Some simple performance improvements. Would be good to take these into new commits as well and could be backported Improved CPU performance with: - Re ordering vector calculations - Removing indirect gameObject call - Simplify LINQ comparison - Using native lenght or count instead of LINQ - Simplify string comparisons - Merge if/else return into 1 return statement --- .../Editor/2D/GameObjectCreation.cs | 2 +- .../Editor/2D/Light2DEditorUtility.cs | 4 +-- .../LightBatchingDebugger.cs | 18 +++++------ .../Editor/2D/ShadowCaster2DEditor.cs | 9 ++---- .../ShapeEditor/EditablePath/BezierUtility.cs | 2 +- .../Editor/AnimationClipUpgrader.cs | 2 +- .../MaterialPostprocessor.cs | 2 +- .../Editor/Converter/Converters.cs | 2 +- .../Converter/MaterialReferenceBuilder.cs | 2 +- .../RenderPipelineConvertersEditor.cs | 10 +++---- ...edUniversalRenderPipelineGlobalSettings.cs | 2 +- .../Editor/ShaderPreprocessor.cs | 24 ++++----------- .../Editor/UpgradeUtility.cs | 2 +- .../Runtime/LightCookieManager.cs | 2 +- .../Runtime/NativeRenderPass.cs | 4 +-- .../Runtime/Passes/DrawObjectsPass.cs | 3 +- .../Runtime/Passes/PostProcessPass.cs | 2 +- .../Runtime/SceneViewDrawMode.cs | 30 ++++++++----------- 18 files changed, 50 insertions(+), 72 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs b/Packages/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs index 61491ba7da6..963933463c5 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/2D/GameObjectCreation.cs @@ -42,7 +42,7 @@ internal static void Place(GameObject go, GameObject parentTransform) transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; - go.layer = parentTransform.gameObject.layer; + go.layer = parentTransform.layer; if (parentTransform.GetComponent()) ObjectFactory.AddComponent(go); diff --git a/Packages/com.unity.render-pipelines.universal/Editor/2D/Light2DEditorUtility.cs b/Packages/com.unity.render-pipelines.universal/Editor/2D/Light2DEditorUtility.cs index 82fde669b49..7cc0b395e19 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/2D/Light2DEditorUtility.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/2D/Light2DEditorUtility.cs @@ -16,7 +16,7 @@ static internal void GUITextureCap(int controlID, Texture texture, Vector3 posit { case (EventType.Layout): { - Vector2 size2 = Vector2.one * size * 0.5f; + Vector2 size2 = 0.5f * size * Vector2.one; if (isAngleHandle) size2.x = 0.0f; @@ -32,7 +32,7 @@ static internal void GUITextureCap(int controlID, Texture texture, Vector3 posit float w = texture.width; float h = texture.height; float max = Mathf.Max(w, h); - Vector3 scale = new Vector2(w / max, h / max) * size * 0.5f; + Vector3 scale = 0.5f * size * new Vector2(w / max, h / max); if (Camera.current == null) scale.y *= -1f; diff --git a/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs b/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs index c0111c57645..b0d7a830de2 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/2D/LightBatchingDebugger/LightBatchingDebugger.cs @@ -133,7 +133,7 @@ private VisualElement GetInfoView() private void ViewBatch(int index) { - if (index >= batchList.Count()) + if (index >= batchList.Count) return; var infoView = GetInfoView(); @@ -150,7 +150,7 @@ private void ViewBatch(int index) var lightLabel1 = infoView.Query