From 00f1d1b53cc47c9be1743bf1b69d28b0c89ee659 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Jul 2019 00:53:00 +0900 Subject: [PATCH 1/6] Reduce Triangle drawnode overhead by ~90% This was never batching, ever. Pointless memory overhead. --- osu.Game/Graphics/Backgrounds/Triangles.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 29113e0e2f..3502531d13 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -137,11 +137,13 @@ namespace osu.Game.Graphics.Backgrounds } } + protected int AimCount; + private void addTriangles(bool randomY) { - int aimTriangleCount = (int)(DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale) * SpawnRatio); + AimCount = (int)(DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale) * SpawnRatio); - for (int i = 0; i < aimTriangleCount - parts.Count; i++) + for (int i = 0; i < AimCount - parts.Count; i++) parts.Add(createTriangle(randomY)); } @@ -190,11 +192,12 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); private Vector2 size; - private readonly LinearBatch vertexBatch = new LinearBatch(100 * 3, 10, PrimitiveType.Triangles); + private readonly LinearBatch vertexBatch; public TrianglesDrawNode(Triangles source) : base(source) { + vertexBatch = new LinearBatch(source.AimCount * 3, 2, PrimitiveType.Triangles); } public override void ApplyState() From a23bb3a6b32f48355dbb6f0b837d1835e4b0a14b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Jul 2019 01:14:55 +0900 Subject: [PATCH 2/6] Account for headless nulls (but how?) --- osu.Game/Graphics/Backgrounds/Triangles.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 3502531d13..20e92cd2c6 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -249,7 +249,7 @@ namespace osu.Game.Graphics.Backgrounds { base.Dispose(isDisposing); - vertexBatch.Dispose(); + vertexBatch?.Dispose(); } } From 95f36c36c4d00dc53c8b27bd2bb44c167d21b739 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Jul 2019 01:52:53 +0900 Subject: [PATCH 3/6] Late-initialize vertex batch for safety --- osu.Game/Graphics/Backgrounds/Triangles.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 20e92cd2c6..4f50abc985 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -192,12 +192,11 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); private Vector2 size; - private readonly LinearBatch vertexBatch; + private LinearBatch vertexBatch; public TrianglesDrawNode(Triangles source) : base(source) { - vertexBatch = new LinearBatch(source.AimCount * 3, 2, PrimitiveType.Triangles); } public override void ApplyState() @@ -214,6 +213,9 @@ namespace osu.Game.Graphics.Backgrounds public override void Draw(Action vertexAction) { + if (vertexBatch == null && Source.AimCount > 0) + vertexBatch = new LinearBatch(Source.AimCount * 3, 2, PrimitiveType.Triangles); + base.Draw(vertexAction); shader.Bind(); From 024f136d820db7791324d988fc4e9d2a20e47676 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Jul 2019 14:24:11 +0900 Subject: [PATCH 4/6] Reduce buffer count by one --- osu.Game/Graphics/Backgrounds/Triangles.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 4f50abc985..62151d066b 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -213,11 +213,14 @@ namespace osu.Game.Graphics.Backgrounds public override void Draw(Action vertexAction) { - if (vertexBatch == null && Source.AimCount > 0) - vertexBatch = new LinearBatch(Source.AimCount * 3, 2, PrimitiveType.Triangles); - base.Draw(vertexAction); + if (vertexBatch == null || vertexBatch.Size != Source.AimCount * 6) + { + vertexBatch?.Dispose(); + vertexBatch = new LinearBatch(Source.AimCount * 6, 1, PrimitiveType.Triangles); + } + shader.Bind(); Vector2 localInflationAmount = edge_smoothness * DrawInfo.MatrixInverse.ExtractScale().Xy; From eebfdd88650446da481fdfceebbfdb0b1f17c8ec Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Jul 2019 23:43:25 +0900 Subject: [PATCH 5/6] Update framework --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 9aa5e631ad..b9451fc744 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -63,6 +63,6 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 86a68d2159..d90b1d36e1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -15,7 +15,7 @@ - + diff --git a/osu.iOS.props b/osu.iOS.props index 712effcc39..fa2521a19e 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -105,8 +105,8 @@ - - + + From 5696d794235850fc37578ef475c4b91e2ec74d98 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 19 Jul 2019 23:47:48 +0900 Subject: [PATCH 6/6] Use TriangleBatch --- osu.Game/Graphics/Backgrounds/Triangles.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/Triangles.cs b/osu.Game/Graphics/Backgrounds/Triangles.cs index 62151d066b..a2d8f42fac 100644 --- a/osu.Game/Graphics/Backgrounds/Triangles.cs +++ b/osu.Game/Graphics/Backgrounds/Triangles.cs @@ -8,7 +8,6 @@ using osuTK.Graphics; using System; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Textures; -using osuTK.Graphics.ES30; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Primitives; using osu.Framework.Allocation; @@ -192,7 +191,7 @@ namespace osu.Game.Graphics.Backgrounds private readonly List parts = new List(); private Vector2 size; - private LinearBatch vertexBatch; + private TriangleBatch vertexBatch; public TrianglesDrawNode(Triangles source) : base(source) @@ -215,10 +214,10 @@ namespace osu.Game.Graphics.Backgrounds { base.Draw(vertexAction); - if (vertexBatch == null || vertexBatch.Size != Source.AimCount * 6) + if (vertexBatch == null || vertexBatch.Size != Source.AimCount) { vertexBatch?.Dispose(); - vertexBatch = new LinearBatch(Source.AimCount * 6, 1, PrimitiveType.Triangles); + vertexBatch = new TriangleBatch(Source.AimCount, 1); } shader.Bind();