Format.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. namespace Ryujinx.Graphics.GAL
  2. {
  3. public enum Format
  4. {
  5. R8Unorm,
  6. R8Snorm,
  7. R8Uint,
  8. R8Sint,
  9. R16Float,
  10. R16Unorm,
  11. R16Snorm,
  12. R16Uint,
  13. R16Sint,
  14. R32Float,
  15. R32Uint,
  16. R32Sint,
  17. R8G8Unorm,
  18. R8G8Snorm,
  19. R8G8Uint,
  20. R8G8Sint,
  21. R16G16Float,
  22. R16G16Unorm,
  23. R16G16Snorm,
  24. R16G16Uint,
  25. R16G16Sint,
  26. R32G32Float,
  27. R32G32Uint,
  28. R32G32Sint,
  29. R8G8B8Unorm,
  30. R8G8B8Snorm,
  31. R8G8B8Uint,
  32. R8G8B8Sint,
  33. R16G16B16Float,
  34. R16G16B16Unorm,
  35. R16G16B16Snorm,
  36. R16G16B16Uint,
  37. R16G16B16Sint,
  38. R32G32B32Float,
  39. R32G32B32Uint,
  40. R32G32B32Sint,
  41. R8G8B8A8Unorm,
  42. R8G8B8A8Snorm,
  43. R8G8B8A8Uint,
  44. R8G8B8A8Sint,
  45. R16G16B16A16Float,
  46. R16G16B16A16Unorm,
  47. R16G16B16A16Snorm,
  48. R16G16B16A16Uint,
  49. R16G16B16A16Sint,
  50. R32G32B32A32Float,
  51. R32G32B32A32Uint,
  52. R32G32B32A32Sint,
  53. S8Uint,
  54. D16Unorm,
  55. D24X8Unorm,
  56. D32Float,
  57. D24UnormS8Uint,
  58. D32FloatS8Uint,
  59. R8G8B8X8Srgb,
  60. R8G8B8A8Srgb,
  61. R4G4Unorm,
  62. R4G4B4A4Unorm,
  63. R5G5B5X1Unorm,
  64. R5G5B5A1Unorm,
  65. R5G6B5Unorm,
  66. R10G10B10A2Unorm,
  67. R10G10B10A2Uint,
  68. R11G11B10Float,
  69. R9G9B9E5Float,
  70. Bc1RgbUnorm,
  71. Bc1RgbaUnorm,
  72. Bc2Unorm,
  73. Bc3Unorm,
  74. Bc1RgbSrgb,
  75. Bc1RgbaSrgb,
  76. Bc2Srgb,
  77. Bc3Srgb,
  78. Bc4Unorm,
  79. Bc4Snorm,
  80. Bc5Unorm,
  81. Bc5Snorm,
  82. Bc7Unorm,
  83. Bc7Srgb,
  84. Bc6HSfloat,
  85. Bc6HUfloat,
  86. Etc2RgbUnorm,
  87. Etc2RgbaUnorm,
  88. Etc2RgbSrgb,
  89. Etc2RgbaSrgb,
  90. R8Uscaled,
  91. R8Sscaled,
  92. R16Uscaled,
  93. R16Sscaled,
  94. R32Uscaled,
  95. R32Sscaled,
  96. R8G8Uscaled,
  97. R8G8Sscaled,
  98. R16G16Uscaled,
  99. R16G16Sscaled,
  100. R32G32Uscaled,
  101. R32G32Sscaled,
  102. R8G8B8Uscaled,
  103. R8G8B8Sscaled,
  104. R16G16B16Uscaled,
  105. R16G16B16Sscaled,
  106. R32G32B32Uscaled,
  107. R32G32B32Sscaled,
  108. R8G8B8A8Uscaled,
  109. R8G8B8A8Sscaled,
  110. R16G16B16A16Uscaled,
  111. R16G16B16A16Sscaled,
  112. R32G32B32A32Uscaled,
  113. R32G32B32A32Sscaled,
  114. R10G10B10A2Snorm,
  115. R10G10B10A2Sint,
  116. R10G10B10A2Uscaled,
  117. R10G10B10A2Sscaled,
  118. R8G8B8X8Unorm,
  119. R8G8B8X8Snorm,
  120. R8G8B8X8Uint,
  121. R8G8B8X8Sint,
  122. R16G16B16X16Float,
  123. R16G16B16X16Unorm,
  124. R16G16B16X16Snorm,
  125. R16G16B16X16Uint,
  126. R16G16B16X16Sint,
  127. R32G32B32X32Float,
  128. R32G32B32X32Uint,
  129. R32G32B32X32Sint,
  130. Astc4x4Unorm,
  131. Astc5x4Unorm,
  132. Astc5x5Unorm,
  133. Astc6x5Unorm,
  134. Astc6x6Unorm,
  135. Astc8x5Unorm,
  136. Astc8x6Unorm,
  137. Astc8x8Unorm,
  138. Astc10x5Unorm,
  139. Astc10x6Unorm,
  140. Astc10x8Unorm,
  141. Astc10x10Unorm,
  142. Astc12x10Unorm,
  143. Astc12x12Unorm,
  144. Astc4x4Srgb,
  145. Astc5x4Srgb,
  146. Astc5x5Srgb,
  147. Astc6x5Srgb,
  148. Astc6x6Srgb,
  149. Astc8x5Srgb,
  150. Astc8x6Srgb,
  151. Astc8x8Srgb,
  152. Astc10x5Srgb,
  153. Astc10x6Srgb,
  154. Astc10x8Srgb,
  155. Astc10x10Srgb,
  156. Astc12x10Srgb,
  157. Astc12x12Srgb,
  158. B5G6R5Unorm,
  159. B5G5R5X1Unorm,
  160. B5G5R5A1Unorm,
  161. A1B5G5R5Unorm,
  162. B8G8R8X8Unorm,
  163. B8G8R8A8Unorm,
  164. B8G8R8X8Srgb,
  165. B8G8R8A8Srgb
  166. }
  167. public static class FormatExtensions
  168. {
  169. /// <summary>
  170. /// Checks if the texture format is an ASTC format.
  171. /// </summary>
  172. /// <param name="format">Texture format</param>
  173. /// <returns>True if the texture format is an ASTC format, false otherwise</returns>
  174. public static bool IsAstc(this Format format)
  175. {
  176. return format.IsAstcUnorm() || format.IsAstcSrgb();
  177. }
  178. /// <summary>
  179. /// Checks if the texture format is an ASTC Unorm format.
  180. /// </summary>
  181. /// <param name="format">Texture format</param>
  182. /// <returns>True if the texture format is an ASTC Unorm format, false otherwise</returns>
  183. public static bool IsAstcUnorm(this Format format)
  184. {
  185. switch (format)
  186. {
  187. case Format.Astc4x4Unorm:
  188. case Format.Astc5x4Unorm:
  189. case Format.Astc5x5Unorm:
  190. case Format.Astc6x5Unorm:
  191. case Format.Astc6x6Unorm:
  192. case Format.Astc8x5Unorm:
  193. case Format.Astc8x6Unorm:
  194. case Format.Astc8x8Unorm:
  195. case Format.Astc10x5Unorm:
  196. case Format.Astc10x6Unorm:
  197. case Format.Astc10x8Unorm:
  198. case Format.Astc10x10Unorm:
  199. case Format.Astc12x10Unorm:
  200. case Format.Astc12x12Unorm:
  201. return true;
  202. }
  203. return false;
  204. }
  205. /// <summary>
  206. /// Checks if the texture format is an ASTC SRGB format.
  207. /// </summary>
  208. /// <param name="format">Texture format</param>
  209. /// <returns>True if the texture format is an ASTC SRGB format, false otherwise</returns>
  210. public static bool IsAstcSrgb(this Format format)
  211. {
  212. switch (format)
  213. {
  214. case Format.Astc4x4Srgb:
  215. case Format.Astc5x4Srgb:
  216. case Format.Astc5x5Srgb:
  217. case Format.Astc6x5Srgb:
  218. case Format.Astc6x6Srgb:
  219. case Format.Astc8x5Srgb:
  220. case Format.Astc8x6Srgb:
  221. case Format.Astc8x8Srgb:
  222. case Format.Astc10x5Srgb:
  223. case Format.Astc10x6Srgb:
  224. case Format.Astc10x8Srgb:
  225. case Format.Astc10x10Srgb:
  226. case Format.Astc12x10Srgb:
  227. case Format.Astc12x12Srgb:
  228. return true;
  229. }
  230. return false;
  231. }
  232. /// <summary>
  233. /// Checks if the texture format is a BGR format.
  234. /// </summary>
  235. /// <param name="format">Texture format</param>
  236. /// <returns>True if the texture format is a BGR format, false otherwise</returns>
  237. public static bool IsBgr(this Format format)
  238. {
  239. switch (format)
  240. {
  241. case Format.B5G6R5Unorm:
  242. case Format.B5G5R5X1Unorm:
  243. case Format.B5G5R5A1Unorm:
  244. case Format.B8G8R8X8Unorm:
  245. case Format.B8G8R8A8Unorm:
  246. case Format.B8G8R8X8Srgb:
  247. case Format.B8G8R8A8Srgb:
  248. return true;
  249. }
  250. return false;
  251. }
  252. /// <summary>
  253. /// Checks if the texture format is a depth, stencil or depth-stencil format.
  254. /// </summary>
  255. /// <param name="format">Texture format</param>
  256. /// <returns>True if the format is a depth, stencil or depth-stencil format, false otherwise</returns>
  257. public static bool IsDepthOrStencil(this Format format)
  258. {
  259. switch (format)
  260. {
  261. case Format.D16Unorm:
  262. case Format.D24UnormS8Uint:
  263. case Format.D24X8Unorm:
  264. case Format.D32Float:
  265. case Format.D32FloatS8Uint:
  266. case Format.S8Uint:
  267. return true;
  268. }
  269. return false;
  270. }
  271. /// <summary>
  272. /// Checks if the texture format is an unsigned integer color format.
  273. /// </summary>
  274. /// <param name="format">Texture format</param>
  275. /// <returns>True if the texture format is an unsigned integer color format, false otherwise</returns>
  276. public static bool IsUint(this Format format)
  277. {
  278. switch (format)
  279. {
  280. case Format.R8Uint:
  281. case Format.R16Uint:
  282. case Format.R32Uint:
  283. case Format.R8G8Uint:
  284. case Format.R16G16Uint:
  285. case Format.R32G32Uint:
  286. case Format.R8G8B8Uint:
  287. case Format.R16G16B16Uint:
  288. case Format.R32G32B32Uint:
  289. case Format.R8G8B8A8Uint:
  290. case Format.R16G16B16A16Uint:
  291. case Format.R32G32B32A32Uint:
  292. case Format.R10G10B10A2Uint:
  293. case Format.R8G8B8X8Uint:
  294. case Format.R16G16B16X16Uint:
  295. case Format.R32G32B32X32Uint:
  296. return true;
  297. }
  298. return false;
  299. }
  300. /// <summary>
  301. /// Checks if the texture format is a signed integer color format.
  302. /// </summary>
  303. /// <param name="format">Texture format</param>
  304. /// <returns>True if the texture format is a signed integer color format, false otherwise</returns>
  305. public static bool IsSint(this Format format)
  306. {
  307. switch (format)
  308. {
  309. case Format.R8Sint:
  310. case Format.R16Sint:
  311. case Format.R32Sint:
  312. case Format.R8G8Sint:
  313. case Format.R16G16Sint:
  314. case Format.R32G32Sint:
  315. case Format.R8G8B8Sint:
  316. case Format.R16G16B16Sint:
  317. case Format.R32G32B32Sint:
  318. case Format.R8G8B8A8Sint:
  319. case Format.R16G16B16A16Sint:
  320. case Format.R32G32B32A32Sint:
  321. case Format.R10G10B10A2Sint:
  322. case Format.R8G8B8X8Sint:
  323. case Format.R16G16B16X16Sint:
  324. case Format.R32G32B32X32Sint:
  325. return true;
  326. }
  327. return false;
  328. }
  329. /// <summary>
  330. /// Checks if the texture format is an integer color format.
  331. /// </summary>
  332. /// <param name="format">Texture format</param>
  333. /// <returns>True if the texture format is an integer color format, false otherwise</returns>
  334. public static bool IsInteger(this Format format)
  335. {
  336. return format.IsUint() || format.IsSint();
  337. }
  338. /// <summary>
  339. /// Checks if the texture format is a BC4 compressed format.
  340. /// </summary>
  341. /// <param name="format">Texture format</param>
  342. /// <returns>True if the texture format is a BC4 compressed format, false otherwise</returns>
  343. public static bool IsBc4(this Format format)
  344. {
  345. return format == Format.Bc4Unorm || format == Format.Bc4Snorm;
  346. }
  347. /// <summary>
  348. /// Checks if the texture format is a BC5 compressed format.
  349. /// </summary>
  350. /// <param name="format">Texture format</param>
  351. /// <returns>True if the texture format is a BC5 compressed format, false otherwise</returns>
  352. public static bool IsBc5(this Format format)
  353. {
  354. return format == Format.Bc5Unorm || format == Format.Bc5Snorm;
  355. }
  356. }
  357. }