FormatTable.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using Ryujinx.Graphics.GAL;
  2. using System.Collections.Generic;
  3. namespace Ryujinx.Graphics.Gpu.Image
  4. {
  5. /// <summary>
  6. /// Contains format tables, for texture and vertex attribute formats.
  7. /// </summary>
  8. static class FormatTable
  9. {
  10. private static Dictionary<uint, FormatInfo> _textureFormats = new Dictionary<uint, FormatInfo>()
  11. {
  12. { 0x2491d, new FormatInfo(Format.R8Unorm, 1, 1, 1, 1) },
  13. { 0x1249d, new FormatInfo(Format.R8Snorm, 1, 1, 1, 1) },
  14. { 0x4921d, new FormatInfo(Format.R8Uint, 1, 1, 1, 1) },
  15. { 0x36d9d, new FormatInfo(Format.R8Sint, 1, 1, 1, 1) },
  16. { 0x7ff9b, new FormatInfo(Format.R16Float, 1, 1, 2, 1) },
  17. { 0x2491b, new FormatInfo(Format.R16Unorm, 1, 1, 2, 1) },
  18. { 0x1249b, new FormatInfo(Format.R16Snorm, 1, 1, 2, 1) },
  19. { 0x4921b, new FormatInfo(Format.R16Uint, 1, 1, 2, 1) },
  20. { 0x36d9b, new FormatInfo(Format.R16Sint, 1, 1, 2, 1) },
  21. { 0x7ff8f, new FormatInfo(Format.R32Float, 1, 1, 4, 1) },
  22. { 0x4920f, new FormatInfo(Format.R32Uint, 1, 1, 4, 1) },
  23. { 0x36d8f, new FormatInfo(Format.R32Sint, 1, 1, 4, 1) },
  24. { 0x24918, new FormatInfo(Format.R8G8Unorm, 1, 1, 2, 2) },
  25. { 0x12498, new FormatInfo(Format.R8G8Snorm, 1, 1, 2, 2) },
  26. { 0x49218, new FormatInfo(Format.R8G8Uint, 1, 1, 2, 2) },
  27. { 0x36d98, new FormatInfo(Format.R8G8Sint, 1, 1, 2, 2) },
  28. { 0x7ff8c, new FormatInfo(Format.R16G16Float, 1, 1, 4, 2) },
  29. { 0x2490c, new FormatInfo(Format.R16G16Unorm, 1, 1, 4, 2) },
  30. { 0x1248c, new FormatInfo(Format.R16G16Snorm, 1, 1, 4, 2) },
  31. { 0x4920c, new FormatInfo(Format.R16G16Uint, 1, 1, 4, 2) },
  32. { 0x36d8c, new FormatInfo(Format.R16G16Sint, 1, 1, 4, 2) },
  33. { 0x7ff84, new FormatInfo(Format.R32G32Float, 1, 1, 8, 2) },
  34. { 0x49204, new FormatInfo(Format.R32G32Uint, 1, 1, 8, 2) },
  35. { 0x36d84, new FormatInfo(Format.R32G32Sint, 1, 1, 8, 2) },
  36. { 0x7ff82, new FormatInfo(Format.R32G32B32Float, 1, 1, 12, 3) },
  37. { 0x49202, new FormatInfo(Format.R32G32B32Uint, 1, 1, 12, 3) },
  38. { 0x36d82, new FormatInfo(Format.R32G32B32Sint, 1, 1, 12, 3) },
  39. { 0x24908, new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4, 4) },
  40. { 0x12488, new FormatInfo(Format.R8G8B8A8Snorm, 1, 1, 4, 4) },
  41. { 0x49208, new FormatInfo(Format.R8G8B8A8Uint, 1, 1, 4, 4) },
  42. { 0x36d88, new FormatInfo(Format.R8G8B8A8Sint, 1, 1, 4, 4) },
  43. { 0x7ff83, new FormatInfo(Format.R16G16B16A16Float, 1, 1, 8, 4) },
  44. { 0x24903, new FormatInfo(Format.R16G16B16A16Unorm, 1, 1, 8, 4) },
  45. { 0x12483, new FormatInfo(Format.R16G16B16A16Snorm, 1, 1, 8, 4) },
  46. { 0x49203, new FormatInfo(Format.R16G16B16A16Uint, 1, 1, 8, 4) },
  47. { 0x36d83, new FormatInfo(Format.R16G16B16A16Sint, 1, 1, 8, 4) },
  48. { 0x7ff81, new FormatInfo(Format.R32G32B32A32Float, 1, 1, 16, 4) },
  49. { 0x49201, new FormatInfo(Format.R32G32B32A32Uint, 1, 1, 16, 4) },
  50. { 0x36d81, new FormatInfo(Format.R32G32B32A32Sint, 1, 1, 16, 4) },
  51. { 0x2493a, new FormatInfo(Format.D16Unorm, 1, 1, 2, 1) },
  52. { 0x7ffaf, new FormatInfo(Format.D32Float, 1, 1, 4, 1) },
  53. { 0x24a0e, new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4, 2) },
  54. { 0x24a29, new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4, 2) },
  55. { 0x48a29, new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4, 2) },
  56. { 0x25385, new FormatInfo(Format.D32FloatS8Uint, 1, 1, 8, 2) },
  57. { 0x253b0, new FormatInfo(Format.D32FloatS8Uint, 1, 1, 8, 2) },
  58. { 0xa4908, new FormatInfo(Format.R8G8B8A8Srgb, 1, 1, 4, 4) },
  59. { 0x24912, new FormatInfo(Format.R4G4B4A4Unorm, 1, 1, 2, 4) },
  60. { 0x24914, new FormatInfo(Format.R5G5B5A1Unorm, 1, 1, 2, 4) },
  61. { 0x24915, new FormatInfo(Format.R5G6B5Unorm, 1, 1, 2, 3) },
  62. { 0x24909, new FormatInfo(Format.R10G10B10A2Unorm, 1, 1, 4, 4) },
  63. { 0x49209, new FormatInfo(Format.R10G10B10A2Uint, 1, 1, 4, 4) },
  64. { 0x7ffa1, new FormatInfo(Format.R11G11B10Float, 1, 1, 4, 3) },
  65. { 0x7ffa0, new FormatInfo(Format.R9G9B9E5Float, 1, 1, 4, 4) },
  66. { 0x24924, new FormatInfo(Format.Bc1RgbaUnorm, 4, 4, 8, 4) },
  67. { 0x24925, new FormatInfo(Format.Bc2Unorm, 4, 4, 16, 4) },
  68. { 0x24926, new FormatInfo(Format.Bc3Unorm, 4, 4, 16, 4) },
  69. { 0xa4924, new FormatInfo(Format.Bc1RgbaSrgb, 4, 4, 8, 4) },
  70. { 0xa4925, new FormatInfo(Format.Bc2Srgb, 4, 4, 16, 4) },
  71. { 0xa4926, new FormatInfo(Format.Bc3Srgb, 4, 4, 16, 4) },
  72. { 0x24927, new FormatInfo(Format.Bc4Unorm, 4, 4, 8, 1) },
  73. { 0x124a7, new FormatInfo(Format.Bc4Snorm, 4, 4, 8, 1) },
  74. { 0x24928, new FormatInfo(Format.Bc5Unorm, 4, 4, 16, 2) },
  75. { 0x124a8, new FormatInfo(Format.Bc5Snorm, 4, 4, 16, 2) },
  76. { 0x24917, new FormatInfo(Format.Bc7Unorm, 4, 4, 16, 4) },
  77. { 0xa4917, new FormatInfo(Format.Bc7Srgb, 4, 4, 16, 4) },
  78. { 0x7ff90, new FormatInfo(Format.Bc6HSfloat, 4, 4, 16, 4) },
  79. { 0x7ff91, new FormatInfo(Format.Bc6HUfloat, 4, 4, 16, 4) },
  80. { 0x2490b, new FormatInfo(Format.Etc2RgbaUnorm, 4, 4, 16, 4) },
  81. { 0xa490b, new FormatInfo(Format.Etc2RgbaSrgb, 4, 4, 16, 4) },
  82. { 0x24940, new FormatInfo(Format.Astc4x4Unorm, 4, 4, 16, 4) },
  83. { 0x24950, new FormatInfo(Format.Astc5x4Unorm, 5, 4, 16, 4) },
  84. { 0x24941, new FormatInfo(Format.Astc5x5Unorm, 5, 5, 16, 4) },
  85. { 0x24951, new FormatInfo(Format.Astc6x5Unorm, 6, 5, 16, 4) },
  86. { 0x24942, new FormatInfo(Format.Astc6x6Unorm, 6, 6, 16, 4) },
  87. { 0x24955, new FormatInfo(Format.Astc8x5Unorm, 8, 5, 16, 4) },
  88. { 0x24952, new FormatInfo(Format.Astc8x6Unorm, 8, 6, 16, 4) },
  89. { 0x24944, new FormatInfo(Format.Astc8x8Unorm, 8, 8, 16, 4) },
  90. { 0x24956, new FormatInfo(Format.Astc10x5Unorm, 10, 5, 16, 4) },
  91. { 0x24957, new FormatInfo(Format.Astc10x6Unorm, 10, 6, 16, 4) },
  92. { 0x24953, new FormatInfo(Format.Astc10x8Unorm, 10, 8, 16, 4) },
  93. { 0x24945, new FormatInfo(Format.Astc10x10Unorm, 10, 10, 16, 4) },
  94. { 0x24954, new FormatInfo(Format.Astc12x10Unorm, 12, 10, 16, 4) },
  95. { 0x24946, new FormatInfo(Format.Astc12x12Unorm, 12, 12, 16, 4) },
  96. { 0xa4940, new FormatInfo(Format.Astc4x4Srgb, 4, 4, 16, 4) },
  97. { 0xa4950, new FormatInfo(Format.Astc5x4Srgb, 5, 4, 16, 4) },
  98. { 0xa4941, new FormatInfo(Format.Astc5x5Srgb, 5, 5, 16, 4) },
  99. { 0xa4951, new FormatInfo(Format.Astc6x5Srgb, 6, 5, 16, 4) },
  100. { 0xa4942, new FormatInfo(Format.Astc6x6Srgb, 6, 6, 16, 4) },
  101. { 0xa4955, new FormatInfo(Format.Astc8x5Srgb, 8, 5, 16, 4) },
  102. { 0xa4952, new FormatInfo(Format.Astc8x6Srgb, 8, 6, 16, 4) },
  103. { 0xa4944, new FormatInfo(Format.Astc8x8Srgb, 8, 8, 16, 4) },
  104. { 0xa4956, new FormatInfo(Format.Astc10x5Srgb, 10, 5, 16, 4) },
  105. { 0xa4957, new FormatInfo(Format.Astc10x6Srgb, 10, 6, 16, 4) },
  106. { 0xa4953, new FormatInfo(Format.Astc10x8Srgb, 10, 8, 16, 4) },
  107. { 0xa4945, new FormatInfo(Format.Astc10x10Srgb, 10, 10, 16, 4) },
  108. { 0xa4954, new FormatInfo(Format.Astc12x10Srgb, 12, 10, 16, 4) },
  109. { 0xa4946, new FormatInfo(Format.Astc12x12Srgb, 12, 12, 16, 4) },
  110. { 0x24913, new FormatInfo(Format.A1B5G5R5Unorm, 1, 1, 2, 4) }
  111. };
  112. private static Dictionary<ulong, Format> _attribFormats = new Dictionary<ulong, Format>()
  113. {
  114. { 0x13a00000, Format.R8Unorm },
  115. { 0x0ba00000, Format.R8Snorm },
  116. { 0x23a00000, Format.R8Uint },
  117. { 0x1ba00000, Format.R8Sint },
  118. { 0x3b600000, Format.R16Float },
  119. { 0x13600000, Format.R16Unorm },
  120. { 0x0b600000, Format.R16Snorm },
  121. { 0x23600000, Format.R16Uint },
  122. { 0x1b600000, Format.R16Sint },
  123. { 0x3a400000, Format.R32Float },
  124. { 0x22400000, Format.R32Uint },
  125. { 0x1a400000, Format.R32Sint },
  126. { 0x13000000, Format.R8G8Unorm },
  127. { 0x0b000000, Format.R8G8Snorm },
  128. { 0x23000000, Format.R8G8Uint },
  129. { 0x1b000000, Format.R8G8Sint },
  130. { 0x39e00000, Format.R16G16Float },
  131. { 0x11e00000, Format.R16G16Unorm },
  132. { 0x09e00000, Format.R16G16Snorm },
  133. { 0x21e00000, Format.R16G16Uint },
  134. { 0x19e00000, Format.R16G16Sint },
  135. { 0x38800000, Format.R32G32Float },
  136. { 0x20800000, Format.R32G32Uint },
  137. { 0x18800000, Format.R32G32Sint },
  138. { 0x12600000, Format.R8G8B8Unorm },
  139. { 0x0a600000, Format.R8G8B8Snorm },
  140. { 0x22600000, Format.R8G8B8Uint },
  141. { 0x1a600000, Format.R8G8B8Sint },
  142. { 0x38a00000, Format.R16G16B16Float },
  143. { 0x10a00000, Format.R16G16B16Unorm },
  144. { 0x08a00000, Format.R16G16B16Snorm },
  145. { 0x20a00000, Format.R16G16B16Uint },
  146. { 0x18a00000, Format.R16G16B16Sint },
  147. { 0x38400000, Format.R32G32B32Float },
  148. { 0x20400000, Format.R32G32B32Uint },
  149. { 0x18400000, Format.R32G32B32Sint },
  150. { 0x11400000, Format.R8G8B8A8Unorm },
  151. { 0x09400000, Format.R8G8B8A8Snorm },
  152. { 0x21400000, Format.R8G8B8A8Uint },
  153. { 0x19400000, Format.R8G8B8A8Sint },
  154. { 0x38600000, Format.R16G16B16A16Float },
  155. { 0x10600000, Format.R16G16B16A16Unorm },
  156. { 0x08600000, Format.R16G16B16A16Snorm },
  157. { 0x20600000, Format.R16G16B16A16Uint },
  158. { 0x18600000, Format.R16G16B16A16Sint },
  159. { 0x38200000, Format.R32G32B32A32Float },
  160. { 0x20200000, Format.R32G32B32A32Uint },
  161. { 0x18200000, Format.R32G32B32A32Sint },
  162. { 0x16000000, Format.R10G10B10A2Unorm },
  163. { 0x26000000, Format.R10G10B10A2Uint },
  164. { 0x3e200000, Format.R11G11B10Float },
  165. { 0x2ba00000, Format.R8Uscaled },
  166. { 0x33a00000, Format.R8Sscaled },
  167. { 0x2b600000, Format.R16Uscaled },
  168. { 0x33600000, Format.R16Sscaled },
  169. { 0x2a400000, Format.R32Uscaled },
  170. { 0x32400000, Format.R32Sscaled },
  171. { 0x2b000000, Format.R8G8Uscaled },
  172. { 0x33000000, Format.R8G8Sscaled },
  173. { 0x29e00000, Format.R16G16Uscaled },
  174. { 0x31e00000, Format.R16G16Sscaled },
  175. { 0x28800000, Format.R32G32Uscaled },
  176. { 0x30800000, Format.R32G32Sscaled },
  177. { 0x2a600000, Format.R8G8B8Uscaled },
  178. { 0x32600000, Format.R8G8B8Sscaled },
  179. { 0x28a00000, Format.R16G16B16Uscaled },
  180. { 0x30a00000, Format.R16G16B16Sscaled },
  181. { 0x28400000, Format.R32G32B32Uscaled },
  182. { 0x30400000, Format.R32G32B32Sscaled },
  183. { 0x29400000, Format.R8G8B8A8Uscaled },
  184. { 0x31400000, Format.R8G8B8A8Sscaled },
  185. { 0x28600000, Format.R16G16B16A16Uscaled },
  186. { 0x30600000, Format.R16G16B16A16Sscaled },
  187. { 0x28200000, Format.R32G32B32A32Uscaled },
  188. { 0x30200000, Format.R32G32B32A32Sscaled },
  189. { 0x0e000000, Format.R10G10B10A2Snorm },
  190. { 0x1e000000, Format.R10G10B10A2Sint },
  191. { 0x2e000000, Format.R10G10B10A2Uscaled },
  192. { 0x36000000, Format.R10G10B10A2Sscaled }
  193. };
  194. /// <summary>
  195. /// Try getting the texture format from an encoded format integer from the Maxwell texture descriptor.
  196. /// </summary>
  197. /// <param name="encoded">The encoded format integer from the texture descriptor</param>
  198. /// <param name="isSrgb">Indicates if the format is a sRGB format</param>
  199. /// <param name="format">The output texture format</param>
  200. /// <returns>True if the format is valid, false otherwise</returns>
  201. public static bool TryGetTextureFormat(uint encoded, bool isSrgb, out FormatInfo format)
  202. {
  203. encoded |= (isSrgb ? 1u << 19 : 0u);
  204. return _textureFormats.TryGetValue(encoded, out format);
  205. }
  206. /// <summary>
  207. /// Try getting the vertex attribute format from an encoded format integer from Maxwell attribute registers.
  208. /// </summary>
  209. /// <param name="encoded">The encoded format integer from the attribute registers</param>
  210. /// <param name="format">The output vertex attribute format</param>
  211. /// <returns>True if the format is valid, false otherwise</returns>
  212. public static bool TryGetAttribFormat(uint encoded, out Format format)
  213. {
  214. return _attribFormats.TryGetValue(encoded, out format);
  215. }
  216. }
  217. }