aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-10-13 03:02:07 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit1876b346fea647e8284a66bb6d62c38801035cff (patch)
tree6eeff094298cda84d1613dc5ec0691e51d7b35f1 /Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs
parentf617fb542a0e3d36012d77a4b5acbde7b08902f2 (diff)
Initial work
Diffstat (limited to 'Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs')
-rw-r--r--Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs b/Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs
new file mode 100644
index 00000000..567277a7
--- /dev/null
+++ b/Ryujinx.Graphics.Shader/IntermediateRepresentation/Operand.cs
@@ -0,0 +1,82 @@
+using Ryujinx.Graphics.Shader.Decoders;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
+{
+ class Operand
+ {
+ private const int CbufSlotBits = 5;
+ private const int CbufSlotLsb = 32 - CbufSlotBits;
+ private const int CbufSlotMask = (1 << CbufSlotBits) - 1;
+
+ public OperandType Type { get; }
+
+ public int Value { get; }
+
+ public InterpolationQualifier Interpolation { get; }
+
+ public INode AsgOp { get; set; }
+
+ public HashSet<INode> UseOps { get; }
+
+ private Operand()
+ {
+ UseOps = new HashSet<INode>();
+ }
+
+ public Operand(OperandType type) : this()
+ {
+ Type = type;
+ }
+
+ public Operand(OperandType type, int value, InterpolationQualifier iq = InterpolationQualifier.None) : this()
+ {
+ Type = type;
+ Value = value;
+ Interpolation = iq;
+ }
+
+ public Operand(Register reg) : this()
+ {
+ Type = OperandType.Register;
+ Value = PackRegInfo(reg.Index, reg.Type);
+ }
+
+ public Operand(int slot, int offset) : this()
+ {
+ Type = OperandType.ConstantBuffer;
+ Value = PackCbufInfo(slot, offset);
+ }
+
+ private static int PackCbufInfo(int slot, int offset)
+ {
+ return (slot << CbufSlotLsb) | offset;
+ }
+
+ private static int PackRegInfo(int index, RegisterType type)
+ {
+ return ((int)type << 24) | index;
+ }
+
+ public int GetCbufSlot()
+ {
+ return (Value >> CbufSlotLsb) & CbufSlotMask;
+ }
+
+ public int GetCbufOffset()
+ {
+ return Value & ~(CbufSlotMask << CbufSlotLsb);
+ }
+
+ public Register GetRegister()
+ {
+ return new Register(Value & 0xffffff, (RegisterType)(Value >> 24));
+ }
+
+ public float AsFloat()
+ {
+ return BitConverter.Int32BitsToSingle(Value);
+ }
+ }
+} \ No newline at end of file