Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GLWrapper and move implementation to IRenderer #5332

Merged
merged 9 commits into from
Aug 5, 2022

Conversation

smoogipoo
Copy link
Contributor

@smoogipoo smoogipoo commented Aug 3, 2022

Prereqs:

For the most part, this is a 1-1 migration of GLWrapper implementation into OpenGLRenderer, with appropriate interfaces added to IRenderer. The rest is passing IRenderer/OpenGLRenderer to GL-specific classes (VBOs, Shaders, etc).

Important changes of note:

  • Drawable DIs in an IRenderer to dispose DrawNodes. Somehow, DrawNode disposal has to be enqueued to run 3 frames behind. There's several ways to do this, and I'm not sure if the way I've chosen here is the best. Alternatives:
    1. Make the disposal queue static.
      • Reason not done: sounds unsafe.
    2. Change Drawable.CreateDrawNode() to take an IRenderer parameter and construct DrawNodes with the renderer.
      • Reason not done: larger breaking change.
    3. Store IRenderer from Drawable.Draw()/Drawable.DrawOpaqueInteriorSubTree().
      • Reason not done: I'm not sure if this will work if exceptions are thrown (e.g. BufferedDrawNode() calls base.Draw() very late.
  • TexturedShaderDrawNode interface has changed slightly because RequiresRoundedShader() needs an IRenderer parameter. osu!-side this only results in a changes to one file.
  • Size check removed from TextureUpload. In Internalise TextureGL and rewrite Texture to take its role #5330 I've moved the check to Texture.SetData().

vNext

GLWrapper removed, replaced by IRenderer

The static GLWrapper class no longer exists, and all drawing functions should be performed via the DrawNode.Draw() IRenderer parameter. There is a 1-1 compatibility between the classes.

TexturedShaderDrawNode interface changed slightly

  • Shader -> GetAppropriateShader(IRenderer).
  • RequriesRoundedShader -> RequiresRoundedShader(IRenderer)

@smoogipoo
Copy link
Contributor Author

Will need a test on iOS, but I'm fairly confident it should work.

@smoogipoo smoogipoo mentioned this pull request Aug 3, 2022
2 tasks

/// <summary>
/// The maximum number of pixels to upload per frame.
/// Defaults to 2 megapixels (8mb alloc).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda weird to specify the defaults in the interface when it doesn't guarantee them, but I guess it's okay.

@peppy
Copy link
Member

peppy commented Aug 5, 2022

While testing on iOS, I got some crashes:

JetBrains Rider 2022-08-05 at 07 04 54

(from the finalizer thread)

and

System.NullReferenceException: Object reference not set to an instance of an object
  at osu.Framework.Graphics.OpenGL.Buffers.FrameBuffer+FrameBufferTexture.set_Width (System.Int32 value) [0x00000] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs:136 
  at osu.Framework.Graphics.OpenGL.Textures.TextureGL..ctor (osu.Framework.Graphics.OpenGL.OpenGLRenderer renderer, System.Int32 width, System.Int32 height, System.Boolean manualMipmaps, osuTK.Graphics.ES30.All filteringMode, SixLabors.ImageSharp.PixelFormats.Rgba32 initialisationColour) [0x00025] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/OpenGL/Textures/TextureGL.cs:66 
  at osu.Framework.Graphics.OpenGL.Buffers.FrameBuffer+FrameBufferTexture..ctor (osu.Framework.Graphics.OpenGL.OpenGLRenderer renderer, osuTK.Graphics.ES30.All filteringMode) [0x00000] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs:125 
  at osu.Framework.Graphics.OpenGL.Buffers.FrameBuffer..ctor (osu.Framework.Graphics.OpenGL.OpenGLRenderer renderer, osuTK.Graphics.ES30.RenderbufferInternalFormat[] renderBufferFormats, osuTK.Graphics.ES30.All filteringMode) [0x00030] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs:27 
  at osu.Framework.Graphics.OpenGL.OpenGLRenderer.CreateFrameBuffer (osu.Framework.Graphics.Rendering.RenderBufferFormat[] renderBufferFormats, osu.Framework.Graphics.Textures.TextureFilteringMode filteringMode) [0x000a5] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/OpenGL/OpenGLRenderer.cs:855 
  at osu.Framework.Graphics.BufferedDrawNodeSharedData.Initialise (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x00021] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/BufferedDrawNodeSharedData.cs:92 
  at osu.Framework.Graphics.BufferedDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x00013] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/BufferedDrawNode.cs:87 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Graphics.Containers.CompositeDrawable+CompositeDrawableDrawNode.Draw (osu.Framework.Graphics.Rendering.IRenderer renderer) [0x0009d] in /Users/dean/Projects/osu-framework/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs:204 
  at osu.Framework.Platform.GameHost.DrawFrame () [0x00168] in /Users/dean/Projects/osu-framework/osu.Framework/Platform/GameHost.cs:506 
  at osu.Framework.Threading.GameThread.processFrame () [0x000d9] in /Users/dean/Projects/osu-framework/osu.Framework/Threading/GameThread.cs:454 
--- End of stack trace from previous location where exception was thrown ---

  at osu.Framework.Platform.GameHost+<>c__DisplayClass133_0.<abortExecutionFromException>b__0 () [0x00002] in /Users/dean/Projects/osu-framework/osu.Framework/Platform/GameHost.cs:390 
  at osu.Framework.Threading.ScheduledDelegate.InvokeTask () [0x00010] in /Users/dean/Projects/osu-framework/osu.Framework/Threading/ScheduledDelegate.cs:106 
  at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal () [0x0002b] in /Users/dean/Projects/osu-framework/osu.Framework/Threading/ScheduledDelegate.cs:92 
  at osu.Framework.Threading.Scheduler.Update () [0x0008a] in /Users/dean/Projects/osu-framework/osu.Framework/Threading/Scheduler.cs:125 
  at osu.Framework.Threading.GameThread.processFrame () [0x00172] in /Users/dean/Projects/osu-framework/osu.Framework/Threading/GameThread.cs:467 
  at osu.Framework.Threading.GameThread.RunSingleFrame () [0x00001] in /Users/dean/Projects/osu-framework/osu.Framework/Threading/GameThread.cs:296 
  at osu.Framework.Platform.ThreadRunner.RunMainLoop () [0x0005f] in /Users/dean/Projects/osu-framework/osu.Framework/Platform/ThreadRunner.cs:114 
  at osu.Framework.Platform.GameHost.windowUpdate () [0x00026] in /Users/dean/Projects/osu-framework/osu.Framework/Platform/GameHost.cs:850 
  at osu.Framework.Platform.GameHost.<Run>b__155_2 (System.Object _, osuTK.FrameEventArgs _) [0x00000] in /Users/dean/Projects/osu-framework/osu.Framework/Platform/GameHost.cs:754 
  at (wrapper delegate-invoke) System.EventHandler`1[osuTK.FrameEventArgs].invoke_void_object_TEventArgs(object,osuTK.FrameEventArgs)
  at osuTK.iOS.iOSGameView.OnUpdateFrame (osuTK.FrameEventArgs e) [0x0000a] in <0fc4a59399e2486f977f9fdb230650a4>:0 
  at osuTK.iOS.iOSGameView.RunIteration (Foundation.NSTimer timer) [0x00042] in <0fc4a59399e2486f977f9fdb230650a4>:0 
  at osuTK.iOS.CADisplayLinkTimeSource.RunIteration (Foundation.NSObject parameter) [0x00000] in <0fc4a59399e2486f977f9fdb230650a4>:0 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:83 
  at osu.Framework.Tests.Application.Main (System.String[] args) [0x00001] in /Users/dean/Projects/osu-framework/osu.Framework.Tests.iOS/Application.cs:18 

JetBrains Rider 2022-08-05 at 07 07 45

JetBrains Rider 2022-08-05 at 07 07 57

Both of these only started after selecting osu.Framework.Tests.Visual.Drawables.TestSceneCircularArcBoundingBox, and now occur on startup due to that test being loaded first.

@smoogipoo
Copy link
Contributor Author

smoogipoo commented Aug 5, 2022

Good catch, came about due to the removal of the null check in the previous PR that wasn't tested in combination with this branch. Fixed.

@peppy
Copy link
Member

peppy commented Aug 5, 2022

I guess the first crash was just triggered as a side-effect of the second and in normal execution won't happen due to the Renderer being the first thing to be initialised now?

@smoogipoo
Copy link
Contributor Author

That's correct, yeah.

@peppy peppy enabled auto-merge August 5, 2022 07:21
@peppy peppy merged commit 306ce5e into ppy:master Aug 5, 2022
@smoogipoo smoogipoo deleted the irenderer-glwrapper branch September 11, 2023 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants