From 484eb645ae0611f60fae845ed011ed6115352e06 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Tue, 7 Jul 2020 03:41:07 +0100 Subject: 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. --- Ryujinx.Graphics.GAL/Format.cs | 141 ++++++++++++++++++++++++++++++++++++++ Ryujinx.Graphics.GAL/IPipeline.cs | 4 ++ Ryujinx.Graphics.GAL/IRenderer.cs | 2 +- Ryujinx.Graphics.GAL/ITexture.cs | 4 ++ 4 files changed, 150 insertions(+), 1 deletion(-) (limited to 'Ryujinx.Graphics.GAL') diff --git a/Ryujinx.Graphics.GAL/Format.cs b/Ryujinx.Graphics.GAL/Format.cs index 0221746b..19939c38 100644 --- a/Ryujinx.Graphics.GAL/Format.cs +++ b/Ryujinx.Graphics.GAL/Format.cs @@ -162,11 +162,21 @@ namespace Ryujinx.Graphics.GAL public static class FormatExtensions { + /// + /// Checks if the texture format is an ASTC format. + /// + /// Texture format + /// True if the texture format is an ASTC format, false otherwise public static bool IsAstc(this Format format) { return format.IsAstcUnorm() || format.IsAstcSrgb(); } + /// + /// Checks if the texture format is an ASTC Unorm format. + /// + /// Texture format + /// True if the texture format is an ASTC Unorm format, false otherwise public static bool IsAstcUnorm(this Format format) { switch (format) @@ -191,6 +201,11 @@ namespace Ryujinx.Graphics.GAL return false; } + /// + /// Checks if the texture format is an ASTC SRGB format. + /// + /// Texture format + /// True if the texture format is an ASTC SRGB format, false otherwise public static bool IsAstcSrgb(this Format format) { switch (format) @@ -214,5 +229,131 @@ namespace Ryujinx.Graphics.GAL return false; } + + /// + /// Checks if the texture format is a depth, stencil or depth-stencil format. + /// + /// Texture format + /// True if the format is a depth, stencil or depth-stencil format, false otherwise + public static bool IsDepthOrStencil(this Format format) + { + switch (format) + { + case Format.D16Unorm: + case Format.D24UnormS8Uint: + case Format.D24X8Unorm: + case Format.D32Float: + case Format.D32FloatS8Uint: + case Format.S8Uint: + return true; + } + + return false; + } + + /// + /// Checks if the texture format is an unsigned integer color format. + /// + /// Texture format + /// True if the texture format is an unsigned integer color format, false otherwise + public static bool IsUint(this Format format) + { + switch (format) + { + case Format.R8Uint: + case Format.R16Uint: + case Format.R32Uint: + case Format.R8G8Uint: + case Format.R16G16Uint: + case Format.R32G32Uint: + case Format.R8G8B8Uint: + case Format.R16G16B16Uint: + case Format.R32G32B32Uint: + case Format.R8G8B8A8Uint: + case Format.R16G16B16A16Uint: + case Format.R32G32B32A32Uint: + case Format.R10G10B10A2Uint: + case Format.R8G8B8X8Uint: + case Format.R16G16B16X16Uint: + case Format.R32G32B32X32Uint: + return true; + } + + return false; + } + + /// + /// Checks if the texture format is a signed integer color format. + /// + /// Texture format + /// True if the texture format is a signed integer color format, false otherwise + public static bool IsSint(this Format format) + { + switch (format) + { + case Format.R8Sint: + case Format.R16Sint: + case Format.R32Sint: + case Format.R8G8Sint: + case Format.R16G16Sint: + case Format.R32G32Sint: + case Format.R8G8B8Sint: + case Format.R16G16B16Sint: + case Format.R32G32B32Sint: + case Format.R8G8B8A8Sint: + case Format.R16G16B16A16Sint: + case Format.R32G32B32A32Sint: + case Format.R10G10B10A2Sint: + case Format.R8G8B8X8Sint: + case Format.R16G16B16X16Sint: + case Format.R32G32B32X32Sint: + return true; + } + + return false; + } + + /// + /// Checks if the texture format is an integer color format. + /// + /// Texture format + /// True if the texture format is an integer color format, false otherwise + public static bool IsInteger(this Format format) + { + return format.IsUint() || format.IsSint(); + } + + /// + /// Checks if the texture format only has one component. + /// + /// Texture format + /// True if the texture format only has one component, false otherwise + public static bool HasOneComponent(this Format format) + { + switch (format) + { + case Format.R8Unorm: + case Format.R8Snorm: + case Format.R8Uint: + case Format.R8Sint: + case Format.R16Float: + case Format.R16Unorm: + case Format.R16Snorm: + case Format.R16Uint: + case Format.R16Sint: + case Format.R32Float: + case Format.R32Uint: + case Format.R32Sint: + case Format.R8Uscaled: + case Format.R8Sscaled: + case Format.R16Uscaled: + case Format.R16Sscaled: + case Format.R32Uscaled: + case Format.R32Sscaled: + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/IPipeline.cs b/Ryujinx.Graphics.GAL/IPipeline.cs index aa59713d..e365529b 100644 --- a/Ryujinx.Graphics.GAL/IPipeline.cs +++ b/Ryujinx.Graphics.GAL/IPipeline.cs @@ -54,6 +54,8 @@ namespace Ryujinx.Graphics.GAL void SetRasterizerDiscard(bool discard); + void SetRenderTargetScale(float scale); + void SetRenderTargetColorMasks(ReadOnlySpan componentMask); void SetRenderTargets(ITexture[] colors, ITexture depthStencil); @@ -84,5 +86,7 @@ namespace Ryujinx.Graphics.GAL bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual); bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual); void EndHostConditionalRendering(); + + void UpdateRenderScale(ShaderStage stage, int textureCount); } } diff --git a/Ryujinx.Graphics.GAL/IRenderer.cs b/Ryujinx.Graphics.GAL/IRenderer.cs index c41b19fe..1052f147 100644 --- a/Ryujinx.Graphics.GAL/IRenderer.cs +++ b/Ryujinx.Graphics.GAL/IRenderer.cs @@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.GAL IProgram CreateProgram(IShader[] shaders); ISampler CreateSampler(SamplerCreateInfo info); - ITexture CreateTexture(TextureCreateInfo info); + ITexture CreateTexture(TextureCreateInfo info, float scale); void DeleteBuffer(BufferHandle buffer); diff --git a/Ryujinx.Graphics.GAL/ITexture.cs b/Ryujinx.Graphics.GAL/ITexture.cs index a818f73a..1c5b6ba5 100644 --- a/Ryujinx.Graphics.GAL/ITexture.cs +++ b/Ryujinx.Graphics.GAL/ITexture.cs @@ -4,6 +4,10 @@ namespace Ryujinx.Graphics.GAL { public interface ITexture : IDisposable { + int Width { get; } + int Height { get; } + float ScaleFactor { get; } + void CopyTo(ITexture destination, int firstLayer, int firstLevel); void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter); -- cgit v1.2.3