2
0

rendering_device.h 58 KB

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