rendering_device_vulkan.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. /*************************************************************************/
  2. /* rendering_device_vulkan.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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_VULKAN_H
  31. #define RENDERING_DEVICE_VULKAN_H
  32. #include "core/os/thread_safe.h"
  33. #include "core/templates/local_vector.h"
  34. #include "core/templates/oa_hash_map.h"
  35. #include "core/templates/rid_owner.h"
  36. #include "servers/rendering/rendering_device.h"
  37. #ifdef DEBUG_ENABLED
  38. #ifndef _DEBUG
  39. #define _DEBUG
  40. #endif
  41. #endif
  42. #include "vk_mem_alloc.h"
  43. #include <vulkan/vulkan.h>
  44. class VulkanContext;
  45. class RenderingDeviceVulkan : public RenderingDevice {
  46. _THREAD_SAFE_CLASS_
  47. // Miscellaneous tables that map
  48. // our enums to enums used
  49. // by vulkan.
  50. VkPhysicalDeviceLimits limits;
  51. static const VkFormat vulkan_formats[DATA_FORMAT_MAX];
  52. static const char *named_formats[DATA_FORMAT_MAX];
  53. static const VkCompareOp compare_operators[COMPARE_OP_MAX];
  54. static const VkStencilOp stencil_operations[STENCIL_OP_MAX];
  55. static const VkSampleCountFlagBits rasterization_sample_count[TEXTURE_SAMPLES_MAX];
  56. static const VkLogicOp logic_operations[RenderingDevice::LOGIC_OP_MAX];
  57. static const VkBlendFactor blend_factors[RenderingDevice::BLEND_FACTOR_MAX];
  58. static const VkBlendOp blend_operations[RenderingDevice::BLEND_OP_MAX];
  59. static const VkSamplerAddressMode address_modes[SAMPLER_REPEAT_MODE_MAX];
  60. static const VkBorderColor sampler_border_colors[SAMPLER_BORDER_COLOR_MAX];
  61. static const VkImageType vulkan_image_type[TEXTURE_TYPE_MAX];
  62. // Functions used for format
  63. // validation, and ensures the
  64. // user passes valid data.
  65. static int get_format_vertex_size(DataFormat p_format);
  66. static uint32_t get_image_format_pixel_size(DataFormat p_format);
  67. static void get_compressed_image_format_block_dimensions(DataFormat p_format, uint32_t &r_w, uint32_t &r_h);
  68. uint32_t get_compressed_image_format_block_byte_size(DataFormat p_format);
  69. static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format);
  70. static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = nullptr, uint32_t *r_blockh = nullptr, uint32_t *r_depth = nullptr);
  71. static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth);
  72. static bool format_has_stencil(DataFormat p_format);
  73. /***************************/
  74. /**** ID INFRASTRUCTURE ****/
  75. /***************************/
  76. enum IDType {
  77. ID_TYPE_FRAMEBUFFER_FORMAT,
  78. ID_TYPE_VERTEX_FORMAT,
  79. ID_TYPE_DRAW_LIST,
  80. ID_TYPE_SPLIT_DRAW_LIST,
  81. ID_TYPE_COMPUTE_LIST,
  82. ID_TYPE_MAX,
  83. ID_BASE_SHIFT = 58 //5 bits for ID types
  84. };
  85. VkDevice device = VK_NULL_HANDLE;
  86. Map<RID, Set<RID>> dependency_map; //IDs to IDs that depend on it
  87. Map<RID, Set<RID>> reverse_dependency_map; //same as above, but in reverse
  88. void _add_dependency(RID p_id, RID p_depends_on);
  89. void _free_dependencies(RID p_id);
  90. /*****************/
  91. /**** TEXTURE ****/
  92. /*****************/
  93. // In Vulkan, the concept of textures does not exist,
  94. // instead there is the image (the memory pretty much,
  95. // the view (how the memory is interpreted) and the
  96. // sampler (how it's sampled from the shader).
  97. //
  98. // Texture here includes the first two stages, but
  99. // It's possible to create textures sharing the image
  100. // but with different views. The main use case for this
  101. // is textures that can be read as both SRGB/Linear,
  102. // or slices of a texture (a mipmap, a layer, a 3D slice)
  103. // for a framebuffer to render into it.
  104. struct Texture {
  105. VkImage image = VK_NULL_HANDLE;
  106. VmaAllocation allocation = nullptr;
  107. VmaAllocationInfo allocation_info;
  108. VkImageView view = VK_NULL_HANDLE;
  109. TextureType type;
  110. DataFormat format;
  111. TextureSamples samples;
  112. uint32_t width = 0;
  113. uint32_t height = 0;
  114. uint32_t depth = 0;
  115. uint32_t layers = 0;
  116. uint32_t mipmaps = 0;
  117. uint32_t usage_flags = 0;
  118. uint32_t base_mipmap = 0;
  119. uint32_t base_layer = 0;
  120. Vector<DataFormat> allowed_shared_formats;
  121. VkImageLayout layout;
  122. uint64_t used_in_frame = 0;
  123. bool used_in_transfer = false;
  124. bool used_in_raster = false;
  125. bool used_in_compute = false;
  126. uint32_t read_aspect_mask = 0;
  127. uint32_t barrier_aspect_mask = 0;
  128. bool bound = false; //bound to framebffer
  129. RID owner;
  130. };
  131. RID_Owner<Texture, true> texture_owner;
  132. uint32_t texture_upload_region_size_px = 0;
  133. Vector<uint8_t> _texture_get_data_from_image(Texture *tex, VkImage p_image, VmaAllocation p_allocation, uint32_t p_layer, bool p_2d = false);
  134. /*****************/
  135. /**** SAMPLER ****/
  136. /*****************/
  137. RID_Owner<VkSampler> sampler_owner;
  138. /***************************/
  139. /**** BUFFER MANAGEMENT ****/
  140. /***************************/
  141. // These are temporary buffers on CPU memory that hold
  142. // the information until the CPU fetches it and places it
  143. // either on GPU buffers, or images (textures). It ensures
  144. // updates are properly synchronized with whathever the
  145. // GPU is doing.
  146. //
  147. // The logic here is as follows, only 3 of these
  148. // blocks are created at the beginning (one per frame)
  149. // they can each belong to a frame (assigned to current when
  150. // used) and they can only be reused after the same frame is
  151. // recycled.
  152. //
  153. // When CPU requires to allocate more than what is available,
  154. // more of these buffers are created. If a limit is reached,
  155. // then a fence will ensure will wait for blocks allocated
  156. // in previous frames are processed. If that fails, then
  157. // another fence will ensure everything pending for the current
  158. // frame is processed (effectively stalling).
  159. //
  160. // See the comments in the code to understand better how it works.
  161. struct StagingBufferBlock {
  162. VkBuffer buffer = VK_NULL_HANDLE;
  163. VmaAllocation allocation = nullptr;
  164. uint64_t frame_used = 0;
  165. uint32_t fill_amount = 0;
  166. };
  167. Vector<StagingBufferBlock> staging_buffer_blocks;
  168. int staging_buffer_current = 0;
  169. uint32_t staging_buffer_block_size = 0;
  170. uint64_t staging_buffer_max_size = 0;
  171. bool staging_buffer_used = false;
  172. Error _staging_buffer_allocate(uint32_t p_amount, uint32_t p_required_align, uint32_t &r_alloc_offset, uint32_t &r_alloc_size, bool p_can_segment = true, bool p_on_draw_command_buffer = false);
  173. Error _insert_staging_block();
  174. struct Buffer {
  175. uint32_t size = 0;
  176. uint32_t usage = 0;
  177. VkBuffer buffer = VK_NULL_HANDLE;
  178. VmaAllocation allocation = nullptr;
  179. VkDescriptorBufferInfo buffer_info; //used for binding
  180. Buffer() {
  181. }
  182. };
  183. Error _buffer_allocate(Buffer *p_buffer, uint32_t p_size, uint32_t p_usage, VmaMemoryUsage p_mapping);
  184. Error _buffer_free(Buffer *p_buffer);
  185. Error _buffer_update(Buffer *p_buffer, size_t p_offset, const uint8_t *p_data, size_t p_data_size, bool p_use_draw_command_buffer = false, uint32_t p_required_align = 32);
  186. void _full_barrier(bool p_sync_with_draw);
  187. void _memory_barrier(VkPipelineStageFlags p_src_stage_mask, VkPipelineStageFlags p_dst_stage_mask, VkAccessFlags p_src_access, VkAccessFlags p_dst_sccess, bool p_sync_with_draw);
  188. void _buffer_memory_barrier(VkBuffer buffer, uint64_t p_from, uint64_t p_size, VkPipelineStageFlags p_src_stage_mask, VkPipelineStageFlags p_dst_stage_mask, VkAccessFlags p_src_access, VkAccessFlags p_dst_sccess, bool p_sync_with_draw);
  189. /*********************/
  190. /**** FRAMEBUFFER ****/
  191. /*********************/
  192. // In Vulkan, framebuffers work similar to how they
  193. // do in OpenGL, with the exception that
  194. // the "format" (vkRenderPass) is not dynamic
  195. // and must be more or less the same as the one
  196. // used for the render pipelines.
  197. struct FramebufferFormatKey {
  198. Vector<AttachmentFormat> attachments;
  199. uint32_t view_count = 1;
  200. bool operator<(const FramebufferFormatKey &p_key) const {
  201. if (view_count != p_key.view_count) {
  202. return view_count < p_key.view_count;
  203. }
  204. int as = attachments.size();
  205. int bs = p_key.attachments.size();
  206. if (as != bs) {
  207. return as < bs;
  208. }
  209. const AttachmentFormat *af_a = attachments.ptr();
  210. const AttachmentFormat *af_b = p_key.attachments.ptr();
  211. for (int i = 0; i < as; i++) {
  212. const AttachmentFormat &a = af_a[i];
  213. const AttachmentFormat &b = af_b[i];
  214. if (a.format != b.format) {
  215. return a.format < b.format;
  216. }
  217. if (a.samples != b.samples) {
  218. return a.samples < b.samples;
  219. }
  220. if (a.usage_flags != b.usage_flags) {
  221. return a.usage_flags < b.usage_flags;
  222. }
  223. }
  224. return false; //equal
  225. }
  226. };
  227. VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depthcolor_action, int *r_color_attachment_count = nullptr, uint32_t p_view_count = 1);
  228. // This is a cache and it's never freed, it ensures
  229. // IDs for a given format are always unique.
  230. Map<FramebufferFormatKey, FramebufferFormatID> framebuffer_format_cache;
  231. struct FramebufferFormat {
  232. const Map<FramebufferFormatKey, FramebufferFormatID>::Element *E;
  233. VkRenderPass render_pass = VK_NULL_HANDLE; //here for constructing shaders, never used, see section (7.2. Render Pass Compatibility from Vulkan spec)
  234. int color_attachments = 0; //used for pipeline validation
  235. TextureSamples samples;
  236. uint32_t view_count = 1; // number of views
  237. };
  238. Map<FramebufferFormatID, FramebufferFormat> framebuffer_formats;
  239. struct Framebuffer {
  240. FramebufferFormatID format_id = 0;
  241. struct VersionKey {
  242. InitialAction initial_color_action;
  243. FinalAction final_color_action;
  244. InitialAction initial_depth_action;
  245. FinalAction final_depth_action;
  246. uint32_t view_count;
  247. bool operator<(const VersionKey &p_key) const {
  248. if (initial_color_action == p_key.initial_color_action) {
  249. if (final_color_action == p_key.final_color_action) {
  250. if (initial_depth_action == p_key.initial_depth_action) {
  251. if (final_depth_action == p_key.final_depth_action) {
  252. return view_count < p_key.view_count;
  253. } else {
  254. return final_depth_action < p_key.final_depth_action;
  255. }
  256. } else {
  257. return initial_depth_action < p_key.initial_depth_action;
  258. }
  259. } else {
  260. return final_color_action < p_key.final_color_action;
  261. }
  262. } else {
  263. return initial_color_action < p_key.initial_color_action;
  264. }
  265. }
  266. };
  267. uint32_t storage_mask = 0;
  268. Vector<RID> texture_ids;
  269. struct Version {
  270. VkFramebuffer framebuffer = VK_NULL_HANDLE;
  271. VkRenderPass render_pass = VK_NULL_HANDLE; //this one is owned
  272. };
  273. Map<VersionKey, Version> framebuffers;
  274. Size2 size;
  275. uint32_t view_count;
  276. };
  277. RID_Owner<Framebuffer, true> framebuffer_owner;
  278. /***********************/
  279. /**** VERTEX BUFFER ****/
  280. /***********************/
  281. // Vertex buffers in Vulkan are similar to how
  282. // they work in OpenGL, except that instead of
  283. // an attribute index, there is a buffer binding
  284. // index (for binding the buffers in real-time)
  285. // and a location index (what is used in the shader).
  286. //
  287. // This mapping is done here internally, and it's not
  288. // exposed.
  289. RID_Owner<Buffer, true> vertex_buffer_owner;
  290. struct VertexDescriptionKey {
  291. Vector<VertexAttribute> vertex_formats;
  292. bool operator==(const VertexDescriptionKey &p_key) const {
  293. int vdc = vertex_formats.size();
  294. int vdck = p_key.vertex_formats.size();
  295. if (vdc != vdck) {
  296. return false;
  297. } else {
  298. const VertexAttribute *a_ptr = vertex_formats.ptr();
  299. const VertexAttribute *b_ptr = p_key.vertex_formats.ptr();
  300. for (int i = 0; i < vdc; i++) {
  301. const VertexAttribute &a = a_ptr[i];
  302. const VertexAttribute &b = b_ptr[i];
  303. if (a.location != b.location) {
  304. return false;
  305. }
  306. if (a.offset != b.offset) {
  307. return false;
  308. }
  309. if (a.format != b.format) {
  310. return false;
  311. }
  312. if (a.stride != b.stride) {
  313. return false;
  314. }
  315. if (a.frequency != b.frequency) {
  316. return false;
  317. }
  318. }
  319. return true; //they are equal
  320. }
  321. }
  322. uint32_t hash() const {
  323. int vdc = vertex_formats.size();
  324. uint32_t h = hash_djb2_one_32(vdc);
  325. const VertexAttribute *ptr = vertex_formats.ptr();
  326. for (int i = 0; i < vdc; i++) {
  327. const VertexAttribute &vd = ptr[i];
  328. h = hash_djb2_one_32(vd.location, h);
  329. h = hash_djb2_one_32(vd.offset, h);
  330. h = hash_djb2_one_32(vd.format, h);
  331. h = hash_djb2_one_32(vd.stride, h);
  332. h = hash_djb2_one_32(vd.frequency, h);
  333. }
  334. return h;
  335. }
  336. };
  337. struct VertexDescriptionHash {
  338. static _FORCE_INLINE_ uint32_t hash(const VertexDescriptionKey &p_key) {
  339. return p_key.hash();
  340. }
  341. };
  342. // This is a cache and it's never freed, it ensures that
  343. // ID used for a specific format always remain the same.
  344. HashMap<VertexDescriptionKey, VertexFormatID, VertexDescriptionHash> vertex_format_cache;
  345. struct VertexDescriptionCache {
  346. Vector<VertexAttribute> vertex_formats;
  347. VkVertexInputBindingDescription *bindings = nullptr;
  348. VkVertexInputAttributeDescription *attributes = nullptr;
  349. VkPipelineVertexInputStateCreateInfo create_info;
  350. };
  351. Map<VertexFormatID, VertexDescriptionCache> vertex_formats;
  352. struct VertexArray {
  353. RID buffer;
  354. VertexFormatID description = 0;
  355. int vertex_count = 0;
  356. uint32_t max_instances_allowed = 0;
  357. Vector<VkBuffer> buffers; //not owned, just referenced
  358. Vector<VkDeviceSize> offsets;
  359. };
  360. RID_Owner<VertexArray, true> vertex_array_owner;
  361. struct IndexBuffer : public Buffer {
  362. uint32_t max_index = 0; //used for validation
  363. uint32_t index_count = 0;
  364. VkIndexType index_type = VK_INDEX_TYPE_NONE_NV;
  365. bool supports_restart_indices = false;
  366. };
  367. RID_Owner<IndexBuffer, true> index_buffer_owner;
  368. struct IndexArray {
  369. uint32_t max_index = 0; //remember the maximum index here too, for validation
  370. VkBuffer buffer; //not owned, inherited from index buffer
  371. uint32_t offset = 0;
  372. uint32_t indices = 0;
  373. VkIndexType index_type = VK_INDEX_TYPE_NONE_NV;
  374. bool supports_restart_indices = false;
  375. };
  376. RID_Owner<IndexArray, true> index_array_owner;
  377. /****************/
  378. /**** SHADER ****/
  379. /****************/
  380. // Vulkan specifies a really complex behavior for the application
  381. // in order to tell when descriptor sets need to be re-bound (or not).
  382. // "When binding a descriptor set (see Descriptor Set Binding) to set
  383. // number N, if the previously bound descriptor sets for sets zero
  384. // through N-1 were all bound using compatible pipeline layouts,
  385. // then performing this binding does not disturb any of the lower numbered sets.
  386. // If, additionally, the previous bound descriptor set for set N was
  387. // bound using a pipeline layout compatible for set N, then the bindings
  388. // in sets numbered greater than N are also not disturbed."
  389. // As a result, we need to figure out quickly when something is no longer "compatible".
  390. // in order to avoid costly rebinds.
  391. enum {
  392. MAX_UNIFORM_SETS = 16
  393. };
  394. struct UniformInfo {
  395. UniformType type = UniformType::UNIFORM_TYPE_MAX;
  396. int binding = 0;
  397. uint32_t stages = 0;
  398. int length = 0; //size of arrays (in total elements), or ubos (in bytes * total elements)
  399. bool operator!=(const UniformInfo &p_info) const {
  400. return (binding != p_info.binding || type != p_info.type || stages != p_info.stages || length != p_info.length);
  401. }
  402. bool operator<(const UniformInfo &p_info) const {
  403. if (binding != p_info.binding) {
  404. return binding < p_info.binding;
  405. }
  406. if (type != p_info.type) {
  407. return type < p_info.type;
  408. }
  409. if (stages != p_info.stages) {
  410. return stages < p_info.stages;
  411. }
  412. return length < p_info.length;
  413. }
  414. };
  415. struct UniformSetFormat {
  416. Vector<UniformInfo> uniform_info;
  417. bool operator<(const UniformSetFormat &p_format) const {
  418. uint32_t size = uniform_info.size();
  419. uint32_t psize = p_format.uniform_info.size();
  420. if (size != psize) {
  421. return size < psize;
  422. }
  423. const UniformInfo *infoptr = uniform_info.ptr();
  424. const UniformInfo *pinfoptr = p_format.uniform_info.ptr();
  425. for (uint32_t i = 0; i < size; i++) {
  426. if (infoptr[i] != pinfoptr[i]) {
  427. return infoptr[i] < pinfoptr[i];
  428. }
  429. }
  430. return false;
  431. }
  432. };
  433. // Always grows, never shrinks, ensuring unique IDs, but we assume
  434. // the amount of formats will never be a problem, as the amount of shaders
  435. // in a game is limited.
  436. Map<UniformSetFormat, uint32_t> uniform_set_format_cache;
  437. // Shaders in Vulkan are just pretty much
  438. // precompiled blocks of SPIR-V bytecode. They
  439. // are most likely not really compiled to host
  440. // assembly until a pipeline is created.
  441. //
  442. // When supplying the shaders, this implementation
  443. // will use the reflection abilities of glslang to
  444. // understand and cache everything required to
  445. // create and use the descriptor sets (Vulkan's
  446. // biggest pain).
  447. //
  448. // Additionally, hashes are created for every set
  449. // to do quick validation and ensuring the user
  450. // does not submit something invalid.
  451. struct Shader {
  452. struct Set {
  453. Vector<UniformInfo> uniform_info;
  454. VkDescriptorSetLayout descriptor_set_layout = VK_NULL_HANDLE;
  455. };
  456. uint32_t vertex_input_mask = 0; //inputs used, this is mostly for validation
  457. int fragment_outputs = 0;
  458. struct PushConstant {
  459. uint32_t push_constant_size = 0;
  460. uint32_t push_constants_vk_stage = 0;
  461. };
  462. PushConstant push_constant;
  463. uint32_t compute_local_size[3] = { 0, 0, 0 };
  464. bool is_compute = false;
  465. int max_output = 0;
  466. Vector<Set> sets;
  467. Vector<uint32_t> set_formats;
  468. Vector<VkPipelineShaderStageCreateInfo> pipeline_stages;
  469. VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
  470. };
  471. String _shader_uniform_debug(RID p_shader, int p_set = -1);
  472. RID_Owner<Shader, true> shader_owner;
  473. /******************/
  474. /**** UNIFORMS ****/
  475. /******************/
  476. // Descriptor sets require allocation from a pool.
  477. // The documentation on how to use pools properly
  478. // is scarce, and the documentation is strange.
  479. //
  480. // Basically, you can mix and match pools as you
  481. // like, but you'll run into fragmentation issues.
  482. // Because of this, the recommended approach is to
  483. // create a a pool for every descriptor set type,
  484. // as this prevents fragmentation.
  485. //
  486. // This is implemented here as a having a list of
  487. // pools (each can contain up to 64 sets) for each
  488. // set layout. The amount of sets for each type
  489. // is used as the key.
  490. enum {
  491. MAX_DESCRIPTOR_POOL_ELEMENT = 65535
  492. };
  493. struct DescriptorPoolKey {
  494. union {
  495. struct {
  496. uint16_t uniform_type[UNIFORM_TYPE_MAX]; // Using 16 bits because, for sending arrays, each element is a pool set.
  497. };
  498. struct {
  499. uint64_t key1;
  500. uint64_t key2;
  501. uint64_t key3;
  502. };
  503. };
  504. bool operator<(const DescriptorPoolKey &p_key) const {
  505. if (key1 != p_key.key1) {
  506. return key1 < p_key.key1;
  507. }
  508. if (key2 != p_key.key2) {
  509. return key2 < p_key.key2;
  510. }
  511. return key3 < p_key.key3;
  512. }
  513. DescriptorPoolKey() {
  514. key1 = 0;
  515. key2 = 0;
  516. key3 = 0;
  517. }
  518. };
  519. struct DescriptorPool {
  520. VkDescriptorPool pool;
  521. uint32_t usage;
  522. };
  523. Map<DescriptorPoolKey, Set<DescriptorPool *>> descriptor_pools;
  524. uint32_t max_descriptors_per_pool = 0;
  525. DescriptorPool *_descriptor_pool_allocate(const DescriptorPoolKey &p_key);
  526. void _descriptor_pool_free(const DescriptorPoolKey &p_key, DescriptorPool *p_pool);
  527. RID_Owner<Buffer, true> uniform_buffer_owner;
  528. RID_Owner<Buffer, true> storage_buffer_owner;
  529. //texture buffer needs a view
  530. struct TextureBuffer {
  531. Buffer buffer;
  532. VkBufferView view = VK_NULL_HANDLE;
  533. };
  534. RID_Owner<TextureBuffer, true> texture_buffer_owner;
  535. // This structure contains the descriptor set. They _need_ to be allocated
  536. // for a shader (and will be erased when this shader is erased), but should
  537. // work for other shaders as long as the hash matches. This covers using
  538. // them in shader variants.
  539. //
  540. // Keep also in mind that you can share buffers between descriptor sets, so
  541. // the above restriction is not too serious.
  542. struct UniformSet {
  543. uint32_t format = 0;
  544. RID shader_id;
  545. uint32_t shader_set = 0;
  546. DescriptorPool *pool = nullptr;
  547. DescriptorPoolKey pool_key;
  548. VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
  549. //VkPipelineLayout pipeline_layout; //not owned, inherited from shader
  550. struct AttachableTexture {
  551. uint32_t bind;
  552. RID texture;
  553. };
  554. LocalVector<AttachableTexture> attachable_textures; //used for validation
  555. Vector<Texture *> mutable_sampled_textures; //used for layout change
  556. Vector<Texture *> mutable_storage_textures; //used for layout change
  557. };
  558. RID_Owner<UniformSet, true> uniform_set_owner;
  559. /*******************/
  560. /**** PIPELINES ****/
  561. /*******************/
  562. // Render pipeline contains ALL the
  563. // information required for drawing.
  564. // This includes all the rasterizer state
  565. // as well as shader used, framebuffer format,
  566. // etc.
  567. // While the pipeline is just a single object
  568. // (VkPipeline) a lot of values are also saved
  569. // here to do validation (vulkan does none by
  570. // default) and warn the user if something
  571. // was not supplied as intended.
  572. struct RenderPipeline {
  573. //Cached values for validation
  574. #ifdef DEBUG_ENABLED
  575. struct Validation {
  576. FramebufferFormatID framebuffer_format = 0;
  577. uint32_t dynamic_state = 0;
  578. VertexFormatID vertex_format = 0;
  579. bool uses_restart_indices = false;
  580. uint32_t primitive_minimum = 0;
  581. uint32_t primitive_divisor = 0;
  582. } validation;
  583. #endif
  584. //Actual pipeline
  585. RID shader;
  586. Vector<uint32_t> set_formats;
  587. VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; // not owned, needed for push constants
  588. VkPipeline pipeline = VK_NULL_HANDLE;
  589. uint32_t push_constant_size = 0;
  590. uint32_t push_constant_stages = 0;
  591. };
  592. RID_Owner<RenderPipeline, true> render_pipeline_owner;
  593. struct ComputePipeline {
  594. RID shader;
  595. Vector<uint32_t> set_formats;
  596. VkPipelineLayout pipeline_layout = VK_NULL_HANDLE; // not owned, needed for push constants
  597. VkPipeline pipeline = VK_NULL_HANDLE;
  598. uint32_t push_constant_size = 0;
  599. uint32_t push_constant_stages = 0;
  600. uint32_t local_group_size[3] = { 0, 0, 0 };
  601. };
  602. RID_Owner<ComputePipeline, true> compute_pipeline_owner;
  603. /*******************/
  604. /**** DRAW LIST ****/
  605. /*******************/
  606. // Draw list contains both the command buffer
  607. // used for drawing as well as a LOT of
  608. // information used for validation. This
  609. // validation is cheap so most of it can
  610. // also run in release builds.
  611. // When using split command lists, this is
  612. // implemented internally using secondary command
  613. // buffers. As they can be created in threads,
  614. // each needs it's own command pool.
  615. struct SplitDrawListAllocator {
  616. VkCommandPool command_pool = VK_NULL_HANDLE;
  617. Vector<VkCommandBuffer> command_buffers; //one for each frame
  618. };
  619. Vector<SplitDrawListAllocator> split_draw_list_allocators;
  620. struct DrawList {
  621. VkCommandBuffer command_buffer = VK_NULL_HANDLE; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
  622. Rect2i viewport;
  623. struct SetState {
  624. uint32_t pipeline_expected_format = 0;
  625. uint32_t uniform_set_format = 0;
  626. VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
  627. RID uniform_set;
  628. bool bound = false;
  629. };
  630. struct State {
  631. SetState sets[MAX_UNIFORM_SETS];
  632. uint32_t set_count = 0;
  633. RID pipeline;
  634. RID pipeline_shader;
  635. VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
  636. RID vertex_array;
  637. RID index_array;
  638. uint32_t pipeline_push_constant_stages = 0;
  639. } state;
  640. #ifdef DEBUG_ENABLED
  641. struct Validation {
  642. bool active = true; // Means command buffer was not closed, so you can keep adding things.
  643. FramebufferFormatID framebuffer_format = INVALID_ID;
  644. // Actual render pass values.
  645. uint32_t dynamic_state = 0;
  646. VertexFormatID vertex_format = INVALID_ID;
  647. uint32_t vertex_array_size = 0;
  648. uint32_t vertex_max_instances_allowed = 0xFFFFFFFF;
  649. bool index_buffer_uses_restart_indices = false;
  650. uint32_t index_array_size = 0;
  651. uint32_t index_array_max_index = 0;
  652. uint32_t index_array_offset = 0;
  653. Vector<uint32_t> set_formats;
  654. Vector<bool> set_bound;
  655. Vector<RID> set_rids;
  656. // Last pipeline set values.
  657. bool pipeline_active = false;
  658. uint32_t pipeline_dynamic_state = 0;
  659. VertexFormatID pipeline_vertex_format = INVALID_ID;
  660. RID pipeline_shader;
  661. uint32_t invalid_set_from = 0;
  662. bool pipeline_uses_restart_indices = false;
  663. uint32_t pipeline_primitive_divisor = 0;
  664. uint32_t pipeline_primitive_minimum = 0;
  665. Vector<uint32_t> pipeline_set_formats;
  666. uint32_t pipeline_push_constant_size = 0;
  667. bool pipeline_push_constant_supplied = false;
  668. } validation;
  669. #else
  670. struct Validation {
  671. uint32_t vertex_array_size = 0;
  672. uint32_t index_array_size = 0;
  673. uint32_t index_array_offset;
  674. } validation;
  675. #endif
  676. };
  677. DrawList *draw_list = nullptr; // One for regular draw lists, multiple for split.
  678. uint32_t draw_list_count = 0;
  679. bool draw_list_split = false;
  680. Vector<RID> draw_list_bound_textures;
  681. Vector<RID> draw_list_storage_textures;
  682. bool draw_list_unbind_color_textures = false;
  683. bool draw_list_unbind_depth_textures = false;
  684. void _draw_list_insert_clear_region(DrawList *draw_list, Framebuffer *framebuffer, Point2i viewport_offset, Point2i viewport_size, bool p_clear_color, const Vector<Color> &p_clear_colors, bool p_clear_depth, float p_depth, uint32_t p_stencil);
  685. 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, VkFramebuffer *r_framebuffer, VkRenderPass *r_render_pass);
  686. Error _draw_list_render_pass_begin(Framebuffer *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 viewport_offset, Point2i viewport_size, VkFramebuffer vkframebuffer, VkRenderPass render_pass, VkCommandBuffer command_buffer, VkSubpassContents subpass_contents, const Vector<RID> &p_storage_textures);
  687. _FORCE_INLINE_ DrawList *_get_draw_list_ptr(DrawListID p_id);
  688. Buffer *_get_buffer_from_owner(RID p_buffer, VkPipelineStageFlags &dst_stage_mask, VkAccessFlags &dst_access, uint32_t p_post_barrier);
  689. /**********************/
  690. /**** COMPUTE LIST ****/
  691. /**********************/
  692. struct ComputeList {
  693. VkCommandBuffer command_buffer = VK_NULL_HANDLE; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
  694. struct SetState {
  695. uint32_t pipeline_expected_format = 0;
  696. uint32_t uniform_set_format = 0;
  697. VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
  698. RID uniform_set;
  699. bool bound = false;
  700. };
  701. struct State {
  702. Set<Texture *> textures_to_sampled_layout;
  703. SetState sets[MAX_UNIFORM_SETS];
  704. uint32_t set_count = 0;
  705. RID pipeline;
  706. RID pipeline_shader;
  707. uint32_t local_group_size[3] = { 0, 0, 0 };
  708. VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
  709. uint32_t pipeline_push_constant_stages = 0;
  710. bool allow_draw_overlap;
  711. } state;
  712. #ifdef DEBUG_ENABLED
  713. struct Validation {
  714. bool active = true; // Means command buffer was not closed, so you can keep adding things.
  715. Vector<uint32_t> set_formats;
  716. Vector<bool> set_bound;
  717. Vector<RID> set_rids;
  718. // Last pipeline set values.
  719. bool pipeline_active = false;
  720. RID pipeline_shader;
  721. uint32_t invalid_set_from = 0;
  722. Vector<uint32_t> pipeline_set_formats;
  723. uint32_t pipeline_push_constant_size = 0;
  724. bool pipeline_push_constant_supplied = false;
  725. } validation;
  726. #endif
  727. };
  728. ComputeList *compute_list = nullptr;
  729. /**************************/
  730. /**** FRAME MANAGEMENT ****/
  731. /**************************/
  732. // This is the frame structure. There are normally
  733. // 3 of these (used for triple buffering), or 2
  734. // (double buffering). They are cycled constantly.
  735. //
  736. // It contains two command buffers, one that is
  737. // used internally for setting up (creating stuff)
  738. // and another used mostly for drawing.
  739. //
  740. // They also contains a list of things that need
  741. // to be disposed of when deleted, which can't
  742. // happen immediately due to the asynchronous
  743. // nature of the GPU. They will get deleted
  744. // when the frame is cycled.
  745. struct Frame {
  746. //list in usage order, from last to free to first to free
  747. List<Buffer> buffers_to_dispose_of;
  748. List<Texture> textures_to_dispose_of;
  749. List<Framebuffer> framebuffers_to_dispose_of;
  750. List<VkSampler> samplers_to_dispose_of;
  751. List<Shader> shaders_to_dispose_of;
  752. List<VkBufferView> buffer_views_to_dispose_of;
  753. List<UniformSet> uniform_sets_to_dispose_of;
  754. List<RenderPipeline> render_pipelines_to_dispose_of;
  755. List<ComputePipeline> compute_pipelines_to_dispose_of;
  756. VkCommandPool command_pool = VK_NULL_HANDLE;
  757. VkCommandBuffer setup_command_buffer = VK_NULL_HANDLE; //used at the beginning of every frame for set-up
  758. VkCommandBuffer draw_command_buffer = VK_NULL_HANDLE; //used at the beginning of every frame for set-up
  759. struct Timestamp {
  760. String description;
  761. uint64_t value = 0;
  762. };
  763. VkQueryPool timestamp_pool;
  764. String *timestamp_names = nullptr;
  765. uint64_t *timestamp_cpu_values = nullptr;
  766. uint32_t timestamp_count = 0;
  767. String *timestamp_result_names = nullptr;
  768. uint64_t *timestamp_cpu_result_values = nullptr;
  769. uint64_t *timestamp_result_values = nullptr;
  770. uint32_t timestamp_result_count = 0;
  771. uint64_t index = 0;
  772. };
  773. uint32_t max_timestamp_query_elements = 0;
  774. Frame *frames = nullptr; //frames available, for main device they are cycled (usually 3), for local devices only 1
  775. int frame = 0; //current frame
  776. int frame_count = 0; //total amount of frames
  777. uint64_t frames_drawn = 0;
  778. RID local_device;
  779. bool local_device_processing = false;
  780. void _free_pending_resources(int p_frame);
  781. VmaAllocator allocator = nullptr;
  782. VulkanContext *context = nullptr;
  783. void _free_internal(RID p_id);
  784. void _flush(bool p_current_frame);
  785. bool screen_prepared = false;
  786. template <class T>
  787. void _free_rids(T &p_owner, const char *p_type);
  788. void _finalize_command_bufers();
  789. void _begin_frame();
  790. public:
  791. virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>());
  792. virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture);
  793. virtual RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, TextureSliceType p_slice_type = TEXTURE_SLICE_2D);
  794. virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier = BARRIER_MASK_ALL);
  795. virtual Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer);
  796. virtual bool texture_is_format_supported_for_usage(DataFormat p_format, uint32_t p_usage) const;
  797. virtual bool texture_is_shared(RID p_texture);
  798. virtual bool texture_is_valid(RID p_texture);
  799. virtual Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, uint32_t p_post_barrier = BARRIER_MASK_ALL);
  800. virtual Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, uint32_t p_post_barrier = BARRIER_MASK_ALL);
  801. virtual Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture, uint32_t p_post_barrier = BARRIER_MASK_ALL);
  802. /*********************/
  803. /**** FRAMEBUFFER ****/
  804. /*********************/
  805. virtual FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format, uint32_t p_view_count = 1);
  806. virtual FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1);
  807. virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format);
  808. virtual RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID, uint32_t p_view_count = 1);
  809. virtual RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID);
  810. virtual FramebufferFormatID framebuffer_get_format(RID p_framebuffer);
  811. /*****************/
  812. /**** SAMPLER ****/
  813. /*****************/
  814. virtual RID sampler_create(const SamplerState &p_state);
  815. /**********************/
  816. /**** VERTEX ARRAY ****/
  817. /**********************/
  818. virtual RID vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_as_storage = false);
  819. // Internally reference counted, this ID is warranted to be unique for the same description, but needs to be freed as many times as it was allocated
  820. virtual VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_formats);
  821. virtual RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector<RID> &p_src_buffers);
  822. virtual RID index_buffer_create(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_restart_indices = false);
  823. virtual RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count);
  824. /****************/
  825. /**** SHADER ****/
  826. /****************/
  827. virtual RID shader_create(const Vector<ShaderStageData> &p_stages);
  828. virtual uint32_t shader_get_vertex_input_attribute_mask(RID p_shader);
  829. /*****************/
  830. /**** UNIFORM ****/
  831. /*****************/
  832. virtual RID uniform_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>());
  833. virtual RID storage_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>(), uint32_t p_usage = 0);
  834. virtual RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>());
  835. virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set);
  836. virtual bool uniform_set_is_valid(RID p_uniform_set);
  837. virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, uint32_t p_post_barrier = BARRIER_MASK_ALL); //works for any buffer
  838. virtual Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size, uint32_t p_post_barrier = BARRIER_MASK_ALL);
  839. virtual Vector<uint8_t> buffer_get_data(RID p_buffer);
  840. /*************************/
  841. /**** RENDER PIPELINE ****/
  842. /*************************/
  843. virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0);
  844. virtual bool render_pipeline_is_valid(RID p_pipeline);
  845. /**************************/
  846. /**** COMPUTE PIPELINE ****/
  847. /**************************/
  848. virtual RID compute_pipeline_create(RID p_shader);
  849. virtual bool compute_pipeline_is_valid(RID p_pipeline);
  850. /****************/
  851. /**** SCREEN ****/
  852. /****************/
  853. virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const;
  854. virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const;
  855. virtual FramebufferFormatID screen_get_framebuffer_format() const;
  856. /********************/
  857. /**** DRAW LISTS ****/
  858. /********************/
  859. virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());
  860. virtual DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector<RID> &p_storage_textures = Vector<RID>());
  861. virtual Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const Vector<RID> &p_storage_textures = Vector<RID>());
  862. virtual void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline);
  863. virtual void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index);
  864. virtual void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array);
  865. virtual void draw_list_bind_index_array(DrawListID p_list, RID p_index_array);
  866. virtual void draw_list_set_line_width(DrawListID p_list, float p_width);
  867. virtual void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size);
  868. virtual void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0);
  869. virtual void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect);
  870. virtual void draw_list_disable_scissor(DrawListID p_list);
  871. virtual void draw_list_end(uint32_t p_post_barrier = BARRIER_MASK_ALL);
  872. /***********************/
  873. /**** COMPUTE LISTS ****/
  874. /***********************/
  875. virtual ComputeListID compute_list_begin(bool p_allow_draw_overlap = false);
  876. virtual void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline);
  877. virtual void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index);
  878. virtual void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size);
  879. virtual void compute_list_add_barrier(ComputeListID p_list);
  880. virtual void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups);
  881. virtual void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads);
  882. virtual void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset);
  883. virtual void compute_list_end(uint32_t p_post_barrier = BARRIER_MASK_ALL);
  884. virtual void barrier(uint32_t p_from = BARRIER_MASK_ALL, uint32_t p_to = BARRIER_MASK_ALL);
  885. virtual void full_barrier();
  886. /**************/
  887. /**** FREE ****/
  888. /**************/
  889. virtual void free(RID p_id);
  890. /****************/
  891. /**** Timing ****/
  892. /****************/
  893. virtual void capture_timestamp(const String &p_name);
  894. virtual uint32_t get_captured_timestamps_count() const;
  895. virtual uint64_t get_captured_timestamps_frame() const;
  896. virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const;
  897. virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const;
  898. virtual String get_captured_timestamp_name(uint32_t p_index) const;
  899. /****************/
  900. /**** Limits ****/
  901. /****************/
  902. virtual int limit_get(Limit p_limit);
  903. virtual void prepare_screen_for_drawing();
  904. void initialize(VulkanContext *p_context, bool p_local_device = false);
  905. void finalize();
  906. virtual void swap_buffers(); //for main device
  907. virtual void submit(); //for local device
  908. virtual void sync(); //for local device
  909. virtual uint32_t get_frame_delay() const;
  910. virtual RenderingDevice *create_local_device();
  911. virtual uint64_t get_memory_usage() const;
  912. virtual void set_resource_name(RID p_id, const String p_name);
  913. virtual void draw_command_begin_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1));
  914. virtual void draw_command_insert_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1));
  915. virtual void draw_command_end_label();
  916. virtual String get_device_vendor_name() const;
  917. virtual String get_device_name() const;
  918. virtual String get_device_pipeline_cache_uuid() const;
  919. RenderingDeviceVulkan();
  920. ~RenderingDeviceVulkan();
  921. };
  922. #endif // RENDERING_DEVICE_VULKAN_H