Instruction.cs
1 using System; 2 3 namespace Ryujinx.Graphics.Shader.IntermediateRepresentation 4 { 5 [Flags] 6 enum Instruction 7 { 8 Absolute = 1, 9 Add, 10 AtomicAdd, 11 AtomicAnd, 12 AtomicCompareAndSwap, 13 AtomicMinS32, 14 AtomicMinU32, 15 AtomicMaxS32, 16 AtomicMaxU32, 17 AtomicOr, 18 AtomicSwap, 19 AtomicXor, 20 Ballot, 21 Barrier, 22 BitCount, 23 BitfieldExtractS32, 24 BitfieldExtractU32, 25 BitfieldInsert, 26 BitfieldReverse, 27 BitwiseAnd, 28 BitwiseExclusiveOr, 29 BitwiseNot, 30 BitwiseOr, 31 Branch, 32 BranchIfFalse, 33 BranchIfTrue, 34 Call, 35 Ceiling, 36 Clamp, 37 ClampU32, 38 Comment, 39 CompareEqual, 40 CompareGreater, 41 CompareGreaterOrEqual, 42 CompareGreaterOrEqualU32, 43 CompareGreaterU32, 44 CompareLess, 45 CompareLessOrEqual, 46 CompareLessOrEqualU32, 47 CompareLessU32, 48 CompareNotEqual, 49 ConditionalSelect, 50 ConvertFP32ToFP64, 51 ConvertFP64ToFP32, 52 ConvertFP32ToS32, 53 ConvertFP32ToU32, 54 ConvertFP64ToS32, 55 ConvertFP64ToU32, 56 ConvertS32ToFP32, 57 ConvertS32ToFP64, 58 ConvertU32ToFP32, 59 ConvertU32ToFP64, 60 Copy, 61 Cosine, 62 Ddx, 63 Ddy, 64 Discard, 65 Divide, 66 EmitVertex, 67 EndPrimitive, 68 ExponentB2, 69 FSIBegin, 70 FSIEnd, 71 FindLSB, 72 FindMSBS32, 73 FindMSBU32, 74 Floor, 75 FusedMultiplyAdd, 76 GroupMemoryBarrier, 77 ImageLoad, 78 ImageStore, 79 ImageAtomic, 80 IsNan, 81 Load, 82 Lod, 83 LogarithmB2, 84 LogicalAnd, 85 LogicalExclusiveOr, 86 LogicalNot, 87 LogicalOr, 88 LoopBreak, 89 LoopContinue, 90 MarkLabel, 91 Maximum, 92 MaximumU32, 93 MemoryBarrier, 94 Minimum, 95 MinimumU32, 96 Modulo, 97 Multiply, 98 MultiplyHighS32, 99 MultiplyHighU32, 100 Negate, 101 PackDouble2x32, 102 PackHalf2x16, 103 ReciprocalSquareRoot, 104 Return, 105 Round, 106 ShiftLeft, 107 ShiftRightS32, 108 ShiftRightU32, 109 Shuffle, 110 ShuffleDown, 111 ShuffleUp, 112 ShuffleXor, 113 Sine, 114 SquareRoot, 115 Store, 116 Subtract, 117 SwizzleAdd, 118 TextureSample, 119 TextureQuerySamples, 120 TextureQuerySize, 121 Truncate, 122 UnpackDouble2x32, 123 UnpackHalf2x16, 124 VectorExtract, 125 VoteAll, 126 VoteAllEqual, 127 VoteAny, 128 129 Count, 130 131 FP32 = 1 << 16, 132 FP64 = 1 << 17, 133 134 Mask = 0xffff, 135 } 136 137 static class InstructionExtensions 138 { 139 public static bool IsAtomic(this Instruction inst) 140 { 141 switch (inst & Instruction.Mask) 142 { 143 case Instruction.AtomicAdd: 144 case Instruction.AtomicAnd: 145 case Instruction.AtomicCompareAndSwap: 146 case Instruction.AtomicMaxS32: 147 case Instruction.AtomicMaxU32: 148 case Instruction.AtomicMinS32: 149 case Instruction.AtomicMinU32: 150 case Instruction.AtomicOr: 151 case Instruction.AtomicSwap: 152 case Instruction.AtomicXor: 153 return true; 154 } 155 156 return false; 157 } 158 159 public static bool IsComparison(this Instruction inst) 160 { 161 switch (inst & Instruction.Mask) 162 { 163 case Instruction.CompareEqual: 164 case Instruction.CompareGreater: 165 case Instruction.CompareGreaterOrEqual: 166 case Instruction.CompareGreaterOrEqualU32: 167 case Instruction.CompareGreaterU32: 168 case Instruction.CompareLess: 169 case Instruction.CompareLessOrEqual: 170 case Instruction.CompareLessOrEqualU32: 171 case Instruction.CompareLessU32: 172 case Instruction.CompareNotEqual: 173 return true; 174 } 175 176 return false; 177 } 178 179 public static bool IsTextureQuery(this Instruction inst) 180 { 181 inst &= Instruction.Mask; 182 return inst == Instruction.Lod || inst == Instruction.TextureQuerySamples || inst == Instruction.TextureQuerySize; 183 } 184 185 public static bool IsImage(this Instruction inst) 186 { 187 inst &= Instruction.Mask; 188 return inst == Instruction.ImageAtomic || inst == Instruction.ImageLoad || inst == Instruction.ImageStore; 189 } 190 191 public static bool IsImageStore(this Instruction inst) 192 { 193 inst &= Instruction.Mask; 194 return inst == Instruction.ImageAtomic || inst == Instruction.ImageStore; 195 } 196 } 197 }