rendering_device_commons.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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. // Breadcrumb markers are useful for debugging GPU crashes (i.e. DEVICE_LOST). Internally
  268. // they're just an uint32_t to "tag" a GPU command. These are only used for debugging and do not
  269. // (or at least shouldn't) alter the execution behavior in any way.
  270. //
  271. // When a GPU crashes and Godot was built in dev or debug mode; Godot will dump what commands
  272. // were being executed and what tag they were marked with.
  273. // This makes narrowing down the cause of a crash easier. Note that a GPU can be executing
  274. // multiple commands at the same time. It is also useful to identify data hazards.
  275. //
  276. // For example if each LIGHTMAPPER_PASS must be executed in sequential order, but dumps
  277. // indicated that pass (LIGHTMAPPER_PASS | 5) was being executed at the same time as
  278. // (LIGHTMAPPER_PASS | 4), that would indicate there is a missing barrier or a render graph bug.
  279. //
  280. // The enums are bitshifted by 16 bits so it's possible to add user data via bitwise operations.
  281. // Using this enum is not mandatory; but it is recommended so that all subsystems agree what each
  282. // ID means when dumping info.
  283. enum BreadcrumbMarker {
  284. NONE = 0,
  285. // Environment
  286. REFLECTION_PROBES = 1u << 16u,
  287. SKY_PASS = 2u << 16u,
  288. // Light mapping
  289. LIGHTMAPPER_PASS = 3u << 16u,
  290. // Shadows
  291. SHADOW_PASS_DIRECTIONAL = 4u << 16u,
  292. SHADOW_PASS_CUBE = 5u << 16u,
  293. // Geometry passes
  294. OPAQUE_PASS = 6u << 16u,
  295. ALPHA_PASS = 7u << 16u,
  296. TRANSPARENT_PASS = 8u << 16u,
  297. // Screen effects
  298. POST_PROCESSING_PASS = 9u << 16u,
  299. BLIT_PASS = 10u << 16u,
  300. UI_PASS = 11u << 16u,
  301. // Other
  302. DEBUG_PASS = 12u << 16u,
  303. };
  304. enum CompareOperator {
  305. COMPARE_OP_NEVER,
  306. COMPARE_OP_LESS,
  307. COMPARE_OP_EQUAL,
  308. COMPARE_OP_LESS_OR_EQUAL,
  309. COMPARE_OP_GREATER,
  310. COMPARE_OP_NOT_EQUAL,
  311. COMPARE_OP_GREATER_OR_EQUAL,
  312. COMPARE_OP_ALWAYS,
  313. COMPARE_OP_MAX
  314. };
  315. /*****************/
  316. /**** TEXTURE ****/
  317. /*****************/
  318. enum TextureType {
  319. TEXTURE_TYPE_1D,
  320. TEXTURE_TYPE_2D,
  321. TEXTURE_TYPE_3D,
  322. TEXTURE_TYPE_CUBE,
  323. TEXTURE_TYPE_1D_ARRAY,
  324. TEXTURE_TYPE_2D_ARRAY,
  325. TEXTURE_TYPE_CUBE_ARRAY,
  326. TEXTURE_TYPE_MAX,
  327. };
  328. enum TextureSamples {
  329. TEXTURE_SAMPLES_1,
  330. TEXTURE_SAMPLES_2,
  331. TEXTURE_SAMPLES_4,
  332. TEXTURE_SAMPLES_8,
  333. TEXTURE_SAMPLES_16,
  334. TEXTURE_SAMPLES_32,
  335. TEXTURE_SAMPLES_64,
  336. TEXTURE_SAMPLES_MAX,
  337. };
  338. enum TextureUsageBits {
  339. TEXTURE_USAGE_SAMPLING_BIT = (1 << 0),
  340. TEXTURE_USAGE_COLOR_ATTACHMENT_BIT = (1 << 1),
  341. TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = (1 << 2),
  342. TEXTURE_USAGE_STORAGE_BIT = (1 << 3),
  343. TEXTURE_USAGE_STORAGE_ATOMIC_BIT = (1 << 4),
  344. TEXTURE_USAGE_CPU_READ_BIT = (1 << 5),
  345. TEXTURE_USAGE_CAN_UPDATE_BIT = (1 << 6),
  346. TEXTURE_USAGE_CAN_COPY_FROM_BIT = (1 << 7),
  347. TEXTURE_USAGE_CAN_COPY_TO_BIT = (1 << 8),
  348. TEXTURE_USAGE_INPUT_ATTACHMENT_BIT = (1 << 9),
  349. TEXTURE_USAGE_VRS_ATTACHMENT_BIT = (1 << 10),
  350. };
  351. struct TextureFormat {
  352. DataFormat format = DATA_FORMAT_R8_UNORM;
  353. uint32_t width = 1;
  354. uint32_t height = 1;
  355. uint32_t depth = 1;
  356. uint32_t array_layers = 1;
  357. uint32_t mipmaps = 1;
  358. TextureType texture_type = TEXTURE_TYPE_2D;
  359. TextureSamples samples = TEXTURE_SAMPLES_1;
  360. uint32_t usage_bits = 0;
  361. Vector<DataFormat> shareable_formats;
  362. bool is_resolve_buffer = false;
  363. bool operator==(const TextureFormat &b) const {
  364. if (format != b.format) {
  365. return false;
  366. } else if (width != b.width) {
  367. return false;
  368. } else if (height != b.height) {
  369. return false;
  370. } else if (depth != b.depth) {
  371. return false;
  372. } else if (array_layers != b.array_layers) {
  373. return false;
  374. } else if (mipmaps != b.mipmaps) {
  375. return false;
  376. } else if (texture_type != b.texture_type) {
  377. return false;
  378. } else if (samples != b.samples) {
  379. return false;
  380. } else if (usage_bits != b.usage_bits) {
  381. return false;
  382. } else if (shareable_formats != b.shareable_formats) {
  383. return false;
  384. } else {
  385. return true;
  386. }
  387. }
  388. };
  389. enum TextureSwizzle {
  390. TEXTURE_SWIZZLE_IDENTITY,
  391. TEXTURE_SWIZZLE_ZERO,
  392. TEXTURE_SWIZZLE_ONE,
  393. TEXTURE_SWIZZLE_R,
  394. TEXTURE_SWIZZLE_G,
  395. TEXTURE_SWIZZLE_B,
  396. TEXTURE_SWIZZLE_A,
  397. TEXTURE_SWIZZLE_MAX
  398. };
  399. enum TextureSliceType {
  400. TEXTURE_SLICE_2D,
  401. TEXTURE_SLICE_CUBEMAP,
  402. TEXTURE_SLICE_3D,
  403. TEXTURE_SLICE_2D_ARRAY,
  404. TEXTURE_SLICE_MAX
  405. };
  406. /*****************/
  407. /**** SAMPLER ****/
  408. /*****************/
  409. enum SamplerFilter {
  410. SAMPLER_FILTER_NEAREST,
  411. SAMPLER_FILTER_LINEAR,
  412. };
  413. enum SamplerRepeatMode {
  414. SAMPLER_REPEAT_MODE_REPEAT,
  415. SAMPLER_REPEAT_MODE_MIRRORED_REPEAT,
  416. SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE,
  417. SAMPLER_REPEAT_MODE_CLAMP_TO_BORDER,
  418. SAMPLER_REPEAT_MODE_MIRROR_CLAMP_TO_EDGE,
  419. SAMPLER_REPEAT_MODE_MAX
  420. };
  421. enum SamplerBorderColor {
  422. SAMPLER_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
  423. SAMPLER_BORDER_COLOR_INT_TRANSPARENT_BLACK,
  424. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
  425. SAMPLER_BORDER_COLOR_INT_OPAQUE_BLACK,
  426. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
  427. SAMPLER_BORDER_COLOR_INT_OPAQUE_WHITE,
  428. SAMPLER_BORDER_COLOR_MAX
  429. };
  430. struct SamplerState {
  431. SamplerFilter mag_filter = SAMPLER_FILTER_NEAREST;
  432. SamplerFilter min_filter = SAMPLER_FILTER_NEAREST;
  433. SamplerFilter mip_filter = SAMPLER_FILTER_NEAREST;
  434. SamplerRepeatMode repeat_u = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  435. SamplerRepeatMode repeat_v = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  436. SamplerRepeatMode repeat_w = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  437. float lod_bias = 0.0f;
  438. bool use_anisotropy = false;
  439. float anisotropy_max = 1.0f;
  440. bool enable_compare = false;
  441. CompareOperator compare_op = COMPARE_OP_ALWAYS;
  442. float min_lod = 0.0f;
  443. float max_lod = 1e20; // Something very large should do.
  444. SamplerBorderColor border_color = SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
  445. bool unnormalized_uvw = false;
  446. };
  447. /**********************/
  448. /**** VERTEX ARRAY ****/
  449. /**********************/
  450. enum IndexBufferFormat {
  451. INDEX_BUFFER_FORMAT_UINT16,
  452. INDEX_BUFFER_FORMAT_UINT32,
  453. };
  454. enum VertexFrequency {
  455. VERTEX_FREQUENCY_VERTEX,
  456. VERTEX_FREQUENCY_INSTANCE,
  457. };
  458. struct VertexAttribute {
  459. uint32_t location = 0; // Shader location.
  460. uint32_t offset = 0;
  461. DataFormat format = DATA_FORMAT_MAX;
  462. uint32_t stride = 0;
  463. VertexFrequency frequency = VERTEX_FREQUENCY_VERTEX;
  464. };
  465. /*********************/
  466. /**** FRAMEBUFFER ****/
  467. /*********************/
  468. static const int32_t ATTACHMENT_UNUSED = -1;
  469. /****************/
  470. /**** SHADER ****/
  471. /****************/
  472. enum ShaderStage {
  473. SHADER_STAGE_VERTEX,
  474. SHADER_STAGE_FRAGMENT,
  475. SHADER_STAGE_TESSELATION_CONTROL,
  476. SHADER_STAGE_TESSELATION_EVALUATION,
  477. SHADER_STAGE_COMPUTE,
  478. SHADER_STAGE_MAX,
  479. SHADER_STAGE_VERTEX_BIT = (1 << SHADER_STAGE_VERTEX),
  480. SHADER_STAGE_FRAGMENT_BIT = (1 << SHADER_STAGE_FRAGMENT),
  481. SHADER_STAGE_TESSELATION_CONTROL_BIT = (1 << SHADER_STAGE_TESSELATION_CONTROL),
  482. SHADER_STAGE_TESSELATION_EVALUATION_BIT = (1 << SHADER_STAGE_TESSELATION_EVALUATION),
  483. SHADER_STAGE_COMPUTE_BIT = (1 << SHADER_STAGE_COMPUTE),
  484. };
  485. struct ShaderStageSPIRVData {
  486. ShaderStage shader_stage = SHADER_STAGE_MAX;
  487. Vector<uint8_t> spirv;
  488. };
  489. /*********************/
  490. /**** UNIFORM SET ****/
  491. /*********************/
  492. static const uint32_t MAX_UNIFORM_SETS = 16;
  493. enum UniformType {
  494. UNIFORM_TYPE_SAMPLER, // For sampling only (sampler GLSL type).
  495. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, // For sampling only, but includes a texture, (samplerXX GLSL type), first a sampler then a texture.
  496. UNIFORM_TYPE_TEXTURE, // Only texture, (textureXX GLSL type).
  497. UNIFORM_TYPE_IMAGE, // Storage image (imageXX GLSL type), for compute mostly.
  498. UNIFORM_TYPE_TEXTURE_BUFFER, // Buffer texture (or TBO, textureBuffer type).
  499. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE_BUFFER, // Buffer texture with a sampler(or TBO, samplerBuffer type).
  500. UNIFORM_TYPE_IMAGE_BUFFER, // Texel buffer, (imageBuffer type), for compute mostly.
  501. UNIFORM_TYPE_UNIFORM_BUFFER, // Regular uniform buffer (or UBO).
  502. UNIFORM_TYPE_STORAGE_BUFFER, // Storage buffer ("buffer" qualifier) like UBO, but supports storage, for compute mostly.
  503. UNIFORM_TYPE_INPUT_ATTACHMENT, // Used for sub-pass read/write, for mobile mostly.
  504. UNIFORM_TYPE_MAX
  505. };
  506. /******************/
  507. /**** PIPELINE ****/
  508. /******************/
  509. enum PipelineSpecializationConstantType {
  510. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL,
  511. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT,
  512. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT,
  513. };
  514. struct PipelineSpecializationConstant {
  515. PipelineSpecializationConstantType type = {};
  516. uint32_t constant_id = 0xffffffff;
  517. union {
  518. uint32_t int_value = 0;
  519. float float_value;
  520. bool bool_value;
  521. };
  522. };
  523. /*******************/
  524. /**** RENDERING ****/
  525. /*******************/
  526. // ----- PIPELINE -----
  527. enum RenderPrimitive {
  528. RENDER_PRIMITIVE_POINTS,
  529. RENDER_PRIMITIVE_LINES,
  530. RENDER_PRIMITIVE_LINES_WITH_ADJACENCY,
  531. RENDER_PRIMITIVE_LINESTRIPS,
  532. RENDER_PRIMITIVE_LINESTRIPS_WITH_ADJACENCY,
  533. RENDER_PRIMITIVE_TRIANGLES,
  534. RENDER_PRIMITIVE_TRIANGLES_WITH_ADJACENCY,
  535. RENDER_PRIMITIVE_TRIANGLE_STRIPS,
  536. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_AJACENCY,
  537. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_RESTART_INDEX,
  538. RENDER_PRIMITIVE_TESSELATION_PATCH,
  539. RENDER_PRIMITIVE_MAX
  540. };
  541. enum PolygonCullMode {
  542. POLYGON_CULL_DISABLED,
  543. POLYGON_CULL_FRONT,
  544. POLYGON_CULL_BACK,
  545. POLYGON_CULL_MAX
  546. };
  547. enum PolygonFrontFace {
  548. POLYGON_FRONT_FACE_CLOCKWISE,
  549. POLYGON_FRONT_FACE_COUNTER_CLOCKWISE,
  550. };
  551. enum StencilOperation {
  552. STENCIL_OP_KEEP,
  553. STENCIL_OP_ZERO,
  554. STENCIL_OP_REPLACE,
  555. STENCIL_OP_INCREMENT_AND_CLAMP,
  556. STENCIL_OP_DECREMENT_AND_CLAMP,
  557. STENCIL_OP_INVERT,
  558. STENCIL_OP_INCREMENT_AND_WRAP,
  559. STENCIL_OP_DECREMENT_AND_WRAP,
  560. STENCIL_OP_MAX
  561. };
  562. enum LogicOperation {
  563. LOGIC_OP_CLEAR,
  564. LOGIC_OP_AND,
  565. LOGIC_OP_AND_REVERSE,
  566. LOGIC_OP_COPY,
  567. LOGIC_OP_AND_INVERTED,
  568. LOGIC_OP_NO_OP,
  569. LOGIC_OP_XOR,
  570. LOGIC_OP_OR,
  571. LOGIC_OP_NOR,
  572. LOGIC_OP_EQUIVALENT,
  573. LOGIC_OP_INVERT,
  574. LOGIC_OP_OR_REVERSE,
  575. LOGIC_OP_COPY_INVERTED,
  576. LOGIC_OP_OR_INVERTED,
  577. LOGIC_OP_NAND,
  578. LOGIC_OP_SET,
  579. LOGIC_OP_MAX
  580. };
  581. enum BlendFactor {
  582. BLEND_FACTOR_ZERO,
  583. BLEND_FACTOR_ONE,
  584. BLEND_FACTOR_SRC_COLOR,
  585. BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
  586. BLEND_FACTOR_DST_COLOR,
  587. BLEND_FACTOR_ONE_MINUS_DST_COLOR,
  588. BLEND_FACTOR_SRC_ALPHA,
  589. BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
  590. BLEND_FACTOR_DST_ALPHA,
  591. BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
  592. BLEND_FACTOR_CONSTANT_COLOR,
  593. BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
  594. BLEND_FACTOR_CONSTANT_ALPHA,
  595. BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
  596. BLEND_FACTOR_SRC_ALPHA_SATURATE,
  597. BLEND_FACTOR_SRC1_COLOR,
  598. BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
  599. BLEND_FACTOR_SRC1_ALPHA,
  600. BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
  601. BLEND_FACTOR_MAX
  602. };
  603. enum BlendOperation {
  604. BLEND_OP_ADD,
  605. BLEND_OP_SUBTRACT,
  606. BLEND_OP_REVERSE_SUBTRACT,
  607. BLEND_OP_MINIMUM,
  608. BLEND_OP_MAXIMUM, // Yes, this one is an actual operator.
  609. BLEND_OP_MAX
  610. };
  611. struct PipelineRasterizationState {
  612. bool enable_depth_clamp = false;
  613. bool discard_primitives = false;
  614. bool wireframe = false;
  615. PolygonCullMode cull_mode = POLYGON_CULL_DISABLED;
  616. PolygonFrontFace front_face = POLYGON_FRONT_FACE_CLOCKWISE;
  617. bool depth_bias_enabled = false;
  618. float depth_bias_constant_factor = 0.0f;
  619. float depth_bias_clamp = 0.0f;
  620. float depth_bias_slope_factor = 0.0f;
  621. float line_width = 1.0f;
  622. uint32_t patch_control_points = 1;
  623. };
  624. struct PipelineMultisampleState {
  625. TextureSamples sample_count = TEXTURE_SAMPLES_1;
  626. bool enable_sample_shading = false;
  627. float min_sample_shading = 0.0f;
  628. Vector<uint32_t> sample_mask;
  629. bool enable_alpha_to_coverage = false;
  630. bool enable_alpha_to_one = false;
  631. };
  632. struct PipelineDepthStencilState {
  633. bool enable_depth_test = false;
  634. bool enable_depth_write = false;
  635. CompareOperator depth_compare_operator = COMPARE_OP_ALWAYS;
  636. bool enable_depth_range = false;
  637. float depth_range_min = 0;
  638. float depth_range_max = 0;
  639. bool enable_stencil = false;
  640. struct StencilOperationState {
  641. StencilOperation fail = STENCIL_OP_ZERO;
  642. StencilOperation pass = STENCIL_OP_ZERO;
  643. StencilOperation depth_fail = STENCIL_OP_ZERO;
  644. CompareOperator compare = COMPARE_OP_ALWAYS;
  645. uint32_t compare_mask = 0;
  646. uint32_t write_mask = 0;
  647. uint32_t reference = 0;
  648. };
  649. StencilOperationState front_op;
  650. StencilOperationState back_op;
  651. };
  652. struct PipelineColorBlendState {
  653. bool enable_logic_op = false;
  654. LogicOperation logic_op = LOGIC_OP_CLEAR;
  655. struct Attachment {
  656. bool enable_blend = false;
  657. BlendFactor src_color_blend_factor = BLEND_FACTOR_ZERO;
  658. BlendFactor dst_color_blend_factor = BLEND_FACTOR_ZERO;
  659. BlendOperation color_blend_op = BLEND_OP_ADD;
  660. BlendFactor src_alpha_blend_factor = BLEND_FACTOR_ZERO;
  661. BlendFactor dst_alpha_blend_factor = BLEND_FACTOR_ZERO;
  662. BlendOperation alpha_blend_op = BLEND_OP_ADD;
  663. bool write_r = true;
  664. bool write_g = true;
  665. bool write_b = true;
  666. bool write_a = true;
  667. };
  668. static PipelineColorBlendState create_disabled(int p_attachments = 1) {
  669. PipelineColorBlendState bs;
  670. for (int i = 0; i < p_attachments; i++) {
  671. bs.attachments.push_back(Attachment());
  672. }
  673. return bs;
  674. }
  675. static PipelineColorBlendState create_blend(int p_attachments = 1) {
  676. PipelineColorBlendState bs;
  677. for (int i = 0; i < p_attachments; i++) {
  678. Attachment ba;
  679. ba.enable_blend = true;
  680. ba.src_color_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  681. ba.dst_color_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  682. ba.src_alpha_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  683. ba.dst_alpha_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  684. bs.attachments.push_back(ba);
  685. }
  686. return bs;
  687. }
  688. Vector<Attachment> attachments; // One per render target texture.
  689. Color blend_constant;
  690. };
  691. enum PipelineDynamicStateFlags {
  692. DYNAMIC_STATE_LINE_WIDTH = (1 << 0),
  693. DYNAMIC_STATE_DEPTH_BIAS = (1 << 1),
  694. DYNAMIC_STATE_BLEND_CONSTANTS = (1 << 2),
  695. DYNAMIC_STATE_DEPTH_BOUNDS = (1 << 3),
  696. DYNAMIC_STATE_STENCIL_COMPARE_MASK = (1 << 4),
  697. DYNAMIC_STATE_STENCIL_WRITE_MASK = (1 << 5),
  698. DYNAMIC_STATE_STENCIL_REFERENCE = (1 << 6),
  699. };
  700. /**************/
  701. /**** MISC ****/
  702. /**************/
  703. // This enum matches VkPhysicalDeviceType (except for `DEVICE_TYPE_MAX`).
  704. // Unlike VkPhysicalDeviceType, DeviceType is exposed to the scripting API.
  705. enum DeviceType {
  706. DEVICE_TYPE_OTHER,
  707. DEVICE_TYPE_INTEGRATED_GPU,
  708. DEVICE_TYPE_DISCRETE_GPU,
  709. DEVICE_TYPE_VIRTUAL_GPU,
  710. DEVICE_TYPE_CPU,
  711. DEVICE_TYPE_MAX
  712. };
  713. // Defined in an API-agnostic way.
  714. // Some may not make sense for the underlying API; in that case, 0 is returned.
  715. enum DriverResource {
  716. DRIVER_RESOURCE_LOGICAL_DEVICE,
  717. DRIVER_RESOURCE_PHYSICAL_DEVICE,
  718. DRIVER_RESOURCE_TOPMOST_OBJECT,
  719. DRIVER_RESOURCE_COMMAND_QUEUE,
  720. DRIVER_RESOURCE_QUEUE_FAMILY,
  721. DRIVER_RESOURCE_TEXTURE,
  722. DRIVER_RESOURCE_TEXTURE_VIEW,
  723. DRIVER_RESOURCE_TEXTURE_DATA_FORMAT,
  724. DRIVER_RESOURCE_SAMPLER,
  725. DRIVER_RESOURCE_UNIFORM_SET,
  726. DRIVER_RESOURCE_BUFFER,
  727. DRIVER_RESOURCE_COMPUTE_PIPELINE,
  728. DRIVER_RESOURCE_RENDER_PIPELINE,
  729. #ifndef DISABLE_DEPRECATED
  730. DRIVER_RESOURCE_VULKAN_DEVICE = DRIVER_RESOURCE_LOGICAL_DEVICE,
  731. DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE = DRIVER_RESOURCE_PHYSICAL_DEVICE,
  732. DRIVER_RESOURCE_VULKAN_INSTANCE = DRIVER_RESOURCE_TOPMOST_OBJECT,
  733. DRIVER_RESOURCE_VULKAN_QUEUE = DRIVER_RESOURCE_COMMAND_QUEUE,
  734. DRIVER_RESOURCE_VULKAN_QUEUE_FAMILY_INDEX = DRIVER_RESOURCE_QUEUE_FAMILY,
  735. DRIVER_RESOURCE_VULKAN_IMAGE = DRIVER_RESOURCE_TEXTURE,
  736. DRIVER_RESOURCE_VULKAN_IMAGE_VIEW = DRIVER_RESOURCE_TEXTURE_VIEW,
  737. DRIVER_RESOURCE_VULKAN_IMAGE_NATIVE_TEXTURE_FORMAT = DRIVER_RESOURCE_TEXTURE_DATA_FORMAT,
  738. DRIVER_RESOURCE_VULKAN_SAMPLER = DRIVER_RESOURCE_SAMPLER,
  739. DRIVER_RESOURCE_VULKAN_DESCRIPTOR_SET = DRIVER_RESOURCE_UNIFORM_SET,
  740. DRIVER_RESOURCE_VULKAN_BUFFER = DRIVER_RESOURCE_BUFFER,
  741. DRIVER_RESOURCE_VULKAN_COMPUTE_PIPELINE = DRIVER_RESOURCE_COMPUTE_PIPELINE,
  742. DRIVER_RESOURCE_VULKAN_RENDER_PIPELINE = DRIVER_RESOURCE_RENDER_PIPELINE,
  743. #endif
  744. };
  745. enum Limit {
  746. LIMIT_MAX_BOUND_UNIFORM_SETS,
  747. LIMIT_MAX_FRAMEBUFFER_COLOR_ATTACHMENTS,
  748. LIMIT_MAX_TEXTURES_PER_UNIFORM_SET,
  749. LIMIT_MAX_SAMPLERS_PER_UNIFORM_SET,
  750. LIMIT_MAX_STORAGE_BUFFERS_PER_UNIFORM_SET,
  751. LIMIT_MAX_STORAGE_IMAGES_PER_UNIFORM_SET,
  752. LIMIT_MAX_UNIFORM_BUFFERS_PER_UNIFORM_SET,
  753. LIMIT_MAX_DRAW_INDEXED_INDEX,
  754. LIMIT_MAX_FRAMEBUFFER_HEIGHT,
  755. LIMIT_MAX_FRAMEBUFFER_WIDTH,
  756. LIMIT_MAX_TEXTURE_ARRAY_LAYERS,
  757. LIMIT_MAX_TEXTURE_SIZE_1D,
  758. LIMIT_MAX_TEXTURE_SIZE_2D,
  759. LIMIT_MAX_TEXTURE_SIZE_3D,
  760. LIMIT_MAX_TEXTURE_SIZE_CUBE,
  761. LIMIT_MAX_TEXTURES_PER_SHADER_STAGE,
  762. LIMIT_MAX_SAMPLERS_PER_SHADER_STAGE,
  763. LIMIT_MAX_STORAGE_BUFFERS_PER_SHADER_STAGE,
  764. LIMIT_MAX_STORAGE_IMAGES_PER_SHADER_STAGE,
  765. LIMIT_MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE,
  766. LIMIT_MAX_PUSH_CONSTANT_SIZE,
  767. LIMIT_MAX_UNIFORM_BUFFER_SIZE,
  768. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTE_OFFSET,
  769. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTES,
  770. LIMIT_MAX_VERTEX_INPUT_BINDINGS,
  771. LIMIT_MAX_VERTEX_INPUT_BINDING_STRIDE,
  772. LIMIT_MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
  773. LIMIT_MAX_COMPUTE_SHARED_MEMORY_SIZE,
  774. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X,
  775. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Y,
  776. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Z,
  777. LIMIT_MAX_COMPUTE_WORKGROUP_INVOCATIONS,
  778. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_X,
  779. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Y,
  780. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z,
  781. LIMIT_MAX_VIEWPORT_DIMENSIONS_X,
  782. LIMIT_MAX_VIEWPORT_DIMENSIONS_Y,
  783. LIMIT_SUBGROUP_SIZE,
  784. LIMIT_SUBGROUP_MIN_SIZE,
  785. LIMIT_SUBGROUP_MAX_SIZE,
  786. LIMIT_SUBGROUP_IN_SHADERS, // Set flags using SHADER_STAGE_VERTEX_BIT, SHADER_STAGE_FRAGMENT_BIT, etc.
  787. LIMIT_SUBGROUP_OPERATIONS,
  788. LIMIT_VRS_TEXEL_WIDTH,
  789. LIMIT_VRS_TEXEL_HEIGHT,
  790. LIMIT_VRS_MAX_FRAGMENT_WIDTH,
  791. LIMIT_VRS_MAX_FRAGMENT_HEIGHT,
  792. };
  793. enum Features {
  794. SUPPORTS_MULTIVIEW,
  795. SUPPORTS_FSR_HALF_FLOAT,
  796. SUPPORTS_ATTACHMENT_VRS,
  797. // 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.
  798. SUPPORTS_FRAGMENT_SHADER_WITH_ONLY_SIDE_EFFECTS,
  799. };
  800. enum SubgroupOperations {
  801. SUBGROUP_BASIC_BIT = 1,
  802. SUBGROUP_VOTE_BIT = 2,
  803. SUBGROUP_ARITHMETIC_BIT = 4,
  804. SUBGROUP_BALLOT_BIT = 8,
  805. SUBGROUP_SHUFFLE_BIT = 16,
  806. SUBGROUP_SHUFFLE_RELATIVE_BIT = 32,
  807. SUBGROUP_CLUSTERED_BIT = 64,
  808. SUBGROUP_QUAD_BIT = 128,
  809. };
  810. ////////////////////////////////////////////
  811. // PROTECTED STUFF
  812. // Not exposed by RenderingDevice, but shared
  813. // with RenderingDeviceDriver for convenience.
  814. ////////////////////////////////////////////
  815. protected:
  816. /*****************/
  817. /**** GENERIC ****/
  818. /*****************/
  819. static const char *const FORMAT_NAMES[DATA_FORMAT_MAX];
  820. /*****************/
  821. /**** TEXTURE ****/
  822. /*****************/
  823. static const uint32_t MAX_IMAGE_FORMAT_PLANES = 2;
  824. static const uint32_t TEXTURE_SAMPLES_COUNT[TEXTURE_SAMPLES_MAX];
  825. static uint32_t get_image_format_pixel_size(DataFormat p_format);
  826. static void get_compressed_image_format_block_dimensions(DataFormat p_format, uint32_t &r_w, uint32_t &r_h);
  827. uint32_t get_compressed_image_format_block_byte_size(DataFormat p_format) const;
  828. static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format);
  829. 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);
  830. static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth);
  831. static bool format_has_stencil(DataFormat p_format);
  832. static uint32_t format_get_plane_count(DataFormat p_format);
  833. /*****************/
  834. /**** SAMPLER ****/
  835. /*****************/
  836. static const Color SAMPLER_BORDER_COLOR_VALUE[SAMPLER_BORDER_COLOR_MAX];
  837. /**********************/
  838. /**** VERTEX ARRAY ****/
  839. /**********************/
  840. static uint32_t get_format_vertex_size(DataFormat p_format);
  841. /****************/
  842. /**** SHADER ****/
  843. /****************/
  844. static const char *SHADER_STAGE_NAMES[SHADER_STAGE_MAX];
  845. public:
  846. struct ShaderUniform {
  847. UniformType type = UniformType::UNIFORM_TYPE_MAX;
  848. bool writable = false;
  849. uint32_t binding = 0;
  850. BitField<ShaderStage> stages;
  851. uint32_t length = 0; // Size of arrays (in total elements), or ubos (in bytes * total elements).
  852. bool operator!=(const ShaderUniform &p_other) const {
  853. return binding != p_other.binding || type != p_other.type || writable != p_other.writable || stages != p_other.stages || length != p_other.length;
  854. }
  855. bool operator<(const ShaderUniform &p_other) const {
  856. if (binding != p_other.binding) {
  857. return binding < p_other.binding;
  858. }
  859. if (type != p_other.type) {
  860. return type < p_other.type;
  861. }
  862. if (writable != p_other.writable) {
  863. return writable < p_other.writable;
  864. }
  865. if (stages != p_other.stages) {
  866. return stages < p_other.stages;
  867. }
  868. if (length != p_other.length) {
  869. return length < p_other.length;
  870. }
  871. return false;
  872. }
  873. };
  874. struct ShaderSpecializationConstant : public PipelineSpecializationConstant {
  875. BitField<ShaderStage> stages;
  876. bool operator<(const ShaderSpecializationConstant &p_other) const { return constant_id < p_other.constant_id; }
  877. };
  878. struct ShaderDescription {
  879. uint64_t vertex_input_mask = 0;
  880. uint32_t fragment_output_mask = 0;
  881. bool is_compute = false;
  882. uint32_t compute_local_size[3] = {};
  883. uint32_t push_constant_size = 0;
  884. Vector<Vector<ShaderUniform>> uniform_sets;
  885. Vector<ShaderSpecializationConstant> specialization_constants;
  886. Vector<ShaderStage> stages;
  887. };
  888. protected:
  889. struct ShaderReflection : public ShaderDescription {
  890. BitField<ShaderStage> stages;
  891. BitField<ShaderStage> push_constant_stages;
  892. };
  893. };
  894. #endif // RENDERING_DEVICE_COMMONS_H