rendering_device.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /**************************************************************************/
  2. /* rendering_device.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_H
  31. #define RENDERING_DEVICE_H
  32. #include "core/object/class_db.h"
  33. #include "core/variant/typed_array.h"
  34. #include "servers/display_server.h"
  35. class RDTextureFormat;
  36. class RDTextureView;
  37. class RDAttachmentFormat;
  38. class RDSamplerState;
  39. class RDVertexAttribute;
  40. class RDShaderSource;
  41. class RDShaderSPIRV;
  42. class RDUniform;
  43. class RDPipelineRasterizationState;
  44. class RDPipelineMultisampleState;
  45. class RDPipelineDepthStencilState;
  46. class RDPipelineColorBlendState;
  47. class RDFramebufferPass;
  48. class RDPipelineSpecializationConstant;
  49. class RenderingDevice : public Object {
  50. GDCLASS(RenderingDevice, Object)
  51. public:
  52. enum DeviceFamily {
  53. DEVICE_UNKNOWN,
  54. DEVICE_OPENGL,
  55. DEVICE_VULKAN,
  56. DEVICE_DIRECTX
  57. };
  58. // This enum matches VkPhysicalDeviceType (except for `DEVICE_TYPE_MAX`).
  59. // Unlike VkPhysicalDeviceType, DeviceType is exposed to the scripting API.
  60. enum DeviceType {
  61. DEVICE_TYPE_OTHER,
  62. DEVICE_TYPE_INTEGRATED_GPU,
  63. DEVICE_TYPE_DISCRETE_GPU,
  64. DEVICE_TYPE_VIRTUAL_GPU,
  65. DEVICE_TYPE_CPU,
  66. DEVICE_TYPE_MAX,
  67. };
  68. enum DriverResource {
  69. DRIVER_RESOURCE_VULKAN_DEVICE = 0,
  70. DRIVER_RESOURCE_VULKAN_PHYSICAL_DEVICE,
  71. DRIVER_RESOURCE_VULKAN_INSTANCE,
  72. DRIVER_RESOURCE_VULKAN_QUEUE,
  73. DRIVER_RESOURCE_VULKAN_QUEUE_FAMILY_INDEX,
  74. DRIVER_RESOURCE_VULKAN_IMAGE,
  75. DRIVER_RESOURCE_VULKAN_IMAGE_VIEW,
  76. DRIVER_RESOURCE_VULKAN_IMAGE_NATIVE_TEXTURE_FORMAT,
  77. DRIVER_RESOURCE_VULKAN_SAMPLER,
  78. DRIVER_RESOURCE_VULKAN_DESCRIPTOR_SET,
  79. DRIVER_RESOURCE_VULKAN_BUFFER,
  80. DRIVER_RESOURCE_VULKAN_COMPUTE_PIPELINE,
  81. DRIVER_RESOURCE_VULKAN_RENDER_PIPELINE,
  82. //next driver continue enum from 1000 to keep order
  83. };
  84. enum ShaderStage {
  85. SHADER_STAGE_VERTEX,
  86. SHADER_STAGE_FRAGMENT,
  87. SHADER_STAGE_TESSELATION_CONTROL,
  88. SHADER_STAGE_TESSELATION_EVALUATION,
  89. SHADER_STAGE_COMPUTE,
  90. SHADER_STAGE_MAX,
  91. SHADER_STAGE_VERTEX_BIT = (1 << SHADER_STAGE_VERTEX),
  92. SHADER_STAGE_FRAGMENT_BIT = (1 << SHADER_STAGE_FRAGMENT),
  93. SHADER_STAGE_TESSELATION_CONTROL_BIT = (1 << SHADER_STAGE_TESSELATION_CONTROL),
  94. SHADER_STAGE_TESSELATION_EVALUATION_BIT = (1 << SHADER_STAGE_TESSELATION_EVALUATION),
  95. SHADER_STAGE_COMPUTE_BIT = (1 << SHADER_STAGE_COMPUTE),
  96. };
  97. enum ShaderLanguage {
  98. SHADER_LANGUAGE_GLSL,
  99. SHADER_LANGUAGE_HLSL
  100. };
  101. enum SubgroupOperations {
  102. SUBGROUP_BASIC_BIT = 1,
  103. SUBGROUP_VOTE_BIT = 2,
  104. SUBGROUP_ARITHMETIC_BIT = 4,
  105. SUBGROUP_BALLOT_BIT = 8,
  106. SUBGROUP_SHUFFLE_BIT = 16,
  107. SUBGROUP_SHUFFLE_RELATIVE_BIT = 32,
  108. SUBGROUP_CLUSTERED_BIT = 64,
  109. SUBGROUP_QUAD_BIT = 128,
  110. };
  111. struct Capabilities {
  112. // main device info
  113. DeviceFamily device_family = DEVICE_UNKNOWN;
  114. uint32_t version_major = 1.0;
  115. uint32_t version_minor = 0.0;
  116. };
  117. typedef String (*ShaderSPIRVGetCacheKeyFunction)(const RenderingDevice *p_render_device);
  118. typedef Vector<uint8_t> (*ShaderCompileToSPIRVFunction)(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language, String *r_error, const RenderingDevice *p_render_device);
  119. typedef Vector<uint8_t> (*ShaderCacheFunction)(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language);
  120. typedef void (*InvalidationCallback)(void *);
  121. private:
  122. static ShaderCompileToSPIRVFunction compile_to_spirv_function;
  123. static ShaderCacheFunction cache_function;
  124. static ShaderSPIRVGetCacheKeyFunction get_spirv_cache_key_function;
  125. static RenderingDevice *singleton;
  126. protected:
  127. static void _bind_methods();
  128. Capabilities device_capabilities;
  129. public:
  130. //base numeric ID for all types
  131. enum {
  132. INVALID_ID = -1,
  133. INVALID_FORMAT_ID = -1
  134. };
  135. /*****************/
  136. /**** GENERIC ****/
  137. /*****************/
  138. enum CompareOperator {
  139. COMPARE_OP_NEVER,
  140. COMPARE_OP_LESS,
  141. COMPARE_OP_EQUAL,
  142. COMPARE_OP_LESS_OR_EQUAL,
  143. COMPARE_OP_GREATER,
  144. COMPARE_OP_NOT_EQUAL,
  145. COMPARE_OP_GREATER_OR_EQUAL,
  146. COMPARE_OP_ALWAYS,
  147. COMPARE_OP_MAX //not an actual operator, just the amount of operators :D
  148. };
  149. enum DataFormat {
  150. DATA_FORMAT_R4G4_UNORM_PACK8,
  151. DATA_FORMAT_R4G4B4A4_UNORM_PACK16,
  152. DATA_FORMAT_B4G4R4A4_UNORM_PACK16,
  153. DATA_FORMAT_R5G6B5_UNORM_PACK16,
  154. DATA_FORMAT_B5G6R5_UNORM_PACK16,
  155. DATA_FORMAT_R5G5B5A1_UNORM_PACK16,
  156. DATA_FORMAT_B5G5R5A1_UNORM_PACK16,
  157. DATA_FORMAT_A1R5G5B5_UNORM_PACK16,
  158. DATA_FORMAT_R8_UNORM,
  159. DATA_FORMAT_R8_SNORM,
  160. DATA_FORMAT_R8_USCALED,
  161. DATA_FORMAT_R8_SSCALED,
  162. DATA_FORMAT_R8_UINT,
  163. DATA_FORMAT_R8_SINT,
  164. DATA_FORMAT_R8_SRGB,
  165. DATA_FORMAT_R8G8_UNORM,
  166. DATA_FORMAT_R8G8_SNORM,
  167. DATA_FORMAT_R8G8_USCALED,
  168. DATA_FORMAT_R8G8_SSCALED,
  169. DATA_FORMAT_R8G8_UINT,
  170. DATA_FORMAT_R8G8_SINT,
  171. DATA_FORMAT_R8G8_SRGB,
  172. DATA_FORMAT_R8G8B8_UNORM,
  173. DATA_FORMAT_R8G8B8_SNORM,
  174. DATA_FORMAT_R8G8B8_USCALED,
  175. DATA_FORMAT_R8G8B8_SSCALED,
  176. DATA_FORMAT_R8G8B8_UINT,
  177. DATA_FORMAT_R8G8B8_SINT,
  178. DATA_FORMAT_R8G8B8_SRGB,
  179. DATA_FORMAT_B8G8R8_UNORM,
  180. DATA_FORMAT_B8G8R8_SNORM,
  181. DATA_FORMAT_B8G8R8_USCALED,
  182. DATA_FORMAT_B8G8R8_SSCALED,
  183. DATA_FORMAT_B8G8R8_UINT,
  184. DATA_FORMAT_B8G8R8_SINT,
  185. DATA_FORMAT_B8G8R8_SRGB,
  186. DATA_FORMAT_R8G8B8A8_UNORM,
  187. DATA_FORMAT_R8G8B8A8_SNORM,
  188. DATA_FORMAT_R8G8B8A8_USCALED,
  189. DATA_FORMAT_R8G8B8A8_SSCALED,
  190. DATA_FORMAT_R8G8B8A8_UINT,
  191. DATA_FORMAT_R8G8B8A8_SINT,
  192. DATA_FORMAT_R8G8B8A8_SRGB,
  193. DATA_FORMAT_B8G8R8A8_UNORM,
  194. DATA_FORMAT_B8G8R8A8_SNORM,
  195. DATA_FORMAT_B8G8R8A8_USCALED,
  196. DATA_FORMAT_B8G8R8A8_SSCALED,
  197. DATA_FORMAT_B8G8R8A8_UINT,
  198. DATA_FORMAT_B8G8R8A8_SINT,
  199. DATA_FORMAT_B8G8R8A8_SRGB,
  200. DATA_FORMAT_A8B8G8R8_UNORM_PACK32,
  201. DATA_FORMAT_A8B8G8R8_SNORM_PACK32,
  202. DATA_FORMAT_A8B8G8R8_USCALED_PACK32,
  203. DATA_FORMAT_A8B8G8R8_SSCALED_PACK32,
  204. DATA_FORMAT_A8B8G8R8_UINT_PACK32,
  205. DATA_FORMAT_A8B8G8R8_SINT_PACK32,
  206. DATA_FORMAT_A8B8G8R8_SRGB_PACK32,
  207. DATA_FORMAT_A2R10G10B10_UNORM_PACK32,
  208. DATA_FORMAT_A2R10G10B10_SNORM_PACK32,
  209. DATA_FORMAT_A2R10G10B10_USCALED_PACK32,
  210. DATA_FORMAT_A2R10G10B10_SSCALED_PACK32,
  211. DATA_FORMAT_A2R10G10B10_UINT_PACK32,
  212. DATA_FORMAT_A2R10G10B10_SINT_PACK32,
  213. DATA_FORMAT_A2B10G10R10_UNORM_PACK32,
  214. DATA_FORMAT_A2B10G10R10_SNORM_PACK32,
  215. DATA_FORMAT_A2B10G10R10_USCALED_PACK32,
  216. DATA_FORMAT_A2B10G10R10_SSCALED_PACK32,
  217. DATA_FORMAT_A2B10G10R10_UINT_PACK32,
  218. DATA_FORMAT_A2B10G10R10_SINT_PACK32,
  219. DATA_FORMAT_R16_UNORM,
  220. DATA_FORMAT_R16_SNORM,
  221. DATA_FORMAT_R16_USCALED,
  222. DATA_FORMAT_R16_SSCALED,
  223. DATA_FORMAT_R16_UINT,
  224. DATA_FORMAT_R16_SINT,
  225. DATA_FORMAT_R16_SFLOAT,
  226. DATA_FORMAT_R16G16_UNORM,
  227. DATA_FORMAT_R16G16_SNORM,
  228. DATA_FORMAT_R16G16_USCALED,
  229. DATA_FORMAT_R16G16_SSCALED,
  230. DATA_FORMAT_R16G16_UINT,
  231. DATA_FORMAT_R16G16_SINT,
  232. DATA_FORMAT_R16G16_SFLOAT,
  233. DATA_FORMAT_R16G16B16_UNORM,
  234. DATA_FORMAT_R16G16B16_SNORM,
  235. DATA_FORMAT_R16G16B16_USCALED,
  236. DATA_FORMAT_R16G16B16_SSCALED,
  237. DATA_FORMAT_R16G16B16_UINT,
  238. DATA_FORMAT_R16G16B16_SINT,
  239. DATA_FORMAT_R16G16B16_SFLOAT,
  240. DATA_FORMAT_R16G16B16A16_UNORM,
  241. DATA_FORMAT_R16G16B16A16_SNORM,
  242. DATA_FORMAT_R16G16B16A16_USCALED,
  243. DATA_FORMAT_R16G16B16A16_SSCALED,
  244. DATA_FORMAT_R16G16B16A16_UINT,
  245. DATA_FORMAT_R16G16B16A16_SINT,
  246. DATA_FORMAT_R16G16B16A16_SFLOAT,
  247. DATA_FORMAT_R32_UINT,
  248. DATA_FORMAT_R32_SINT,
  249. DATA_FORMAT_R32_SFLOAT,
  250. DATA_FORMAT_R32G32_UINT,
  251. DATA_FORMAT_R32G32_SINT,
  252. DATA_FORMAT_R32G32_SFLOAT,
  253. DATA_FORMAT_R32G32B32_UINT,
  254. DATA_FORMAT_R32G32B32_SINT,
  255. DATA_FORMAT_R32G32B32_SFLOAT,
  256. DATA_FORMAT_R32G32B32A32_UINT,
  257. DATA_FORMAT_R32G32B32A32_SINT,
  258. DATA_FORMAT_R32G32B32A32_SFLOAT,
  259. DATA_FORMAT_R64_UINT,
  260. DATA_FORMAT_R64_SINT,
  261. DATA_FORMAT_R64_SFLOAT,
  262. DATA_FORMAT_R64G64_UINT,
  263. DATA_FORMAT_R64G64_SINT,
  264. DATA_FORMAT_R64G64_SFLOAT,
  265. DATA_FORMAT_R64G64B64_UINT,
  266. DATA_FORMAT_R64G64B64_SINT,
  267. DATA_FORMAT_R64G64B64_SFLOAT,
  268. DATA_FORMAT_R64G64B64A64_UINT,
  269. DATA_FORMAT_R64G64B64A64_SINT,
  270. DATA_FORMAT_R64G64B64A64_SFLOAT,
  271. DATA_FORMAT_B10G11R11_UFLOAT_PACK32,
  272. DATA_FORMAT_E5B9G9R9_UFLOAT_PACK32,
  273. DATA_FORMAT_D16_UNORM,
  274. DATA_FORMAT_X8_D24_UNORM_PACK32,
  275. DATA_FORMAT_D32_SFLOAT,
  276. DATA_FORMAT_S8_UINT,
  277. DATA_FORMAT_D16_UNORM_S8_UINT,
  278. DATA_FORMAT_D24_UNORM_S8_UINT,
  279. DATA_FORMAT_D32_SFLOAT_S8_UINT,
  280. DATA_FORMAT_BC1_RGB_UNORM_BLOCK,
  281. DATA_FORMAT_BC1_RGB_SRGB_BLOCK,
  282. DATA_FORMAT_BC1_RGBA_UNORM_BLOCK,
  283. DATA_FORMAT_BC1_RGBA_SRGB_BLOCK,
  284. DATA_FORMAT_BC2_UNORM_BLOCK,
  285. DATA_FORMAT_BC2_SRGB_BLOCK,
  286. DATA_FORMAT_BC3_UNORM_BLOCK,
  287. DATA_FORMAT_BC3_SRGB_BLOCK,
  288. DATA_FORMAT_BC4_UNORM_BLOCK,
  289. DATA_FORMAT_BC4_SNORM_BLOCK,
  290. DATA_FORMAT_BC5_UNORM_BLOCK,
  291. DATA_FORMAT_BC5_SNORM_BLOCK,
  292. DATA_FORMAT_BC6H_UFLOAT_BLOCK,
  293. DATA_FORMAT_BC6H_SFLOAT_BLOCK,
  294. DATA_FORMAT_BC7_UNORM_BLOCK,
  295. DATA_FORMAT_BC7_SRGB_BLOCK,
  296. DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
  297. DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
  298. DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
  299. DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
  300. DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
  301. DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
  302. DATA_FORMAT_EAC_R11_UNORM_BLOCK,
  303. DATA_FORMAT_EAC_R11_SNORM_BLOCK,
  304. DATA_FORMAT_EAC_R11G11_UNORM_BLOCK,
  305. DATA_FORMAT_EAC_R11G11_SNORM_BLOCK,
  306. DATA_FORMAT_ASTC_4x4_UNORM_BLOCK,
  307. DATA_FORMAT_ASTC_4x4_SRGB_BLOCK,
  308. DATA_FORMAT_ASTC_5x4_UNORM_BLOCK,
  309. DATA_FORMAT_ASTC_5x4_SRGB_BLOCK,
  310. DATA_FORMAT_ASTC_5x5_UNORM_BLOCK,
  311. DATA_FORMAT_ASTC_5x5_SRGB_BLOCK,
  312. DATA_FORMAT_ASTC_6x5_UNORM_BLOCK,
  313. DATA_FORMAT_ASTC_6x5_SRGB_BLOCK,
  314. DATA_FORMAT_ASTC_6x6_UNORM_BLOCK,
  315. DATA_FORMAT_ASTC_6x6_SRGB_BLOCK,
  316. DATA_FORMAT_ASTC_8x5_UNORM_BLOCK,
  317. DATA_FORMAT_ASTC_8x5_SRGB_BLOCK,
  318. DATA_FORMAT_ASTC_8x6_UNORM_BLOCK,
  319. DATA_FORMAT_ASTC_8x6_SRGB_BLOCK,
  320. DATA_FORMAT_ASTC_8x8_UNORM_BLOCK,
  321. DATA_FORMAT_ASTC_8x8_SRGB_BLOCK,
  322. DATA_FORMAT_ASTC_10x5_UNORM_BLOCK,
  323. DATA_FORMAT_ASTC_10x5_SRGB_BLOCK,
  324. DATA_FORMAT_ASTC_10x6_UNORM_BLOCK,
  325. DATA_FORMAT_ASTC_10x6_SRGB_BLOCK,
  326. DATA_FORMAT_ASTC_10x8_UNORM_BLOCK,
  327. DATA_FORMAT_ASTC_10x8_SRGB_BLOCK,
  328. DATA_FORMAT_ASTC_10x10_UNORM_BLOCK,
  329. DATA_FORMAT_ASTC_10x10_SRGB_BLOCK,
  330. DATA_FORMAT_ASTC_12x10_UNORM_BLOCK,
  331. DATA_FORMAT_ASTC_12x10_SRGB_BLOCK,
  332. DATA_FORMAT_ASTC_12x12_UNORM_BLOCK,
  333. DATA_FORMAT_ASTC_12x12_SRGB_BLOCK,
  334. DATA_FORMAT_G8B8G8R8_422_UNORM,
  335. DATA_FORMAT_B8G8R8G8_422_UNORM,
  336. DATA_FORMAT_G8_B8_R8_3PLANE_420_UNORM,
  337. DATA_FORMAT_G8_B8R8_2PLANE_420_UNORM,
  338. DATA_FORMAT_G8_B8_R8_3PLANE_422_UNORM,
  339. DATA_FORMAT_G8_B8R8_2PLANE_422_UNORM,
  340. DATA_FORMAT_G8_B8_R8_3PLANE_444_UNORM,
  341. DATA_FORMAT_R10X6_UNORM_PACK16,
  342. DATA_FORMAT_R10X6G10X6_UNORM_2PACK16,
  343. DATA_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16,
  344. DATA_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
  345. DATA_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,
  346. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
  347. DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
  348. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16,
  349. DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16,
  350. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16,
  351. DATA_FORMAT_R12X4_UNORM_PACK16,
  352. DATA_FORMAT_R12X4G12X4_UNORM_2PACK16,
  353. DATA_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,
  354. DATA_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
  355. DATA_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,
  356. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16,
  357. DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16,
  358. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16,
  359. DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16,
  360. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16,
  361. DATA_FORMAT_G16B16G16R16_422_UNORM,
  362. DATA_FORMAT_B16G16R16G16_422_UNORM,
  363. DATA_FORMAT_G16_B16_R16_3PLANE_420_UNORM,
  364. DATA_FORMAT_G16_B16R16_2PLANE_420_UNORM,
  365. DATA_FORMAT_G16_B16_R16_3PLANE_422_UNORM,
  366. DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM,
  367. DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM,
  368. DATA_FORMAT_MAX
  369. };
  370. /*****************/
  371. /**** BARRIER ****/
  372. /*****************/
  373. enum BarrierMask {
  374. BARRIER_MASK_RASTER = 1,
  375. BARRIER_MASK_COMPUTE = 2,
  376. BARRIER_MASK_TRANSFER = 4,
  377. BARRIER_MASK_ALL_BARRIERS = BARRIER_MASK_RASTER | BARRIER_MASK_COMPUTE | BARRIER_MASK_TRANSFER, // 7
  378. BARRIER_MASK_NO_BARRIER = 8,
  379. };
  380. /*****************/
  381. /**** TEXTURE ****/
  382. /*****************/
  383. enum TextureType {
  384. TEXTURE_TYPE_1D,
  385. TEXTURE_TYPE_2D,
  386. TEXTURE_TYPE_3D,
  387. TEXTURE_TYPE_CUBE,
  388. TEXTURE_TYPE_1D_ARRAY,
  389. TEXTURE_TYPE_2D_ARRAY,
  390. TEXTURE_TYPE_CUBE_ARRAY,
  391. TEXTURE_TYPE_MAX
  392. };
  393. enum TextureSamples {
  394. TEXTURE_SAMPLES_1,
  395. TEXTURE_SAMPLES_2,
  396. TEXTURE_SAMPLES_4,
  397. TEXTURE_SAMPLES_8,
  398. TEXTURE_SAMPLES_16,
  399. TEXTURE_SAMPLES_32,
  400. TEXTURE_SAMPLES_64,
  401. TEXTURE_SAMPLES_MAX
  402. };
  403. enum TextureUsageBits {
  404. TEXTURE_USAGE_SAMPLING_BIT = (1 << 0),
  405. TEXTURE_USAGE_COLOR_ATTACHMENT_BIT = (1 << 1),
  406. TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = (1 << 2),
  407. TEXTURE_USAGE_STORAGE_BIT = (1 << 3),
  408. TEXTURE_USAGE_STORAGE_ATOMIC_BIT = (1 << 4),
  409. TEXTURE_USAGE_CPU_READ_BIT = (1 << 5),
  410. TEXTURE_USAGE_CAN_UPDATE_BIT = (1 << 6),
  411. TEXTURE_USAGE_CAN_COPY_FROM_BIT = (1 << 7),
  412. TEXTURE_USAGE_CAN_COPY_TO_BIT = (1 << 8),
  413. TEXTURE_USAGE_INPUT_ATTACHMENT_BIT = (1 << 9),
  414. TEXTURE_USAGE_VRS_ATTACHMENT_BIT = (1 << 10),
  415. };
  416. enum TextureSwizzle {
  417. TEXTURE_SWIZZLE_IDENTITY,
  418. TEXTURE_SWIZZLE_ZERO,
  419. TEXTURE_SWIZZLE_ONE,
  420. TEXTURE_SWIZZLE_R,
  421. TEXTURE_SWIZZLE_G,
  422. TEXTURE_SWIZZLE_B,
  423. TEXTURE_SWIZZLE_A,
  424. TEXTURE_SWIZZLE_MAX
  425. };
  426. struct TextureFormat {
  427. DataFormat format;
  428. uint32_t width;
  429. uint32_t height;
  430. uint32_t depth;
  431. uint32_t array_layers;
  432. uint32_t mipmaps;
  433. TextureType texture_type;
  434. TextureSamples samples;
  435. uint32_t usage_bits;
  436. Vector<DataFormat> shareable_formats;
  437. bool is_resolve_buffer = false;
  438. bool operator==(const TextureFormat &b) const {
  439. if (format != b.format) {
  440. return false;
  441. } else if (width != b.width) {
  442. return false;
  443. } else if (height != b.height) {
  444. return false;
  445. } else if (depth != b.depth) {
  446. return false;
  447. } else if (array_layers != b.array_layers) {
  448. return false;
  449. } else if (mipmaps != b.mipmaps) {
  450. return false;
  451. } else if (texture_type != b.texture_type) {
  452. return false;
  453. } else if (samples != b.samples) {
  454. return false;
  455. } else if (usage_bits != b.usage_bits) {
  456. return false;
  457. } else if (shareable_formats != b.shareable_formats) {
  458. return false;
  459. } else {
  460. return true;
  461. }
  462. }
  463. TextureFormat() {
  464. format = DATA_FORMAT_R8_UNORM;
  465. width = 1;
  466. height = 1;
  467. depth = 1;
  468. array_layers = 1;
  469. mipmaps = 1;
  470. texture_type = TEXTURE_TYPE_2D;
  471. samples = TEXTURE_SAMPLES_1;
  472. usage_bits = 0;
  473. }
  474. };
  475. struct TextureView {
  476. DataFormat format_override;
  477. TextureSwizzle swizzle_r;
  478. TextureSwizzle swizzle_g;
  479. TextureSwizzle swizzle_b;
  480. TextureSwizzle swizzle_a;
  481. TextureView() {
  482. format_override = DATA_FORMAT_MAX; //means, use same as format
  483. swizzle_r = TEXTURE_SWIZZLE_R;
  484. swizzle_g = TEXTURE_SWIZZLE_G;
  485. swizzle_b = TEXTURE_SWIZZLE_B;
  486. swizzle_a = TEXTURE_SWIZZLE_A;
  487. }
  488. };
  489. virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>()) = 0;
  490. virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture) = 0;
  491. virtual RID texture_create_from_extension(TextureType p_type, DataFormat p_format, TextureSamples p_samples, uint64_t p_flags, uint64_t p_image, uint64_t p_width, uint64_t p_height, uint64_t p_depth, uint64_t p_layers) = 0;
  492. enum TextureSliceType {
  493. TEXTURE_SLICE_2D,
  494. TEXTURE_SLICE_CUBEMAP,
  495. TEXTURE_SLICE_3D,
  496. TEXTURE_SLICE_2D_ARRAY,
  497. };
  498. virtual RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D, uint32_t p_layers = 0) = 0;
  499. virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  500. virtual Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer) = 0; // CPU textures will return immediately, while GPU textures will most likely force a flush
  501. virtual bool texture_is_format_supported_for_usage(DataFormat p_format, BitField<RenderingDevice::TextureUsageBits> p_usage) const = 0;
  502. virtual bool texture_is_shared(RID p_texture) = 0;
  503. virtual bool texture_is_valid(RID p_texture) = 0;
  504. virtual Size2i texture_size(RID p_texture) = 0;
  505. virtual uint64_t texture_get_native_handle(RID p_texture) = 0;
  506. virtual Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  507. virtual Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  508. virtual Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  509. /*********************/
  510. /**** FRAMEBUFFER ****/
  511. /*********************/
  512. struct AttachmentFormat {
  513. enum { UNUSED_ATTACHMENT = 0xFFFFFFFF };
  514. DataFormat format;
  515. TextureSamples samples;
  516. uint32_t usage_flags;
  517. AttachmentFormat() {
  518. format = DATA_FORMAT_R8G8B8A8_UNORM;
  519. samples = TEXTURE_SAMPLES_1;
  520. usage_flags = 0;
  521. }
  522. };
  523. typedef int64_t FramebufferFormatID;
  524. // This ID is warranted to be unique for the same formats, does not need to be freed
  525. virtual FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1) = 0;
  526. struct FramebufferPass {
  527. enum {
  528. ATTACHMENT_UNUSED = -1
  529. };
  530. Vector<int32_t> color_attachments;
  531. Vector<int32_t> input_attachments;
  532. Vector<int32_t> resolve_attachments;
  533. Vector<int32_t> preserve_attachments;
  534. int32_t depth_attachment = ATTACHMENT_UNUSED;
  535. int32_t vrs_attachment = ATTACHMENT_UNUSED; // density map for VRS, only used if supported
  536. };
  537. virtual FramebufferFormatID framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, uint32_t p_view_count = 1) = 0;
  538. virtual FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1) = 0;
  539. virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0) = 0;
  540. virtual RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1) = 0;
  541. virtual RID framebuffer_create_multipass(const Vector<RID> &p_texture_attachments, const Vector<FramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1) = 0;
  542. virtual RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID) = 0;
  543. virtual bool framebuffer_is_valid(RID p_framebuffer) const = 0;
  544. virtual void framebuffer_set_invalidation_callback(RID p_framebuffer, InvalidationCallback p_callback, void *p_userdata) = 0;
  545. virtual FramebufferFormatID framebuffer_get_format(RID p_framebuffer) = 0;
  546. /*****************/
  547. /**** SAMPLER ****/
  548. /*****************/
  549. enum SamplerFilter {
  550. SAMPLER_FILTER_NEAREST,
  551. SAMPLER_FILTER_LINEAR,
  552. };
  553. enum SamplerRepeatMode {
  554. SAMPLER_REPEAT_MODE_REPEAT,
  555. SAMPLER_REPEAT_MODE_MIRRORED_REPEAT,
  556. SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE,
  557. SAMPLER_REPEAT_MODE_CLAMP_TO_BORDER,
  558. SAMPLER_REPEAT_MODE_MIRROR_CLAMP_TO_EDGE,
  559. SAMPLER_REPEAT_MODE_MAX
  560. };
  561. enum SamplerBorderColor {
  562. SAMPLER_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
  563. SAMPLER_BORDER_COLOR_INT_TRANSPARENT_BLACK,
  564. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
  565. SAMPLER_BORDER_COLOR_INT_OPAQUE_BLACK,
  566. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
  567. SAMPLER_BORDER_COLOR_INT_OPAQUE_WHITE,
  568. SAMPLER_BORDER_COLOR_MAX
  569. };
  570. struct SamplerState {
  571. SamplerFilter mag_filter;
  572. SamplerFilter min_filter;
  573. SamplerFilter mip_filter;
  574. SamplerRepeatMode repeat_u;
  575. SamplerRepeatMode repeat_v;
  576. SamplerRepeatMode repeat_w;
  577. float lod_bias;
  578. bool use_anisotropy;
  579. float anisotropy_max;
  580. bool enable_compare;
  581. CompareOperator compare_op;
  582. float min_lod;
  583. float max_lod;
  584. SamplerBorderColor border_color;
  585. bool unnormalized_uvw;
  586. SamplerState() {
  587. mag_filter = SAMPLER_FILTER_NEAREST;
  588. min_filter = SAMPLER_FILTER_NEAREST;
  589. mip_filter = SAMPLER_FILTER_NEAREST;
  590. repeat_u = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  591. repeat_v = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  592. repeat_w = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  593. lod_bias = 0;
  594. use_anisotropy = false;
  595. anisotropy_max = 1.0;
  596. enable_compare = false;
  597. compare_op = COMPARE_OP_ALWAYS;
  598. min_lod = 0;
  599. max_lod = 1e20; //something very large should do
  600. border_color = SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
  601. unnormalized_uvw = false;
  602. }
  603. };
  604. virtual RID sampler_create(const SamplerState &p_state) = 0;
  605. virtual bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_sampler_filter) const = 0;
  606. /**********************/
  607. /**** VERTEX ARRAY ****/
  608. /**********************/
  609. enum VertexFrequency {
  610. VERTEX_FREQUENCY_VERTEX,
  611. VERTEX_FREQUENCY_INSTANCE,
  612. };
  613. struct VertexAttribute {
  614. uint32_t location; //shader location
  615. uint32_t offset;
  616. DataFormat format;
  617. uint32_t stride;
  618. VertexFrequency frequency;
  619. VertexAttribute() {
  620. location = 0;
  621. offset = 0;
  622. stride = 0;
  623. format = DATA_FORMAT_MAX;
  624. frequency = VERTEX_FREQUENCY_VERTEX;
  625. }
  626. };
  627. virtual RID vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_as_storage = false) = 0;
  628. typedef int64_t VertexFormatID;
  629. // This ID is warranted to be unique for the same formats, does not need to be freed
  630. virtual VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_formats) = 0;
  631. virtual RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector<RID> &p_src_buffers, const Vector<uint64_t> &p_offsets = Vector<uint64_t>()) = 0;
  632. enum IndexBufferFormat {
  633. INDEX_BUFFER_FORMAT_UINT16,
  634. INDEX_BUFFER_FORMAT_UINT32,
  635. };
  636. virtual RID index_buffer_create(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_restart_indices = false) = 0;
  637. virtual RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count) = 0;
  638. /****************/
  639. /**** SHADER ****/
  640. /****************/
  641. const Capabilities *get_device_capabilities() const { return &device_capabilities; };
  642. enum Features {
  643. SUPPORTS_MULTIVIEW,
  644. SUPPORTS_FSR_HALF_FLOAT,
  645. SUPPORTS_ATTACHMENT_VRS,
  646. // 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.
  647. SUPPORTS_FRAGMENT_SHADER_WITH_ONLY_SIDE_EFFECTS,
  648. };
  649. virtual bool has_feature(const Features p_feature) const = 0;
  650. virtual Vector<uint8_t> shader_compile_spirv_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language = SHADER_LANGUAGE_GLSL, String *r_error = nullptr, bool p_allow_cache = true);
  651. virtual String shader_get_spirv_cache_key() const;
  652. static void shader_set_compile_to_spirv_function(ShaderCompileToSPIRVFunction p_function);
  653. static void shader_set_spirv_cache_function(ShaderCacheFunction p_function);
  654. static void shader_set_get_cache_key_function(ShaderSPIRVGetCacheKeyFunction p_function);
  655. struct ShaderStageSPIRVData {
  656. ShaderStage shader_stage;
  657. Vector<uint8_t> spir_v;
  658. ShaderStageSPIRVData() {
  659. shader_stage = SHADER_STAGE_VERTEX;
  660. }
  661. };
  662. virtual String shader_get_binary_cache_key() const = 0;
  663. virtual Vector<uint8_t> shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "") = 0;
  664. virtual RID shader_create_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");
  665. virtual RID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary) = 0;
  666. virtual uint32_t shader_get_vertex_input_attribute_mask(RID p_shader) = 0;
  667. /******************/
  668. /**** UNIFORMS ****/
  669. /******************/
  670. enum UniformType {
  671. UNIFORM_TYPE_SAMPLER, //for sampling only (sampler GLSL type)
  672. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, // for sampling only, but includes a texture, (samplerXX GLSL type), first a sampler then a texture
  673. UNIFORM_TYPE_TEXTURE, //only texture, (textureXX GLSL type)
  674. UNIFORM_TYPE_IMAGE, // storage image (imageXX GLSL type), for compute mostly
  675. UNIFORM_TYPE_TEXTURE_BUFFER, // buffer texture (or TBO, textureBuffer type)
  676. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE_BUFFER, // buffer texture with a sampler(or TBO, samplerBuffer type)
  677. UNIFORM_TYPE_IMAGE_BUFFER, //texel buffer, (imageBuffer type), for compute mostly
  678. UNIFORM_TYPE_UNIFORM_BUFFER, //regular uniform buffer (or UBO).
  679. UNIFORM_TYPE_STORAGE_BUFFER, //storage buffer ("buffer" qualifier) like UBO, but supports storage, for compute mostly
  680. UNIFORM_TYPE_INPUT_ATTACHMENT, //used for sub-pass read/write, for mobile mostly
  681. UNIFORM_TYPE_MAX
  682. };
  683. enum StorageBufferUsage {
  684. STORAGE_BUFFER_USAGE_DISPATCH_INDIRECT = 1,
  685. };
  686. virtual RID uniform_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>()) = 0;
  687. virtual RID storage_buffer_create(uint32_t p_size, const Vector<uint8_t> &p_data = Vector<uint8_t>(), BitField<StorageBufferUsage> p_usage = 0) = 0;
  688. virtual RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>()) = 0;
  689. struct Uniform {
  690. UniformType uniform_type;
  691. int binding; // Binding index as specified in shader.
  692. private:
  693. // In most cases only one ID is provided per binding, so avoid allocating memory unnecessarily for performance.
  694. RID id; // If only one is provided, this is used.
  695. Vector<RID> ids; // If multiple ones are provided, this is used instead.
  696. public:
  697. _FORCE_INLINE_ uint32_t get_id_count() const {
  698. return (id.is_valid() ? 1 : ids.size());
  699. }
  700. _FORCE_INLINE_ RID get_id(uint32_t p_idx) const {
  701. if (id.is_valid()) {
  702. ERR_FAIL_COND_V(p_idx != 0, RID());
  703. return id;
  704. } else {
  705. return ids[p_idx];
  706. }
  707. }
  708. _FORCE_INLINE_ void set_id(uint32_t p_idx, RID p_id) {
  709. if (id.is_valid()) {
  710. ERR_FAIL_COND(p_idx != 0);
  711. id = p_id;
  712. } else {
  713. ids.write[p_idx] = p_id;
  714. }
  715. }
  716. _FORCE_INLINE_ void append_id(RID p_id) {
  717. if (ids.is_empty()) {
  718. if (id == RID()) {
  719. id = p_id;
  720. } else {
  721. ids.push_back(id);
  722. ids.push_back(p_id);
  723. id = RID();
  724. }
  725. } else {
  726. ids.push_back(p_id);
  727. }
  728. }
  729. _FORCE_INLINE_ void clear_ids() {
  730. id = RID();
  731. ids.clear();
  732. }
  733. _FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, RID p_id) {
  734. uniform_type = p_type;
  735. binding = p_binding;
  736. id = p_id;
  737. }
  738. _FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, const Vector<RID> &p_ids) {
  739. uniform_type = p_type;
  740. binding = p_binding;
  741. ids = p_ids;
  742. }
  743. _FORCE_INLINE_ Uniform() {
  744. uniform_type = UNIFORM_TYPE_IMAGE;
  745. binding = 0;
  746. }
  747. };
  748. virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) = 0;
  749. virtual bool uniform_set_is_valid(RID p_uniform_set) = 0;
  750. virtual void uniform_set_set_invalidation_callback(RID p_uniform_set, InvalidationCallback p_callback, void *p_userdata) = 0;
  751. virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  752. virtual Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  753. virtual Vector<uint8_t> buffer_get_data(RID p_buffer, uint32_t p_offset = 0, uint32_t p_size = 0) = 0; // This causes stall, only use to retrieve large buffers for saving.
  754. /******************************************/
  755. /**** PIPELINE SPECIALIZATION CONSTANT ****/
  756. /******************************************/
  757. enum PipelineSpecializationConstantType {
  758. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL,
  759. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_INT,
  760. PIPELINE_SPECIALIZATION_CONSTANT_TYPE_FLOAT,
  761. };
  762. struct PipelineSpecializationConstant {
  763. PipelineSpecializationConstantType type;
  764. uint32_t constant_id;
  765. union {
  766. uint32_t int_value;
  767. float float_value;
  768. bool bool_value;
  769. };
  770. PipelineSpecializationConstant() {
  771. type = PIPELINE_SPECIALIZATION_CONSTANT_TYPE_BOOL;
  772. constant_id = 0;
  773. int_value = 0;
  774. }
  775. };
  776. /*************************/
  777. /**** RENDER PIPELINE ****/
  778. /*************************/
  779. enum RenderPrimitive {
  780. RENDER_PRIMITIVE_POINTS,
  781. RENDER_PRIMITIVE_LINES,
  782. RENDER_PRIMITIVE_LINES_WITH_ADJACENCY,
  783. RENDER_PRIMITIVE_LINESTRIPS,
  784. RENDER_PRIMITIVE_LINESTRIPS_WITH_ADJACENCY,
  785. RENDER_PRIMITIVE_TRIANGLES,
  786. RENDER_PRIMITIVE_TRIANGLES_WITH_ADJACENCY,
  787. RENDER_PRIMITIVE_TRIANGLE_STRIPS,
  788. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_AJACENCY,
  789. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_RESTART_INDEX,
  790. RENDER_PRIMITIVE_TESSELATION_PATCH,
  791. RENDER_PRIMITIVE_MAX
  792. };
  793. //disable optimization, tessellate control points
  794. enum PolygonCullMode {
  795. POLYGON_CULL_DISABLED,
  796. POLYGON_CULL_FRONT,
  797. POLYGON_CULL_BACK,
  798. };
  799. enum PolygonFrontFace {
  800. POLYGON_FRONT_FACE_CLOCKWISE,
  801. POLYGON_FRONT_FACE_COUNTER_CLOCKWISE,
  802. };
  803. enum StencilOperation {
  804. STENCIL_OP_KEEP,
  805. STENCIL_OP_ZERO,
  806. STENCIL_OP_REPLACE,
  807. STENCIL_OP_INCREMENT_AND_CLAMP,
  808. STENCIL_OP_DECREMENT_AND_CLAMP,
  809. STENCIL_OP_INVERT,
  810. STENCIL_OP_INCREMENT_AND_WRAP,
  811. STENCIL_OP_DECREMENT_AND_WRAP,
  812. STENCIL_OP_MAX //not an actual operator, just the amount of operators :D
  813. };
  814. enum LogicOperation {
  815. LOGIC_OP_CLEAR,
  816. LOGIC_OP_AND,
  817. LOGIC_OP_AND_REVERSE,
  818. LOGIC_OP_COPY,
  819. LOGIC_OP_AND_INVERTED,
  820. LOGIC_OP_NO_OP,
  821. LOGIC_OP_XOR,
  822. LOGIC_OP_OR,
  823. LOGIC_OP_NOR,
  824. LOGIC_OP_EQUIVALENT,
  825. LOGIC_OP_INVERT,
  826. LOGIC_OP_OR_REVERSE,
  827. LOGIC_OP_COPY_INVERTED,
  828. LOGIC_OP_OR_INVERTED,
  829. LOGIC_OP_NAND,
  830. LOGIC_OP_SET,
  831. LOGIC_OP_MAX //not an actual operator, just the amount of operators :D
  832. };
  833. enum BlendFactor {
  834. BLEND_FACTOR_ZERO,
  835. BLEND_FACTOR_ONE,
  836. BLEND_FACTOR_SRC_COLOR,
  837. BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
  838. BLEND_FACTOR_DST_COLOR,
  839. BLEND_FACTOR_ONE_MINUS_DST_COLOR,
  840. BLEND_FACTOR_SRC_ALPHA,
  841. BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
  842. BLEND_FACTOR_DST_ALPHA,
  843. BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
  844. BLEND_FACTOR_CONSTANT_COLOR,
  845. BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
  846. BLEND_FACTOR_CONSTANT_ALPHA,
  847. BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
  848. BLEND_FACTOR_SRC_ALPHA_SATURATE,
  849. BLEND_FACTOR_SRC1_COLOR,
  850. BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
  851. BLEND_FACTOR_SRC1_ALPHA,
  852. BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
  853. BLEND_FACTOR_MAX
  854. };
  855. enum BlendOperation {
  856. BLEND_OP_ADD,
  857. BLEND_OP_SUBTRACT,
  858. BLEND_OP_REVERSE_SUBTRACT,
  859. BLEND_OP_MINIMUM,
  860. BLEND_OP_MAXIMUM, //yes this one is an actual operator
  861. BLEND_OP_MAX //not an actual operator, just the amount of operators :D
  862. };
  863. struct PipelineRasterizationState {
  864. bool enable_depth_clamp;
  865. bool discard_primitives;
  866. bool wireframe;
  867. PolygonCullMode cull_mode;
  868. PolygonFrontFace front_face;
  869. bool depth_bias_enabled;
  870. float depth_bias_constant_factor;
  871. float depth_bias_clamp;
  872. float depth_bias_slope_factor;
  873. float line_width;
  874. uint32_t patch_control_points;
  875. PipelineRasterizationState() {
  876. enable_depth_clamp = false;
  877. discard_primitives = false;
  878. wireframe = false;
  879. cull_mode = POLYGON_CULL_DISABLED;
  880. front_face = POLYGON_FRONT_FACE_CLOCKWISE;
  881. depth_bias_enabled = false;
  882. depth_bias_constant_factor = 0;
  883. depth_bias_clamp = 0;
  884. depth_bias_slope_factor = 0;
  885. line_width = 1.0;
  886. patch_control_points = 1;
  887. }
  888. };
  889. struct PipelineMultisampleState {
  890. TextureSamples sample_count;
  891. bool enable_sample_shading;
  892. float min_sample_shading;
  893. Vector<uint32_t> sample_mask;
  894. bool enable_alpha_to_coverage;
  895. bool enable_alpha_to_one;
  896. PipelineMultisampleState() {
  897. sample_count = TEXTURE_SAMPLES_1;
  898. enable_sample_shading = false;
  899. min_sample_shading = 0;
  900. enable_alpha_to_coverage = false;
  901. enable_alpha_to_one = false;
  902. }
  903. };
  904. struct PipelineDepthStencilState {
  905. bool enable_depth_test;
  906. bool enable_depth_write;
  907. CompareOperator depth_compare_operator;
  908. bool enable_depth_range;
  909. float depth_range_min;
  910. float depth_range_max;
  911. bool enable_stencil;
  912. struct StencilOperationState {
  913. StencilOperation fail;
  914. StencilOperation pass;
  915. StencilOperation depth_fail;
  916. CompareOperator compare;
  917. uint32_t compare_mask;
  918. uint32_t write_mask;
  919. uint32_t reference;
  920. StencilOperationState() {
  921. fail = STENCIL_OP_ZERO;
  922. pass = STENCIL_OP_ZERO;
  923. depth_fail = STENCIL_OP_ZERO;
  924. compare = COMPARE_OP_ALWAYS;
  925. compare_mask = 0;
  926. write_mask = 0;
  927. reference = 0;
  928. }
  929. };
  930. StencilOperationState front_op;
  931. StencilOperationState back_op;
  932. PipelineDepthStencilState() {
  933. enable_depth_test = false;
  934. enable_depth_write = false;
  935. depth_compare_operator = COMPARE_OP_ALWAYS;
  936. enable_depth_range = false;
  937. depth_range_min = 0;
  938. depth_range_max = 0;
  939. enable_stencil = false;
  940. }
  941. };
  942. struct PipelineColorBlendState {
  943. bool enable_logic_op;
  944. LogicOperation logic_op;
  945. struct Attachment {
  946. bool enable_blend;
  947. BlendFactor src_color_blend_factor;
  948. BlendFactor dst_color_blend_factor;
  949. BlendOperation color_blend_op;
  950. BlendFactor src_alpha_blend_factor;
  951. BlendFactor dst_alpha_blend_factor;
  952. BlendOperation alpha_blend_op;
  953. bool write_r;
  954. bool write_g;
  955. bool write_b;
  956. bool write_a;
  957. Attachment() {
  958. enable_blend = false;
  959. src_color_blend_factor = BLEND_FACTOR_ZERO;
  960. dst_color_blend_factor = BLEND_FACTOR_ZERO;
  961. color_blend_op = BLEND_OP_ADD;
  962. src_alpha_blend_factor = BLEND_FACTOR_ZERO;
  963. dst_alpha_blend_factor = BLEND_FACTOR_ZERO;
  964. alpha_blend_op = BLEND_OP_ADD;
  965. write_r = true;
  966. write_g = true;
  967. write_b = true;
  968. write_a = true;
  969. }
  970. };
  971. static PipelineColorBlendState create_disabled(int p_attachments = 1) {
  972. PipelineColorBlendState bs;
  973. for (int i = 0; i < p_attachments; i++) {
  974. bs.attachments.push_back(Attachment());
  975. }
  976. return bs;
  977. }
  978. static PipelineColorBlendState create_blend(int p_attachments = 1) {
  979. PipelineColorBlendState bs;
  980. for (int i = 0; i < p_attachments; i++) {
  981. Attachment ba;
  982. ba.enable_blend = true;
  983. ba.src_color_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  984. ba.dst_color_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  985. ba.src_alpha_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  986. ba.dst_alpha_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  987. bs.attachments.push_back(ba);
  988. }
  989. return bs;
  990. }
  991. Vector<Attachment> attachments; //one per render target texture
  992. Color blend_constant;
  993. PipelineColorBlendState() {
  994. enable_logic_op = false;
  995. logic_op = LOGIC_OP_CLEAR;
  996. }
  997. };
  998. enum PipelineDynamicStateFlags {
  999. DYNAMIC_STATE_LINE_WIDTH = (1 << 0),
  1000. DYNAMIC_STATE_DEPTH_BIAS = (1 << 1),
  1001. DYNAMIC_STATE_BLEND_CONSTANTS = (1 << 2),
  1002. DYNAMIC_STATE_DEPTH_BOUNDS = (1 << 3),
  1003. DYNAMIC_STATE_STENCIL_COMPARE_MASK = (1 << 4),
  1004. DYNAMIC_STATE_STENCIL_WRITE_MASK = (1 << 5),
  1005. DYNAMIC_STATE_STENCIL_REFERENCE = (1 << 6),
  1006. };
  1007. virtual bool render_pipeline_is_valid(RID p_pipeline) = 0;
  1008. virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()) = 0;
  1009. /**************************/
  1010. /**** COMPUTE PIPELINE ****/
  1011. /**************************/
  1012. virtual RID compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()) = 0;
  1013. virtual bool compute_pipeline_is_valid(RID p_pipeline) = 0;
  1014. /****************/
  1015. /**** SCREEN ****/
  1016. /****************/
  1017. virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const = 0;
  1018. virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const = 0;
  1019. virtual FramebufferFormatID screen_get_framebuffer_format() const = 0;
  1020. /********************/
  1021. /**** DRAW LISTS ****/
  1022. /********************/
  1023. enum InitialAction {
  1024. INITIAL_ACTION_CLEAR, // Start rendering and clear the whole framebuffer.
  1025. INITIAL_ACTION_CLEAR_REGION, // Start rendering and clear the framebuffer in the specified region.
  1026. INITIAL_ACTION_CLEAR_REGION_CONTINUE, // Continue rendering and clear the framebuffer in the specified region. Framebuffer must have been left in `FINAL_ACTION_CONTINUE` state as the final action previously.
  1027. INITIAL_ACTION_KEEP, // Start rendering, but keep attached color texture contents. If the framebuffer was previously used to read in a shader, this will automatically insert a layout transition.
  1028. INITIAL_ACTION_DROP, // Start rendering, ignore what is there; write above it. In general, this is the fastest option when you will be writing every single pixel and you don't need a clear color.
  1029. INITIAL_ACTION_CONTINUE, // Continue rendering. Framebuffer must have been left in `FINAL_ACTION_CONTINUE` state as the final action previously.
  1030. INITIAL_ACTION_MAX
  1031. };
  1032. enum FinalAction {
  1033. FINAL_ACTION_READ, // Store the texture for reading and make it read-only if it has the `TEXTURE_USAGE_SAMPLING_BIT` bit (only applies to color, depth and stencil attachments).
  1034. FINAL_ACTION_DISCARD, // Discard the texture data and make it read-only if it has the `TEXTURE_USAGE_SAMPLING_BIT` bit (only applies to color, depth and stencil attachments).
  1035. FINAL_ACTION_CONTINUE, // Store the texture and continue for further processing. Similar to `FINAL_ACTION_READ`, but does not make the texture read-only if it has the `TEXTURE_USAGE_SAMPLING_BIT` bit.
  1036. FINAL_ACTION_MAX
  1037. };
  1038. typedef int64_t DrawListID;
  1039. virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color()) = 0;
  1040. virtual DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector<RID> &p_storage_textures = Vector<RID>()) = 0;
  1041. virtual Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector<RID> &p_storage_textures = Vector<RID>()) = 0;
  1042. virtual void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color) = 0;
  1043. virtual void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline) = 0;
  1044. virtual void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index) = 0;
  1045. virtual void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array) = 0;
  1046. virtual void draw_list_bind_index_array(DrawListID p_list, RID p_index_array) = 0;
  1047. virtual void draw_list_set_line_width(DrawListID p_list, float p_width) = 0;
  1048. virtual void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size) = 0;
  1049. virtual void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0) = 0;
  1050. virtual void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect) = 0;
  1051. virtual void draw_list_disable_scissor(DrawListID p_list) = 0;
  1052. virtual uint32_t draw_list_get_current_pass() = 0;
  1053. virtual DrawListID draw_list_switch_to_next_pass() = 0;
  1054. virtual Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids) = 0;
  1055. virtual void draw_list_end(BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  1056. /***********************/
  1057. /**** COMPUTE LISTS ****/
  1058. /***********************/
  1059. typedef int64_t ComputeListID;
  1060. virtual ComputeListID compute_list_begin(bool p_allow_draw_overlap = false) = 0;
  1061. virtual void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline) = 0;
  1062. virtual void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index) = 0;
  1063. virtual void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size) = 0;
  1064. virtual void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) = 0;
  1065. virtual void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads) = 0;
  1066. virtual void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset) = 0;
  1067. virtual void compute_list_add_barrier(ComputeListID p_list) = 0;
  1068. virtual void compute_list_end(BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS) = 0;
  1069. virtual void barrier(BitField<BarrierMask> p_from = BARRIER_MASK_ALL_BARRIERS, BitField<BarrierMask> p_to = BARRIER_MASK_ALL_BARRIERS) = 0;
  1070. virtual void full_barrier() = 0;
  1071. /***************/
  1072. /**** FREE! ****/
  1073. /***************/
  1074. virtual void free(RID p_id) = 0;
  1075. /****************/
  1076. /**** Timing ****/
  1077. /****************/
  1078. virtual void capture_timestamp(const String &p_name) = 0;
  1079. virtual uint32_t get_captured_timestamps_count() const = 0;
  1080. virtual uint64_t get_captured_timestamps_frame() const = 0;
  1081. virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const = 0;
  1082. virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const = 0;
  1083. virtual String get_captured_timestamp_name(uint32_t p_index) const = 0;
  1084. /****************/
  1085. /**** LIMITS ****/
  1086. /****************/
  1087. enum Limit {
  1088. LIMIT_MAX_BOUND_UNIFORM_SETS,
  1089. LIMIT_MAX_FRAMEBUFFER_COLOR_ATTACHMENTS,
  1090. LIMIT_MAX_TEXTURES_PER_UNIFORM_SET,
  1091. LIMIT_MAX_SAMPLERS_PER_UNIFORM_SET,
  1092. LIMIT_MAX_STORAGE_BUFFERS_PER_UNIFORM_SET,
  1093. LIMIT_MAX_STORAGE_IMAGES_PER_UNIFORM_SET,
  1094. LIMIT_MAX_UNIFORM_BUFFERS_PER_UNIFORM_SET,
  1095. LIMIT_MAX_DRAW_INDEXED_INDEX,
  1096. LIMIT_MAX_FRAMEBUFFER_HEIGHT,
  1097. LIMIT_MAX_FRAMEBUFFER_WIDTH,
  1098. LIMIT_MAX_TEXTURE_ARRAY_LAYERS,
  1099. LIMIT_MAX_TEXTURE_SIZE_1D,
  1100. LIMIT_MAX_TEXTURE_SIZE_2D,
  1101. LIMIT_MAX_TEXTURE_SIZE_3D,
  1102. LIMIT_MAX_TEXTURE_SIZE_CUBE,
  1103. LIMIT_MAX_TEXTURES_PER_SHADER_STAGE,
  1104. LIMIT_MAX_SAMPLERS_PER_SHADER_STAGE,
  1105. LIMIT_MAX_STORAGE_BUFFERS_PER_SHADER_STAGE,
  1106. LIMIT_MAX_STORAGE_IMAGES_PER_SHADER_STAGE,
  1107. LIMIT_MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE,
  1108. LIMIT_MAX_PUSH_CONSTANT_SIZE,
  1109. LIMIT_MAX_UNIFORM_BUFFER_SIZE,
  1110. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTE_OFFSET,
  1111. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTES,
  1112. LIMIT_MAX_VERTEX_INPUT_BINDINGS,
  1113. LIMIT_MAX_VERTEX_INPUT_BINDING_STRIDE,
  1114. LIMIT_MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
  1115. LIMIT_MAX_COMPUTE_SHARED_MEMORY_SIZE,
  1116. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X,
  1117. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Y,
  1118. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Z,
  1119. LIMIT_MAX_COMPUTE_WORKGROUP_INVOCATIONS,
  1120. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_X,
  1121. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Y,
  1122. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z,
  1123. LIMIT_MAX_VIEWPORT_DIMENSIONS_X,
  1124. LIMIT_MAX_VIEWPORT_DIMENSIONS_Y,
  1125. LIMIT_SUBGROUP_SIZE,
  1126. LIMIT_SUBGROUP_IN_SHADERS, // Set flags using SHADER_STAGE_VERTEX_BIT, SHADER_STAGE_FRAGMENT_BIT, etc.
  1127. LIMIT_SUBGROUP_OPERATIONS,
  1128. LIMIT_VRS_TEXEL_WIDTH,
  1129. LIMIT_VRS_TEXEL_HEIGHT,
  1130. };
  1131. virtual uint64_t limit_get(Limit p_limit) const = 0;
  1132. //methods below not exposed, used by RenderingDeviceRD
  1133. virtual void prepare_screen_for_drawing() = 0;
  1134. virtual void swap_buffers() = 0;
  1135. virtual uint32_t get_frame_delay() const = 0;
  1136. virtual void submit() = 0;
  1137. virtual void sync() = 0;
  1138. enum MemoryType {
  1139. MEMORY_TEXTURES,
  1140. MEMORY_BUFFERS,
  1141. MEMORY_TOTAL
  1142. };
  1143. virtual uint64_t get_memory_usage(MemoryType p_type) const = 0;
  1144. virtual RenderingDevice *create_local_device() = 0;
  1145. virtual void set_resource_name(RID p_id, const String p_name) = 0;
  1146. virtual void draw_command_begin_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1)) = 0;
  1147. virtual void draw_command_insert_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1)) = 0;
  1148. virtual void draw_command_end_label() = 0;
  1149. virtual String get_device_vendor_name() const = 0;
  1150. virtual String get_device_name() const = 0;
  1151. virtual RenderingDevice::DeviceType get_device_type() const = 0;
  1152. virtual String get_device_api_version() const = 0;
  1153. virtual String get_device_pipeline_cache_uuid() const = 0;
  1154. virtual uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0) = 0;
  1155. static RenderingDevice *get_singleton();
  1156. RenderingDevice();
  1157. protected:
  1158. static const char *shader_stage_names[RenderingDevice::SHADER_STAGE_MAX];
  1159. static const uint32_t MAX_UNIFORM_SETS = 16;
  1160. //binders to script API
  1161. RID _texture_create(const Ref<RDTextureFormat> &p_format, const Ref<RDTextureView> &p_view, const TypedArray<PackedByteArray> &p_data = Array());
  1162. RID _texture_create_shared(const Ref<RDTextureView> &p_view, RID p_with_texture);
  1163. RID _texture_create_shared_from_slice(const Ref<RDTextureView> &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, uint32_t p_mipmaps = 1, TextureSliceType p_slice_type = TEXTURE_SLICE_2D);
  1164. FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments, uint32_t p_view_count);
  1165. FramebufferFormatID _framebuffer_format_create_multipass(const TypedArray<RDAttachmentFormat> &p_attachments, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_view_count);
  1166. RID _framebuffer_create(const TypedArray<RID> &p_textures, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  1167. RID _framebuffer_create_multipass(const TypedArray<RID> &p_textures, const TypedArray<RDFramebufferPass> &p_passes, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  1168. RID _sampler_create(const Ref<RDSamplerState> &p_state);
  1169. VertexFormatID _vertex_format_create(const TypedArray<RDVertexAttribute> &p_vertex_formats);
  1170. RID _vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const TypedArray<RID> &p_src_buffers, const Vector<int64_t> &p_offsets = Vector<int64_t>());
  1171. Ref<RDShaderSPIRV> _shader_compile_spirv_from_source(const Ref<RDShaderSource> &p_source, bool p_allow_cache = true);
  1172. Vector<uint8_t> _shader_compile_binary_from_spirv(const Ref<RDShaderSPIRV> &p_bytecode, const String &p_shader_name = "");
  1173. RID _shader_create_from_spirv(const Ref<RDShaderSPIRV> &p_spirv, const String &p_shader_name = "");
  1174. RID _uniform_set_create(const TypedArray<RDUniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
  1175. Error _buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS);
  1176. RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants);
  1177. RID _compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants);
  1178. DrawListID _draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray<RID> &p_storage_textures = TypedArray<RID>());
  1179. Vector<int64_t> _draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray<RID> &p_storage_textures = TypedArray<RID>());
  1180. void _draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  1181. void _compute_list_set_push_constant(ComputeListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  1182. Vector<int64_t> _draw_list_switch_to_next_pass_split(uint32_t p_splits);
  1183. struct SpirvReflectionData {
  1184. BitField<ShaderStage> stages_mask;
  1185. uint32_t vertex_input_mask;
  1186. uint32_t fragment_output_mask;
  1187. bool is_compute;
  1188. uint32_t compute_local_size[3];
  1189. uint32_t push_constant_size;
  1190. BitField<ShaderStage> push_constant_stages_mask;
  1191. struct Uniform {
  1192. UniformType type;
  1193. uint32_t binding;
  1194. BitField<ShaderStage> stages_mask;
  1195. uint32_t length; // Size of arrays (in total elements), or ubos (in bytes * total elements).
  1196. bool writable;
  1197. };
  1198. Vector<Vector<Uniform>> uniforms;
  1199. struct SpecializationConstant {
  1200. PipelineSpecializationConstantType type;
  1201. uint32_t constant_id;
  1202. union {
  1203. uint32_t int_value;
  1204. float float_value;
  1205. bool bool_value;
  1206. };
  1207. BitField<ShaderStage> stages_mask;
  1208. };
  1209. Vector<SpecializationConstant> specialization_constants;
  1210. };
  1211. Error _reflect_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, SpirvReflectionData &r_reflection_data);
  1212. };
  1213. VARIANT_ENUM_CAST(RenderingDevice::DeviceType)
  1214. VARIANT_ENUM_CAST(RenderingDevice::DriverResource)
  1215. VARIANT_ENUM_CAST(RenderingDevice::ShaderStage)
  1216. VARIANT_ENUM_CAST(RenderingDevice::ShaderLanguage)
  1217. VARIANT_ENUM_CAST(RenderingDevice::CompareOperator)
  1218. VARIANT_ENUM_CAST(RenderingDevice::DataFormat)
  1219. VARIANT_BITFIELD_CAST(RenderingDevice::BarrierMask);
  1220. VARIANT_ENUM_CAST(RenderingDevice::TextureType)
  1221. VARIANT_ENUM_CAST(RenderingDevice::TextureSamples)
  1222. VARIANT_BITFIELD_CAST(RenderingDevice::TextureUsageBits)
  1223. VARIANT_ENUM_CAST(RenderingDevice::TextureSwizzle)
  1224. VARIANT_ENUM_CAST(RenderingDevice::TextureSliceType)
  1225. VARIANT_ENUM_CAST(RenderingDevice::SamplerFilter)
  1226. VARIANT_ENUM_CAST(RenderingDevice::SamplerRepeatMode)
  1227. VARIANT_ENUM_CAST(RenderingDevice::SamplerBorderColor)
  1228. VARIANT_ENUM_CAST(RenderingDevice::VertexFrequency)
  1229. VARIANT_ENUM_CAST(RenderingDevice::IndexBufferFormat)
  1230. VARIANT_BITFIELD_CAST(RenderingDevice::StorageBufferUsage)
  1231. VARIANT_ENUM_CAST(RenderingDevice::UniformType)
  1232. VARIANT_ENUM_CAST(RenderingDevice::RenderPrimitive)
  1233. VARIANT_ENUM_CAST(RenderingDevice::PolygonCullMode)
  1234. VARIANT_ENUM_CAST(RenderingDevice::PolygonFrontFace)
  1235. VARIANT_ENUM_CAST(RenderingDevice::StencilOperation)
  1236. VARIANT_ENUM_CAST(RenderingDevice::LogicOperation)
  1237. VARIANT_ENUM_CAST(RenderingDevice::BlendFactor)
  1238. VARIANT_ENUM_CAST(RenderingDevice::BlendOperation)
  1239. VARIANT_BITFIELD_CAST(RenderingDevice::PipelineDynamicStateFlags)
  1240. VARIANT_ENUM_CAST(RenderingDevice::PipelineSpecializationConstantType)
  1241. VARIANT_ENUM_CAST(RenderingDevice::InitialAction)
  1242. VARIANT_ENUM_CAST(RenderingDevice::FinalAction)
  1243. VARIANT_ENUM_CAST(RenderingDevice::Limit)
  1244. VARIANT_ENUM_CAST(RenderingDevice::MemoryType)
  1245. VARIANT_ENUM_CAST(RenderingDevice::Features)
  1246. typedef RenderingDevice RD;
  1247. #endif // RENDERING_DEVICE_H