diff options
| author | riperiperi <rhy3756547@hotmail.com> | 2020-07-07 03:41:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-07 04:41:07 +0200 |
| commit | 484eb645ae0611f60fae845ed011ed6115352e06 (patch) | |
| tree | b15972f04dae0b1b6c644cbbbdfcd98856adee15 /Ryujinx.Graphics.Gpu/Engine | |
| parent | 43b78ae157eed5c9436dc19a6d498655891202d8 (diff) | |
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.
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Engine')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/Compute.cs | 6 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/MethodClear.cs | 6 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs | 42 | ||||
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/Methods.cs | 51 |
4 files changed, 76 insertions, 29 deletions
diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute.cs b/Ryujinx.Graphics.Gpu/Engine/Compute.cs index 4d18f4d3..e40984af 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Compute.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Compute.cs @@ -132,11 +132,11 @@ namespace Ryujinx.Graphics.Gpu.Engine if (descriptor.IsBindless) { - textureBindings[index] = new TextureBindingInfo(target, descriptor.CbufOffset, descriptor.CbufSlot); + textureBindings[index] = new TextureBindingInfo(target, descriptor.CbufOffset, descriptor.CbufSlot, descriptor.Flags); } else { - textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex); + textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex, descriptor.Flags); } } @@ -150,7 +150,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.SetComputeImages(imageBindings); diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs b/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs index a9552762..5da87e6c 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs @@ -26,7 +26,9 @@ namespace Ryujinx.Graphics.Gpu.Engine UpdateScissorState(state); } - UpdateRenderTargetState(state, useControl: false); + int index = (argument >> 6) & 0xf; + + UpdateRenderTargetState(state, useControl: false, singleUse: index); TextureManager.CommitGraphicsBindings(); @@ -35,8 +37,6 @@ namespace Ryujinx.Graphics.Gpu.Engine uint componentMask = (uint)((argument >> 2) & 0xf); - int index = (argument >> 6) & 0xf; - if (componentMask != 0) { var clearColor = state.Get<ClearColors>(MethodOffset.ClearColors); diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs b/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs index 4900db1b..07afb253 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs @@ -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); } diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index af32c6bc..5677c8a0 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -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); |
