From a15b951721d7c52c30a8e8864e91353ec6fc65f4 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 27 May 2020 20:03:07 -0300 Subject: Fix wrong face culling once and for all (#1277) * Viewport swizzle support on NV and clip origin * Initialize default viewport swizzle state, emulate viewport swizzle on shaders when not supported * Address PR feedback --- Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Ryujinx.Graphics.Gpu/Shader') diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs index 76b06ea5..2774b7d1 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuAccessor.cs @@ -3,6 +3,7 @@ using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.Image; using Ryujinx.Graphics.Gpu.State; using Ryujinx.Graphics.Shader; +using System; namespace Ryujinx.Graphics.Gpu.Shader { @@ -187,6 +188,12 @@ namespace Ryujinx.Graphics.Gpu.Shader /// True if the GPU and driver supports non-constant texture offsets, false otherwise public bool QuerySupportsNonConstantTextureOffset() => _context.Capabilities.SupportsNonConstantTextureOffset; + /// + /// Queries host GPU viewport swizzle support. + /// + /// True if the GPU and driver supports viewport swizzle, false otherwise + public bool QuerySupportsViewportSwizzle() => _context.Capabilities.SupportsViewportSwizzle; + /// /// Queries texture format information, for shaders using image load or store. /// @@ -250,6 +257,24 @@ namespace Ryujinx.Graphics.Gpu.Shader }; } + public int QueryViewportSwizzle(int component) + { + YControl yControl = _state.Get(MethodOffset.YControl); + + bool flipY = yControl.HasFlag(YControl.NegateY) ^ !yControl.HasFlag(YControl.TriangleRastFlip); + + ViewportTransform transform = _state.Get(MethodOffset.ViewportTransform, 0); + + return component switch + { + 0 => (int)(transform.UnpackSwizzleX() ^ (transform.ScaleX < 0 ? ViewportSwizzle.NegativeFlag : 0)), + 1 => (int)(transform.UnpackSwizzleY() ^ (transform.ScaleY < 0 ? ViewportSwizzle.NegativeFlag : 0) ^ (flipY ? ViewportSwizzle.NegativeFlag : 0)), + 2 => (int)(transform.UnpackSwizzleZ() ^ (transform.ScaleZ < 0 ? ViewportSwizzle.NegativeFlag : 0)), + 3 => (int)transform.UnpackSwizzleW(), + _ => throw new ArgumentOutOfRangeException(nameof(component)) + }; + } + /// /// Gets the texture descriptor for a given texture on the pool. /// -- cgit v1.2.3