FormatTable.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. using Ryujinx.Graphics.GAL;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. namespace Ryujinx.Graphics.Gpu.Image
  5. {
  6. /// <summary>
  7. /// Contains format tables, for texture and vertex attribute formats.
  8. /// </summary>
  9. static class FormatTable
  10. {
  11. #pragma warning disable IDE0055 // Disable formatting
  12. [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
  13. private enum TextureFormat : uint
  14. {
  15. // Formats
  16. R32G32B32A32 = 0x01,
  17. R32G32B32 = 0x02,
  18. R16G16B16A16 = 0x03,
  19. R32G32 = 0x04,
  20. R32B24G8 = 0x05,
  21. X8B8G8R8 = 0x07,
  22. A8B8G8R8 = 0x08,
  23. A2B10G10R10 = 0x09,
  24. R16G16 = 0x0c,
  25. G8R24 = 0x0d,
  26. G24R8 = 0x0e,
  27. R32 = 0x0f,
  28. A4B4G4R4 = 0x12,
  29. A5B5G5R1 = 0x13,
  30. A1B5G5R5 = 0x14,
  31. B5G6R5 = 0x15,
  32. B6G5R5 = 0x16,
  33. G8R8 = 0x18,
  34. R16 = 0x1b,
  35. Y8Video = 0x1c,
  36. R8 = 0x1d,
  37. G4R4 = 0x1e,
  38. R1 = 0x1f,
  39. E5B9G9R9SharedExp = 0x20,
  40. Bf10Gf11Rf11 = 0x21,
  41. G8B8G8R8 = 0x22,
  42. B8G8R8G8 = 0x23,
  43. Bc1 = 0x24,
  44. Bc2 = 0x25,
  45. Bc3 = 0x26,
  46. Bc4 = 0x27,
  47. Bc5 = 0x28,
  48. Bc6HSf16 = 0x10,
  49. Bc6HUf16 = 0x11,
  50. Bc7U = 0x17,
  51. Etc2Rgb = 0x06,
  52. Etc2RgbPta = 0x0a,
  53. Etc2Rgba = 0x0b,
  54. Eac = 0x19,
  55. Eacx2 = 0x1a,
  56. Z24S8 = 0x29,
  57. X8Z24 = 0x2a,
  58. S8Z24 = 0x2b,
  59. X4V4Z24Cov4R4V = 0x2c,
  60. X4V4Z24Cov8R8V = 0x2d,
  61. V8Z24Cov4R12V = 0x2e,
  62. Zf32 = 0x2f,
  63. Zf32X24S8 = 0x30,
  64. X8Z24X20V4S8Cov4R4V = 0x31,
  65. X8Z24X20V4S8Cov8R8V = 0x32,
  66. Zf32X20V4X8Cov4R4V = 0x33,
  67. Zf32X20V4X8Cov8R8V = 0x34,
  68. Zf32X20V4S8Cov4R4V = 0x35,
  69. Zf32X20V4S8Cov8R8V = 0x36,
  70. X8Z24X16V8S8Cov4R12V = 0x37,
  71. Zf32X16V8X8Cov4R12V = 0x38,
  72. Zf32X16V8S8Cov4R12V = 0x39,
  73. Z16 = 0x3a,
  74. V8Z24Cov8R24V = 0x3b,
  75. X8Z24X16V8S8Cov8R24V = 0x3c,
  76. Zf32X16V8X8Cov8R24V = 0x3d,
  77. Zf32X16V8S8Cov8R24V = 0x3e,
  78. Astc2D4x4 = 0x40,
  79. Astc2D5x4 = 0x50,
  80. Astc2D5x5 = 0x41,
  81. Astc2D6x5 = 0x51,
  82. Astc2D6x6 = 0x42,
  83. Astc2D8x5 = 0x55,
  84. Astc2D8x6 = 0x52,
  85. Astc2D8x8 = 0x44,
  86. Astc2D10x5 = 0x56,
  87. Astc2D10x6 = 0x57,
  88. Astc2D10x8 = 0x53,
  89. Astc2D10x10 = 0x45,
  90. Astc2D12x10 = 0x54,
  91. Astc2D12x12 = 0x46,
  92. // Types
  93. Snorm = 0x1,
  94. Unorm = 0x2,
  95. Sint = 0x3,
  96. Uint = 0x4,
  97. SnormForceFp16 = 0x5,
  98. UnormForceFp16 = 0x6,
  99. Float = 0x7,
  100. // Component Types
  101. RSnorm = Snorm << 7,
  102. GSnorm = Snorm << 10,
  103. BSnorm = Snorm << 13,
  104. ASnorm = Snorm << 16,
  105. RUnorm = Unorm << 7,
  106. GUnorm = Unorm << 10,
  107. BUnorm = Unorm << 13,
  108. AUnorm = Unorm << 16,
  109. RSint = Sint << 7,
  110. GSint = Sint << 10,
  111. BSint = Sint << 13,
  112. ASint = Sint << 16,
  113. RUint = Uint << 7,
  114. GUint = Uint << 10,
  115. BUint = Uint << 13,
  116. AUint = Uint << 16,
  117. RSnormForceFp16 = SnormForceFp16 << 7,
  118. GSnormForceFp16 = SnormForceFp16 << 10,
  119. BSnormForceFp16 = SnormForceFp16 << 13,
  120. ASnormForceFp16 = SnormForceFp16 << 16,
  121. RUnormForceFp16 = UnormForceFp16 << 7,
  122. GUnormForceFp16 = UnormForceFp16 << 10,
  123. BUnormForceFp16 = UnormForceFp16 << 13,
  124. AUnormForceFp16 = UnormForceFp16 << 16,
  125. RFloat = Float << 7,
  126. GFloat = Float << 10,
  127. BFloat = Float << 13,
  128. AFloat = Float << 16,
  129. Srgb = 0x1 << 19, // Custom encoding
  130. // Combinations
  131. R8Unorm = R8 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2491d
  132. R8Snorm = R8 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x1249d
  133. R8Uint = R8 | RUint | GUint | BUint | AUint, // 0x4921d
  134. R8Sint = R8 | RSint | GSint | BSint | ASint, // 0x36d9d
  135. R16Float = R16 | RFloat | GFloat | BFloat | AFloat, // 0x7ff9b
  136. R16Unorm = R16 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2491b
  137. R16Snorm = R16 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x1249b
  138. R16Uint = R16 | RUint | GUint | BUint | AUint, // 0x4921b
  139. R16Sint = R16 | RSint | GSint | BSint | ASint, // 0x36d9b
  140. R32Float = R32 | RFloat | GFloat | BFloat | AFloat, // 0x7ff8f
  141. R32Uint = R32 | RUint | GUint | BUint | AUint, // 0x4920f
  142. R32Sint = R32 | RSint | GSint | BSint | ASint, // 0x36d8f
  143. G8R8Unorm = G8R8 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24918
  144. G8R8Snorm = G8R8 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x12498
  145. G8R8Uint = G8R8 | RUint | GUint | BUint | AUint, // 0x49218
  146. G8R8Sint = G8R8 | RSint | GSint | BSint | ASint, // 0x36d98
  147. R16G16Float = R16G16 | RFloat | GFloat | BFloat | AFloat, // 0x7ff8c
  148. R16G16Unorm = R16G16 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2490c
  149. R16G16Snorm = R16G16 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x1248c
  150. R16G16Uint = R16G16 | RUint | GUint | BUint | AUint, // 0x4920c
  151. R16G16Sint = R16G16 | RSint | GSint | BSint | ASint, // 0x36d8c
  152. R32G32Float = R32G32 | RFloat | GFloat | BFloat | AFloat, // 0x7ff84
  153. R32G32Uint = R32G32 | RUint | GUint | BUint | AUint, // 0x49204
  154. R32G32Sint = R32G32 | RSint | GSint | BSint | ASint, // 0x36d84
  155. R32G32B32Float = R32G32B32 | RFloat | GFloat | BFloat | AFloat, // 0x7ff82
  156. R32G32B32Uint = R32G32B32 | RUint | GUint | BUint | AUint, // 0x49202
  157. R32G32B32Sint = R32G32B32 | RSint | GSint | BSint | ASint, // 0x36d82
  158. A8B8G8R8Unorm = A8B8G8R8 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24908
  159. A8B8G8R8Snorm = A8B8G8R8 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x12488
  160. A8B8G8R8Uint = A8B8G8R8 | RUint | GUint | BUint | AUint, // 0x49208
  161. A8B8G8R8Sint = A8B8G8R8 | RSint | GSint | BSint | ASint, // 0x36d88
  162. R16G16B16A16Float = R16G16B16A16 | RFloat | GFloat | BFloat | AFloat, // 0x7ff83
  163. R16G16B16A16Unorm = R16G16B16A16 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24903
  164. R16G16B16A16Snorm = R16G16B16A16 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x12483
  165. R16G16B16A16Uint = R16G16B16A16 | RUint | GUint | BUint | AUint, // 0x49203
  166. R16G16B16A16Sint = R16G16B16A16 | RSint | GSint | BSint | ASint, // 0x36d83
  167. R32G32B32A32Float = R32G32B32A32 | RFloat | GFloat | BFloat | AFloat, // 0x7ff81
  168. R32G32B32A32Uint = R32G32B32A32 | RUint | GUint | BUint | AUint, // 0x49201
  169. R32G32B32A32Sint = R32G32B32A32 | RSint | GSint | BSint | ASint, // 0x36d81
  170. Z16Unorm = Z16 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2493a
  171. Z16RUnormGUintBUintAUint = Z16 | RUnorm | GUint | BUint | AUint, // 0x4913a
  172. Zf32RFloatGUintBUintAUint = Zf32 | RFloat | GUint | BUint | AUint, // 0x493af
  173. Zf32Float = Zf32 | RFloat | GFloat | BFloat | AFloat, // 0x7ffaf
  174. G24R8RUintGUnormBUnormAUnorm = G24R8 | RUint | GUnorm | BUnorm | AUnorm, // 0x24a0e
  175. Z24S8RUintGUnormBUnormAUnorm = Z24S8 | RUint | GUnorm | BUnorm | AUnorm, // 0x24a29
  176. Z24S8RUintGUnormBUintAUint = Z24S8 | RUint | GUnorm | BUint | AUint, // 0x48a29
  177. X8Z24RUnormGUintBUintAUint = X8Z24 | RUnorm | GUint | BUint | AUint, // 0x4912a
  178. S8Z24RUnormGUintBUintAUint = S8Z24 | RUnorm | GUint | BUint | AUint, // 0x4912b
  179. R32B24G8RFloatGUintBUnormAUnorm = R32B24G8 | RFloat | GUint | BUnorm | AUnorm, // 0x25385
  180. Zf32X24S8RFloatGUintBUnormAUnorm = Zf32X24S8 | RFloat | GUint | BUnorm | AUnorm, // 0x253b0
  181. A8B8G8R8UnormSrgb = A8B8G8R8 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4908
  182. G4R4Unorm = G4R4 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2491e
  183. A4B4G4R4Unorm = A4B4G4R4 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24912
  184. A1B5G5R5Unorm = A1B5G5R5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24914
  185. B5G6R5Unorm = B5G6R5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24915
  186. A2B10G10R10Unorm = A2B10G10R10 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24909
  187. A2B10G10R10Uint = A2B10G10R10 | RUint | GUint | BUint | AUint, // 0x49209
  188. Bf10Gf11Rf11Float = Bf10Gf11Rf11 | RFloat | GFloat | BFloat | AFloat, // 0x7ffa1
  189. E5B9G9R9SharedExpFloat = E5B9G9R9SharedExp | RFloat | GFloat | BFloat | AFloat, // 0x7ffa0
  190. Bc1Unorm = Bc1 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24924
  191. Bc2Unorm = Bc2 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24925
  192. Bc3Unorm = Bc3 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24926
  193. Bc1UnormSrgb = Bc1 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4924
  194. Bc2UnormSrgb = Bc2 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4925
  195. Bc3UnormSrgb = Bc3 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4926
  196. Bc4Unorm = Bc4 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24927
  197. Bc4Snorm = Bc4 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x124a7
  198. Bc5Unorm = Bc5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24928
  199. Bc5Snorm = Bc5 | RSnorm | GSnorm | BSnorm | ASnorm, // 0x124a8
  200. Bc7UUnorm = Bc7U | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24917
  201. Bc7UUnormSrgb = Bc7U | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4917
  202. Bc6HSf16Float = Bc6HSf16 | RFloat | GFloat | BFloat | AFloat, // 0x7ff90
  203. Bc6HUf16Float = Bc6HUf16 | RFloat | GFloat | BFloat | AFloat, // 0x7ff91
  204. Etc2RgbUnorm = Etc2Rgb | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24906
  205. Etc2RgbPtaUnorm = Etc2RgbPta | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2490a
  206. Etc2RgbaUnorm = Etc2Rgba | RUnorm | GUnorm | BUnorm | AUnorm, // 0x2490b
  207. Etc2RgbUnormSrgb = Etc2Rgb | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4906
  208. Etc2RgbPtaUnormSrgb = Etc2RgbPta | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa490a
  209. Etc2RgbaUnormSrgb = Etc2Rgba | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa490b
  210. Astc2D4x4Unorm = Astc2D4x4 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24940
  211. Astc2D5x4Unorm = Astc2D5x4 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24950
  212. Astc2D5x5Unorm = Astc2D5x5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24941
  213. Astc2D6x5Unorm = Astc2D6x5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24951
  214. Astc2D6x6Unorm = Astc2D6x6 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24942
  215. Astc2D8x5Unorm = Astc2D8x5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24955
  216. Astc2D8x6Unorm = Astc2D8x6 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24952
  217. Astc2D8x8Unorm = Astc2D8x8 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24944
  218. Astc2D10x5Unorm = Astc2D10x5 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24956
  219. Astc2D10x6Unorm = Astc2D10x6 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24957
  220. Astc2D10x8Unorm = Astc2D10x8 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24953
  221. Astc2D10x10Unorm = Astc2D10x10 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24945
  222. Astc2D12x10Unorm = Astc2D12x10 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24954
  223. Astc2D12x12Unorm = Astc2D12x12 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24946
  224. Astc2D4x4UnormSrgb = Astc2D4x4 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4940
  225. Astc2D5x4UnormSrgb = Astc2D5x4 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4950
  226. Astc2D5x5UnormSrgb = Astc2D5x5 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4941
  227. Astc2D6x5UnormSrgb = Astc2D6x5 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4951
  228. Astc2D6x6UnormSrgb = Astc2D6x6 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4942
  229. Astc2D8x5UnormSrgb = Astc2D8x5 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4955
  230. Astc2D8x6UnormSrgb = Astc2D8x6 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4952
  231. Astc2D8x8UnormSrgb = Astc2D8x8 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4944
  232. Astc2D10x5UnormSrgb = Astc2D10x5 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4956
  233. Astc2D10x6UnormSrgb = Astc2D10x6 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4957
  234. Astc2D10x8UnormSrgb = Astc2D10x8 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4953
  235. Astc2D10x10UnormSrgb = Astc2D10x10 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4945
  236. Astc2D12x10UnormSrgb = Astc2D12x10 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4954
  237. Astc2D12x12UnormSrgb = Astc2D12x12 | RUnorm | GUnorm | BUnorm | AUnorm | Srgb, // 0xa4946
  238. A5B5G5R1Unorm = A5B5G5R1 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24913
  239. }
  240. [SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
  241. private enum VertexAttributeFormat : uint
  242. {
  243. // Width
  244. R32G32B32A32 = 0x01,
  245. R32G32B32 = 0x02,
  246. R16G16B16A16 = 0x03,
  247. R32G32 = 0x04,
  248. R16G16B16 = 0x05,
  249. A8B8G8R8 = 0x2f,
  250. R8G8B8A8 = 0x0a,
  251. X8B8G8R8 = 0x33,
  252. A2B10G10R10 = 0x30,
  253. B10G11R11 = 0x31,
  254. R16G16 = 0x0f,
  255. R32 = 0x12,
  256. R8G8B8 = 0x13,
  257. G8R8 = 0x32,
  258. R8G8 = 0x18,
  259. R16 = 0x1b,
  260. R8 = 0x1d,
  261. A8 = 0x34,
  262. // Type
  263. Snorm = 0x01,
  264. Unorm = 0x02,
  265. Sint = 0x03,
  266. Uint = 0x04,
  267. Uscaled = 0x05,
  268. Sscaled = 0x06,
  269. Float = 0x07,
  270. // Combinations
  271. R8Unorm = (R8 << 21) | (Unorm << 27), // 0x13a00000
  272. R8Snorm = (R8 << 21) | (Snorm << 27), // 0x0ba00000
  273. R8Uint = (R8 << 21) | (Uint << 27), // 0x23a00000
  274. R8Sint = (R8 << 21) | (Sint << 27), // 0x1ba00000
  275. R16Float = (R16 << 21) | (Float << 27), // 0x3b600000
  276. R16Unorm = (R16 << 21) | (Unorm << 27), // 0x13600000
  277. R16Snorm = (R16 << 21) | (Snorm << 27), // 0x0b600000
  278. R16Uint = (R16 << 21) | (Uint << 27), // 0x23600000
  279. R16Sint = (R16 << 21) | (Sint << 27), // 0x1b600000
  280. R32Float = (R32 << 21) | (Float << 27), // 0x3a400000
  281. R32Uint = (R32 << 21) | (Uint << 27), // 0x22400000
  282. R32Sint = (R32 << 21) | (Sint << 27), // 0x1a400000
  283. R8G8Unorm = (R8G8 << 21) | (Unorm << 27), // 0x13000000
  284. R8G8Snorm = (R8G8 << 21) | (Snorm << 27), // 0x0b000000
  285. R8G8Uint = (R8G8 << 21) | (Uint << 27), // 0x23000000
  286. R8G8Sint = (R8G8 << 21) | (Sint << 27), // 0x1b000000
  287. R16G16Float = (R16G16 << 21) | (Float << 27), // 0x39e00000
  288. R16G16Unorm = (R16G16 << 21) | (Unorm << 27), // 0x11e00000
  289. R16G16Snorm = (R16G16 << 21) | (Snorm << 27), // 0x09e00000
  290. R16G16Uint = (R16G16 << 21) | (Uint << 27), // 0x21e00000
  291. R16G16Sint = (R16G16 << 21) | (Sint << 27), // 0x19e00000
  292. R32G32Float = (R32G32 << 21) | (Float << 27), // 0x38800000
  293. R32G32Uint = (R32G32 << 21) | (Uint << 27), // 0x20800000
  294. R32G32Sint = (R32G32 << 21) | (Sint << 27), // 0x18800000
  295. R8G8B8Unorm = (R8G8B8 << 21) | (Unorm << 27), // 0x12600000
  296. R8G8B8Snorm = (R8G8B8 << 21) | (Snorm << 27), // 0x0a600000
  297. R8G8B8Uint = (R8G8B8 << 21) | (Uint << 27), // 0x22600000
  298. R8G8B8Sint = (R8G8B8 << 21) | (Sint << 27), // 0x1a600000
  299. R16G16B16Float = (R16G16B16 << 21) | (Float << 27), // 0x38a00000
  300. R16G16B16Unorm = (R16G16B16 << 21) | (Unorm << 27), // 0x10a00000
  301. R16G16B16Snorm = (R16G16B16 << 21) | (Snorm << 27), // 0x08a00000
  302. R16G16B16Uint = (R16G16B16 << 21) | (Uint << 27), // 0x20a00000
  303. R16G16B16Sint = (R16G16B16 << 21) | (Sint << 27), // 0x18a00000
  304. R32G32B32Float = (R32G32B32 << 21) | (Float << 27), // 0x38400000
  305. R32G32B32Uint = (R32G32B32 << 21) | (Uint << 27), // 0x20400000
  306. R32G32B32Sint = (R32G32B32 << 21) | (Sint << 27), // 0x18400000
  307. R8G8B8A8Unorm = (R8G8B8A8 << 21) | (Unorm << 27), // 0x11400000
  308. R8G8B8A8Snorm = (R8G8B8A8 << 21) | (Snorm << 27), // 0x09400000
  309. R8G8B8A8Uint = (R8G8B8A8 << 21) | (Uint << 27), // 0x21400000
  310. R8G8B8A8Sint = (R8G8B8A8 << 21) | (Sint << 27), // 0x19400000
  311. R16G16B16A16Float = (R16G16B16A16 << 21) | (Float << 27), // 0x38600000
  312. R16G16B16A16Unorm = (R16G16B16A16 << 21) | (Unorm << 27), // 0x10600000
  313. R16G16B16A16Snorm = (R16G16B16A16 << 21) | (Snorm << 27), // 0x08600000
  314. R16G16B16A16Uint = (R16G16B16A16 << 21) | (Uint << 27), // 0x20600000
  315. R16G16B16A16Sint = (R16G16B16A16 << 21) | (Sint << 27), // 0x18600000
  316. R32G32B32A32Float = (R32G32B32A32 << 21) | (Float << 27), // 0x38200000
  317. R32G32B32A32Uint = (R32G32B32A32 << 21) | (Uint << 27), // 0x20200000
  318. R32G32B32A32Sint = (R32G32B32A32 << 21) | (Sint << 27), // 0x18200000
  319. A2B10G10R10Unorm = (A2B10G10R10 << 21) | (Unorm << 27), // 0x16000000
  320. A2B10G10R10Uint = (A2B10G10R10 << 21) | (Uint << 27), // 0x26000000
  321. B10G11R11Float = (B10G11R11 << 21) | (Float << 27), // 0x3e200000
  322. R8Uscaled = (R8 << 21) | (Uscaled << 27), // 0x2ba00000
  323. R8Sscaled = (R8 << 21) | (Sscaled << 27), // 0x33a00000
  324. R16Uscaled = (R16 << 21) | (Uscaled << 27), // 0x2b600000
  325. R16Sscaled = (R16 << 21) | (Sscaled << 27), // 0x33600000
  326. R32Uscaled = (R32 << 21) | (Uscaled << 27), // 0x2a400000
  327. R32Sscaled = (R32 << 21) | (Sscaled << 27), // 0x32400000
  328. R8G8Uscaled = (R8G8 << 21) | (Uscaled << 27), // 0x2b000000
  329. R8G8Sscaled = (R8G8 << 21) | (Sscaled << 27), // 0x33000000
  330. R16G16Uscaled = (R16G16 << 21) | (Uscaled << 27), // 0x29e00000
  331. R16G16Sscaled = (R16G16 << 21) | (Sscaled << 27), // 0x31e00000
  332. R32G32Uscaled = (R32G32 << 21) | (Uscaled << 27), // 0x28800000
  333. R32G32Sscaled = (R32G32 << 21) | (Sscaled << 27), // 0x30800000
  334. R8G8B8Uscaled = (R8G8B8 << 21) | (Uscaled << 27), // 0x2a600000
  335. R8G8B8Sscaled = (R8G8B8 << 21) | (Sscaled << 27), // 0x32600000
  336. R16G16B16Uscaled = (R16G16B16 << 21) | (Uscaled << 27), // 0x28a00000
  337. R16G16B16Sscaled = (R16G16B16 << 21) | (Sscaled << 27), // 0x30a00000
  338. R32G32B32Uscaled = (R32G32B32 << 21) | (Uscaled << 27), // 0x28400000
  339. R32G32B32Sscaled = (R32G32B32 << 21) | (Sscaled << 27), // 0x30400000
  340. R8G8B8A8Uscaled = (R8G8B8A8 << 21) | (Uscaled << 27), // 0x29400000
  341. R8G8B8A8Sscaled = (R8G8B8A8 << 21) | (Sscaled << 27), // 0x31400000
  342. R16G16B16A16Uscaled = (R16G16B16A16 << 21) | (Uscaled << 27), // 0x28600000
  343. R16G16B16A16Sscaled = (R16G16B16A16 << 21) | (Sscaled << 27), // 0x30600000
  344. R32G32B32A32Uscaled = (R32G32B32A32 << 21) | (Uscaled << 27), // 0x28200000
  345. R32G32B32A32Sscaled = (R32G32B32A32 << 21) | (Sscaled << 27), // 0x30200000
  346. A2B10G10R10Snorm = (A2B10G10R10 << 21) | (Snorm << 27), // 0x0e000000
  347. A2B10G10R10Sint = (A2B10G10R10 << 21) | (Sint << 27), // 0x1e000000
  348. A2B10G10R10Uscaled = (A2B10G10R10 << 21) | (Uscaled << 27), // 0x2e000000
  349. A2B10G10R10Sscaled = (A2B10G10R10 << 21) | (Sscaled << 27), // 0x36000000
  350. }
  351. private static readonly Dictionary<TextureFormat, FormatInfo> _textureFormats = new()
  352. {
  353. { TextureFormat.R8Unorm, new FormatInfo(Format.R8Unorm, 1, 1, 1, 1) },
  354. { TextureFormat.R8Snorm, new FormatInfo(Format.R8Snorm, 1, 1, 1, 1) },
  355. { TextureFormat.R8Uint, new FormatInfo(Format.R8Uint, 1, 1, 1, 1) },
  356. { TextureFormat.R8Sint, new FormatInfo(Format.R8Sint, 1, 1, 1, 1) },
  357. { TextureFormat.R16Float, new FormatInfo(Format.R16Float, 1, 1, 2, 1) },
  358. { TextureFormat.R16Unorm, new FormatInfo(Format.R16Unorm, 1, 1, 2, 1) },
  359. { TextureFormat.R16Snorm, new FormatInfo(Format.R16Snorm, 1, 1, 2, 1) },
  360. { TextureFormat.R16Uint, new FormatInfo(Format.R16Uint, 1, 1, 2, 1) },
  361. { TextureFormat.R16Sint, new FormatInfo(Format.R16Sint, 1, 1, 2, 1) },
  362. { TextureFormat.R32Float, new FormatInfo(Format.R32Float, 1, 1, 4, 1) },
  363. { TextureFormat.R32Uint, new FormatInfo(Format.R32Uint, 1, 1, 4, 1) },
  364. { TextureFormat.R32Sint, new FormatInfo(Format.R32Sint, 1, 1, 4, 1) },
  365. { TextureFormat.G8R8Unorm, new FormatInfo(Format.R8G8Unorm, 1, 1, 2, 2) },
  366. { TextureFormat.G8R8Snorm, new FormatInfo(Format.R8G8Snorm, 1, 1, 2, 2) },
  367. { TextureFormat.G8R8Uint, new FormatInfo(Format.R8G8Uint, 1, 1, 2, 2) },
  368. { TextureFormat.G8R8Sint, new FormatInfo(Format.R8G8Sint, 1, 1, 2, 2) },
  369. { TextureFormat.R16G16Float, new FormatInfo(Format.R16G16Float, 1, 1, 4, 2) },
  370. { TextureFormat.R16G16Unorm, new FormatInfo(Format.R16G16Unorm, 1, 1, 4, 2) },
  371. { TextureFormat.R16G16Snorm, new FormatInfo(Format.R16G16Snorm, 1, 1, 4, 2) },
  372. { TextureFormat.R16G16Uint, new FormatInfo(Format.R16G16Uint, 1, 1, 4, 2) },
  373. { TextureFormat.R16G16Sint, new FormatInfo(Format.R16G16Sint, 1, 1, 4, 2) },
  374. { TextureFormat.R32G32Float, new FormatInfo(Format.R32G32Float, 1, 1, 8, 2) },
  375. { TextureFormat.R32G32Uint, new FormatInfo(Format.R32G32Uint, 1, 1, 8, 2) },
  376. { TextureFormat.R32G32Sint, new FormatInfo(Format.R32G32Sint, 1, 1, 8, 2) },
  377. { TextureFormat.R32G32B32Float, new FormatInfo(Format.R32G32B32Float, 1, 1, 12, 3) },
  378. { TextureFormat.R32G32B32Uint, new FormatInfo(Format.R32G32B32Uint, 1, 1, 12, 3) },
  379. { TextureFormat.R32G32B32Sint, new FormatInfo(Format.R32G32B32Sint, 1, 1, 12, 3) },
  380. { TextureFormat.A8B8G8R8Unorm, new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4, 4) },
  381. { TextureFormat.A8B8G8R8Snorm, new FormatInfo(Format.R8G8B8A8Snorm, 1, 1, 4, 4) },
  382. { TextureFormat.A8B8G8R8Uint, new FormatInfo(Format.R8G8B8A8Uint, 1, 1, 4, 4) },
  383. { TextureFormat.A8B8G8R8Sint, new FormatInfo(Format.R8G8B8A8Sint, 1, 1, 4, 4) },
  384. { TextureFormat.R16G16B16A16Float, new FormatInfo(Format.R16G16B16A16Float, 1, 1, 8, 4) },
  385. { TextureFormat.R16G16B16A16Unorm, new FormatInfo(Format.R16G16B16A16Unorm, 1, 1, 8, 4) },
  386. { TextureFormat.R16G16B16A16Snorm, new FormatInfo(Format.R16G16B16A16Snorm, 1, 1, 8, 4) },
  387. { TextureFormat.R16G16B16A16Uint, new FormatInfo(Format.R16G16B16A16Uint, 1, 1, 8, 4) },
  388. { TextureFormat.R16G16B16A16Sint, new FormatInfo(Format.R16G16B16A16Sint, 1, 1, 8, 4) },
  389. { TextureFormat.R32G32B32A32Float, new FormatInfo(Format.R32G32B32A32Float, 1, 1, 16, 4) },
  390. { TextureFormat.R32G32B32A32Uint, new FormatInfo(Format.R32G32B32A32Uint, 1, 1, 16, 4) },
  391. { TextureFormat.R32G32B32A32Sint, new FormatInfo(Format.R32G32B32A32Sint, 1, 1, 16, 4) },
  392. { TextureFormat.Z16Unorm, new FormatInfo(Format.D16Unorm, 1, 1, 2, 1) },
  393. { TextureFormat.Z16RUnormGUintBUintAUint, new FormatInfo(Format.D16Unorm, 1, 1, 2, 1) },
  394. { TextureFormat.Zf32RFloatGUintBUintAUint, new FormatInfo(Format.D32Float, 1, 1, 4, 1) },
  395. { TextureFormat.Zf32Float, new FormatInfo(Format.D32Float, 1, 1, 4, 1) },
  396. { TextureFormat.G24R8RUintGUnormBUnormAUnorm, new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4, 2) },
  397. { TextureFormat.Z24S8RUintGUnormBUnormAUnorm, new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4, 2) },
  398. { TextureFormat.Z24S8RUintGUnormBUintAUint, new FormatInfo(Format.D24UnormS8Uint, 1, 1, 4, 2) },
  399. { TextureFormat.X8Z24RUnormGUintBUintAUint, new FormatInfo(Format.X8UintD24Unorm, 1, 1, 4, 2) },
  400. { TextureFormat.S8Z24RUnormGUintBUintAUint, new FormatInfo(Format.S8UintD24Unorm, 1, 1, 4, 2) },
  401. { TextureFormat.R32B24G8RFloatGUintBUnormAUnorm, new FormatInfo(Format.D32FloatS8Uint, 1, 1, 8, 2) },
  402. { TextureFormat.Zf32X24S8RFloatGUintBUnormAUnorm, new FormatInfo(Format.D32FloatS8Uint, 1, 1, 8, 2) },
  403. { TextureFormat.A8B8G8R8UnormSrgb, new FormatInfo(Format.R8G8B8A8Srgb, 1, 1, 4, 4) },
  404. { TextureFormat.G4R4Unorm, new FormatInfo(Format.R4G4Unorm, 1, 1, 1, 2) },
  405. { TextureFormat.A4B4G4R4Unorm, new FormatInfo(Format.R4G4B4A4Unorm, 1, 1, 2, 4) },
  406. { TextureFormat.A1B5G5R5Unorm, new FormatInfo(Format.R5G5B5A1Unorm, 1, 1, 2, 4) },
  407. { TextureFormat.B5G6R5Unorm, new FormatInfo(Format.R5G6B5Unorm, 1, 1, 2, 3) },
  408. { TextureFormat.A2B10G10R10Unorm, new FormatInfo(Format.R10G10B10A2Unorm, 1, 1, 4, 4) },
  409. { TextureFormat.A2B10G10R10Uint, new FormatInfo(Format.R10G10B10A2Uint, 1, 1, 4, 4) },
  410. { TextureFormat.Bf10Gf11Rf11Float, new FormatInfo(Format.R11G11B10Float, 1, 1, 4, 3) },
  411. { TextureFormat.E5B9G9R9SharedExpFloat, new FormatInfo(Format.R9G9B9E5Float, 1, 1, 4, 4) },
  412. { TextureFormat.Bc1Unorm, new FormatInfo(Format.Bc1RgbaUnorm, 4, 4, 8, 4) },
  413. { TextureFormat.Bc2Unorm, new FormatInfo(Format.Bc2Unorm, 4, 4, 16, 4) },
  414. { TextureFormat.Bc3Unorm, new FormatInfo(Format.Bc3Unorm, 4, 4, 16, 4) },
  415. { TextureFormat.Bc1UnormSrgb, new FormatInfo(Format.Bc1RgbaSrgb, 4, 4, 8, 4) },
  416. { TextureFormat.Bc2UnormSrgb, new FormatInfo(Format.Bc2Srgb, 4, 4, 16, 4) },
  417. { TextureFormat.Bc3UnormSrgb, new FormatInfo(Format.Bc3Srgb, 4, 4, 16, 4) },
  418. { TextureFormat.Bc4Unorm, new FormatInfo(Format.Bc4Unorm, 4, 4, 8, 1) },
  419. { TextureFormat.Bc4Snorm, new FormatInfo(Format.Bc4Snorm, 4, 4, 8, 1) },
  420. { TextureFormat.Bc5Unorm, new FormatInfo(Format.Bc5Unorm, 4, 4, 16, 2) },
  421. { TextureFormat.Bc5Snorm, new FormatInfo(Format.Bc5Snorm, 4, 4, 16, 2) },
  422. { TextureFormat.Bc7UUnorm, new FormatInfo(Format.Bc7Unorm, 4, 4, 16, 4) },
  423. { TextureFormat.Bc7UUnormSrgb, new FormatInfo(Format.Bc7Srgb, 4, 4, 16, 4) },
  424. { TextureFormat.Bc6HSf16Float, new FormatInfo(Format.Bc6HSfloat, 4, 4, 16, 4) },
  425. { TextureFormat.Bc6HUf16Float, new FormatInfo(Format.Bc6HUfloat, 4, 4, 16, 4) },
  426. { TextureFormat.Etc2RgbUnorm, new FormatInfo(Format.Etc2RgbUnorm, 4, 4, 8, 3) },
  427. { TextureFormat.Etc2RgbPtaUnorm, new FormatInfo(Format.Etc2RgbPtaUnorm, 4, 4, 8, 4) },
  428. { TextureFormat.Etc2RgbaUnorm, new FormatInfo(Format.Etc2RgbaUnorm, 4, 4, 16, 4) },
  429. { TextureFormat.Etc2RgbUnormSrgb, new FormatInfo(Format.Etc2RgbSrgb, 4, 4, 8, 3) },
  430. { TextureFormat.Etc2RgbPtaUnormSrgb, new FormatInfo(Format.Etc2RgbPtaSrgb, 4, 4, 8, 4) },
  431. { TextureFormat.Etc2RgbaUnormSrgb, new FormatInfo(Format.Etc2RgbaSrgb, 4, 4, 16, 4) },
  432. { TextureFormat.Astc2D4x4Unorm, new FormatInfo(Format.Astc4x4Unorm, 4, 4, 16, 4) },
  433. { TextureFormat.Astc2D5x4Unorm, new FormatInfo(Format.Astc5x4Unorm, 5, 4, 16, 4) },
  434. { TextureFormat.Astc2D5x5Unorm, new FormatInfo(Format.Astc5x5Unorm, 5, 5, 16, 4) },
  435. { TextureFormat.Astc2D6x5Unorm, new FormatInfo(Format.Astc6x5Unorm, 6, 5, 16, 4) },
  436. { TextureFormat.Astc2D6x6Unorm, new FormatInfo(Format.Astc6x6Unorm, 6, 6, 16, 4) },
  437. { TextureFormat.Astc2D8x5Unorm, new FormatInfo(Format.Astc8x5Unorm, 8, 5, 16, 4) },
  438. { TextureFormat.Astc2D8x6Unorm, new FormatInfo(Format.Astc8x6Unorm, 8, 6, 16, 4) },
  439. { TextureFormat.Astc2D8x8Unorm, new FormatInfo(Format.Astc8x8Unorm, 8, 8, 16, 4) },
  440. { TextureFormat.Astc2D10x5Unorm, new FormatInfo(Format.Astc10x5Unorm, 10, 5, 16, 4) },
  441. { TextureFormat.Astc2D10x6Unorm, new FormatInfo(Format.Astc10x6Unorm, 10, 6, 16, 4) },
  442. { TextureFormat.Astc2D10x8Unorm, new FormatInfo(Format.Astc10x8Unorm, 10, 8, 16, 4) },
  443. { TextureFormat.Astc2D10x10Unorm, new FormatInfo(Format.Astc10x10Unorm, 10, 10, 16, 4) },
  444. { TextureFormat.Astc2D12x10Unorm, new FormatInfo(Format.Astc12x10Unorm, 12, 10, 16, 4) },
  445. { TextureFormat.Astc2D12x12Unorm, new FormatInfo(Format.Astc12x12Unorm, 12, 12, 16, 4) },
  446. { TextureFormat.Astc2D4x4UnormSrgb, new FormatInfo(Format.Astc4x4Srgb, 4, 4, 16, 4) },
  447. { TextureFormat.Astc2D5x4UnormSrgb, new FormatInfo(Format.Astc5x4Srgb, 5, 4, 16, 4) },
  448. { TextureFormat.Astc2D5x5UnormSrgb, new FormatInfo(Format.Astc5x5Srgb, 5, 5, 16, 4) },
  449. { TextureFormat.Astc2D6x5UnormSrgb, new FormatInfo(Format.Astc6x5Srgb, 6, 5, 16, 4) },
  450. { TextureFormat.Astc2D6x6UnormSrgb, new FormatInfo(Format.Astc6x6Srgb, 6, 6, 16, 4) },
  451. { TextureFormat.Astc2D8x5UnormSrgb, new FormatInfo(Format.Astc8x5Srgb, 8, 5, 16, 4) },
  452. { TextureFormat.Astc2D8x6UnormSrgb, new FormatInfo(Format.Astc8x6Srgb, 8, 6, 16, 4) },
  453. { TextureFormat.Astc2D8x8UnormSrgb, new FormatInfo(Format.Astc8x8Srgb, 8, 8, 16, 4) },
  454. { TextureFormat.Astc2D10x5UnormSrgb, new FormatInfo(Format.Astc10x5Srgb, 10, 5, 16, 4) },
  455. { TextureFormat.Astc2D10x6UnormSrgb, new FormatInfo(Format.Astc10x6Srgb, 10, 6, 16, 4) },
  456. { TextureFormat.Astc2D10x8UnormSrgb, new FormatInfo(Format.Astc10x8Srgb, 10, 8, 16, 4) },
  457. { TextureFormat.Astc2D10x10UnormSrgb, new FormatInfo(Format.Astc10x10Srgb, 10, 10, 16, 4) },
  458. { TextureFormat.Astc2D12x10UnormSrgb, new FormatInfo(Format.Astc12x10Srgb, 12, 10, 16, 4) },
  459. { TextureFormat.Astc2D12x12UnormSrgb, new FormatInfo(Format.Astc12x12Srgb, 12, 12, 16, 4) },
  460. { TextureFormat.A5B5G5R1Unorm, new FormatInfo(Format.A1B5G5R5Unorm, 1, 1, 2, 4) },
  461. };
  462. private static readonly Dictionary<VertexAttributeFormat, Format> _attribFormats = new()
  463. {
  464. { VertexAttributeFormat.R8Unorm, Format.R8Unorm },
  465. { VertexAttributeFormat.R8Snorm, Format.R8Snorm },
  466. { VertexAttributeFormat.R8Uint, Format.R8Uint },
  467. { VertexAttributeFormat.R8Sint, Format.R8Sint },
  468. { VertexAttributeFormat.R16Float, Format.R16Float },
  469. { VertexAttributeFormat.R16Unorm, Format.R16Unorm },
  470. { VertexAttributeFormat.R16Snorm, Format.R16Snorm },
  471. { VertexAttributeFormat.R16Uint, Format.R16Uint },
  472. { VertexAttributeFormat.R16Sint, Format.R16Sint },
  473. { VertexAttributeFormat.R32Float, Format.R32Float },
  474. { VertexAttributeFormat.R32Uint, Format.R32Uint },
  475. { VertexAttributeFormat.R32Sint, Format.R32Sint },
  476. { VertexAttributeFormat.R8G8Unorm, Format.R8G8Unorm },
  477. { VertexAttributeFormat.R8G8Snorm, Format.R8G8Snorm },
  478. { VertexAttributeFormat.R8G8Uint, Format.R8G8Uint },
  479. { VertexAttributeFormat.R8G8Sint, Format.R8G8Sint },
  480. { VertexAttributeFormat.R16G16Float, Format.R16G16Float },
  481. { VertexAttributeFormat.R16G16Unorm, Format.R16G16Unorm },
  482. { VertexAttributeFormat.R16G16Snorm, Format.R16G16Snorm },
  483. { VertexAttributeFormat.R16G16Uint, Format.R16G16Uint },
  484. { VertexAttributeFormat.R16G16Sint, Format.R16G16Sint },
  485. { VertexAttributeFormat.R32G32Float, Format.R32G32Float },
  486. { VertexAttributeFormat.R32G32Uint, Format.R32G32Uint },
  487. { VertexAttributeFormat.R32G32Sint, Format.R32G32Sint },
  488. { VertexAttributeFormat.R8G8B8Unorm, Format.R8G8B8Unorm },
  489. { VertexAttributeFormat.R8G8B8Snorm, Format.R8G8B8Snorm },
  490. { VertexAttributeFormat.R8G8B8Uint, Format.R8G8B8Uint },
  491. { VertexAttributeFormat.R8G8B8Sint, Format.R8G8B8Sint },
  492. { VertexAttributeFormat.R16G16B16Float, Format.R16G16B16Float },
  493. { VertexAttributeFormat.R16G16B16Unorm, Format.R16G16B16Unorm },
  494. { VertexAttributeFormat.R16G16B16Snorm, Format.R16G16B16Snorm },
  495. { VertexAttributeFormat.R16G16B16Uint, Format.R16G16B16Uint },
  496. { VertexAttributeFormat.R16G16B16Sint, Format.R16G16B16Sint },
  497. { VertexAttributeFormat.R32G32B32Float, Format.R32G32B32Float },
  498. { VertexAttributeFormat.R32G32B32Uint, Format.R32G32B32Uint },
  499. { VertexAttributeFormat.R32G32B32Sint, Format.R32G32B32Sint },
  500. { VertexAttributeFormat.R8G8B8A8Unorm, Format.R8G8B8A8Unorm },
  501. { VertexAttributeFormat.R8G8B8A8Snorm, Format.R8G8B8A8Snorm },
  502. { VertexAttributeFormat.R8G8B8A8Uint, Format.R8G8B8A8Uint },
  503. { VertexAttributeFormat.R8G8B8A8Sint, Format.R8G8B8A8Sint },
  504. { VertexAttributeFormat.R16G16B16A16Float, Format.R16G16B16A16Float },
  505. { VertexAttributeFormat.R16G16B16A16Unorm, Format.R16G16B16A16Unorm },
  506. { VertexAttributeFormat.R16G16B16A16Snorm, Format.R16G16B16A16Snorm },
  507. { VertexAttributeFormat.R16G16B16A16Uint, Format.R16G16B16A16Uint },
  508. { VertexAttributeFormat.R16G16B16A16Sint, Format.R16G16B16A16Sint },
  509. { VertexAttributeFormat.R32G32B32A32Float, Format.R32G32B32A32Float },
  510. { VertexAttributeFormat.R32G32B32A32Uint, Format.R32G32B32A32Uint },
  511. { VertexAttributeFormat.R32G32B32A32Sint, Format.R32G32B32A32Sint },
  512. { VertexAttributeFormat.A2B10G10R10Unorm, Format.R10G10B10A2Unorm },
  513. { VertexAttributeFormat.A2B10G10R10Uint, Format.R10G10B10A2Uint },
  514. { VertexAttributeFormat.B10G11R11Float, Format.R11G11B10Float },
  515. { VertexAttributeFormat.R8Uscaled, Format.R8Uscaled },
  516. { VertexAttributeFormat.R8Sscaled, Format.R8Sscaled },
  517. { VertexAttributeFormat.R16Uscaled, Format.R16Uscaled },
  518. { VertexAttributeFormat.R16Sscaled, Format.R16Sscaled },
  519. { VertexAttributeFormat.R32Uscaled, Format.R32Uscaled },
  520. { VertexAttributeFormat.R32Sscaled, Format.R32Sscaled },
  521. { VertexAttributeFormat.R8G8Uscaled, Format.R8G8Uscaled },
  522. { VertexAttributeFormat.R8G8Sscaled, Format.R8G8Sscaled },
  523. { VertexAttributeFormat.R16G16Uscaled, Format.R16G16Uscaled },
  524. { VertexAttributeFormat.R16G16Sscaled, Format.R16G16Sscaled },
  525. { VertexAttributeFormat.R32G32Uscaled, Format.R32G32Uscaled },
  526. { VertexAttributeFormat.R32G32Sscaled, Format.R32G32Sscaled },
  527. { VertexAttributeFormat.R8G8B8Uscaled, Format.R8G8B8Uscaled },
  528. { VertexAttributeFormat.R8G8B8Sscaled, Format.R8G8B8Sscaled },
  529. { VertexAttributeFormat.R16G16B16Uscaled, Format.R16G16B16Uscaled },
  530. { VertexAttributeFormat.R16G16B16Sscaled, Format.R16G16B16Sscaled },
  531. { VertexAttributeFormat.R32G32B32Uscaled, Format.R32G32B32Uscaled },
  532. { VertexAttributeFormat.R32G32B32Sscaled, Format.R32G32B32Sscaled },
  533. { VertexAttributeFormat.R8G8B8A8Uscaled, Format.R8G8B8A8Uscaled },
  534. { VertexAttributeFormat.R8G8B8A8Sscaled, Format.R8G8B8A8Sscaled },
  535. { VertexAttributeFormat.R16G16B16A16Uscaled, Format.R16G16B16A16Uscaled },
  536. { VertexAttributeFormat.R16G16B16A16Sscaled, Format.R16G16B16A16Sscaled },
  537. { VertexAttributeFormat.R32G32B32A32Uscaled, Format.R32G32B32A32Uscaled },
  538. { VertexAttributeFormat.R32G32B32A32Sscaled, Format.R32G32B32A32Sscaled },
  539. { VertexAttributeFormat.A2B10G10R10Snorm, Format.R10G10B10A2Snorm },
  540. { VertexAttributeFormat.A2B10G10R10Sint, Format.R10G10B10A2Sint },
  541. { VertexAttributeFormat.A2B10G10R10Uscaled, Format.R10G10B10A2Uscaled },
  542. { VertexAttributeFormat.A2B10G10R10Sscaled, Format.R10G10B10A2Sscaled },
  543. };
  544. #pragma warning restore IDE0055
  545. // Note: Some of those formats have been changed and requires conversion on the shader,
  546. // as GPUs don't support them when used as buffer texture format.
  547. private static readonly Dictionary<VertexAttributeFormat, (Format, int)> _singleComponentAttribFormats = new()
  548. {
  549. { VertexAttributeFormat.R8Unorm, (Format.R8Unorm, 1) },
  550. { VertexAttributeFormat.R8Snorm, (Format.R8Snorm, 1) },
  551. { VertexAttributeFormat.R8Uint, (Format.R8Uint, 1) },
  552. { VertexAttributeFormat.R8Sint, (Format.R8Sint, 1) },
  553. { VertexAttributeFormat.R16Float, (Format.R16Float, 1) },
  554. { VertexAttributeFormat.R16Unorm, (Format.R16Unorm, 1) },
  555. { VertexAttributeFormat.R16Snorm, (Format.R16Snorm, 1) },
  556. { VertexAttributeFormat.R16Uint, (Format.R16Uint, 1) },
  557. { VertexAttributeFormat.R16Sint, (Format.R16Sint, 1) },
  558. { VertexAttributeFormat.R32Float, (Format.R32Float, 1) },
  559. { VertexAttributeFormat.R32Uint, (Format.R32Uint, 1) },
  560. { VertexAttributeFormat.R32Sint, (Format.R32Sint, 1) },
  561. { VertexAttributeFormat.R8G8Unorm, (Format.R8Unorm, 2) },
  562. { VertexAttributeFormat.R8G8Snorm, (Format.R8Snorm, 2) },
  563. { VertexAttributeFormat.R8G8Uint, (Format.R8Uint, 2) },
  564. { VertexAttributeFormat.R8G8Sint, (Format.R8Sint, 2) },
  565. { VertexAttributeFormat.R16G16Float, (Format.R16Float, 2) },
  566. { VertexAttributeFormat.R16G16Unorm, (Format.R16Unorm, 2) },
  567. { VertexAttributeFormat.R16G16Snorm, (Format.R16Snorm, 2) },
  568. { VertexAttributeFormat.R16G16Uint, (Format.R16Uint, 2) },
  569. { VertexAttributeFormat.R16G16Sint, (Format.R16Sint, 2) },
  570. { VertexAttributeFormat.R32G32Float, (Format.R32Float, 2) },
  571. { VertexAttributeFormat.R32G32Uint, (Format.R32Uint, 2) },
  572. { VertexAttributeFormat.R32G32Sint, (Format.R32Sint, 2) },
  573. { VertexAttributeFormat.R8G8B8Unorm, (Format.R8Unorm, 3) },
  574. { VertexAttributeFormat.R8G8B8Snorm, (Format.R8Snorm, 3) },
  575. { VertexAttributeFormat.R8G8B8Uint, (Format.R8Uint, 3) },
  576. { VertexAttributeFormat.R8G8B8Sint, (Format.R8Sint, 3) },
  577. { VertexAttributeFormat.R16G16B16Float, (Format.R16Float, 3) },
  578. { VertexAttributeFormat.R16G16B16Unorm, (Format.R16Unorm, 3) },
  579. { VertexAttributeFormat.R16G16B16Snorm, (Format.R16Snorm, 3) },
  580. { VertexAttributeFormat.R16G16B16Uint, (Format.R16Uint, 3) },
  581. { VertexAttributeFormat.R16G16B16Sint, (Format.R16Sint, 3) },
  582. { VertexAttributeFormat.R32G32B32Float, (Format.R32Float, 3) },
  583. { VertexAttributeFormat.R32G32B32Uint, (Format.R32Uint, 3) },
  584. { VertexAttributeFormat.R32G32B32Sint, (Format.R32Sint, 3) },
  585. { VertexAttributeFormat.R8G8B8A8Unorm, (Format.R8Unorm, 4) },
  586. { VertexAttributeFormat.R8G8B8A8Snorm, (Format.R8Snorm, 4) },
  587. { VertexAttributeFormat.R8G8B8A8Uint, (Format.R8Uint, 4) },
  588. { VertexAttributeFormat.R8G8B8A8Sint, (Format.R8Sint, 4) },
  589. { VertexAttributeFormat.R16G16B16A16Float, (Format.R16Float, 4) },
  590. { VertexAttributeFormat.R16G16B16A16Unorm, (Format.R16Unorm, 4) },
  591. { VertexAttributeFormat.R16G16B16A16Snorm, (Format.R16Snorm, 4) },
  592. { VertexAttributeFormat.R16G16B16A16Uint, (Format.R16Uint, 4) },
  593. { VertexAttributeFormat.R16G16B16A16Sint, (Format.R16Sint, 4) },
  594. { VertexAttributeFormat.R32G32B32A32Float, (Format.R32Float, 4) },
  595. { VertexAttributeFormat.R32G32B32A32Uint, (Format.R32Uint, 4) },
  596. { VertexAttributeFormat.R32G32B32A32Sint, (Format.R32Sint, 4) },
  597. { VertexAttributeFormat.A2B10G10R10Unorm, (Format.R10G10B10A2Unorm, 4) },
  598. { VertexAttributeFormat.A2B10G10R10Uint, (Format.R10G10B10A2Uint, 4) },
  599. { VertexAttributeFormat.B10G11R11Float, (Format.R11G11B10Float, 3) },
  600. { VertexAttributeFormat.R8Uscaled, (Format.R8Uint, 1) }, // Uscaled -> Uint
  601. { VertexAttributeFormat.R8Sscaled, (Format.R8Sint, 1) }, // Sscaled -> Sint
  602. { VertexAttributeFormat.R16Uscaled, (Format.R16Uint, 1) }, // Uscaled -> Uint
  603. { VertexAttributeFormat.R16Sscaled, (Format.R16Sint, 1) }, // Sscaled -> Sint
  604. { VertexAttributeFormat.R32Uscaled, (Format.R32Uint, 1) }, // Uscaled -> Uint
  605. { VertexAttributeFormat.R32Sscaled, (Format.R32Sint, 1) }, // Sscaled -> Sint
  606. { VertexAttributeFormat.R8G8Uscaled, (Format.R8Uint, 2) }, // Uscaled -> Uint
  607. { VertexAttributeFormat.R8G8Sscaled, (Format.R8Sint, 2) }, // Sscaled -> Sint
  608. { VertexAttributeFormat.R16G16Uscaled, (Format.R16Uint, 2) }, // Uscaled -> Uint
  609. { VertexAttributeFormat.R16G16Sscaled, (Format.R16Sint, 2) }, // Sscaled -> Sint
  610. { VertexAttributeFormat.R32G32Uscaled, (Format.R32Uint, 2) }, // Uscaled -> Uint
  611. { VertexAttributeFormat.R32G32Sscaled, (Format.R32Sint, 2) }, // Sscaled -> Sint
  612. { VertexAttributeFormat.R8G8B8Uscaled, (Format.R8Uint, 3) }, // Uscaled -> Uint
  613. { VertexAttributeFormat.R8G8B8Sscaled, (Format.R8Sint, 3) }, // Sscaled -> Sint
  614. { VertexAttributeFormat.R16G16B16Uscaled, (Format.R16Uint, 3) }, // Uscaled -> Uint
  615. { VertexAttributeFormat.R16G16B16Sscaled, (Format.R16Sint, 3) }, // Sscaled -> Sint
  616. { VertexAttributeFormat.R32G32B32Uscaled, (Format.R32Uint, 3) }, // Uscaled -> Uint
  617. { VertexAttributeFormat.R32G32B32Sscaled, (Format.R32Sint , 3) }, // Sscaled -> Sint
  618. { VertexAttributeFormat.R8G8B8A8Uscaled, (Format.R8Uint, 4) }, // Uscaled -> Uint
  619. { VertexAttributeFormat.R8G8B8A8Sscaled, (Format.R8Sint, 4) }, // Sscaled -> Sint
  620. { VertexAttributeFormat.R16G16B16A16Uscaled, (Format.R16Uint, 4) }, // Uscaled -> Uint
  621. { VertexAttributeFormat.R16G16B16A16Sscaled, (Format.R16Sint, 4) }, // Sscaled -> Sint
  622. { VertexAttributeFormat.R32G32B32A32Uscaled, (Format.R32Uint, 4) }, // Uscaled -> Uint
  623. { VertexAttributeFormat.R32G32B32A32Sscaled, (Format.R32Sint, 4) }, // Sscaled -> Sint
  624. { VertexAttributeFormat.A2B10G10R10Snorm, (Format.R10G10B10A2Uint, 4) }, // Snorm -> Uint
  625. { VertexAttributeFormat.A2B10G10R10Sint, (Format.R10G10B10A2Uint, 4) }, // Sint -> Uint
  626. { VertexAttributeFormat.A2B10G10R10Uscaled, (Format.R10G10B10A2Uint, 4) }, // Uscaled -> Uint
  627. { VertexAttributeFormat.A2B10G10R10Sscaled, (Format.R10G10B10A2Sint, 4) } // Sscaled -> Sint
  628. };
  629. /// <summary>
  630. /// Try getting the texture format from an encoded format integer from the Maxwell texture descriptor.
  631. /// </summary>
  632. /// <param name="encoded">The encoded format integer from the texture descriptor</param>
  633. /// <param name="isSrgb">Indicates if the format is a sRGB format</param>
  634. /// <param name="format">The output texture format</param>
  635. /// <returns>True if the format is valid, false otherwise</returns>
  636. public static bool TryGetTextureFormat(uint encoded, bool isSrgb, out FormatInfo format)
  637. {
  638. bool isPacked = (encoded & 0x80000000u) != 0;
  639. if (isPacked)
  640. {
  641. encoded &= ~0x80000000u;
  642. }
  643. encoded |= isSrgb ? 1u << 19 : 0u;
  644. bool found = _textureFormats.TryGetValue((TextureFormat)encoded, out format);
  645. if (found && isPacked && !format.Format.IsDepthOrStencil())
  646. {
  647. // If the packed flag is set, then the components of the pixel are tightly packed into the
  648. // GPU registers on the shader.
  649. // We can get the same behaviour by aliasing the texture as a format with the same amount of
  650. // bytes per pixel, but only a single or the lowest possible number of components.
  651. format = format.BytesPerPixel switch
  652. {
  653. 1 => new FormatInfo(Format.R8Unorm, 1, 1, 1, 1),
  654. 2 => new FormatInfo(Format.R16Unorm, 1, 1, 2, 1),
  655. 4 => new FormatInfo(Format.R32Uint, 1, 1, 4, 1),
  656. 8 => new FormatInfo(Format.R32G32Uint, 1, 1, 8, 2),
  657. 16 => new FormatInfo(Format.R32G32B32A32Uint, 1, 1, 16, 4),
  658. _ => format,
  659. };
  660. }
  661. return found;
  662. }
  663. /// <summary>
  664. /// Try getting the vertex attribute format from an encoded format integer from Maxwell attribute registers.
  665. /// </summary>
  666. /// <param name="encoded">The encoded format integer from the attribute registers</param>
  667. /// <param name="format">The output vertex attribute format</param>
  668. /// <returns>True if the format is valid, false otherwise</returns>
  669. public static bool TryGetAttribFormat(uint encoded, out Format format)
  670. {
  671. return _attribFormats.TryGetValue((VertexAttributeFormat)encoded, out format);
  672. }
  673. /// <summary>
  674. /// Try getting a single component vertex attribute format from an encoded format integer from Maxwell attribute registers.
  675. /// </summary>
  676. /// <param name="encoded">The encoded format integer from the attribute registers</param>
  677. /// <param name="format">The output single component vertex attribute format</param>
  678. /// <param name="componentsCount">Number of components that the format has</param>
  679. /// <returns>True if the format is valid, false otherwise</returns>
  680. public static bool TryGetSingleComponentAttribFormat(uint encoded, out Format format, out int componentsCount)
  681. {
  682. bool result = _singleComponentAttribFormats.TryGetValue((VertexAttributeFormat)encoded, out var tuple);
  683. format = tuple.Item1;
  684. componentsCount = tuple.Item2;
  685. return result;
  686. }
  687. }
  688. }