Skip to content

Commit

Permalink
Merge pull request #5990 from smoogipoo/revert-masking-ssbo
Browse files Browse the repository at this point in the history
Revert masking ssbo changes
  • Loading branch information
bdach authored Sep 14, 2023
2 parents 3f83dc3 + f2363cb commit 5307515
Show file tree
Hide file tree
Showing 24 changed files with 205 additions and 366 deletions.
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Audio/WaveformGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public override void Draw(IRenderer renderer)
// We're dealing with a _large_ number of points, so we need to optimise the quadToDraw * drawInfo.Matrix multiplications below
// for points that are going to be masked out anyway. This allows for higher resolution graphs at larger scales with virtually no performance loss.
// Since the points are generated in the local coordinate space, we need to convert the screen space masking quad coordinates into the local coordinate space
RectangleF localMaskingRectangle = (Quad.FromRectangle(renderer.CurrentMaskingInfo.ScreenSpaceScissorArea) * DrawInfo.MatrixInverse).AABBFloat;
RectangleF localMaskingRectangle = (Quad.FromRectangle(renderer.CurrentMaskingInfo.ScreenSpaceAABB) * DrawInfo.MatrixInverse).AABBFloat;

float separation = drawSize.X / (points.Count - 1);

Expand Down
17 changes: 11 additions & 6 deletions osu.Framework/Graphics/BufferedDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class BufferedDrawNode : TexturedShaderDrawNode
protected RectangleF DrawRectangle { get; private set; }

private Color4 backgroundColour;
private RectangleF localDrawRectangle;
private RectangleF screenSpaceDrawRectangle;
private Vector2 frameBufferScale;
private Vector2 frameBufferSize;
Expand All @@ -53,7 +52,6 @@ public override void ApplyState()
base.ApplyState();

backgroundColour = Source.BackgroundColour;
localDrawRectangle = Source.DrawRectangle;
screenSpaceDrawRectangle = Source.ScreenSpaceDrawQuad.AABBFloat;
DrawColourInfo = Source.FrameBufferDrawColour ?? new DrawColourInfo(Color4.White, base.DrawColourInfo.Blending);
frameBufferScale = Source.FrameBufferScale;
Expand Down Expand Up @@ -157,25 +155,32 @@ protected IDisposable BindFrameBuffer(IFrameBuffer frameBuffer)

private IDisposable establishFrameBufferViewport(IRenderer renderer)
{
// Disable masking for generating the frame buffer since masking will be re-applied
// when actually drawing later on anyways. This allows more information to be captured
// in the frame buffer and helps with cached buffers being re-used.
RectangleI screenSpaceMaskingRect = new RectangleI((int)Math.Floor(screenSpaceDrawRectangle.X), (int)Math.Floor(screenSpaceDrawRectangle.Y), (int)frameBufferSize.X + 1,
(int)frameBufferSize.Y + 1);

renderer.PushMaskingInfo(new MaskingInfo
{
ScreenSpaceScissorArea = screenSpaceDrawRectangle,
MaskingArea = localDrawRectangle,
ToMaskingSpace = DrawInfo.MatrixInverse,
ToScissorSpace = Matrix3.Identity,
ScreenSpaceAABB = screenSpaceMaskingRect,
MaskingRect = screenSpaceDrawRectangle,
ToMaskingSpace = Matrix3.Identity,
BlendRange = 1,
AlphaExponent = 1,
}, true);

// Match viewport to FrameBuffer such that we don't draw unnecessary pixels.
renderer.PushViewport(new RectangleI(0, 0, (int)frameBufferSize.X, (int)frameBufferSize.Y));
renderer.PushScissor(new RectangleI(0, 0, (int)frameBufferSize.X, (int)frameBufferSize.Y));
renderer.PushScissorOffset(screenSpaceMaskingRect.Location);

return new ValueInvokeOnDisposal<(BufferedDrawNode node, IRenderer renderer)>((this, renderer), tup => tup.node.returnViewport(tup.renderer));
}

private void returnViewport(IRenderer renderer)
{
renderer.PopScissorOffset();
renderer.PopViewport();
renderer.PopScissor();
renderer.PopMaskingInfo();
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Containers/BufferedContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public BufferedContainer(RenderBufferFormat[] formats = null, bool pixelSnapping
private void load(ShaderManager shaders)
{
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE);
blurShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2_NO_MASKING, FragmentShaderDescriptor.BLUR);
blurShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.BLUR);
}

protected override DrawNode CreateDrawNode() => new BufferedContainerDrawNode(this, sharedData);
Expand Down
13 changes: 6 additions & 7 deletions osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected class CompositeDrawableDrawNode : DrawNode, ICompositeDrawNode
private MaskingInfo? maskingInfo;

/// <summary>
/// The screen-space version of <see cref="MaskingInfo.MaskingArea"/>.
/// The screen-space version of <see cref="MaskingInfo.MaskingRect"/>.
/// Used as cache of screen-space masking quads computed in previous frames.
/// Assign null to reset.
/// </summary>
Expand Down Expand Up @@ -92,11 +92,10 @@ public override void ApplyState()
? null
: new MaskingInfo
{
ScreenSpaceScissorArea = Source.ScreenSpaceDrawQuad.AABBFloat,
MaskingArea = Source.DrawRectangle.Normalize(),
ScreenSpaceAABB = Source.ScreenSpaceDrawQuad.AABB,
MaskingRect = Source.DrawRectangle.Normalize(),
ConservativeScreenSpaceQuad = Quad.FromRectangle(shrunkDrawRectangle) * DrawInfo.Matrix,
ToMaskingSpace = DrawInfo.MatrixInverse,
ToScissorSpace = Matrix3.Identity,
CornerRadius = Source.effectiveCornerRadius,
CornerExponent = Source.CornerExponent,
BorderThickness = Source.BorderThickness,
Expand All @@ -122,13 +121,13 @@ private void drawEdgeEffect(IRenderer renderer)
if (maskingInfo == null || edgeEffect.Type == EdgeEffectType.None || edgeEffect.Radius <= 0.0f || edgeEffect.Colour.Alpha <= 0)
return;

RectangleF effectRect = maskingInfo.Value.MaskingArea.Inflate(edgeEffect.Radius).Offset(edgeEffect.Offset);
RectangleF effectRect = maskingInfo.Value.MaskingRect.Inflate(edgeEffect.Radius).Offset(edgeEffect.Offset);

screenSpaceMaskingQuad ??= Quad.FromRectangle(effectRect) * DrawInfo.Matrix;

MaskingInfo edgeEffectMaskingInfo = maskingInfo.Value;
edgeEffectMaskingInfo.MaskingArea = effectRect;
edgeEffectMaskingInfo.ScreenSpaceScissorArea = screenSpaceMaskingQuad.Value.AABBFloat;
edgeEffectMaskingInfo.MaskingRect = effectRect;
edgeEffectMaskingInfo.ScreenSpaceAABB = screenSpaceMaskingQuad.Value.AABB;
edgeEffectMaskingInfo.CornerRadius = maskingInfo.Value.CornerRadius + edgeEffect.Radius + edgeEffect.Roundness;
edgeEffectMaskingInfo.BorderThickness = 0;
// HACK HACK HACK. We abuse blend range to give us the linear alpha gradient of
Expand Down
46 changes: 23 additions & 23 deletions osu.Framework/Graphics/Lines/Path_DrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void Draw(IRenderer renderer)

texture.Bind();

updateVertexBuffer(renderer);
updateVertexBuffer();

pathShader.Unbind();

Expand All @@ -88,7 +88,7 @@ private Color4 colourAt(Vector2 localPos) => DrawColourInfo.Colour.TryExtractSin
? colour.SRGB
: DrawColourInfo.Colour.Interpolate(relativePosition(localPos)).SRGB;

private void addSegmentQuads(IRenderer renderer, Line segment, Line segmentLeft, Line segmentRight, RectangleF texRect)
private void addSegmentQuads(Line segment, Line segmentLeft, Line segmentRight, RectangleF texRect)
{
Debug.Assert(triangleBatch != null);

Expand All @@ -101,87 +101,87 @@ private void addSegmentQuads(IRenderer renderer, Line segment, Line segmentLeft,

// Each of the quads (mentioned above) is rendered as 2 triangles:
// Outer quad, triangle 1
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(segmentRight.EndPoint.X, segmentRight.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.EndPoint)
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(segmentRight.StartPoint.X, segmentRight.StartPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.StartPoint)
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});

// Outer quad, triangle 2
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = secondMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = secondMiddleColour
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(segmentRight.EndPoint.X, segmentRight.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentRight.EndPoint)
});

// Inner quad, triangle 1
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = secondMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = secondMiddleColour
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(segmentLeft.EndPoint.X, segmentLeft.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.EndPoint)
});

// Inner quad, triangle 2
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(segmentLeft.EndPoint.X, segmentLeft.EndPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.EndPoint)
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(segmentLeft.StartPoint.X, segmentLeft.StartPoint.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Colour = colourAt(segmentLeft.StartPoint)
});
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = firstMiddlePoint,
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = firstMiddleColour
});
}

private void addSegmentCaps(IRenderer renderer, float thetaDiff, Line segmentLeft, Line segmentRight, Line prevSegmentLeft, Line prevSegmentRight, RectangleF texRect)
private void addSegmentCaps(float thetaDiff, Line segmentLeft, Line segmentRight, Line prevSegmentLeft, Line prevSegmentRight, RectangleF texRect)
{
Debug.Assert(triangleBatch != null);

Expand Down Expand Up @@ -210,15 +210,15 @@ private void addSegmentCaps(IRenderer renderer, float thetaDiff, Line segmentLef
for (int i = 1; i <= stepCount; i++)
{
// Center point
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(origin.X, origin.Y, 1),
TexturePosition = new Vector2(texRect.Right, texRect.Centre.Y),
Colour = originColour
});

// First outer point
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(current.X, current.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Expand All @@ -229,7 +229,7 @@ private void addSegmentCaps(IRenderer renderer, float thetaDiff, Line segmentLef
currentColour = colourAt(current);

// Second outer point
triangleBatch.Add(new TexturedVertex3D(renderer)
triangleBatch.Add(new TexturedVertex3D
{
Position = new Vector3(current.X, current.Y, 0),
TexturePosition = new Vector2(texRect.Left, texRect.Centre.Y),
Expand All @@ -238,7 +238,7 @@ private void addSegmentCaps(IRenderer renderer, float thetaDiff, Line segmentLef
}
}

private void updateVertexBuffer(IRenderer renderer)
private void updateVertexBuffer()
{
// Explanation of the terms "left" and "right":
// "Left" and "right" are used here in terms of a typical (Cartesian) coordinate system.
Expand Down Expand Up @@ -277,15 +277,15 @@ private void updateVertexBuffer(IRenderer renderer)
Line currSegmentLeft = new Line(currSegment.StartPoint + ortho * radius, currSegment.EndPoint + ortho * radius);
Line currSegmentRight = new Line(currSegment.StartPoint - ortho * radius, currSegment.EndPoint - ortho * radius);

addSegmentQuads(renderer, currSegment, currSegmentLeft, currSegmentRight, texRect);
addSegmentQuads(currSegment, currSegmentLeft, currSegmentRight, texRect);

if (prevSegmentLeft is Line psLeft && prevSegmentRight is Line psRight)
{
Debug.Assert(i > 0);

// Connection/filler caps between segment quads
float thetaDiff = currSegment.Theta - segments[i - 1].Theta;
addSegmentCaps(renderer, thetaDiff, currSegmentLeft, currSegmentRight, psLeft, psRight, texRect);
addSegmentCaps(thetaDiff, currSegmentLeft, currSegmentRight, psLeft, psRight, texRect);
}

// Explanation of semi-circle caps:
Expand All @@ -300,7 +300,7 @@ private void updateVertexBuffer(IRenderer renderer)
Line flippedLeft = new Line(currSegmentRight.EndPoint, currSegmentRight.StartPoint);
Line flippedRight = new Line(currSegmentLeft.EndPoint, currSegmentLeft.StartPoint);

addSegmentCaps(renderer, MathF.PI, currSegmentLeft, currSegmentRight, flippedLeft, flippedRight, texRect);
addSegmentCaps(MathF.PI, currSegmentLeft, currSegmentRight, flippedLeft, flippedRight, texRect);
}

if (i == segments.Count - 1)
Expand All @@ -309,7 +309,7 @@ private void updateVertexBuffer(IRenderer renderer)
Line flippedLeft = new Line(currSegmentRight.EndPoint, currSegmentRight.StartPoint);
Line flippedRight = new Line(currSegmentLeft.EndPoint, currSegmentLeft.StartPoint);

addSegmentCaps(renderer, MathF.PI, flippedLeft, flippedRight, currSegmentLeft, currSegmentRight, texRect);
addSegmentCaps(MathF.PI, flippedLeft, flippedRight, currSegmentLeft, currSegmentRight, texRect);
}

prevSegmentLeft = currSegmentLeft;
Expand Down
1 change: 0 additions & 1 deletion osu.Framework/Graphics/OpenGL/GLRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ public void DrawVertices(PrimitiveType type, int vertexStart, int verticesCount)
var glShader = (GLShader)Shader!;

glShader.BindUniformBlock("g_GlobalUniforms", GlobalUniformBuffer!);
glShader.BindUniformBlock("g_MaskingBuffer", ShaderMaskingStack!.CurrentBuffer);

int currentUniformBinding = 0;
int currentStorageBinding = 0;
Expand Down
1 change: 0 additions & 1 deletion osu.Framework/Graphics/Rendering/Dummy/DummyRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public sealed class DummyRenderer : IRenderer
public bool IsUvOriginTopLeft => true;
public bool IsClipSpaceYInverted => true;
public ref readonly MaskingInfo CurrentMaskingInfo => ref maskingInfo;
public int CurrentMaskingIndex => 0;
private readonly MaskingInfo maskingInfo;

public RectangleI Viewport => RectangleI.Empty;
Expand Down
1 change: 1 addition & 0 deletions osu.Framework/Graphics/Rendering/FlushBatchSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum FlushBatchSource
SetBlendMask,
SetDepthInfo,
SetFrameBuffer,
SetMasking,
SetProjection,
SetScissor,
SetShader,
Expand Down
16 changes: 15 additions & 1 deletion osu.Framework/Graphics/Rendering/GlobalUniformData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ public record struct GlobalUniformData
public UniformBool IsUvOriginTopLeft;

public UniformMatrix4 ProjMatrix;
public UniformMatrix3 ToMaskingSpace;
public UniformBool IsMasking;
public UniformFloat CornerRadius;
public UniformFloat CornerExponent;
private readonly UniformPadding4 pad2;

public UniformVector4 MaskingRect;
public UniformFloat BorderThickness;
private readonly UniformPadding12 pad3;

public UniformMatrix4 BorderColour;
public UniformFloat MaskingBlendRange;
public UniformFloat AlphaExponent;
public UniformVector2 EdgeOffset;
public UniformBool DiscardInner;
public UniformFloat InnerCornerRadius;
public UniformInt WrapModeS;
public UniformInt WrapModeT;
private readonly UniformPadding8 pad1;
}
}
13 changes: 11 additions & 2 deletions osu.Framework/Graphics/Rendering/IRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public interface IRenderer
/// </summary>
ref readonly MaskingInfo CurrentMaskingInfo { get; }

int CurrentMaskingIndex { get; }

/// <summary>
/// The current viewport.
/// </summary>
Expand Down Expand Up @@ -278,6 +276,17 @@ public interface IRenderer
/// </summary>
void PopScissor();

/// <summary>
/// Applies a new scissor offset to the scissor rectangle.
/// </summary>
/// <param name="offset">The scissor offset.</param>
void PushScissorOffset(Vector2I offset);

/// <summary>
/// Restores the last scissor offset.
/// </summary>
void PopScissorOffset();

/// <summary>
/// Applies a new projection matrix.
/// </summary>
Expand Down
Loading

0 comments on commit 5307515

Please sign in to comment.