Move support buffer update out of the backends (#5411)
* Move support buffer update out of the backends * Fix render scale init and remove redundant state from SupportBufferUpdater * Stop passing texture scale to the backends * XML docs for SupportBufferUpdater
This commit is contained in:
parent
fa32ef9275
commit
9c6071a645
51 changed files with 364 additions and 496 deletions
|
@ -114,7 +114,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
|
|||
originalInfo.SwizzleB,
|
||||
originalInfo.SwizzleA);
|
||||
|
||||
_intermediaryTexture = new TextureStorage(_renderer, info, view.ScaleFactor);
|
||||
_intermediaryTexture = new TextureStorage(_renderer, info);
|
||||
_intermediaryTexture.CreateDefaultView();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
|
|||
if (_textureStorage == null || _textureStorage.Info.Width != view.Width || _textureStorage.Info.Height != view.Height)
|
||||
{
|
||||
_textureStorage?.Dispose();
|
||||
_textureStorage = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_textureStorage = new TextureStorage(_renderer, view.Info);
|
||||
_textureStorage.CreateDefaultView();
|
||||
}
|
||||
|
||||
|
|
|
@ -147,8 +147,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
|
|||
SwizzleComponent.Blue,
|
||||
SwizzleComponent.Alpha);
|
||||
|
||||
_areaTexture = new TextureStorage(_renderer, areaInfo, 1);
|
||||
_searchTexture = new TextureStorage(_renderer, searchInfo, 1);
|
||||
_areaTexture = new TextureStorage(_renderer, areaInfo);
|
||||
_searchTexture = new TextureStorage(_renderer, searchInfo);
|
||||
|
||||
var areaTexture = EmbeddedResources.Read("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaAreaTexture.bin");
|
||||
var searchTexture = EmbeddedResources.Read("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaSearchTexture.bin");
|
||||
|
@ -165,11 +165,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
|
|||
if (_outputTexture == null || _outputTexture.Info.Width != view.Width || _outputTexture.Info.Height != view.Height)
|
||||
{
|
||||
_outputTexture?.Dispose();
|
||||
_outputTexture = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_outputTexture = new TextureStorage(_renderer, view.Info);
|
||||
_outputTexture.CreateDefaultView();
|
||||
_edgeOutputTexture = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_edgeOutputTexture = new TextureStorage(_renderer, view.Info);
|
||||
_edgeOutputTexture.CreateDefaultView();
|
||||
_blendOutputTexture = new TextureStorage(_renderer, view.Info, view.ScaleFactor);
|
||||
_blendOutputTexture = new TextureStorage(_renderer, view.Info);
|
||||
_blendOutputTexture.CreateDefaultView();
|
||||
|
||||
DeleteShaders();
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
SwizzleComponent.Red,
|
||||
SwizzleComponent.Green,
|
||||
SwizzleComponent.Blue,
|
||||
SwizzleComponent.Alpha), 1f);
|
||||
SwizzleComponent.Alpha));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -11,15 +11,13 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
|
||||
public int Width => Info.Width;
|
||||
public int Height => Info.Height;
|
||||
public float ScaleFactor { get; }
|
||||
|
||||
public Target Target => Info.Target;
|
||||
public Format Format => Info.Format;
|
||||
|
||||
public TextureBase(TextureCreateInfo info, float scaleFactor = 1f)
|
||||
public TextureBase(TextureCreateInfo info)
|
||||
{
|
||||
Info = info;
|
||||
ScaleFactor = scaleFactor;
|
||||
|
||||
Handle = GL.GenTexture();
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
|
||||
public TextureView BgraSwap(TextureView from)
|
||||
{
|
||||
TextureView to = (TextureView)_renderer.CreateTexture(from.Info, from.ScaleFactor);
|
||||
TextureView to = (TextureView)_renderer.CreateTexture(from.Info);
|
||||
|
||||
EnsurePbo(from);
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
{
|
||||
public ITextureInfo Storage => this;
|
||||
public int Handle { get; private set; }
|
||||
public float ScaleFactor { get; private set; }
|
||||
|
||||
public TextureCreateInfo Info { get; }
|
||||
|
||||
|
@ -18,13 +17,12 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
|
||||
internal ITexture DefaultView { get; private set; }
|
||||
|
||||
public TextureStorage(OpenGLRenderer renderer, TextureCreateInfo info, float scaleFactor)
|
||||
public TextureStorage(OpenGLRenderer renderer, TextureCreateInfo info)
|
||||
{
|
||||
_renderer = renderer;
|
||||
Info = info;
|
||||
|
||||
Handle = GL.GenTexture();
|
||||
ScaleFactor = scaleFactor;
|
||||
|
||||
CreateImmutableStorage();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
|||
TextureStorage parent,
|
||||
TextureCreateInfo info,
|
||||
int firstLayer,
|
||||
int firstLevel) : base(info, parent.ScaleFactor)
|
||||
int firstLevel) : base(info)
|
||||
{
|
||||
_renderer = renderer;
|
||||
_parent = parent;
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
return new Sampler(info);
|
||||
}
|
||||
|
||||
public ITexture CreateTexture(TextureCreateInfo info, float scaleFactor)
|
||||
public ITexture CreateTexture(TextureCreateInfo info)
|
||||
{
|
||||
if (info.Target == Target.TextureBuffer)
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
}
|
||||
else
|
||||
{
|
||||
return ResourcePool.GetTextureOrNull(info, scaleFactor) ?? new TextureStorage(this, info, scaleFactor).CreateDefaultView();
|
||||
return ResourcePool.GetTextureOrNull(info) ?? new TextureStorage(this, info).CreateDefaultView();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,9 +194,9 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
ResourcePool.Tick();
|
||||
}
|
||||
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, bool hostReserved)
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
return _counters.QueueReport(type, resultHandler, _pipeline.DrawCount, hostReserved);
|
||||
return _counters.QueueReport(type, resultHandler, divisor, _pipeline.DrawCount, hostReserved);
|
||||
}
|
||||
|
||||
public void Initialize(GraphicsDebugLevel glLogLevel)
|
||||
|
@ -210,7 +210,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
GL.Arb.MaxShaderCompilerThreads(Math.Min(Environment.ProcessorCount, 8));
|
||||
}
|
||||
|
||||
_pipeline.Initialize(this);
|
||||
_counters.Initialize(_pipeline);
|
||||
|
||||
// This is required to disable [0, 1] clamping for SNorm outputs on compatibility profiles.
|
||||
|
|
|
@ -44,9 +44,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
private CounterQueueEvent _activeConditionalRender;
|
||||
|
||||
private readonly Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
|
||||
private readonly Vector4<float>[] _renderScale = new Vector4<float>[73];
|
||||
private int _fragmentScaleCount;
|
||||
private Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
|
||||
|
||||
private readonly (TextureBase, Format)[] _images;
|
||||
private TextureBase _unit0Texture;
|
||||
|
@ -66,7 +64,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
private bool _tfEnabled;
|
||||
private TransformFeedbackPrimitiveType _tfTopology;
|
||||
|
||||
private SupportBufferUpdater _supportBuffer;
|
||||
private readonly BufferHandle[] _tfbs;
|
||||
private readonly BufferRange[] _tfbTargets;
|
||||
|
||||
|
@ -84,22 +81,10 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
_images = new (TextureBase, Format)[SavedImages];
|
||||
|
||||
var defaultScale = new Vector4<float> { X = 1f, Y = 0f, Z = 0f, W = 0f };
|
||||
new Span<Vector4<float>>(_renderScale).Fill(defaultScale);
|
||||
|
||||
_tfbs = new BufferHandle[Constants.MaxTransformFeedbackBuffers];
|
||||
_tfbTargets = new BufferRange[Constants.MaxTransformFeedbackBuffers];
|
||||
}
|
||||
|
||||
public void Initialize(OpenGLRenderer renderer)
|
||||
{
|
||||
_supportBuffer = new SupportBufferUpdater(renderer);
|
||||
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, Unsafe.As<BufferHandle, int>(ref _supportBuffer.Handle));
|
||||
|
||||
_supportBuffer.UpdateFragmentIsBgra(_fpIsBgra, 0, SupportBuffer.FragmentIsBgraCount);
|
||||
_supportBuffer.UpdateRenderScale(_renderScale, 0, SupportBuffer.RenderScaleMaxCount);
|
||||
}
|
||||
|
||||
public void Barrier()
|
||||
{
|
||||
GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits);
|
||||
|
@ -684,8 +669,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
if (texture is TextureView view && sampler is Sampler samp)
|
||||
{
|
||||
_supportBuffer.Commit();
|
||||
|
||||
if (HwCapabilities.SupportsDrawTexture)
|
||||
{
|
||||
GL.NV.DrawTexture(
|
||||
|
@ -777,16 +760,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
_tfEnabled = false;
|
||||
}
|
||||
|
||||
public double GetCounterDivisor(CounterType type)
|
||||
{
|
||||
if (type == CounterType.SamplesPassed)
|
||||
{
|
||||
return _renderScale[0].X * _renderScale[0].X;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void SetAlphaTest(bool enable, float reference, CompareOp op)
|
||||
{
|
||||
if (!enable)
|
||||
|
@ -1172,12 +1145,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
_rasterizerDiscard = discard;
|
||||
}
|
||||
|
||||
public void SetRenderTargetScale(float scale)
|
||||
{
|
||||
_renderScale[0].X = scale;
|
||||
_supportBuffer.UpdateRenderScale(_renderScale, 0, 1); // Just the first element.
|
||||
}
|
||||
|
||||
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMasks)
|
||||
{
|
||||
_componentMasks = 0;
|
||||
|
@ -1194,8 +1161,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
EnsureFramebuffer();
|
||||
|
||||
bool isBgraChanged = false;
|
||||
|
||||
for (int index = 0; index < colors.Length; index++)
|
||||
{
|
||||
TextureView color = (TextureView)colors[index];
|
||||
|
@ -1209,18 +1174,12 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
if (_fpIsBgra[index].X != isBgra)
|
||||
{
|
||||
_fpIsBgra[index].X = isBgra;
|
||||
isBgraChanged = true;
|
||||
|
||||
RestoreComponentMask(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isBgraChanged)
|
||||
{
|
||||
_supportBuffer.UpdateFragmentIsBgra(_fpIsBgra, 0, SupportBuffer.FragmentIsBgraCount);
|
||||
}
|
||||
|
||||
TextureView depthStencilView = (TextureView)depthStencil;
|
||||
|
||||
_framebuffer.AttachDepthStencil(depthStencilView);
|
||||
|
@ -1411,7 +1370,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
_vertexArray.SetVertexBuffers(vertexBuffers);
|
||||
}
|
||||
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports, bool disableTransform)
|
||||
public void SetViewports(ReadOnlySpan<Viewport> viewports)
|
||||
{
|
||||
Array.Resize(ref _viewportArray, viewports.Length * 4);
|
||||
Array.Resize(ref _depthRangeArray, viewports.Length * 2);
|
||||
|
@ -1450,19 +1409,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
GL.ViewportArray(0, viewports.Length, viewportArray);
|
||||
GL.DepthRangeArray(0, viewports.Length, depthRangeArray);
|
||||
|
||||
float disableTransformF = disableTransform ? 1.0f : 0.0f;
|
||||
if (_supportBuffer.Data.ViewportInverse.W != disableTransformF || disableTransform)
|
||||
{
|
||||
float scale = _renderScale[0].X;
|
||||
_supportBuffer.UpdateViewportInverse(new Vector4<float>
|
||||
{
|
||||
X = scale * 2f / viewports[0].Region.Width,
|
||||
Y = scale * 2f / viewports[0].Region.Height,
|
||||
Z = 1,
|
||||
W = disableTransformF
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void TextureBarrier()
|
||||
|
@ -1552,36 +1498,9 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
return (_boundDrawFramebuffer, _boundReadFramebuffer);
|
||||
}
|
||||
|
||||
public void UpdateRenderScale(ReadOnlySpan<float> scales, int totalCount, int fragmentCount)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
for (int index = 0; index < totalCount; index++)
|
||||
{
|
||||
if (_renderScale[1 + index].X != scales[index])
|
||||
{
|
||||
_renderScale[1 + index].X = scales[index];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update fragment count if there are scales after it for the vertex stage.
|
||||
if (fragmentCount != totalCount && fragmentCount != _fragmentScaleCount)
|
||||
{
|
||||
_fragmentScaleCount = fragmentCount;
|
||||
_supportBuffer.UpdateFragmentRenderScaleCount(_fragmentScaleCount);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
_supportBuffer.UpdateRenderScale(_renderScale, 0, 1 + totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareForDispatch()
|
||||
{
|
||||
_unit0Texture?.Bind(0);
|
||||
_supportBuffer.Commit();
|
||||
}
|
||||
|
||||
private void PreDraw(int vertexCount)
|
||||
|
@ -1601,7 +1520,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
DrawCount++;
|
||||
|
||||
_unit0Texture?.Bind(0);
|
||||
_supportBuffer.Commit();
|
||||
}
|
||||
|
||||
private void PostDraw()
|
||||
|
@ -1752,8 +1670,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
_supportBuffer?.Dispose();
|
||||
|
||||
for (int i = 0; i < Constants.MaxTransformFeedbackBuffers; i++)
|
||||
{
|
||||
if (_tfbs[i] != BufferHandle.Null)
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
|||
}
|
||||
}
|
||||
|
||||
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, ulong lastDrawIndex, bool hostReserved)
|
||||
public CounterQueueEvent QueueReport(EventHandler<ulong> resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved)
|
||||
{
|
||||
CounterQueueEvent result;
|
||||
ulong draws = lastDrawIndex - _current.DrawIndex;
|
||||
|
@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
|||
_current.ReserveForHostAccess();
|
||||
}
|
||||
|
||||
_current.Complete(draws > 0, _pipeline.GetCounterDivisor(Type));
|
||||
_current.Complete(draws > 0, divisor);
|
||||
_events.Enqueue(_current);
|
||||
|
||||
_current.OnResult += resultHandler;
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
|||
}
|
||||
}
|
||||
|
||||
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, ulong lastDrawIndex, bool hostReserved)
|
||||
public CounterQueueEvent QueueReport(CounterType type, EventHandler<ulong> resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved)
|
||||
{
|
||||
return _counterQueues[(int)type].QueueReport(resultHandler, lastDrawIndex, hostReserved);
|
||||
return _counterQueues[(int)type].QueueReport(resultHandler, divisor, lastDrawIndex, hostReserved);
|
||||
}
|
||||
|
||||
public void QueueReset(CounterType type)
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
public TextureCreateInfo Info;
|
||||
public TextureView View;
|
||||
public float ScaleFactor;
|
||||
public int RemainingFrames;
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
Info = view.Info,
|
||||
View = view,
|
||||
ScaleFactor = view.ScaleFactor,
|
||||
RemainingFrames = DisposedLiveFrames
|
||||
});
|
||||
}
|
||||
|
@ -52,9 +50,8 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
/// Attempt to obtain a texture from the resource cache with the desired parameters.
|
||||
/// </summary>
|
||||
/// <param name="info">The creation info for the desired texture</param>
|
||||
/// <param name="scaleFactor">The scale factor for the desired texture</param>
|
||||
/// <returns>A TextureView with the description specified, or null if one was not found.</returns>
|
||||
public TextureView GetTextureOrNull(TextureCreateInfo info, float scaleFactor)
|
||||
public TextureView GetTextureOrNull(TextureCreateInfo info)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
|
@ -65,11 +62,8 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
foreach (DisposedTexture texture in list)
|
||||
{
|
||||
if (scaleFactor == texture.ScaleFactor)
|
||||
{
|
||||
list.Remove(texture);
|
||||
return texture.View;
|
||||
}
|
||||
list.Remove(texture);
|
||||
return texture.View;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -111,12 +111,11 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
|
||||
int srcX0, srcX1, srcY0, srcY1;
|
||||
float scale = viewConverted.ScaleFactor;
|
||||
|
||||
if (crop.Left == 0 && crop.Right == 0)
|
||||
{
|
||||
srcX0 = 0;
|
||||
srcX1 = (int)(viewConverted.Width / scale);
|
||||
srcX1 = viewConverted.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -127,7 +126,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
if (crop.Top == 0 && crop.Bottom == 0)
|
||||
{
|
||||
srcY0 = 0;
|
||||
srcY1 = (int)(viewConverted.Height / scale);
|
||||
srcY1 = viewConverted.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -135,14 +134,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
srcY1 = crop.Bottom;
|
||||
}
|
||||
|
||||
if (scale != 1f)
|
||||
{
|
||||
srcX0 = (int)(srcX0 * scale);
|
||||
srcY0 = (int)(srcY0 * scale);
|
||||
srcX1 = (int)Math.Ceiling(srcX1 * scale);
|
||||
srcY1 = (int)Math.Ceiling(srcY1 * scale);
|
||||
}
|
||||
|
||||
float ratioX = crop.IsStretched ? 1.0f : MathF.Min(1.0f, _height * crop.AspectRatioX / (_width * crop.AspectRatioY));
|
||||
float ratioY = crop.IsStretched ? 1.0f : MathF.Min(1.0f, _width * crop.AspectRatioY / (_height * crop.AspectRatioX));
|
||||
|
||||
|
@ -408,7 +399,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
SwizzleComponent.Alpha);
|
||||
|
||||
_isBgra = forceBgra;
|
||||
_upscaledTexture = _renderer.CreateTexture(info, 1) as TextureView;
|
||||
_upscaledTexture = _renderer.CreateTexture(info) as TextureView;
|
||||
}
|
||||
|
||||
public void SetScalingFilterLevel(float level)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue