AttributeType.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Ryujinx.Graphics.Shader.Translation;
  2. using System;
  3. namespace Ryujinx.Graphics.Shader
  4. {
  5. public enum AttributeType : byte
  6. {
  7. // Generic types.
  8. Float,
  9. Sint,
  10. Uint,
  11. Sscaled,
  12. Uscaled,
  13. Packed = 1 << 6,
  14. PackedRgb10A2Signed = 1 << 7,
  15. AnyPacked = Packed | PackedRgb10A2Signed,
  16. }
  17. static class AttributeTypeExtensions
  18. {
  19. public static AggregateType ToAggregateType(this AttributeType type)
  20. {
  21. return (type & ~AttributeType.AnyPacked) switch
  22. {
  23. AttributeType.Float => AggregateType.FP32,
  24. AttributeType.Sint => AggregateType.S32,
  25. AttributeType.Uint => AggregateType.U32,
  26. _ => throw new ArgumentException($"Invalid attribute type \"{type}\"."),
  27. };
  28. }
  29. public static AggregateType ToAggregateType(this AttributeType type, bool supportsScaledFormats)
  30. {
  31. return (type & ~AttributeType.AnyPacked) switch
  32. {
  33. AttributeType.Float => AggregateType.FP32,
  34. AttributeType.Sint => AggregateType.S32,
  35. AttributeType.Uint => AggregateType.U32,
  36. AttributeType.Sscaled => supportsScaledFormats ? AggregateType.FP32 : AggregateType.S32,
  37. AttributeType.Uscaled => supportsScaledFormats ? AggregateType.FP32 : AggregateType.U32,
  38. _ => throw new ArgumentException($"Invalid attribute type \"{type}\"."),
  39. };
  40. }
  41. }
  42. }