rendering_device.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489
  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/object/worker_thread_pool.h"
  34. #include "core/os/thread_safe.h"
  35. #include "core/templates/local_vector.h"
  36. #include "core/templates/oa_hash_map.h"
  37. #include "core/templates/rid_owner.h"
  38. #include "core/variant/typed_array.h"
  39. #include "servers/display_server.h"
  40. #include "servers/rendering/rendering_device_commons.h"
  41. #include "servers/rendering/rendering_device_driver.h"
  42. #include "servers/rendering/rendering_device_graph.h"
  43. class RDTextureFormat;
  44. class RDTextureView;
  45. class RDAttachmentFormat;
  46. class RDSamplerState;
  47. class RDVertexAttribute;
  48. class RDShaderSource;
  49. class RDShaderSPIRV;
  50. class RDUniform;
  51. class RDPipelineRasterizationState;
  52. class RDPipelineMultisampleState;
  53. class RDPipelineDepthStencilState;
  54. class RDPipelineColorBlendState;
  55. class RDFramebufferPass;
  56. class RDPipelineSpecializationConstant;
  57. class RenderingDevice : public RenderingDeviceCommons {
  58. GDCLASS(RenderingDevice, Object)
  59. _THREAD_SAFE_CLASS_
  60. public:
  61. enum ShaderLanguage {
  62. SHADER_LANGUAGE_GLSL,
  63. SHADER_LANGUAGE_HLSL
  64. };
  65. typedef int64_t DrawListID;
  66. typedef int64_t ComputeListID;
  67. typedef String (*ShaderSPIRVGetCacheKeyFunction)(const RenderingDevice *p_render_device);
  68. typedef Vector<uint8_t> (*ShaderCompileToSPIRVFunction)(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language, String *r_error, const RenderingDevice *p_render_device);
  69. typedef Vector<uint8_t> (*ShaderCacheFunction)(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language);
  70. typedef void (*InvalidationCallback)(void *);
  71. private:
  72. static ShaderCompileToSPIRVFunction compile_to_spirv_function;
  73. static ShaderCacheFunction cache_function;
  74. static ShaderSPIRVGetCacheKeyFunction get_spirv_cache_key_function;
  75. static RenderingDevice *singleton;
  76. RenderingContextDriver *context = nullptr;
  77. RenderingDeviceDriver *driver = nullptr;
  78. RenderingContextDriver::Device device;
  79. bool local_device_processing = false;
  80. bool is_main_instance = false;
  81. protected:
  82. static void _bind_methods();
  83. #ifndef DISABLE_DEPRECATED
  84. RID _shader_create_from_bytecode_bind_compat_79606(const Vector<uint8_t> &p_shader_binary);
  85. static void _bind_compatibility_methods();
  86. #endif
  87. /***************************/
  88. /**** ID INFRASTRUCTURE ****/
  89. /***************************/
  90. public:
  91. //base numeric ID for all types
  92. enum {
  93. INVALID_FORMAT_ID = -1
  94. };
  95. enum IDType {
  96. ID_TYPE_FRAMEBUFFER_FORMAT,
  97. ID_TYPE_VERTEX_FORMAT,
  98. ID_TYPE_DRAW_LIST,
  99. ID_TYPE_COMPUTE_LIST = 4,
  100. ID_TYPE_MAX,
  101. ID_BASE_SHIFT = 58, // 5 bits for ID types.
  102. ID_MASK = (ID_BASE_SHIFT - 1),
  103. };
  104. private:
  105. HashMap<RID, HashSet<RID>> dependency_map; // IDs to IDs that depend on it.
  106. HashMap<RID, HashSet<RID>> reverse_dependency_map; // Same as above, but in reverse.
  107. void _add_dependency(RID p_id, RID p_depends_on);
  108. void _free_dependencies(RID p_id);
  109. private:
  110. /***************************/
  111. /**** BUFFER MANAGEMENT ****/
  112. /***************************/
  113. // These are temporary buffers on CPU memory that hold
  114. // the information until the CPU fetches it and places it
  115. // either on GPU buffers, or images (textures). It ensures
  116. // updates are properly synchronized with whatever the
  117. // GPU is doing.
  118. //
  119. // The logic here is as follows, only 3 of these
  120. // blocks are created at the beginning (one per frame)
  121. // they can each belong to a frame (assigned to current when
  122. // used) and they can only be reused after the same frame is
  123. // recycled.
  124. //
  125. // When CPU requires to allocate more than what is available,
  126. // more of these buffers are created. If a limit is reached,
  127. // then a fence will ensure will wait for blocks allocated
  128. // in previous frames are processed. If that fails, then
  129. // another fence will ensure everything pending for the current
  130. // frame is processed (effectively stalling).
  131. //
  132. // See the comments in the code to understand better how it works.
  133. struct StagingBufferBlock {
  134. RDD::BufferID driver_id;
  135. uint64_t frame_used = 0;
  136. uint32_t fill_amount = 0;
  137. };
  138. Vector<StagingBufferBlock> staging_buffer_blocks;
  139. int staging_buffer_current = 0;
  140. uint32_t staging_buffer_block_size = 0;
  141. uint64_t staging_buffer_max_size = 0;
  142. bool staging_buffer_used = false;
  143. enum StagingRequiredAction {
  144. STAGING_REQUIRED_ACTION_NONE,
  145. STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL,
  146. STAGING_REQUIRED_ACTION_STALL_PREVIOUS
  147. };
  148. Error _staging_buffer_allocate(uint32_t p_amount, uint32_t p_required_align, uint32_t &r_alloc_offset, uint32_t &r_alloc_size, StagingRequiredAction &r_required_action, bool p_can_segment = true);
  149. void _staging_buffer_execute_required_action(StagingRequiredAction p_required_action);
  150. Error _insert_staging_block();
  151. struct Buffer {
  152. RDD::BufferID driver_id;
  153. uint32_t size = 0;
  154. BitField<RDD::BufferUsageBits> usage;
  155. RDG::ResourceTracker *draw_tracker = nullptr;
  156. };
  157. Buffer *_get_buffer_from_owner(RID p_buffer);
  158. Error _buffer_update(Buffer *p_buffer, RID p_buffer_id, size_t p_offset, const uint8_t *p_data, size_t p_data_size, bool p_use_draw_queue = false, uint32_t p_required_align = 32);
  159. RID_Owner<Buffer> uniform_buffer_owner;
  160. RID_Owner<Buffer> storage_buffer_owner;
  161. RID_Owner<Buffer> texture_buffer_owner;
  162. public:
  163. 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);
  164. Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data);
  165. Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size);
  166. Vector<uint8_t> buffer_get_data(RID p_buffer, uint32_t p_offset = 0, uint32_t p_size = 0); // This causes stall, only use to retrieve large buffers for saving.
  167. /*****************/
  168. /**** TEXTURE ****/
  169. /*****************/
  170. // In modern APIs, the concept of textures may not exist;
  171. // instead there is the image (the memory pretty much,
  172. // the view (how the memory is interpreted) and the
  173. // sampler (how it's sampled from the shader).
  174. //
  175. // Texture here includes the first two stages, but
  176. // It's possible to create textures sharing the image
  177. // but with different views. The main use case for this
  178. // is textures that can be read as both SRGB/Linear,
  179. // or slices of a texture (a mipmap, a layer, a 3D slice)
  180. // for a framebuffer to render into it.
  181. struct Texture {
  182. struct SharedFallback {
  183. uint32_t revision = 1;
  184. RDD::TextureID texture;
  185. RDG::ResourceTracker *texture_tracker = nullptr;
  186. RDD::BufferID buffer;
  187. RDG::ResourceTracker *buffer_tracker = nullptr;
  188. bool raw_reinterpretation = false;
  189. };
  190. RDD::TextureID driver_id;
  191. TextureType type = TEXTURE_TYPE_MAX;
  192. DataFormat format = DATA_FORMAT_MAX;
  193. TextureSamples samples = TEXTURE_SAMPLES_MAX;
  194. TextureSliceType slice_type = TEXTURE_SLICE_MAX;
  195. Rect2i slice_rect;
  196. uint32_t width = 0;
  197. uint32_t height = 0;
  198. uint32_t depth = 0;
  199. uint32_t layers = 0;
  200. uint32_t mipmaps = 0;
  201. uint32_t usage_flags = 0;
  202. uint32_t base_mipmap = 0;
  203. uint32_t base_layer = 0;
  204. Vector<DataFormat> allowed_shared_formats;
  205. bool is_resolve_buffer = false;
  206. bool has_initial_data = false;
  207. BitField<RDD::TextureAspectBits> read_aspect_flags;
  208. BitField<RDD::TextureAspectBits> barrier_aspect_flags;
  209. bool bound = false; // Bound to framebuffer.
  210. RID owner;
  211. RDG::ResourceTracker *draw_tracker = nullptr;
  212. HashMap<Rect2i, RDG::ResourceTracker *> slice_trackers;
  213. SharedFallback *shared_fallback = nullptr;
  214. RDD::TextureSubresourceRange barrier_range() const {
  215. RDD::TextureSubresourceRange r;
  216. r.aspect = barrier_aspect_flags;
  217. r.base_mipmap = base_mipmap;
  218. r.mipmap_count = mipmaps;
  219. r.base_layer = base_layer;
  220. r.layer_count = layers;
  221. return r;
  222. }
  223. TextureFormat texture_format() const {
  224. TextureFormat tf;
  225. tf.format = format;
  226. tf.width = width;
  227. tf.height = height;
  228. tf.depth = depth;
  229. tf.array_layers = layers;
  230. tf.mipmaps = mipmaps;
  231. tf.texture_type = type;
  232. tf.samples = samples;
  233. tf.usage_bits = usage_flags;
  234. tf.shareable_formats = allowed_shared_formats;
  235. tf.is_resolve_buffer = is_resolve_buffer;
  236. return tf;
  237. }
  238. };
  239. RID_Owner<Texture> texture_owner;
  240. uint32_t texture_upload_region_size_px = 0;
  241. Vector<uint8_t> _texture_get_data(Texture *tex, uint32_t p_layer, bool p_2d = false);
  242. Error _texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, bool p_use_setup_queue, bool p_validate_can_update);
  243. void _texture_check_shared_fallback(Texture *p_texture);
  244. void _texture_update_shared_fallback(RID p_texture_rid, Texture *p_texture, bool p_for_writing);
  245. void _texture_free_shared_fallback(Texture *p_texture);
  246. void _texture_copy_shared(RID p_src_texture_rid, Texture *p_src_texture, RID p_dst_texture_rid, Texture *p_dst_texture);
  247. void _texture_create_reinterpret_buffer(Texture *p_texture);
  248. public:
  249. struct TextureView {
  250. DataFormat format_override = DATA_FORMAT_MAX; // // Means, use same as format.
  251. TextureSwizzle swizzle_r = TEXTURE_SWIZZLE_R;
  252. TextureSwizzle swizzle_g = TEXTURE_SWIZZLE_G;
  253. TextureSwizzle swizzle_b = TEXTURE_SWIZZLE_B;
  254. TextureSwizzle swizzle_a = TEXTURE_SWIZZLE_A;
  255. bool operator==(const TextureView &p_other) const {
  256. if (format_override != p_other.format_override) {
  257. return false;
  258. } else if (swizzle_r != p_other.swizzle_r) {
  259. return false;
  260. } else if (swizzle_g != p_other.swizzle_g) {
  261. return false;
  262. } else if (swizzle_b != p_other.swizzle_b) {
  263. return false;
  264. } else if (swizzle_a != p_other.swizzle_a) {
  265. return false;
  266. } else {
  267. return true;
  268. }
  269. }
  270. };
  271. RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>());
  272. RID texture_create_shared(const TextureView &p_view, RID p_with_texture);
  273. RID texture_create_from_extension(TextureType p_type, DataFormat p_format, TextureSamples p_samples, BitField<RenderingDevice::TextureUsageBits> p_usage, uint64_t p_image, uint64_t p_width, uint64_t p_height, uint64_t p_depth, uint64_t p_layers);
  274. 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);
  275. Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data);
  276. Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer); // CPU textures will return immediately, while GPU textures will most likely force a flush
  277. bool texture_is_format_supported_for_usage(DataFormat p_format, BitField<TextureUsageBits> p_usage) const;
  278. bool texture_is_shared(RID p_texture);
  279. bool texture_is_valid(RID p_texture);
  280. TextureFormat texture_get_format(RID p_texture);
  281. Size2i texture_size(RID p_texture);
  282. #ifndef DISABLE_DEPRECATED
  283. uint64_t texture_get_native_handle(RID p_texture);
  284. #endif
  285. 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);
  286. 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);
  287. Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture);
  288. /************************/
  289. /**** DRAW LISTS (I) ****/
  290. /************************/
  291. enum InitialAction {
  292. INITIAL_ACTION_LOAD,
  293. INITIAL_ACTION_CLEAR,
  294. INITIAL_ACTION_DISCARD,
  295. INITIAL_ACTION_MAX,
  296. #ifndef DISABLE_DEPRECATED
  297. INITIAL_ACTION_CLEAR_REGION = INITIAL_ACTION_CLEAR,
  298. INITIAL_ACTION_CLEAR_REGION_CONTINUE = INITIAL_ACTION_CLEAR,
  299. INITIAL_ACTION_KEEP = INITIAL_ACTION_LOAD,
  300. INITIAL_ACTION_DROP = INITIAL_ACTION_DISCARD,
  301. INITIAL_ACTION_CONTINUE = INITIAL_ACTION_LOAD,
  302. #endif
  303. };
  304. enum FinalAction {
  305. FINAL_ACTION_STORE,
  306. FINAL_ACTION_DISCARD,
  307. FINAL_ACTION_MAX,
  308. #ifndef DISABLE_DEPRECATED
  309. FINAL_ACTION_READ = FINAL_ACTION_STORE,
  310. FINAL_ACTION_CONTINUE = FINAL_ACTION_STORE,
  311. #endif
  312. };
  313. /*********************/
  314. /**** FRAMEBUFFER ****/
  315. /*********************/
  316. // In modern APIs, generally, framebuffers work similar to how they
  317. // do in OpenGL, with the exception that
  318. // the "format" (RDD::RenderPassID) is not dynamic
  319. // and must be more or less the same as the one
  320. // used for the render pipelines.
  321. struct AttachmentFormat {
  322. enum { UNUSED_ATTACHMENT = 0xFFFFFFFF };
  323. DataFormat format;
  324. TextureSamples samples;
  325. uint32_t usage_flags;
  326. AttachmentFormat() {
  327. format = DATA_FORMAT_R8G8B8A8_UNORM;
  328. samples = TEXTURE_SAMPLES_1;
  329. usage_flags = 0;
  330. }
  331. };
  332. struct FramebufferPass {
  333. Vector<int32_t> color_attachments;
  334. Vector<int32_t> input_attachments;
  335. Vector<int32_t> resolve_attachments;
  336. Vector<int32_t> preserve_attachments;
  337. int32_t depth_attachment = ATTACHMENT_UNUSED;
  338. int32_t vrs_attachment = ATTACHMENT_UNUSED; // density map for VRS, only used if supported
  339. };
  340. typedef int64_t FramebufferFormatID;
  341. private:
  342. struct FramebufferFormatKey {
  343. Vector<AttachmentFormat> attachments;
  344. Vector<FramebufferPass> passes;
  345. uint32_t view_count = 1;
  346. bool operator<(const FramebufferFormatKey &p_key) const {
  347. if (view_count != p_key.view_count) {
  348. return view_count < p_key.view_count;
  349. }
  350. uint32_t pass_size = passes.size();
  351. uint32_t key_pass_size = p_key.passes.size();
  352. if (pass_size != key_pass_size) {
  353. return pass_size < key_pass_size;
  354. }
  355. const FramebufferPass *pass_ptr = passes.ptr();
  356. const FramebufferPass *key_pass_ptr = p_key.passes.ptr();
  357. for (uint32_t i = 0; i < pass_size; i++) {
  358. { // Compare color attachments.
  359. uint32_t attachment_size = pass_ptr[i].color_attachments.size();
  360. uint32_t key_attachment_size = key_pass_ptr[i].color_attachments.size();
  361. if (attachment_size != key_attachment_size) {
  362. return attachment_size < key_attachment_size;
  363. }
  364. const int32_t *pass_attachment_ptr = pass_ptr[i].color_attachments.ptr();
  365. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].color_attachments.ptr();
  366. for (uint32_t j = 0; j < attachment_size; j++) {
  367. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  368. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  369. }
  370. }
  371. }
  372. { // Compare input attachments.
  373. uint32_t attachment_size = pass_ptr[i].input_attachments.size();
  374. uint32_t key_attachment_size = key_pass_ptr[i].input_attachments.size();
  375. if (attachment_size != key_attachment_size) {
  376. return attachment_size < key_attachment_size;
  377. }
  378. const int32_t *pass_attachment_ptr = pass_ptr[i].input_attachments.ptr();
  379. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].input_attachments.ptr();
  380. for (uint32_t j = 0; j < attachment_size; j++) {
  381. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  382. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  383. }
  384. }
  385. }
  386. { // Compare resolve attachments.
  387. uint32_t attachment_size = pass_ptr[i].resolve_attachments.size();
  388. uint32_t key_attachment_size = key_pass_ptr[i].resolve_attachments.size();
  389. if (attachment_size != key_attachment_size) {
  390. return attachment_size < key_attachment_size;
  391. }
  392. const int32_t *pass_attachment_ptr = pass_ptr[i].resolve_attachments.ptr();
  393. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].resolve_attachments.ptr();
  394. for (uint32_t j = 0; j < attachment_size; j++) {
  395. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  396. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  397. }
  398. }
  399. }
  400. { // Compare preserve attachments.
  401. uint32_t attachment_size = pass_ptr[i].preserve_attachments.size();
  402. uint32_t key_attachment_size = key_pass_ptr[i].preserve_attachments.size();
  403. if (attachment_size != key_attachment_size) {
  404. return attachment_size < key_attachment_size;
  405. }
  406. const int32_t *pass_attachment_ptr = pass_ptr[i].preserve_attachments.ptr();
  407. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].preserve_attachments.ptr();
  408. for (uint32_t j = 0; j < attachment_size; j++) {
  409. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  410. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  411. }
  412. }
  413. }
  414. if (pass_ptr[i].depth_attachment != key_pass_ptr[i].depth_attachment) {
  415. return pass_ptr[i].depth_attachment < key_pass_ptr[i].depth_attachment;
  416. }
  417. }
  418. int as = attachments.size();
  419. int bs = p_key.attachments.size();
  420. if (as != bs) {
  421. return as < bs;
  422. }
  423. const AttachmentFormat *af_a = attachments.ptr();
  424. const AttachmentFormat *af_b = p_key.attachments.ptr();
  425. for (int i = 0; i < as; i++) {
  426. const AttachmentFormat &a = af_a[i];
  427. const AttachmentFormat &b = af_b[i];
  428. if (a.format != b.format) {
  429. return a.format < b.format;
  430. }
  431. if (a.samples != b.samples) {
  432. return a.samples < b.samples;
  433. }
  434. if (a.usage_flags != b.usage_flags) {
  435. return a.usage_flags < b.usage_flags;
  436. }
  437. }
  438. return false; // Equal.
  439. }
  440. };
  441. RDD::RenderPassID _render_pass_create(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, uint32_t p_view_count = 1, Vector<TextureSamples> *r_samples = nullptr);
  442. // This is a cache and it's never freed, it ensures
  443. // IDs for a given format are always unique.
  444. RBMap<FramebufferFormatKey, FramebufferFormatID> framebuffer_format_cache;
  445. struct FramebufferFormat {
  446. const RBMap<FramebufferFormatKey, FramebufferFormatID>::Element *E;
  447. RDD::RenderPassID render_pass; // Here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec).
  448. Vector<TextureSamples> pass_samples;
  449. uint32_t view_count = 1; // Number of views.
  450. };
  451. HashMap<FramebufferFormatID, FramebufferFormat> framebuffer_formats;
  452. struct Framebuffer {
  453. FramebufferFormatID format_id;
  454. struct VersionKey {
  455. InitialAction initial_color_action;
  456. FinalAction final_color_action;
  457. InitialAction initial_depth_action;
  458. FinalAction final_depth_action;
  459. uint32_t view_count;
  460. bool operator<(const VersionKey &p_key) const {
  461. if (initial_color_action == p_key.initial_color_action) {
  462. if (final_color_action == p_key.final_color_action) {
  463. if (initial_depth_action == p_key.initial_depth_action) {
  464. if (final_depth_action == p_key.final_depth_action) {
  465. return view_count < p_key.view_count;
  466. } else {
  467. return final_depth_action < p_key.final_depth_action;
  468. }
  469. } else {
  470. return initial_depth_action < p_key.initial_depth_action;
  471. }
  472. } else {
  473. return final_color_action < p_key.final_color_action;
  474. }
  475. } else {
  476. return initial_color_action < p_key.initial_color_action;
  477. }
  478. }
  479. };
  480. uint32_t storage_mask = 0;
  481. Vector<RID> texture_ids;
  482. InvalidationCallback invalidated_callback = nullptr;
  483. void *invalidated_callback_userdata = nullptr;
  484. struct Version {
  485. RDD::FramebufferID framebuffer;
  486. RDD::RenderPassID render_pass; // This one is owned.
  487. uint32_t subpass_count = 1;
  488. };
  489. RBMap<VersionKey, Version> framebuffers;
  490. Size2 size;
  491. uint32_t view_count;
  492. };
  493. RID_Owner<Framebuffer> framebuffer_owner;
  494. public:
  495. // This ID is warranted to be unique for the same formats, does not need to be freed
  496. FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1);
  497. FramebufferFormatID framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, uint32_t p_view_count = 1);
  498. FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1);
  499. TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0);
  500. RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  501. 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);
  502. RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID);
  503. bool framebuffer_is_valid(RID p_framebuffer) const;
  504. void framebuffer_set_invalidation_callback(RID p_framebuffer, InvalidationCallback p_callback, void *p_userdata);
  505. FramebufferFormatID framebuffer_get_format(RID p_framebuffer);
  506. /*****************/
  507. /**** SAMPLER ****/
  508. /*****************/
  509. private:
  510. RID_Owner<RDD::SamplerID> sampler_owner;
  511. public:
  512. RID sampler_create(const SamplerState &p_state);
  513. bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_sampler_filter) const;
  514. /**********************/
  515. /**** VERTEX ARRAY ****/
  516. /**********************/
  517. typedef int64_t VertexFormatID;
  518. private:
  519. // Vertex buffers in Vulkan are similar to how
  520. // they work in OpenGL, except that instead of
  521. // an attribute index, there is a buffer binding
  522. // index (for binding the buffers in real-time)
  523. // and a location index (what is used in the shader).
  524. //
  525. // This mapping is done here internally, and it's not
  526. // exposed.
  527. RID_Owner<Buffer> vertex_buffer_owner;
  528. struct VertexDescriptionKey {
  529. Vector<VertexAttribute> vertex_formats;
  530. bool operator==(const VertexDescriptionKey &p_key) const {
  531. int vdc = vertex_formats.size();
  532. int vdck = p_key.vertex_formats.size();
  533. if (vdc != vdck) {
  534. return false;
  535. } else {
  536. const VertexAttribute *a_ptr = vertex_formats.ptr();
  537. const VertexAttribute *b_ptr = p_key.vertex_formats.ptr();
  538. for (int i = 0; i < vdc; i++) {
  539. const VertexAttribute &a = a_ptr[i];
  540. const VertexAttribute &b = b_ptr[i];
  541. if (a.location != b.location) {
  542. return false;
  543. }
  544. if (a.offset != b.offset) {
  545. return false;
  546. }
  547. if (a.format != b.format) {
  548. return false;
  549. }
  550. if (a.stride != b.stride) {
  551. return false;
  552. }
  553. if (a.frequency != b.frequency) {
  554. return false;
  555. }
  556. }
  557. return true; // They are equal.
  558. }
  559. }
  560. uint32_t hash() const {
  561. int vdc = vertex_formats.size();
  562. uint32_t h = hash_murmur3_one_32(vdc);
  563. const VertexAttribute *ptr = vertex_formats.ptr();
  564. for (int i = 0; i < vdc; i++) {
  565. const VertexAttribute &vd = ptr[i];
  566. h = hash_murmur3_one_32(vd.location, h);
  567. h = hash_murmur3_one_32(vd.offset, h);
  568. h = hash_murmur3_one_32(vd.format, h);
  569. h = hash_murmur3_one_32(vd.stride, h);
  570. h = hash_murmur3_one_32(vd.frequency, h);
  571. }
  572. return hash_fmix32(h);
  573. }
  574. };
  575. struct VertexDescriptionHash {
  576. static _FORCE_INLINE_ uint32_t hash(const VertexDescriptionKey &p_key) {
  577. return p_key.hash();
  578. }
  579. };
  580. // This is a cache and it's never freed, it ensures that
  581. // ID used for a specific format always remain the same.
  582. HashMap<VertexDescriptionKey, VertexFormatID, VertexDescriptionHash> vertex_format_cache;
  583. struct VertexDescriptionCache {
  584. Vector<VertexAttribute> vertex_formats;
  585. RDD::VertexFormatID driver_id;
  586. };
  587. HashMap<VertexFormatID, VertexDescriptionCache> vertex_formats;
  588. struct VertexArray {
  589. RID buffer;
  590. VertexFormatID description;
  591. int vertex_count = 0;
  592. uint32_t max_instances_allowed = 0;
  593. Vector<RDD::BufferID> buffers; // Not owned, just referenced.
  594. Vector<RDG::ResourceTracker *> draw_trackers; // Not owned, just referenced.
  595. Vector<uint64_t> offsets;
  596. HashSet<RID> untracked_buffers;
  597. };
  598. RID_Owner<VertexArray> vertex_array_owner;
  599. struct IndexBuffer : public Buffer {
  600. uint32_t max_index = 0; // Used for validation.
  601. uint32_t index_count = 0;
  602. IndexBufferFormat format = INDEX_BUFFER_FORMAT_UINT16;
  603. bool supports_restart_indices = false;
  604. };
  605. RID_Owner<IndexBuffer> index_buffer_owner;
  606. struct IndexArray {
  607. uint32_t max_index = 0; // Remember the maximum index here too, for validation.
  608. RDD::BufferID driver_id; // Not owned, inherited from index buffer.
  609. RDG::ResourceTracker *draw_tracker = nullptr; // Not owned, inherited from index buffer.
  610. uint32_t offset = 0;
  611. uint32_t indices = 0;
  612. IndexBufferFormat format = INDEX_BUFFER_FORMAT_UINT16;
  613. bool supports_restart_indices = false;
  614. };
  615. RID_Owner<IndexArray> index_array_owner;
  616. public:
  617. RID vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_as_storage = false);
  618. // This ID is warranted to be unique for the same formats, does not need to be freed
  619. VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_descriptions);
  620. 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>());
  621. 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);
  622. RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count);
  623. /****************/
  624. /**** SHADER ****/
  625. /****************/
  626. // Some APIs (e.g., Vulkan) specifies a really complex behavior for the application
  627. // in order to tell when descriptor sets need to be re-bound (or not).
  628. // "When binding a descriptor set (see Descriptor Set Binding) to set
  629. // number N, if the previously bound descriptor sets for sets zero
  630. // through N-1 were all bound using compatible pipeline layouts,
  631. // then performing this binding does not disturb any of the lower numbered sets.
  632. // If, additionally, the previous bound descriptor set for set N was
  633. // bound using a pipeline layout compatible for set N, then the bindings
  634. // in sets numbered greater than N are also not disturbed."
  635. // As a result, we need to figure out quickly when something is no longer "compatible".
  636. // in order to avoid costly rebinds.
  637. private:
  638. struct UniformSetFormat {
  639. Vector<ShaderUniform> uniforms;
  640. _FORCE_INLINE_ bool operator<(const UniformSetFormat &p_other) const {
  641. if (uniforms.size() != p_other.uniforms.size()) {
  642. return uniforms.size() < p_other.uniforms.size();
  643. }
  644. for (int i = 0; i < uniforms.size(); i++) {
  645. if (uniforms[i] < p_other.uniforms[i]) {
  646. return true;
  647. } else if (p_other.uniforms[i] < uniforms[i]) {
  648. return false;
  649. }
  650. }
  651. return false;
  652. }
  653. };
  654. // Always grows, never shrinks, ensuring unique IDs, but we assume
  655. // the amount of formats will never be a problem, as the amount of shaders
  656. // in a game is limited.
  657. RBMap<UniformSetFormat, uint32_t> uniform_set_format_cache;
  658. // Shaders in Vulkan are just pretty much
  659. // precompiled blocks of SPIR-V bytecode. They
  660. // are most likely not really compiled to host
  661. // assembly until a pipeline is created.
  662. //
  663. // When supplying the shaders, this implementation
  664. // will use the reflection abilities of glslang to
  665. // understand and cache everything required to
  666. // create and use the descriptor sets (Vulkan's
  667. // biggest pain).
  668. //
  669. // Additionally, hashes are created for every set
  670. // to do quick validation and ensuring the user
  671. // does not submit something invalid.
  672. struct Shader : public ShaderDescription {
  673. String name; // Used for debug.
  674. RDD::ShaderID driver_id;
  675. uint32_t layout_hash = 0;
  676. BitField<RDD::PipelineStageBits> stage_bits;
  677. Vector<uint32_t> set_formats;
  678. };
  679. String _shader_uniform_debug(RID p_shader, int p_set = -1);
  680. RID_Owner<Shader> shader_owner;
  681. #ifndef DISABLE_DEPRECATED
  682. public:
  683. enum BarrierMask{
  684. BARRIER_MASK_VERTEX = 1,
  685. BARRIER_MASK_FRAGMENT = 8,
  686. BARRIER_MASK_COMPUTE = 2,
  687. BARRIER_MASK_TRANSFER = 4,
  688. BARRIER_MASK_RASTER = BARRIER_MASK_VERTEX | BARRIER_MASK_FRAGMENT, // 9,
  689. BARRIER_MASK_ALL_BARRIERS = 0x7FFF, // all flags set
  690. BARRIER_MASK_NO_BARRIER = 0x8000,
  691. };
  692. void barrier(BitField<BarrierMask> p_from = BARRIER_MASK_ALL_BARRIERS, BitField<BarrierMask> p_to = BARRIER_MASK_ALL_BARRIERS);
  693. void full_barrier();
  694. void draw_command_insert_label(String p_label_name, const Color &p_color = Color(1, 1, 1, 1));
  695. 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>());
  696. Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids);
  697. 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>());
  698. Vector<int64_t> _draw_list_switch_to_next_pass_split(uint32_t p_splits);
  699. private:
  700. void _draw_list_end_bind_compat_81356(BitField<BarrierMask> p_post_barrier);
  701. void _compute_list_end_bind_compat_81356(BitField<BarrierMask> p_post_barrier);
  702. void _barrier_bind_compat_81356(BitField<BarrierMask> p_from, BitField<BarrierMask> p_to);
  703. void _draw_list_end_bind_compat_84976(BitField<BarrierMask> p_post_barrier);
  704. void _compute_list_end_bind_compat_84976(BitField<BarrierMask> p_post_barrier);
  705. InitialAction _convert_initial_action_84976(InitialAction p_old_initial_action);
  706. FinalAction _convert_final_action_84976(FinalAction p_old_final_action);
  707. DrawListID _draw_list_begin_bind_compat_84976(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, float p_clear_depth, uint32_t p_clear_stencil, const Rect2 &p_region, const TypedArray<RID> &p_storage_textures);
  708. ComputeListID _compute_list_begin_bind_compat_84976(bool p_allow_draw_overlap);
  709. Error _buffer_update_bind_compat_84976(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier);
  710. Error _buffer_clear_bind_compat_84976(RID p_buffer, uint32_t p_offset, uint32_t p_size, BitField<BarrierMask> p_post_barrier);
  711. Error _texture_update_bind_compat_84976(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier);
  712. Error _texture_copy_bind_compat_84976(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);
  713. Error _texture_clear_bind_compat_84976(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);
  714. Error _texture_resolve_multisample_bind_compat_84976(RID p_from_texture, RID p_to_texture, BitField<BarrierMask> p_post_barrier);
  715. FramebufferFormatID _screen_get_framebuffer_format_bind_compat_87340() const;
  716. #endif
  717. public:
  718. RenderingContextDriver *get_context_driver() const { return context; }
  719. const RDD::Capabilities &get_device_capabilities() const { return driver->get_capabilities(); }
  720. bool has_feature(const Features p_feature) const;
  721. 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);
  722. String shader_get_spirv_cache_key() const;
  723. static void shader_set_compile_to_spirv_function(ShaderCompileToSPIRVFunction p_function);
  724. static void shader_set_spirv_cache_function(ShaderCacheFunction p_function);
  725. static void shader_set_get_cache_key_function(ShaderSPIRVGetCacheKeyFunction p_function);
  726. String shader_get_binary_cache_key() const;
  727. Vector<uint8_t> shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");
  728. RID shader_create_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");
  729. RID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary, RID p_placeholder = RID());
  730. RID shader_create_placeholder();
  731. uint64_t shader_get_vertex_input_attribute_mask(RID p_shader);
  732. /******************/
  733. /**** UNIFORMS ****/
  734. /******************/
  735. enum StorageBufferUsage {
  736. STORAGE_BUFFER_USAGE_DISPATCH_INDIRECT = 1,
  737. };
  738. RID uniform_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>());
  739. RID storage_buffer_create(uint32_t p_size, const Vector<uint8_t> &p_data = Vector<uint8_t>(), BitField<StorageBufferUsage> p_usage = 0);
  740. RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>());
  741. struct Uniform {
  742. UniformType uniform_type = UNIFORM_TYPE_IMAGE;
  743. uint32_t binding = 0; // Binding index as specified in shader.
  744. private:
  745. // In most cases only one ID is provided per binding, so avoid allocating memory unnecessarily for performance.
  746. RID id; // If only one is provided, this is used.
  747. Vector<RID> ids; // If multiple ones are provided, this is used instead.
  748. public:
  749. _FORCE_INLINE_ uint32_t get_id_count() const {
  750. return (id.is_valid() ? 1 : ids.size());
  751. }
  752. _FORCE_INLINE_ RID get_id(uint32_t p_idx) const {
  753. if (id.is_valid()) {
  754. ERR_FAIL_COND_V(p_idx != 0, RID());
  755. return id;
  756. } else {
  757. return ids[p_idx];
  758. }
  759. }
  760. _FORCE_INLINE_ void set_id(uint32_t p_idx, RID p_id) {
  761. if (id.is_valid()) {
  762. ERR_FAIL_COND(p_idx != 0);
  763. id = p_id;
  764. } else {
  765. ids.write[p_idx] = p_id;
  766. }
  767. }
  768. _FORCE_INLINE_ void append_id(RID p_id) {
  769. if (ids.is_empty()) {
  770. if (id == RID()) {
  771. id = p_id;
  772. } else {
  773. ids.push_back(id);
  774. ids.push_back(p_id);
  775. id = RID();
  776. }
  777. } else {
  778. ids.push_back(p_id);
  779. }
  780. }
  781. _FORCE_INLINE_ void clear_ids() {
  782. id = RID();
  783. ids.clear();
  784. }
  785. _FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, RID p_id) {
  786. uniform_type = p_type;
  787. binding = p_binding;
  788. id = p_id;
  789. }
  790. _FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, const Vector<RID> &p_ids) {
  791. uniform_type = p_type;
  792. binding = p_binding;
  793. ids = p_ids;
  794. }
  795. _FORCE_INLINE_ Uniform() = default;
  796. };
  797. private:
  798. static const uint32_t MAX_UNIFORM_SETS = 16;
  799. static const uint32_t MAX_PUSH_CONSTANT_SIZE = 128;
  800. // This structure contains the descriptor set. They _need_ to be allocated
  801. // for a shader (and will be erased when this shader is erased), but should
  802. // work for other shaders as long as the hash matches. This covers using
  803. // them in shader variants.
  804. //
  805. // Keep also in mind that you can share buffers between descriptor sets, so
  806. // the above restriction is not too serious.
  807. struct UniformSet {
  808. uint32_t format = 0;
  809. RID shader_id;
  810. uint32_t shader_set = 0;
  811. RDD::UniformSetID driver_id;
  812. struct AttachableTexture {
  813. uint32_t bind = 0;
  814. RID texture;
  815. };
  816. struct SharedTexture {
  817. uint32_t writing = 0;
  818. RID texture;
  819. };
  820. LocalVector<AttachableTexture> attachable_textures; // Used for validation.
  821. Vector<RDG::ResourceTracker *> draw_trackers;
  822. Vector<RDG::ResourceUsage> draw_trackers_usage;
  823. HashMap<RID, RDG::ResourceUsage> untracked_usage;
  824. LocalVector<SharedTexture> shared_textures_to_update;
  825. InvalidationCallback invalidated_callback = nullptr;
  826. void *invalidated_callback_userdata = nullptr;
  827. };
  828. RID_Owner<UniformSet> uniform_set_owner;
  829. void _uniform_set_update_shared(UniformSet *p_uniform_set);
  830. public:
  831. RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
  832. bool uniform_set_is_valid(RID p_uniform_set);
  833. void uniform_set_set_invalidation_callback(RID p_uniform_set, InvalidationCallback p_callback, void *p_userdata);
  834. /*******************/
  835. /**** PIPELINES ****/
  836. /*******************/
  837. // Render pipeline contains ALL the
  838. // information required for drawing.
  839. // This includes all the rasterizer state
  840. // as well as shader used, framebuffer format,
  841. // etc.
  842. // While the pipeline is just a single object
  843. // (VkPipeline) a lot of values are also saved
  844. // here to do validation (vulkan does none by
  845. // default) and warn the user if something
  846. // was not supplied as intended.
  847. private:
  848. struct RenderPipeline {
  849. // Cached values for validation.
  850. #ifdef DEBUG_ENABLED
  851. struct Validation {
  852. FramebufferFormatID framebuffer_format;
  853. uint32_t render_pass = 0;
  854. uint32_t dynamic_state = 0;
  855. VertexFormatID vertex_format;
  856. bool uses_restart_indices = false;
  857. uint32_t primitive_minimum = 0;
  858. uint32_t primitive_divisor = 0;
  859. } validation;
  860. #endif
  861. // Actual pipeline.
  862. RID shader;
  863. RDD::ShaderID shader_driver_id;
  864. uint32_t shader_layout_hash = 0;
  865. Vector<uint32_t> set_formats;
  866. RDD::PipelineID driver_id;
  867. BitField<RDD::PipelineStageBits> stage_bits;
  868. uint32_t push_constant_size = 0;
  869. };
  870. RID_Owner<RenderPipeline> render_pipeline_owner;
  871. bool pipeline_cache_enabled = false;
  872. size_t pipeline_cache_size = 0;
  873. String pipeline_cache_file_path;
  874. WorkerThreadPool::TaskID pipeline_cache_save_task = WorkerThreadPool::INVALID_TASK_ID;
  875. Vector<uint8_t> _load_pipeline_cache();
  876. void _update_pipeline_cache(bool p_closing = false);
  877. static void _save_pipeline_cache(void *p_data);
  878. struct ComputePipeline {
  879. RID shader;
  880. RDD::ShaderID shader_driver_id;
  881. uint32_t shader_layout_hash = 0;
  882. Vector<uint32_t> set_formats;
  883. RDD::PipelineID driver_id;
  884. uint32_t push_constant_size = 0;
  885. uint32_t local_group_size[3] = { 0, 0, 0 };
  886. };
  887. RID_Owner<ComputePipeline> compute_pipeline_owner;
  888. public:
  889. 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>());
  890. bool render_pipeline_is_valid(RID p_pipeline);
  891. RID compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>());
  892. bool compute_pipeline_is_valid(RID p_pipeline);
  893. private:
  894. /****************/
  895. /**** SCREEN ****/
  896. /****************/
  897. HashMap<DisplayServer::WindowID, RDD::SwapChainID> screen_swap_chains;
  898. HashMap<DisplayServer::WindowID, RDD::FramebufferID> screen_framebuffers;
  899. uint32_t _get_swap_chain_desired_count() const;
  900. public:
  901. Error screen_create(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
  902. Error screen_prepare_for_drawing(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
  903. int screen_get_width(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  904. int screen_get_height(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  905. FramebufferFormatID screen_get_framebuffer_format(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  906. Error screen_free(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
  907. /*************************/
  908. /**** DRAW LISTS (II) ****/
  909. /*************************/
  910. private:
  911. // Draw list contains both the command buffer
  912. // used for drawing as well as a LOT of
  913. // information used for validation. This
  914. // validation is cheap so most of it can
  915. // also run in release builds.
  916. struct DrawList {
  917. Rect2i viewport;
  918. bool viewport_set = false;
  919. struct SetState {
  920. uint32_t pipeline_expected_format = 0;
  921. uint32_t uniform_set_format = 0;
  922. RDD::UniformSetID uniform_set_driver_id;
  923. RID uniform_set;
  924. bool bound = false;
  925. };
  926. struct State {
  927. SetState sets[MAX_UNIFORM_SETS];
  928. uint32_t set_count = 0;
  929. RID pipeline;
  930. RID pipeline_shader;
  931. RDD::ShaderID pipeline_shader_driver_id;
  932. uint32_t pipeline_shader_layout_hash = 0;
  933. RID vertex_array;
  934. RID index_array;
  935. uint32_t draw_count = 0;
  936. } state;
  937. #ifdef DEBUG_ENABLED
  938. struct Validation {
  939. bool active = true; // Means command buffer was not closed, so you can keep adding things.
  940. // Actual render pass values.
  941. uint32_t dynamic_state = 0;
  942. VertexFormatID vertex_format = INVALID_ID;
  943. uint32_t vertex_array_size = 0;
  944. uint32_t vertex_max_instances_allowed = 0xFFFFFFFF;
  945. bool index_buffer_uses_restart_indices = false;
  946. uint32_t index_array_count = 0;
  947. uint32_t index_array_max_index = 0;
  948. Vector<uint32_t> set_formats;
  949. Vector<bool> set_bound;
  950. Vector<RID> set_rids;
  951. // Last pipeline set values.
  952. bool pipeline_active = false;
  953. uint32_t pipeline_dynamic_state = 0;
  954. VertexFormatID pipeline_vertex_format = INVALID_ID;
  955. RID pipeline_shader;
  956. bool pipeline_uses_restart_indices = false;
  957. uint32_t pipeline_primitive_divisor = 0;
  958. uint32_t pipeline_primitive_minimum = 0;
  959. uint32_t pipeline_push_constant_size = 0;
  960. bool pipeline_push_constant_supplied = false;
  961. } validation;
  962. #else
  963. struct Validation {
  964. uint32_t vertex_array_size = 0;
  965. uint32_t index_array_count = 0;
  966. } validation;
  967. #endif
  968. };
  969. DrawList *draw_list = nullptr;
  970. uint32_t draw_list_subpass_count = 0;
  971. RDD::RenderPassID draw_list_render_pass;
  972. RDD::FramebufferID draw_list_vkframebuffer;
  973. #ifdef DEBUG_ENABLED
  974. FramebufferFormatID draw_list_framebuffer_format = INVALID_ID;
  975. #endif
  976. uint32_t draw_list_current_subpass = 0;
  977. Vector<RID> draw_list_bound_textures;
  978. void _draw_list_insert_clear_region(DrawList *p_draw_list, Framebuffer *p_framebuffer, Point2i p_viewport_offset, Point2i p_viewport_size, bool p_clear_color, const Vector<Color> &p_clear_colors, bool p_clear_depth, float p_depth, uint32_t p_stencil);
  979. Error _draw_list_setup_framebuffer(Framebuffer *p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, RDD::FramebufferID *r_framebuffer, RDD::RenderPassID *r_render_pass, uint32_t *r_subpass_count);
  980. Error _draw_list_render_pass_begin(Framebuffer *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_colors, float p_clear_depth, uint32_t p_clear_stencil, Point2i p_viewport_offset, Point2i p_viewport_size, RDD::FramebufferID p_framebuffer_driver_id, RDD::RenderPassID p_render_pass);
  981. void _draw_list_set_viewport(Rect2i p_rect);
  982. void _draw_list_set_scissor(Rect2i p_rect);
  983. _FORCE_INLINE_ DrawList *_get_draw_list_ptr(DrawListID p_id);
  984. Error _draw_list_allocate(const Rect2i &p_viewport, uint32_t p_subpass);
  985. void _draw_list_free(Rect2i *r_last_viewport = nullptr);
  986. public:
  987. DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());
  988. 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());
  989. void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color);
  990. void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline);
  991. void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index);
  992. void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array);
  993. void draw_list_bind_index_array(DrawListID p_list, RID p_index_array);
  994. void draw_list_set_line_width(DrawListID p_list, float p_width);
  995. void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size);
  996. void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0);
  997. void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect);
  998. void draw_list_disable_scissor(DrawListID p_list);
  999. uint32_t draw_list_get_current_pass();
  1000. DrawListID draw_list_switch_to_next_pass();
  1001. void draw_list_end();
  1002. private:
  1003. /***********************/
  1004. /**** COMPUTE LISTS ****/
  1005. /***********************/
  1006. struct ComputeList {
  1007. struct SetState {
  1008. uint32_t pipeline_expected_format = 0;
  1009. uint32_t uniform_set_format = 0;
  1010. RDD::UniformSetID uniform_set_driver_id;
  1011. RID uniform_set;
  1012. bool bound = false;
  1013. };
  1014. struct State {
  1015. SetState sets[MAX_UNIFORM_SETS];
  1016. uint32_t set_count = 0;
  1017. RID pipeline;
  1018. RID pipeline_shader;
  1019. RDD::ShaderID pipeline_shader_driver_id;
  1020. uint32_t pipeline_shader_layout_hash = 0;
  1021. uint32_t local_group_size[3] = { 0, 0, 0 };
  1022. uint8_t push_constant_data[MAX_PUSH_CONSTANT_SIZE] = {};
  1023. uint32_t push_constant_size = 0;
  1024. uint32_t dispatch_count = 0;
  1025. } state;
  1026. #ifdef DEBUG_ENABLED
  1027. struct Validation {
  1028. bool active = true; // Means command buffer was not closed, so you can keep adding things.
  1029. Vector<uint32_t> set_formats;
  1030. Vector<bool> set_bound;
  1031. Vector<RID> set_rids;
  1032. // Last pipeline set values.
  1033. bool pipeline_active = false;
  1034. RID pipeline_shader;
  1035. uint32_t invalid_set_from = 0;
  1036. uint32_t pipeline_push_constant_size = 0;
  1037. bool pipeline_push_constant_supplied = false;
  1038. } validation;
  1039. #endif
  1040. };
  1041. ComputeList *compute_list = nullptr;
  1042. ComputeList::State compute_list_barrier_state;
  1043. public:
  1044. ComputeListID compute_list_begin();
  1045. void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline);
  1046. void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index);
  1047. void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size);
  1048. void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups);
  1049. void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads);
  1050. void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset);
  1051. void compute_list_add_barrier(ComputeListID p_list);
  1052. void compute_list_end();
  1053. private:
  1054. /***********************/
  1055. /**** COMMAND GRAPH ****/
  1056. /***********************/
  1057. bool _texture_make_mutable(Texture *p_texture, RID p_texture_id);
  1058. bool _buffer_make_mutable(Buffer *p_buffer, RID p_buffer_id);
  1059. bool _vertex_array_make_mutable(VertexArray *p_vertex_array, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);
  1060. bool _index_array_make_mutable(IndexArray *p_index_array, RDG::ResourceTracker *p_resource_tracker);
  1061. bool _uniform_set_make_mutable(UniformSet *p_uniform_set, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);
  1062. bool _dependency_make_mutable(RID p_id, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);
  1063. bool _dependencies_make_mutable(RID p_id, RDG::ResourceTracker *p_resource_tracker);
  1064. RenderingDeviceGraph draw_graph;
  1065. /**************************/
  1066. /**** QUEUE MANAGEMENT ****/
  1067. /**************************/
  1068. RDD::CommandQueueFamilyID main_queue_family;
  1069. RDD::CommandQueueFamilyID present_queue_family;
  1070. RDD::CommandQueueID main_queue;
  1071. RDD::CommandQueueID present_queue;
  1072. /**************************/
  1073. /**** FRAME MANAGEMENT ****/
  1074. /**************************/
  1075. // This is the frame structure. There are normally
  1076. // 3 of these (used for triple buffering), or 2
  1077. // (double buffering). They are cycled constantly.
  1078. //
  1079. // It contains two command buffers, one that is
  1080. // used internally for setting up (creating stuff)
  1081. // and another used mostly for drawing.
  1082. //
  1083. // They also contains a list of things that need
  1084. // to be disposed of when deleted, which can't
  1085. // happen immediately due to the asynchronous
  1086. // nature of the GPU. They will get deleted
  1087. // when the frame is cycled.
  1088. struct Frame {
  1089. // List in usage order, from last to free to first to free.
  1090. List<Buffer> buffers_to_dispose_of;
  1091. List<Texture> textures_to_dispose_of;
  1092. List<Framebuffer> framebuffers_to_dispose_of;
  1093. List<RDD::SamplerID> samplers_to_dispose_of;
  1094. List<Shader> shaders_to_dispose_of;
  1095. List<UniformSet> uniform_sets_to_dispose_of;
  1096. List<RenderPipeline> render_pipelines_to_dispose_of;
  1097. List<ComputePipeline> compute_pipelines_to_dispose_of;
  1098. RDD::CommandPoolID command_pool;
  1099. // Used at the beginning of every frame for set-up.
  1100. // Used for filling up newly created buffers with data provided on creation.
  1101. // Primarily intended to be accessed by worker threads.
  1102. // Ideally this command buffer should use an async transfer queue.
  1103. RDD::CommandBufferID setup_command_buffer;
  1104. // The main command buffer for drawing and compute.
  1105. // Primarily intended to be used by the main thread to do most stuff.
  1106. RDD::CommandBufferID draw_command_buffer;
  1107. // Signaled by the setup submission. Draw must wait on this semaphore.
  1108. RDD::SemaphoreID setup_semaphore;
  1109. // Signaled by the draw submission. Present must wait on this semaphore.
  1110. RDD::SemaphoreID draw_semaphore;
  1111. // Signaled by the draw submission. Must wait on this fence before beginning
  1112. // command recording for the frame.
  1113. RDD::FenceID draw_fence;
  1114. bool draw_fence_signaled = false;
  1115. // Swap chains prepared for drawing during the frame that must be presented.
  1116. LocalVector<RDD::SwapChainID> swap_chains_to_present;
  1117. // Extra command buffer pool used for driver workarounds.
  1118. RDG::CommandBufferPool command_buffer_pool;
  1119. struct Timestamp {
  1120. String description;
  1121. uint64_t value = 0;
  1122. };
  1123. RDD::QueryPoolID timestamp_pool;
  1124. TightLocalVector<String> timestamp_names;
  1125. TightLocalVector<uint64_t> timestamp_cpu_values;
  1126. uint32_t timestamp_count = 0;
  1127. TightLocalVector<String> timestamp_result_names;
  1128. TightLocalVector<uint64_t> timestamp_cpu_result_values;
  1129. TightLocalVector<uint64_t> timestamp_result_values;
  1130. uint32_t timestamp_result_count = 0;
  1131. uint64_t index = 0;
  1132. };
  1133. uint32_t max_timestamp_query_elements = 0;
  1134. int frame = 0;
  1135. TightLocalVector<Frame> frames;
  1136. uint64_t frames_drawn = 0;
  1137. void _free_pending_resources(int p_frame);
  1138. uint64_t texture_memory = 0;
  1139. uint64_t buffer_memory = 0;
  1140. void _free_internal(RID p_id);
  1141. void _begin_frame();
  1142. void _end_frame();
  1143. void _execute_frame(bool p_present);
  1144. void _stall_for_previous_frames();
  1145. void _flush_and_stall_for_all_frames();
  1146. template <typename T>
  1147. void _free_rids(T &p_owner, const char *p_type);
  1148. #ifdef DEV_ENABLED
  1149. HashMap<RID, String> resource_names;
  1150. #endif
  1151. public:
  1152. Error initialize(RenderingContextDriver *p_context, DisplayServer::WindowID p_main_window = DisplayServer::INVALID_WINDOW_ID);
  1153. void finalize();
  1154. void free(RID p_id);
  1155. /****************/
  1156. /**** Timing ****/
  1157. /****************/
  1158. void capture_timestamp(const String &p_name);
  1159. uint32_t get_captured_timestamps_count() const;
  1160. uint64_t get_captured_timestamps_frame() const;
  1161. uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const;
  1162. uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;
  1163. String get_captured_timestamp_name(uint32_t p_index) const;
  1164. /****************/
  1165. /**** LIMITS ****/
  1166. /****************/
  1167. uint64_t limit_get(Limit p_limit) const;
  1168. void swap_buffers();
  1169. uint32_t get_frame_delay() const;
  1170. void submit();
  1171. void sync();
  1172. enum MemoryType {
  1173. MEMORY_TEXTURES,
  1174. MEMORY_BUFFERS,
  1175. MEMORY_TOTAL
  1176. };
  1177. uint64_t get_memory_usage(MemoryType p_type) const;
  1178. RenderingDevice *create_local_device();
  1179. void set_resource_name(RID p_id, const String &p_name);
  1180. void draw_command_begin_label(String p_label_name, const Color &p_color = Color(1, 1, 1, 1));
  1181. void draw_command_end_label();
  1182. String get_device_vendor_name() const;
  1183. String get_device_name() const;
  1184. DeviceType get_device_type() const;
  1185. String get_device_api_name() const;
  1186. String get_device_api_version() const;
  1187. String get_device_pipeline_cache_uuid() const;
  1188. bool is_composite_alpha_supported() const;
  1189. uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0);
  1190. static RenderingDevice *get_singleton();
  1191. RenderingDevice();
  1192. ~RenderingDevice();
  1193. private:
  1194. /*****************/
  1195. /**** BINDERS ****/
  1196. /*****************/
  1197. RID _texture_create(const Ref<RDTextureFormat> &p_format, const Ref<RDTextureView> &p_view, const TypedArray<PackedByteArray> &p_data = Array());
  1198. RID _texture_create_shared(const Ref<RDTextureView> &p_view, RID p_with_texture);
  1199. 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);
  1200. Ref<RDTextureFormat> _texture_get_format(RID p_rd_texture);
  1201. FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments, uint32_t p_view_count);
  1202. FramebufferFormatID _framebuffer_format_create_multipass(const TypedArray<RDAttachmentFormat> &p_attachments, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_view_count);
  1203. RID _framebuffer_create(const TypedArray<RID> &p_textures, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  1204. 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);
  1205. RID _sampler_create(const Ref<RDSamplerState> &p_state);
  1206. VertexFormatID _vertex_format_create(const TypedArray<RDVertexAttribute> &p_vertex_formats);
  1207. 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>());
  1208. Ref<RDShaderSPIRV> _shader_compile_spirv_from_source(const Ref<RDShaderSource> &p_source, bool p_allow_cache = true);
  1209. Vector<uint8_t> _shader_compile_binary_from_spirv(const Ref<RDShaderSPIRV> &p_bytecode, const String &p_shader_name = "");
  1210. RID _shader_create_from_spirv(const Ref<RDShaderSPIRV> &p_spirv, const String &p_shader_name = "");
  1211. RID _uniform_set_create(const TypedArray<RDUniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
  1212. Error _buffer_update_bind(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data);
  1213. 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);
  1214. RID _compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants);
  1215. void _draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  1216. void _compute_list_set_push_constant(ComputeListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  1217. };
  1218. VARIANT_ENUM_CAST(RenderingDevice::DeviceType)
  1219. VARIANT_ENUM_CAST(RenderingDevice::DriverResource)
  1220. VARIANT_ENUM_CAST(RenderingDevice::ShaderStage)
  1221. VARIANT_ENUM_CAST(RenderingDevice::ShaderLanguage)
  1222. VARIANT_ENUM_CAST(RenderingDevice::CompareOperator)
  1223. VARIANT_ENUM_CAST(RenderingDevice::DataFormat)
  1224. VARIANT_ENUM_CAST(RenderingDevice::TextureType)
  1225. VARIANT_ENUM_CAST(RenderingDevice::TextureSamples)
  1226. VARIANT_BITFIELD_CAST(RenderingDevice::TextureUsageBits)
  1227. VARIANT_ENUM_CAST(RenderingDevice::TextureSwizzle)
  1228. VARIANT_ENUM_CAST(RenderingDevice::TextureSliceType)
  1229. VARIANT_ENUM_CAST(RenderingDevice::SamplerFilter)
  1230. VARIANT_ENUM_CAST(RenderingDevice::SamplerRepeatMode)
  1231. VARIANT_ENUM_CAST(RenderingDevice::SamplerBorderColor)
  1232. VARIANT_ENUM_CAST(RenderingDevice::VertexFrequency)
  1233. VARIANT_ENUM_CAST(RenderingDevice::IndexBufferFormat)
  1234. VARIANT_BITFIELD_CAST(RenderingDevice::StorageBufferUsage)
  1235. VARIANT_ENUM_CAST(RenderingDevice::UniformType)
  1236. VARIANT_ENUM_CAST(RenderingDevice::RenderPrimitive)
  1237. VARIANT_ENUM_CAST(RenderingDevice::PolygonCullMode)
  1238. VARIANT_ENUM_CAST(RenderingDevice::PolygonFrontFace)
  1239. VARIANT_ENUM_CAST(RenderingDevice::StencilOperation)
  1240. VARIANT_ENUM_CAST(RenderingDevice::LogicOperation)
  1241. VARIANT_ENUM_CAST(RenderingDevice::BlendFactor)
  1242. VARIANT_ENUM_CAST(RenderingDevice::BlendOperation)
  1243. VARIANT_BITFIELD_CAST(RenderingDevice::PipelineDynamicStateFlags)
  1244. VARIANT_ENUM_CAST(RenderingDevice::PipelineSpecializationConstantType)
  1245. VARIANT_ENUM_CAST(RenderingDevice::InitialAction)
  1246. VARIANT_ENUM_CAST(RenderingDevice::FinalAction)
  1247. VARIANT_ENUM_CAST(RenderingDevice::Limit)
  1248. VARIANT_ENUM_CAST(RenderingDevice::MemoryType)
  1249. VARIANT_ENUM_CAST(RenderingDevice::Features)
  1250. #ifndef DISABLE_DEPRECATED
  1251. VARIANT_BITFIELD_CAST(RenderingDevice::BarrierMask);
  1252. #endif
  1253. typedef RenderingDevice RD;
  1254. #endif // RENDERING_DEVICE_H