From acc0b0f3138b0ea4d573db5152927026c29bd61d Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 5 Dec 2021 09:25:05 -0300 Subject: [PATCH] Fix FLO.SH shader instruction with a input of 0 (#2876) * Fix FLO.SH shader instruction with a input of 0 * Shader cache version bump --- Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 2 +- .../CodeGen/Glsl/Instructions/InstGenHelper.cs | 5 +++-- .../Instructions/InstEmitBitfield.cs | 12 ++++++++---- .../IntermediateRepresentation/Instruction.cs | 5 +++-- .../StructuredIr/InstructionInfo.cs | 5 +++-- .../Translation/EmitterContextInsts.cs | 13 +++++++++---- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 353c5dfed..4785c843f 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// Version of the codegen (to be changed when codegen or guest format change). /// - private const ulong ShaderCodeGenVersion = 2816; + private const ulong ShaderCodeGenVersion = 2876; // Progress reporting helpers private volatile int _shaderCount; diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs index a52e70c31..69214a355 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenHelper.cs @@ -71,8 +71,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions Add(Instruction.ExponentB2, InstType.CallUnary, "exp2"); Add(Instruction.FSIBegin, InstType.Special); Add(Instruction.FSIEnd, InstType.Special); - Add(Instruction.FindFirstSetS32, InstType.CallUnary, "findMSB"); - Add(Instruction.FindFirstSetU32, InstType.CallUnary, "findMSB"); + Add(Instruction.FindLSB, InstType.CallUnary, "findLSB"); + Add(Instruction.FindMSBS32, InstType.CallUnary, "findMSB"); + Add(Instruction.FindMSBU32, InstType.CallUnary, "findMSB"); Add(Instruction.Floor, InstType.CallUnary, "floor"); Add(Instruction.FusedMultiplyAdd, InstType.CallTernary, "fma"); Add(Instruction.GroupMemoryBarrier, InstType.CallNullary, "groupMemoryBarrier"); diff --git a/Ryujinx.Graphics.Shader/Instructions/InstEmitBitfield.cs b/Ryujinx.Graphics.Shader/Instructions/InstEmitBitfield.cs index 7a141bbcf..719252696 100644 --- a/Ryujinx.Graphics.Shader/Instructions/InstEmitBitfield.cs +++ b/Ryujinx.Graphics.Shader/Instructions/InstEmitBitfield.cs @@ -166,13 +166,17 @@ namespace Ryujinx.Graphics.Shader.Instructions { Operand srcB = context.BitwiseNot(src, invert); - Operand res = isSigned - ? context.FindFirstSetS32(srcB) - : context.FindFirstSetU32(srcB); + Operand res; if (sh) { - res = context.BitwiseExclusiveOr(res, Const(31)); + res = context.FindLSB(context.BitfieldReverse(srcB)); + } + else + { + res = isSigned + ? context.FindMSBS32(srcB) + : context.FindMSBU32(srcB); } context.Copy(GetDest(rd), res); diff --git a/Ryujinx.Graphics.Shader/IntermediateRepresentation/Instruction.cs b/Ryujinx.Graphics.Shader/IntermediateRepresentation/Instruction.cs index c3fb28827..9a2c844d1 100644 --- a/Ryujinx.Graphics.Shader/IntermediateRepresentation/Instruction.cs +++ b/Ryujinx.Graphics.Shader/IntermediateRepresentation/Instruction.cs @@ -68,8 +68,9 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation ExponentB2, FSIBegin, FSIEnd, - FindFirstSetS32, - FindFirstSetU32, + FindLSB, + FindMSBS32, + FindMSBU32, Floor, FusedMultiplyAdd, GroupMemoryBarrier, diff --git a/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs b/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs index f3397adaa..7190d22a2 100644 --- a/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs +++ b/Ryujinx.Graphics.Shader/StructuredIr/InstructionInfo.cs @@ -79,8 +79,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr Add(Instruction.Ddy, VariableType.F32, VariableType.F32); Add(Instruction.Divide, VariableType.Scalar, VariableType.Scalar, VariableType.Scalar); Add(Instruction.ExponentB2, VariableType.Scalar, VariableType.Scalar); - Add(Instruction.FindFirstSetS32, VariableType.S32, VariableType.S32); - Add(Instruction.FindFirstSetU32, VariableType.S32, VariableType.U32); + Add(Instruction.FindLSB, VariableType.Int, VariableType.Int); + Add(Instruction.FindMSBS32, VariableType.S32, VariableType.S32); + Add(Instruction.FindMSBU32, VariableType.S32, VariableType.U32); Add(Instruction.Floor, VariableType.Scalar, VariableType.Scalar); Add(Instruction.FusedMultiplyAdd, VariableType.Scalar, VariableType.Scalar, VariableType.Scalar, VariableType.Scalar); Add(Instruction.ImageLoad, VariableType.F32); diff --git a/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs b/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs index 6baf33e1a..307c08c7a 100644 --- a/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs +++ b/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs @@ -181,14 +181,19 @@ namespace Ryujinx.Graphics.Shader.Translation return context.Add(Instruction.EndPrimitive); } - public static Operand FindFirstSetS32(this EmitterContext context, Operand a) + public static Operand FindLSB(this EmitterContext context, Operand a) { - return context.Add(Instruction.FindFirstSetS32, Local(), a); + return context.Add(Instruction.FindLSB, Local(), a); } - public static Operand FindFirstSetU32(this EmitterContext context, Operand a) + public static Operand FindMSBS32(this EmitterContext context, Operand a) { - return context.Add(Instruction.FindFirstSetU32, Local(), a); + return context.Add(Instruction.FindMSBS32, Local(), a); + } + + public static Operand FindMSBU32(this EmitterContext context, Operand a) + { + return context.Add(Instruction.FindMSBU32, Local(), a); } public static Operand FP32ConvertToFP64(this EmitterContext context, Operand a)