Format.cs 11 KB

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