diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 353c5dfedd..4785c843f6 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 a52e70c31d..69214a3556 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 7a141bbcf6..719252696f 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 c3fb288270..9a2c844d12 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 f3397adaaf..7190d22a2c 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 6baf33e1af..307c08c7aa 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)