Format.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RHI.Reflect/Format.h>
  9. #include <Atom/RHI.Reflect/Bits.h>
  10. #include <AzCore/std/algorithm.h>
  11. namespace AZ::RHI
  12. {
  13. uint32_t GetFormatSize(Format format)
  14. {
  15. switch (format)
  16. {
  17. case Format::Unknown:
  18. return 0;
  19. case Format::R32G32B32A32_FLOAT:
  20. case Format::R32G32B32A32_UINT:
  21. case Format::R32G32B32A32_SINT:
  22. return 16;
  23. case Format::R32G32B32_FLOAT:
  24. case Format::R32G32B32_UINT:
  25. case Format::R32G32B32_SINT:
  26. return 12;
  27. case Format::R16G16B16A16_FLOAT:
  28. case Format::R16G16B16A16_UNORM:
  29. case Format::R16G16B16A16_UINT:
  30. case Format::R16G16B16A16_SNORM:
  31. case Format::R16G16B16A16_SINT:
  32. case Format::R32G32_FLOAT:
  33. case Format::R32G32_UINT:
  34. case Format::R32G32_SINT:
  35. case Format::D32_FLOAT_S8X24_UINT:
  36. case Format::Y416:
  37. case Format::Y210:
  38. case Format::Y216:
  39. return 8;
  40. case Format::R10G10B10A2_UNORM:
  41. case Format::R10G10B10A2_UINT:
  42. case Format::R11G11B10_FLOAT:
  43. case Format::R8G8B8A8_UNORM:
  44. case Format::R8G8B8A8_UNORM_SRGB:
  45. case Format::R8G8B8A8_UINT:
  46. case Format::R8G8B8A8_SNORM:
  47. case Format::R8G8B8A8_SINT:
  48. case Format::R16G16_FLOAT:
  49. case Format::R16G16_UNORM:
  50. case Format::R16G16_UINT:
  51. case Format::R16G16_SNORM:
  52. case Format::R16G16_SINT:
  53. case Format::D32_FLOAT:
  54. case Format::R32_FLOAT:
  55. case Format::R32_UINT:
  56. case Format::R32_SINT:
  57. case Format::D24_UNORM_S8_UINT:
  58. case Format::R9G9B9E5_SHAREDEXP:
  59. case Format::R8G8_B8G8_UNORM:
  60. case Format::G8R8_G8B8_UNORM:
  61. case Format::B8G8R8A8_UNORM:
  62. case Format::B8G8R8A8_SNORM:
  63. case Format::B8G8R8X8_UNORM:
  64. case Format::R10G10B10_XR_BIAS_A2_UNORM:
  65. case Format::B8G8R8A8_UNORM_SRGB:
  66. case Format::B8G8R8X8_UNORM_SRGB:
  67. case Format::AYUV:
  68. case Format::Y410:
  69. case Format::YUY2:
  70. return 4;
  71. case Format::P010:
  72. case Format::P016:
  73. return 24;
  74. case Format::R8G8_UNORM:
  75. case Format::R8G8_UINT:
  76. case Format::R8G8_SNORM:
  77. case Format::R8G8_SINT:
  78. case Format::R16_FLOAT:
  79. case Format::D16_UNORM:
  80. case Format::R16_UNORM:
  81. case Format::R16_UINT:
  82. case Format::R16_SNORM:
  83. case Format::R16_SINT:
  84. case Format::R5G6B5_UNORM:
  85. case Format::B5G6R5_UNORM:
  86. case Format::B5G5R5A1_UNORM:
  87. case Format::A8P8:
  88. case Format::B4G4R4A4_UNORM:
  89. return 2;
  90. case Format::NV12:
  91. case Format::NV11:
  92. return 12;
  93. case Format::R8_UNORM:
  94. case Format::R8_UINT:
  95. case Format::R8_SNORM:
  96. case Format::R8_SINT:
  97. case Format::A8_UNORM:
  98. case Format::AI44:
  99. case Format::IA44:
  100. case Format::P8:
  101. case Format::R1_UNORM:
  102. return 1;
  103. case Format::BC1_UNORM:
  104. case Format::BC1_UNORM_SRGB:
  105. case Format::BC4_UNORM:
  106. case Format::BC4_SNORM:
  107. case Format::EAC_R11_UNORM:
  108. case Format::EAC_R11_SNORM:
  109. case Format::ETC2_UNORM:
  110. case Format::ETC2_UNORM_SRGB:
  111. case Format::ETC2A1_UNORM:
  112. case Format::ETC2A1_UNORM_SRGB:
  113. return 8;
  114. case Format::BC2_UNORM:
  115. case Format::BC2_UNORM_SRGB:
  116. case Format::BC3_UNORM:
  117. case Format::BC3_UNORM_SRGB:
  118. case Format::BC5_UNORM:
  119. case Format::BC5_SNORM:
  120. case Format::BC6H_UF16:
  121. case Format::BC6H_SF16:
  122. case Format::BC7_UNORM:
  123. case Format::BC7_UNORM_SRGB:
  124. case Format::EAC_RG11_UNORM:
  125. case Format::EAC_RG11_SNORM:
  126. case Format::ETC2A_UNORM:
  127. case Format::ETC2A_UNORM_SRGB:
  128. case Format::ASTC_4x4_UNORM:
  129. case Format::ASTC_4x4_UNORM_SRGB:
  130. case Format::ASTC_5x4_UNORM:
  131. case Format::ASTC_5x4_UNORM_SRGB:
  132. case Format::ASTC_5x5_UNORM:
  133. case Format::ASTC_5x5_UNORM_SRGB:
  134. case Format::ASTC_6x5_UNORM:
  135. case Format::ASTC_6x5_UNORM_SRGB:
  136. case Format::ASTC_6x6_UNORM:
  137. case Format::ASTC_6x6_UNORM_SRGB:
  138. case Format::ASTC_8x5_UNORM:
  139. case Format::ASTC_8x5_UNORM_SRGB:
  140. case Format::ASTC_8x6_UNORM:
  141. case Format::ASTC_8x6_UNORM_SRGB:
  142. case Format::ASTC_8x8_UNORM:
  143. case Format::ASTC_8x8_UNORM_SRGB:
  144. case Format::ASTC_10x5_UNORM:
  145. case Format::ASTC_10x5_UNORM_SRGB:
  146. case Format::ASTC_10x6_UNORM:
  147. case Format::ASTC_10x6_UNORM_SRGB:
  148. case Format::ASTC_10x8_UNORM:
  149. case Format::ASTC_10x8_UNORM_SRGB:
  150. case Format::ASTC_10x10_UNORM:
  151. case Format::ASTC_10x10_UNORM_SRGB:
  152. case Format::ASTC_12x10_UNORM:
  153. case Format::ASTC_12x10_UNORM_SRGB:
  154. case Format::ASTC_12x12_UNORM:
  155. case Format::ASTC_12x12_UNORM_SRGB:
  156. return 16;
  157. default:
  158. AZ_Assert(false, "Unimplemented format");
  159. return 0;
  160. }
  161. }
  162. uint32_t GetFormatComponentCount(Format format)
  163. {
  164. switch (format)
  165. {
  166. case Format::Unknown:
  167. return 0;
  168. case Format::R32G32B32A32_FLOAT:
  169. case Format::R32G32B32A32_UINT:
  170. case Format::R32G32B32A32_SINT:
  171. return 4;
  172. case Format::R32G32B32_FLOAT:
  173. case Format::R32G32B32_UINT:
  174. case Format::R32G32B32_SINT:
  175. return 3;
  176. case Format::R16G16B16A16_FLOAT:
  177. case Format::R16G16B16A16_UNORM:
  178. case Format::R16G16B16A16_UINT:
  179. case Format::R16G16B16A16_SNORM:
  180. case Format::R16G16B16A16_SINT:
  181. return 4;
  182. case Format::R32G32_FLOAT:
  183. case Format::R32G32_UINT:
  184. case Format::R32G32_SINT:
  185. return 2;
  186. case Format::D32_FLOAT_S8X24_UINT:
  187. return 3;
  188. case Format::Y416:
  189. case Format::Y210:
  190. case Format::Y216:
  191. return 4;
  192. case Format::R10G10B10A2_UNORM:
  193. case Format::R10G10B10A2_UINT:
  194. return 4;
  195. case Format::R11G11B10_FLOAT:
  196. return 3;
  197. case Format::R8G8B8A8_UNORM:
  198. case Format::R8G8B8A8_UNORM_SRGB:
  199. case Format::R8G8B8A8_UINT:
  200. case Format::R8G8B8A8_SNORM:
  201. case Format::R8G8B8A8_SINT:
  202. case Format::A8B8G8R8_UNORM:
  203. case Format::A8B8G8R8_UNORM_SRGB:
  204. case Format::A8B8G8R8_SNORM:
  205. return 4;
  206. case Format::R16G16_FLOAT:
  207. case Format::R16G16_UNORM:
  208. case Format::R16G16_UINT:
  209. case Format::R16G16_SNORM:
  210. case Format::R16G16_SINT:
  211. return 2;
  212. case Format::D32_FLOAT:
  213. case Format::R32_FLOAT:
  214. case Format::R32_UINT:
  215. case Format::R32_SINT:
  216. return 1;
  217. case Format::D24_UNORM_S8_UINT:
  218. return 2;
  219. case Format::R9G9B9E5_SHAREDEXP:
  220. return 3;
  221. case Format::R8G8_B8G8_UNORM:
  222. case Format::G8R8_G8B8_UNORM:
  223. return 3; // One entry represents a pair of RGB colors, where R/B are repeated.
  224. case Format::B8G8R8A8_UNORM:
  225. return 4;
  226. case Format::B8G8R8A8_SNORM:
  227. return 4;
  228. case Format::B8G8R8X8_UNORM:
  229. return 3;
  230. case Format::R10G10B10_XR_BIAS_A2_UNORM:
  231. return 4;
  232. case Format::B8G8R8A8_UNORM_SRGB:
  233. return 4;
  234. case Format::B8G8R8X8_UNORM_SRGB:
  235. return 3;
  236. case Format::AYUV:
  237. case Format::Y410:
  238. case Format::YUY2:
  239. return 4;
  240. case Format::P010:
  241. case Format::P016:
  242. return 3; // Not sure this is right
  243. case Format::R8G8_UNORM:
  244. case Format::R8G8_UINT:
  245. case Format::R8G8_SNORM:
  246. case Format::R8G8_SINT:
  247. return 2;
  248. case Format::R16_FLOAT:
  249. case Format::D16_UNORM:
  250. case Format::R16_UNORM:
  251. case Format::R16_UINT:
  252. case Format::R16_SNORM:
  253. case Format::R16_SINT:
  254. return 1;
  255. case Format::R5G6B5_UNORM:
  256. case Format::B5G6R5_UNORM:
  257. return 3;
  258. case Format::B5G5R5A1_UNORM:
  259. return 4;
  260. case Format::A8P8:
  261. return 2;
  262. case Format::B4G4R4A4_UNORM:
  263. return 4;
  264. case Format::NV12:
  265. case Format::NV11:
  266. return 3;
  267. case Format::R8_UNORM:
  268. case Format::R8_UINT:
  269. case Format::R8_SNORM:
  270. case Format::R8_SINT:
  271. case Format::A8_UNORM:
  272. return 1;
  273. case Format::AI44:
  274. case Format::IA44:
  275. case Format::P8:
  276. return 1; // Not sure this is right. These are palletized formats.
  277. case Format::R1_UNORM:
  278. return 1;
  279. case Format::BC1_UNORM:
  280. case Format::BC1_UNORM_SRGB:
  281. return 4;
  282. case Format::BC4_UNORM:
  283. case Format::BC4_SNORM:
  284. return 1;
  285. case Format::BC2_UNORM:
  286. case Format::BC2_UNORM_SRGB:
  287. case Format::BC3_UNORM:
  288. case Format::BC3_UNORM_SRGB:
  289. return 4;
  290. case Format::BC5_UNORM:
  291. case Format::BC5_SNORM:
  292. return 2;
  293. case Format::BC6H_UF16:
  294. case Format::BC6H_SF16:
  295. return 3;
  296. case Format::BC7_UNORM:
  297. case Format::BC7_UNORM_SRGB:
  298. return 4; // May actually represent 3 or 4 elements depending on the compression settings
  299. case Format::ASTC_4x4_UNORM:
  300. case Format::ASTC_4x4_UNORM_SRGB:
  301. case Format::ASTC_5x4_UNORM:
  302. case Format::ASTC_5x4_UNORM_SRGB:
  303. case Format::ASTC_5x5_UNORM:
  304. case Format::ASTC_5x5_UNORM_SRGB:
  305. case Format::ASTC_6x5_UNORM:
  306. case Format::ASTC_6x5_UNORM_SRGB:
  307. case Format::ASTC_6x6_UNORM:
  308. case Format::ASTC_6x6_UNORM_SRGB:
  309. case Format::ASTC_8x5_UNORM:
  310. case Format::ASTC_8x5_UNORM_SRGB:
  311. case Format::ASTC_8x6_UNORM:
  312. case Format::ASTC_8x6_UNORM_SRGB:
  313. case Format::ASTC_8x8_UNORM:
  314. case Format::ASTC_8x8_UNORM_SRGB:
  315. case Format::ASTC_10x5_UNORM:
  316. case Format::ASTC_10x5_UNORM_SRGB:
  317. case Format::ASTC_10x6_UNORM:
  318. case Format::ASTC_10x6_UNORM_SRGB:
  319. case Format::ASTC_10x8_UNORM:
  320. case Format::ASTC_10x8_UNORM_SRGB:
  321. case Format::ASTC_10x10_UNORM:
  322. case Format::ASTC_10x10_UNORM_SRGB:
  323. case Format::ASTC_12x10_UNORM:
  324. case Format::ASTC_12x10_UNORM_SRGB:
  325. case Format::ASTC_12x12_UNORM:
  326. case Format::ASTC_12x12_UNORM_SRGB:
  327. return 4;
  328. case Format::ETC2_UNORM:
  329. case Format::ETC2_UNORM_SRGB:
  330. return 3;
  331. case Format::ETC2A_UNORM:
  332. case Format::ETC2A_UNORM_SRGB:
  333. case Format::ETC2A1_UNORM:
  334. case Format::ETC2A1_UNORM_SRGB:
  335. return 4;
  336. default:
  337. AZ_Assert(false, "Unimplemented format");
  338. return 0;
  339. }
  340. }
  341. const char* ToString(Format format)
  342. {
  343. switch (format)
  344. {
  345. case Format::Unknown: return "Unknown";
  346. case Format::R32G32B32A32_FLOAT: return "R32G32B32A32_FLOAT";
  347. case Format::R32G32B32A32_UINT: return "R32G32B32A32_UINT";
  348. case Format::R32G32B32A32_SINT: return "R32G32B32A32_SINT";
  349. case Format::R32G32B32_FLOAT: return "R32G32B32_FLOAT";
  350. case Format::R32G32B32_UINT: return "R32G32B32_UINT";
  351. case Format::R32G32B32_SINT: return "R32G32B32_SINT";
  352. case Format::R16G16B16A16_FLOAT: return "R16G16B16A16_FLOAT";
  353. case Format::R16G16B16A16_UNORM: return "R16G16B16A16_UNORM";
  354. case Format::R16G16B16A16_UINT: return "R16G16B16A16_UINT";
  355. case Format::R16G16B16A16_SNORM: return "R16G16B16A16_SNORM";
  356. case Format::R16G16B16A16_SINT: return "R16G16B16A16_SINT";
  357. case Format::R32G32_FLOAT: return "R32G32_FLOAT";
  358. case Format::R32G32_UINT: return "R32G32_UINT";
  359. case Format::R32G32_SINT: return "R32G32_SINT";
  360. case Format::D32_FLOAT_S8X24_UINT: return "D32_FLOAT_S8X24_UINT";
  361. case Format::Y416: return "Y416";
  362. case Format::Y210: return "Y210";
  363. case Format::Y216: return "Y216";
  364. case Format::R10G10B10A2_UNORM: return "R10G10B10A2_UNORM";
  365. case Format::R10G10B10A2_UINT: return "R10G10B10A2_UINT";
  366. case Format::R11G11B10_FLOAT: return "R11G11B10_FLOAT";
  367. case Format::R8G8B8A8_UNORM: return "R8G8B8A8_UNORM";
  368. case Format::R8G8B8A8_UNORM_SRGB: return "R8G8B8A8_UNORM_SRGB";
  369. case Format::R8G8B8A8_UINT: return "R8G8B8A8_UINT";
  370. case Format::R8G8B8A8_SNORM: return "R8G8B8A8_SNORM";
  371. case Format::R8G8B8A8_SINT: return "R8G8B8A8_SINT";
  372. case Format::A8B8G8R8_UNORM: return "A8B8G8R8_UNORM";
  373. case Format::A8B8G8R8_UNORM_SRGB: return "A8B8G8R8_UNORM_SRGB";
  374. case Format::A8B8G8R8_SNORM: return "A8B8G8R8_SNORM";
  375. case Format::R16G16_FLOAT: return "R16G16_FLOAT";
  376. case Format::R16G16_UNORM: return "R16G16_UNORM";
  377. case Format::R16G16_UINT: return "R16G16_UINT";
  378. case Format::R16G16_SNORM: return "R16G16_SNORM";
  379. case Format::R16G16_SINT: return "R16G16_SINT";
  380. case Format::D32_FLOAT: return "D32_FLOAT";
  381. case Format::R32_FLOAT: return "R32_FLOAT";
  382. case Format::R32_UINT: return "R32_UINT";
  383. case Format::R32_SINT: return "R32_SINT";
  384. case Format::D24_UNORM_S8_UINT: return "D24_UNORM_S8_UINT";
  385. case Format::R9G9B9E5_SHAREDEXP: return "R9G9B9E5_SHAREDEXP";
  386. case Format::R8G8_B8G8_UNORM: return "R8G8_B8G8_UNORM";
  387. case Format::G8R8_G8B8_UNORM: return "G8R8_G8B8_UNORM";
  388. case Format::B8G8R8A8_UNORM: return "B8G8R8A8_UNORM";
  389. case Format::B8G8R8A8_SNORM: return "B8G8R8A8_SNORM";
  390. case Format::B8G8R8X8_UNORM: return "B8G8R8X8_UNORM";
  391. case Format::R10G10B10_XR_BIAS_A2_UNORM: return "R10G10B10_XR_BIAS_A2_UNORM";
  392. case Format::B8G8R8A8_UNORM_SRGB: return "B8G8R8A8_UNORM_SRGB";
  393. case Format::B8G8R8X8_UNORM_SRGB: return "B8G8R8X8_UNORM_SRGB";
  394. case Format::AYUV: return "AYUV";
  395. case Format::Y410: return "Y410";
  396. case Format::YUY2: return "YUY2";
  397. case Format::P010: return "P010";
  398. case Format::P016: return "P016";
  399. case Format::R8G8_UNORM: return "R8G8_UNORM";
  400. case Format::R8G8_UINT: return "R8G8_UINT";
  401. case Format::R8G8_SNORM: return "R8G8_SNORM";
  402. case Format::R8G8_SINT: return "R8G8_SINT";
  403. case Format::R16_FLOAT: return "R16_FLOAT";
  404. case Format::D16_UNORM: return "D16_UNORM";
  405. case Format::R16_UNORM: return "R16_UNORM";
  406. case Format::R16_UINT: return "R16_UINT";
  407. case Format::R16_SNORM: return "R16_SNORM";
  408. case Format::R16_SINT: return "R16_SINT";
  409. case Format::B5G6R5_UNORM: return "B5G6R5_UNORM";
  410. case Format::B5G5R5A1_UNORM: return "B5G5R5A1_UNORM";
  411. case Format::A8P8: return "A8P8";
  412. case Format::B4G4R4A4_UNORM: return "B4G4R4A4_UNORM";
  413. case Format::NV12: return "NV12";
  414. case Format::NV11: return "NV11";
  415. case Format::R8_UNORM: return "R8_UNORM";
  416. case Format::R8_UINT: return "R8_UINT";
  417. case Format::R8_SNORM: return "R8_SNORM";
  418. case Format::R8_SINT: return "R8_SINT";
  419. case Format::A8_UNORM: return "A8_UNORM";
  420. case Format::AI44: return "AI44";
  421. case Format::IA44: return "IA44";
  422. case Format::P8: return "P8";
  423. case Format::R1_UNORM: return "R1_UNORM";
  424. case Format::BC1_UNORM: return "BC1_UNORM";
  425. case Format::BC1_UNORM_SRGB: return "BC1_UNORM_SRGB";
  426. case Format::BC4_UNORM: return "BC4_UNORM";
  427. case Format::BC4_SNORM: return "BC4_SNORM";
  428. case Format::BC2_UNORM: return "BC2_UNORM";
  429. case Format::BC2_UNORM_SRGB: return "BC2_UNORM_SRGB";
  430. case Format::BC3_UNORM: return "BC3_UNORM";
  431. case Format::BC3_UNORM_SRGB: return "BC3_UNORM_SRGB";
  432. case Format::BC5_UNORM: return "BC5_UNORM";
  433. case Format::BC5_SNORM: return "BC5_SNORM";
  434. case Format::BC6H_UF16: return "BC6H_UF16";
  435. case Format::BC6H_SF16: return "BC6H_SF16";
  436. case Format::BC7_UNORM: return "BC7_UNORM";
  437. case Format::BC7_UNORM_SRGB: return "BC7_UNORM_SRGB";
  438. case Format::ASTC_4x4_UNORM: return "ASTC_4x4_UNORM";
  439. case Format::ASTC_4x4_UNORM_SRGB: return "ASTC_4x4_UNORM_SRGB";
  440. case Format::ASTC_5x4_UNORM: return "ASTC_5x4_UNORM";
  441. case Format::ASTC_5x4_UNORM_SRGB: return "ASTC_5x4_UNORM_SRGB";
  442. case Format::ASTC_5x5_UNORM: return "ASTC_5x5_UNORM";
  443. case Format::ASTC_5x5_UNORM_SRGB: return "ASTC_5x5_UNORM_SRGB";
  444. case Format::ASTC_6x5_UNORM: return "ASTC_6x5_UNORM";
  445. case Format::ASTC_6x5_UNORM_SRGB: return "ASTC_6x5_UNORM_SRGB";
  446. case Format::ASTC_6x6_UNORM: return "ASTC_6x6_UNORM";
  447. case Format::ASTC_6x6_UNORM_SRGB: return "ASTC_6x6_UNORM_SRGB";
  448. case Format::ASTC_8x5_UNORM: return "ASTC_8x5_UNORM";
  449. case Format::ASTC_8x5_UNORM_SRGB: return "ASTC_8x5_UNORM_SRGB";
  450. case Format::ASTC_8x6_UNORM: return "ASTC_8x6_UNORM";
  451. case Format::ASTC_8x6_UNORM_SRGB: return "ASTC_8x6_UNORM_SRGB";
  452. case Format::ASTC_8x8_UNORM: return "ASTC_8x8_UNORM";
  453. case Format::ASTC_8x8_UNORM_SRGB: return "ASTC_8x8_UNORM_SRGB";
  454. case Format::ASTC_10x5_UNORM: return "ASTC_10x5_UNORM";
  455. case Format::ASTC_10x5_UNORM_SRGB: return "ASTC_10x5_UNORM_SRGB";
  456. case Format::ASTC_10x6_UNORM: return "ASTC_10x6_UNORM";
  457. case Format::ASTC_10x6_UNORM_SRGB: return "ASTC_10x6_UNORM_SRGB";
  458. case Format::ASTC_10x8_UNORM: return "ASTC_10x8_UNORM";
  459. case Format::ASTC_10x8_UNORM_SRGB: return "ASTC_10x8_UNORM_SRGB";
  460. case Format::ASTC_10x10_UNORM: return "ASTC_10x10_UNORM";
  461. case Format::ASTC_10x10_UNORM_SRGB: return "ASTC_10x10_UNORM_SRGB";
  462. case Format::ASTC_12x10_UNORM: return "ASTC_12x10_UNORM";
  463. case Format::ASTC_12x10_UNORM_SRGB: return "ASTC_12x10_UNORM_SRGB";
  464. case Format::ASTC_12x12_UNORM: return "ASTC_12x12_UNORM";
  465. case Format::ASTC_12x12_UNORM_SRGB: return "ASTC_12x12_UNORM_SRGB";
  466. case Format::ETC2_UNORM: return "ETC2_UNORM";
  467. case Format::ETC2_UNORM_SRGB: return "ETC2_UNORM_SRGB";
  468. case Format::ETC2A1_UNORM: return "ETC2A1_UNORM";
  469. case Format::ETC2A1_UNORM_SRGB: return "ETC2A1_UNORM_SRGB";
  470. case Format::ETC2A_UNORM: return "ETC2A_UNORM";
  471. case Format::ETC2A_UNORM_SRGB: return "ETC2A_UNORM_SRGB";
  472. }
  473. return "<<Format Value Error>>";
  474. }
  475. RHI::Size GetFormatDimensionAlignment(Format format)
  476. {
  477. switch (format)
  478. {
  479. case Format::BC1_UNORM:
  480. case Format::BC1_UNORM_SRGB:
  481. case Format::BC4_UNORM:
  482. case Format::BC4_SNORM:
  483. case Format::BC2_UNORM:
  484. case Format::BC2_UNORM_SRGB:
  485. case Format::BC3_UNORM:
  486. case Format::BC3_UNORM_SRGB:
  487. case Format::BC5_UNORM:
  488. case Format::BC5_SNORM:
  489. case Format::BC6H_UF16:
  490. case Format::BC6H_SF16:
  491. case Format::BC7_UNORM:
  492. case Format::BC7_UNORM_SRGB:
  493. case Format::ETC2_UNORM:
  494. case Format::ETC2_UNORM_SRGB:
  495. case Format::ETC2A_UNORM:
  496. case Format::ETC2A_UNORM_SRGB:
  497. case Format::ETC2A1_UNORM:
  498. case Format::ETC2A1_UNORM_SRGB:
  499. case Format::EAC_RG11_UNORM:
  500. case Format::EAC_RG11_SNORM:
  501. case Format::EAC_R11_UNORM:
  502. case Format::EAC_R11_SNORM:
  503. case Format::ASTC_4x4_UNORM:
  504. case Format::ASTC_4x4_UNORM_SRGB:
  505. return RHI::Size(4, 4, 1);
  506. case Format::ASTC_5x4_UNORM:
  507. case Format::ASTC_5x4_UNORM_SRGB:
  508. return RHI::Size(5, 4, 1);
  509. case Format::ASTC_5x5_UNORM:
  510. case Format::ASTC_5x5_UNORM_SRGB:
  511. return RHI::Size(5, 5, 1);
  512. case Format::ASTC_6x5_UNORM:
  513. case Format::ASTC_6x5_UNORM_SRGB:
  514. return RHI::Size(6, 5, 1);
  515. case Format::ASTC_6x6_UNORM:
  516. case Format::ASTC_6x6_UNORM_SRGB:
  517. return RHI::Size(6, 6, 1);
  518. case Format::ASTC_8x5_UNORM:
  519. case Format::ASTC_8x5_UNORM_SRGB:
  520. return RHI::Size(8, 5, 1);
  521. case Format::ASTC_8x6_UNORM:
  522. case Format::ASTC_8x6_UNORM_SRGB:
  523. return RHI::Size(8, 6, 1);
  524. case Format::ASTC_8x8_UNORM:
  525. case Format::ASTC_8x8_UNORM_SRGB:
  526. return RHI::Size(8, 8, 1);
  527. case Format::ASTC_10x5_UNORM:
  528. case Format::ASTC_10x5_UNORM_SRGB:
  529. return RHI::Size(10, 5, 1);
  530. case Format::ASTC_10x6_UNORM:
  531. case Format::ASTC_10x6_UNORM_SRGB:
  532. return RHI::Size(10, 6, 1);
  533. case Format::ASTC_10x8_UNORM:
  534. case Format::ASTC_10x8_UNORM_SRGB:
  535. return RHI::Size(10, 8, 1);
  536. case Format::ASTC_10x10_UNORM:
  537. case Format::ASTC_10x10_UNORM_SRGB:
  538. return RHI::Size(10, 10, 1);
  539. case Format::ASTC_12x10_UNORM:
  540. case Format::ASTC_12x10_UNORM_SRGB:
  541. return RHI::Size(12, 10, 1);
  542. case Format::ASTC_12x12_UNORM:
  543. case Format::ASTC_12x12_UNORM_SRGB:
  544. return RHI::Size(12, 12, 1);
  545. case Format::R8G8_B8G8_UNORM:
  546. case Format::G8R8_G8B8_UNORM:
  547. case Format::YUY2:
  548. case Format::Y210:
  549. case Format::Y216:
  550. case Format::NV12:
  551. case Format::P010:
  552. case Format::P016:
  553. return RHI::Size(2, 2, 1);
  554. default:
  555. return RHI::Size(1, 1, 1);
  556. }
  557. }
  558. Format ConvertLinearToSRGB(Format format)
  559. {
  560. switch (format)
  561. {
  562. case Format::R8G8B8A8_UNORM:
  563. return Format::R8G8B8A8_UNORM_SRGB;
  564. case Format::A8B8G8R8_UNORM:
  565. return Format::A8B8G8R8_UNORM_SRGB;
  566. case Format::BC1_UNORM:
  567. return Format::BC1_UNORM_SRGB;
  568. case Format::BC2_UNORM:
  569. return Format::BC2_UNORM_SRGB;
  570. case Format::BC3_UNORM:
  571. return Format::BC3_UNORM_SRGB;
  572. case Format::B8G8R8A8_UNORM:
  573. return Format::B8G8R8A8_UNORM_SRGB;
  574. case Format::B8G8R8X8_UNORM:
  575. return Format::B8G8R8X8_UNORM_SRGB;
  576. case Format::BC7_UNORM:
  577. return Format::BC7_UNORM_SRGB;
  578. case Format::ASTC_4x4_UNORM:
  579. return Format::ASTC_4x4_UNORM_SRGB;
  580. case Format::ASTC_5x4_UNORM:
  581. return Format::ASTC_5x4_UNORM_SRGB;
  582. case Format::ASTC_5x5_UNORM:
  583. return Format::ASTC_5x5_UNORM_SRGB;
  584. case Format::ASTC_6x5_UNORM:
  585. return Format::ASTC_6x5_UNORM_SRGB;
  586. case Format::ASTC_6x6_UNORM:
  587. return Format::ASTC_6x6_UNORM_SRGB;
  588. case Format::ASTC_8x5_UNORM:
  589. return Format::ASTC_8x5_UNORM_SRGB;
  590. case Format::ASTC_8x6_UNORM:
  591. return Format::ASTC_8x6_UNORM_SRGB;
  592. case Format::ASTC_8x8_UNORM:
  593. return Format::ASTC_8x8_UNORM_SRGB;
  594. case Format::ASTC_10x5_UNORM:
  595. return Format::ASTC_10x5_UNORM_SRGB;
  596. case Format::ASTC_10x6_UNORM:
  597. return Format::ASTC_10x6_UNORM_SRGB;
  598. case Format::ASTC_10x8_UNORM:
  599. return Format::ASTC_10x8_UNORM_SRGB;
  600. case Format::ASTC_10x10_UNORM:
  601. return Format::ASTC_10x10_UNORM_SRGB;
  602. case Format::ASTC_12x10_UNORM:
  603. return Format::ASTC_12x10_UNORM_SRGB;
  604. case Format::ASTC_12x12_UNORM:
  605. return Format::ASTC_12x12_UNORM_SRGB;
  606. case Format::ETC2_UNORM:
  607. return Format::ETC2_UNORM_SRGB;
  608. case Format::ETC2A1_UNORM:
  609. return Format::ETC2A1_UNORM_SRGB;
  610. case Format::ETC2A_UNORM:
  611. return Format::ETC2A_UNORM_SRGB;
  612. default:
  613. return format;
  614. }
  615. }
  616. Format ConvertSRGBToLinear(Format format)
  617. {
  618. switch (format)
  619. {
  620. case Format::A8B8G8R8_UNORM_SRGB:
  621. return Format::A8B8G8R8_UNORM;
  622. case Format::R8G8B8A8_UNORM_SRGB:
  623. return Format::R8G8B8A8_UNORM;
  624. case Format::BC1_UNORM_SRGB:
  625. return Format::BC1_UNORM;
  626. case Format::BC2_UNORM_SRGB:
  627. return Format::BC2_UNORM;
  628. case Format::BC3_UNORM_SRGB:
  629. return Format::BC3_UNORM;
  630. case Format::B8G8R8A8_UNORM_SRGB:
  631. return Format::B8G8R8A8_UNORM;
  632. case Format::B8G8R8X8_UNORM_SRGB:
  633. return Format::B8G8R8X8_UNORM;
  634. case Format::BC7_UNORM_SRGB:
  635. return Format::BC7_UNORM;
  636. case Format::ASTC_4x4_UNORM_SRGB:
  637. return Format::ASTC_4x4_UNORM;
  638. case Format::ASTC_5x4_UNORM_SRGB:
  639. return Format::ASTC_5x4_UNORM;
  640. case Format::ASTC_5x5_UNORM_SRGB:
  641. return Format::ASTC_5x5_UNORM;
  642. case Format::ASTC_6x5_UNORM_SRGB:
  643. return Format::ASTC_6x5_UNORM;
  644. case Format::ASTC_6x6_UNORM_SRGB:
  645. return Format::ASTC_6x6_UNORM;
  646. case Format::ASTC_8x5_UNORM_SRGB:
  647. return Format::ASTC_8x5_UNORM;
  648. case Format::ASTC_8x6_UNORM_SRGB:
  649. return Format::ASTC_8x6_UNORM;
  650. case Format::ASTC_8x8_UNORM_SRGB:
  651. return Format::ASTC_8x8_UNORM;
  652. case Format::ASTC_10x5_UNORM_SRGB:
  653. return Format::ASTC_10x5_UNORM;
  654. case Format::ASTC_10x6_UNORM_SRGB:
  655. return Format::ASTC_10x6_UNORM;
  656. case Format::ASTC_10x8_UNORM_SRGB:
  657. return Format::ASTC_10x8_UNORM;
  658. case Format::ASTC_10x10_UNORM_SRGB:
  659. return Format::ASTC_10x10_UNORM;
  660. case Format::ASTC_12x10_UNORM_SRGB:
  661. return Format::ASTC_12x10_UNORM;
  662. case Format::ASTC_12x12_UNORM_SRGB:
  663. return Format::ASTC_12x12_UNORM;
  664. case Format::ETC2_UNORM_SRGB:
  665. return Format::ETC2_UNORM;
  666. case Format::ETC2A1_UNORM_SRGB:
  667. return Format::ETC2A1_UNORM;
  668. case Format::ETC2A_UNORM_SRGB:
  669. return Format::ETC2A_UNORM;
  670. default:
  671. return format;
  672. }
  673. }
  674. ImageAspectFlags GetImageAspectFlags(Format format)
  675. {
  676. switch (format)
  677. {
  678. case Format::D32_FLOAT_S8X24_UINT:
  679. case Format::D16_UNORM_S8_UINT:
  680. case Format::D24_UNORM_S8_UINT:
  681. return ImageAspectFlags::DepthStencil;
  682. case Format::D32_FLOAT:
  683. case Format::D16_UNORM:
  684. return ImageAspectFlags::Depth;
  685. default:
  686. return ImageAspectFlags::Color;
  687. }
  688. }
  689. }