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

@ -1,5 +1,6 @@
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.State;
using System;
namespace Ryujinx.Graphics.Gpu.Engine
{
@ -32,13 +33,18 @@ namespace Ryujinx.Graphics.Gpu.Engine
dstCopyTexture.Format = RtFormat.D32Float;
}
Texture dstTexture = TextureManager.FindOrCreateTexture(dstCopyTexture);
Texture dstTexture = TextureManager.FindOrCreateTexture(dstCopyTexture, srcTexture.ScaleMode == Image.TextureScaleMode.Scaled);
if (dstTexture == null)
{
return;
}
if (srcTexture.ScaleFactor != dstTexture.ScaleFactor)
{
srcTexture.PropagateScale(dstTexture);
}
var control = state.Get<CopyTextureControl>(MethodOffset.CopyTextureControl);
var region = state.Get<CopyRegion>(MethodOffset.CopyRegion);
@ -55,17 +61,19 @@ namespace Ryujinx.Graphics.Gpu.Engine
int dstX2 = region.DstX + region.DstWidth;
int dstY2 = region.DstY + region.DstHeight;
float scale = srcTexture.ScaleFactor; // src and dest scales are identical now.
Extents2D srcRegion = new Extents2D(
srcX1 / srcTexture.Info.SamplesInX,
srcY1 / srcTexture.Info.SamplesInY,
srcX2 / srcTexture.Info.SamplesInX,
srcY2 / srcTexture.Info.SamplesInY);
(int)Math.Ceiling(scale * (srcX1 / srcTexture.Info.SamplesInX)),
(int)Math.Ceiling(scale * (srcY1 / srcTexture.Info.SamplesInY)),
(int)Math.Ceiling(scale * (srcX2 / srcTexture.Info.SamplesInX)),
(int)Math.Ceiling(scale * (srcY2 / srcTexture.Info.SamplesInY)));
Extents2D dstRegion = new Extents2D(
dstX1 / dstTexture.Info.SamplesInX,
dstY1 / dstTexture.Info.SamplesInY,
dstX2 / dstTexture.Info.SamplesInX,
dstY2 / dstTexture.Info.SamplesInY);
(int)Math.Ceiling(scale * (dstX1 / dstTexture.Info.SamplesInX)),
(int)Math.Ceiling(scale * (dstY1 / dstTexture.Info.SamplesInY)),
(int)Math.Ceiling(scale * (dstX2 / dstTexture.Info.SamplesInX)),
(int)Math.Ceiling(scale * (dstY2 / dstTexture.Info.SamplesInY)));
bool linearFilter = control.UnpackLinearFilter();
@ -79,17 +87,21 @@ namespace Ryujinx.Graphics.Gpu.Engine
// the second handles the region outside of the bounds).
// We must also extend the source texture by one line to ensure we can wrap on the last line.
// This is required by the (guest) OpenGL driver.
if (srcRegion.X2 > srcTexture.Info.Width)
if (srcX2 / srcTexture.Info.SamplesInX > srcTexture.Info.Width)
{
srcCopyTexture.Height++;
srcTexture = TextureManager.FindOrCreateTexture(srcCopyTexture);
srcTexture = TextureManager.FindOrCreateTexture(srcCopyTexture, srcTexture.ScaleMode == Image.TextureScaleMode.Scaled);
if (srcTexture.ScaleFactor != dstTexture.ScaleFactor)
{
srcTexture.PropagateScale(dstTexture);
}
srcRegion = new Extents2D(
srcRegion.X1 - srcTexture.Info.Width,
srcRegion.Y1 + 1,
srcRegion.X2 - srcTexture.Info.Width,
srcRegion.Y2 + 1);
(int)Math.Ceiling(scale * ((srcX1 / srcTexture.Info.SamplesInX) - srcTexture.Info.Width)),
(int)Math.Ceiling(scale * ((srcY1 / srcTexture.Info.SamplesInY) + 1)),
(int)Math.Ceiling(scale * ((srcX2 / srcTexture.Info.SamplesInX) - srcTexture.Info.Width)),
(int)Math.Ceiling(scale * ((srcY2 / srcTexture.Info.SamplesInY) + 1)));
srcTexture.HostTexture.CopyTo(dstTexture.HostTexture, srcRegion, dstRegion, linearFilter);
}