aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/Translation
diff options
context:
space:
mode:
authorTSRBerry <20988865+TSRBerry@users.noreply.github.com>2023-06-28 08:59:13 +0200
committerGitHub <noreply@github.com>2023-06-28 08:59:13 +0200
commit9becbd7d728fc2002c176dfd9d1d1aae86f86b12 (patch)
tree4aa3e608f438e706856ec8482c5053c13611caa4 /src/Ryujinx.Graphics.Shader/Translation
parente055217292e034e46ebadd2e839b301b996d7064 (diff)
[Ryujinx.Graphics.Shader] Address dotnet-format issues (#5373)1.1.929
* dotnet format style --severity info Some changes were manually reverted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0052 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format CA1069 warnings * Address or silence dotnet format CA2211 warnings * Address review comments * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Fix naming rule violation, Convert shader properties to auto-property and convert values to const * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * Address a few disabled IDE0060 warnings * Silence IDE0060 in .editorconfig * Run dotnet format after rebase * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Fix naming rule violations * Add trailing commas * Remove unused members and most unnecessary value assignments * Remove more unnecessary assignments * Remove NRE suppressor
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/Translation')
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/AggregateType.cs6
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/ControlFlowGraph.cs16
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Dominance.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs11
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs4
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/FunctionMatch.cs39
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/HelperFunctionManager.cs23
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/HelperFunctionName.cs4
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs8
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessToIndexed.cs14
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/BranchElimination.cs4
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/ConstantFolding.cs14
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/DoubleToFloat.cs4
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs63
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs20
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/Simplification.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/RegisterUsage.cs38
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs34
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs75
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs66
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs20
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/ShaderIdentifier.cs4
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Ssa.cs23
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/TargetApi.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs2
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/TranslationFlags.cs8
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/Translator.cs14
-rw-r--r--src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs11
31 files changed, 252 insertions, 285 deletions
diff --git a/src/Ryujinx.Graphics.Shader/Translation/AggregateType.cs b/src/Ryujinx.Graphics.Shader/Translation/AggregateType.cs
index a54eddc5..def8f1a9 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/AggregateType.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/AggregateType.cs
@@ -1,8 +1,10 @@
using System;
+using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.Graphics.Shader.Translation
{
[Flags]
+ [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
enum AggregateType
{
Invalid,
@@ -23,7 +25,7 @@ namespace Ryujinx.Graphics.Shader.Translation
Vector3 = 2 << ElementCountShift,
Vector4 = 3 << ElementCountShift,
- Array = 1 << 10
+ Array = 1 << 10,
}
static class AggregateTypeExtensions
@@ -37,7 +39,7 @@ namespace Ryujinx.Graphics.Shader.Translation
AggregateType.S32 or
AggregateType.U32 => 4,
AggregateType.FP64 => 8,
- _ => 0
+ _ => 0,
};
switch (type & AggregateType.ElementCountMask)
diff --git a/src/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs b/src/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
index 683b0d8a..f749cecb 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
@@ -33,4 +33,4 @@ namespace Ryujinx.Graphics.Shader.Translation
public const int UserAttributePerPatchBase = 0x18;
public const int UserAttributePerPatchEnd = 0x200;
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/ControlFlowGraph.cs b/src/Ryujinx.Graphics.Shader/Translation/ControlFlowGraph.cs
index 65328fd7..9b07c28f 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/ControlFlowGraph.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/ControlFlowGraph.cs
@@ -13,11 +13,11 @@ namespace Ryujinx.Graphics.Shader.Translation
{
Blocks = blocks;
- HashSet<BasicBlock> visited = new HashSet<BasicBlock>();
+ HashSet<BasicBlock> visited = new();
- Stack<BasicBlock> blockStack = new Stack<BasicBlock>();
+ Stack<BasicBlock> blockStack = new();
- List<BasicBlock> postOrderBlocks = new List<BasicBlock>(blocks.Length);
+ List<BasicBlock> postOrderBlocks = new(blocks.Length);
PostOrderMap = new int[blocks.Length];
@@ -50,9 +50,9 @@ namespace Ryujinx.Graphics.Shader.Translation
public static ControlFlowGraph Create(Operation[] operations)
{
- Dictionary<Operand, BasicBlock> labels = new Dictionary<Operand, BasicBlock>();
+ Dictionary<Operand, BasicBlock> labels = new();
- List<BasicBlock> blocks = new List<BasicBlock>();
+ List<BasicBlock> blocks = new();
BasicBlock currentBlock = null;
@@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Shader.Translation
void NewNextBlock()
{
- BasicBlock block = new BasicBlock(blocks.Count);
+ BasicBlock block = new(blocks.Count);
blocks.Add(block);
@@ -110,7 +110,7 @@ namespace Ryujinx.Graphics.Shader.Translation
currentBlock.Operations.AddLast(operation);
}
- needsNewBlock = operation.Inst == Instruction.Branch ||
+ needsNewBlock = operation.Inst == Instruction.Branch ||
operation.Inst == Instruction.BranchIfTrue ||
operation.Inst == Instruction.BranchIfFalse;
@@ -173,4 +173,4 @@ namespace Ryujinx.Graphics.Shader.Translation
return false;
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Dominance.cs b/src/Ryujinx.Graphics.Shader/Translation/Dominance.cs
index 09c2eb0f..cd651ce0 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/Dominance.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/Dominance.cs
@@ -91,4 +91,4 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs b/src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
index 87e5457f..9eedc3f9 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
-
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
namespace Ryujinx.Graphics.Shader.Translation
@@ -84,7 +83,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public Operand Add(Instruction inst, Operand dest = null, params Operand[] sources)
{
- Operation operation = new Operation(inst, dest, sources);
+ Operation operation = new(inst, dest, sources);
_operations.Add(operation);
@@ -93,7 +92,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public Operand Add(Instruction inst, StorageKind storageKind, Operand dest = null, params Operand[] sources)
{
- Operation operation = new Operation(inst, storageKind, dest, sources);
+ Operation operation = new(inst, storageKind, dest, sources);
_operations.Add(operation);
@@ -104,7 +103,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
Operand[] dests = new[] { dest.Item1, dest.Item2 };
- Operation operation = new Operation(inst, 0, dests, sources);
+ Operation operation = new(inst, 0, dests, sources);
Add(operation);
@@ -430,7 +429,7 @@ namespace Ryujinx.Graphics.Shader.Translation
AlphaTestOp.Less => Instruction.CompareLess,
AlphaTestOp.LessOrEqual => Instruction.CompareLessOrEqual,
AlphaTestOp.NotEqual => Instruction.CompareNotEqual,
- _ => 0
+ _ => 0,
};
Debug.Assert(comparator != 0, $"Invalid alpha test operation \"{alphaTestOp}\".");
@@ -532,4 +531,4 @@ namespace Ryujinx.Graphics.Shader.Translation
return _operations.ToArray();
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs b/src/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs
index 0ba26107..c2f1b790 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/EmitterContextInsts.cs
@@ -850,4 +850,4 @@ namespace Ryujinx.Graphics.Shader.Translation
return context.Add(Instruction.VoteAny, Local(), a);
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs b/src/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs
index 59d35d90..9d4d032a 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/FeatureFlags.cs
@@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Shader.Translation
// Affected by resolution scaling.
IntegerSampling = 1 << 0,
- FragCoordXY = 1 << 1,
+ FragCoordXY = 1 << 1,
Bindless = 1 << 2,
InstanceId = 1 << 3,
@@ -23,6 +23,6 @@ namespace Ryujinx.Graphics.Shader.Translation
OaIndexing = 1 << 8,
FixedFuncAttr = 1 << 9,
LocalMemory = 1 << 10,
- SharedMemory = 1 << 11
+ SharedMemory = 1 << 11,
}
}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/FunctionMatch.cs b/src/Ryujinx.Graphics.Shader/Translation/FunctionMatch.cs
index 073e120a..714a9d68 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/FunctionMatch.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/FunctionMatch.cs
@@ -7,11 +7,11 @@ namespace Ryujinx.Graphics.Shader.Translation
{
static class FunctionMatch
{
- private static IPatternTreeNode[] _fsiGetAddressTree = PatternTrees.GetFsiGetAddress();
- private static IPatternTreeNode[] _fsiGetAddressV2Tree = PatternTrees.GetFsiGetAddressV2();
- private static IPatternTreeNode[] _fsiIsLastWarpThreadPatternTree = PatternTrees.GetFsiIsLastWarpThread();
- private static IPatternTreeNode[] _fsiBeginPatternTree = PatternTrees.GetFsiBeginPattern();
- private static IPatternTreeNode[] _fsiEndPatternTree = PatternTrees.GetFsiEndPattern();
+ private static readonly IPatternTreeNode[] _fsiGetAddressTree = PatternTrees.GetFsiGetAddress();
+ private static readonly IPatternTreeNode[] _fsiGetAddressV2Tree = PatternTrees.GetFsiGetAddressV2();
+ private static readonly IPatternTreeNode[] _fsiIsLastWarpThreadPatternTree = PatternTrees.GetFsiIsLastWarpThread();
+ private static readonly IPatternTreeNode[] _fsiBeginPatternTree = PatternTrees.GetFsiBeginPattern();
+ private static readonly IPatternTreeNode[] _fsiEndPatternTree = PatternTrees.GetFsiEndPattern();
public static void RunPass(DecodedProgram program)
{
@@ -113,7 +113,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private enum TreeNodeType : byte
{
Op,
- Label
+ Label,
}
private class TreeNode
@@ -150,9 +150,9 @@ namespace Ryujinx.Graphics.Shader.Translation
private static TreeNode[] BuildTree(Block[] blocks)
{
- List<TreeNode> nodes = new List<TreeNode>();
+ List<TreeNode> nodes = new();
- Dictionary<ulong, TreeNode> labels = new Dictionary<ulong, TreeNode>();
+ Dictionary<ulong, TreeNode> labels = new();
TreeNodeUse[] predDefs = new TreeNodeUse[RegisterConsts.PredsCount];
TreeNodeUse[] gprDefs = new TreeNodeUse[RegisterConsts.GprsCount];
@@ -223,7 +223,7 @@ namespace Ryujinx.Graphics.Shader.Translation
if (block.Predecessors.Count > 1)
{
- TreeNode label = new TreeNode(order++);
+ TreeNode label = new(order++);
nodes.Add(label);
labels.Add(block.Address, label);
}
@@ -232,7 +232,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
InstOp op = block.OpCodes[opIndex];
- TreeNode node = new TreeNode(op, IsOrderDependant(op.Name) ? order : (byte)0);
+ TreeNode node = new(op, IsOrderDependant(op.Name) ? order : (byte)0);
// Add uses.
@@ -288,7 +288,7 @@ namespace Ryujinx.Graphics.Shader.Translation
InstProps.SPd => 30,
InstProps.TPd => 51,
InstProps.VPd => 45,
- _ => throw new InvalidOperationException($"Table has unknown predicate destination {pdType}.")
+ _ => throw new InvalidOperationException($"Table has unknown predicate destination {pdType}."),
};
byte predIndex = (byte)((op.RawOpCode >> bit) & 7);
@@ -350,7 +350,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public IPatternTreeNode Node { get; }
public int Index { get; }
public bool Inverted { get; }
- public PatternTreeNodeUse Inv => new PatternTreeNodeUse(Index, !Inverted, Node);
+ public PatternTreeNodeUse Inv => new(Index, !Inverted, Node);
private PatternTreeNodeUse(int index, bool inverted, IPatternTreeNode node)
{
@@ -373,7 +373,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public TreeNodeType Type { get; }
public byte Order { get; }
public bool IsImm { get; }
- public PatternTreeNodeUse Out => new PatternTreeNodeUse(0, this);
+ public PatternTreeNodeUse Out => new(0, this);
public PatternTreeNode(InstName name, Func<T, bool> match, TreeNodeType type = TreeNodeType.Op, byte order = 0, bool isImm = false)
{
@@ -435,7 +435,7 @@ namespace Ryujinx.Graphics.Shader.Translation
}
DecodedFunction callTarget = program.GetFunctionByAddress(callOp.GetAbsoluteAddress());
- TreeNode[] callTargetTree = null;
+ TreeNode[] callTargetTree;
if (callTarget == null || !Matches(_fsiIsLastWarpThreadPatternTree, callTargetTree = BuildTree(callTarget.Blocks)))
{
@@ -548,7 +548,7 @@ namespace Ryujinx.Graphics.Shader.Translation
.Use(PT)
.Use(orderingTicketValue).Out),
Iadd(x: true, 0, 405).Use(PT).Use(RZ),
- Ret().Use(PT)
+ Ret().Use(PT),
};
}
@@ -576,7 +576,7 @@ namespace Ryujinx.Graphics.Shader.Translation
.Use(PT)
.Use(orderingTicketValue).Out).Out),
Iadd(x: true, 0, 405).Use(PT).Use(RZ),
- Ret().Use(PT)
+ Ret().Use(PT),
};
}
@@ -603,7 +603,7 @@ namespace Ryujinx.Graphics.Shader.Translation
.Use(threadKillValue).OutAt(1))
.Use(RZ).Out).OutAt(1)).Out)
.Use(laneIdValue),
- Ret().Use(PT)
+ Ret().Use(PT),
};
}
@@ -638,7 +638,7 @@ namespace Ryujinx.Graphics.Shader.Translation
.Use(PT)
.Use(addressLowValue).Out).Inv)
.Use(label.Out),
- Ret().Use(PT)
+ Ret().Use(PT),
};
}
@@ -684,7 +684,7 @@ namespace Ryujinx.Graphics.Shader.Translation
.Use(incrementValue)
.Use(popcResult)
.Use(RZ).Out).Out),
- Ret().Use(PT)
+ Ret().Use(PT),
};
}
@@ -806,7 +806,6 @@ namespace Ryujinx.Graphics.Shader.Translation
private static PatternTreeNodeUse PT => PTOrRZ();
private static PatternTreeNodeUse RZ => PTOrRZ();
- private static PatternTreeNodeUse Undef => new PatternTreeNodeUse(0, null);
private static PatternTreeNodeUse CallArg(int index)
{
diff --git a/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionManager.cs b/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionManager.cs
index 51a39682..2addff5c 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionManager.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionManager.cs
@@ -1,7 +1,6 @@
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using System;
using System.Collections.Generic;
-
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
namespace Ryujinx.Graphics.Shader.Translation
@@ -65,13 +64,13 @@ namespace Ryujinx.Graphics.Shader.Translation
HelperFunctionName.ConvertFloatToDouble => GenerateConvertFloatToDoubleFunction(),
HelperFunctionName.TexelFetchScale => GenerateTexelFetchScaleFunction(),
HelperFunctionName.TextureSizeUnscale => GenerateTextureSizeUnscaleFunction(),
- _ => throw new ArgumentException($"Invalid function name {functionName}")
+ _ => throw new ArgumentException($"Invalid function name {functionName}"),
};
}
- private Function GenerateConvertDoubleToFloatFunction()
+ private static Function GenerateConvertDoubleToFloatFunction()
{
- EmitterContext context = new EmitterContext();
+ EmitterContext context = new();
Operand valueLow = Argument(0);
Operand valueHigh = Argument(1);
@@ -119,9 +118,9 @@ namespace Ryujinx.Graphics.Shader.Translation
return new Function(ControlFlowGraph.Create(context.GetOperations()).Blocks, "ConvertDoubleToFloat", true, 2, 0);
}
- private Function GenerateConvertFloatToDoubleFunction()
+ private static Function GenerateConvertFloatToDoubleFunction()
{
- EmitterContext context = new EmitterContext();
+ EmitterContext context = new();
Operand value = Argument(0);
@@ -164,13 +163,13 @@ namespace Ryujinx.Graphics.Shader.Translation
HelperFunctionName.SharedAtomicMinS32 => GenerateSharedAtomicSigned(id, isMin: true),
HelperFunctionName.SharedStore8 => GenerateSharedStore8(id),
HelperFunctionName.SharedStore16 => GenerateSharedStore16(id),
- _ => throw new ArgumentException($"Invalid function name {functionName}")
+ _ => throw new ArgumentException($"Invalid function name {functionName}"),
};
}
private static Function GenerateSharedAtomicSigned(int id, bool isMin)
{
- EmitterContext context = new EmitterContext();
+ EmitterContext context = new();
Operand wordOffset = Argument(0);
Operand value = Argument(1);
@@ -199,7 +198,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private static Function GenerateSharedStore(int id, int bitSize)
{
- EmitterContext context = new EmitterContext();
+ EmitterContext context = new();
Operand offset = Argument(0);
Operand value = Argument(1);
@@ -219,7 +218,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private Function GenerateTexelFetchScaleFunction()
{
- EmitterContext context = new EmitterContext();
+ EmitterContext context = new();
Operand input = Argument(0);
Operand samplerIndex = Argument(1);
@@ -270,7 +269,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private Function GenerateTextureSizeUnscaleFunction()
{
- EmitterContext context = new EmitterContext();
+ EmitterContext context = new();
Operand input = Argument(0);
Operand samplerIndex = Argument(1);
@@ -328,4 +327,4 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionName.cs b/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionName.cs
index 984f2d04..e5af1735 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionName.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/HelperFunctionName.cs
@@ -9,6 +9,6 @@ namespace Ryujinx.Graphics.Shader.Translation
SharedStore8,
SharedStore16,
TexelFetchScale,
- TextureSizeUnscale
+ TextureSizeUnscale,
}
-} \ No newline at end of file
+}
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)
diff --git a/src/Ryujinx.Graphics.Shader/Translation/RegisterUsage.cs b/src/Ryujinx.Graphics.Shader/Translation/RegisterUsage.cs
index 9e31831d..e27e4707 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/RegisterUsage.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/RegisterUsage.cs
@@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Shader.Translation
static class RegisterUsage
{
private const int RegsCount = 256;
- private const int RegsMask = RegsCount - 1;
+ private const int RegsMask = RegsCount - 1;
private const int GprMasks = 4;
private const int PredMasks = 1;
@@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Shader.Translation
FlagMask = flagMask;
}
- public long GetMask(int index)
+ public readonly long GetMask(int index)
{
return index switch
{
@@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Shader.Translation
3 => GprMask3,
4 => PredMask,
5 => FlagMask,
- _ => throw new ArgumentOutOfRangeException(nameof(index))
+ _ => throw new ArgumentOutOfRangeException(nameof(index)),
};
}
@@ -93,12 +93,12 @@ namespace Ryujinx.Graphics.Shader.Translation
return !x.Equals(y);
}
- public override bool Equals(object obj)
+ public readonly override bool Equals(object obj)
{
return obj is RegisterMask regMask && Equals(regMask);
}
- public bool Equals(RegisterMask other)
+ public readonly bool Equals(RegisterMask other)
{
return GprMask0 == other.GprMask0 &&
GprMask1 == other.GprMask1 &&
@@ -108,7 +108,7 @@ namespace Ryujinx.Graphics.Shader.Translation
FlagMask == other.FlagMask;
}
- public override int GetHashCode()
+ public readonly override int GetHashCode()
{
return HashCode.Combine(GprMask0, GprMask1, GprMask2, GprMask3, PredMask, FlagMask);
}
@@ -121,18 +121,18 @@ namespace Ryujinx.Graphics.Shader.Translation
public FunctionRegisterUsage(Register[] inArguments, Register[] outArguments)
{
- InArguments = inArguments;
+ InArguments = inArguments;
OutArguments = outArguments;
}
}
public static FunctionRegisterUsage RunPass(ControlFlowGraph cfg)
{
- List<Register> inArguments = new List<Register>();
- List<Register> outArguments = new List<Register>();
+ List<Register> inArguments = new();
+ List<Register> outArguments = new();
// Compute local register inputs and outputs used inside blocks.
- RegisterMask[] localInputs = new RegisterMask[cfg.Blocks.Length];
+ RegisterMask[] localInputs = new RegisterMask[cfg.Blocks.Length];
RegisterMask[] localOutputs = new RegisterMask[cfg.Blocks.Length];
foreach (BasicBlock block in cfg.Blocks)
@@ -165,11 +165,11 @@ namespace Ryujinx.Graphics.Shader.Translation
// Compute global register inputs and outputs used across blocks.
RegisterMask[] globalCmnOutputs = new RegisterMask[cfg.Blocks.Length];
- RegisterMask[] globalInputs = new RegisterMask[cfg.Blocks.Length];
+ RegisterMask[] globalInputs = new RegisterMask[cfg.Blocks.Length];
RegisterMask[] globalOutputs = new RegisterMask[cfg.Blocks.Length];
- RegisterMask allOutputs = new RegisterMask();
- RegisterMask allCmnOutputs = new RegisterMask(-1L, -1L, -1L, -1L, -1L, -1L);
+ RegisterMask allOutputs = new();
+ RegisterMask allCmnOutputs = new(-1L, -1L, -1L, -1L, -1L, -1L);
bool modified;
@@ -389,14 +389,14 @@ namespace Ryujinx.Graphics.Shader.Translation
mask &= ~(1L << bit);
- Register register = new Register(baseRegIndex + bit, regType);
+ Register register = new(baseRegIndex + bit, regType);
if (fillArgsList)
{
inArguments.Add(register);
}
- Operation copyOp = new Operation(Instruction.Copy, OperandHelper.Register(register), OperandHelper.Argument(argIndex++));
+ Operation copyOp = new(Instruction.Copy, OperandHelper.Register(register), OperandHelper.Argument(argIndex++));
if (node == null)
{
@@ -429,14 +429,14 @@ namespace Ryujinx.Graphics.Shader.Translation
mask &= ~(1L << bit);
- Register register = new Register(baseRegIndex + bit, regType);
+ Register register = new(baseRegIndex + bit, regType);
if (fillArgsList)
{
outArguments.Add(register);
}
- Operation copyOp = new Operation(Instruction.Copy, OperandHelper.Argument(argIndex++), OperandHelper.Register(register));
+ Operation copyOp = new(Instruction.Copy, OperandHelper.Argument(argIndex++), OperandHelper.Register(register));
if (node == null)
{
@@ -475,7 +475,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private static bool EndsWithReturn(BasicBlock block)
{
- if (!(block.GetLastOp() is Operation operation))
+ if (block.GetLastOp() is not Operation operation)
{
return false;
}
@@ -483,4 +483,4 @@ namespace Ryujinx.Graphics.Shader.Translation
return operation.Inst == Instruction.Return;
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs b/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs
index 3a46f6e4..f3a5ba6c 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/ResourceManager.cs
@@ -13,10 +13,9 @@ namespace Ryujinx.Graphics.Shader.Translation
private const int DefaultLocalMemorySize = 128;
private const int DefaultSharedMemorySize = 4096;
- private static readonly string[] _stagePrefixes = new string[] { "cp", "vp", "tcp", "tep", "gp", "fp" };
+ private static readonly string[] _stagePrefixes = { "cp", "vp", "tcp", "tep", "gp", "fp" };
private readonly IGpuAccessor _gpuAccessor;
- private readonly ShaderProperties _properties;
private readonly string _stagePrefix;
private readonly int[] _cbSlotToBindingMap;
@@ -31,12 +30,12 @@ namespace Ryujinx.Graphics.Shader.Translation
public int LocalMemoryId { get; private set; }
public int SharedMemoryId { get; private set; }
- public ShaderProperties Properties => _properties;
+ public ShaderProperties Properties { get; }
public ResourceManager(ShaderStage stage, IGpuAccessor gpuAccessor, ShaderProperties properties)
{
_gpuAccessor = gpuAccessor;
- _properties = properties;
+ Properties = properties;
_stagePrefix = GetShaderStagePrefix(stage);
_cbSlotToBindingMap = new int[18];
@@ -83,7 +82,7 @@ namespace Ryujinx.Graphics.Shader.Translation
size = DefaultSharedMemorySize;
}
- var smem = new MemoryDefinition("shared_memory", AggregateType.Array | AggregateType.U32, BitUtils.DivRoundUp(size, sizeof(uint)));
+ var smem = new MemoryDefinition("shared_memory", AggregateType.Array | AggregateType.U32, BitUtils.DivRoundUp(size, sizeof(uint)));
SharedMemoryId = Properties.AddSharedMemory(smem);
}
@@ -211,7 +210,7 @@ namespace Ryujinx.Graphics.Shader.Translation
(int sbCbSlot, int sbCbOffset) = UnpackSbCbInfo(key);
descriptors[descriptorIndex++] = new BufferDescriptor(binding, slot, sbCbSlot, sbCbOffset)
{
- Flags = (_sbSlotWritten & (1u << slot)) != 0 ? BufferUsageFlags.Write : BufferUsageFlags.None
+ Flags = (_sbSlotWritten & (1u << slot)) != 0 ? BufferUsageFlags.Write : BufferUsageFlags.None,
};
}
}
@@ -226,39 +225,34 @@ namespace Ryujinx.Graphics.Shader.Translation
private void AddNewConstantBuffer(int binding, string name)
{
- StructureType type = new StructureType(new[]
+ StructureType type = new(new[]
{
- new StructureField(AggregateType.Array | AggregateType.Vector4 | AggregateType.FP32, "data", Constants.ConstantBufferSize / 16)
+ new StructureField(AggregateType.Array | AggregateType.Vector4 | AggregateType.FP32, "data", Constants.ConstantBufferSize / 16),
});
- _properties.AddConstantBuffer(binding, new BufferDefinition(BufferLayout.Std140, 0, binding, name, type));
+ Properties.AddConstantBuffer(binding, new BufferDefinition(BufferLayout.Std140, 0, binding, name, type));
}
private void AddNewStorageBuffer(int binding, string name)
{
- StructureType type = new StructureType(new[]
+ StructureType type = new(new[]
{
- new StructureField(AggregateType.Array | AggregateType.U32, "data", 0)
+ new StructureField(AggregateType.Array | AggregateType.U32, "data", 0),
});
- _properties.AddStorageBuffer(binding, new BufferDefinition(BufferLayout.Std430, 1, binding, name, type));
+ Properties.AddStorageBuffer(binding, new BufferDefinition(BufferLayout.Std430, 1, binding, name, type));
}
public static string GetShaderStagePrefix(ShaderStage stage)
{
uint index = (uint)stage;
- if (index >= _stagePrefixes.Length)
- {
- return "invalid";
- }
-
- return _stagePrefixes[index];
+ return index >= _stagePrefixes.Length ? "invalid" : _stagePrefixes[index];
}
private static int PackSbCbInfo(int sbCbSlot, int sbCbOffset)
{
- return sbCbOffset | ((int)sbCbSlot << 16);
+ return sbCbOffset | (sbCbSlot << 16);
}
private static (int, int) UnpackSbCbInfo(int key)
@@ -266,4 +260,4 @@ namespace Ryujinx.Graphics.Shader.Translation
return ((byte)(key >> 16), (ushort)key);
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs b/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
index f5a524a0..42e3ecee 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/Rewriter.cs
@@ -4,7 +4,6 @@ using Ryujinx.Graphics.Shader.Translation.Optimizations;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
-
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
namespace Ryujinx.Graphics.Shader.Translation
@@ -134,7 +133,7 @@ namespace Ryujinx.Graphics.Shader.Translation
AggregateType.Vector2 => 2,
AggregateType.Vector3 => 3,
AggregateType.Vector4 => 4,
- _ => 1
+ _ => 1,
};
if (elemCount == 1)
@@ -154,9 +153,9 @@ namespace Ryujinx.Graphics.Shader.Translation
inputs[srcIndex] = operation.GetSource(srcIndex);
}
- inputs[inputs.Length - 1] = Const(i);
+ inputs[^1] = Const(i);
- Operation loadOp = new Operation(Instruction.Load, StorageKind.ConstantBuffer, value, inputs);
+ Operation loadOp = new(Instruction.Load, StorageKind.ConstantBuffer, value, inputs);
node.List.AddBefore(node, loadOp);
@@ -169,8 +168,8 @@ namespace Ryujinx.Graphics.Shader.Translation
Operand isCurrentIndex = Local();
Operand selection = Local();
- Operation compareOp = new Operation(Instruction.CompareEqual, isCurrentIndex, new Operand[] { elemIndex, Const(i) });
- Operation selectOp = new Operation(Instruction.ConditionalSelect, selection, new Operand[] { isCurrentIndex, value, result });
+ Operation compareOp = new(Instruction.CompareEqual, isCurrentIndex, new Operand[] { elemIndex, Const(i) });
+ Operation selectOp = new(Instruction.ConditionalSelect, selection, new Operand[] { isCurrentIndex, value, result });
node.List.AddBefore(node, compareOp);
node.List.AddBefore(node, selectOp);
@@ -267,10 +266,8 @@ namespace Ryujinx.Graphics.Shader.Translation
{
TextureOperation texOp = (TextureOperation)node.Value;
- bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
- bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
-
- bool isArray = (texOp.Type & SamplerType.Array) != 0;
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
+ bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
int coordsCount = texOp.Type.GetDimensions();
@@ -318,10 +315,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
TextureOperation texOp = (TextureOperation)node.Value;
- bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
- bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
-
- bool isArray = (texOp.Type & SamplerType.Array) != 0;
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
if (texOp.Inst == Instruction.TextureSize &&
@@ -383,8 +377,8 @@ namespace Ryujinx.Graphics.Shader.Translation
TextureOperation texOp = (TextureOperation)node.Value;
- bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
- bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
+ bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
+ bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
bool isCoordNormalized = isBindless || config.GpuAccessor.QueryTextureCoordNormalized(texOp.Handle, texOp.CbufSlot);
@@ -393,7 +387,6 @@ namespace Ryujinx.Graphics.Shader.Translation
return node;
}
- bool isArray = (texOp.Type & SamplerType.Array) != 0;
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
int coordsCount = texOp.Type.GetDimensions();
@@ -453,7 +446,7 @@ namespace Ryujinx.Graphics.Shader.Translation
TextureOperation texOp = (TextureOperation)node.Value;
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
- bool isGather = (texOp.Flags & TextureFlags.Gather) != 0;
+ bool isGather = (texOp.Flags & TextureFlags.Gather) != 0;
int gatherBiasPrecision = config.GpuAccessor.QueryHostGatherBiasPrecision();
@@ -462,10 +455,12 @@ namespace Ryujinx.Graphics.Shader.Translation
return node;
}
+#pragma warning disable IDE0059 // Remove unnecessary value assignment
bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
- bool isArray = (texOp.Type & SamplerType.Array) != 0;
+ bool isArray = (texOp.Type & SamplerType.Array) != 0;
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
+#pragma warning restore IDE0059
int coordsCount = texOp.Type.GetDimensions();
int coordsIndex = isBindless || isIndexed ? 1 : 0;
@@ -536,7 +531,7 @@ namespace Ryujinx.Graphics.Shader.Translation
TextureOperation texOp = (TextureOperation)node.Value;
- bool hasOffset = (texOp.Flags & TextureFlags.Offset) != 0;
+ bool hasOffset = (texOp.Flags & TextureFlags.Offset) != 0;
bool hasOffsets = (texOp.Flags & TextureFlags.Offsets) != 0;
bool hasInvalidOffset = (hasOffset || hasOffsets) && !config.GpuAccessor.QueryHostSupportsNonConstantTextureOffset();
@@ -548,16 +543,16 @@ namespace Ryujinx.Graphics.Shader.Translation
return node;
}
- bool isGather = (texOp.Flags & TextureFlags.Gather) != 0;
+ bool isGather = (texOp.Flags & TextureFlags.Gather) != 0;
bool hasDerivatives = (texOp.Flags & TextureFlags.Derivatives) != 0;
- bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
- bool hasLodBias = (texOp.Flags & TextureFlags.LodBias) != 0;
- bool hasLodLevel = (texOp.Flags & TextureFlags.LodLevel) != 0;
+ bool intCoords = (texOp.Flags & TextureFlags.IntCoords) != 0;
+ bool hasLodBias = (texOp.Flags & TextureFlags.LodBias) != 0;
+ bool hasLodLevel = (texOp.Flags & TextureFlags.LodLevel) != 0;
- bool isArray = (texOp.Type & SamplerType.Array) != 0;
- bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
+ bool isArray = (texOp.Type & SamplerType.Array) != 0;
+ bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
bool isMultisample = (texOp.Type & SamplerType.Multisample) != 0;
- bool isShadow = (texOp.Type & SamplerType.Shadow) != 0;
+ bool isShadow = (texOp.Type & SamplerType.Shadow) != 0;
int coordsCount = texOp.Type.GetDimensions();
@@ -647,12 +642,12 @@ namespace Ryujinx.Graphics.Shader.Translation
if (hasLodBias)
{
- sources[dstIndex++] = texOp.GetSource(srcIndex++);
+ sources[dstIndex++] = texOp.GetSource(srcIndex++);
}
if (isGather && !isShadow)
{
- sources[dstIndex++] = texOp.GetSource(srcIndex++);
+ sources[dstIndex++] = texOp.GetSource(srcIndex++);
}
int coordsIndex = isBindless || isIndexed ? 1 : 0;
@@ -712,7 +707,7 @@ namespace Ryujinx.Graphics.Shader.Translation
newSources[coordsIndex + index] = coordPlusOffset;
}
- TextureOperation newTexOp = new TextureOperation(
+ TextureOperation newTexOp = new(
Instruction.TextureSample,
texOp.Type,
texOp.Format,
@@ -771,7 +766,7 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
- TextureOperation newTexOp = new TextureOperation(
+ TextureOperation newTexOp = new(
Instruction.TextureSample,
texOp.Type,
texOp.Format,
@@ -862,13 +857,13 @@ namespace Ryujinx.Graphics.Shader.Translation
int maxPositive = format switch
{
- TextureFormat.R8Snorm => sbyte.MaxValue,
- TextureFormat.R8G8Snorm => sbyte.MaxValue,
- TextureFormat.R8G8B8A8Snorm => sbyte.MaxValue,
- TextureFormat.R16Snorm => short.MaxValue,
- TextureFormat.R16G16Snorm => short.MaxValue,
+ TextureFormat.R8Snorm => sbyte.MaxValue,
+ TextureFormat.R8G8Snorm => sbyte.MaxValue,
+ TextureFormat.R8G8B8A8Snorm => sbyte.MaxValue,
+ TextureFormat.R16Snorm => short.MaxValue,
+ TextureFormat.R16G16Snorm => short.MaxValue,
TextureFormat.R16G16B16A16Snorm => short.MaxValue,
- _ => 0
+ _ => 0,
};
// The value being 0 means that the format is not a SNORM format,
@@ -886,8 +881,8 @@ namespace Ryujinx.Graphics.Shader.Translation
INode[] uses = dest.UseOps.ToArray();
- Operation convOp = new Operation(Instruction.ConvertS32ToFP32, Local(), dest);
- Operation normOp = new Operation(Instruction.FP32 | Instruction.Multiply, Local(), convOp.Dest, ConstF(1f / maxPositive));
+ Operation convOp = new(Instruction.ConvertS32ToFP32, Local(), dest);
+ Operation normOp = new(Instruction.FP32 | Instruction.Multiply, Local(), convOp.Dest, ConstF(1f / maxPositive));
node = node.List.AddAfter(node, convOp);
node = node.List.AddAfter(node, normOp);
@@ -990,4 +985,4 @@ namespace Ryujinx.Graphics.Shader.Translation
return false;
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/src/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
index e50c9a84..e93a709c 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs
@@ -126,9 +126,9 @@ namespace Ryujinx.Graphics.Shader.Translation
public ShaderConfig(ShaderStage stage, IGpuAccessor gpuAccessor, TranslationOptions options, int localMemorySize)
{
- Stage = stage;
- GpuAccessor = gpuAccessor;
- Options = options;
+ Stage = stage;
+ GpuAccessor = gpuAccessor;
+ Options = options;
LocalMemorySize = localMemorySize;
_transformFeedbackDefinitions = new Dictionary<TransformFeedbackVariable, TransformFeedbackOutput>();
@@ -138,35 +138,35 @@ namespace Ryujinx.Graphics.Shader.Translation
gpuAccessor.QueryTransformFeedbackEnabled() &&
gpuAccessor.QueryHostSupportsTransformFeedback();
- UsedInputAttributesPerPatch = new HashSet<int>();
+ UsedInputAttributesPerPatch = new HashSet<int>();
UsedOutputAttributesPerPatch = new HashSet<int>();
_usedTextures = new Dictionary<TextureInfo, TextureMeta>();
- _usedImages = new Dictionary<TextureInfo, TextureMeta>();
+ _usedImages = new Dictionary<TextureInfo, TextureMeta>();
ResourceManager = new ResourceManager(stage, gpuAccessor, new ShaderProperties());
if (!gpuAccessor.QueryHostSupportsTransformFeedback() && gpuAccessor.QueryTransformFeedbackEnabled())
{
- StructureType tfeInfoStruct = new StructureType(new StructureField[]
+ StructureType tfeInfoStruct = new(new StructureField[]
{
- new StructureField(AggregateType.Array | AggregateType.U32, "base_offset", 4),
- new StructureField(AggregateType.U32, "vertex_count")
+ new(AggregateType.Array | AggregateType.U32, "base_offset", 4),
+ new(AggregateType.U32, "vertex_count"),
});
- BufferDefinition tfeInfoBuffer = new BufferDefinition(BufferLayout.Std430, 1, Constants.TfeInfoBinding, "tfe_info", tfeInfoStruct);
+ BufferDefinition tfeInfoBuffer = new(BufferLayout.Std430, 1, Constants.TfeInfoBinding, "tfe_info", tfeInfoStruct);
Properties.AddStorageBuffer(Constants.TfeInfoBinding, tfeInfoBuffer);
- StructureType tfeDataStruct = new StructureType(new StructureField[]
+ StructureType tfeDataStruct = new(new StructureField[]
{
- new StructureField(AggregateType.Array | AggregateType.U32, "data", 0)
+ new(AggregateType.Array | AggregateType.U32, "data", 0),
});
for (int i = 0; i < Constants.TfeBuffersCount; i++)
{
int binding = Constants.TfeBufferBaseBinding + i;
- BufferDefinition tfeDataBuffer = new BufferDefinition(BufferLayout.Std430, 1, binding, $"tfe_data{i}", tfeDataStruct);
+ BufferDefinition tfeDataBuffer = new(BufferLayout.Std430, 1, binding, $"tfe_data{i}", tfeDataStruct);
Properties.AddStorageBuffer(binding, tfeDataBuffer);
}
}
@@ -180,8 +180,8 @@ namespace Ryujinx.Graphics.Shader.Translation
TranslationOptions options) : this(stage, gpuAccessor, options, 0)
{
ThreadsPerInputPrimitive = 1;
- OutputTopology = outputTopology;
- MaxOutputVertices = maxOutputVertices;
+ OutputTopology = outputTopology;
+ MaxOutputVertices = maxOutputVertices;
}
public ShaderConfig(
@@ -189,15 +189,15 @@ namespace Ryujinx.Graphics.Shader.Translation
IGpuAccessor gpuAccessor,
TranslationOptions options) : this(header.Stage, gpuAccessor, options, GetLocalMemorySize(header))
{
- GpPassthrough = header.Stage == ShaderStage.Geometry && header.GpPassthrough;
+ GpPassthrough = header.Stage == ShaderStage.Geometry && header.GpPassthrough;
ThreadsPerInputPrimitive = header.ThreadsPerInputPrimitive;
- OutputTopology = header.OutputTopology;
- MaxOutputVertices = header.MaxOutputVertexCount;
- ImapTypes = header.ImapTypes;
- OmapTargets = header.OmapTargets;
- OmapSampleMask = header.OmapSampleMask;
- OmapDepth = header.OmapDepth;
- LastInVertexPipeline = header.Stage < ShaderStage.Fragment;
+ OutputTopology = header.OutputTopology;
+ MaxOutputVertices = header.MaxOutputVertexCount;
+ ImapTypes = header.ImapTypes;
+ OmapTargets = header.OmapTargets;
+ OmapSampleMask = header.OmapSampleMask;
+ OmapDepth = header.OmapDepth;
+ LastInVertexPipeline = header.Stage < ShaderStage.Fragment;
}
private static int GetLocalMemorySize(ShaderHeader header)
@@ -524,7 +524,7 @@ namespace Ryujinx.Graphics.Shader.Translation
// Regular and per-patch input/output locations can't overlap,
// so we must assign on our location using unused regular input/output locations.
- Dictionary<int, int> locationsMap = new Dictionary<int, int>();
+ Dictionary<int, int> locationsMap = new();
int freeMask = ~UsedOutputAttributes;
@@ -718,7 +718,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
AccurateType = accurateType,
Type = type,
- UsageFlags = usageFlags
+ UsageFlags = usageFlags,
};
if (dict.TryGetValue(info, out var existingMeta))
@@ -797,24 +797,6 @@ namespace Ryujinx.Graphics.Shader.Translation
return default;
}
- private static int FindDescriptorIndex(TextureDescriptor[] array, AstTextureOperation texOp)
- {
- for (int i = 0; i < array.Length; i++)
- {
- var descriptor = array[i];
-
- if (descriptor.Type == texOp.Type &&
- descriptor.CbufSlot == texOp.CbufSlot &&
- descriptor.HandleIndex == texOp.Handle &&
- descriptor.Format == texOp.Format)
- {
- return i;
- }
- }
-
- return -1;
- }
-
private static int FindDescriptorIndex(TextureDescriptor[] array, TextureOperation texOp, bool ignoreType = false)
{
for (int i = 0; i < array.Length; i++)
diff --git a/src/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs b/src/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs
index 01f7f08a..39f01b1c 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs
@@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.Shader.Translation
Unused = 0,
Constant = 1,
Perspective = 2,
- ScreenLinear = 3
+ ScreenLinear = 3,
}
readonly struct ImapPixelType
@@ -29,9 +29,19 @@ namespace Ryujinx.Graphics.Shader.Translation
public PixelImap GetFirstUsedType()
{
- if (X != PixelImap.Unused) return X;
- if (Y != PixelImap.Unused) return Y;
- if (Z != PixelImap.Unused) return Z;
+ if (X != PixelImap.Unused)
+ {
+ return X;
+ }
+ if (Y != PixelImap.Unused)
+ {
+ return Y;
+ }
+ if (Z != PixelImap.Unused)
+ {
+ return Z;
+ }
+
return W;
}
}
@@ -155,4 +165,4 @@ namespace Ryujinx.Graphics.Shader.Translation
OmapDepth = type2Omap.Extract(1);
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/ShaderIdentifier.cs b/src/Ryujinx.Graphics.Shader/Translation/ShaderIdentifier.cs
index 68400437..e9c25994 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/ShaderIdentifier.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/ShaderIdentifier.cs
@@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.Shader.Translation
foreach (INode node in block.Operations)
{
- if (!(node is Operation operation))
+ if (node is not Operation operation)
{
continue;
}
@@ -84,7 +84,7 @@ namespace Ryujinx.Graphics.Shader.Translation
}
writesLayer = true;
- layerInputAttr = srcAttributeAsgOp.GetSource(1).Value * 4 + srcAttributeAsgOp.GetSource(3).Value;;
+ layerInputAttr = srcAttributeAsgOp.GetSource(1).Value * 4 + srcAttributeAsgOp.GetSource(3).Value;
}
else
{
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Ssa.cs b/src/Ryujinx.Graphics.Shader/Translation/Ssa.cs
index 16b8b924..89aaa3b4 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/Ssa.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/Ssa.cs
@@ -1,7 +1,6 @@
using Ryujinx.Graphics.Shader.Decoders;
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using System.Collections.Generic;
-
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
namespace Ryujinx.Graphics.Shader.Translation
@@ -12,9 +11,9 @@ namespace Ryujinx.Graphics.Shader.Translation
private class DefMap
{
- private Dictionary<Register, Operand> _map;
+ private readonly Dictionary<Register, Operand> _map;
- private long[] _phiMasks;
+ private readonly long[] _phiMasks;
public DefMap()
{
@@ -38,7 +37,7 @@ namespace Ryujinx.Graphics.Shader.Translation
int key = GetKeyFromRegister(reg);
int index = key / 64;
- int bit = key & 63;
+ int bit = key & 63;
long mask = 1L << bit;
@@ -57,7 +56,7 @@ namespace Ryujinx.Graphics.Shader.Translation
int key = GetKeyFromRegister(reg);
int index = key / 64;
- int bit = key & 63;
+ int bit = key & 63;
return (_phiMasks[index] & (1L << bit)) != 0;
}
@@ -65,8 +64,8 @@ namespace Ryujinx.Graphics.Shader.Translation
private class LocalDefMap
{
- private Operand[] _map;
- private int[] _uses;
+ private readonly Operand[] _map;
+ private readonly int[] _uses;
public int UseCount { get; private set; }
public LocalDefMap()
@@ -111,7 +110,7 @@ namespace Ryujinx.Graphics.Shader.Translation
private readonly struct Definition
{
public BasicBlock Block { get; }
- public Operand Local { get; }
+ public Operand Local { get; }
public Definition(BasicBlock block, Operand local)
{
@@ -123,14 +122,14 @@ namespace Ryujinx.Graphics.Shader.Translation
public static void Rename(BasicBlock[] blocks)
{
DefMap[] globalDefs = new DefMap[blocks.Length];
- LocalDefMap localDefs = new LocalDefMap();
+ LocalDefMap localDefs = new();
for (int blkIndex = 0; blkIndex < blocks.Length; blkIndex++)
{
globalDefs[blkIndex] = new DefMap();
}
- Queue<BasicBlock> dfPhiBlocks = new Queue<BasicBlock>();
+ Queue<BasicBlock> dfPhiBlocks = new();
// First pass, get all defs and locals uses.
for (int blkIndex = 0; blkIndex < blocks.Length; blkIndex++)
@@ -303,7 +302,7 @@ namespace Ryujinx.Graphics.Shader.Translation
// then use the definition from that Phi.
Operand local = Local();
- PhiNode phi = new PhiNode(local);
+ PhiNode phi = new(local);
AddPhi(block, phi);
@@ -373,4 +372,4 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/TargetApi.cs b/src/Ryujinx.Graphics.Shader/Translation/TargetApi.cs
index 6ac235a4..51960093 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/TargetApi.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/TargetApi.cs
@@ -3,6 +3,6 @@ namespace Ryujinx.Graphics.Shader.Translation
public enum TargetApi
{
OpenGL,
- Vulkan
+ Vulkan,
}
}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs b/src/Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs
index 8314b223..863c7447 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs
@@ -4,6 +4,6 @@ namespace Ryujinx.Graphics.Shader.Translation
{
Glsl,
Spirv,
- Arb
+ Arb,
}
}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/TranslationFlags.cs b/src/Ryujinx.Graphics.Shader/Translation/TranslationFlags.cs
index 1874dec3..df1e76a1 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/TranslationFlags.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/TranslationFlags.cs
@@ -7,8 +7,8 @@ namespace Ryujinx.Graphics.Shader.Translation
{
None = 0,
- VertexA = 1 << 0,
- Compute = 1 << 1,
- DebugMode = 1 << 2
+ VertexA = 1 << 0,
+ Compute = 1 << 1,
+ DebugMode = 1 << 2,
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/Translator.cs b/src/Ryujinx.Graphics.Shader/Translation/Translator.cs
index 255030a4..010c80db 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/Translator.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/Translator.cs
@@ -45,14 +45,14 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
- List<Function> funcs = new List<Function>(functions.Length);
+ List<Function> funcs = new(functions.Length);
for (int i = 0; i < functions.Length; i++)
{
funcs.Add(null);
}
- HelperFunctionManager hfm = new HelperFunctionManager(funcs, config.Stage);
+ HelperFunctionManager hfm = new(funcs, config.Stage);
for (int i = 0; i < functions.Length; i++)
{
@@ -65,7 +65,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
var fru = frus[i];
- inArgumentsCount = fru.InArguments.Length;
+ inArgumentsCount = fru.InArguments.Length;
outArgumentsCount = fru.OutArguments.Length;
}
@@ -95,7 +95,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
TargetLanguage.Glsl => new ShaderProgram(info, TargetLanguage.Glsl, GlslGenerator.Generate(sInfo, config)),
TargetLanguage.Spirv => new ShaderProgram(info, TargetLanguage.Spirv, SpirvGenerator.Generate(sInfo, config)),
- _ => throw new NotImplementedException(config.Options.TargetLanguage.ToString())
+ _ => throw new NotImplementedException(config.Options.TargetLanguage.ToString()),
};
}
@@ -149,7 +149,7 @@ namespace Ryujinx.Graphics.Shader.Translation
for (int index = 0; index < functions.Length; index++)
{
- EmitterContext context = new EmitterContext(program, config, index != 0);
+ EmitterContext context = new(program, config, index != 0);
if (initializeOutputs && index == 0)
{
@@ -306,7 +306,7 @@ namespace Ryujinx.Graphics.Shader.Translation
context.Add(new CommentNode(dbgComment));
}
- InstConditional opConditional = new InstConditional(op.RawOpCode);
+ InstConditional opConditional = new(op.RawOpCode);
bool noPred = op.Props.HasFlag(InstProps.NoPred);
if (!noPred && opConditional.Pred == RegisterConsts.PredicateTrueIndex && opConditional.PredInv)
@@ -367,4 +367,4 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs b/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
index 13c5e0e4..40a79c54 100644
--- a/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
+++ b/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
@@ -7,7 +7,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
-
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
using static Ryujinx.Graphics.Shader.Translation.Translator;
@@ -16,7 +15,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public class TranslatorContext
{
private readonly DecodedProgram _program;
- private ShaderConfig _config;
+ private readonly ShaderConfig _config;
public ulong Address { get; }
@@ -59,7 +58,7 @@ namespace Ryujinx.Graphics.Shader.Translation
// temporary variable, as long that attribute is written by shader A.
FunctionCode[] output = new FunctionCode[a.Length + b.Length - 1];
- List<Operation> ops = new List<Operation>(a.Length + b.Length);
+ List<Operation> ops = new(a.Length + b.Length);
Operand[] temps = new Operand[AttributeConsts.UserAttributesCount * 4];
@@ -205,9 +204,9 @@ namespace Ryujinx.Graphics.Shader.Translation
break;
}
- ShaderConfig config = new ShaderConfig(ShaderStage.Geometry, outputTopology, maxOutputVertices, GpuAccessor, _config.Options);
+ ShaderConfig config = new(ShaderStage.Geometry, outputTopology, maxOutputVertices, GpuAccessor, _config.Options);
- EmitterContext context = new EmitterContext(default, config, false);
+ EmitterContext context = new(default, config, false);
for (int v = 0; v < maxOutputVertices; v++)
{
@@ -263,7 +262,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
TargetLanguage.Glsl => new ShaderProgram(info, TargetLanguage.Glsl, GlslGenerator.Generate(sInfo, config)),
TargetLanguage.Spirv => new ShaderProgram(info, TargetLanguage.Spirv, SpirvGenerator.Generate(sInfo, config)),
- _ => throw new NotImplementedException(config.Options.TargetLanguage.ToString())
+ _ => throw new NotImplementedException(config.Options.TargetLanguage.ToString()),
};
}
}