rendering_device_driver.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /**************************************************************************/
  2. /* rendering_device_driver.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. // ***********************************************************************************
  32. // RenderingDeviceDriver - Design principles
  33. // -----------------------------------------
  34. // - Very little validation is done, and normally only in dev or debug builds.
  35. // - Error reporting is generally simple: returning an id of 0 or a false boolean.
  36. // - Certain enums/constants/structs follow Vulkan values/layout. That makes things easier for RDDVulkan (it asserts compatibility).
  37. // - We allocate as little as possible in functions expected to be quick (a counterexample is loading/saving shaders) and use alloca() whenever suitable.
  38. // - We try to back opaque ids with the native ones or memory addresses.
  39. // - When using bookkeeping structures because the actual API id of a resource is not enough, we use a PagedAllocator.
  40. // - Every struct has default initializers.
  41. // - Using VectorView to take array-like arguments. Vector<uint8_t> is an exception (an indiom for "BLOB").
  42. // - If a driver needs some higher-level information (the kind of info RenderingDevice keeps), it shall store a copy of what it needs.
  43. // There's no backwards communication from the driver to query data from RenderingDevice.
  44. // ***********************************************************************************
  45. #include "core/object/object.h"
  46. #include "core/variant/type_info.h"
  47. #include "servers/rendering/rendering_context_driver.h"
  48. #include "servers/rendering/rendering_device_commons.h"
  49. class RenderingShaderContainer;
  50. class RenderingShaderContainerFormat;
  51. // These utilities help drivers avoid allocations.
  52. #define ALLOCA(m_size) ((m_size != 0) ? alloca(m_size) : nullptr)
  53. #define ALLOCA_ARRAY(m_type, m_count) ((m_type *)ALLOCA(sizeof(m_type) * (m_count)))
  54. #define ALLOCA_SINGLE(m_type) ALLOCA_ARRAY(m_type, 1)
  55. // This helps forwarding certain arrays to the API with confidence.
  56. #define ARRAYS_COMPATIBLE(m_type_a, m_type_b) (sizeof(m_type_a) == sizeof(m_type_b) && alignof(m_type_a) == alignof(m_type_b))
  57. // This is used when you also need to ensure structured types are compatible field-by-field.
  58. // TODO: The fieldwise check is unimplemented, but still this one is useful, as a strong annotation about the needs.
  59. #define ARRAYS_COMPATIBLE_FIELDWISE(m_type_a, m_type_b) ARRAYS_COMPATIBLE(m_type_a, m_type_b)
  60. // Another utility, to make it easy to compare members of different enums, which is not fine with some compilers.
  61. #define ENUM_MEMBERS_EQUAL(m_a, m_b) ((int64_t)m_a == (int64_t)m_b)
  62. // This helps using a single paged allocator for many resource types.
  63. template <typename... RESOURCE_TYPES>
  64. struct VersatileResourceTemplate {
  65. static constexpr size_t RESOURCE_SIZES[] = { sizeof(RESOURCE_TYPES)... };
  66. static constexpr size_t MAX_RESOURCE_SIZE = Span(RESOURCE_SIZES).max();
  67. uint8_t data[MAX_RESOURCE_SIZE];
  68. template <typename T>
  69. static T *allocate(PagedAllocator<VersatileResourceTemplate, true> &p_allocator) {
  70. T *obj = (T *)p_allocator.alloc();
  71. memnew_placement(obj, T);
  72. return obj;
  73. }
  74. template <typename T>
  75. static void free(PagedAllocator<VersatileResourceTemplate, true> &p_allocator, T *p_object) {
  76. p_object->~T();
  77. p_allocator.free((VersatileResourceTemplate *)p_object);
  78. }
  79. };
  80. class RenderingDeviceDriver : public RenderingDeviceCommons {
  81. GDSOFTCLASS(RenderingDeviceDriver, RenderingDeviceCommons);
  82. public:
  83. struct ID {
  84. uint64_t id = 0;
  85. _ALWAYS_INLINE_ ID() = default;
  86. _ALWAYS_INLINE_ ID(uint64_t p_id) :
  87. id(p_id) {}
  88. };
  89. #define DEFINE_ID(m_name) \
  90. struct m_name##ID : public ID { \
  91. _ALWAYS_INLINE_ explicit operator bool() const { \
  92. return id != 0; \
  93. } \
  94. _ALWAYS_INLINE_ m_name##ID &operator=(m_name##ID p_other) { \
  95. id = p_other.id; \
  96. return *this; \
  97. } \
  98. _ALWAYS_INLINE_ bool operator<(const m_name##ID &p_other) const { \
  99. return id < p_other.id; \
  100. } \
  101. _ALWAYS_INLINE_ bool operator==(const m_name##ID &p_other) const { \
  102. return id == p_other.id; \
  103. } \
  104. _ALWAYS_INLINE_ bool operator!=(const m_name##ID &p_other) const { \
  105. return id != p_other.id; \
  106. } \
  107. _ALWAYS_INLINE_ m_name##ID(const m_name##ID &p_other) : ID(p_other.id) {} \
  108. _ALWAYS_INLINE_ explicit m_name##ID(uint64_t p_int) : ID(p_int) {} \
  109. _ALWAYS_INLINE_ explicit m_name##ID(void *p_ptr) : ID((uint64_t)p_ptr) {} \
  110. _ALWAYS_INLINE_ m_name##ID() = default; \
  111. };
  112. // Id types declared before anything else to prevent cyclic dependencies between the different concerns.
  113. DEFINE_ID(Buffer);
  114. DEFINE_ID(Texture);
  115. DEFINE_ID(Sampler);
  116. DEFINE_ID(VertexFormat);
  117. DEFINE_ID(CommandQueue);
  118. DEFINE_ID(CommandQueueFamily);
  119. DEFINE_ID(CommandPool);
  120. DEFINE_ID(CommandBuffer);
  121. DEFINE_ID(SwapChain);
  122. DEFINE_ID(Framebuffer);
  123. DEFINE_ID(Shader);
  124. DEFINE_ID(UniformSet);
  125. DEFINE_ID(Pipeline);
  126. DEFINE_ID(RenderPass);
  127. DEFINE_ID(QueryPool);
  128. DEFINE_ID(Fence);
  129. DEFINE_ID(Semaphore);
  130. public:
  131. /*****************/
  132. /**** GENERIC ****/
  133. /*****************/
  134. virtual Error initialize(uint32_t p_device_index, uint32_t p_frame_count) = 0;
  135. /****************/
  136. /**** MEMORY ****/
  137. /****************/
  138. enum MemoryAllocationType {
  139. MEMORY_ALLOCATION_TYPE_CPU, // For images, CPU allocation also means linear, GPU is tiling optimal.
  140. MEMORY_ALLOCATION_TYPE_GPU,
  141. };
  142. /*****************/
  143. /**** BUFFERS ****/
  144. /*****************/
  145. enum BufferUsageBits {
  146. BUFFER_USAGE_TRANSFER_FROM_BIT = (1 << 0),
  147. BUFFER_USAGE_TRANSFER_TO_BIT = (1 << 1),
  148. BUFFER_USAGE_TEXEL_BIT = (1 << 2),
  149. BUFFER_USAGE_UNIFORM_BIT = (1 << 4),
  150. BUFFER_USAGE_STORAGE_BIT = (1 << 5),
  151. BUFFER_USAGE_INDEX_BIT = (1 << 6),
  152. BUFFER_USAGE_VERTEX_BIT = (1 << 7),
  153. BUFFER_USAGE_INDIRECT_BIT = (1 << 8),
  154. BUFFER_USAGE_DEVICE_ADDRESS_BIT = (1 << 17),
  155. // There are no Vulkan-equivalent. Try to use unused/unclaimed bits.
  156. BUFFER_USAGE_DYNAMIC_PERSISTENT_BIT = (1 << 31),
  157. };
  158. enum {
  159. BUFFER_WHOLE_SIZE = ~0ULL
  160. };
  161. /** Allocates a new GPU buffer. Must be destroyed with buffer_free().
  162. * @param p_size The size in bytes of the buffer.
  163. * @param p_usage Usage flags.
  164. * @param p_allocation_type See MemoryAllocationType.
  165. * @param p_frames_drawn Used for debug checks when BUFFER_USAGE_DYNAMIC_PERSISTENT_BIT is set.
  166. * @return the buffer.
  167. */
  168. virtual BufferID buffer_create(uint64_t p_size, BitField<BufferUsageBits> p_usage, MemoryAllocationType p_allocation_type, uint64_t p_frames_drawn) = 0;
  169. // Only for a buffer with BUFFER_USAGE_TEXEL_BIT.
  170. virtual bool buffer_set_texel_format(BufferID p_buffer, DataFormat p_format) = 0;
  171. virtual void buffer_free(BufferID p_buffer) = 0;
  172. virtual uint64_t buffer_get_allocation_size(BufferID p_buffer) = 0;
  173. virtual uint8_t *buffer_map(BufferID p_buffer) = 0;
  174. virtual void buffer_unmap(BufferID p_buffer) = 0;
  175. virtual uint8_t *buffer_persistent_map_advance(BufferID p_buffer, uint64_t p_frames_drawn) = 0;
  176. virtual uint64_t buffer_get_dynamic_offsets(Span<BufferID> p_buffers) = 0;
  177. virtual void buffer_flush(BufferID p_buffer) {}
  178. // Only for a buffer with BUFFER_USAGE_DEVICE_ADDRESS_BIT.
  179. virtual uint64_t buffer_get_device_address(BufferID p_buffer) = 0;
  180. /*****************/
  181. /**** TEXTURE ****/
  182. /*****************/
  183. struct TextureView {
  184. DataFormat format = DATA_FORMAT_MAX;
  185. TextureSwizzle swizzle_r = TEXTURE_SWIZZLE_R;
  186. TextureSwizzle swizzle_g = TEXTURE_SWIZZLE_G;
  187. TextureSwizzle swizzle_b = TEXTURE_SWIZZLE_B;
  188. TextureSwizzle swizzle_a = TEXTURE_SWIZZLE_A;
  189. };
  190. enum TextureLayout {
  191. TEXTURE_LAYOUT_UNDEFINED,
  192. TEXTURE_LAYOUT_GENERAL,
  193. TEXTURE_LAYOUT_STORAGE_OPTIMAL,
  194. TEXTURE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
  195. TEXTURE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
  196. TEXTURE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
  197. TEXTURE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
  198. TEXTURE_LAYOUT_COPY_SRC_OPTIMAL,
  199. TEXTURE_LAYOUT_COPY_DST_OPTIMAL,
  200. TEXTURE_LAYOUT_RESOLVE_SRC_OPTIMAL,
  201. TEXTURE_LAYOUT_RESOLVE_DST_OPTIMAL,
  202. TEXTURE_LAYOUT_FRAGMENT_SHADING_RATE_ATTACHMENT_OPTIMAL,
  203. TEXTURE_LAYOUT_FRAGMENT_DENSITY_MAP_ATTACHMENT_OPTIMAL,
  204. TEXTURE_LAYOUT_MAX
  205. };
  206. enum TextureAspect {
  207. TEXTURE_ASPECT_COLOR = 0,
  208. TEXTURE_ASPECT_DEPTH = 1,
  209. TEXTURE_ASPECT_STENCIL = 2,
  210. TEXTURE_ASPECT_MAX
  211. };
  212. enum TextureUsageMethod {
  213. TEXTURE_USAGE_VRS_FRAGMENT_SHADING_RATE_BIT = TEXTURE_USAGE_MAX_BIT << 1,
  214. TEXTURE_USAGE_VRS_FRAGMENT_DENSITY_MAP_BIT = TEXTURE_USAGE_MAX_BIT << 2,
  215. };
  216. enum TextureAspectBits {
  217. TEXTURE_ASPECT_COLOR_BIT = (1 << TEXTURE_ASPECT_COLOR),
  218. TEXTURE_ASPECT_DEPTH_BIT = (1 << TEXTURE_ASPECT_DEPTH),
  219. TEXTURE_ASPECT_STENCIL_BIT = (1 << TEXTURE_ASPECT_STENCIL),
  220. };
  221. struct TextureSubresource {
  222. TextureAspect aspect = TEXTURE_ASPECT_COLOR;
  223. uint32_t layer = 0;
  224. uint32_t mipmap = 0;
  225. };
  226. struct TextureSubresourceLayers {
  227. BitField<TextureAspectBits> aspect = {};
  228. uint32_t mipmap = 0;
  229. uint32_t base_layer = 0;
  230. uint32_t layer_count = 0;
  231. };
  232. struct TextureSubresourceRange {
  233. BitField<TextureAspectBits> aspect = {};
  234. uint32_t base_mipmap = 0;
  235. uint32_t mipmap_count = 0;
  236. uint32_t base_layer = 0;
  237. uint32_t layer_count = 0;
  238. };
  239. struct TextureCopyableLayout {
  240. uint64_t size = 0;
  241. uint64_t row_pitch = 0;
  242. };
  243. virtual TextureID texture_create(const TextureFormat &p_format, const TextureView &p_view) = 0;
  244. virtual TextureID texture_create_from_extension(uint64_t p_native_texture, TextureType p_type, DataFormat p_format, uint32_t p_array_layers, bool p_depth_stencil, uint32_t p_mipmaps) = 0;
  245. // texture_create_shared_*() can only use original, non-view textures as original. RenderingDevice is responsible for ensuring that.
  246. virtual TextureID texture_create_shared(TextureID p_original_texture, const TextureView &p_view) = 0;
  247. virtual TextureID texture_create_shared_from_slice(TextureID p_original_texture, const TextureView &p_view, TextureSliceType p_slice_type, uint32_t p_layer, uint32_t p_layers, uint32_t p_mipmap, uint32_t p_mipmaps) = 0;
  248. virtual void texture_free(TextureID p_texture) = 0;
  249. virtual uint64_t texture_get_allocation_size(TextureID p_texture) = 0;
  250. // Returns a texture layout for buffer <-> texture copies. If you are copying multiple texture subresources to/from the same buffer,
  251. // you are responsible for correctly aligning the start offset for every buffer region. See API_TRAIT_TEXTURE_TRANSFER_ALIGNMENT.
  252. virtual void texture_get_copyable_layout(TextureID p_texture, const TextureSubresource &p_subresource, TextureCopyableLayout *r_layout) = 0;
  253. // Returns the data of a texture layer for a CPU texture that was created with TEXTURE_USAGE_CPU_READ_BIT.
  254. virtual Vector<uint8_t> texture_get_data(TextureID p_texture, uint32_t p_layer) = 0;
  255. virtual BitField<TextureUsageBits> texture_get_usages_supported_by_format(DataFormat p_format, bool p_cpu_readable) = 0;
  256. virtual bool texture_can_make_shared_with_format(TextureID p_texture, DataFormat p_format, bool &r_raw_reinterpretation) = 0;
  257. /*****************/
  258. /**** SAMPLER ****/
  259. /*****************/
  260. virtual SamplerID sampler_create(const SamplerState &p_state) = 0;
  261. virtual void sampler_free(SamplerID p_sampler) = 0;
  262. virtual bool sampler_is_format_supported_for_filter(DataFormat p_format, SamplerFilter p_filter) = 0;
  263. /**********************/
  264. /**** VERTEX ARRAY ****/
  265. /**********************/
  266. virtual VertexFormatID vertex_format_create(Span<VertexAttribute> p_vertex_attribs, const VertexAttributeBindingsMap &p_vertex_bindings) = 0;
  267. virtual void vertex_format_free(VertexFormatID p_vertex_format) = 0;
  268. /******************/
  269. /**** BARRIERS ****/
  270. /******************/
  271. enum PipelineStageBits {
  272. PIPELINE_STAGE_TOP_OF_PIPE_BIT = (1 << 0),
  273. PIPELINE_STAGE_DRAW_INDIRECT_BIT = (1 << 1),
  274. PIPELINE_STAGE_VERTEX_INPUT_BIT = (1 << 2),
  275. PIPELINE_STAGE_VERTEX_SHADER_BIT = (1 << 3),
  276. PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT = (1 << 4),
  277. PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT = (1 << 5),
  278. PIPELINE_STAGE_GEOMETRY_SHADER_BIT = (1 << 6),
  279. PIPELINE_STAGE_FRAGMENT_SHADER_BIT = (1 << 7),
  280. PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT = (1 << 8),
  281. PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT = (1 << 9),
  282. PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT = (1 << 10),
  283. PIPELINE_STAGE_COMPUTE_SHADER_BIT = (1 << 11),
  284. PIPELINE_STAGE_COPY_BIT = (1 << 12),
  285. PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT = (1 << 13),
  286. PIPELINE_STAGE_RESOLVE_BIT = (1 << 14),
  287. PIPELINE_STAGE_ALL_GRAPHICS_BIT = (1 << 15),
  288. PIPELINE_STAGE_ALL_COMMANDS_BIT = (1 << 16),
  289. PIPELINE_STAGE_CLEAR_STORAGE_BIT = (1 << 17),
  290. PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT = (1 << 22),
  291. PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT = (1 << 23),
  292. };
  293. enum BarrierAccessBits {
  294. BARRIER_ACCESS_INDIRECT_COMMAND_READ_BIT = (1 << 0),
  295. BARRIER_ACCESS_INDEX_READ_BIT = (1 << 1),
  296. BARRIER_ACCESS_VERTEX_ATTRIBUTE_READ_BIT = (1 << 2),
  297. BARRIER_ACCESS_UNIFORM_READ_BIT = (1 << 3),
  298. BARRIER_ACCESS_INPUT_ATTACHMENT_READ_BIT = (1 << 4),
  299. BARRIER_ACCESS_SHADER_READ_BIT = (1 << 5),
  300. BARRIER_ACCESS_SHADER_WRITE_BIT = (1 << 6),
  301. BARRIER_ACCESS_COLOR_ATTACHMENT_READ_BIT = (1 << 7),
  302. BARRIER_ACCESS_COLOR_ATTACHMENT_WRITE_BIT = (1 << 8),
  303. BARRIER_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT = (1 << 9),
  304. BARRIER_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT = (1 << 10),
  305. BARRIER_ACCESS_COPY_READ_BIT = (1 << 11),
  306. BARRIER_ACCESS_COPY_WRITE_BIT = (1 << 12),
  307. BARRIER_ACCESS_HOST_READ_BIT = (1 << 13),
  308. BARRIER_ACCESS_HOST_WRITE_BIT = (1 << 14),
  309. BARRIER_ACCESS_MEMORY_READ_BIT = (1 << 15),
  310. BARRIER_ACCESS_MEMORY_WRITE_BIT = (1 << 16),
  311. BARRIER_ACCESS_FRAGMENT_SHADING_RATE_ATTACHMENT_READ_BIT = (1 << 23),
  312. BARRIER_ACCESS_FRAGMENT_DENSITY_MAP_ATTACHMENT_READ_BIT = (1 << 24),
  313. BARRIER_ACCESS_RESOLVE_READ_BIT = (1 << 25),
  314. BARRIER_ACCESS_RESOLVE_WRITE_BIT = (1 << 26),
  315. BARRIER_ACCESS_STORAGE_CLEAR_BIT = (1 << 27),
  316. };
  317. // https://github.com/godotengine/godot/pull/110360 - "MemoryBarrier" conflicts with Windows header defines
  318. struct MemoryAccessBarrier {
  319. BitField<BarrierAccessBits> src_access = {};
  320. BitField<BarrierAccessBits> dst_access = {};
  321. };
  322. struct BufferBarrier {
  323. BufferID buffer;
  324. BitField<BarrierAccessBits> src_access = {};
  325. BitField<BarrierAccessBits> dst_access = {};
  326. uint64_t offset = 0;
  327. uint64_t size = 0;
  328. };
  329. struct TextureBarrier {
  330. TextureID texture;
  331. BitField<BarrierAccessBits> src_access = {};
  332. BitField<BarrierAccessBits> dst_access = {};
  333. TextureLayout prev_layout = TEXTURE_LAYOUT_UNDEFINED;
  334. TextureLayout next_layout = TEXTURE_LAYOUT_UNDEFINED;
  335. TextureSubresourceRange subresources;
  336. };
  337. virtual void command_pipeline_barrier(
  338. CommandBufferID p_cmd_buffer,
  339. BitField<PipelineStageBits> p_src_stages,
  340. BitField<PipelineStageBits> p_dst_stages,
  341. VectorView<MemoryAccessBarrier> p_memory_barriers,
  342. VectorView<BufferBarrier> p_buffer_barriers,
  343. VectorView<TextureBarrier> p_texture_barriers) = 0;
  344. /****************/
  345. /**** FENCES ****/
  346. /****************/
  347. virtual FenceID fence_create() = 0;
  348. virtual Error fence_wait(FenceID p_fence) = 0;
  349. virtual void fence_free(FenceID p_fence) = 0;
  350. /********************/
  351. /**** SEMAPHORES ****/
  352. /********************/
  353. virtual SemaphoreID semaphore_create() = 0;
  354. virtual void semaphore_free(SemaphoreID p_semaphore) = 0;
  355. /*************************/
  356. /**** COMMAND BUFFERS ****/
  357. /*************************/
  358. // ----- QUEUE FAMILY -----
  359. enum CommandQueueFamilyBits {
  360. COMMAND_QUEUE_FAMILY_GRAPHICS_BIT = 0x1,
  361. COMMAND_QUEUE_FAMILY_COMPUTE_BIT = 0x2,
  362. COMMAND_QUEUE_FAMILY_TRANSFER_BIT = 0x4
  363. };
  364. // The requested command queue family must support all specified bits or it'll fail to return a valid family otherwise. If a valid surface is specified, the queue must support presenting to it.
  365. // It is valid to specify no bits and a valid surface: in this case, the dedicated presentation queue family will be the preferred option.
  366. virtual CommandQueueFamilyID command_queue_family_get(BitField<CommandQueueFamilyBits> p_cmd_queue_family_bits, RenderingContextDriver::SurfaceID p_surface = 0) = 0;
  367. // ----- QUEUE -----
  368. virtual CommandQueueID command_queue_create(CommandQueueFamilyID p_cmd_queue_family, bool p_identify_as_main_queue = false) = 0;
  369. virtual Error command_queue_execute_and_present(CommandQueueID p_cmd_queue, VectorView<SemaphoreID> p_wait_semaphores, VectorView<CommandBufferID> p_cmd_buffers, VectorView<SemaphoreID> p_cmd_semaphores, FenceID p_cmd_fence, VectorView<SwapChainID> p_swap_chains) = 0;
  370. virtual void command_queue_free(CommandQueueID p_cmd_queue) = 0;
  371. // ----- POOL -----
  372. enum CommandBufferType {
  373. COMMAND_BUFFER_TYPE_PRIMARY,
  374. COMMAND_BUFFER_TYPE_SECONDARY,
  375. };
  376. virtual CommandPoolID command_pool_create(CommandQueueFamilyID p_cmd_queue_family, CommandBufferType p_cmd_buffer_type) = 0;
  377. virtual bool command_pool_reset(CommandPoolID p_cmd_pool) = 0;
  378. virtual void command_pool_free(CommandPoolID p_cmd_pool) = 0;
  379. // ----- BUFFER -----
  380. virtual CommandBufferID command_buffer_create(CommandPoolID p_cmd_pool) = 0;
  381. virtual bool command_buffer_begin(CommandBufferID p_cmd_buffer) = 0;
  382. virtual bool command_buffer_begin_secondary(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, uint32_t p_subpass, FramebufferID p_framebuffer) = 0;
  383. virtual void command_buffer_end(CommandBufferID p_cmd_buffer) = 0;
  384. virtual void command_buffer_execute_secondary(CommandBufferID p_cmd_buffer, VectorView<CommandBufferID> p_secondary_cmd_buffers) = 0;
  385. /********************/
  386. /**** SWAP CHAIN ****/
  387. /********************/
  388. // The swap chain won't be valid for use until it is resized at least once.
  389. virtual SwapChainID swap_chain_create(RenderingContextDriver::SurfaceID p_surface) = 0;
  390. // The swap chain must not be in use when a resize is requested. Wait until all rendering associated to the swap chain is finished before resizing it.
  391. virtual Error swap_chain_resize(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, uint32_t p_desired_framebuffer_count) = 0;
  392. // Acquire the framebuffer that can be used for drawing. This must be called only once every time a new frame will be rendered.
  393. virtual FramebufferID swap_chain_acquire_framebuffer(CommandQueueID p_cmd_queue, SwapChainID p_swap_chain, bool &r_resize_required) = 0;
  394. // Retrieve the render pass that can be used to draw on the swap chain's framebuffers.
  395. virtual RenderPassID swap_chain_get_render_pass(SwapChainID p_swap_chain) = 0;
  396. // Retrieve the rotation in degrees to apply as a pre-transform. Usually 0 on PC. May be 0, 90, 180 & 270 on Android.
  397. virtual int swap_chain_get_pre_rotation_degrees(SwapChainID p_swap_chain) { return 0; }
  398. // Retrieve the format used by the swap chain's framebuffers.
  399. virtual DataFormat swap_chain_get_format(SwapChainID p_swap_chain) = 0;
  400. // Tells the swapchain the max_fps so it can use the proper frame pacing.
  401. // Android uses this with Swappy library. Some implementations or platforms may ignore this hint.
  402. virtual void swap_chain_set_max_fps(SwapChainID p_swap_chain, int p_max_fps) {}
  403. // Wait until all rendering associated to the swap chain is finished before deleting it.
  404. virtual void swap_chain_free(SwapChainID p_swap_chain) = 0;
  405. /*********************/
  406. /**** FRAMEBUFFER ****/
  407. /*********************/
  408. virtual FramebufferID framebuffer_create(RenderPassID p_render_pass, VectorView<TextureID> p_attachments, uint32_t p_width, uint32_t p_height) = 0;
  409. virtual void framebuffer_free(FramebufferID p_framebuffer) = 0;
  410. /****************/
  411. /**** SHADER ****/
  412. /****************/
  413. struct ImmutableSampler {
  414. UniformType type = UNIFORM_TYPE_MAX;
  415. uint32_t binding = 0xffffffff; // Binding index as specified in shader.
  416. LocalVector<ID> ids;
  417. };
  418. // Creates a Pipeline State Object (PSO) out of the shader and all the input data it needs.
  419. // Immutable samplers can be embedded when creating the pipeline layout on the condition they remain valid and unchanged, so they don't need to be
  420. // specified when creating uniform sets PSO resource for binding.
  421. virtual ShaderID shader_create_from_container(const Ref<RenderingShaderContainer> &p_shader_container, const Vector<ImmutableSampler> &p_immutable_samplers) = 0;
  422. // Only meaningful if API_TRAIT_SHADER_CHANGE_INVALIDATION is SHADER_CHANGE_INVALIDATION_ALL_OR_NONE_ACCORDING_TO_LAYOUT_HASH.
  423. virtual uint32_t shader_get_layout_hash(ShaderID p_shader) { return 0; }
  424. virtual void shader_free(ShaderID p_shader) = 0;
  425. virtual void shader_destroy_modules(ShaderID p_shader) = 0;
  426. public:
  427. /*********************/
  428. /**** UNIFORM SET ****/
  429. /*********************/
  430. struct BoundUniform {
  431. UniformType type = UNIFORM_TYPE_MAX;
  432. uint32_t binding = 0xffffffff; // Binding index as specified in shader.
  433. LocalVector<ID> ids;
  434. // Flag to indicate that this is an immutable sampler so it is skipped when creating uniform
  435. // sets, as it would be set previously when creating the pipeline layout.
  436. bool immutable_sampler = false;
  437. _FORCE_INLINE_ bool is_dynamic() const {
  438. return type == UNIFORM_TYPE_STORAGE_BUFFER_DYNAMIC || type == UNIFORM_TYPE_UNIFORM_BUFFER_DYNAMIC;
  439. }
  440. };
  441. virtual UniformSetID uniform_set_create(VectorView<BoundUniform> p_uniforms, ShaderID p_shader, uint32_t p_set_index, int p_linear_pool_index) = 0;
  442. virtual void linear_uniform_set_pools_reset(int p_linear_pool_index) {}
  443. virtual void uniform_set_free(UniformSetID p_uniform_set) = 0;
  444. virtual bool uniform_sets_have_linear_pools() const { return false; }
  445. virtual uint32_t uniform_sets_get_dynamic_offsets(VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count) const = 0;
  446. // ----- COMMANDS -----
  447. virtual void command_uniform_set_prepare_for_use(CommandBufferID p_cmd_buffer, UniformSetID p_uniform_set, ShaderID p_shader, uint32_t p_set_index) = 0;
  448. /******************/
  449. /**** TRANSFER ****/
  450. /******************/
  451. struct BufferCopyRegion {
  452. uint64_t src_offset = 0;
  453. uint64_t dst_offset = 0;
  454. uint64_t size = 0;
  455. };
  456. struct TextureCopyRegion {
  457. TextureSubresourceLayers src_subresources;
  458. Vector3i src_offset;
  459. TextureSubresourceLayers dst_subresources;
  460. Vector3i dst_offset;
  461. Vector3i size;
  462. };
  463. struct BufferTextureCopyRegion {
  464. uint64_t buffer_offset = 0;
  465. uint64_t row_pitch = 0;
  466. TextureSubresource texture_subresource;
  467. Vector3i texture_offset;
  468. Vector3i texture_region_size;
  469. };
  470. virtual void command_clear_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, uint64_t p_offset, uint64_t p_size) = 0;
  471. virtual void command_copy_buffer(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, BufferID p_dst_buffer, VectorView<BufferCopyRegion> p_regions) = 0;
  472. virtual void command_copy_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<TextureCopyRegion> p_regions) = 0;
  473. virtual void command_resolve_texture(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, uint32_t p_src_layer, uint32_t p_src_mipmap, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, uint32_t p_dst_layer, uint32_t p_dst_mipmap) = 0;
  474. virtual void command_clear_color_texture(CommandBufferID p_cmd_buffer, TextureID p_texture, TextureLayout p_texture_layout, const Color &p_color, const TextureSubresourceRange &p_subresources) = 0;
  475. virtual void command_clear_depth_stencil_texture(CommandBufferID p_cmd_buffer, TextureID p_texture, TextureLayout p_texture_layout, float p_depth, uint8_t p_stencil, const TextureSubresourceRange &p_subresources) = 0;
  476. virtual void command_copy_buffer_to_texture(CommandBufferID p_cmd_buffer, BufferID p_src_buffer, TextureID p_dst_texture, TextureLayout p_dst_texture_layout, VectorView<BufferTextureCopyRegion> p_regions) = 0;
  477. virtual void command_copy_texture_to_buffer(CommandBufferID p_cmd_buffer, TextureID p_src_texture, TextureLayout p_src_texture_layout, BufferID p_dst_buffer, VectorView<BufferTextureCopyRegion> p_regions) = 0;
  478. /******************/
  479. /**** PIPELINE ****/
  480. /******************/
  481. virtual void pipeline_free(PipelineID p_pipeline) = 0;
  482. // ----- BINDING -----
  483. virtual void command_bind_push_constants(CommandBufferID p_cmd_buffer, ShaderID p_shader, uint32_t p_first_index, VectorView<uint32_t> p_data) = 0;
  484. // ----- CACHE -----
  485. virtual bool pipeline_cache_create(const Vector<uint8_t> &p_data) = 0;
  486. virtual void pipeline_cache_free() = 0;
  487. virtual size_t pipeline_cache_query_size() = 0;
  488. virtual Vector<uint8_t> pipeline_cache_serialize() = 0;
  489. /*******************/
  490. /**** RENDERING ****/
  491. /*******************/
  492. // ----- SUBPASS -----
  493. enum AttachmentLoadOp {
  494. ATTACHMENT_LOAD_OP_LOAD = 0,
  495. ATTACHMENT_LOAD_OP_CLEAR = 1,
  496. ATTACHMENT_LOAD_OP_DONT_CARE = 2,
  497. };
  498. enum AttachmentStoreOp {
  499. ATTACHMENT_STORE_OP_STORE = 0,
  500. ATTACHMENT_STORE_OP_DONT_CARE = 1,
  501. };
  502. struct Attachment {
  503. DataFormat format = DATA_FORMAT_MAX;
  504. TextureSamples samples = TEXTURE_SAMPLES_MAX;
  505. AttachmentLoadOp load_op = ATTACHMENT_LOAD_OP_DONT_CARE;
  506. AttachmentStoreOp store_op = ATTACHMENT_STORE_OP_DONT_CARE;
  507. AttachmentLoadOp stencil_load_op = ATTACHMENT_LOAD_OP_DONT_CARE;
  508. AttachmentStoreOp stencil_store_op = ATTACHMENT_STORE_OP_DONT_CARE;
  509. TextureLayout initial_layout = TEXTURE_LAYOUT_UNDEFINED;
  510. TextureLayout final_layout = TEXTURE_LAYOUT_UNDEFINED;
  511. };
  512. struct AttachmentReference {
  513. static constexpr uint32_t UNUSED = 0xffffffff;
  514. uint32_t attachment = UNUSED;
  515. TextureLayout layout = TEXTURE_LAYOUT_UNDEFINED;
  516. BitField<TextureAspectBits> aspect = {};
  517. };
  518. struct Subpass {
  519. LocalVector<AttachmentReference> input_references;
  520. LocalVector<AttachmentReference> color_references;
  521. AttachmentReference depth_stencil_reference;
  522. AttachmentReference depth_resolve_reference;
  523. LocalVector<AttachmentReference> resolve_references;
  524. LocalVector<uint32_t> preserve_attachments;
  525. AttachmentReference fragment_shading_rate_reference;
  526. Size2i fragment_shading_rate_texel_size;
  527. };
  528. struct SubpassDependency {
  529. uint32_t src_subpass = 0xffffffff;
  530. uint32_t dst_subpass = 0xffffffff;
  531. BitField<PipelineStageBits> src_stages = {};
  532. BitField<PipelineStageBits> dst_stages = {};
  533. BitField<BarrierAccessBits> src_access = {};
  534. BitField<BarrierAccessBits> dst_access = {};
  535. };
  536. virtual RenderPassID render_pass_create(VectorView<Attachment> p_attachments, VectorView<Subpass> p_subpasses, VectorView<SubpassDependency> p_subpass_dependencies, uint32_t p_view_count, AttachmentReference p_fragment_density_map_attachment) = 0;
  537. virtual void render_pass_free(RenderPassID p_render_pass) = 0;
  538. // ----- COMMANDS -----
  539. union RenderPassClearValue {
  540. Color color = {};
  541. struct {
  542. float depth;
  543. uint32_t stencil;
  544. };
  545. RenderPassClearValue() {}
  546. };
  547. struct AttachmentClear {
  548. BitField<TextureAspectBits> aspect = {};
  549. uint32_t color_attachment = 0xffffffff;
  550. RenderPassClearValue value;
  551. };
  552. virtual void command_begin_render_pass(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, FramebufferID p_framebuffer, CommandBufferType p_cmd_buffer_type, const Rect2i &p_rect, VectorView<RenderPassClearValue> p_clear_values) = 0;
  553. virtual void command_end_render_pass(CommandBufferID p_cmd_buffer) = 0;
  554. virtual void command_next_render_subpass(CommandBufferID p_cmd_buffer, CommandBufferType p_cmd_buffer_type) = 0;
  555. virtual void command_render_set_viewport(CommandBufferID p_cmd_buffer, VectorView<Rect2i> p_viewports) = 0;
  556. virtual void command_render_set_scissor(CommandBufferID p_cmd_buffer, VectorView<Rect2i> p_scissors) = 0;
  557. virtual void command_render_clear_attachments(CommandBufferID p_cmd_buffer, VectorView<AttachmentClear> p_attachment_clears, VectorView<Rect2i> p_rects) = 0;
  558. // Binding.
  559. virtual void command_bind_render_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) = 0;
  560. virtual void command_bind_render_uniform_sets(CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count, uint32_t p_dynamic_offsets) = 0;
  561. // Drawing.
  562. virtual void command_render_draw(CommandBufferID p_cmd_buffer, uint32_t p_vertex_count, uint32_t p_instance_count, uint32_t p_base_vertex, uint32_t p_first_instance) = 0;
  563. virtual void command_render_draw_indexed(CommandBufferID p_cmd_buffer, uint32_t p_index_count, uint32_t p_instance_count, uint32_t p_first_index, int32_t p_vertex_offset, uint32_t p_first_instance) = 0;
  564. virtual void command_render_draw_indexed_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, uint32_t p_draw_count, uint32_t p_stride) = 0;
  565. virtual void command_render_draw_indexed_indirect_count(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, BufferID p_count_buffer, uint64_t p_count_buffer_offset, uint32_t p_max_draw_count, uint32_t p_stride) = 0;
  566. virtual void command_render_draw_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, uint32_t p_draw_count, uint32_t p_stride) = 0;
  567. virtual void command_render_draw_indirect_count(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset, BufferID p_count_buffer, uint64_t p_count_buffer_offset, uint32_t p_max_draw_count, uint32_t p_stride) = 0;
  568. // Buffer binding.
  569. virtual void command_render_bind_vertex_buffers(CommandBufferID p_cmd_buffer, uint32_t p_binding_count, const BufferID *p_buffers, const uint64_t *p_offsets, uint64_t p_dynamic_offsets) = 0;
  570. virtual void command_render_bind_index_buffer(CommandBufferID p_cmd_buffer, BufferID p_buffer, IndexBufferFormat p_format, uint64_t p_offset) = 0;
  571. // Dynamic state.
  572. virtual void command_render_set_blend_constants(CommandBufferID p_cmd_buffer, const Color &p_constants) = 0;
  573. virtual void command_render_set_line_width(CommandBufferID p_cmd_buffer, float p_width) = 0;
  574. // ----- PIPELINE -----
  575. virtual PipelineID render_pipeline_create(
  576. ShaderID p_shader,
  577. VertexFormatID p_vertex_format,
  578. RenderPrimitive p_render_primitive,
  579. PipelineRasterizationState p_rasterization_state,
  580. PipelineMultisampleState p_multisample_state,
  581. PipelineDepthStencilState p_depth_stencil_state,
  582. PipelineColorBlendState p_blend_state,
  583. VectorView<int32_t> p_color_attachments,
  584. BitField<PipelineDynamicStateFlags> p_dynamic_state,
  585. RenderPassID p_render_pass,
  586. uint32_t p_render_subpass,
  587. VectorView<PipelineSpecializationConstant> p_specialization_constants) = 0;
  588. /*****************/
  589. /**** COMPUTE ****/
  590. /*****************/
  591. // ----- COMMANDS -----
  592. // Binding.
  593. virtual void command_bind_compute_pipeline(CommandBufferID p_cmd_buffer, PipelineID p_pipeline) = 0;
  594. virtual void command_bind_compute_uniform_sets(CommandBufferID p_cmd_buffer, VectorView<UniformSetID> p_uniform_sets, ShaderID p_shader, uint32_t p_first_set_index, uint32_t p_set_count, uint32_t p_dynamic_offsets) = 0;
  595. // Dispatching.
  596. virtual void command_compute_dispatch(CommandBufferID p_cmd_buffer, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) = 0;
  597. virtual void command_compute_dispatch_indirect(CommandBufferID p_cmd_buffer, BufferID p_indirect_buffer, uint64_t p_offset) = 0;
  598. // ----- PIPELINE -----
  599. virtual PipelineID compute_pipeline_create(ShaderID p_shader, VectorView<PipelineSpecializationConstant> p_specialization_constants) = 0;
  600. /******************/
  601. /**** CALLBACK ****/
  602. /******************/
  603. typedef void (*DriverCallback)(RenderingDeviceDriver *p_driver, CommandBufferID p_command_buffer, void *p_userdata);
  604. /*****************/
  605. /**** QUERIES ****/
  606. /*****************/
  607. // ----- TIMESTAMP -----
  608. // Basic.
  609. virtual QueryPoolID timestamp_query_pool_create(uint32_t p_query_count) = 0;
  610. virtual void timestamp_query_pool_free(QueryPoolID p_pool_id) = 0;
  611. virtual void timestamp_query_pool_get_results(QueryPoolID p_pool_id, uint32_t p_query_count, uint64_t *r_results) = 0;
  612. virtual uint64_t timestamp_query_result_to_time(uint64_t p_result) = 0;
  613. // Commands.
  614. virtual void command_timestamp_query_pool_reset(CommandBufferID p_cmd_buffer, QueryPoolID p_pool_id, uint32_t p_query_count) = 0;
  615. virtual void command_timestamp_write(CommandBufferID p_cmd_buffer, QueryPoolID p_pool_id, uint32_t p_index) = 0;
  616. /****************/
  617. /**** LABELS ****/
  618. /****************/
  619. virtual void command_begin_label(CommandBufferID p_cmd_buffer, const char *p_label_name, const Color &p_color) = 0;
  620. virtual void command_end_label(CommandBufferID p_cmd_buffer) = 0;
  621. /****************/
  622. /**** DEBUG *****/
  623. /****************/
  624. virtual void command_insert_breadcrumb(CommandBufferID p_cmd_buffer, uint32_t p_data) = 0;
  625. /********************/
  626. /**** SUBMISSION ****/
  627. /********************/
  628. virtual void begin_segment(uint32_t p_frame_index, uint32_t p_frames_drawn) = 0;
  629. virtual void end_segment() = 0;
  630. /**************/
  631. /**** MISC ****/
  632. /**************/
  633. enum ObjectType {
  634. OBJECT_TYPE_TEXTURE,
  635. OBJECT_TYPE_SAMPLER,
  636. OBJECT_TYPE_BUFFER,
  637. OBJECT_TYPE_SHADER,
  638. OBJECT_TYPE_UNIFORM_SET,
  639. OBJECT_TYPE_PIPELINE,
  640. };
  641. struct MultiviewCapabilities {
  642. bool is_supported = false;
  643. bool geometry_shader_is_supported = false;
  644. bool tessellation_shader_is_supported = false;
  645. uint32_t max_view_count = 0;
  646. uint32_t max_instance_count = 0;
  647. };
  648. struct FragmentShadingRateCapabilities {
  649. Size2i min_texel_size;
  650. Size2i max_texel_size;
  651. Size2i max_fragment_size;
  652. bool pipeline_supported = false;
  653. bool primitive_supported = false;
  654. bool attachment_supported = false;
  655. };
  656. struct FragmentDensityMapCapabilities {
  657. Size2i min_texel_size;
  658. Size2i max_texel_size;
  659. Size2i offset_granularity;
  660. bool attachment_supported = false;
  661. bool dynamic_attachment_supported = false;
  662. bool non_subsampled_images_supported = false;
  663. bool invocations_supported = false;
  664. bool offset_supported = false;
  665. };
  666. enum ApiTrait {
  667. API_TRAIT_HONORS_PIPELINE_BARRIERS,
  668. API_TRAIT_SHADER_CHANGE_INVALIDATION,
  669. API_TRAIT_TEXTURE_TRANSFER_ALIGNMENT,
  670. API_TRAIT_TEXTURE_DATA_ROW_PITCH_STEP,
  671. API_TRAIT_SECONDARY_VIEWPORT_SCISSOR,
  672. API_TRAIT_CLEARS_WITH_COPY_ENGINE,
  673. API_TRAIT_USE_GENERAL_IN_COPY_QUEUES,
  674. API_TRAIT_BUFFERS_REQUIRE_TRANSITIONS,
  675. API_TRAIT_TEXTURE_OUTPUTS_REQUIRE_CLEARS,
  676. };
  677. enum ShaderChangeInvalidation {
  678. SHADER_CHANGE_INVALIDATION_ALL_BOUND_UNIFORM_SETS,
  679. // What Vulkan does.
  680. SHADER_CHANGE_INVALIDATION_INCOMPATIBLE_SETS_PLUS_CASCADE,
  681. // What D3D12 does.
  682. SHADER_CHANGE_INVALIDATION_ALL_OR_NONE_ACCORDING_TO_LAYOUT_HASH,
  683. };
  684. enum DeviceFamily {
  685. DEVICE_UNKNOWN,
  686. DEVICE_OPENGL,
  687. DEVICE_VULKAN,
  688. DEVICE_DIRECTX,
  689. DEVICE_METAL,
  690. };
  691. struct Capabilities {
  692. DeviceFamily device_family = DEVICE_UNKNOWN;
  693. uint32_t version_major = 1;
  694. uint32_t version_minor = 0;
  695. };
  696. virtual void set_object_name(ObjectType p_type, ID p_driver_id, const String &p_name) = 0;
  697. virtual uint64_t get_resource_native_handle(DriverResource p_type, ID p_driver_id) = 0;
  698. virtual uint64_t get_total_memory_used() = 0;
  699. virtual uint64_t get_lazily_memory_used() = 0;
  700. virtual uint64_t limit_get(Limit p_limit) = 0;
  701. virtual uint64_t api_trait_get(ApiTrait p_trait);
  702. virtual bool has_feature(Features p_feature) = 0;
  703. virtual const MultiviewCapabilities &get_multiview_capabilities() = 0;
  704. virtual const FragmentShadingRateCapabilities &get_fragment_shading_rate_capabilities() = 0;
  705. virtual const FragmentDensityMapCapabilities &get_fragment_density_map_capabilities() = 0;
  706. virtual String get_api_name() const = 0;
  707. virtual String get_api_version() const = 0;
  708. virtual String get_pipeline_cache_uuid() const = 0;
  709. virtual const Capabilities &get_capabilities() const = 0;
  710. virtual const RenderingShaderContainerFormat &get_shader_container_format() const = 0;
  711. virtual bool is_composite_alpha_supported(CommandQueueID p_queue) const { return false; }
  712. /******************/
  713. virtual ~RenderingDeviceDriver();
  714. };
  715. using RDD = RenderingDeviceDriver;