From 51fbc1fde4363760bb47a2a5c960476ffceeac17 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 26 Jul 2020 18:11:28 -0300 Subject: [PATCH] Use polygon offset clamp if supported (#1429) --- Ryujinx.Graphics.Gpu/Engine/Methods.cs | 4 ++-- Ryujinx.Graphics.OpenGL/HwCapabilities.cs | 2 ++ Ryujinx.Graphics.OpenGL/Pipeline.cs | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index e84687effd..fbde0f0a38 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -568,7 +568,7 @@ namespace Ryujinx.Graphics.Gpu.Engine enables |= (depthBias.LineEnable ? PolygonModeMask.Line : 0); enables |= (depthBias.FillEnable ? PolygonModeMask.Fill : 0); - _context.Renderer.Pipeline.SetDepthBias(enables, factor, units, clamp); + _context.Renderer.Pipeline.SetDepthBias(enables, factor, units / 2f, clamp); } /// @@ -697,7 +697,7 @@ namespace Ryujinx.Graphics.Gpu.Engine float size = state.Get(MethodOffset.PointSize); bool isProgramPointSize = state.Get(MethodOffset.VertexProgramPointSize); bool enablePointSprite = state.Get(MethodOffset.PointSpriteEnable); - + // TODO: Need to figure out a way to map PointCoordReplace enable bit. Origin origin = (state.Get(MethodOffset.PointCoordReplace) & 4) == 0 ? Origin.LowerLeft : Origin.UpperLeft; diff --git a/Ryujinx.Graphics.OpenGL/HwCapabilities.cs b/Ryujinx.Graphics.OpenGL/HwCapabilities.cs index 14515b6188..9278c59ef4 100644 --- a/Ryujinx.Graphics.OpenGL/HwCapabilities.cs +++ b/Ryujinx.Graphics.OpenGL/HwCapabilities.cs @@ -7,6 +7,7 @@ namespace Ryujinx.Graphics.OpenGL { private static readonly Lazy _supportsAstcCompression = new Lazy(() => HasExtension("GL_KHR_texture_compression_astc_ldr")); private static readonly Lazy _supportsImageLoadFormatted = new Lazy(() => HasExtension("GL_EXT_shader_image_load_formatted")); + private static readonly Lazy _supportsPolygonOffsetClamp = new Lazy(() => HasExtension("GL_EXT_polygon_offset_clamp")); private static readonly Lazy _supportsViewportSwizzle = new Lazy(() => HasExtension("GL_NV_viewport_swizzle")); private static readonly Lazy _maximumComputeSharedMemorySize = new Lazy(() => GetLimit(All.MaxComputeSharedMemorySize)); @@ -28,6 +29,7 @@ namespace Ryujinx.Graphics.OpenGL public static bool SupportsAstcCompression => _supportsAstcCompression.Value; public static bool SupportsImageLoadFormatted => _supportsImageLoadFormatted.Value; + public static bool SupportsPolygonOffsetClamp => _supportsPolygonOffsetClamp.Value; public static bool SupportsViewportSwizzle => _supportsViewportSwizzle.Value; public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia; diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 09ba9be0b1..4f3c2a29bd 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -610,9 +610,14 @@ namespace Ryujinx.Graphics.OpenGL return; } - GL.PolygonOffset(factor, units / 2f); - // TODO: Enable when GL_EXT_polygon_offset_clamp is supported. - // GL.PolygonOffsetClamp(factor, units, clamp); + if (HwCapabilities.SupportsPolygonOffsetClamp) + { + GL.PolygonOffsetClamp(factor, units, clamp); + } + else + { + GL.PolygonOffset(factor, units); + } } public void SetDepthClamp(bool clamp)