rendering_device.h 57 KB

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