Format.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. S8UintD24Unorm,
  56. D32Float,
  57. D24UnormS8Uint,
  58. D32FloatS8Uint,
  59. R8G8B8A8Srgb,
  60. R4G4Unorm,
  61. R4G4B4A4Unorm,
  62. R5G5B5X1Unorm,
  63. R5G5B5A1Unorm,
  64. R5G6B5Unorm,
  65. R10G10B10A2Unorm,
  66. R10G10B10A2Uint,
  67. R11G11B10Float,
  68. R9G9B9E5Float,
  69. Bc1RgbaUnorm,
  70. Bc2Unorm,
  71. Bc3Unorm,
  72. Bc1RgbaSrgb,
  73. Bc2Srgb,
  74. Bc3Srgb,
  75. Bc4Unorm,
  76. Bc4Snorm,
  77. Bc5Unorm,
  78. Bc5Snorm,
  79. Bc7Unorm,
  80. Bc7Srgb,
  81. Bc6HSfloat,
  82. Bc6HUfloat,
  83. Etc2RgbUnorm,
  84. Etc2RgbaUnorm,
  85. Etc2RgbPtaUnorm,
  86. Etc2RgbSrgb,
  87. Etc2RgbaSrgb,
  88. Etc2RgbPtaSrgb,
  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. Astc4x4Unorm,
  118. Astc5x4Unorm,
  119. Astc5x5Unorm,
  120. Astc6x5Unorm,
  121. Astc6x6Unorm,
  122. Astc8x5Unorm,
  123. Astc8x6Unorm,
  124. Astc8x8Unorm,
  125. Astc10x5Unorm,
  126. Astc10x6Unorm,
  127. Astc10x8Unorm,
  128. Astc10x10Unorm,
  129. Astc12x10Unorm,
  130. Astc12x12Unorm,
  131. Astc4x4Srgb,
  132. Astc5x4Srgb,
  133. Astc5x5Srgb,
  134. Astc6x5Srgb,
  135. Astc6x6Srgb,
  136. Astc8x5Srgb,
  137. Astc8x6Srgb,
  138. Astc8x8Srgb,
  139. Astc10x5Srgb,
  140. Astc10x6Srgb,
  141. Astc10x8Srgb,
  142. Astc10x10Srgb,
  143. Astc12x10Srgb,
  144. Astc12x12Srgb,
  145. B5G6R5Unorm,
  146. B5G5R5A1Unorm,
  147. A1B5G5R5Unorm,
  148. B8G8R8A8Unorm,
  149. B8G8R8A8Srgb
  150. }
  151. public static class FormatExtensions
  152. {
  153. /// <summary>
  154. /// Checks if the texture format is valid to use as image format.
  155. /// </summary>
  156. /// <param name="format">Texture format</param>
  157. /// <returns>True if the texture can be used as image, false otherwise</returns>
  158. public static bool IsImageCompatible(this Format format)
  159. {
  160. switch (format)
  161. {
  162. case Format.R8Unorm:
  163. case Format.R8Snorm:
  164. case Format.R8Uint:
  165. case Format.R8Sint:
  166. case Format.R16Float:
  167. case Format.R16Unorm:
  168. case Format.R16Snorm:
  169. case Format.R16Uint:
  170. case Format.R16Sint:
  171. case Format.R32Float:
  172. case Format.R32Uint:
  173. case Format.R32Sint:
  174. case Format.R8G8Unorm:
  175. case Format.R8G8Snorm:
  176. case Format.R8G8Uint:
  177. case Format.R8G8Sint:
  178. case Format.R16G16Float:
  179. case Format.R16G16Unorm:
  180. case Format.R16G16Snorm:
  181. case Format.R16G16Uint:
  182. case Format.R16G16Sint:
  183. case Format.R32G32Float:
  184. case Format.R32G32Uint:
  185. case Format.R32G32Sint:
  186. case Format.R8G8B8A8Unorm:
  187. case Format.R8G8B8A8Snorm:
  188. case Format.R8G8B8A8Uint:
  189. case Format.R8G8B8A8Sint:
  190. case Format.R16G16B16A16Float:
  191. case Format.R16G16B16A16Unorm:
  192. case Format.R16G16B16A16Snorm:
  193. case Format.R16G16B16A16Uint:
  194. case Format.R16G16B16A16Sint:
  195. case Format.R32G32B32A32Float:
  196. case Format.R32G32B32A32Uint:
  197. case Format.R32G32B32A32Sint:
  198. case Format.R10G10B10A2Unorm:
  199. case Format.R10G10B10A2Uint:
  200. case Format.R11G11B10Float:
  201. return true;
  202. }
  203. return false;
  204. }
  205. /// <summary>
  206. /// Checks if the texture format is valid to use as render target color format.
  207. /// </summary>
  208. /// <param name="format">Texture format</param>
  209. /// <returns>True if the texture can be used as render target, false otherwise</returns>
  210. public static bool IsRtColorCompatible(this Format format)
  211. {
  212. switch (format)
  213. {
  214. case Format.R32G32B32A32Float:
  215. case Format.R32G32B32A32Sint:
  216. case Format.R32G32B32A32Uint:
  217. case Format.R16G16B16A16Unorm:
  218. case Format.R16G16B16A16Snorm:
  219. case Format.R16G16B16A16Sint:
  220. case Format.R16G16B16A16Uint:
  221. case Format.R16G16B16A16Float:
  222. case Format.R32G32Float:
  223. case Format.R32G32Sint:
  224. case Format.R32G32Uint:
  225. case Format.B8G8R8A8Unorm:
  226. case Format.B8G8R8A8Srgb:
  227. case Format.R10G10B10A2Unorm:
  228. case Format.R10G10B10A2Uint:
  229. case Format.R8G8B8A8Unorm:
  230. case Format.R8G8B8A8Srgb:
  231. case Format.R8G8B8A8Snorm:
  232. case Format.R8G8B8A8Sint:
  233. case Format.R8G8B8A8Uint:
  234. case Format.R16G16Unorm:
  235. case Format.R16G16Snorm:
  236. case Format.R16G16Sint:
  237. case Format.R16G16Uint:
  238. case Format.R16G16Float:
  239. case Format.R11G11B10Float:
  240. case Format.R32Sint:
  241. case Format.R32Uint:
  242. case Format.R32Float:
  243. case Format.B5G6R5Unorm:
  244. case Format.B5G5R5A1Unorm:
  245. case Format.R8G8Unorm:
  246. case Format.R8G8Snorm:
  247. case Format.R8G8Sint:
  248. case Format.R8G8Uint:
  249. case Format.R16Unorm:
  250. case Format.R16Snorm:
  251. case Format.R16Sint:
  252. case Format.R16Uint:
  253. case Format.R16Float:
  254. case Format.R8Unorm:
  255. case Format.R8Snorm:
  256. case Format.R8Sint:
  257. case Format.R8Uint:
  258. return true;
  259. }
  260. return false;
  261. }
  262. /// <summary>
  263. /// Checks if the texture format is an ASTC format.
  264. /// </summary>
  265. /// <param name="format">Texture format</param>
  266. /// <returns>True if the texture format is an ASTC format, false otherwise</returns>
  267. public static bool IsAstc(this Format format)
  268. {
  269. return format.IsAstcUnorm() || format.IsAstcSrgb();
  270. }
  271. /// <summary>
  272. /// Checks if the texture format is an ASTC Unorm format.
  273. /// </summary>
  274. /// <param name="format">Texture format</param>
  275. /// <returns>True if the texture format is an ASTC Unorm format, false otherwise</returns>
  276. public static bool IsAstcUnorm(this Format format)
  277. {
  278. switch (format)
  279. {
  280. case Format.Astc4x4Unorm:
  281. case Format.Astc5x4Unorm:
  282. case Format.Astc5x5Unorm:
  283. case Format.Astc6x5Unorm:
  284. case Format.Astc6x6Unorm:
  285. case Format.Astc8x5Unorm:
  286. case Format.Astc8x6Unorm:
  287. case Format.Astc8x8Unorm:
  288. case Format.Astc10x5Unorm:
  289. case Format.Astc10x6Unorm:
  290. case Format.Astc10x8Unorm:
  291. case Format.Astc10x10Unorm:
  292. case Format.Astc12x10Unorm:
  293. case Format.Astc12x12Unorm:
  294. return true;
  295. }
  296. return false;
  297. }
  298. /// <summary>
  299. /// Checks if the texture format is an ASTC SRGB format.
  300. /// </summary>
  301. /// <param name="format">Texture format</param>
  302. /// <returns>True if the texture format is an ASTC SRGB format, false otherwise</returns>
  303. public static bool IsAstcSrgb(this Format format)
  304. {
  305. switch (format)
  306. {
  307. case Format.Astc4x4Srgb:
  308. case Format.Astc5x4Srgb:
  309. case Format.Astc5x5Srgb:
  310. case Format.Astc6x5Srgb:
  311. case Format.Astc6x6Srgb:
  312. case Format.Astc8x5Srgb:
  313. case Format.Astc8x6Srgb:
  314. case Format.Astc8x8Srgb:
  315. case Format.Astc10x5Srgb:
  316. case Format.Astc10x6Srgb:
  317. case Format.Astc10x8Srgb:
  318. case Format.Astc10x10Srgb:
  319. case Format.Astc12x10Srgb:
  320. case Format.Astc12x12Srgb:
  321. return true;
  322. }
  323. return false;
  324. }
  325. /// <summary>
  326. /// Checks if the texture format is a BGR format.
  327. /// </summary>
  328. /// <param name="format">Texture format</param>
  329. /// <returns>True if the texture format is a BGR format, false otherwise</returns>
  330. public static bool IsBgr(this Format format)
  331. {
  332. switch (format)
  333. {
  334. case Format.B5G6R5Unorm:
  335. case Format.B5G5R5A1Unorm:
  336. case Format.B8G8R8A8Unorm:
  337. case Format.B8G8R8A8Srgb:
  338. return true;
  339. }
  340. return false;
  341. }
  342. /// <summary>
  343. /// Checks if the texture format is a depth, stencil or depth-stencil format.
  344. /// </summary>
  345. /// <param name="format">Texture format</param>
  346. /// <returns>True if the format is a depth, stencil or depth-stencil format, false otherwise</returns>
  347. public static bool IsDepthOrStencil(this Format format)
  348. {
  349. switch (format)
  350. {
  351. case Format.D16Unorm:
  352. case Format.D24UnormS8Uint:
  353. case Format.S8UintD24Unorm:
  354. case Format.D32Float:
  355. case Format.D32FloatS8Uint:
  356. case Format.S8Uint:
  357. return true;
  358. }
  359. return false;
  360. }
  361. /// <summary>
  362. /// Checks if the texture format is an unsigned integer color format.
  363. /// </summary>
  364. /// <param name="format">Texture format</param>
  365. /// <returns>True if the texture format is an unsigned integer color format, false otherwise</returns>
  366. public static bool IsUint(this Format format)
  367. {
  368. switch (format)
  369. {
  370. case Format.R8Uint:
  371. case Format.R16Uint:
  372. case Format.R32Uint:
  373. case Format.R8G8Uint:
  374. case Format.R16G16Uint:
  375. case Format.R32G32Uint:
  376. case Format.R8G8B8Uint:
  377. case Format.R16G16B16Uint:
  378. case Format.R32G32B32Uint:
  379. case Format.R8G8B8A8Uint:
  380. case Format.R16G16B16A16Uint:
  381. case Format.R32G32B32A32Uint:
  382. case Format.R10G10B10A2Uint:
  383. return true;
  384. }
  385. return false;
  386. }
  387. /// <summary>
  388. /// Checks if the texture format is a signed integer color format.
  389. /// </summary>
  390. /// <param name="format">Texture format</param>
  391. /// <returns>True if the texture format is a signed integer color format, false otherwise</returns>
  392. public static bool IsSint(this Format format)
  393. {
  394. switch (format)
  395. {
  396. case Format.R8Sint:
  397. case Format.R16Sint:
  398. case Format.R32Sint:
  399. case Format.R8G8Sint:
  400. case Format.R16G16Sint:
  401. case Format.R32G32Sint:
  402. case Format.R8G8B8Sint:
  403. case Format.R16G16B16Sint:
  404. case Format.R32G32B32Sint:
  405. case Format.R8G8B8A8Sint:
  406. case Format.R16G16B16A16Sint:
  407. case Format.R32G32B32A32Sint:
  408. case Format.R10G10B10A2Sint:
  409. return true;
  410. }
  411. return false;
  412. }
  413. /// <summary>
  414. /// Checks if the texture format is an integer color format.
  415. /// </summary>
  416. /// <param name="format">Texture format</param>
  417. /// <returns>True if the texture format is an integer color format, false otherwise</returns>
  418. public static bool IsInteger(this Format format)
  419. {
  420. return format.IsUint() || format.IsSint();
  421. }
  422. }
  423. }