rendering_device.h 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  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. #pragma once
  31. #include "core/object/worker_thread_pool.h"
  32. #include "core/os/condition_variable.h"
  33. #include "core/os/thread_safe.h"
  34. #include "core/templates/local_vector.h"
  35. #include "core/templates/rid_owner.h"
  36. #include "core/variant/typed_array.h"
  37. #include "servers/display/display_server.h"
  38. #include "servers/rendering/rendering_device_commons.h"
  39. #include "servers/rendering/rendering_device_driver.h"
  40. #include "servers/rendering/rendering_device_graph.h"
  41. class RDTextureFormat;
  42. class RDTextureView;
  43. class RDAttachmentFormat;
  44. class RDSamplerState;
  45. class RDVertexAttribute;
  46. class RDShaderSource;
  47. class RDShaderSPIRV;
  48. class RDUniform;
  49. class RDPipelineRasterizationState;
  50. class RDPipelineMultisampleState;
  51. class RDPipelineDepthStencilState;
  52. class RDPipelineColorBlendState;
  53. class RDFramebufferPass;
  54. class RDPipelineSpecializationConstant;
  55. class RenderingDevice : public RenderingDeviceCommons {
  56. GDCLASS(RenderingDevice, Object)
  57. _THREAD_SAFE_CLASS_
  58. private:
  59. Thread::ID render_thread_id;
  60. public:
  61. typedef int64_t DrawListID;
  62. typedef int64_t ComputeListID;
  63. typedef void (*InvalidationCallback)(void *);
  64. private:
  65. static RenderingDevice *singleton;
  66. RenderingContextDriver *context = nullptr;
  67. RenderingDeviceDriver *driver = nullptr;
  68. RenderingContextDriver::Device device;
  69. bool local_device_processing = false;
  70. bool is_main_instance = false;
  71. protected:
  72. static void _bind_methods();
  73. #ifndef DISABLE_DEPRECATED
  74. RID _shader_create_from_bytecode_bind_compat_79606(const Vector<uint8_t> &p_shader_binary);
  75. RID _texture_create_from_extension_compat_105570(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);
  76. static void _bind_compatibility_methods();
  77. #endif
  78. /***************************/
  79. /**** ID INFRASTRUCTURE ****/
  80. /***************************/
  81. public:
  82. //base numeric ID for all types
  83. enum {
  84. INVALID_FORMAT_ID = -1
  85. };
  86. enum IDType {
  87. ID_TYPE_FRAMEBUFFER_FORMAT,
  88. ID_TYPE_VERTEX_FORMAT,
  89. ID_TYPE_DRAW_LIST,
  90. ID_TYPE_COMPUTE_LIST = 4,
  91. ID_TYPE_MAX,
  92. ID_BASE_SHIFT = 58, // 5 bits for ID types.
  93. ID_MASK = (ID_BASE_SHIFT - 1),
  94. };
  95. private:
  96. HashMap<RID, HashSet<RID>> dependency_map; // IDs to IDs that depend on it.
  97. HashMap<RID, HashSet<RID>> reverse_dependency_map; // Same as above, but in reverse.
  98. void _add_dependency(RID p_id, RID p_depends_on);
  99. void _free_dependencies(RID p_id);
  100. private:
  101. /***************************/
  102. /**** BUFFER MANAGEMENT ****/
  103. /***************************/
  104. // These are temporary buffers on CPU memory that hold
  105. // the information until the CPU fetches it and places it
  106. // either on GPU buffers, or images (textures). It ensures
  107. // updates are properly synchronized with whatever the
  108. // GPU is doing.
  109. //
  110. // The logic here is as follows, only 3 of these
  111. // blocks are created at the beginning (one per frame)
  112. // they can each belong to a frame (assigned to current when
  113. // used) and they can only be reused after the same frame is
  114. // recycled.
  115. //
  116. // When CPU requires to allocate more than what is available,
  117. // more of these buffers are created. If a limit is reached,
  118. // then a fence will ensure will wait for blocks allocated
  119. // in previous frames are processed. If that fails, then
  120. // another fence will ensure everything pending for the current
  121. // frame is processed (effectively stalling).
  122. //
  123. // See the comments in the code to understand better how it works.
  124. enum StagingRequiredAction {
  125. STAGING_REQUIRED_ACTION_NONE,
  126. STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL,
  127. STAGING_REQUIRED_ACTION_STALL_PREVIOUS,
  128. };
  129. struct StagingBufferBlock {
  130. RDD::BufferID driver_id;
  131. uint64_t frame_used = 0;
  132. uint32_t fill_amount = 0;
  133. uint8_t *data_ptr = nullptr;
  134. };
  135. struct StagingBuffers {
  136. Vector<StagingBufferBlock> blocks;
  137. int current = 0;
  138. uint32_t block_size = 0;
  139. uint64_t max_size = 0;
  140. BitField<RDD::BufferUsageBits> usage_bits = {};
  141. bool used = false;
  142. };
  143. Error _staging_buffer_allocate(StagingBuffers &p_staging_buffers, 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);
  144. void _staging_buffer_execute_required_action(StagingBuffers &p_staging_buffers, StagingRequiredAction p_required_action);
  145. Error _insert_staging_block(StagingBuffers &p_staging_buffers);
  146. StagingBuffers upload_staging_buffers;
  147. StagingBuffers download_staging_buffers;
  148. struct Buffer {
  149. RDD::BufferID driver_id;
  150. uint32_t size = 0;
  151. BitField<RDD::BufferUsageBits> usage = {};
  152. RDG::ResourceTracker *draw_tracker = nullptr;
  153. int32_t transfer_worker_index = -1;
  154. uint64_t transfer_worker_operation = 0;
  155. };
  156. Buffer *_get_buffer_from_owner(RID p_buffer);
  157. Error _buffer_initialize(Buffer *p_buffer, Span<uint8_t> p_data, uint32_t p_required_align = 32);
  158. void update_perf_report();
  159. // Flag for batching descriptor sets.
  160. bool descriptor_set_batching = true;
  161. // When true, the final draw call that copies our offscreen result into the Swapchain is put into its
  162. // own cmd buffer, so that the whole rendering can start early instead of having to wait for the
  163. // swapchain semaphore to be signaled (which causes bubbles).
  164. bool split_swapchain_into_its_own_cmd_buffer = true;
  165. uint32_t gpu_copy_count = 0;
  166. uint32_t direct_copy_count = 0;
  167. uint32_t copy_bytes_count = 0;
  168. uint32_t prev_gpu_copy_count = 0;
  169. uint32_t prev_copy_bytes_count = 0;
  170. RID_Owner<Buffer, true> uniform_buffer_owner;
  171. RID_Owner<Buffer, true> storage_buffer_owner;
  172. RID_Owner<Buffer, true> texture_buffer_owner;
  173. struct BufferGetDataRequest {
  174. uint32_t frame_local_index = 0;
  175. uint32_t frame_local_count = 0;
  176. Callable callback;
  177. uint32_t size = 0;
  178. };
  179. public:
  180. 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);
  181. /**
  182. * @brief Updates the given GPU buffer at offset and size with the given CPU data.
  183. * @remarks
  184. * Buffer update is queued into the render graph. The render graph will reorder this operation so
  185. * that it happens together with other buffer_update() in bulk and before rendering operations
  186. * (or compute dispatches) that need it.
  187. *
  188. * This means that the following will not work as intended:
  189. * @code
  190. * buffer_update(buffer_a, ..., data_source_x, ...);
  191. * draw_list_draw(buffer_a); // render data_render_x.
  192. * buffer_update(buffer_a, ..., data_source_y, ...);
  193. * draw_list_draw(buffer_a); // render data_source_y.
  194. * @endcode
  195. *
  196. * Because it will be *reordered* to become the following:
  197. * @code
  198. * buffer_update(buffer_a, ..., data_source_x, ...);
  199. * buffer_update(buffer_a, ..., data_source_y, ...);
  200. * draw_list_draw(buffer_a); // render data_source_y. <-- Oops! should be data_source_x
  201. * draw_list_draw(buffer_a); // render data_source_y.
  202. * @endcode
  203. *
  204. * When p_skip_check = true, we will perform checks to prevent this situation from happening
  205. * (buffer_update must not be called while creating a draw or compute list).
  206. * Do NOT set it to false for user-facing public API because users had trouble understanding
  207. * this problem when manually creating draw lists.
  208. *
  209. * Godot internally can set p_skip_check = true when it believes it will only update
  210. * the buffer once and it needs to be done while a draw/compute list is being created.
  211. *
  212. * Important: The Vulkan & Metal APIs do not allow issuing copies while inside a RenderPass.
  213. * We can do it because Godot's render graph will reorder them.
  214. *
  215. * @param p_buffer GPU buffer to update.
  216. * @param p_offset Offset in bytes (relative to p_buffer).
  217. * @param p_size Size in bytes of the data.
  218. * @param p_data CPU data to transfer to GPU.
  219. * Pointer can be deleted after buffer_update returns.
  220. * @param p_skip_check Must always be false for user-facing public API. See remarks.
  221. * @return Status result of the operation.
  222. */
  223. Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, bool p_skip_check = false);
  224. Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size);
  225. 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.
  226. Error buffer_get_data_async(RID p_buffer, const Callable &p_callback, uint32_t p_offset = 0, uint32_t p_size = 0);
  227. uint64_t buffer_get_device_address(RID p_buffer);
  228. uint8_t *buffer_persistent_map_advance(RID p_buffer);
  229. void buffer_flush(RID p_buffer);
  230. private:
  231. /******************/
  232. /**** CALLBACK ****/
  233. /******************/
  234. public:
  235. enum CallbackResourceType {
  236. CALLBACK_RESOURCE_TYPE_TEXTURE,
  237. CALLBACK_RESOURCE_TYPE_BUFFER,
  238. };
  239. enum CallbackResourceUsage {
  240. CALLBACK_RESOURCE_USAGE_NONE,
  241. CALLBACK_RESOURCE_USAGE_COPY_FROM,
  242. CALLBACK_RESOURCE_USAGE_COPY_TO,
  243. CALLBACK_RESOURCE_USAGE_RESOLVE_FROM,
  244. CALLBACK_RESOURCE_USAGE_RESOLVE_TO,
  245. CALLBACK_RESOURCE_USAGE_UNIFORM_BUFFER_READ,
  246. CALLBACK_RESOURCE_USAGE_INDIRECT_BUFFER_READ,
  247. CALLBACK_RESOURCE_USAGE_TEXTURE_BUFFER_READ,
  248. CALLBACK_RESOURCE_USAGE_TEXTURE_BUFFER_READ_WRITE,
  249. CALLBACK_RESOURCE_USAGE_STORAGE_BUFFER_READ,
  250. CALLBACK_RESOURCE_USAGE_STORAGE_BUFFER_READ_WRITE,
  251. CALLBACK_RESOURCE_USAGE_VERTEX_BUFFER_READ,
  252. CALLBACK_RESOURCE_USAGE_INDEX_BUFFER_READ,
  253. CALLBACK_RESOURCE_USAGE_TEXTURE_SAMPLE,
  254. CALLBACK_RESOURCE_USAGE_STORAGE_IMAGE_READ,
  255. CALLBACK_RESOURCE_USAGE_STORAGE_IMAGE_READ_WRITE,
  256. CALLBACK_RESOURCE_USAGE_ATTACHMENT_COLOR_READ_WRITE,
  257. CALLBACK_RESOURCE_USAGE_ATTACHMENT_DEPTH_STENCIL_READ_WRITE,
  258. CALLBACK_RESOURCE_USAGE_ATTACHMENT_FRAGMENT_SHADING_RATE_READ,
  259. CALLBACK_RESOURCE_USAGE_ATTACHMENT_FRAGMENT_DENSITY_MAP_READ,
  260. CALLBACK_RESOURCE_USAGE_GENERAL,
  261. CALLBACK_RESOURCE_USAGE_MAX
  262. };
  263. struct CallbackResource {
  264. RID rid;
  265. CallbackResourceType type = CALLBACK_RESOURCE_TYPE_TEXTURE;
  266. CallbackResourceUsage usage = CALLBACK_RESOURCE_USAGE_NONE;
  267. };
  268. Error driver_callback_add(RDD::DriverCallback p_callback, void *p_userdata, VectorView<CallbackResource> p_resources);
  269. /*****************/
  270. /**** TEXTURE ****/
  271. /*****************/
  272. // In modern APIs, the concept of textures may not exist;
  273. // instead there is the image (the memory pretty much,
  274. // the view (how the memory is interpreted) and the
  275. // sampler (how it's sampled from the shader).
  276. //
  277. // Texture here includes the first two stages, but
  278. // It's possible to create textures sharing the image
  279. // but with different views. The main use case for this
  280. // is textures that can be read as both SRGB/Linear,
  281. // or slices of a texture (a mipmap, a layer, a 3D slice)
  282. // for a framebuffer to render into it.
  283. struct Texture {
  284. struct SharedFallback {
  285. uint32_t revision = 1;
  286. RDD::TextureID texture;
  287. RDG::ResourceTracker *texture_tracker = nullptr;
  288. RDD::BufferID buffer;
  289. RDG::ResourceTracker *buffer_tracker = nullptr;
  290. bool raw_reinterpretation = false;
  291. };
  292. RDD::TextureID driver_id;
  293. TextureType type = TEXTURE_TYPE_MAX;
  294. DataFormat format = DATA_FORMAT_MAX;
  295. TextureSamples samples = TEXTURE_SAMPLES_MAX;
  296. TextureSliceType slice_type = TEXTURE_SLICE_MAX;
  297. Rect2i slice_rect;
  298. uint32_t width = 0;
  299. uint32_t height = 0;
  300. uint32_t depth = 0;
  301. uint32_t layers = 0;
  302. uint32_t mipmaps = 0;
  303. uint32_t usage_flags = 0;
  304. uint32_t base_mipmap = 0;
  305. uint32_t base_layer = 0;
  306. Vector<DataFormat> allowed_shared_formats;
  307. bool is_resolve_buffer = false;
  308. bool is_discardable = false;
  309. bool has_initial_data = false;
  310. bool pending_clear = false;
  311. BitField<RDD::TextureAspectBits> read_aspect_flags = {};
  312. BitField<RDD::TextureAspectBits> barrier_aspect_flags = {};
  313. bool bound = false; // Bound to framebuffer.
  314. RID owner;
  315. RDG::ResourceTracker *draw_tracker = nullptr;
  316. HashMap<Rect2i, RDG::ResourceTracker *> *slice_trackers = nullptr;
  317. SharedFallback *shared_fallback = nullptr;
  318. int32_t transfer_worker_index = -1;
  319. uint64_t transfer_worker_operation = 0;
  320. RDD::TextureSubresourceRange barrier_range() const {
  321. RDD::TextureSubresourceRange r;
  322. r.aspect = barrier_aspect_flags;
  323. r.base_mipmap = base_mipmap;
  324. r.mipmap_count = mipmaps;
  325. r.base_layer = base_layer;
  326. r.layer_count = layers;
  327. return r;
  328. }
  329. TextureFormat texture_format() const {
  330. TextureFormat tf;
  331. tf.format = format;
  332. tf.width = width;
  333. tf.height = height;
  334. tf.depth = depth;
  335. tf.array_layers = layers;
  336. tf.mipmaps = mipmaps;
  337. tf.texture_type = type;
  338. tf.samples = samples;
  339. tf.usage_bits = usage_flags;
  340. tf.shareable_formats = allowed_shared_formats;
  341. tf.is_resolve_buffer = is_resolve_buffer;
  342. tf.is_discardable = is_discardable;
  343. return tf;
  344. }
  345. };
  346. RID_Owner<Texture, true> texture_owner;
  347. uint32_t texture_upload_region_size_px = 0;
  348. uint32_t texture_download_region_size_px = 0;
  349. uint32_t _texture_layer_count(Texture *p_texture) const;
  350. uint32_t _texture_alignment(Texture *p_texture) const;
  351. Error _texture_initialize(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, RDD::TextureLayout p_dst_layout, bool p_immediate_flush);
  352. void _texture_check_shared_fallback(Texture *p_texture);
  353. void _texture_update_shared_fallback(RID p_texture_rid, Texture *p_texture, bool p_for_writing);
  354. void _texture_free_shared_fallback(Texture *p_texture);
  355. void _texture_copy_shared(RID p_src_texture_rid, Texture *p_src_texture, RID p_dst_texture_rid, Texture *p_dst_texture);
  356. void _texture_create_reinterpret_buffer(Texture *p_texture);
  357. void _texture_check_pending_clear(RID p_texture_rid, Texture *p_texture);
  358. void _texture_clear_color(RID p_texture_rid, Texture *p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers);
  359. void _texture_clear_depth_stencil(RID p_texture_rid, Texture *p_texture, float p_depth, uint8_t p_stencil, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers);
  360. uint32_t _texture_vrs_method_to_usage_bits() const;
  361. struct TextureGetDataRequest {
  362. uint32_t frame_local_index = 0;
  363. uint32_t frame_local_count = 0;
  364. Callable callback;
  365. uint32_t width = 0;
  366. uint32_t height = 0;
  367. uint32_t depth = 0;
  368. uint32_t mipmaps = 0;
  369. RDD::DataFormat format = RDD::DATA_FORMAT_MAX;
  370. };
  371. public:
  372. struct TextureView {
  373. DataFormat format_override = DATA_FORMAT_MAX; // // Means, use same as format.
  374. TextureSwizzle swizzle_r = TEXTURE_SWIZZLE_R;
  375. TextureSwizzle swizzle_g = TEXTURE_SWIZZLE_G;
  376. TextureSwizzle swizzle_b = TEXTURE_SWIZZLE_B;
  377. TextureSwizzle swizzle_a = TEXTURE_SWIZZLE_A;
  378. bool operator==(const TextureView &p_other) const {
  379. if (format_override != p_other.format_override) {
  380. return false;
  381. } else if (swizzle_r != p_other.swizzle_r) {
  382. return false;
  383. } else if (swizzle_g != p_other.swizzle_g) {
  384. return false;
  385. } else if (swizzle_b != p_other.swizzle_b) {
  386. return false;
  387. } else if (swizzle_a != p_other.swizzle_a) {
  388. return false;
  389. } else {
  390. return true;
  391. }
  392. }
  393. };
  394. RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>());
  395. RID texture_create_shared(const TextureView &p_view, RID p_with_texture);
  396. 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, uint64_t p_mipmaps = 1);
  397. 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);
  398. Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data);
  399. 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
  400. Error texture_get_data_async(RID p_texture, uint32_t p_layer, const Callable &p_callback);
  401. bool texture_is_format_supported_for_usage(DataFormat p_format, BitField<TextureUsageBits> p_usage) const;
  402. bool texture_is_shared(RID p_texture);
  403. bool texture_is_valid(RID p_texture);
  404. TextureFormat texture_get_format(RID p_texture);
  405. Size2i texture_size(RID p_texture);
  406. #ifndef DISABLE_DEPRECATED
  407. uint64_t texture_get_native_handle(RID p_texture);
  408. #endif
  409. 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);
  410. 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);
  411. Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture);
  412. void texture_set_discardable(RID p_texture, bool p_discardable);
  413. bool texture_is_discardable(RID p_texture);
  414. public:
  415. /*************/
  416. /**** VRS ****/
  417. /*************/
  418. enum VRSMethod {
  419. VRS_METHOD_NONE,
  420. VRS_METHOD_FRAGMENT_SHADING_RATE,
  421. VRS_METHOD_FRAGMENT_DENSITY_MAP,
  422. };
  423. private:
  424. VRSMethod vrs_method = VRS_METHOD_NONE;
  425. DataFormat vrs_format = DATA_FORMAT_MAX;
  426. Size2i vrs_texel_size;
  427. static RDG::ResourceUsage _vrs_usage_from_method(VRSMethod p_method);
  428. static RDD::PipelineStageBits _vrs_stages_from_method(VRSMethod p_method);
  429. static RDD::TextureLayout _vrs_layout_from_method(VRSMethod p_method);
  430. void _vrs_detect_method();
  431. public:
  432. VRSMethod vrs_get_method() const;
  433. DataFormat vrs_get_format() const;
  434. Size2i vrs_get_texel_size() const;
  435. /*********************/
  436. /**** FRAMEBUFFER ****/
  437. /*********************/
  438. // In modern APIs, generally, framebuffers work similar to how they
  439. // do in OpenGL, with the exception that
  440. // the "format" (RDD::RenderPassID) is not dynamic
  441. // and must be more or less the same as the one
  442. // used for the render pipelines.
  443. struct AttachmentFormat {
  444. enum : uint32_t {
  445. UNUSED_ATTACHMENT = 0xFFFFFFFF
  446. };
  447. DataFormat format;
  448. TextureSamples samples;
  449. uint32_t usage_flags;
  450. AttachmentFormat() {
  451. format = DATA_FORMAT_R8G8B8A8_UNORM;
  452. samples = TEXTURE_SAMPLES_1;
  453. usage_flags = 0;
  454. }
  455. };
  456. struct FramebufferPass {
  457. Vector<int32_t> color_attachments;
  458. Vector<int32_t> input_attachments;
  459. Vector<int32_t> resolve_attachments;
  460. Vector<int32_t> preserve_attachments;
  461. int32_t depth_attachment = ATTACHMENT_UNUSED;
  462. int32_t depth_resolve_attachment = ATTACHMENT_UNUSED;
  463. };
  464. typedef int64_t FramebufferFormatID;
  465. private:
  466. struct FramebufferFormatKey {
  467. Vector<AttachmentFormat> attachments;
  468. Vector<FramebufferPass> passes;
  469. uint32_t view_count = 1;
  470. VRSMethod vrs_method = VRS_METHOD_NONE;
  471. int32_t vrs_attachment = ATTACHMENT_UNUSED;
  472. Size2i vrs_texel_size;
  473. bool operator<(const FramebufferFormatKey &p_key) const {
  474. if (vrs_texel_size != p_key.vrs_texel_size) {
  475. return vrs_texel_size < p_key.vrs_texel_size;
  476. }
  477. if (vrs_attachment != p_key.vrs_attachment) {
  478. return vrs_attachment < p_key.vrs_attachment;
  479. }
  480. if (vrs_method != p_key.vrs_method) {
  481. return vrs_method < p_key.vrs_method;
  482. }
  483. if (view_count != p_key.view_count) {
  484. return view_count < p_key.view_count;
  485. }
  486. uint32_t pass_size = passes.size();
  487. uint32_t key_pass_size = p_key.passes.size();
  488. if (pass_size != key_pass_size) {
  489. return pass_size < key_pass_size;
  490. }
  491. const FramebufferPass *pass_ptr = passes.ptr();
  492. const FramebufferPass *key_pass_ptr = p_key.passes.ptr();
  493. for (uint32_t i = 0; i < pass_size; i++) {
  494. { // Compare color attachments.
  495. uint32_t attachment_size = pass_ptr[i].color_attachments.size();
  496. uint32_t key_attachment_size = key_pass_ptr[i].color_attachments.size();
  497. if (attachment_size != key_attachment_size) {
  498. return attachment_size < key_attachment_size;
  499. }
  500. const int32_t *pass_attachment_ptr = pass_ptr[i].color_attachments.ptr();
  501. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].color_attachments.ptr();
  502. for (uint32_t j = 0; j < attachment_size; j++) {
  503. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  504. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  505. }
  506. }
  507. }
  508. { // Compare input attachments.
  509. uint32_t attachment_size = pass_ptr[i].input_attachments.size();
  510. uint32_t key_attachment_size = key_pass_ptr[i].input_attachments.size();
  511. if (attachment_size != key_attachment_size) {
  512. return attachment_size < key_attachment_size;
  513. }
  514. const int32_t *pass_attachment_ptr = pass_ptr[i].input_attachments.ptr();
  515. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].input_attachments.ptr();
  516. for (uint32_t j = 0; j < attachment_size; j++) {
  517. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  518. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  519. }
  520. }
  521. }
  522. { // Compare resolve attachments.
  523. uint32_t attachment_size = pass_ptr[i].resolve_attachments.size();
  524. uint32_t key_attachment_size = key_pass_ptr[i].resolve_attachments.size();
  525. if (attachment_size != key_attachment_size) {
  526. return attachment_size < key_attachment_size;
  527. }
  528. const int32_t *pass_attachment_ptr = pass_ptr[i].resolve_attachments.ptr();
  529. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].resolve_attachments.ptr();
  530. for (uint32_t j = 0; j < attachment_size; j++) {
  531. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  532. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  533. }
  534. }
  535. }
  536. { // Compare preserve attachments.
  537. uint32_t attachment_size = pass_ptr[i].preserve_attachments.size();
  538. uint32_t key_attachment_size = key_pass_ptr[i].preserve_attachments.size();
  539. if (attachment_size != key_attachment_size) {
  540. return attachment_size < key_attachment_size;
  541. }
  542. const int32_t *pass_attachment_ptr = pass_ptr[i].preserve_attachments.ptr();
  543. const int32_t *key_pass_attachment_ptr = key_pass_ptr[i].preserve_attachments.ptr();
  544. for (uint32_t j = 0; j < attachment_size; j++) {
  545. if (pass_attachment_ptr[j] != key_pass_attachment_ptr[j]) {
  546. return pass_attachment_ptr[j] < key_pass_attachment_ptr[j];
  547. }
  548. }
  549. }
  550. if (pass_ptr[i].depth_attachment != key_pass_ptr[i].depth_attachment) {
  551. return pass_ptr[i].depth_attachment < key_pass_ptr[i].depth_attachment;
  552. }
  553. }
  554. int as = attachments.size();
  555. int bs = p_key.attachments.size();
  556. if (as != bs) {
  557. return as < bs;
  558. }
  559. const AttachmentFormat *af_a = attachments.ptr();
  560. const AttachmentFormat *af_b = p_key.attachments.ptr();
  561. for (int i = 0; i < as; i++) {
  562. const AttachmentFormat &a = af_a[i];
  563. const AttachmentFormat &b = af_b[i];
  564. if (a.format != b.format) {
  565. return a.format < b.format;
  566. }
  567. if (a.samples != b.samples) {
  568. return a.samples < b.samples;
  569. }
  570. if (a.usage_flags != b.usage_flags) {
  571. return a.usage_flags < b.usage_flags;
  572. }
  573. }
  574. return false; // Equal.
  575. }
  576. };
  577. static RDD::RenderPassID _render_pass_create(RenderingDeviceDriver *p_driver, const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, VectorView<RDD::AttachmentLoadOp> p_load_ops, VectorView<RDD::AttachmentStoreOp> p_store_ops, uint32_t p_view_count = 1, VRSMethod p_vrs_method = VRS_METHOD_NONE, int32_t p_vrs_attachment = -1, Size2i p_vrs_texel_size = Size2i(), Vector<TextureSamples> *r_samples = nullptr);
  578. static RDD::RenderPassID _render_pass_create_from_graph(RenderingDeviceDriver *p_driver, VectorView<RDD::AttachmentLoadOp> p_load_ops, VectorView<RDD::AttachmentStoreOp> p_store_ops, void *p_user_data);
  579. // This is a cache and it's never freed, it ensures
  580. // IDs for a given format are always unique.
  581. RBMap<FramebufferFormatKey, FramebufferFormatID> framebuffer_format_cache;
  582. struct FramebufferFormat {
  583. const RBMap<FramebufferFormatKey, FramebufferFormatID>::Element *E;
  584. RDD::RenderPassID render_pass; // Here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec).
  585. Vector<TextureSamples> pass_samples;
  586. uint32_t view_count = 1; // Number of views.
  587. };
  588. HashMap<FramebufferFormatID, FramebufferFormat> framebuffer_formats;
  589. struct Framebuffer {
  590. FramebufferFormatID format_id;
  591. uint32_t storage_mask = 0;
  592. Vector<RID> texture_ids;
  593. InvalidationCallback invalidated_callback = nullptr;
  594. void *invalidated_callback_userdata = nullptr;
  595. RDG::FramebufferCache *framebuffer_cache = nullptr;
  596. Size2 size;
  597. uint32_t view_count;
  598. };
  599. RID_Owner<Framebuffer, true> framebuffer_owner;
  600. public:
  601. // This ID is warranted to be unique for the same formats, does not need to be freed
  602. FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1, int32_t p_vrs_attachment = -1);
  603. FramebufferFormatID framebuffer_format_create_multipass(const Vector<AttachmentFormat> &p_attachments, const Vector<FramebufferPass> &p_passes, uint32_t p_view_count = 1, int32_t p_vrs_attachment = -1);
  604. FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1);
  605. TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format, uint32_t p_pass = 0);
  606. RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  607. 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);
  608. RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID);
  609. bool framebuffer_is_valid(RID p_framebuffer) const;
  610. void framebuffer_set_invalidation_callback(RID p_framebuffer, InvalidationCallback p_callback, void *p_userdata);
  611. FramebufferFormatID framebuffer_get_format(RID p_framebuffer);
  612. Size2 framebuffer_get_size(RID p_framebuffer);
  613. /*****************/
  614. /**** SAMPLER ****/
  615. /*****************/
  616. private:
  617. RID_Owner<RDD::SamplerID, true> sampler_owner;
  618. public:
  619. RID sampler_create(const SamplerState &p_state);
  620. bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_sampler_filter) const;
  621. /**********************/
  622. /**** VERTEX ARRAY ****/
  623. /**********************/
  624. typedef int64_t VertexFormatID;
  625. private:
  626. // Vertex buffers in Vulkan are similar to how
  627. // they work in OpenGL, except that instead of
  628. // an attribute index, there is a buffer binding
  629. // index (for binding the buffers in real-time)
  630. // and a location index (what is used in the shader).
  631. //
  632. // This mapping is done here internally, and it's not
  633. // exposed.
  634. RID_Owner<Buffer, true> vertex_buffer_owner;
  635. struct VertexDescriptionKey {
  636. Vector<VertexAttribute> vertex_formats;
  637. bool operator==(const VertexDescriptionKey &p_key) const {
  638. int vdc = vertex_formats.size();
  639. int vdck = p_key.vertex_formats.size();
  640. if (vdc != vdck) {
  641. return false;
  642. } else {
  643. const VertexAttribute *a_ptr = vertex_formats.ptr();
  644. const VertexAttribute *b_ptr = p_key.vertex_formats.ptr();
  645. for (int i = 0; i < vdc; i++) {
  646. const VertexAttribute &a = a_ptr[i];
  647. const VertexAttribute &b = b_ptr[i];
  648. if (a.location != b.location) {
  649. return false;
  650. }
  651. if (a.offset != b.offset) {
  652. return false;
  653. }
  654. if (a.format != b.format) {
  655. return false;
  656. }
  657. if (a.stride != b.stride) {
  658. return false;
  659. }
  660. if (a.frequency != b.frequency) {
  661. return false;
  662. }
  663. }
  664. return true; // They are equal.
  665. }
  666. }
  667. uint32_t hash() const {
  668. int vdc = vertex_formats.size();
  669. uint32_t h = hash_murmur3_one_32(vdc);
  670. const VertexAttribute *ptr = vertex_formats.ptr();
  671. for (int i = 0; i < vdc; i++) {
  672. const VertexAttribute &vd = ptr[i];
  673. h = hash_murmur3_one_32(vd.location, h);
  674. h = hash_murmur3_one_32(vd.offset, h);
  675. h = hash_murmur3_one_32(vd.format, h);
  676. h = hash_murmur3_one_32(vd.stride, h);
  677. h = hash_murmur3_one_32(vd.frequency, h);
  678. }
  679. return hash_fmix32(h);
  680. }
  681. };
  682. struct VertexDescriptionHash {
  683. static _FORCE_INLINE_ uint32_t hash(const VertexDescriptionKey &p_key) {
  684. return p_key.hash();
  685. }
  686. };
  687. // This is a cache and it's never freed, it ensures that
  688. // ID used for a specific format always remain the same.
  689. HashMap<VertexDescriptionKey, VertexFormatID, VertexDescriptionHash> vertex_format_cache;
  690. struct VertexDescriptionCache {
  691. Vector<VertexAttribute> vertex_formats;
  692. VertexAttributeBindingsMap bindings;
  693. RDD::VertexFormatID driver_id;
  694. };
  695. HashMap<VertexFormatID, VertexDescriptionCache> vertex_formats;
  696. struct VertexArray {
  697. RID buffer;
  698. VertexFormatID description;
  699. int vertex_count = 0;
  700. uint32_t max_instances_allowed = 0;
  701. Vector<RDD::BufferID> buffers; // Not owned, just referenced.
  702. Vector<RDG::ResourceTracker *> draw_trackers; // Not owned, just referenced.
  703. Vector<uint64_t> offsets;
  704. Vector<int32_t> transfer_worker_indices;
  705. Vector<uint64_t> transfer_worker_operations;
  706. HashSet<RID> untracked_buffers;
  707. };
  708. RID_Owner<VertexArray, true> vertex_array_owner;
  709. struct IndexBuffer : public Buffer {
  710. uint32_t max_index = 0; // Used for validation.
  711. uint32_t index_count = 0;
  712. IndexBufferFormat format = INDEX_BUFFER_FORMAT_UINT16;
  713. bool supports_restart_indices = false;
  714. };
  715. RID_Owner<IndexBuffer, true> index_buffer_owner;
  716. struct IndexArray {
  717. uint32_t max_index = 0; // Remember the maximum index here too, for validation.
  718. RDD::BufferID driver_id; // Not owned, inherited from index buffer.
  719. RDG::ResourceTracker *draw_tracker = nullptr; // Not owned, inherited from index buffer.
  720. uint32_t offset = 0;
  721. uint32_t indices = 0;
  722. IndexBufferFormat format = INDEX_BUFFER_FORMAT_UINT16;
  723. bool supports_restart_indices = false;
  724. int32_t transfer_worker_index = -1;
  725. uint64_t transfer_worker_operation = 0;
  726. };
  727. RID_Owner<IndexArray, true> index_array_owner;
  728. public:
  729. enum BufferCreationBits {
  730. BUFFER_CREATION_DEVICE_ADDRESS_BIT = (1 << 0),
  731. BUFFER_CREATION_AS_STORAGE_BIT = (1 << 1),
  732. BUFFER_CREATION_DYNAMIC_PERSISTENT_BIT = (1 << 2),
  733. };
  734. enum StorageBufferUsage {
  735. STORAGE_BUFFER_USAGE_DISPATCH_INDIRECT = (1 << 0),
  736. };
  737. RID vertex_buffer_create(uint32_t p_size_bytes, Span<uint8_t> p_data = {}, BitField<BufferCreationBits> p_creation_bits = 0);
  738. RID _vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, BitField<BufferCreationBits> p_creation_bits = 0) {
  739. return vertex_buffer_create(p_size_bytes, p_data, p_creation_bits);
  740. }
  741. // This ID is warranted to be unique for the same formats, does not need to be freed
  742. VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_descriptions);
  743. 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>());
  744. RID index_buffer_create(uint32_t p_index_count, IndexBufferFormat p_format, Span<uint8_t> p_data = {}, bool p_use_restart_indices = false, BitField<BufferCreationBits> p_creation_bits = 0);
  745. RID _index_buffer_create(uint32_t p_index_count, IndexBufferFormat p_format, const Vector<uint8_t> &p_data, bool p_use_restart_indices = false, BitField<BufferCreationBits> p_creation_bits = 0) {
  746. return index_buffer_create(p_index_count, p_format, p_data, p_use_restart_indices, p_creation_bits);
  747. }
  748. RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count);
  749. /****************/
  750. /**** SHADER ****/
  751. /****************/
  752. // Some APIs (e.g., Vulkan) specifies a really complex behavior for the application
  753. // in order to tell when descriptor sets need to be re-bound (or not).
  754. // "When binding a descriptor set (see Descriptor Set Binding) to set
  755. // number N, if the previously bound descriptor sets for sets zero
  756. // through N-1 were all bound using compatible pipeline layouts,
  757. // then performing this binding does not disturb any of the lower numbered sets.
  758. // If, additionally, the previous bound descriptor set for set N was
  759. // bound using a pipeline layout compatible for set N, then the bindings
  760. // in sets numbered greater than N are also not disturbed."
  761. // As a result, we need to figure out quickly when something is no longer "compatible".
  762. // in order to avoid costly rebinds.
  763. private:
  764. struct UniformSetFormat {
  765. Vector<ShaderUniform> uniforms;
  766. _FORCE_INLINE_ bool operator<(const UniformSetFormat &p_other) const {
  767. if (uniforms.size() != p_other.uniforms.size()) {
  768. return uniforms.size() < p_other.uniforms.size();
  769. }
  770. for (int i = 0; i < uniforms.size(); i++) {
  771. if (uniforms[i] < p_other.uniforms[i]) {
  772. return true;
  773. } else if (p_other.uniforms[i] < uniforms[i]) {
  774. return false;
  775. }
  776. }
  777. return false;
  778. }
  779. };
  780. // Always grows, never shrinks, ensuring unique IDs, but we assume
  781. // the amount of formats will never be a problem, as the amount of shaders
  782. // in a game is limited.
  783. RBMap<UniformSetFormat, uint32_t> uniform_set_format_cache;
  784. // Shaders in Vulkan are just pretty much
  785. // precompiled blocks of SPIR-V bytecode. They
  786. // are most likely not really compiled to host
  787. // assembly until a pipeline is created.
  788. //
  789. // When supplying the shaders, this implementation
  790. // will use the reflection abilities of glslang to
  791. // understand and cache everything required to
  792. // create and use the descriptor sets (Vulkan's
  793. // biggest pain).
  794. //
  795. // Additionally, hashes are created for every set
  796. // to do quick validation and ensuring the user
  797. // does not submit something invalid.
  798. struct Shader : public ShaderReflection {
  799. String name; // Used for debug.
  800. RDD::ShaderID driver_id;
  801. uint32_t layout_hash = 0;
  802. BitField<RDD::PipelineStageBits> stage_bits = {};
  803. Vector<uint32_t> set_formats;
  804. };
  805. String _shader_uniform_debug(RID p_shader, int p_set = -1);
  806. RID_Owner<Shader, true> shader_owner;
  807. #ifndef DISABLE_DEPRECATED
  808. public:
  809. enum BarrierMask {
  810. BARRIER_MASK_VERTEX = 1,
  811. BARRIER_MASK_FRAGMENT = 8,
  812. BARRIER_MASK_COMPUTE = 2,
  813. BARRIER_MASK_TRANSFER = 4,
  814. BARRIER_MASK_RASTER = BARRIER_MASK_VERTEX | BARRIER_MASK_FRAGMENT, // 9,
  815. BARRIER_MASK_ALL_BARRIERS = 0x7FFF, // all flags set
  816. BARRIER_MASK_NO_BARRIER = 0x8000,
  817. };
  818. enum InitialAction {
  819. INITIAL_ACTION_LOAD,
  820. INITIAL_ACTION_CLEAR,
  821. INITIAL_ACTION_DISCARD,
  822. INITIAL_ACTION_MAX,
  823. INITIAL_ACTION_CLEAR_REGION = INITIAL_ACTION_CLEAR,
  824. INITIAL_ACTION_CLEAR_REGION_CONTINUE = INITIAL_ACTION_CLEAR,
  825. INITIAL_ACTION_KEEP = INITIAL_ACTION_LOAD,
  826. INITIAL_ACTION_DROP = INITIAL_ACTION_DISCARD,
  827. INITIAL_ACTION_CONTINUE = INITIAL_ACTION_LOAD,
  828. };
  829. enum FinalAction {
  830. FINAL_ACTION_STORE,
  831. FINAL_ACTION_DISCARD,
  832. FINAL_ACTION_MAX,
  833. FINAL_ACTION_READ = FINAL_ACTION_STORE,
  834. FINAL_ACTION_CONTINUE = FINAL_ACTION_STORE,
  835. };
  836. void barrier(BitField<BarrierMask> p_from = BARRIER_MASK_ALL_BARRIERS, BitField<BarrierMask> p_to = BARRIER_MASK_ALL_BARRIERS);
  837. void full_barrier();
  838. void draw_command_insert_label(String p_label_name, const Color &p_color = Color(1, 1, 1, 1));
  839. 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>());
  840. Error draw_list_switch_to_next_pass_split(uint32_t p_splits, DrawListID *r_split_ids);
  841. 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>());
  842. Vector<int64_t> _draw_list_switch_to_next_pass_split(uint32_t p_splits);
  843. private:
  844. void _draw_list_end_bind_compat_81356(BitField<BarrierMask> p_post_barrier);
  845. void _compute_list_end_bind_compat_81356(BitField<BarrierMask> p_post_barrier);
  846. void _barrier_bind_compat_81356(BitField<BarrierMask> p_from, BitField<BarrierMask> p_to);
  847. void _draw_list_end_bind_compat_84976(BitField<BarrierMask> p_post_barrier);
  848. void _compute_list_end_bind_compat_84976(BitField<BarrierMask> p_post_barrier);
  849. InitialAction _convert_initial_action_84976(InitialAction p_old_initial_action);
  850. FinalAction _convert_final_action_84976(FinalAction p_old_final_action);
  851. 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);
  852. ComputeListID _compute_list_begin_bind_compat_84976(bool p_allow_draw_overlap);
  853. 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);
  854. Error _buffer_clear_bind_compat_84976(RID p_buffer, uint32_t p_offset, uint32_t p_size, BitField<BarrierMask> p_post_barrier);
  855. Error _texture_update_bind_compat_84976(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier);
  856. 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);
  857. 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);
  858. Error _texture_resolve_multisample_bind_compat_84976(RID p_from_texture, RID p_to_texture, BitField<BarrierMask> p_post_barrier);
  859. FramebufferFormatID _screen_get_framebuffer_format_bind_compat_87340() const;
  860. DrawListID _draw_list_begin_bind_compat_90993(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);
  861. DrawListID _draw_list_begin_bind_compat_98670(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, uint32_t p_breadcrumb);
  862. RID _uniform_buffer_create_bind_compat_101561(uint32_t p_size_bytes, const Vector<uint8_t> &p_data);
  863. RID _vertex_buffer_create_bind_compat_101561(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, bool p_use_as_storage);
  864. RID _index_buffer_create_bind_compat_101561(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector<uint8_t> &p_data, bool p_use_restart_indices);
  865. RID _storage_buffer_create_bind_compat_101561(uint32_t p_size, const Vector<uint8_t> &p_data, BitField<StorageBufferUsage> p_usage);
  866. #endif
  867. public:
  868. RenderingDeviceDriver *get_device_driver() const { return driver; }
  869. RenderingContextDriver *get_context_driver() const { return context; }
  870. const RDD::Capabilities &get_device_capabilities() const { return driver->get_capabilities(); }
  871. bool has_feature(const Features p_feature) const;
  872. 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);
  873. Vector<uint8_t> shader_compile_binary_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");
  874. RID shader_create_from_spirv(const Vector<ShaderStageSPIRVData> &p_spirv, const String &p_shader_name = "");
  875. RID shader_create_from_bytecode(const Vector<uint8_t> &p_shader_binary, RID p_placeholder = RID());
  876. RID shader_create_placeholder();
  877. void shader_destroy_modules(RID p_shader);
  878. uint64_t shader_get_vertex_input_attribute_mask(RID p_shader);
  879. /******************/
  880. /**** UNIFORMS ****/
  881. /******************/
  882. String get_perf_report() const;
  883. /*****************/
  884. /**** BUFFERS ****/
  885. /*****************/
  886. RID uniform_buffer_create(uint32_t p_size_bytes, Span<uint8_t> p_data = {}, BitField<BufferCreationBits> p_creation_bits = 0);
  887. RID _uniform_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, BitField<BufferCreationBits> p_creation_bits = 0) {
  888. return uniform_buffer_create(p_size_bytes, p_data, p_creation_bits);
  889. }
  890. RID storage_buffer_create(uint32_t p_size_bytes, Span<uint8_t> p_data = {}, BitField<StorageBufferUsage> p_usage = 0, BitField<BufferCreationBits> p_creation_bits = 0);
  891. RID _storage_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, BitField<StorageBufferUsage> p_usage = 0, BitField<BufferCreationBits> p_creation_bits = 0) {
  892. return storage_buffer_create(p_size_bytes, p_data, p_usage, p_creation_bits);
  893. }
  894. RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, Span<uint8_t> p_data = {});
  895. RID _texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data) {
  896. return texture_buffer_create(p_size_elements, p_format, p_data);
  897. }
  898. struct Uniform {
  899. UniformType uniform_type = UNIFORM_TYPE_IMAGE;
  900. uint32_t binding = 0; // Binding index as specified in shader.
  901. // This flag specifies that this is an immutable sampler to be set when creating pipeline layout.
  902. bool immutable_sampler = false;
  903. private:
  904. // In most cases only one ID is provided per binding, so avoid allocating memory unnecessarily for performance.
  905. RID id; // If only one is provided, this is used.
  906. Vector<RID> ids; // If multiple ones are provided, this is used instead.
  907. public:
  908. _FORCE_INLINE_ uint32_t get_id_count() const {
  909. return (id.is_valid() ? 1 : ids.size());
  910. }
  911. _FORCE_INLINE_ RID get_id(uint32_t p_idx) const {
  912. if (id.is_valid()) {
  913. ERR_FAIL_COND_V(p_idx != 0, RID());
  914. return id;
  915. } else {
  916. return ids[p_idx];
  917. }
  918. }
  919. _FORCE_INLINE_ void set_id(uint32_t p_idx, RID p_id) {
  920. if (id.is_valid()) {
  921. ERR_FAIL_COND(p_idx != 0);
  922. id = p_id;
  923. } else {
  924. ids.write[p_idx] = p_id;
  925. }
  926. }
  927. _FORCE_INLINE_ void append_id(RID p_id) {
  928. if (ids.is_empty()) {
  929. if (id == RID()) {
  930. id = p_id;
  931. } else {
  932. ids.push_back(id);
  933. ids.push_back(p_id);
  934. id = RID();
  935. }
  936. } else {
  937. ids.push_back(p_id);
  938. }
  939. }
  940. _FORCE_INLINE_ void clear_ids() {
  941. id = RID();
  942. ids.clear();
  943. }
  944. _FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, RID p_id) {
  945. uniform_type = p_type;
  946. binding = p_binding;
  947. id = p_id;
  948. }
  949. _FORCE_INLINE_ Uniform(UniformType p_type, int p_binding, const Vector<RID> &p_ids) {
  950. uniform_type = p_type;
  951. binding = p_binding;
  952. ids = p_ids;
  953. }
  954. _FORCE_INLINE_ Uniform() = default;
  955. };
  956. typedef Uniform PipelineImmutableSampler;
  957. RID shader_create_from_bytecode_with_samplers(const Vector<uint8_t> &p_shader_binary, RID p_placeholder = RID(), const Vector<PipelineImmutableSampler> &p_immutable_samplers = Vector<PipelineImmutableSampler>());
  958. private:
  959. static const uint32_t MAX_UNIFORM_SETS = 16;
  960. static const uint32_t MAX_PUSH_CONSTANT_SIZE = 128;
  961. // This structure contains the descriptor set. They _need_ to be allocated
  962. // for a shader (and will be erased when this shader is erased), but should
  963. // work for other shaders as long as the hash matches. This covers using
  964. // them in shader variants.
  965. //
  966. // Keep also in mind that you can share buffers between descriptor sets, so
  967. // the above restriction is not too serious.
  968. struct UniformSet {
  969. uint32_t format = 0;
  970. RID shader_id;
  971. uint32_t shader_set = 0;
  972. RDD::UniformSetID driver_id;
  973. struct AttachableTexture {
  974. uint32_t bind = 0;
  975. RID texture;
  976. };
  977. struct SharedTexture {
  978. uint32_t writing = 0;
  979. RID texture;
  980. };
  981. LocalVector<AttachableTexture> attachable_textures; // Used for validation.
  982. Vector<RDG::ResourceTracker *> draw_trackers;
  983. Vector<RDG::ResourceUsage> draw_trackers_usage;
  984. HashMap<RID, RDG::ResourceUsage> untracked_usage;
  985. LocalVector<SharedTexture> shared_textures_to_update;
  986. LocalVector<RID> pending_clear_textures;
  987. InvalidationCallback invalidated_callback = nullptr;
  988. void *invalidated_callback_userdata = nullptr;
  989. };
  990. RID_Owner<UniformSet, true> uniform_set_owner;
  991. void _uniform_set_update_shared(UniformSet *p_uniform_set);
  992. void _uniform_set_update_clears(UniformSet *p_uniform_set);
  993. public:
  994. /** Bake a set of uniforms that can be bound at runtime with the given shader.
  995. * @remark Setting p_linear_pool = true while keeping the RID around for longer than the current frame will result in undefined behavior.
  996. * @param p_uniforms The uniforms to bake into a set.
  997. * @param p_shader The shader you intend to bind these uniforms with.
  998. * @param p_set_index The set. Should be in range [0; 4)
  999. * The value 4 comes from physical_device_properties.limits.maxBoundDescriptorSets. Vulkan only guarantees maxBoundDescriptorSets >= 4 (== 4 is very common on Mobile).
  1000. * @param p_linear_pool If you call this function every frame (and free the returned RID within the same frame!), set it to true for better performance.
  1001. * If you plan on keeping the return value around for more than one frame (e.g. Sets that are created once and reused forever) you MUST set it to false.
  1002. * @return Baked descriptor set.
  1003. */
  1004. RID uniform_set_create(const VectorView<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set, bool p_linear_pool = false);
  1005. bool uniform_set_is_valid(RID p_uniform_set);
  1006. void uniform_set_set_invalidation_callback(RID p_uniform_set, InvalidationCallback p_callback, void *p_userdata);
  1007. bool uniform_sets_have_linear_pools() const;
  1008. /*******************/
  1009. /**** PIPELINES ****/
  1010. /*******************/
  1011. // Render pipeline contains ALL the
  1012. // information required for drawing.
  1013. // This includes all the rasterizer state
  1014. // as well as shader used, framebuffer format,
  1015. // etc.
  1016. // While the pipeline is just a single object
  1017. // (VkPipeline) a lot of values are also saved
  1018. // here to do validation (vulkan does none by
  1019. // default) and warn the user if something
  1020. // was not supplied as intended.
  1021. private:
  1022. struct RenderPipeline {
  1023. // Cached values for validation.
  1024. #ifdef DEBUG_ENABLED
  1025. struct Validation {
  1026. FramebufferFormatID framebuffer_format;
  1027. uint32_t render_pass = 0;
  1028. uint32_t dynamic_state = 0;
  1029. VertexFormatID vertex_format;
  1030. bool uses_restart_indices = false;
  1031. uint32_t primitive_minimum = 0;
  1032. uint32_t primitive_divisor = 0;
  1033. } validation;
  1034. #endif
  1035. // Actual pipeline.
  1036. RID shader;
  1037. RDD::ShaderID shader_driver_id;
  1038. uint32_t shader_layout_hash = 0;
  1039. Vector<uint32_t> set_formats;
  1040. RDD::PipelineID driver_id;
  1041. BitField<RDD::PipelineStageBits> stage_bits = {};
  1042. uint32_t push_constant_size = 0;
  1043. };
  1044. RID_Owner<RenderPipeline, true> render_pipeline_owner;
  1045. bool pipeline_cache_enabled = false;
  1046. size_t pipeline_cache_size = 0;
  1047. String pipeline_cache_file_path;
  1048. WorkerThreadPool::TaskID pipeline_cache_save_task = WorkerThreadPool::INVALID_TASK_ID;
  1049. Vector<uint8_t> _load_pipeline_cache();
  1050. static void _save_pipeline_cache(void *p_data);
  1051. struct ComputePipeline {
  1052. RID shader;
  1053. RDD::ShaderID shader_driver_id;
  1054. uint32_t shader_layout_hash = 0;
  1055. Vector<uint32_t> set_formats;
  1056. RDD::PipelineID driver_id;
  1057. uint32_t push_constant_size = 0;
  1058. uint32_t local_group_size[3] = { 0, 0, 0 };
  1059. };
  1060. RID_Owner<ComputePipeline, true> compute_pipeline_owner;
  1061. public:
  1062. 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>());
  1063. bool render_pipeline_is_valid(RID p_pipeline);
  1064. RID compute_pipeline_create(RID p_shader, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>());
  1065. bool compute_pipeline_is_valid(RID p_pipeline);
  1066. void update_pipeline_cache(bool p_closing = false);
  1067. private:
  1068. /****************/
  1069. /**** SCREEN ****/
  1070. /****************/
  1071. HashMap<DisplayServer::WindowID, RDD::SwapChainID> screen_swap_chains;
  1072. HashMap<DisplayServer::WindowID, RDD::FramebufferID> screen_framebuffers;
  1073. uint32_t _get_swap_chain_desired_count() const;
  1074. public:
  1075. Error screen_create(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
  1076. Error screen_prepare_for_drawing(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
  1077. int screen_get_width(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  1078. int screen_get_height(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  1079. int screen_get_pre_rotation_degrees(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  1080. FramebufferFormatID screen_get_framebuffer_format(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID) const;
  1081. Error screen_free(DisplayServer::WindowID p_screen = DisplayServer::MAIN_WINDOW_ID);
  1082. /*************************/
  1083. /**** DRAW LISTS (II) ****/
  1084. /*************************/
  1085. private:
  1086. // Draw list contains both the command buffer
  1087. // used for drawing as well as a LOT of
  1088. // information used for validation. This
  1089. // validation is cheap so most of it can
  1090. // also run in release builds.
  1091. struct DrawList {
  1092. Rect2i viewport;
  1093. bool active = false;
  1094. struct SetState {
  1095. uint32_t pipeline_expected_format = 0;
  1096. uint32_t uniform_set_format = 0;
  1097. RDD::UniformSetID uniform_set_driver_id;
  1098. RID uniform_set;
  1099. bool bound = false;
  1100. };
  1101. struct State {
  1102. SetState sets[MAX_UNIFORM_SETS];
  1103. uint32_t set_count = 0;
  1104. RID pipeline;
  1105. RID pipeline_shader;
  1106. RDD::ShaderID pipeline_shader_driver_id;
  1107. uint32_t pipeline_shader_layout_hash = 0;
  1108. uint32_t pipeline_push_constant_size = 0;
  1109. RID vertex_array;
  1110. RID index_array;
  1111. uint32_t draw_count = 0;
  1112. } state;
  1113. #ifdef DEBUG_ENABLED
  1114. struct Validation {
  1115. // Actual render pass values.
  1116. uint32_t dynamic_state = 0;
  1117. VertexFormatID vertex_format = INVALID_ID;
  1118. uint32_t vertex_array_size = 0;
  1119. uint32_t vertex_max_instances_allowed = 0xFFFFFFFF;
  1120. bool index_buffer_uses_restart_indices = false;
  1121. uint32_t index_array_count = 0;
  1122. uint32_t index_array_max_index = 0;
  1123. Vector<uint32_t> set_formats;
  1124. Vector<bool> set_bound;
  1125. Vector<RID> set_rids;
  1126. // Last pipeline set values.
  1127. bool pipeline_active = false;
  1128. uint32_t pipeline_dynamic_state = 0;
  1129. VertexFormatID pipeline_vertex_format = INVALID_ID;
  1130. RID pipeline_shader;
  1131. bool pipeline_uses_restart_indices = false;
  1132. uint32_t pipeline_primitive_divisor = 0;
  1133. uint32_t pipeline_primitive_minimum = 0;
  1134. uint32_t pipeline_push_constant_size = 0;
  1135. bool pipeline_push_constant_supplied = false;
  1136. } validation;
  1137. #else
  1138. struct Validation {
  1139. uint32_t vertex_array_size = 0;
  1140. uint32_t index_array_count = 0;
  1141. } validation;
  1142. #endif
  1143. };
  1144. DrawList draw_list;
  1145. uint32_t draw_list_subpass_count = 0;
  1146. #ifdef DEBUG_ENABLED
  1147. FramebufferFormatID draw_list_framebuffer_format = INVALID_ID;
  1148. #endif
  1149. uint32_t draw_list_current_subpass = 0;
  1150. LocalVector<RID> draw_list_bound_textures;
  1151. void _draw_list_start(const Rect2i &p_viewport);
  1152. void _draw_list_end(Rect2i *r_last_viewport = nullptr);
  1153. public:
  1154. enum DrawFlags {
  1155. DRAW_DEFAULT_ALL = 0,
  1156. DRAW_CLEAR_COLOR_0 = (1 << 0),
  1157. DRAW_CLEAR_COLOR_1 = (1 << 1),
  1158. DRAW_CLEAR_COLOR_2 = (1 << 2),
  1159. DRAW_CLEAR_COLOR_3 = (1 << 3),
  1160. DRAW_CLEAR_COLOR_4 = (1 << 4),
  1161. DRAW_CLEAR_COLOR_5 = (1 << 5),
  1162. DRAW_CLEAR_COLOR_6 = (1 << 6),
  1163. DRAW_CLEAR_COLOR_7 = (1 << 7),
  1164. DRAW_CLEAR_COLOR_MASK = 0xFF,
  1165. DRAW_CLEAR_COLOR_ALL = DRAW_CLEAR_COLOR_MASK,
  1166. DRAW_IGNORE_COLOR_0 = (1 << 8),
  1167. DRAW_IGNORE_COLOR_1 = (1 << 9),
  1168. DRAW_IGNORE_COLOR_2 = (1 << 10),
  1169. DRAW_IGNORE_COLOR_3 = (1 << 11),
  1170. DRAW_IGNORE_COLOR_4 = (1 << 12),
  1171. DRAW_IGNORE_COLOR_5 = (1 << 13),
  1172. DRAW_IGNORE_COLOR_6 = (1 << 14),
  1173. DRAW_IGNORE_COLOR_7 = (1 << 15),
  1174. DRAW_IGNORE_COLOR_MASK = 0xFF00,
  1175. DRAW_IGNORE_COLOR_ALL = DRAW_IGNORE_COLOR_MASK,
  1176. DRAW_CLEAR_DEPTH = (1 << 16),
  1177. DRAW_IGNORE_DEPTH = (1 << 17),
  1178. DRAW_CLEAR_STENCIL = (1 << 18),
  1179. DRAW_IGNORE_STENCIL = (1 << 19),
  1180. DRAW_CLEAR_ALL = DRAW_CLEAR_COLOR_ALL | DRAW_CLEAR_DEPTH | DRAW_CLEAR_STENCIL,
  1181. DRAW_IGNORE_ALL = DRAW_IGNORE_COLOR_ALL | DRAW_IGNORE_DEPTH | DRAW_IGNORE_STENCIL
  1182. };
  1183. /**
  1184. * @param p_clear_color Must use linear encoding when HDR 2D is active.
  1185. */
  1186. DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());
  1187. /**
  1188. * @param p_clear_color_values Color values must use linear encoding when HDR 2D is active.
  1189. */
  1190. DrawListID draw_list_begin(RID p_framebuffer, BitField<DrawFlags> p_draw_flags = DRAW_DEFAULT_ALL, VectorView<Color> p_clear_color_values = VectorView<Color>(), float p_clear_depth_value = 1.0f, uint32_t p_clear_stencil_value = 0, const Rect2 &p_region = Rect2(), uint32_t p_breadcrumb = 0);
  1191. DrawListID _draw_list_begin_bind(RID p_framebuffer, BitField<DrawFlags> p_draw_flags = DRAW_DEFAULT_ALL, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth_value = 1.0f, uint32_t p_clear_stencil_value = 0, const Rect2 &p_region = Rect2(), uint32_t p_breadcrumb = 0);
  1192. void draw_list_set_blend_constants(DrawListID p_list, const Color &p_color);
  1193. void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline);
  1194. void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index);
  1195. void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array);
  1196. void draw_list_bind_vertex_buffers_format(DrawListID p_list, VertexFormatID p_vertex_format, uint32_t p_vertex_count, const Span<RID> &p_vertex_buffers, const Span<uint64_t> &p_offsets = Vector<uint64_t>());
  1197. void draw_list_bind_index_array(DrawListID p_list, RID p_index_array);
  1198. void draw_list_set_line_width(DrawListID p_list, float p_width);
  1199. void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size);
  1200. void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0);
  1201. void draw_list_draw_indirect(DrawListID p_list, bool p_use_indices, RID p_buffer, uint32_t p_offset = 0, uint32_t p_draw_count = 1, uint32_t p_stride = 0);
  1202. void draw_list_set_viewport(DrawListID p_list, const Rect2 &p_rect);
  1203. void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect);
  1204. void draw_list_disable_scissor(DrawListID p_list);
  1205. uint32_t draw_list_get_current_pass();
  1206. DrawListID draw_list_switch_to_next_pass();
  1207. void draw_list_end();
  1208. private:
  1209. /***********************/
  1210. /**** COMPUTE LISTS ****/
  1211. /***********************/
  1212. struct ComputeList {
  1213. bool active = false;
  1214. struct SetState {
  1215. uint32_t pipeline_expected_format = 0;
  1216. uint32_t uniform_set_format = 0;
  1217. RDD::UniformSetID uniform_set_driver_id;
  1218. RID uniform_set;
  1219. bool bound = false;
  1220. };
  1221. struct State {
  1222. SetState sets[MAX_UNIFORM_SETS];
  1223. uint32_t set_count = 0;
  1224. RID pipeline;
  1225. RID pipeline_shader;
  1226. RDD::ShaderID pipeline_shader_driver_id;
  1227. uint32_t pipeline_shader_layout_hash = 0;
  1228. uint32_t local_group_size[3] = { 0, 0, 0 };
  1229. uint8_t push_constant_data[MAX_PUSH_CONSTANT_SIZE] = {};
  1230. uint32_t push_constant_size = 0;
  1231. uint32_t dispatch_count = 0;
  1232. } state;
  1233. #ifdef DEBUG_ENABLED
  1234. struct Validation {
  1235. Vector<uint32_t> set_formats;
  1236. Vector<bool> set_bound;
  1237. Vector<RID> set_rids;
  1238. // Last pipeline set values.
  1239. bool pipeline_active = false;
  1240. RID pipeline_shader;
  1241. uint32_t invalid_set_from = 0;
  1242. uint32_t pipeline_push_constant_size = 0;
  1243. bool pipeline_push_constant_supplied = false;
  1244. } validation;
  1245. #endif
  1246. };
  1247. ComputeList compute_list;
  1248. ComputeList::State compute_list_barrier_state;
  1249. public:
  1250. ComputeListID compute_list_begin();
  1251. void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline);
  1252. void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index);
  1253. void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size);
  1254. void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups);
  1255. void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads);
  1256. void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset);
  1257. void compute_list_add_barrier(ComputeListID p_list);
  1258. void compute_list_end();
  1259. private:
  1260. /*************************/
  1261. /**** TRANSFER WORKER ****/
  1262. /*************************/
  1263. struct TransferWorker {
  1264. uint32_t index = 0;
  1265. RDD::BufferID staging_buffer;
  1266. uint32_t max_transfer_size = 0;
  1267. uint32_t staging_buffer_size_in_use = 0;
  1268. uint32_t staging_buffer_size_allocated = 0;
  1269. RDD::CommandBufferID command_buffer;
  1270. RDD::CommandPoolID command_pool;
  1271. RDD::FenceID command_fence;
  1272. LocalVector<RDD::TextureBarrier> texture_barriers;
  1273. bool recording = false;
  1274. bool submitted = false;
  1275. BinaryMutex thread_mutex;
  1276. uint64_t operations_processed = 0;
  1277. uint64_t operations_submitted = 0;
  1278. uint64_t operations_counter = 0;
  1279. BinaryMutex operations_mutex;
  1280. };
  1281. LocalVector<TransferWorker *> transfer_worker_pool;
  1282. uint32_t transfer_worker_pool_max_size = 1;
  1283. LocalVector<uint64_t> transfer_worker_operation_used_by_draw;
  1284. LocalVector<uint32_t> transfer_worker_pool_available_list;
  1285. LocalVector<RDD::TextureBarrier> transfer_worker_pool_texture_barriers;
  1286. BinaryMutex transfer_worker_pool_mutex;
  1287. BinaryMutex transfer_worker_pool_texture_barriers_mutex;
  1288. ConditionVariable transfer_worker_pool_condition;
  1289. TransferWorker *_acquire_transfer_worker(uint32_t p_transfer_size, uint32_t p_required_align, uint32_t &r_staging_offset);
  1290. void _release_transfer_worker(TransferWorker *p_transfer_worker);
  1291. void _end_transfer_worker(TransferWorker *p_transfer_worker);
  1292. void _submit_transfer_worker(TransferWorker *p_transfer_worker, VectorView<RDD::SemaphoreID> p_signal_semaphores = VectorView<RDD::SemaphoreID>());
  1293. void _wait_for_transfer_worker(TransferWorker *p_transfer_worker);
  1294. void _flush_barriers_for_transfer_worker(TransferWorker *p_transfer_worker);
  1295. void _check_transfer_worker_operation(uint32_t p_transfer_worker_index, uint64_t p_transfer_worker_operation);
  1296. void _check_transfer_worker_buffer(Buffer *p_buffer);
  1297. void _check_transfer_worker_texture(Texture *p_texture);
  1298. void _check_transfer_worker_vertex_array(VertexArray *p_vertex_array);
  1299. void _check_transfer_worker_index_array(IndexArray *p_index_array);
  1300. void _submit_transfer_workers(RDD::CommandBufferID p_draw_command_buffer = RDD::CommandBufferID());
  1301. void _submit_transfer_barriers(RDD::CommandBufferID p_draw_command_buffer);
  1302. void _wait_for_transfer_workers();
  1303. void _free_transfer_workers();
  1304. /***********************/
  1305. /**** COMMAND GRAPH ****/
  1306. /***********************/
  1307. bool _texture_make_mutable(Texture *p_texture, RID p_texture_id);
  1308. bool _buffer_make_mutable(Buffer *p_buffer, RID p_buffer_id);
  1309. bool _vertex_array_make_mutable(VertexArray *p_vertex_array, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);
  1310. bool _index_array_make_mutable(IndexArray *p_index_array, RDG::ResourceTracker *p_resource_tracker);
  1311. bool _uniform_set_make_mutable(UniformSet *p_uniform_set, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);
  1312. bool _dependency_make_mutable(RID p_id, RID p_resource_id, RDG::ResourceTracker *p_resource_tracker);
  1313. bool _dependencies_make_mutable_recursive(RID p_id, RDG::ResourceTracker *p_resource_tracker);
  1314. bool _dependencies_make_mutable(RID p_id, RDG::ResourceTracker *p_resource_tracker);
  1315. RenderingDeviceGraph draw_graph;
  1316. /**************************/
  1317. /**** QUEUE MANAGEMENT ****/
  1318. /**************************/
  1319. RDD::CommandQueueFamilyID main_queue_family;
  1320. RDD::CommandQueueFamilyID transfer_queue_family;
  1321. RDD::CommandQueueFamilyID present_queue_family;
  1322. RDD::CommandQueueID main_queue;
  1323. RDD::CommandQueueID transfer_queue;
  1324. RDD::CommandQueueID present_queue;
  1325. /**************************/
  1326. /**** FRAME MANAGEMENT ****/
  1327. /**************************/
  1328. // This is the frame structure. There are normally
  1329. // 3 of these (used for triple buffering), or 2
  1330. // (double buffering). They are cycled constantly.
  1331. //
  1332. // It contains two command buffers, one that is
  1333. // used internally for setting up (creating stuff)
  1334. // and another used mostly for drawing.
  1335. //
  1336. // They also contains a list of things that need
  1337. // to be disposed of when deleted, which can't
  1338. // happen immediately due to the asynchronous
  1339. // nature of the GPU. They will get deleted
  1340. // when the frame is cycled.
  1341. struct Frame {
  1342. // List in usage order, from last to free to first to free.
  1343. List<Buffer> buffers_to_dispose_of;
  1344. List<Texture> textures_to_dispose_of;
  1345. List<Framebuffer> framebuffers_to_dispose_of;
  1346. List<RDD::SamplerID> samplers_to_dispose_of;
  1347. List<Shader> shaders_to_dispose_of;
  1348. List<UniformSet> uniform_sets_to_dispose_of;
  1349. List<RenderPipeline> render_pipelines_to_dispose_of;
  1350. List<ComputePipeline> compute_pipelines_to_dispose_of;
  1351. // Pending asynchronous data transfer for buffers.
  1352. LocalVector<RDD::BufferID> download_buffer_staging_buffers;
  1353. LocalVector<RDD::BufferCopyRegion> download_buffer_copy_regions;
  1354. LocalVector<BufferGetDataRequest> download_buffer_get_data_requests;
  1355. // Pending asynchronous data transfer for textures.
  1356. LocalVector<RDD::BufferID> download_texture_staging_buffers;
  1357. LocalVector<RDD::BufferTextureCopyRegion> download_buffer_texture_copy_regions;
  1358. LocalVector<uint32_t> download_texture_mipmap_offsets;
  1359. LocalVector<TextureGetDataRequest> download_texture_get_data_requests;
  1360. // The command pool used by the command buffer.
  1361. RDD::CommandPoolID command_pool;
  1362. // The command buffer used by the main thread when recording the frame.
  1363. RDD::CommandBufferID command_buffer;
  1364. // Signaled by the command buffer submission. Present must wait on this semaphore.
  1365. RDD::SemaphoreID semaphore;
  1366. // Signaled by the command buffer submission. Must wait on this fence before beginning command recording for the frame.
  1367. RDD::FenceID fence;
  1368. bool fence_signaled = false;
  1369. // Semaphores the frame must wait on before executing the command buffer.
  1370. LocalVector<RDD::SemaphoreID> semaphores_to_wait_on;
  1371. // Swap chains prepared for drawing during the frame that must be presented.
  1372. LocalVector<RDD::SwapChainID> swap_chains_to_present;
  1373. // Semaphores the transfer workers can use to wait before rendering the frame.
  1374. // This must have the same size of the transfer worker pool.
  1375. TightLocalVector<RDD::SemaphoreID> transfer_worker_semaphores;
  1376. // Extra command buffer pool used for driver workarounds or to reduce GPU bubbles by
  1377. // splitting the final render pass to the swapchain into its own cmd buffer.
  1378. RDG::CommandBufferPool command_buffer_pool;
  1379. struct Timestamp {
  1380. String description;
  1381. uint64_t value = 0;
  1382. };
  1383. RDD::QueryPoolID timestamp_pool;
  1384. TightLocalVector<String> timestamp_names;
  1385. TightLocalVector<uint64_t> timestamp_cpu_values;
  1386. uint32_t timestamp_count = 0;
  1387. TightLocalVector<String> timestamp_result_names;
  1388. TightLocalVector<uint64_t> timestamp_cpu_result_values;
  1389. TightLocalVector<uint64_t> timestamp_result_values;
  1390. uint32_t timestamp_result_count = 0;
  1391. uint64_t index = 0;
  1392. };
  1393. uint32_t max_timestamp_query_elements = 0;
  1394. int frame = 0;
  1395. TightLocalVector<Frame> frames;
  1396. uint64_t frames_drawn = 0;
  1397. // Whenever logic/physics request a graphics operation (not just deleting a resource) that requires
  1398. // us to flush all graphics commands, we must set frames_pending_resources_for_processing = frames.size().
  1399. // This is important for when the user requested for the logic loop to still be updated while
  1400. // graphics should not (e.g. headless Multiplayer servers, minimized windows that need to still
  1401. // process something on the background).
  1402. uint32_t frames_pending_resources_for_processing = 0u;
  1403. public:
  1404. bool has_pending_resources_for_processing() const { return frames_pending_resources_for_processing != 0u; }
  1405. private:
  1406. void _free_pending_resources(int p_frame);
  1407. uint64_t texture_memory = 0;
  1408. uint64_t buffer_memory = 0;
  1409. protected:
  1410. void execute_chained_cmds(bool p_present_swap_chain,
  1411. RenderingDeviceDriver::FenceID p_draw_fence,
  1412. RenderingDeviceDriver::SemaphoreID p_dst_draw_semaphore_to_signal);
  1413. public:
  1414. void _free_internal(RID p_id);
  1415. void _begin_frame(bool p_presented = false);
  1416. void _end_frame();
  1417. void _execute_frame(bool p_present);
  1418. void _stall_for_frame(uint32_t p_frame);
  1419. void _stall_for_previous_frames();
  1420. void _flush_and_stall_for_all_frames(bool p_begin_frame = true);
  1421. template <typename T>
  1422. void _free_rids(T &p_owner, const char *p_type);
  1423. #ifdef DEV_ENABLED
  1424. HashMap<RID, String> resource_names;
  1425. #endif
  1426. public:
  1427. Error initialize(RenderingContextDriver *p_context, DisplayServer::WindowID p_main_window = DisplayServer::INVALID_WINDOW_ID);
  1428. void finalize();
  1429. void _set_max_fps(int p_max_fps);
  1430. void free_rid(RID p_rid);
  1431. #ifndef DISABLE_DEPRECATED
  1432. [[deprecated("Use `free_rid()` instead.")]] void free(RID p_rid) {
  1433. free_rid(p_rid);
  1434. }
  1435. #endif // DISABLE_DEPRECATED
  1436. /****************/
  1437. /**** Timing ****/
  1438. /****************/
  1439. void capture_timestamp(const String &p_name);
  1440. uint32_t get_captured_timestamps_count() const;
  1441. uint64_t get_captured_timestamps_frame() const;
  1442. uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const;
  1443. uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;
  1444. String get_captured_timestamp_name(uint32_t p_index) const;
  1445. /****************/
  1446. /**** LIMITS ****/
  1447. /****************/
  1448. uint64_t limit_get(Limit p_limit) const;
  1449. void swap_buffers(bool p_present);
  1450. uint32_t get_frame_delay() const;
  1451. void submit();
  1452. void sync();
  1453. enum MemoryType {
  1454. MEMORY_TEXTURES,
  1455. MEMORY_BUFFERS,
  1456. MEMORY_TOTAL
  1457. };
  1458. uint64_t get_memory_usage(MemoryType p_type) const;
  1459. RenderingDevice *create_local_device();
  1460. void set_resource_name(RID p_id, const String &p_name);
  1461. void _draw_command_begin_label(String p_label_name, const Color &p_color = Color(1, 1, 1, 1));
  1462. void draw_command_begin_label(const Span<char> p_label_name, const Color &p_color = Color(1, 1, 1, 1));
  1463. void draw_command_end_label();
  1464. String get_device_vendor_name() const;
  1465. String get_device_name() const;
  1466. DeviceType get_device_type() const;
  1467. String get_device_api_name() const;
  1468. String get_device_api_version() const;
  1469. String get_device_pipeline_cache_uuid() const;
  1470. uint64_t get_frames_drawn() const { return frames_drawn; }
  1471. bool is_composite_alpha_supported() const;
  1472. uint64_t get_driver_resource(DriverResource p_resource, RID p_rid = RID(), uint64_t p_index = 0);
  1473. String get_driver_and_device_memory_report() const;
  1474. String get_tracked_object_name(uint32_t p_type_index) const;
  1475. uint64_t get_tracked_object_type_count() const;
  1476. uint64_t get_driver_total_memory() const;
  1477. uint64_t get_driver_allocation_count() const;
  1478. uint64_t get_driver_memory_by_object_type(uint32_t p_type) const;
  1479. uint64_t get_driver_allocs_by_object_type(uint32_t p_type) const;
  1480. uint64_t get_device_total_memory() const;
  1481. uint64_t get_device_allocation_count() const;
  1482. uint64_t get_device_memory_by_object_type(uint32_t p_type) const;
  1483. uint64_t get_device_allocs_by_object_type(uint32_t p_type) const;
  1484. static RenderingDevice *get_singleton();
  1485. void make_current();
  1486. RenderingDevice();
  1487. ~RenderingDevice();
  1488. private:
  1489. /*****************/
  1490. /**** BINDERS ****/
  1491. /*****************/
  1492. RID _texture_create(const Ref<RDTextureFormat> &p_format, const Ref<RDTextureView> &p_view, const TypedArray<PackedByteArray> &p_data = Array());
  1493. RID _texture_create_shared(const Ref<RDTextureView> &p_view, RID p_with_texture);
  1494. 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);
  1495. Ref<RDTextureFormat> _texture_get_format(RID p_rd_texture);
  1496. FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments, uint32_t p_view_count);
  1497. FramebufferFormatID _framebuffer_format_create_multipass(const TypedArray<RDAttachmentFormat> &p_attachments, const TypedArray<RDFramebufferPass> &p_passes, uint32_t p_view_count);
  1498. RID _framebuffer_create(const TypedArray<RID> &p_textures, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  1499. 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);
  1500. RID _sampler_create(const Ref<RDSamplerState> &p_state);
  1501. VertexFormatID _vertex_format_create(const TypedArray<RDVertexAttribute> &p_vertex_formats);
  1502. 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>());
  1503. void _draw_list_bind_vertex_buffers_format(DrawListID p_list, VertexFormatID p_vertex_format, uint32_t p_vertex_count, const TypedArray<RID> &p_vertex_buffers, const Vector<int64_t> &p_offsets = Vector<int64_t>());
  1504. Ref<RDShaderSPIRV> _shader_compile_spirv_from_source(const Ref<RDShaderSource> &p_source, bool p_allow_cache = true);
  1505. Vector<uint8_t> _shader_compile_binary_from_spirv(const Ref<RDShaderSPIRV> &p_bytecode, const String &p_shader_name = "");
  1506. RID _shader_create_from_spirv(const Ref<RDShaderSPIRV> &p_spirv, const String &p_shader_name = "");
  1507. RID _uniform_set_create(const TypedArray<RDUniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
  1508. Error _buffer_update_bind(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data);
  1509. 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);
  1510. RID _compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants);
  1511. void _draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  1512. void _compute_list_set_push_constant(ComputeListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  1513. };
  1514. VARIANT_ENUM_CAST(RenderingDevice::DeviceType)
  1515. VARIANT_ENUM_CAST(RenderingDevice::DriverResource)
  1516. VARIANT_ENUM_CAST(RenderingDevice::ShaderStage)
  1517. VARIANT_ENUM_CAST(RenderingDevice::ShaderLanguage)
  1518. VARIANT_ENUM_CAST(RenderingDevice::CompareOperator)
  1519. VARIANT_ENUM_CAST(RenderingDevice::DataFormat)
  1520. VARIANT_ENUM_CAST(RenderingDevice::TextureType)
  1521. VARIANT_ENUM_CAST(RenderingDevice::TextureSamples)
  1522. VARIANT_BITFIELD_CAST(RenderingDevice::TextureUsageBits)
  1523. VARIANT_ENUM_CAST(RenderingDevice::TextureSwizzle)
  1524. VARIANT_ENUM_CAST(RenderingDevice::TextureSliceType)
  1525. VARIANT_ENUM_CAST(RenderingDevice::SamplerFilter)
  1526. VARIANT_ENUM_CAST(RenderingDevice::SamplerRepeatMode)
  1527. VARIANT_ENUM_CAST(RenderingDevice::SamplerBorderColor)
  1528. VARIANT_ENUM_CAST(RenderingDevice::VertexFrequency)
  1529. VARIANT_ENUM_CAST(RenderingDevice::IndexBufferFormat)
  1530. VARIANT_BITFIELD_CAST(RenderingDevice::StorageBufferUsage)
  1531. VARIANT_BITFIELD_CAST(RenderingDevice::BufferCreationBits)
  1532. VARIANT_ENUM_CAST(RenderingDevice::UniformType)
  1533. VARIANT_ENUM_CAST(RenderingDevice::RenderPrimitive)
  1534. VARIANT_ENUM_CAST(RenderingDevice::PolygonCullMode)
  1535. VARIANT_ENUM_CAST(RenderingDevice::PolygonFrontFace)
  1536. VARIANT_ENUM_CAST(RenderingDevice::StencilOperation)
  1537. VARIANT_ENUM_CAST(RenderingDevice::LogicOperation)
  1538. VARIANT_ENUM_CAST(RenderingDevice::BlendFactor)
  1539. VARIANT_ENUM_CAST(RenderingDevice::BlendOperation)
  1540. VARIANT_BITFIELD_CAST(RenderingDevice::PipelineDynamicStateFlags)
  1541. VARIANT_ENUM_CAST(RenderingDevice::PipelineSpecializationConstantType)
  1542. VARIANT_ENUM_CAST(RenderingDevice::Limit)
  1543. VARIANT_ENUM_CAST(RenderingDevice::MemoryType)
  1544. VARIANT_ENUM_CAST(RenderingDevice::Features)
  1545. VARIANT_ENUM_CAST(RenderingDevice::BreadcrumbMarker)
  1546. VARIANT_BITFIELD_CAST(RenderingDevice::DrawFlags);
  1547. #ifndef DISABLE_DEPRECATED
  1548. VARIANT_BITFIELD_CAST(RenderingDevice::BarrierMask);
  1549. VARIANT_ENUM_CAST(RenderingDevice::InitialAction)
  1550. VARIANT_ENUM_CAST(RenderingDevice::FinalAction)
  1551. #endif
  1552. typedef RenderingDevice RD;