SamplerType.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Ryujinx.Graphics.Shader.Translation;
  2. using System;
  3. namespace Ryujinx.Graphics.Shader
  4. {
  5. [Flags]
  6. public enum SamplerType
  7. {
  8. None = 0,
  9. Texture1D,
  10. TextureBuffer,
  11. Texture2D,
  12. Texture3D,
  13. TextureCube,
  14. Mask = 0xff,
  15. Array = 1 << 8,
  16. Indexed = 1 << 9,
  17. Multisample = 1 << 10,
  18. Shadow = 1 << 11
  19. }
  20. static class SamplerTypeExtensions
  21. {
  22. public static int GetDimensions(this SamplerType type)
  23. {
  24. return (type & SamplerType.Mask) switch
  25. {
  26. SamplerType.Texture1D => 1,
  27. SamplerType.TextureBuffer => 1,
  28. SamplerType.Texture2D => 2,
  29. SamplerType.Texture3D => 3,
  30. SamplerType.TextureCube => 3,
  31. _ => throw new ArgumentException($"Invalid sampler type \"{type}\".")
  32. };
  33. }
  34. public static string ToGlslSamplerType(this SamplerType type)
  35. {
  36. string typeName = (type & SamplerType.Mask) switch
  37. {
  38. SamplerType.Texture1D => "sampler1D",
  39. SamplerType.TextureBuffer => "samplerBuffer",
  40. SamplerType.Texture2D => "sampler2D",
  41. SamplerType.Texture3D => "sampler3D",
  42. SamplerType.TextureCube => "samplerCube",
  43. _ => throw new ArgumentException($"Invalid sampler type \"{type}\".")
  44. };
  45. if ((type & SamplerType.Multisample) != 0)
  46. {
  47. typeName += "MS";
  48. }
  49. if ((type & SamplerType.Array) != 0)
  50. {
  51. typeName += "Array";
  52. }
  53. if ((type & SamplerType.Shadow) != 0)
  54. {
  55. typeName += "Shadow";
  56. }
  57. return typeName;
  58. }
  59. public static string ToGlslImageType(this SamplerType type, AggregateType componentType)
  60. {
  61. string typeName = (type & SamplerType.Mask) switch
  62. {
  63. SamplerType.Texture1D => "image1D",
  64. SamplerType.TextureBuffer => "imageBuffer",
  65. SamplerType.Texture2D => "image2D",
  66. SamplerType.Texture3D => "image3D",
  67. SamplerType.TextureCube => "imageCube",
  68. _ => throw new ArgumentException($"Invalid sampler type \"{type}\".")
  69. };
  70. if ((type & SamplerType.Multisample) != 0)
  71. {
  72. typeName += "MS";
  73. }
  74. if ((type & SamplerType.Array) != 0)
  75. {
  76. typeName += "Array";
  77. }
  78. switch (componentType)
  79. {
  80. case AggregateType.U32: typeName = 'u' + typeName; break;
  81. case AggregateType.S32: typeName = 'i' + typeName; break;
  82. }
  83. return typeName;
  84. }
  85. }
  86. }