-
Notifications
You must be signed in to change notification settings - Fork 458
Dispose VBOs created during mipmap generation #5755
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
base: master
Are you sure you want to change the base?
Conversation
|
This branch somehow is causing segfaults on my linux setup (ubuntu 22.04, NVIDIA GeForce RTX 3060 laptop version, nvidia proprietary drivers, legacy gl) that are not there on Not sure where to even begin with this, but I'll have a poke... |
|
Following patch appears to fix the segfault: diff --git a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
index 524fa8d57..4d66540b4 100644
--- a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
+++ b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
@@ -81,7 +81,7 @@ protected virtual void Initialise()
public void Dispose()
{
- Dispose(true);
+ Renderer.ScheduleDisposal(v => v.Dispose(true), this);
GC.SuppressFinalize(this);
}
I would be lying if I said I'm entirely following why, but that was the primary difference between |
|
Hmm, that's pretty weird. It should definitely be a valid operation to delete a VBO after a Or… are you able to repro in debug? Can you check if it fails on the |
Removing the schedule for veldrid vertex buffer does not seem to reproduce the same segfault, no. I have no clue why this is the case, but that's what I'm seeing.
Debug doesn't do much here since it's a segfault, and so the kernel just kills the game process. The disposal completes just fine ( diff --git a/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs b/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs
index 904f20812..175fee0b8 100644
--- a/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs
+++ b/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs
@@ -314,8 +314,8 @@ public unsafe bool Upload()
// Perform the actual mip level draw
Renderer.PushViewport(new RectangleI(0, 0, width, height));
- quadBuffer.Update();
- quadBuffer.Draw();
+ //quadBuffer.Update();
+ //quadBuffer.Draw();
Renderer.PopViewport();
}then the game looks broken (because mipmaps are now empty), but at least it stops segfaulting. So to my uneducated eye this appears to be an indication that the nvidia driver might be reordering gl calls such that both the update and draw calls end up being called after the VBO is disposed causing it to panic. It is also both calls that need to be commented out to observe this, commenting just any one of those two without commenting the other still causes a crash. |
|
You could try inserting a Another thing comes to mind is if VAOs should be unbound before deleting it. Veldrid for example generates one VAO and always keeps it bound for the lifetime of the graphics device. It would make sense why it doesn't fail when scheduling the disposal, because another VAO would've already been bound before deleting the current one. Try this and see if it helps: diff --git a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
index 524fa8d57..f94d2b0f3 100644
--- a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
+++ b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
@@ -177,6 +177,8 @@ void IVertexBuffer.Free()
{
if (isInitialised)
{
+ GL.BindVertexArray(0);
+
GL.DeleteBuffer(vboId);
GL.DeleteVertexArray(vaoId);
}Or: diff --git a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
index 524fa8d57..0fa00d9b4 100644
--- a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
+++ b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
@@ -114,6 +114,7 @@ public void Bind(bool forRendering)
public virtual void Unbind()
{
+ Renderer.BindVertexArray(0);
}
protected virtual int ToElements(int vertices) => vertices;
@@ -133,6 +134,8 @@ public void DrawRange(int startIndex, int endIndex)
int countVertices = endIndex - startIndex;
GL.DrawElements(Type, ToElements(countVertices), DrawElementsType.UnsignedShort, (IntPtr)(ToElementIndex(startIndex) * sizeof(ushort)));
+
+ Unbind();
}
public void Update()
@@ -150,6 +153,8 @@ public void UpdateRange(int startIndex, int endIndex)
GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)(startIndex * STRIDE), (IntPtr)(countVertices * STRIDE), ref getMemory().Span[startIndex]);
FrameStatistics.Add(StatisticsCounterType.VerticesUpl, countVertices);
+
+ Unbind();
}
private ref Memory<DepthWrappingVertex<T>> getMemory()or maybe just generate one VAO and bind it for the lifetime of the renderer. |
I tried applying this: diff --git a/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs b/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs
index 904f20812..3b081c2aa 100644
--- a/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs
+++ b/osu.Framework/Graphics/OpenGL/Textures/GLTexture.cs
@@ -316,6 +316,7 @@ public unsafe bool Upload()
quadBuffer.Update();
quadBuffer.Draw();
+ GL.Finish();
Renderer.PopViewport();
}and it still segfaults.
This one doesn't work either, but:
this one appears to stop the crashes. |
|
That's interesting, I'm also wondering if commenting the |
|
If you mean something like this: diff --git a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
index 524fa8d57..285f0eb7c 100644
--- a/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
+++ b/osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
@@ -178,7 +178,7 @@ void IVertexBuffer.Free()
if (isInitialised)
{
GL.DeleteBuffer(vboId);
- GL.DeleteVertexArray(vaoId);
+ //GL.DeleteVertexArray(vaoId);
}
memoryOwner?.Dispose();then yes, not deleting the VAO also fixes. |
I don't think this would've caused any problems because these are periodically free'd via
osu-framework/osu.Framework/Graphics/Rendering/Renderer.cs
Lines 811 to 823 in 7c5b248