Operand.cs
 1  using Ryujinx.Graphics.Shader.Decoders;
 2  using System;
 3  using System.Collections.Generic;
 4  
 5  namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
 6  {
 7      class Operand
 8      {
 9          private const int CbufSlotBits = 5;
10          private const int CbufSlotLsb = 32 - CbufSlotBits;
11          private const int CbufSlotMask = (1 << CbufSlotBits) - 1;
12  
13          public OperandType Type { get; }
14  
15          public int Value { get; }
16  
17          public INode AsgOp { get; set; }
18  
19          public HashSet<INode> UseOps { get; }
20  
21          private Operand()
22          {
23              UseOps = new HashSet<INode>();
24          }
25  
26          public Operand(OperandType type) : this()
27          {
28              Type = type;
29          }
30  
31          public Operand(OperandType type, int value) : this()
32          {
33              Type = type;
34              Value = value;
35          }
36  
37          public Operand(Register reg) : this()
38          {
39              Type = OperandType.Register;
40              Value = PackRegInfo(reg.Index, reg.Type);
41          }
42  
43          public Operand(int slot, int offset) : this()
44          {
45              Type = OperandType.ConstantBuffer;
46              Value = PackCbufInfo(slot, offset);
47          }
48  
49          private static int PackCbufInfo(int slot, int offset)
50          {
51              return (slot << CbufSlotLsb) | offset;
52          }
53  
54          private static int PackRegInfo(int index, RegisterType type)
55          {
56              return ((int)type << 24) | index;
57          }
58  
59          public int GetCbufSlot()
60          {
61              return (Value >> CbufSlotLsb) & CbufSlotMask;
62          }
63  
64          public int GetCbufOffset()
65          {
66              return Value & ~(CbufSlotMask << CbufSlotLsb);
67          }
68  
69          public Register GetRegister()
70          {
71              return new Register(Value & 0xffffff, (RegisterType)(Value >> 24));
72          }
73  
74          public float AsFloat()
75          {
76              return BitConverter.Int32BitsToSingle(Value);
77          }
78      }
79  }