Format.cs 11 KB

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