Implement Zero-Configuration Resolution Scaling (#1365)

* Initial implementation of Render Target Scaling

Works with most games I have. No GUI option right now, it is hardcoded.

Missing handling for texelFetch operation.

* Realtime Configuration, refactoring.

* texelFetch scaling on fragment shader (WIP)

* Improve Shader-Side changes.

* Fix potential crash when no color/depth bound

* Workaround random uses of textures in compute.

This was blacklisting textures in a few games despite causing no bugs. Will eventually add full support so this doesn't break anything.

* Fix scales oscillating when changing between non-native scales.

* Scaled textures on compute, cleanup, lazier uniform update.

* Cleanup.

* Fix stupidity

* Address Thog Feedback.

* Cover most of GDK's feedback (two comments remain)

* Fix bad rename

* Move IsDepthStencil to FormatExtensions, add docs.

* Fix default config, square texture detection.

* Three final fixes:

- Nearest copy when texture is integer format.
- Texture2D -> Texture3D copy correctly blacklists the texture before trying an unscaled copy (caused driver error)
- Discount small textures.

* Remove scale threshold.

Not needed right now - we'll see if we run into problems.

* All CPU modification blacklists scale.

* Fix comment.
This commit is contained in:
riperiperi 2020-07-07 03:41:07 +01:00 committed by GitHub
parent 43b78ae157
commit 484eb645ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 1163 additions and 131 deletions

View file

@ -313,7 +313,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="useControl">Use draw buffers information from render target control register</param>
private void UpdateRenderTargetState(GpuState state, bool useControl)
/// <param name="singleUse">If this is not -1, it indicates that only the given indexed target will be used.</param>
private void UpdateRenderTargetState(GpuState state, bool useControl, int singleUse = -1)
{
var rtControl = state.Get<RtControl>(MethodOffset.RtControl);
@ -324,6 +325,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
int samplesInX = msaaMode.SamplesInX();
int samplesInY = msaaMode.SamplesInY();
bool changedScale = false;
for (int index = 0; index < Constants.TotalRenderTargets; index++)
{
int rtIndex = useControl ? rtControl.UnpackPermutationIndex(index) : index;
@ -332,14 +335,14 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (index >= count || !IsRtEnabled(colorState))
{
TextureManager.SetRenderTargetColor(index, null);
changedScale |= TextureManager.SetRenderTargetColor(index, null);
continue;
}
Texture color = TextureManager.FindOrCreateTexture(colorState, samplesInX, samplesInY);
TextureManager.SetRenderTargetColor(index, color);
changedScale |= TextureManager.SetRenderTargetColor(index, color);
if (color != null)
{
@ -359,7 +362,16 @@ namespace Ryujinx.Graphics.Gpu.Engine
depthStencil = TextureManager.FindOrCreateTexture(dsState, dsSize, samplesInX, samplesInY);
}
TextureManager.SetRenderTargetDepthStencil(depthStencil);
changedScale |= TextureManager.SetRenderTargetDepthStencil(depthStencil);
if (changedScale)
{
TextureManager.UpdateRenderTargetScale(singleUse);
_context.Renderer.Pipeline.SetRenderTargetScale(TextureManager.RenderTargetScale);
UpdateViewportTransform(state);
UpdateScissorState(state);
}
if (depthStencil != null)
{
@ -394,7 +406,21 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (enable)
{
_context.Renderer.Pipeline.SetScissor(index, scissor.X1, scissor.Y1, scissor.X2 - scissor.X1, scissor.Y2 - scissor.Y1);
int x = scissor.X1;
int y = scissor.Y1;
int width = scissor.X2 - x;
int height = scissor.Y2 - y;
float scale = TextureManager.RenderTargetScale;
if (scale != 1f)
{
x = (int)(x * scale);
y = (int)(y * scale);
width = (int)Math.Ceiling(width * scale);
height = (int)Math.Ceiling(height * scale);
}
_context.Renderer.Pipeline.SetScissor(index, x, y, width, height);
}
}
}
@ -460,6 +486,15 @@ namespace Ryujinx.Graphics.Gpu.Engine
float width = MathF.Abs(transform.ScaleX) * 2;
float height = MathF.Abs(transform.ScaleY) * 2;
float scale = TextureManager.RenderTargetScale;
if (scale != 1f)
{
x *= scale;
y *= scale;
width *= scale;
height *= scale;
}
RectangleF region = new RectangleF(x, y, width, height);
ViewportSwizzle swizzleX = transform.UnpackSwizzleX();
@ -909,11 +944,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (descriptor.IsBindless)
{
textureBindings[index] = new TextureBindingInfo(target, descriptor.CbufSlot, descriptor.CbufOffset);
textureBindings[index] = new TextureBindingInfo(target, descriptor.CbufSlot, descriptor.CbufOffset, descriptor.Flags);
}
else
{
textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex, descriptor.Flags);
}
}
@ -927,7 +962,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
Target target = GetTarget(descriptor.Type);
imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex, descriptor.Flags);
}
TextureManager.SetGraphicsImages(stage, imageBindings);