rendering_device_commons.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /**************************************************************************/
  2. /* rendering_device_commons.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "rendering_device_commons.h"
  31. /*****************/
  32. /**** GENERIC ****/
  33. /*****************/
  34. const char *const RenderingDeviceCommons::FORMAT_NAMES[DATA_FORMAT_MAX] = {
  35. "R4G4_Unorm_Pack8",
  36. "R4G4B4A4_Unorm_Pack16",
  37. "B4G4R4A4_Unorm_Pack16",
  38. "R5G6B5_Unorm_Pack16",
  39. "B5G6R5_Unorm_Pack16",
  40. "R5G5B5A1_Unorm_Pack16",
  41. "B5G5R5A1_Unorm_Pack16",
  42. "A1R5G5B5_Unorm_Pack16",
  43. "R8_Unorm",
  44. "R8_Snorm",
  45. "R8_Uscaled",
  46. "R8_Sscaled",
  47. "R8_Uint",
  48. "R8_Sint",
  49. "R8_Srgb",
  50. "R8G8_Unorm",
  51. "R8G8_Snorm",
  52. "R8G8_Uscaled",
  53. "R8G8_Sscaled",
  54. "R8G8_Uint",
  55. "R8G8_Sint",
  56. "R8G8_Srgb",
  57. "R8G8B8_Unorm",
  58. "R8G8B8_Snorm",
  59. "R8G8B8_Uscaled",
  60. "R8G8B8_Sscaled",
  61. "R8G8B8_Uint",
  62. "R8G8B8_Sint",
  63. "R8G8B8_Srgb",
  64. "B8G8R8_Unorm",
  65. "B8G8R8_Snorm",
  66. "B8G8R8_Uscaled",
  67. "B8G8R8_Sscaled",
  68. "B8G8R8_Uint",
  69. "B8G8R8_Sint",
  70. "B8G8R8_Srgb",
  71. "R8G8B8A8_Unorm",
  72. "R8G8B8A8_Snorm",
  73. "R8G8B8A8_Uscaled",
  74. "R8G8B8A8_Sscaled",
  75. "R8G8B8A8_Uint",
  76. "R8G8B8A8_Sint",
  77. "R8G8B8A8_Srgb",
  78. "B8G8R8A8_Unorm",
  79. "B8G8R8A8_Snorm",
  80. "B8G8R8A8_Uscaled",
  81. "B8G8R8A8_Sscaled",
  82. "B8G8R8A8_Uint",
  83. "B8G8R8A8_Sint",
  84. "B8G8R8A8_Srgb",
  85. "A8B8G8R8_Unorm_Pack32",
  86. "A8B8G8R8_Snorm_Pack32",
  87. "A8B8G8R8_Uscaled_Pack32",
  88. "A8B8G8R8_Sscaled_Pack32",
  89. "A8B8G8R8_Uint_Pack32",
  90. "A8B8G8R8_Sint_Pack32",
  91. "A8B8G8R8_Srgb_Pack32",
  92. "A2R10G10B10_Unorm_Pack32",
  93. "A2R10G10B10_Snorm_Pack32",
  94. "A2R10G10B10_Uscaled_Pack32",
  95. "A2R10G10B10_Sscaled_Pack32",
  96. "A2R10G10B10_Uint_Pack32",
  97. "A2R10G10B10_Sint_Pack32",
  98. "A2B10G10R10_Unorm_Pack32",
  99. "A2B10G10R10_Snorm_Pack32",
  100. "A2B10G10R10_Uscaled_Pack32",
  101. "A2B10G10R10_Sscaled_Pack32",
  102. "A2B10G10R10_Uint_Pack32",
  103. "A2B10G10R10_Sint_Pack32",
  104. "R16_Unorm",
  105. "R16_Snorm",
  106. "R16_Uscaled",
  107. "R16_Sscaled",
  108. "R16_Uint",
  109. "R16_Sint",
  110. "R16_Sfloat",
  111. "R16G16_Unorm",
  112. "R16G16_Snorm",
  113. "R16G16_Uscaled",
  114. "R16G16_Sscaled",
  115. "R16G16_Uint",
  116. "R16G16_Sint",
  117. "R16G16_Sfloat",
  118. "R16G16B16_Unorm",
  119. "R16G16B16_Snorm",
  120. "R16G16B16_Uscaled",
  121. "R16G16B16_Sscaled",
  122. "R16G16B16_Uint",
  123. "R16G16B16_Sint",
  124. "R16G16B16_Sfloat",
  125. "R16G16B16A16_Unorm",
  126. "R16G16B16A16_Snorm",
  127. "R16G16B16A16_Uscaled",
  128. "R16G16B16A16_Sscaled",
  129. "R16G16B16A16_Uint",
  130. "R16G16B16A16_Sint",
  131. "R16G16B16A16_Sfloat",
  132. "R32_Uint",
  133. "R32_Sint",
  134. "R32_Sfloat",
  135. "R32G32_Uint",
  136. "R32G32_Sint",
  137. "R32G32_Sfloat",
  138. "R32G32B32_Uint",
  139. "R32G32B32_Sint",
  140. "R32G32B32_Sfloat",
  141. "R32G32B32A32_Uint",
  142. "R32G32B32A32_Sint",
  143. "R32G32B32A32_Sfloat",
  144. "R64_Uint",
  145. "R64_Sint",
  146. "R64_Sfloat",
  147. "R64G64_Uint",
  148. "R64G64_Sint",
  149. "R64G64_Sfloat",
  150. "R64G64B64_Uint",
  151. "R64G64B64_Sint",
  152. "R64G64B64_Sfloat",
  153. "R64G64B64A64_Uint",
  154. "R64G64B64A64_Sint",
  155. "R64G64B64A64_Sfloat",
  156. "B10G11R11_Ufloat_Pack32",
  157. "E5B9G9R9_Ufloat_Pack32",
  158. "D16_Unorm",
  159. "X8_D24_Unorm_Pack32",
  160. "D32_Sfloat",
  161. "S8_Uint",
  162. "D16_Unorm_S8_Uint",
  163. "D24_Unorm_S8_Uint",
  164. "D32_Sfloat_S8_Uint",
  165. "Bc1_Rgb_Unorm_Block",
  166. "Bc1_Rgb_Srgb_Block",
  167. "Bc1_Rgba_Unorm_Block",
  168. "Bc1_Rgba_Srgb_Block",
  169. "Bc2_Unorm_Block",
  170. "Bc2_Srgb_Block",
  171. "Bc3_Unorm_Block",
  172. "Bc3_Srgb_Block",
  173. "Bc4_Unorm_Block",
  174. "Bc4_Snorm_Block",
  175. "Bc5_Unorm_Block",
  176. "Bc5_Snorm_Block",
  177. "Bc6H_Ufloat_Block",
  178. "Bc6H_Sfloat_Block",
  179. "Bc7_Unorm_Block",
  180. "Bc7_Srgb_Block",
  181. "Etc2_R8G8B8_Unorm_Block",
  182. "Etc2_R8G8B8_Srgb_Block",
  183. "Etc2_R8G8B8A1_Unorm_Block",
  184. "Etc2_R8G8B8A1_Srgb_Block",
  185. "Etc2_R8G8B8A8_Unorm_Block",
  186. "Etc2_R8G8B8A8_Srgb_Block",
  187. "Eac_R11_Unorm_Block",
  188. "Eac_R11_Snorm_Block",
  189. "Eac_R11G11_Unorm_Block",
  190. "Eac_R11G11_Snorm_Block",
  191. "Astc_4X4_Unorm_Block",
  192. "Astc_4X4_Srgb_Block",
  193. "Astc_5X4_Unorm_Block",
  194. "Astc_5X4_Srgb_Block",
  195. "Astc_5X5_Unorm_Block",
  196. "Astc_5X5_Srgb_Block",
  197. "Astc_6X5_Unorm_Block",
  198. "Astc_6X5_Srgb_Block",
  199. "Astc_6X6_Unorm_Block",
  200. "Astc_6X6_Srgb_Block",
  201. "Astc_8X5_Unorm_Block",
  202. "Astc_8X5_Srgb_Block",
  203. "Astc_8X6_Unorm_Block",
  204. "Astc_8X6_Srgb_Block",
  205. "Astc_8X8_Unorm_Block",
  206. "Astc_8X8_Srgb_Block",
  207. "Astc_10X5_Unorm_Block",
  208. "Astc_10X5_Srgb_Block",
  209. "Astc_10X6_Unorm_Block",
  210. "Astc_10X6_Srgb_Block",
  211. "Astc_10X8_Unorm_Block",
  212. "Astc_10X8_Srgb_Block",
  213. "Astc_10X10_Unorm_Block",
  214. "Astc_10X10_Srgb_Block",
  215. "Astc_12X10_Unorm_Block",
  216. "Astc_12X10_Srgb_Block",
  217. "Astc_12X12_Unorm_Block",
  218. "Astc_12X12_Srgb_Block",
  219. "G8B8G8R8_422_Unorm",
  220. "B8G8R8G8_422_Unorm",
  221. "G8_B8_R8_3Plane_420_Unorm",
  222. "G8_B8R8_2Plane_420_Unorm",
  223. "G8_B8_R8_3Plane_422_Unorm",
  224. "G8_B8R8_2Plane_422_Unorm",
  225. "G8_B8_R8_3Plane_444_Unorm",
  226. "R10X6_Unorm_Pack16",
  227. "R10X6G10X6_Unorm_2Pack16",
  228. "R10X6G10X6B10X6A10X6_Unorm_4Pack16",
  229. "G10X6B10X6G10X6R10X6_422_Unorm_4Pack16",
  230. "B10X6G10X6R10X6G10X6_422_Unorm_4Pack16",
  231. "G10X6_B10X6_R10X6_3Plane_420_Unorm_3Pack16",
  232. "G10X6_B10X6R10X6_2Plane_420_Unorm_3Pack16",
  233. "G10X6_B10X6_R10X6_3Plane_422_Unorm_3Pack16",
  234. "G10X6_B10X6R10X6_2Plane_422_Unorm_3Pack16",
  235. "G10X6_B10X6_R10X6_3Plane_444_Unorm_3Pack16",
  236. "R12X4_Unorm_Pack16",
  237. "R12X4G12X4_Unorm_2Pack16",
  238. "R12X4G12X4B12X4A12X4_Unorm_4Pack16",
  239. "G12X4B12X4G12X4R12X4_422_Unorm_4Pack16",
  240. "B12X4G12X4R12X4G12X4_422_Unorm_4Pack16",
  241. "G12X4_B12X4_R12X4_3Plane_420_Unorm_3Pack16",
  242. "G12X4_B12X4R12X4_2Plane_420_Unorm_3Pack16",
  243. "G12X4_B12X4_R12X4_3Plane_422_Unorm_3Pack16",
  244. "G12X4_B12X4R12X4_2Plane_422_Unorm_3Pack16",
  245. "G12X4_B12X4_R12X4_3Plane_444_Unorm_3Pack16",
  246. "G16B16G16R16_422_Unorm",
  247. "B16G16R16G16_422_Unorm",
  248. "G16_B16_R16_3Plane_420_Unorm",
  249. "G16_B16R16_2Plane_420_Unorm",
  250. "G16_B16_R16_3Plane_422_Unorm",
  251. "G16_B16R16_2Plane_422_Unorm",
  252. "G16_B16_R16_3Plane_444_Unorm",
  253. };
  254. /*****************/
  255. /**** TEXTURE ****/
  256. /*****************/
  257. const uint32_t RenderingDeviceCommons::TEXTURE_SAMPLES_COUNT[TEXTURE_SAMPLES_MAX] = { 1, 2, 4, 8, 16, 32, 64 };
  258. uint32_t RenderingDeviceCommons::get_image_format_pixel_size(DataFormat p_format) {
  259. switch (p_format) {
  260. case DATA_FORMAT_R4G4_UNORM_PACK8:
  261. return 1;
  262. case DATA_FORMAT_R4G4B4A4_UNORM_PACK16:
  263. case DATA_FORMAT_B4G4R4A4_UNORM_PACK16:
  264. case DATA_FORMAT_R5G6B5_UNORM_PACK16:
  265. case DATA_FORMAT_B5G6R5_UNORM_PACK16:
  266. case DATA_FORMAT_R5G5B5A1_UNORM_PACK16:
  267. case DATA_FORMAT_B5G5R5A1_UNORM_PACK16:
  268. case DATA_FORMAT_A1R5G5B5_UNORM_PACK16:
  269. return 2;
  270. case DATA_FORMAT_R8_UNORM:
  271. case DATA_FORMAT_R8_SNORM:
  272. case DATA_FORMAT_R8_USCALED:
  273. case DATA_FORMAT_R8_SSCALED:
  274. case DATA_FORMAT_R8_UINT:
  275. case DATA_FORMAT_R8_SINT:
  276. case DATA_FORMAT_R8_SRGB:
  277. return 1;
  278. case DATA_FORMAT_R8G8_UNORM:
  279. case DATA_FORMAT_R8G8_SNORM:
  280. case DATA_FORMAT_R8G8_USCALED:
  281. case DATA_FORMAT_R8G8_SSCALED:
  282. case DATA_FORMAT_R8G8_UINT:
  283. case DATA_FORMAT_R8G8_SINT:
  284. case DATA_FORMAT_R8G8_SRGB:
  285. return 2;
  286. case DATA_FORMAT_R8G8B8_UNORM:
  287. case DATA_FORMAT_R8G8B8_SNORM:
  288. case DATA_FORMAT_R8G8B8_USCALED:
  289. case DATA_FORMAT_R8G8B8_SSCALED:
  290. case DATA_FORMAT_R8G8B8_UINT:
  291. case DATA_FORMAT_R8G8B8_SINT:
  292. case DATA_FORMAT_R8G8B8_SRGB:
  293. case DATA_FORMAT_B8G8R8_UNORM:
  294. case DATA_FORMAT_B8G8R8_SNORM:
  295. case DATA_FORMAT_B8G8R8_USCALED:
  296. case DATA_FORMAT_B8G8R8_SSCALED:
  297. case DATA_FORMAT_B8G8R8_UINT:
  298. case DATA_FORMAT_B8G8R8_SINT:
  299. case DATA_FORMAT_B8G8R8_SRGB:
  300. return 3;
  301. case DATA_FORMAT_R8G8B8A8_UNORM:
  302. case DATA_FORMAT_R8G8B8A8_SNORM:
  303. case DATA_FORMAT_R8G8B8A8_USCALED:
  304. case DATA_FORMAT_R8G8B8A8_SSCALED:
  305. case DATA_FORMAT_R8G8B8A8_UINT:
  306. case DATA_FORMAT_R8G8B8A8_SINT:
  307. case DATA_FORMAT_R8G8B8A8_SRGB:
  308. case DATA_FORMAT_B8G8R8A8_UNORM:
  309. case DATA_FORMAT_B8G8R8A8_SNORM:
  310. case DATA_FORMAT_B8G8R8A8_USCALED:
  311. case DATA_FORMAT_B8G8R8A8_SSCALED:
  312. case DATA_FORMAT_B8G8R8A8_UINT:
  313. case DATA_FORMAT_B8G8R8A8_SINT:
  314. case DATA_FORMAT_B8G8R8A8_SRGB:
  315. return 4;
  316. case DATA_FORMAT_A8B8G8R8_UNORM_PACK32:
  317. case DATA_FORMAT_A8B8G8R8_SNORM_PACK32:
  318. case DATA_FORMAT_A8B8G8R8_USCALED_PACK32:
  319. case DATA_FORMAT_A8B8G8R8_SSCALED_PACK32:
  320. case DATA_FORMAT_A8B8G8R8_UINT_PACK32:
  321. case DATA_FORMAT_A8B8G8R8_SINT_PACK32:
  322. case DATA_FORMAT_A8B8G8R8_SRGB_PACK32:
  323. case DATA_FORMAT_A2R10G10B10_UNORM_PACK32:
  324. case DATA_FORMAT_A2R10G10B10_SNORM_PACK32:
  325. case DATA_FORMAT_A2R10G10B10_USCALED_PACK32:
  326. case DATA_FORMAT_A2R10G10B10_SSCALED_PACK32:
  327. case DATA_FORMAT_A2R10G10B10_UINT_PACK32:
  328. case DATA_FORMAT_A2R10G10B10_SINT_PACK32:
  329. case DATA_FORMAT_A2B10G10R10_UNORM_PACK32:
  330. case DATA_FORMAT_A2B10G10R10_SNORM_PACK32:
  331. case DATA_FORMAT_A2B10G10R10_USCALED_PACK32:
  332. case DATA_FORMAT_A2B10G10R10_SSCALED_PACK32:
  333. case DATA_FORMAT_A2B10G10R10_UINT_PACK32:
  334. case DATA_FORMAT_A2B10G10R10_SINT_PACK32:
  335. return 4;
  336. case DATA_FORMAT_R16_UNORM:
  337. case DATA_FORMAT_R16_SNORM:
  338. case DATA_FORMAT_R16_USCALED:
  339. case DATA_FORMAT_R16_SSCALED:
  340. case DATA_FORMAT_R16_UINT:
  341. case DATA_FORMAT_R16_SINT:
  342. case DATA_FORMAT_R16_SFLOAT:
  343. return 2;
  344. case DATA_FORMAT_R16G16_UNORM:
  345. case DATA_FORMAT_R16G16_SNORM:
  346. case DATA_FORMAT_R16G16_USCALED:
  347. case DATA_FORMAT_R16G16_SSCALED:
  348. case DATA_FORMAT_R16G16_UINT:
  349. case DATA_FORMAT_R16G16_SINT:
  350. case DATA_FORMAT_R16G16_SFLOAT:
  351. return 4;
  352. case DATA_FORMAT_R16G16B16_UNORM:
  353. case DATA_FORMAT_R16G16B16_SNORM:
  354. case DATA_FORMAT_R16G16B16_USCALED:
  355. case DATA_FORMAT_R16G16B16_SSCALED:
  356. case DATA_FORMAT_R16G16B16_UINT:
  357. case DATA_FORMAT_R16G16B16_SINT:
  358. case DATA_FORMAT_R16G16B16_SFLOAT:
  359. return 6;
  360. case DATA_FORMAT_R16G16B16A16_UNORM:
  361. case DATA_FORMAT_R16G16B16A16_SNORM:
  362. case DATA_FORMAT_R16G16B16A16_USCALED:
  363. case DATA_FORMAT_R16G16B16A16_SSCALED:
  364. case DATA_FORMAT_R16G16B16A16_UINT:
  365. case DATA_FORMAT_R16G16B16A16_SINT:
  366. case DATA_FORMAT_R16G16B16A16_SFLOAT:
  367. return 8;
  368. case DATA_FORMAT_R32_UINT:
  369. case DATA_FORMAT_R32_SINT:
  370. case DATA_FORMAT_R32_SFLOAT:
  371. return 4;
  372. case DATA_FORMAT_R32G32_UINT:
  373. case DATA_FORMAT_R32G32_SINT:
  374. case DATA_FORMAT_R32G32_SFLOAT:
  375. return 8;
  376. case DATA_FORMAT_R32G32B32_UINT:
  377. case DATA_FORMAT_R32G32B32_SINT:
  378. case DATA_FORMAT_R32G32B32_SFLOAT:
  379. return 12;
  380. case DATA_FORMAT_R32G32B32A32_UINT:
  381. case DATA_FORMAT_R32G32B32A32_SINT:
  382. case DATA_FORMAT_R32G32B32A32_SFLOAT:
  383. return 16;
  384. case DATA_FORMAT_R64_UINT:
  385. case DATA_FORMAT_R64_SINT:
  386. case DATA_FORMAT_R64_SFLOAT:
  387. return 8;
  388. case DATA_FORMAT_R64G64_UINT:
  389. case DATA_FORMAT_R64G64_SINT:
  390. case DATA_FORMAT_R64G64_SFLOAT:
  391. return 16;
  392. case DATA_FORMAT_R64G64B64_UINT:
  393. case DATA_FORMAT_R64G64B64_SINT:
  394. case DATA_FORMAT_R64G64B64_SFLOAT:
  395. return 24;
  396. case DATA_FORMAT_R64G64B64A64_UINT:
  397. case DATA_FORMAT_R64G64B64A64_SINT:
  398. case DATA_FORMAT_R64G64B64A64_SFLOAT:
  399. return 32;
  400. case DATA_FORMAT_B10G11R11_UFLOAT_PACK32:
  401. case DATA_FORMAT_E5B9G9R9_UFLOAT_PACK32:
  402. return 4;
  403. case DATA_FORMAT_D16_UNORM:
  404. return 2;
  405. case DATA_FORMAT_X8_D24_UNORM_PACK32:
  406. return 4;
  407. case DATA_FORMAT_D32_SFLOAT:
  408. return 4;
  409. case DATA_FORMAT_S8_UINT:
  410. return 1;
  411. case DATA_FORMAT_D16_UNORM_S8_UINT:
  412. return 4;
  413. case DATA_FORMAT_D24_UNORM_S8_UINT:
  414. return 4;
  415. case DATA_FORMAT_D32_SFLOAT_S8_UINT:
  416. return 5; // ?
  417. case DATA_FORMAT_BC1_RGB_UNORM_BLOCK:
  418. case DATA_FORMAT_BC1_RGB_SRGB_BLOCK:
  419. case DATA_FORMAT_BC1_RGBA_UNORM_BLOCK:
  420. case DATA_FORMAT_BC1_RGBA_SRGB_BLOCK:
  421. case DATA_FORMAT_BC2_UNORM_BLOCK:
  422. case DATA_FORMAT_BC2_SRGB_BLOCK:
  423. case DATA_FORMAT_BC3_UNORM_BLOCK:
  424. case DATA_FORMAT_BC3_SRGB_BLOCK:
  425. case DATA_FORMAT_BC4_UNORM_BLOCK:
  426. case DATA_FORMAT_BC4_SNORM_BLOCK:
  427. case DATA_FORMAT_BC5_UNORM_BLOCK:
  428. case DATA_FORMAT_BC5_SNORM_BLOCK:
  429. case DATA_FORMAT_BC6H_UFLOAT_BLOCK:
  430. case DATA_FORMAT_BC6H_SFLOAT_BLOCK:
  431. case DATA_FORMAT_BC7_UNORM_BLOCK:
  432. case DATA_FORMAT_BC7_SRGB_BLOCK:
  433. return 1;
  434. case DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
  435. case DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
  436. case DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
  437. case DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
  438. case DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
  439. case DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
  440. return 1;
  441. case DATA_FORMAT_EAC_R11_UNORM_BLOCK:
  442. case DATA_FORMAT_EAC_R11_SNORM_BLOCK:
  443. case DATA_FORMAT_EAC_R11G11_UNORM_BLOCK:
  444. case DATA_FORMAT_EAC_R11G11_SNORM_BLOCK:
  445. return 1;
  446. case DATA_FORMAT_ASTC_4x4_UNORM_BLOCK:
  447. case DATA_FORMAT_ASTC_4x4_SRGB_BLOCK:
  448. case DATA_FORMAT_ASTC_5x4_UNORM_BLOCK:
  449. case DATA_FORMAT_ASTC_5x4_SRGB_BLOCK:
  450. case DATA_FORMAT_ASTC_5x5_UNORM_BLOCK:
  451. case DATA_FORMAT_ASTC_5x5_SRGB_BLOCK:
  452. case DATA_FORMAT_ASTC_6x5_UNORM_BLOCK:
  453. case DATA_FORMAT_ASTC_6x5_SRGB_BLOCK:
  454. case DATA_FORMAT_ASTC_6x6_UNORM_BLOCK:
  455. case DATA_FORMAT_ASTC_6x6_SRGB_BLOCK:
  456. case DATA_FORMAT_ASTC_8x5_UNORM_BLOCK:
  457. case DATA_FORMAT_ASTC_8x5_SRGB_BLOCK:
  458. case DATA_FORMAT_ASTC_8x6_UNORM_BLOCK:
  459. case DATA_FORMAT_ASTC_8x6_SRGB_BLOCK:
  460. case DATA_FORMAT_ASTC_8x8_UNORM_BLOCK:
  461. case DATA_FORMAT_ASTC_8x8_SRGB_BLOCK:
  462. case DATA_FORMAT_ASTC_10x5_UNORM_BLOCK:
  463. case DATA_FORMAT_ASTC_10x5_SRGB_BLOCK:
  464. case DATA_FORMAT_ASTC_10x6_UNORM_BLOCK:
  465. case DATA_FORMAT_ASTC_10x6_SRGB_BLOCK:
  466. case DATA_FORMAT_ASTC_10x8_UNORM_BLOCK:
  467. case DATA_FORMAT_ASTC_10x8_SRGB_BLOCK:
  468. case DATA_FORMAT_ASTC_10x10_UNORM_BLOCK:
  469. case DATA_FORMAT_ASTC_10x10_SRGB_BLOCK:
  470. case DATA_FORMAT_ASTC_12x10_UNORM_BLOCK:
  471. case DATA_FORMAT_ASTC_12x10_SRGB_BLOCK:
  472. case DATA_FORMAT_ASTC_12x12_UNORM_BLOCK:
  473. case DATA_FORMAT_ASTC_12x12_SRGB_BLOCK:
  474. return 1;
  475. case DATA_FORMAT_G8B8G8R8_422_UNORM:
  476. case DATA_FORMAT_B8G8R8G8_422_UNORM:
  477. return 4;
  478. case DATA_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
  479. case DATA_FORMAT_G8_B8R8_2PLANE_420_UNORM:
  480. case DATA_FORMAT_G8_B8_R8_3PLANE_422_UNORM:
  481. case DATA_FORMAT_G8_B8R8_2PLANE_422_UNORM:
  482. case DATA_FORMAT_G8_B8_R8_3PLANE_444_UNORM:
  483. return 4;
  484. case DATA_FORMAT_R10X6_UNORM_PACK16:
  485. case DATA_FORMAT_R10X6G10X6_UNORM_2PACK16:
  486. case DATA_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16:
  487. case DATA_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16:
  488. case DATA_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16:
  489. case DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16:
  490. case DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16:
  491. case DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16:
  492. case DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16:
  493. case DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16:
  494. case DATA_FORMAT_R12X4_UNORM_PACK16:
  495. case DATA_FORMAT_R12X4G12X4_UNORM_2PACK16:
  496. case DATA_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16:
  497. case DATA_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16:
  498. case DATA_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16:
  499. case DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16:
  500. case DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16:
  501. case DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16:
  502. case DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16:
  503. case DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16:
  504. return 2;
  505. case DATA_FORMAT_G16B16G16R16_422_UNORM:
  506. case DATA_FORMAT_B16G16R16G16_422_UNORM:
  507. case DATA_FORMAT_G16_B16_R16_3PLANE_420_UNORM:
  508. case DATA_FORMAT_G16_B16R16_2PLANE_420_UNORM:
  509. case DATA_FORMAT_G16_B16_R16_3PLANE_422_UNORM:
  510. case DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM:
  511. case DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
  512. return 8;
  513. default: {
  514. ERR_PRINT("Format not handled, bug");
  515. }
  516. }
  517. return 1;
  518. }
  519. // https://www.khronos.org/registry/DataFormat/specs/1.1/dataformat.1.1.pdf
  520. void RenderingDeviceCommons::get_compressed_image_format_block_dimensions(DataFormat p_format, uint32_t &r_w, uint32_t &r_h) {
  521. switch (p_format) {
  522. case DATA_FORMAT_BC1_RGB_UNORM_BLOCK:
  523. case DATA_FORMAT_BC1_RGB_SRGB_BLOCK:
  524. case DATA_FORMAT_BC1_RGBA_UNORM_BLOCK:
  525. case DATA_FORMAT_BC1_RGBA_SRGB_BLOCK:
  526. case DATA_FORMAT_BC2_UNORM_BLOCK:
  527. case DATA_FORMAT_BC2_SRGB_BLOCK:
  528. case DATA_FORMAT_BC3_UNORM_BLOCK:
  529. case DATA_FORMAT_BC3_SRGB_BLOCK:
  530. case DATA_FORMAT_BC4_UNORM_BLOCK:
  531. case DATA_FORMAT_BC4_SNORM_BLOCK:
  532. case DATA_FORMAT_BC5_UNORM_BLOCK:
  533. case DATA_FORMAT_BC5_SNORM_BLOCK:
  534. case DATA_FORMAT_BC6H_UFLOAT_BLOCK:
  535. case DATA_FORMAT_BC6H_SFLOAT_BLOCK:
  536. case DATA_FORMAT_BC7_UNORM_BLOCK:
  537. case DATA_FORMAT_BC7_SRGB_BLOCK:
  538. case DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
  539. case DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
  540. case DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
  541. case DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
  542. case DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
  543. case DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
  544. case DATA_FORMAT_EAC_R11_UNORM_BLOCK:
  545. case DATA_FORMAT_EAC_R11_SNORM_BLOCK:
  546. case DATA_FORMAT_EAC_R11G11_UNORM_BLOCK:
  547. case DATA_FORMAT_EAC_R11G11_SNORM_BLOCK:
  548. case DATA_FORMAT_ASTC_4x4_UNORM_BLOCK: // Again, not sure about astc.
  549. case DATA_FORMAT_ASTC_4x4_SRGB_BLOCK: {
  550. r_w = 4;
  551. r_h = 4;
  552. } break;
  553. case DATA_FORMAT_ASTC_5x4_UNORM_BLOCK: // Unsupported
  554. case DATA_FORMAT_ASTC_5x4_SRGB_BLOCK:
  555. case DATA_FORMAT_ASTC_5x5_UNORM_BLOCK:
  556. case DATA_FORMAT_ASTC_5x5_SRGB_BLOCK:
  557. case DATA_FORMAT_ASTC_6x5_UNORM_BLOCK:
  558. case DATA_FORMAT_ASTC_6x5_SRGB_BLOCK:
  559. case DATA_FORMAT_ASTC_6x6_UNORM_BLOCK:
  560. case DATA_FORMAT_ASTC_6x6_SRGB_BLOCK:
  561. case DATA_FORMAT_ASTC_8x5_UNORM_BLOCK:
  562. case DATA_FORMAT_ASTC_8x5_SRGB_BLOCK:
  563. case DATA_FORMAT_ASTC_8x6_UNORM_BLOCK:
  564. case DATA_FORMAT_ASTC_8x6_SRGB_BLOCK: {
  565. r_w = 4;
  566. r_h = 4;
  567. } break;
  568. case DATA_FORMAT_ASTC_8x8_UNORM_BLOCK:
  569. case DATA_FORMAT_ASTC_8x8_SRGB_BLOCK: {
  570. r_w = 8;
  571. r_h = 8;
  572. } break;
  573. case DATA_FORMAT_ASTC_10x5_UNORM_BLOCK: // Unsupported
  574. case DATA_FORMAT_ASTC_10x5_SRGB_BLOCK:
  575. case DATA_FORMAT_ASTC_10x6_UNORM_BLOCK:
  576. case DATA_FORMAT_ASTC_10x6_SRGB_BLOCK:
  577. case DATA_FORMAT_ASTC_10x8_UNORM_BLOCK:
  578. case DATA_FORMAT_ASTC_10x8_SRGB_BLOCK:
  579. case DATA_FORMAT_ASTC_10x10_UNORM_BLOCK:
  580. case DATA_FORMAT_ASTC_10x10_SRGB_BLOCK:
  581. case DATA_FORMAT_ASTC_12x10_UNORM_BLOCK:
  582. case DATA_FORMAT_ASTC_12x10_SRGB_BLOCK:
  583. case DATA_FORMAT_ASTC_12x12_UNORM_BLOCK:
  584. case DATA_FORMAT_ASTC_12x12_SRGB_BLOCK:
  585. r_w = 4;
  586. r_h = 4;
  587. return;
  588. default: {
  589. r_w = 1;
  590. r_h = 1;
  591. }
  592. }
  593. }
  594. uint32_t RenderingDeviceCommons::get_compressed_image_format_block_byte_size(DataFormat p_format) const {
  595. switch (p_format) {
  596. case DATA_FORMAT_BC1_RGB_UNORM_BLOCK:
  597. case DATA_FORMAT_BC1_RGB_SRGB_BLOCK:
  598. case DATA_FORMAT_BC1_RGBA_UNORM_BLOCK:
  599. case DATA_FORMAT_BC1_RGBA_SRGB_BLOCK:
  600. return 8;
  601. case DATA_FORMAT_BC2_UNORM_BLOCK:
  602. case DATA_FORMAT_BC2_SRGB_BLOCK:
  603. return 16;
  604. case DATA_FORMAT_BC3_UNORM_BLOCK:
  605. case DATA_FORMAT_BC3_SRGB_BLOCK:
  606. return 16;
  607. case DATA_FORMAT_BC4_UNORM_BLOCK:
  608. case DATA_FORMAT_BC4_SNORM_BLOCK:
  609. return 8;
  610. case DATA_FORMAT_BC5_UNORM_BLOCK:
  611. case DATA_FORMAT_BC5_SNORM_BLOCK:
  612. return 16;
  613. case DATA_FORMAT_BC6H_UFLOAT_BLOCK:
  614. case DATA_FORMAT_BC6H_SFLOAT_BLOCK:
  615. return 16;
  616. case DATA_FORMAT_BC7_UNORM_BLOCK:
  617. case DATA_FORMAT_BC7_SRGB_BLOCK:
  618. return 16;
  619. case DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
  620. case DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
  621. return 8;
  622. case DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
  623. case DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
  624. return 8;
  625. case DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
  626. case DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
  627. return 16;
  628. case DATA_FORMAT_EAC_R11_UNORM_BLOCK:
  629. case DATA_FORMAT_EAC_R11_SNORM_BLOCK:
  630. return 8;
  631. case DATA_FORMAT_EAC_R11G11_UNORM_BLOCK:
  632. case DATA_FORMAT_EAC_R11G11_SNORM_BLOCK:
  633. return 16;
  634. case DATA_FORMAT_ASTC_4x4_UNORM_BLOCK: // Again, not sure about astc.
  635. case DATA_FORMAT_ASTC_4x4_SRGB_BLOCK:
  636. case DATA_FORMAT_ASTC_5x4_UNORM_BLOCK:
  637. case DATA_FORMAT_ASTC_5x4_SRGB_BLOCK:
  638. case DATA_FORMAT_ASTC_5x5_UNORM_BLOCK:
  639. case DATA_FORMAT_ASTC_5x5_SRGB_BLOCK:
  640. case DATA_FORMAT_ASTC_6x5_UNORM_BLOCK:
  641. case DATA_FORMAT_ASTC_6x5_SRGB_BLOCK:
  642. case DATA_FORMAT_ASTC_6x6_UNORM_BLOCK:
  643. case DATA_FORMAT_ASTC_6x6_SRGB_BLOCK:
  644. case DATA_FORMAT_ASTC_8x5_UNORM_BLOCK:
  645. case DATA_FORMAT_ASTC_8x5_SRGB_BLOCK:
  646. case DATA_FORMAT_ASTC_8x6_UNORM_BLOCK:
  647. case DATA_FORMAT_ASTC_8x6_SRGB_BLOCK:
  648. case DATA_FORMAT_ASTC_8x8_UNORM_BLOCK:
  649. case DATA_FORMAT_ASTC_8x8_SRGB_BLOCK:
  650. case DATA_FORMAT_ASTC_10x5_UNORM_BLOCK:
  651. case DATA_FORMAT_ASTC_10x5_SRGB_BLOCK:
  652. case DATA_FORMAT_ASTC_10x6_UNORM_BLOCK:
  653. case DATA_FORMAT_ASTC_10x6_SRGB_BLOCK:
  654. case DATA_FORMAT_ASTC_10x8_UNORM_BLOCK:
  655. case DATA_FORMAT_ASTC_10x8_SRGB_BLOCK:
  656. case DATA_FORMAT_ASTC_10x10_UNORM_BLOCK:
  657. case DATA_FORMAT_ASTC_10x10_SRGB_BLOCK:
  658. case DATA_FORMAT_ASTC_12x10_UNORM_BLOCK:
  659. case DATA_FORMAT_ASTC_12x10_SRGB_BLOCK:
  660. case DATA_FORMAT_ASTC_12x12_UNORM_BLOCK:
  661. case DATA_FORMAT_ASTC_12x12_SRGB_BLOCK:
  662. return 16;
  663. default: {
  664. }
  665. }
  666. return 1;
  667. }
  668. uint32_t RenderingDeviceCommons::get_compressed_image_format_pixel_rshift(DataFormat p_format) {
  669. switch (p_format) {
  670. case DATA_FORMAT_BC1_RGB_UNORM_BLOCK: // These formats are half byte size, so rshift is 1.
  671. case DATA_FORMAT_BC1_RGB_SRGB_BLOCK:
  672. case DATA_FORMAT_BC1_RGBA_UNORM_BLOCK:
  673. case DATA_FORMAT_BC1_RGBA_SRGB_BLOCK:
  674. case DATA_FORMAT_BC4_UNORM_BLOCK:
  675. case DATA_FORMAT_BC4_SNORM_BLOCK:
  676. case DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
  677. case DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
  678. case DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
  679. case DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
  680. case DATA_FORMAT_EAC_R11_UNORM_BLOCK:
  681. case DATA_FORMAT_EAC_R11_SNORM_BLOCK:
  682. return 1;
  683. case DATA_FORMAT_ASTC_8x8_SRGB_BLOCK:
  684. case DATA_FORMAT_ASTC_8x8_UNORM_BLOCK: {
  685. return 2;
  686. }
  687. default: {
  688. }
  689. }
  690. return 0;
  691. }
  692. uint32_t RenderingDeviceCommons::get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw, uint32_t *r_blockh, uint32_t *r_depth) {
  693. ERR_FAIL_COND_V(p_mipmaps == 0, 0);
  694. uint32_t w = p_width;
  695. uint32_t h = p_height;
  696. uint32_t d = p_depth;
  697. uint32_t size = 0;
  698. uint32_t pixel_size = get_image_format_pixel_size(p_format);
  699. uint32_t pixel_rshift = get_compressed_image_format_pixel_rshift(p_format);
  700. uint32_t blockw = 0;
  701. uint32_t blockh = 0;
  702. get_compressed_image_format_block_dimensions(p_format, blockw, blockh);
  703. for (uint32_t i = 0; i < p_mipmaps; i++) {
  704. uint32_t bw = STEPIFY(w, blockw);
  705. uint32_t bh = STEPIFY(h, blockh);
  706. uint32_t s = bw * bh;
  707. s *= pixel_size;
  708. s >>= pixel_rshift;
  709. size += s * d;
  710. if (r_blockw) {
  711. *r_blockw = bw;
  712. }
  713. if (r_blockh) {
  714. *r_blockh = bh;
  715. }
  716. if (r_depth) {
  717. *r_depth = d;
  718. }
  719. w = MAX(blockw, w >> 1);
  720. h = MAX(blockh, h >> 1);
  721. d = MAX(1u, d >> 1);
  722. }
  723. return size;
  724. }
  725. uint32_t RenderingDeviceCommons::get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth) {
  726. // Formats and block size don't really matter here since they can all go down to 1px (even if block is larger).
  727. uint32_t w = p_width;
  728. uint32_t h = p_height;
  729. uint32_t d = p_depth;
  730. uint32_t mipmaps = 1;
  731. while (true) {
  732. if (w == 1 && h == 1 && d == 1) {
  733. break;
  734. }
  735. w = MAX(1u, w >> 1);
  736. h = MAX(1u, h >> 1);
  737. d = MAX(1u, d >> 1);
  738. mipmaps++;
  739. }
  740. return mipmaps;
  741. }
  742. bool RenderingDeviceCommons::format_has_stencil(DataFormat p_format) {
  743. switch (p_format) {
  744. case DATA_FORMAT_S8_UINT:
  745. case DATA_FORMAT_D16_UNORM_S8_UINT:
  746. case DATA_FORMAT_D24_UNORM_S8_UINT:
  747. case DATA_FORMAT_D32_SFLOAT_S8_UINT: {
  748. return true;
  749. }
  750. default: {
  751. }
  752. }
  753. return false;
  754. }
  755. uint32_t RenderingDeviceCommons::format_get_plane_count(DataFormat p_format) {
  756. uint32_t planes = 1;
  757. switch (p_format) {
  758. case DATA_FORMAT_D16_UNORM_S8_UINT:
  759. case DATA_FORMAT_D24_UNORM_S8_UINT:
  760. case DATA_FORMAT_D32_SFLOAT_S8_UINT: {
  761. planes = 2;
  762. break;
  763. }
  764. default: {
  765. }
  766. }
  767. DEV_ASSERT(planes <= MAX_IMAGE_FORMAT_PLANES);
  768. return planes;
  769. }
  770. /*****************/
  771. /**** SAMPLER ****/
  772. /*****************/
  773. const Color RenderingDeviceCommons::SAMPLER_BORDER_COLOR_VALUE[SAMPLER_BORDER_COLOR_MAX] = {
  774. Color(0, 0, 0, 0),
  775. Color(0, 0, 0, 0),
  776. Color(0, 0, 0, 1),
  777. Color(0, 0, 0, 1),
  778. Color(1, 1, 1, 1),
  779. Color(1, 1, 1, 1),
  780. };
  781. /**********************/
  782. /**** VERTEX ARRAY ****/
  783. /**********************/
  784. uint32_t RenderingDeviceCommons::get_format_vertex_size(DataFormat p_format) {
  785. switch (p_format) {
  786. case DATA_FORMAT_R8_UNORM:
  787. case DATA_FORMAT_R8_SNORM:
  788. case DATA_FORMAT_R8_UINT:
  789. case DATA_FORMAT_R8_SINT:
  790. case DATA_FORMAT_R8G8_UNORM:
  791. case DATA_FORMAT_R8G8_SNORM:
  792. case DATA_FORMAT_R8G8_UINT:
  793. case DATA_FORMAT_R8G8_SINT:
  794. case DATA_FORMAT_R8G8B8_UNORM:
  795. case DATA_FORMAT_R8G8B8_SNORM:
  796. case DATA_FORMAT_R8G8B8_UINT:
  797. case DATA_FORMAT_R8G8B8_SINT:
  798. case DATA_FORMAT_B8G8R8_UNORM:
  799. case DATA_FORMAT_B8G8R8_SNORM:
  800. case DATA_FORMAT_B8G8R8_UINT:
  801. case DATA_FORMAT_B8G8R8_SINT:
  802. case DATA_FORMAT_R8G8B8A8_UNORM:
  803. case DATA_FORMAT_R8G8B8A8_SNORM:
  804. case DATA_FORMAT_R8G8B8A8_UINT:
  805. case DATA_FORMAT_R8G8B8A8_SINT:
  806. case DATA_FORMAT_B8G8R8A8_UNORM:
  807. case DATA_FORMAT_B8G8R8A8_SNORM:
  808. case DATA_FORMAT_B8G8R8A8_UINT:
  809. case DATA_FORMAT_B8G8R8A8_SINT:
  810. case DATA_FORMAT_A2B10G10R10_UNORM_PACK32:
  811. return 4;
  812. case DATA_FORMAT_R16_UNORM:
  813. case DATA_FORMAT_R16_SNORM:
  814. case DATA_FORMAT_R16_UINT:
  815. case DATA_FORMAT_R16_SINT:
  816. case DATA_FORMAT_R16_SFLOAT:
  817. return 4;
  818. case DATA_FORMAT_R16G16_UNORM:
  819. case DATA_FORMAT_R16G16_SNORM:
  820. case DATA_FORMAT_R16G16_UINT:
  821. case DATA_FORMAT_R16G16_SINT:
  822. case DATA_FORMAT_R16G16_SFLOAT:
  823. return 4;
  824. case DATA_FORMAT_R16G16B16_UNORM:
  825. case DATA_FORMAT_R16G16B16_SNORM:
  826. case DATA_FORMAT_R16G16B16_UINT:
  827. case DATA_FORMAT_R16G16B16_SINT:
  828. case DATA_FORMAT_R16G16B16_SFLOAT:
  829. return 8;
  830. case DATA_FORMAT_R16G16B16A16_UNORM:
  831. case DATA_FORMAT_R16G16B16A16_SNORM:
  832. case DATA_FORMAT_R16G16B16A16_UINT:
  833. case DATA_FORMAT_R16G16B16A16_SINT:
  834. case DATA_FORMAT_R16G16B16A16_SFLOAT:
  835. return 8;
  836. case DATA_FORMAT_R32_UINT:
  837. case DATA_FORMAT_R32_SINT:
  838. case DATA_FORMAT_R32_SFLOAT:
  839. return 4;
  840. case DATA_FORMAT_R32G32_UINT:
  841. case DATA_FORMAT_R32G32_SINT:
  842. case DATA_FORMAT_R32G32_SFLOAT:
  843. return 8;
  844. case DATA_FORMAT_R32G32B32_UINT:
  845. case DATA_FORMAT_R32G32B32_SINT:
  846. case DATA_FORMAT_R32G32B32_SFLOAT:
  847. return 12;
  848. case DATA_FORMAT_R32G32B32A32_UINT:
  849. case DATA_FORMAT_R32G32B32A32_SINT:
  850. case DATA_FORMAT_R32G32B32A32_SFLOAT:
  851. return 16;
  852. case DATA_FORMAT_R64_UINT:
  853. case DATA_FORMAT_R64_SINT:
  854. case DATA_FORMAT_R64_SFLOAT:
  855. return 8;
  856. case DATA_FORMAT_R64G64_UINT:
  857. case DATA_FORMAT_R64G64_SINT:
  858. case DATA_FORMAT_R64G64_SFLOAT:
  859. return 16;
  860. case DATA_FORMAT_R64G64B64_UINT:
  861. case DATA_FORMAT_R64G64B64_SINT:
  862. case DATA_FORMAT_R64G64B64_SFLOAT:
  863. return 24;
  864. case DATA_FORMAT_R64G64B64A64_UINT:
  865. case DATA_FORMAT_R64G64B64A64_SINT:
  866. case DATA_FORMAT_R64G64B64A64_SFLOAT:
  867. return 32;
  868. default:
  869. return 0;
  870. }
  871. }
  872. /****************/
  873. /**** SHADER ****/
  874. /****************/
  875. const char *RenderingDeviceCommons::SHADER_STAGE_NAMES[SHADER_STAGE_MAX] = {
  876. "Vertex",
  877. "Fragment",
  878. "TesselationControl",
  879. "TesselationEvaluation",
  880. "Compute",
  881. };