rendering_device_commons.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. /**************************************************************************/
  2. /* rendering_device_commons.h */
  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. #ifndef RENDERING_DEVICE_COMMONS_H
  31. #define RENDERING_DEVICE_COMMONS_H
  32. #include "core/object/object.h"
  33. #include "core/variant/type_info.h"
  34. #define STEPIFY(m_number, m_alignment) ((((m_number) + ((m_alignment)-1)) / (m_alignment)) * (m_alignment))
  35. class RenderingDeviceCommons : public Object {
  36. ////////////////////////////////////////////
  37. // PUBLIC STUFF
  38. // Exposed by RenderingDevice, and shared
  39. // with RenderingDeviceDriver.
  40. ////////////////////////////////////////////
  41. public:
  42. /*****************/
  43. /**** GENERIC ****/
  44. /*****************/
  45. static const int INVALID_ID = -1;
  46. enum DataFormat {
  47. DATA_FORMAT_R4G4_UNORM_PACK8,
  48. DATA_FORMAT_R4G4B4A4_UNORM_PACK16,
  49. DATA_FORMAT_B4G4R4A4_UNORM_PACK16,
  50. DATA_FORMAT_R5G6B5_UNORM_PACK16,
  51. DATA_FORMAT_B5G6R5_UNORM_PACK16,
  52. DATA_FORMAT_R5G5B5A1_UNORM_PACK16,
  53. DATA_FORMAT_B5G5R5A1_UNORM_PACK16,
  54. DATA_FORMAT_A1R5G5B5_UNORM_PACK16,
  55. DATA_FORMAT_R8_UNORM,
  56. DATA_FORMAT_R8_SNORM,
  57. DATA_FORMAT_R8_USCALED,
  58. DATA_FORMAT_R8_SSCALED,
  59. DATA_FORMAT_R8_UINT,
  60. DATA_FORMAT_R8_SINT,
  61. DATA_FORMAT_R8_SRGB,
  62. DATA_FORMAT_R8G8_UNORM,
  63. DATA_FORMAT_R8G8_SNORM,
  64. DATA_FORMAT_R8G8_USCALED,
  65. DATA_FORMAT_R8G8_SSCALED,
  66. DATA_FORMAT_R8G8_UINT,
  67. DATA_FORMAT_R8G8_SINT,
  68. DATA_FORMAT_R8G8_SRGB,
  69. DATA_FORMAT_R8G8B8_UNORM,
  70. DATA_FORMAT_R8G8B8_SNORM,
  71. DATA_FORMAT_R8G8B8_USCALED,
  72. DATA_FORMAT_R8G8B8_SSCALED,
  73. DATA_FORMAT_R8G8B8_UINT,
  74. DATA_FORMAT_R8G8B8_SINT,
  75. DATA_FORMAT_R8G8B8_SRGB,
  76. DATA_FORMAT_B8G8R8_UNORM,
  77. DATA_FORMAT_B8G8R8_SNORM,
  78. DATA_FORMAT_B8G8R8_USCALED,
  79. DATA_FORMAT_B8G8R8_SSCALED,
  80. DATA_FORMAT_B8G8R8_UINT,
  81. DATA_FORMAT_B8G8R8_SINT,
  82. DATA_FORMAT_B8G8R8_SRGB,
  83. DATA_FORMAT_R8G8B8A8_UNORM,
  84. DATA_FORMAT_R8G8B8A8_SNORM,
  85. DATA_FORMAT_R8G8B8A8_USCALED,
  86. DATA_FORMAT_R8G8B8A8_SSCALED,
  87. DATA_FORMAT_R8G8B8A8_UINT,
  88. DATA_FORMAT_R8G8B8A8_SINT,
  89. DATA_FORMAT_R8G8B8A8_SRGB,
  90. DATA_FORMAT_B8G8R8A8_UNORM,
  91. DATA_FORMAT_B8G8R8A8_SNORM,
  92. DATA_FORMAT_B8G8R8A8_USCALED,
  93. DATA_FORMAT_B8G8R8A8_SSCALED,
  94. DATA_FORMAT_B8G8R8A8_UINT,
  95. DATA_FORMAT_B8G8R8A8_SINT,
  96. DATA_FORMAT_B8G8R8A8_SRGB,
  97. DATA_FORMAT_A8B8G8R8_UNORM_PACK32,
  98. DATA_FORMAT_A8B8G8R8_SNORM_PACK32,
  99. DATA_FORMAT_A8B8G8R8_USCALED_PACK32,
  100. DATA_FORMAT_A8B8G8R8_SSCALED_PACK32,
  101. DATA_FORMAT_A8B8G8R8_UINT_PACK32,
  102. DATA_FORMAT_A8B8G8R8_SINT_PACK32,
  103. DATA_FORMAT_A8B8G8R8_SRGB_PACK32,
  104. DATA_FORMAT_A2R10G10B10_UNORM_PACK32,
  105. DATA_FORMAT_A2R10G10B10_SNORM_PACK32,
  106. DATA_FORMAT_A2R10G10B10_USCALED_PACK32,
  107. DATA_FORMAT_A2R10G10B10_SSCALED_PACK32,
  108. DATA_FORMAT_A2R10G10B10_UINT_PACK32,
  109. DATA_FORMAT_A2R10G10B10_SINT_PACK32,
  110. DATA_FORMAT_A2B10G10R10_UNORM_PACK32,
  111. DATA_FORMAT_A2B10G10R10_SNORM_PACK32,
  112. DATA_FORMAT_A2B10G10R10_USCALED_PACK32,
  113. DATA_FORMAT_A2B10G10R10_SSCALED_PACK32,
  114. DATA_FORMAT_A2B10G10R10_UINT_PACK32,
  115. DATA_FORMAT_A2B10G10R10_SINT_PACK32,
  116. DATA_FORMAT_R16_UNORM,
  117. DATA_FORMAT_R16_SNORM,
  118. DATA_FORMAT_R16_USCALED,
  119. DATA_FORMAT_R16_SSCALED,
  120. DATA_FORMAT_R16_UINT,
  121. DATA_FORMAT_R16_SINT,
  122. DATA_FORMAT_R16_SFLOAT,
  123. DATA_FORMAT_R16G16_UNORM,
  124. DATA_FORMAT_R16G16_SNORM,
  125. DATA_FORMAT_R16G16_USCALED,
  126. DATA_FORMAT_R16G16_SSCALED,
  127. DATA_FORMAT_R16G16_UINT,
  128. DATA_FORMAT_R16G16_SINT,
  129. DATA_FORMAT_R16G16_SFLOAT,
  130. DATA_FORMAT_R16G16B16_UNORM,
  131. DATA_FORMAT_R16G16B16_SNORM,
  132. DATA_FORMAT_R16G16B16_USCALED,
  133. DATA_FORMAT_R16G16B16_SSCALED,
  134. DATA_FORMAT_R16G16B16_UINT,
  135. DATA_FORMAT_R16G16B16_SINT,
  136. DATA_FORMAT_R16G16B16_SFLOAT,
  137. DATA_FORMAT_R16G16B16A16_UNORM,
  138. DATA_FORMAT_R16G16B16A16_SNORM,
  139. DATA_FORMAT_R16G16B16A16_USCALED,
  140. DATA_FORMAT_R16G16B16A16_SSCALED,
  141. DATA_FORMAT_R16G16B16A16_UINT,
  142. DATA_FORMAT_R16G16B16A16_SINT,
  143. DATA_FORMAT_R16G16B16A16_SFLOAT,
  144. DATA_FORMAT_R32_UINT,
  145. DATA_FORMAT_R32_SINT,
  146. DATA_FORMAT_R32_SFLOAT,
  147. DATA_FORMAT_R32G32_UINT,
  148. DATA_FORMAT_R32G32_SINT,
  149. DATA_FORMAT_R32G32_SFLOAT,
  150. DATA_FORMAT_R32G32B32_UINT,
  151. DATA_FORMAT_R32G32B32_SINT,
  152. DATA_FORMAT_R32G32B32_SFLOAT,
  153. DATA_FORMAT_R32G32B32A32_UINT,
  154. DATA_FORMAT_R32G32B32A32_SINT,
  155. DATA_FORMAT_R32G32B32A32_SFLOAT,
  156. DATA_FORMAT_R64_UINT,
  157. DATA_FORMAT_R64_SINT,
  158. DATA_FORMAT_R64_SFLOAT,
  159. DATA_FORMAT_R64G64_UINT,
  160. DATA_FORMAT_R64G64_SINT,
  161. DATA_FORMAT_R64G64_SFLOAT,
  162. DATA_FORMAT_R64G64B64_UINT,
  163. DATA_FORMAT_R64G64B64_SINT,
  164. DATA_FORMAT_R64G64B64_SFLOAT,
  165. DATA_FORMAT_R64G64B64A64_UINT,
  166. DATA_FORMAT_R64G64B64A64_SINT,
  167. DATA_FORMAT_R64G64B64A64_SFLOAT,
  168. DATA_FORMAT_B10G11R11_UFLOAT_PACK32,
  169. DATA_FORMAT_E5B9G9R9_UFLOAT_PACK32,
  170. DATA_FORMAT_D16_UNORM,
  171. DATA_FORMAT_X8_D24_UNORM_PACK32,
  172. DATA_FORMAT_D32_SFLOAT,
  173. DATA_FORMAT_S8_UINT,
  174. DATA_FORMAT_D16_UNORM_S8_UINT,
  175. DATA_FORMAT_D24_UNORM_S8_UINT,
  176. DATA_FORMAT_D32_SFLOAT_S8_UINT,
  177. DATA_FORMAT_BC1_RGB_UNORM_BLOCK,
  178. DATA_FORMAT_BC1_RGB_SRGB_BLOCK,
  179. DATA_FORMAT_BC1_RGBA_UNORM_BLOCK,
  180. DATA_FORMAT_BC1_RGBA_SRGB_BLOCK,
  181. DATA_FORMAT_BC2_UNORM_BLOCK,
  182. DATA_FORMAT_BC2_SRGB_BLOCK,
  183. DATA_FORMAT_BC3_UNORM_BLOCK,
  184. DATA_FORMAT_BC3_SRGB_BLOCK,
  185. DATA_FORMAT_BC4_UNORM_BLOCK,
  186. DATA_FORMAT_BC4_SNORM_BLOCK,
  187. DATA_FORMAT_BC5_UNORM_BLOCK,
  188. DATA_FORMAT_BC5_SNORM_BLOCK,
  189. DATA_FORMAT_BC6H_UFLOAT_BLOCK,
  190. DATA_FORMAT_BC6H_SFLOAT_BLOCK,
  191. DATA_FORMAT_BC7_UNORM_BLOCK,
  192. DATA_FORMAT_BC7_SRGB_BLOCK,
  193. DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
  194. DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
  195. DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
  196. DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
  197. DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
  198. DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
  199. DATA_FORMAT_EAC_R11_UNORM_BLOCK,
  200. DATA_FORMAT_EAC_R11_SNORM_BLOCK,
  201. DATA_FORMAT_EAC_R11G11_UNORM_BLOCK,
  202. DATA_FORMAT_EAC_R11G11_SNORM_BLOCK,
  203. DATA_FORMAT_ASTC_4x4_UNORM_BLOCK,
  204. DATA_FORMAT_ASTC_4x4_SRGB_BLOCK,
  205. DATA_FORMAT_ASTC_5x4_UNORM_BLOCK,
  206. DATA_FORMAT_ASTC_5x4_SRGB_BLOCK,
  207. DATA_FORMAT_ASTC_5x5_UNORM_BLOCK,
  208. DATA_FORMAT_ASTC_5x5_SRGB_BLOCK,
  209. DATA_FORMAT_ASTC_6x5_UNORM_BLOCK,
  210. DATA_FORMAT_ASTC_6x5_SRGB_BLOCK,
  211. DATA_FORMAT_ASTC_6x6_UNORM_BLOCK,
  212. DATA_FORMAT_ASTC_6x6_SRGB_BLOCK,
  213. DATA_FORMAT_ASTC_8x5_UNORM_BLOCK,
  214. DATA_FORMAT_ASTC_8x5_SRGB_BLOCK,
  215. DATA_FORMAT_ASTC_8x6_UNORM_BLOCK,
  216. DATA_FORMAT_ASTC_8x6_SRGB_BLOCK,
  217. DATA_FORMAT_ASTC_8x8_UNORM_BLOCK,
  218. DATA_FORMAT_ASTC_8x8_SRGB_BLOCK,
  219. DATA_FORMAT_ASTC_10x5_UNORM_BLOCK,
  220. DATA_FORMAT_ASTC_10x5_SRGB_BLOCK,
  221. DATA_FORMAT_ASTC_10x6_UNORM_BLOCK,
  222. DATA_FORMAT_ASTC_10x6_SRGB_BLOCK,
  223. DATA_FORMAT_ASTC_10x8_UNORM_BLOCK,
  224. DATA_FORMAT_ASTC_10x8_SRGB_BLOCK,
  225. DATA_FORMAT_ASTC_10x10_UNORM_BLOCK,
  226. DATA_FORMAT_ASTC_10x10_SRGB_BLOCK,
  227. DATA_FORMAT_ASTC_12x10_UNORM_BLOCK,
  228. DATA_FORMAT_ASTC_12x10_SRGB_BLOCK,
  229. DATA_FORMAT_ASTC_12x12_UNORM_BLOCK,
  230. DATA_FORMAT_ASTC_12x12_SRGB_BLOCK,
  231. DATA_FORMAT_G8B8G8R8_422_UNORM,
  232. DATA_FORMAT_B8G8R8G8_422_UNORM,
  233. DATA_FORMAT_G8_B8_R8_3PLANE_420_UNORM,
  234. DATA_FORMAT_G8_B8R8_2PLANE_420_UNORM,
  235. DATA_FORMAT_G8_B8_R8_3PLANE_422_UNORM,
  236. DATA_FORMAT_G8_B8R8_2PLANE_422_UNORM,
  237. DATA_FORMAT_G8_B8_R8_3PLANE_444_UNORM,
  238. DATA_FORMAT_R10X6_UNORM_PACK16,
  239. DATA_FORMAT_R10X6G10X6_UNORM_2PACK16,
  240. DATA_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16,
  241. DATA_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
  242. DATA_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,
  243. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
  244. DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
  245. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16,
  246. DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16,
  247. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16,
  248. DATA_FORMAT_R12X4_UNORM_PACK16,
  249. DATA_FORMAT_R12X4G12X4_UNORM_2PACK16,
  250. DATA_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,
  251. DATA_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
  252. DATA_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,
  253. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16,
  254. DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16,
  255. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16,
  256. DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16,
  257. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16,
  258. DATA_FORMAT_G16B16G16R16_422_UNORM,
  259. DATA_FORMAT_B16G16R16G16_422_UNORM,
  260. DATA_FORMAT_G16_B16_R16_3PLANE_420_UNORM,
  261. DATA_FORMAT_G16_B16R16_2PLANE_420_UNORM,
  262. DATA_FORMAT_G16_B16_R16_3PLANE_422_UNORM,
  263. DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM,
  264. DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM,
  265. DATA_FORMAT_MAX,
  266. };
  267. enum CompareOperator {
  268. COMPARE_OP_NEVER,
  269. COMPARE_OP_LESS,
  270. COMPARE_OP_EQUAL,
  271. COMPARE_OP_LESS_OR_EQUAL,
  272. COMPARE_OP_GREATER,
  273. COMPARE_OP_NOT_EQUAL,
  274. COMPARE_OP_GREATER_OR_EQUAL,
  275. COMPARE_OP_ALWAYS,
  276. COMPARE_OP_MAX
  277. };
  278. /*****************/
  279. /**** TEXTURE ****/
  280. /*****************/
  281. enum TextureType {
  282. TEXTURE_TYPE_1D,
  283. TEXTURE_TYPE_2D,
  284. TEXTURE_TYPE_3D,
  285. TEXTURE_TYPE_CUBE,
  286. TEXTURE_TYPE_1D_ARRAY,
  287. TEXTURE_TYPE_2D_ARRAY,
  288. TEXTURE_TYPE_CUBE_ARRAY,
  289. TEXTURE_TYPE_MAX,
  290. };
  291. enum TextureSamples {
  292. TEXTURE_SAMPLES_1,
  293. TEXTURE_SAMPLES_2,
  294. TEXTURE_SAMPLES_4,
  295. TEXTURE_SAMPLES_8,
  296. TEXTURE_SAMPLES_16,
  297. TEXTURE_SAMPLES_32,
  298. TEXTURE_SAMPLES_64,
  299. TEXTURE_SAMPLES_MAX,
  300. };
  301. enum TextureUsageBits {
  302. TEXTURE_USAGE_SAMPLING_BIT = (1 << 0),
  303. TEXTURE_USAGE_COLOR_ATTACHMENT_BIT = (1 << 1),
  304. TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = (1 << 2),
  305. TEXTURE_USAGE_STORAGE_BIT = (1 << 3),
  306. TEXTURE_USAGE_STORAGE_ATOMIC_BIT = (1 << 4),
  307. TEXTURE_USAGE_CPU_READ_BIT = (1 << 5),
  308. TEXTURE_USAGE_CAN_UPDATE_BIT = (1 << 6),
  309. TEXTURE_USAGE_CAN_COPY_FROM_BIT = (1 << 7),
  310. TEXTURE_USAGE_CAN_COPY_TO_BIT = (1 << 8),
  311. TEXTURE_USAGE_INPUT_ATTACHMENT_BIT = (1 << 9),
  312. TEXTURE_USAGE_VRS_ATTACHMENT_BIT = (1 << 10),
  313. };
  314. struct TextureFormat {
  315. DataFormat format = DATA_FORMAT_R8_UNORM;
  316. uint32_t width = 1;
  317. uint32_t height = 1;
  318. uint32_t depth = 1;
  319. uint32_t array_layers = 1;
  320. uint32_t mipmaps = 1;
  321. TextureType texture_type = TEXTURE_TYPE_2D;
  322. TextureSamples samples = TEXTURE_SAMPLES_1;
  323. uint32_t usage_bits = 0;
  324. Vector<DataFormat> shareable_formats;
  325. bool is_resolve_buffer = false;
  326. bool operator==(const TextureFormat &b) const {
  327. if (format != b.format) {
  328. return false;
  329. } else if (width != b.width) {
  330. return false;
  331. } else if (height != b.height) {
  332. return false;
  333. } else if (depth != b.depth) {
  334. return false;
  335. } else if (array_layers != b.array_layers) {
  336. return false;
  337. } else if (mipmaps != b.mipmaps) {
  338. return false;
  339. } else if (texture_type != b.texture_type) {
  340. return false;
  341. } else if (samples != b.samples) {
  342. return false;
  343. } else if (usage_bits != b.usage_bits) {
  344. return false;
  345. } else if (shareable_formats != b.shareable_formats) {
  346. return false;
  347. } else {
  348. return true;
  349. }
  350. }
  351. };
  352. enum TextureSwizzle {
  353. TEXTURE_SWIZZLE_IDENTITY,
  354. TEXTURE_SWIZZLE_ZERO,
  355. TEXTURE_SWIZZLE_ONE,
  356. TEXTURE_SWIZZLE_R,
  357. TEXTURE_SWIZZLE_G,
  358. TEXTURE_SWIZZLE_B,
  359. TEXTURE_SWIZZLE_A,
  360. TEXTURE_SWIZZLE_MAX
  361. };
  362. enum TextureSliceType {
  363. TEXTURE_SLICE_2D,
  364. TEXTURE_SLICE_CUBEMAP,
  365. TEXTURE_SLICE_3D,
  366. TEXTURE_SLICE_2D_ARRAY,
  367. TEXTURE_SLICE_MAX
  368. };
  369. /*****************/
  370. /**** SAMPLER ****/
  371. /*****************/
  372. enum SamplerFilter {
  373. SAMPLER_FILTER_NEAREST,
  374. SAMPLER_FILTER_LINEAR,
  375. };
  376. enum SamplerRepeatMode {
  377. SAMPLER_REPEAT_MODE_REPEAT,
  378. SAMPLER_REPEAT_MODE_MIRRORED_REPEAT,
  379. SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE,
  380. SAMPLER_REPEAT_MODE_CLAMP_TO_BORDER,
  381. SAMPLER_REPEAT_MODE_MIRROR_CLAMP_TO_EDGE,
  382. SAMPLER_REPEAT_MODE_MAX
  383. };
  384. enum SamplerBorderColor {
  385. SAMPLER_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
  386. SAMPLER_BORDER_COLOR_INT_TRANSPARENT_BLACK,
  387. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
  388. SAMPLER_BORDER_COLOR_INT_OPAQUE_BLACK,
  389. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
  390. SAMPLER_BORDER_COLOR_INT_OPAQUE_WHITE,
  391. SAMPLER_BORDER_COLOR_MAX
  392. };
  393. struct SamplerState {
  394. SamplerFilter mag_filter = SAMPLER_FILTER_NEAREST;
  395. SamplerFilter min_filter = SAMPLER_FILTER_NEAREST;
  396. SamplerFilter mip_filter = SAMPLER_FILTER_NEAREST;
  397. SamplerRepeatMode repeat_u = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  398. SamplerRepeatMode repeat_v = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  399. SamplerRepeatMode repeat_w = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  400. float lod_bias = 0.0f;
  401. bool use_anisotropy = false;
  402. float anisotropy_max = 1.0f;
  403. bool enable_compare = false;
  404. CompareOperator compare_op = COMPARE_OP_ALWAYS;
  405. float min_lod = 0.0f;
  406. float max_lod = 1e20; // Something very large should do.
  407. SamplerBorderColor border_color = SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
  408. bool unnormalized_uvw = false;
  409. };
  410. /**********************/
  411. /**** VERTEX ARRAY ****/
  412. /**********************/
  413. enum IndexBufferFormat {
  414. INDEX_BUFFER_FORMAT_UINT16,
  415. INDEX_BUFFER_FORMAT_UINT32,
  416. };
  417. enum VertexFrequency {
  418. VERTEX_FREQUENCY_VERTEX,
  419. VERTEX_FREQUENCY_INSTANCE,
  420. };
  421. struct VertexAttribute {
  422. uint32_t location = 0; // Shader location.
  423. uint32_t offset = 0;
  424. DataFormat format = DATA_FORMAT_MAX;
  425. uint32_t stride = 0;
  426. VertexFrequency frequency = VERTEX_FREQUENCY_VERTEX;
  427. };
  428. /*********************/
  429. /**** FRAMEBUFFER ****/
  430. /*********************/
  431. static const int32_t ATTACHMENT_UNUSED = -1;
  432. /****************/
  433. /**** SHADER ****/
  434. /****************/
  435. enum ShaderStage {
  436. SHADER_STAGE_VERTEX,
  437. SHADER_STAGE_FRAGMENT,
  438. SHADER_STAGE_TESSELATION_CONTROL,
  439. SHADER_STAGE_TESSELATION_EVALUATION,
  440. SHADER_STAGE_COMPUTE,
  441. SHADER_STAGE_MAX,
  442. SHADER_STAGE_VERTEX_BIT = (1 << SHADER_STAGE_VERTEX),
  443. SHADER_STAGE_FRAGMENT_BIT = (1 << SHADER_STAGE_FRAGMENT),
  444. SHADER_STAGE_TESSELATION_CONTROL_BIT = (1 << SHADER_STAGE_TESSELATION_CONTROL),
  445. SHADER_STAGE_TESSELATION_EVALUATION_BIT = (1 << SHADER_STAGE_TESSELATION_EVALUATION),
  446. SHADER_STAGE_COMPUTE_BIT = (1 << SHADER_STAGE_COMPUTE),
  447. };
  448. struct ShaderStageSPIRVData {
  449. ShaderStage shader_stage = SHADER_STAGE_MAX;
  450. Vector<uint8_t> spirv;
  451. };
  452. /*********************/
  453. /**** UNIFORM SET ****/
  454. /*********************/
  455. static const uint32_t MAX_UNIFORM_SETS = 16;
  456. enum UniformType {
  457. UNIFORM_TYPE_SAMPLER, // For sampling only (sampler GLSL type).
  458. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, // For sampling only, but includes a texture, (samplerXX GLSL type), first a sampler then a texture.
  459. UNIFORM_TYPE_TEXTURE, // Only texture, (textureXX GLSL type).
  460. UNIFORM_TYPE_IMAGE, // Storage image (imageXX GLSL type), for compute mostly.
  461. UNIFORM_TYPE_TEXTURE_BUFFER, // Buffer texture (or TBO, textureBuffer type).
  462. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE_BUFFER, // Buffer texture with a sampler(or TBO, samplerBuffer type).
  463. UNIFORM_TYPE_IMAGE_BUFFER, // Texel buffer, (imageBuffer type), for compute mostly.
  464. UNIFORM_TYPE_UNIFORM_BUFFER, // Regular uniform buffer (or UBO).
  465. UNIFORM_TYPE_STORAGE_BUFFER, // Storage buffer ("buffer" qualifier) like UBO, but supports storage, for compute mostly.
  466. UNIFORM_TYPE_INPUT_ATTACHMENT, // Used for sub-pass read/write, for mobile mostly.
  467. UNIFORM_TYPE_MAX
  468. };
  469. /******************/
  470. /**** PIPELINE ****/
  471. /******************/
  472. enum PipelineSpecializationConstantType {
  473. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL,
  474. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT,
  475. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT,
  476. };
  477. struct PipelineSpecializationConstant {
  478. PipelineSpecializationConstantType type = {};
  479. uint32_t constant_id = 0xffffffff;
  480. union {
  481. uint32_t int_value = 0;
  482. float float_value;
  483. bool bool_value;
  484. };
  485. };
  486. /*******************/
  487. /**** RENDERING ****/
  488. /*******************/
  489. // ----- PIPELINE -----
  490. enum RenderPrimitive {
  491. RENDER_PRIMITIVE_POINTS,
  492. RENDER_PRIMITIVE_LINES,
  493. RENDER_PRIMITIVE_LINES_WITH_ADJACENCY,
  494. RENDER_PRIMITIVE_LINESTRIPS,
  495. RENDER_PRIMITIVE_LINESTRIPS_WITH_ADJACENCY,
  496. RENDER_PRIMITIVE_TRIANGLES,
  497. RENDER_PRIMITIVE_TRIANGLES_WITH_ADJACENCY,
  498. RENDER_PRIMITIVE_TRIANGLE_STRIPS,
  499. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_AJACENCY,
  500. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_RESTART_INDEX,
  501. RENDER_PRIMITIVE_TESSELATION_PATCH,
  502. RENDER_PRIMITIVE_MAX
  503. };
  504. enum PolygonCullMode {
  505. POLYGON_CULL_DISABLED,
  506. POLYGON_CULL_FRONT,
  507. POLYGON_CULL_BACK,
  508. POLYGON_CULL_MAX
  509. };
  510. enum PolygonFrontFace {
  511. POLYGON_FRONT_FACE_CLOCKWISE,
  512. POLYGON_FRONT_FACE_COUNTER_CLOCKWISE,
  513. };
  514. enum StencilOperation {
  515. STENCIL_OP_KEEP,
  516. STENCIL_OP_ZERO,
  517. STENCIL_OP_REPLACE,
  518. STENCIL_OP_INCREMENT_AND_CLAMP,
  519. STENCIL_OP_DECREMENT_AND_CLAMP,
  520. STENCIL_OP_INVERT,
  521. STENCIL_OP_INCREMENT_AND_WRAP,
  522. STENCIL_OP_DECREMENT_AND_WRAP,
  523. STENCIL_OP_MAX
  524. };
  525. enum LogicOperation {
  526. LOGIC_OP_CLEAR,
  527. LOGIC_OP_AND,
  528. LOGIC_OP_AND_REVERSE,
  529. LOGIC_OP_COPY,
  530. LOGIC_OP_AND_INVERTED,
  531. LOGIC_OP_NO_OP,
  532. LOGIC_OP_XOR,
  533. LOGIC_OP_OR,
  534. LOGIC_OP_NOR,
  535. LOGIC_OP_EQUIVALENT,
  536. LOGIC_OP_INVERT,
  537. LOGIC_OP_OR_REVERSE,
  538. LOGIC_OP_COPY_INVERTED,
  539. LOGIC_OP_OR_INVERTED,
  540. LOGIC_OP_NAND,
  541. LOGIC_OP_SET,
  542. LOGIC_OP_MAX
  543. };
  544. enum BlendFactor {
  545. BLEND_FACTOR_ZERO,
  546. BLEND_FACTOR_ONE,
  547. BLEND_FACTOR_SRC_COLOR,
  548. BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
  549. BLEND_FACTOR_DST_COLOR,
  550. BLEND_FACTOR_ONE_MINUS_DST_COLOR,
  551. BLEND_FACTOR_SRC_ALPHA,
  552. BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
  553. BLEND_FACTOR_DST_ALPHA,
  554. BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
  555. BLEND_FACTOR_CONSTANT_COLOR,
  556. BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
  557. BLEND_FACTOR_CONSTANT_ALPHA,
  558. BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
  559. BLEND_FACTOR_SRC_ALPHA_SATURATE,
  560. BLEND_FACTOR_SRC1_COLOR,
  561. BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
  562. BLEND_FACTOR_SRC1_ALPHA,
  563. BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
  564. BLEND_FACTOR_MAX
  565. };
  566. enum BlendOperation {
  567. BLEND_OP_ADD,
  568. BLEND_OP_SUBTRACT,
  569. BLEND_OP_REVERSE_SUBTRACT,
  570. BLEND_OP_MINIMUM,
  571. BLEND_OP_MAXIMUM, // Yes, this one is an actual operator.
  572. BLEND_OP_MAX
  573. };
  574. struct PipelineRasterizationState {
  575. bool enable_depth_clamp = false;
  576. bool discard_primitives = false;
  577. bool wireframe = false;
  578. PolygonCullMode cull_mode = POLYGON_CULL_DISABLED;
  579. PolygonFrontFace front_face = POLYGON_FRONT_FACE_CLOCKWISE;
  580. bool depth_bias_enabled = false;
  581. float depth_bias_constant_factor = 0.0f;
  582. float depth_bias_clamp = 0.0f;
  583. float depth_bias_slope_factor = 0.0f;
  584. float line_width = 1.0f;
  585. uint32_t patch_control_points = 1;
  586. };
  587. struct PipelineMultisampleState {
  588. TextureSamples sample_count = TEXTURE_SAMPLES_1;
  589. bool enable_sample_shading = false;
  590. float min_sample_shading = 0.0f;
  591. Vector<uint32_t> sample_mask;
  592. bool enable_alpha_to_coverage = false;
  593. bool enable_alpha_to_one = false;
  594. };
  595. struct PipelineDepthStencilState {
  596. bool enable_depth_test = false;
  597. bool enable_depth_write = false;
  598. CompareOperator depth_compare_operator = COMPARE_OP_ALWAYS;
  599. bool enable_depth_range = false;
  600. float depth_range_min = 0;
  601. float depth_range_max = 0;
  602. bool enable_stencil = false;
  603. struct StencilOperationState {
  604. StencilOperation fail = STENCIL_OP_ZERO;
  605. StencilOperation pass = STENCIL_OP_ZERO;
  606. StencilOperation depth_fail = STENCIL_OP_ZERO;
  607. CompareOperator compare = COMPARE_OP_ALWAYS;
  608. uint32_t compare_mask = 0;
  609. uint32_t write_mask = 0;
  610. uint32_t reference = 0;
  611. };
  612. StencilOperationState front_op;
  613. StencilOperationState back_op;
  614. };
  615. struct PipelineColorBlendState {
  616. bool enable_logic_op = false;
  617. LogicOperation logic_op = LOGIC_OP_CLEAR;
  618. struct Attachment {
  619. bool enable_blend = false;
  620. BlendFactor src_color_blend_factor = BLEND_FACTOR_ZERO;
  621. BlendFactor dst_color_blend_factor = BLEND_FACTOR_ZERO;
  622. BlendOperation color_blend_op = BLEND_OP_ADD;
  623. BlendFactor src_alpha_blend_factor = BLEND_FACTOR_ZERO;
  624. BlendFactor dst_alpha_blend_factor = BLEND_FACTOR_ZERO;
  625. BlendOperation alpha_blend_op = BLEND_OP_ADD;
  626. bool write_r = true;
  627. bool write_g = true;
  628. bool write_b = true;
  629. bool write_a = true;
  630. };
  631. static PipelineColorBlendState create_disabled(int p_attachments = 1) {
  632. PipelineColorBlendState bs;
  633. for (int i = 0; i < p_attachments; i++) {
  634. bs.attachments.push_back(Attachment());
  635. }
  636. return bs;
  637. }
  638. static PipelineColorBlendState create_blend(int p_attachments = 1) {
  639. PipelineColorBlendState bs;
  640. for (int i = 0; i < p_attachments; i++) {
  641. Attachment ba;
  642. ba.enable_blend = true;
  643. ba.src_color_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  644. ba.dst_color_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  645. ba.src_alpha_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  646. ba.dst_alpha_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  647. bs.attachments.push_back(ba);
  648. }
  649. return bs;
  650. }
  651. Vector<Attachment> attachments; // One per render target texture.
  652. Color blend_constant;
  653. };
  654. enum PipelineDynamicStateFlags {
  655. DYNAMIC_STATE_LINE_WIDTH = (1 << 0),
  656. DYNAMIC_STATE_DEPTH_BIAS = (1 << 1),
  657. DYNAMIC_STATE_BLEND_CONSTANTS = (1 << 2),
  658. DYNAMIC_STATE_DEPTH_BOUNDS = (1 << 3),
  659. DYNAMIC_STATE_STENCIL_COMPARE_MASK = (1 << 4),
  660. DYNAMIC_STATE_STENCIL_WRITE_MASK = (1 << 5),
  661. DYNAMIC_STATE_STENCIL_REFERENCE = (1 << 6),
  662. };
  663. /**************/
  664. /**** MISC ****/
  665. /**************/
  666. // This enum matches VkPhysicalDeviceType (except for `DEVICE_TYPE_MAX`).
  667. // Unlike VkPhysicalDeviceType, DeviceType is exposed to the scripting API.
  668. enum DeviceType {
  669. DEVICE_TYPE_OTHER,
  670. DEVICE_TYPE_INTEGRATED_GPU,
  671. DEVICE_TYPE_DISCRETE_GPU,
  672. DEVICE_TYPE_VIRTUAL_GPU,
  673. DEVICE_TYPE_CPU,
  674. DEVICE_TYPE_MAX
  675. };
  676. // Defined in an API-agnostic way.
  677. // Some may not make sense for the underlying API; in that case, 0 is returned.
  678. enum DriverResource {
  679. DRIVER_RESOURCE_LOGICAL_DEVICE,
  680. DRIVER_RESOURCE_PHYSICAL_DEVICE,
  681. DRIVER_RESOURCE_TOPMOST_OBJECT,
  682. DRIVER_RESOURCE_COMMAND_QUEUE,
  683. DRIVER_RESOURCE_QUEUE_FAMILY,
  684. DRIVER_RESOURCE_TEXTURE,
  685. DRIVER_RESOURCE_TEXTURE_VIEW,
  686. DRIVER_RESOURCE_TEXTURE_DATA_FORMAT,
  687. DRIVER_RESOURCE_SAMPLER,
  688. DRIVER_RESOURCE_UNIFORM_SET,
  689. DRIVER_RESOURCE_BUFFER,
  690. DRIVER_RESOURCE_COMPUTE_PIPELINE,
  691. DRIVER_RESOURCE_RENDER_PIPELINE,
  692. #ifndef DISABLE_DEPRECATED
  693. DRIVER_RESOURCE_VULKAN_DEVICE = DRIVER_RESOURCE_LOGICAL_DEVICE,
  694. DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE = DRIVER_RESOURCE_PHYSICAL_DEVICE,
  695. DRIVER_RESOURCE_VULKAN_INSTANCE = DRIVER_RESOURCE_TOPMOST_OBJECT,
  696. DRIVER_RESOURCE_VULKAN_QUEUE = DRIVER_RESOURCE_COMMAND_QUEUE,
  697. DRIVER_RESOURCE_VULKAN_QUEUE_FAMILY_INDEX = DRIVER_RESOURCE_QUEUE_FAMILY,
  698. DRIVER_RESOURCE_VULKAN_IMAGE = DRIVER_RESOURCE_TEXTURE,
  699. DRIVER_RESOURCE_VULKAN_IMAGE_VIEW = DRIVER_RESOURCE_TEXTURE_VIEW,
  700. DRIVER_RESOURCE_VULKAN_IMAGE_NATIVE_TEXTURE_FORMAT = DRIVER_RESOURCE_TEXTURE_DATA_FORMAT,
  701. DRIVER_RESOURCE_VULKAN_SAMPLER = DRIVER_RESOURCE_SAMPLER,
  702. DRIVER_RESOURCE_VULKAN_DESCRIPTOR_SET = DRIVER_RESOURCE_UNIFORM_SET,
  703. DRIVER_RESOURCE_VULKAN_BUFFER = DRIVER_RESOURCE_BUFFER,
  704. DRIVER_RESOURCE_VULKAN_COMPUTE_PIPELINE = DRIVER_RESOURCE_COMPUTE_PIPELINE,
  705. DRIVER_RESOURCE_VULKAN_RENDER_PIPELINE = DRIVER_RESOURCE_RENDER_PIPELINE,
  706. #endif
  707. };
  708. enum Limit {
  709. LIMIT_MAX_BOUND_UNIFORM_SETS,
  710. LIMIT_MAX_FRAMEBUFFER_COLOR_ATTACHMENTS,
  711. LIMIT_MAX_TEXTURES_PER_UNIFORM_SET,
  712. LIMIT_MAX_SAMPLERS_PER_UNIFORM_SET,
  713. LIMIT_MAX_STORAGE_BUFFERS_PER_UNIFORM_SET,
  714. LIMIT_MAX_STORAGE_IMAGES_PER_UNIFORM_SET,
  715. LIMIT_MAX_UNIFORM_BUFFERS_PER_UNIFORM_SET,
  716. LIMIT_MAX_DRAW_INDEXED_INDEX,
  717. LIMIT_MAX_FRAMEBUFFER_HEIGHT,
  718. LIMIT_MAX_FRAMEBUFFER_WIDTH,
  719. LIMIT_MAX_TEXTURE_ARRAY_LAYERS,
  720. LIMIT_MAX_TEXTURE_SIZE_1D,
  721. LIMIT_MAX_TEXTURE_SIZE_2D,
  722. LIMIT_MAX_TEXTURE_SIZE_3D,
  723. LIMIT_MAX_TEXTURE_SIZE_CUBE,
  724. LIMIT_MAX_TEXTURES_PER_SHADER_STAGE,
  725. LIMIT_MAX_SAMPLERS_PER_SHADER_STAGE,
  726. LIMIT_MAX_STORAGE_BUFFERS_PER_SHADER_STAGE,
  727. LIMIT_MAX_STORAGE_IMAGES_PER_SHADER_STAGE,
  728. LIMIT_MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE,
  729. LIMIT_MAX_PUSH_CONSTANT_SIZE,
  730. LIMIT_MAX_UNIFORM_BUFFER_SIZE,
  731. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTE_OFFSET,
  732. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTES,
  733. LIMIT_MAX_VERTEX_INPUT_BINDINGS,
  734. LIMIT_MAX_VERTEX_INPUT_BINDING_STRIDE,
  735. LIMIT_MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
  736. LIMIT_MAX_COMPUTE_SHARED_MEMORY_SIZE,
  737. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X,
  738. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Y,
  739. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Z,
  740. LIMIT_MAX_COMPUTE_WORKGROUP_INVOCATIONS,
  741. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_X,
  742. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Y,
  743. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z,
  744. LIMIT_MAX_VIEWPORT_DIMENSIONS_X,
  745. LIMIT_MAX_VIEWPORT_DIMENSIONS_Y,
  746. LIMIT_SUBGROUP_SIZE,
  747. LIMIT_SUBGROUP_MIN_SIZE,
  748. LIMIT_SUBGROUP_MAX_SIZE,
  749. LIMIT_SUBGROUP_IN_SHADERS, // Set flags using SHADER_STAGE_VERTEX_BIT, SHADER_STAGE_FRAGMENT_BIT, etc.
  750. LIMIT_SUBGROUP_OPERATIONS,
  751. LIMIT_VRS_TEXEL_WIDTH,
  752. LIMIT_VRS_TEXEL_HEIGHT,
  753. LIMIT_VRS_MAX_FRAGMENT_WIDTH,
  754. LIMIT_VRS_MAX_FRAGMENT_HEIGHT,
  755. };
  756. enum Features {
  757. SUPPORTS_MULTIVIEW,
  758. SUPPORTS_FSR_HALF_FLOAT,
  759. SUPPORTS_ATTACHMENT_VRS,
  760. // If not supported, a fragment shader with only side effets (i.e., writes to buffers, but doesn't output to attachments), may be optimized down to no-op by the GPU driver.
  761. SUPPORTS_FRAGMENT_SHADER_WITH_ONLY_SIDE_EFFECTS,
  762. };
  763. enum SubgroupOperations {
  764. SUBGROUP_BASIC_BIT = 1,
  765. SUBGROUP_VOTE_BIT = 2,
  766. SUBGROUP_ARITHMETIC_BIT = 4,
  767. SUBGROUP_BALLOT_BIT = 8,
  768. SUBGROUP_SHUFFLE_BIT = 16,
  769. SUBGROUP_SHUFFLE_RELATIVE_BIT = 32,
  770. SUBGROUP_CLUSTERED_BIT = 64,
  771. SUBGROUP_QUAD_BIT = 128,
  772. };
  773. ////////////////////////////////////////////
  774. // PROTECTED STUFF
  775. // Not exposed by RenderingDevice, but shared
  776. // with RenderingDeviceDriver for convenience.
  777. ////////////////////////////////////////////
  778. protected:
  779. /*****************/
  780. /**** GENERIC ****/
  781. /*****************/
  782. static const char *const FORMAT_NAMES[DATA_FORMAT_MAX];
  783. /*****************/
  784. /**** TEXTURE ****/
  785. /*****************/
  786. static const uint32_t MAX_IMAGE_FORMAT_PLANES = 2;
  787. static const uint32_t TEXTURE_SAMPLES_COUNT[TEXTURE_SAMPLES_MAX];
  788. static uint32_t get_image_format_pixel_size(DataFormat p_format);
  789. static void get_compressed_image_format_block_dimensions(DataFormat p_format, uint32_t &r_w, uint32_t &r_h);
  790. uint32_t get_compressed_image_format_block_byte_size(DataFormat p_format);
  791. static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format);
  792. static uint32_t 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 = nullptr, uint32_t *r_blockh = nullptr, uint32_t *r_depth = nullptr);
  793. static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth);
  794. static bool format_has_stencil(DataFormat p_format);
  795. static uint32_t format_get_plane_count(DataFormat p_format);
  796. /*****************/
  797. /**** SAMPLER ****/
  798. /*****************/
  799. static const Color SAMPLER_BORDER_COLOR_VALUE[SAMPLER_BORDER_COLOR_MAX];
  800. /**********************/
  801. /**** VERTEX ARRAY ****/
  802. /**********************/
  803. static uint32_t get_format_vertex_size(DataFormat p_format);
  804. /****************/
  805. /**** SHADER ****/
  806. /****************/
  807. static const char *SHADER_STAGE_NAMES[SHADER_STAGE_MAX];
  808. public:
  809. struct ShaderUniform {
  810. UniformType type = UniformType::UNIFORM_TYPE_MAX;
  811. bool writable = false;
  812. uint32_t binding = 0;
  813. BitField<ShaderStage> stages;
  814. uint32_t length = 0; // Size of arrays (in total elements), or ubos (in bytes * total elements).
  815. bool operator!=(const ShaderUniform &p_other) const {
  816. return binding != p_other.binding || type != p_other.type || writable != p_other.writable || stages != p_other.stages || length != p_other.length;
  817. }
  818. bool operator<(const ShaderUniform &p_other) const {
  819. if (binding != p_other.binding) {
  820. return binding < p_other.binding;
  821. }
  822. if (type != p_other.type) {
  823. return type < p_other.type;
  824. }
  825. if (writable != p_other.writable) {
  826. return writable < p_other.writable;
  827. }
  828. if (stages != p_other.stages) {
  829. return stages < p_other.stages;
  830. }
  831. if (length != p_other.length) {
  832. return length < p_other.length;
  833. }
  834. return false;
  835. }
  836. };
  837. struct ShaderSpecializationConstant : public PipelineSpecializationConstant {
  838. BitField<ShaderStage> stages;
  839. bool operator<(const ShaderSpecializationConstant &p_other) const { return constant_id < p_other.constant_id; }
  840. };
  841. struct ShaderDescription {
  842. uint64_t vertex_input_mask = 0;
  843. uint32_t fragment_output_mask = 0;
  844. bool is_compute = false;
  845. uint32_t compute_local_size[3] = {};
  846. uint32_t push_constant_size = 0;
  847. Vector<Vector<ShaderUniform>> uniform_sets;
  848. Vector<ShaderSpecializationConstant> specialization_constants;
  849. Vector<ShaderStage> stages;
  850. };
  851. protected:
  852. struct ShaderReflection : public ShaderDescription {
  853. BitField<ShaderStage> stages;
  854. BitField<ShaderStage> push_constant_stages;
  855. };
  856. };
  857. #endif // RENDERING_DEVICE_COMMONS_H