AggregateType.cs
1 using System; 2 using System.Diagnostics.CodeAnalysis; 3 4 namespace Ryujinx.Graphics.Shader.Translation 5 { 6 [Flags] 7 [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")] 8 enum AggregateType 9 { 10 Invalid, 11 Void, 12 Bool, 13 FP32, 14 FP64, 15 S32, 16 U32, 17 18 ElementTypeMask = 0xff, 19 20 ElementCountShift = 8, 21 ElementCountMask = 3 << ElementCountShift, 22 23 Scalar = 0 << ElementCountShift, 24 Vector2 = 1 << ElementCountShift, 25 Vector3 = 2 << ElementCountShift, 26 Vector4 = 3 << ElementCountShift, 27 28 Array = 1 << 10, 29 } 30 31 static class AggregateTypeExtensions 32 { 33 public static int GetSizeInBytes(this AggregateType type) 34 { 35 int elementSize = (type & AggregateType.ElementTypeMask) switch 36 { 37 AggregateType.Bool or 38 AggregateType.FP32 or 39 AggregateType.S32 or 40 AggregateType.U32 => 4, 41 AggregateType.FP64 => 8, 42 _ => 0, 43 }; 44 45 switch (type & AggregateType.ElementCountMask) 46 { 47 case AggregateType.Vector2: 48 elementSize *= 2; 49 break; 50 case AggregateType.Vector3: 51 elementSize *= 3; 52 break; 53 case AggregateType.Vector4: 54 elementSize *= 4; 55 break; 56 } 57 58 return elementSize; 59 } 60 } 61 }