diff options
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/Translation/Optimizations')
9 files changed, 60 insertions, 71 deletions
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs index 0c196c4d..bb25c160 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs @@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // - Both sources of the OR operation comes from a constant buffer. for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next) { - if (!(node.Value is TextureOperation texOp)) + if (node.Value is not TextureOperation texOp) { continue; } @@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations continue; } - if (!(bindlessHandle.AsgOp is Operation handleCombineOp)) + if (bindlessHandle.AsgOp is not Operation handleCombineOp) { continue; } @@ -66,9 +66,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // and having a "canonical" representation simplifies some checks below. if (src0.Type == OperandType.Constant && src1.Type != OperandType.Constant) { - Operand temp = src1; - src1 = src0; - src0 = temp; + (src0, src1) = (src1, src0); } TextureHandleType handleType = TextureHandleType.SeparateSamplerHandle; diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessToIndexed.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessToIndexed.cs index 9a3ae1b8..f966a4fc 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessToIndexed.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessToIndexed.cs @@ -17,7 +17,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // The base offset of the array of handles on the constant buffer is the constant offset. for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next) { - if (!(node.Value is TextureOperation texOp)) + if (node.Value is not TextureOperation texOp) { continue; } @@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations continue; } - if (!(texOp.GetSource(0).AsgOp is Operation handleAsgOp)) + if (texOp.GetSource(0).AsgOp is not Operation handleAsgOp) { continue; } @@ -64,17 +64,17 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // Plus this whole transform is fundamentally flawed as-is since we have no way to know the array size. // Eventually, this should be entirely removed in favor of a implementation that supports true bindless // texture access. - if (!(ldcSrc2.AsgOp is Operation shrOp) || shrOp.Inst != Instruction.ShiftRightU32) + if (ldcSrc2.AsgOp is not Operation shrOp || shrOp.Inst != Instruction.ShiftRightU32) { continue; } - if (!(shrOp.GetSource(0).AsgOp is Operation shrOp2) || shrOp2.Inst != Instruction.ShiftRightU32) + if (shrOp.GetSource(0).AsgOp is not Operation shrOp2 || shrOp2.Inst != Instruction.ShiftRightU32) { continue; } - if (!(shrOp2.GetSource(0).AsgOp is Operation addOp) || addOp.Inst != Instruction.Add) + if (shrOp2.GetSource(0).AsgOp is not Operation addOp || addOp.Inst != Instruction.Add) { continue; } @@ -92,7 +92,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations Operand source = addOp.GetSource(0); - Operation shrBy3 = new Operation(Instruction.ShiftRightU32, index, source, Const(3)); + Operation shrBy3 = new(Instruction.ShiftRightU32, index, source, Const(3)); block.Operations.AddBefore(node, shrBy3); @@ -106,4 +106,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations config.SetUsedTexture(texOp.Inst, texOp.Type, texOp.Format, texOp.Flags, texOp.CbufSlot, handle); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BranchElimination.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BranchElimination.cs index c87d1474..bd2eceda 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BranchElimination.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/BranchElimination.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return false; } - if (!(nextBlock.Operations.First?.Value is Operation next)) + if (nextBlock.Operations.First?.Value is not Operation next) { return false; } @@ -61,4 +61,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return block; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs index 4caadb73..0cca0ac6 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs @@ -1,7 +1,6 @@ using Ryujinx.Common.Utilities; using Ryujinx.Graphics.Shader.IntermediateRepresentation; using System; - using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper; namespace Ryujinx.Graphics.Shader.Translation.Optimizations @@ -262,8 +261,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations private static int GetBitfieldExtractValue(Operation operation) { - int value = operation.GetSource(0).Value; - int lsb = operation.GetSource(1).Value; + int value = operation.GetSource(0).Value; + int lsb = operation.GetSource(1).Value; int length = operation.GetSource(2).Value; return value.Extract(lsb, length); @@ -278,13 +277,6 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations operation.TurnIntoCopy(ConstF((float)BitConverter.UInt16BitsToHalf((ushort)value))); } - private static void FPNegate(Operation operation) - { - float value = operation.GetSource(0).AsFloat(); - - operation.TurnIntoCopy(ConstF(-value)); - } - private static void EvaluateUnary(Operation operation, Func<int, int> op) { int x = operation.GetSource(0).Value; @@ -356,4 +348,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations operation.TurnIntoCopy(ConstF(op(x, y, z))); } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/DoubleToFloat.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/DoubleToFloat.cs index 42bce5cc..aec95a9c 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/DoubleToFloat.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/DoubleToFloat.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next) { - if (node.Value is not Operation operation) + if (node.Value is not Operation) { continue; } @@ -67,4 +67,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs index 9d260c67..2433aeb2 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs @@ -2,7 +2,6 @@ using Ryujinx.Graphics.Shader.IntermediateRepresentation; using System; using System.Collections.Generic; using System.Linq; - using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper; namespace Ryujinx.Graphics.Shader.Translation.Optimizations @@ -14,12 +13,12 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations enum LsMemoryType { Local, - Shared + Shared, } private class GtsContext { - private struct Entry + private readonly struct Entry { public readonly int FunctionId; public readonly Instruction Inst; @@ -42,7 +41,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } } - private struct LsKey : IEquatable<LsKey> + private readonly struct LsKey : IEquatable<LsKey> { public readonly Operand BaseOffset; public readonly int ConstOffset; @@ -127,7 +126,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations public void AddMemoryTargetCb(LsMemoryType type, Operand baseOffset, int constOffset, uint targetCb, SearchResult result) { - LsKey key = new LsKey(baseOffset, constOffset, type); + LsKey key = new(baseOffset, constOffset, type); if (!_sharedEntries.TryGetValue(key, out Dictionary<uint, SearchResult> targetCbs)) { @@ -162,7 +161,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations public bool TryGetMemoryTargetCb(LsMemoryType type, Operand baseOffset, int constOffset, out SearchResult result) { - LsKey key = new LsKey(baseOffset, constOffset, type); + LsKey key = new(baseOffset, constOffset, type); if (_sharedEntries.TryGetValue(key, out Dictionary<uint, SearchResult> targetCbs) && targetCbs.Count == 1) { @@ -182,9 +181,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } } - private struct SearchResult + private readonly struct SearchResult { - public static SearchResult NotFound => new SearchResult(-1, 0); + public static SearchResult NotFound => new(-1, 0); public bool Found => SbCbSlot != -1; public int SbCbSlot { get; } public int SbCbOffset { get; } @@ -208,13 +207,13 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations public static void RunPass(HelperFunctionManager hfm, BasicBlock[] blocks, ShaderConfig config) { - GtsContext gtsContext = new GtsContext(hfm); + GtsContext gtsContext = new(hfm); foreach (BasicBlock block in blocks) { for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next) { - if (!(node.Value is Operation operation)) + if (node.Value is not Operation operation) { continue; } @@ -315,8 +314,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations int alignment = config.GpuAccessor.QueryHostStorageBufferOffsetAlignment(); - Operation maskOp = new Operation(Instruction.BitwiseAnd, baseAddressMasked, new[] { baseAddress, Const(-alignment) }); - Operation subOp = new Operation(Instruction.Subtract, hostOffset, new[] { globalAddress, baseAddressMasked }); + Operation maskOp = new(Instruction.BitwiseAnd, baseAddressMasked, baseAddress, Const(-alignment)); + Operation subOp = new(Instruction.Subtract, hostOffset, globalAddress, baseAddressMasked); node.List.AddBefore(node, maskOp); node.List.AddBefore(node, subOp); @@ -327,7 +326,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { Operand newOffset = Local(); - Operation addOp = new Operation(Instruction.Add, newOffset, new[] { offset, Const(result.ConstOffset) }); + Operation addOp = new(Instruction.Add, newOffset, offset, Const(result.ConstOffset)); node.List.AddBefore(node, addOp); @@ -394,26 +393,26 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations if (operation.Inst == Instruction.AtomicCompareAndSwap) { - sources = new Operand[] + sources = new[] { Const(binding), Const(0), wordOffset, operation.GetSource(operation.SourcesCount - 2), - operation.GetSource(operation.SourcesCount - 1) + operation.GetSource(operation.SourcesCount - 1), }; } else if (isStore) { - sources = new Operand[] { Const(binding), Const(0), wordOffset, operation.GetSource(operation.SourcesCount - 1) }; + sources = new[] { Const(binding), Const(0), wordOffset, operation.GetSource(operation.SourcesCount - 1) }; } else { - sources = new Operand[] { Const(binding), Const(0), wordOffset }; + sources = new[] { Const(binding), Const(0), wordOffset }; } - Operation shiftOp = new Operation(Instruction.ShiftRightU32, wordOffset, new[] { offset, Const(2) }); - Operation storageOp = new Operation(operation.Inst, StorageKind.StorageBuffer, operation.Dest, sources); + Operation shiftOp = new(Instruction.ShiftRightU32, wordOffset, offset, Const(2)); + Operation storageOp = new(operation.Inst, StorageKind.StorageBuffer, operation.Dest, sources); node.List.AddBefore(node, shiftOp); LinkedListNode<INode> newNode = node.List.AddBefore(node, storageOp); @@ -455,7 +454,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations bool returnsValue = operation.Dest != null; Operand returnValue = returnsValue ? Local() : null; - Operation callOp = new Operation(Instruction.Call, returnValue, sources); + Operation callOp = new(Instruction.Call, returnValue, sources); LinkedListNode<INode> newNode = node.List.AddBefore(node, callOp); @@ -480,7 +479,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations SearchResult result, out int functionId) { - List<uint> targetCbs = new List<uint>() { PackCbSlotAndOffset(result.SbCbSlot, result.SbCbOffset) }; + List<uint> targetCbs = new() { PackCbSlotAndOffset(result.SbCbSlot, result.SbCbOffset) }; if (gtsContext.TryGetFunctionId(operation, isMultiTarget: false, targetCbs, out functionId)) { @@ -498,7 +497,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations inArgumentsCount = 2; } - EmitterContext context = new EmitterContext(); + EmitterContext context = new(); Operand offset = Argument(0); Operand compare = null; @@ -542,7 +541,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations string functionName = GetFunctionName(operation, isMultiTarget: false, targetCbs); - Function function = new Function( + Function function = new( ControlFlowGraph.Create(context.GetOperations()).Blocks, functionName, returnsValue, @@ -561,9 +560,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations Operation operation, out int functionId) { - Queue<PhiNode> phis = new Queue<PhiNode>(); - HashSet<PhiNode> visited = new HashSet<PhiNode>(); - List<uint> targetCbs = new List<uint>(); + Queue<PhiNode> phis = new(); + HashSet<PhiNode> visited = new(); + List<uint> targetCbs = new(); Operand globalAddress = operation.GetSource(0); @@ -644,7 +643,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations inArgumentsCount = 3; } - EmitterContext context = new EmitterContext(); + EmitterContext context = new(); Operand globalAddressLow = Argument(0); Operand globalAddressHigh = Argument(1); @@ -684,7 +683,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations value = Argument(2); } - SearchResult result = new SearchResult(sbCbSlot, sbCbOffset); + SearchResult result = new(sbCbSlot, sbCbOffset); int alignment = config.GpuAccessor.QueryHostStorageBufferOffsetAlignment(); @@ -731,7 +730,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations string functionName = GetFunctionName(operation, isMultiTarget: true, targetCbs); - Function function = new Function( + Function function = new( ControlFlowGraph.Create(context.GetOperations()).Blocks, functionName, returnsValue, @@ -763,7 +762,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations StorageKind.GlobalMemoryS16 => "S16", StorageKind.GlobalMemoryU8 => "U8", StorageKind.GlobalMemoryU16 => "U16", - _ => string.Empty + _ => string.Empty, }; if (isMultiTarget) @@ -871,7 +870,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations StorageKind.GlobalMemoryU8 => 8, StorageKind.GlobalMemoryS16 or StorageKind.GlobalMemoryU16 => 16, - _ => 32 + _ => 32, }; if (bitSize < 32) @@ -1137,4 +1136,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return false; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs index 8d2669c0..e7805027 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs @@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations bool isUnused = IsUnused(node.Value); - if (!(node.Value is Operation operation) || isUnused) + if (node.Value is not Operation operation || isUnused) { if (node.Value is PhiNode phi && !isUnused) { @@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations modified = true; } else if ((operation.Inst == Instruction.PackHalf2x16 && PropagatePack(operation)) || - (operation.Inst == Instruction.ShuffleXor && MatchDdxOrDdy(operation))) + (operation.Inst == Instruction.ShuffleXor && MatchDdxOrDdy(operation))) { if (DestHasNoUses(operation)) { @@ -124,7 +124,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // the destination operand. Operand dest = copyOp.Dest; - Operand src = copyOp.GetSource(0); + Operand src = copyOp.GetSource(0); INode[] uses = dest.UseOps.ToArray(); @@ -199,7 +199,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations foreach (INode useNode in uses) { - if (!(useNode is Operation operation) || operation.Inst != Instruction.UnpackHalf2x16) + if (useNode is not Operation operation || operation.Inst != Instruction.UnpackHalf2x16) { continue; } @@ -248,12 +248,12 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations foreach (INode use in uses) { - if (!(use is Operation test)) + if (use is not Operation test) { continue; } - if (!(use is Operation useOp) || useOp.Inst != Instruction.SwizzleAdd) + if (use is not Operation useOp || useOp.Inst != Instruction.SwizzleAdd) { continue; } @@ -323,7 +323,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations Operand rhs = operation.GetSource(1); // Check LHS of the the main multiplication operation. We expect an input being multiplied by gl_FragCoord.w. - if (!(lhs.AsgOp is Operation attrMulOp) || attrMulOp.Inst != (Instruction.FP32 | Instruction.Multiply)) + if (lhs.AsgOp is not Operation attrMulOp || attrMulOp.Inst != (Instruction.FP32 | Instruction.Multiply)) { return; } @@ -338,7 +338,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } // RHS of the main multiplication should be a reciprocal operation (1.0 / x). - if (!(rhs.AsgOp is Operation reciprocalOp) || reciprocalOp.Inst != (Instruction.FP32 | Instruction.Divide)) + if (rhs.AsgOp is not Operation reciprocalOp || reciprocalOp.Inst != (Instruction.FP32 | Instruction.Divide)) { return; } @@ -368,7 +368,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations // from all the use lists on the operands that this node uses. block.Operations.Remove(llNode); - Queue<INode> nodes = new Queue<INode>(); + Queue<INode> nodes = new(); nodes.Enqueue(llNode.Value); @@ -457,4 +457,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return true; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Simplification.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Simplification.cs index 9b78c8aa..a509fcb4 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Simplification.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Simplification.cs @@ -202,4 +202,4 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return operand.Value == comparand; } } -}
\ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs index ffbd16f8..baf8e66e 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations public static bool IsInputLoad(INode node, IoVariable ioVariable, int elemIndex) { - if (!(node is Operation operation) || + if (node is not Operation operation || operation.Inst != Instruction.Load || operation.StorageKind != StorageKind.Input || operation.SourcesCount != 2) |