Format.cs 11 KB

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