From 1fc0f569de518581761ab2f4b751b0dbaf2cd279 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Mon, 28 Nov 2022 22:18:22 +0000 Subject: [PATCH] GPU: Always draw polygon topology as triangle fan (#3932) Polygon topology wasn't really supported and would only work on OpenGL on drivers that haven't removed it. As an alternative, this PR makes all cases of polygon topology use triangle fan. The topology type and transform feedback type have not been changed, as I don't think geo shader/tfb should be used with polygons. The OpenGL spec states: Only convex polygons are guaranteed to be drawn correctly by the GL. For convex polygons, triangle fan is equivalent to polygon. I imagine this is probably how it works on device, as this get-out-of-jail-free card is too enticing to pass up. This fixes the stat display in Pokemon S/V. --- Ryujinx.Graphics.OpenGL/EnumConversion.cs | 2 +- Ryujinx.Graphics.Vulkan/EnumConversion.cs | 1 + Ryujinx.Graphics.Vulkan/PipelineBase.cs | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 4a06e964..f262c584 100644 --- a/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -331,7 +331,7 @@ namespace Ryujinx.Graphics.OpenGL case PrimitiveTopology.QuadStrip: return PrimitiveType.QuadStrip; case PrimitiveTopology.Polygon: - return PrimitiveType.Polygon; + return PrimitiveType.TriangleFan; case PrimitiveTopology.LinesAdjacency: return PrimitiveType.LinesAdjacency; case PrimitiveTopology.LineStripAdjacency: diff --git a/Ryujinx.Graphics.Vulkan/EnumConversion.cs b/Ryujinx.Graphics.Vulkan/EnumConversion.cs index 804cd70c..9d9be65e 100644 --- a/Ryujinx.Graphics.Vulkan/EnumConversion.cs +++ b/Ryujinx.Graphics.Vulkan/EnumConversion.cs @@ -180,6 +180,7 @@ namespace Ryujinx.Graphics.Vulkan GAL.PrimitiveTopology.TrianglesAdjacency => Silk.NET.Vulkan.PrimitiveTopology.TriangleListWithAdjacency, GAL.PrimitiveTopology.TriangleStripAdjacency => Silk.NET.Vulkan.PrimitiveTopology.TriangleStripWithAdjacency, GAL.PrimitiveTopology.Patches => Silk.NET.Vulkan.PrimitiveTopology.PatchList, + GAL.PrimitiveTopology.Polygon => Silk.NET.Vulkan.PrimitiveTopology.TriangleFan, GAL.PrimitiveTopology.Quads => throw new NotSupportedException("Quad topology is not available in Vulkan."), GAL.PrimitiveTopology.QuadStrip => throw new NotSupportedException("QuadStrip topology is not available in Vulkan."), _ => LogInvalidAndReturn(topology, nameof(GAL.PrimitiveTopology), Silk.NET.Vulkan.PrimitiveTopology.TriangleList) diff --git a/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 87155a0d..594ed5e7 100644 --- a/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -328,7 +328,8 @@ namespace Ryujinx.Graphics.Vulkan IndexBufferPattern pattern = _topology switch { GAL.PrimitiveTopology.Quads => QuadsToTrisPattern, - GAL.PrimitiveTopology.TriangleFan => TriFanToTrisPattern, + GAL.PrimitiveTopology.TriangleFan or + GAL.PrimitiveTopology.Polygon => TriFanToTrisPattern, _ => throw new NotSupportedException($"Unsupported topology: {_topology}") }; @@ -359,7 +360,8 @@ namespace Ryujinx.Graphics.Vulkan pattern = _topology switch { GAL.PrimitiveTopology.Quads => QuadsToTrisPattern, - GAL.PrimitiveTopology.TriangleFan => TriFanToTrisPattern, + GAL.PrimitiveTopology.TriangleFan or + GAL.PrimitiveTopology.Polygon => TriFanToTrisPattern, _ => throw new NotSupportedException($"Unsupported topology: {_topology}") }; }