rendering_device.h 54 KB

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