0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-23 23:15:47 +00:00
Ryujinx/Ryujinx.Graphics/Shader/IntermediateRepresentation/Operation.cs
Alex Barney b2b736abc2 Misc cleanup (#708)
* Fix typos

* Remove unneeded using statements

* Enforce var style more

* Remove redundant qualifiers

* Fix some indentation

* Disable naming warnings on files with external enum names

* Fix build

* Mass find & replace for comments with no spacing

* Standardize todo capitalization and for/if spacing
2019-07-02 04:39:22 +02:00

101 lines
No EOL
2.5 KiB
C#

namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
{
class Operation : INode
{
public Instruction Inst { get; private set; }
private Operand _dest;
public Operand Dest
{
get => _dest;
set => _dest = AssignDest(value);
}
private Operand[] _sources;
public int SourcesCount => _sources.Length;
public int ComponentIndex { get; }
public Operation(Instruction inst, Operand dest, params Operand[] sources)
{
Inst = inst;
Dest = dest;
// The array may be modified externally, so we store a copy.
_sources = (Operand[])sources.Clone();
for (int index = 0; index < _sources.Length; index++)
{
Operand source = _sources[index];
if (source.Type == OperandType.LocalVariable)
{
source.UseOps.Add(this);
}
}
}
public Operation(
Instruction inst,
int compIndex,
Operand dest,
params Operand[] sources) : this(inst, dest, sources)
{
ComponentIndex = compIndex;
}
private Operand AssignDest(Operand dest)
{
if (dest != null && dest.Type == OperandType.LocalVariable)
{
dest.AsgOp = this;
}
return dest;
}
public Operand GetSource(int index)
{
return _sources[index];
}
public void SetSource(int index, Operand source)
{
Operand oldSrc = _sources[index];
if (oldSrc != null && oldSrc.Type == OperandType.LocalVariable)
{
oldSrc.UseOps.Remove(this);
}
if (source.Type == OperandType.LocalVariable)
{
source.UseOps.Add(this);
}
_sources[index] = source;
}
public void TurnIntoCopy(Operand source)
{
Inst = Instruction.Copy;
foreach (Operand oldSrc in _sources)
{
if (oldSrc.Type == OperandType.LocalVariable)
{
oldSrc.UseOps.Remove(this);
}
}
if (source.Type == OperandType.LocalVariable)
{
source.UseOps.Add(this);
}
_sources = new Operand[] { source };
}
}
}