rendering_device.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. /*************************************************************************/
  2. /* rendering_device.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_H
  31. #define RENDERING_DEVICE_H
  32. #include "core/object/class_db.h"
  33. #include "core/variant/typed_array.h"
  34. #include "servers/display_server.h"
  35. class RDTextureFormat;
  36. class RDTextureView;
  37. class RDAttachmentFormat;
  38. class RDSamplerState;
  39. class RDVertexAttribute;
  40. class RDShaderSource;
  41. class RDShaderBytecode;
  42. class RDUniforms;
  43. class RDPipelineRasterizationState;
  44. class RDPipelineMultisampleState;
  45. class RDPipelineDepthStencilState;
  46. class RDPipelineColorBlendState;
  47. class RenderingDevice : public Object {
  48. GDCLASS(RenderingDevice, Object)
  49. public:
  50. enum ShaderStage {
  51. SHADER_STAGE_VERTEX,
  52. SHADER_STAGE_FRAGMENT,
  53. SHADER_STAGE_TESSELATION_CONTROL,
  54. SHADER_STAGE_TESSELATION_EVALUATION,
  55. SHADER_STAGE_COMPUTE,
  56. SHADER_STAGE_MAX,
  57. SHADER_STAGE_VERTEX_BIT = (1 << SHADER_STAGE_VERTEX),
  58. SHADER_STAGE_FRAGMENT_BIT = (1 << SHADER_STAGE_FRAGMENT),
  59. SHADER_STAGE_TESSELATION_CONTROL_BIT = (1 << SHADER_STAGE_TESSELATION_CONTROL),
  60. SHADER_STAGE_TESSELATION_EVALUATION_BIT = (1 << SHADER_STAGE_TESSELATION_EVALUATION),
  61. SHADER_STAGE_COMPUTE_BIT = (1 << SHADER_STAGE_COMPUTE),
  62. };
  63. enum ShaderLanguage {
  64. SHADER_LANGUAGE_GLSL,
  65. SHADER_LANGUAGE_HLSL
  66. };
  67. typedef Vector<uint8_t> (*ShaderCompileFunction)(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language, String *r_error);
  68. typedef Vector<uint8_t> (*ShaderCacheFunction)(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language);
  69. private:
  70. static ShaderCompileFunction compile_function;
  71. static ShaderCacheFunction cache_function;
  72. static RenderingDevice *singleton;
  73. protected:
  74. static void _bind_methods();
  75. public:
  76. //base numeric ID for all types
  77. enum {
  78. INVALID_ID = -1,
  79. INVALID_FORMAT_ID = -1
  80. };
  81. /*****************/
  82. /**** GENERIC ****/
  83. /*****************/
  84. enum CompareOperator {
  85. COMPARE_OP_NEVER,
  86. COMPARE_OP_LESS,
  87. COMPARE_OP_EQUAL,
  88. COMPARE_OP_LESS_OR_EQUAL,
  89. COMPARE_OP_GREATER,
  90. COMPARE_OP_NOT_EQUAL,
  91. COMPARE_OP_GREATER_OR_EQUAL,
  92. COMPARE_OP_ALWAYS,
  93. COMPARE_OP_MAX //not an actual operator, just the amount of operators :D
  94. };
  95. enum DataFormat {
  96. DATA_FORMAT_R4G4_UNORM_PACK8,
  97. DATA_FORMAT_R4G4B4A4_UNORM_PACK16,
  98. DATA_FORMAT_B4G4R4A4_UNORM_PACK16,
  99. DATA_FORMAT_R5G6B5_UNORM_PACK16,
  100. DATA_FORMAT_B5G6R5_UNORM_PACK16,
  101. DATA_FORMAT_R5G5B5A1_UNORM_PACK16,
  102. DATA_FORMAT_B5G5R5A1_UNORM_PACK16,
  103. DATA_FORMAT_A1R5G5B5_UNORM_PACK16,
  104. DATA_FORMAT_R8_UNORM,
  105. DATA_FORMAT_R8_SNORM,
  106. DATA_FORMAT_R8_USCALED,
  107. DATA_FORMAT_R8_SSCALED,
  108. DATA_FORMAT_R8_UINT,
  109. DATA_FORMAT_R8_SINT,
  110. DATA_FORMAT_R8_SRGB,
  111. DATA_FORMAT_R8G8_UNORM,
  112. DATA_FORMAT_R8G8_SNORM,
  113. DATA_FORMAT_R8G8_USCALED,
  114. DATA_FORMAT_R8G8_SSCALED,
  115. DATA_FORMAT_R8G8_UINT,
  116. DATA_FORMAT_R8G8_SINT,
  117. DATA_FORMAT_R8G8_SRGB,
  118. DATA_FORMAT_R8G8B8_UNORM,
  119. DATA_FORMAT_R8G8B8_SNORM,
  120. DATA_FORMAT_R8G8B8_USCALED,
  121. DATA_FORMAT_R8G8B8_SSCALED,
  122. DATA_FORMAT_R8G8B8_UINT,
  123. DATA_FORMAT_R8G8B8_SINT,
  124. DATA_FORMAT_R8G8B8_SRGB,
  125. DATA_FORMAT_B8G8R8_UNORM,
  126. DATA_FORMAT_B8G8R8_SNORM,
  127. DATA_FORMAT_B8G8R8_USCALED,
  128. DATA_FORMAT_B8G8R8_SSCALED,
  129. DATA_FORMAT_B8G8R8_UINT,
  130. DATA_FORMAT_B8G8R8_SINT,
  131. DATA_FORMAT_B8G8R8_SRGB,
  132. DATA_FORMAT_R8G8B8A8_UNORM,
  133. DATA_FORMAT_R8G8B8A8_SNORM,
  134. DATA_FORMAT_R8G8B8A8_USCALED,
  135. DATA_FORMAT_R8G8B8A8_SSCALED,
  136. DATA_FORMAT_R8G8B8A8_UINT,
  137. DATA_FORMAT_R8G8B8A8_SINT,
  138. DATA_FORMAT_R8G8B8A8_SRGB,
  139. DATA_FORMAT_B8G8R8A8_UNORM,
  140. DATA_FORMAT_B8G8R8A8_SNORM,
  141. DATA_FORMAT_B8G8R8A8_USCALED,
  142. DATA_FORMAT_B8G8R8A8_SSCALED,
  143. DATA_FORMAT_B8G8R8A8_UINT,
  144. DATA_FORMAT_B8G8R8A8_SINT,
  145. DATA_FORMAT_B8G8R8A8_SRGB,
  146. DATA_FORMAT_A8B8G8R8_UNORM_PACK32,
  147. DATA_FORMAT_A8B8G8R8_SNORM_PACK32,
  148. DATA_FORMAT_A8B8G8R8_USCALED_PACK32,
  149. DATA_FORMAT_A8B8G8R8_SSCALED_PACK32,
  150. DATA_FORMAT_A8B8G8R8_UINT_PACK32,
  151. DATA_FORMAT_A8B8G8R8_SINT_PACK32,
  152. DATA_FORMAT_A8B8G8R8_SRGB_PACK32,
  153. DATA_FORMAT_A2R10G10B10_UNORM_PACK32,
  154. DATA_FORMAT_A2R10G10B10_SNORM_PACK32,
  155. DATA_FORMAT_A2R10G10B10_USCALED_PACK32,
  156. DATA_FORMAT_A2R10G10B10_SSCALED_PACK32,
  157. DATA_FORMAT_A2R10G10B10_UINT_PACK32,
  158. DATA_FORMAT_A2R10G10B10_SINT_PACK32,
  159. DATA_FORMAT_A2B10G10R10_UNORM_PACK32,
  160. DATA_FORMAT_A2B10G10R10_SNORM_PACK32,
  161. DATA_FORMAT_A2B10G10R10_USCALED_PACK32,
  162. DATA_FORMAT_A2B10G10R10_SSCALED_PACK32,
  163. DATA_FORMAT_A2B10G10R10_UINT_PACK32,
  164. DATA_FORMAT_A2B10G10R10_SINT_PACK32,
  165. DATA_FORMAT_R16_UNORM,
  166. DATA_FORMAT_R16_SNORM,
  167. DATA_FORMAT_R16_USCALED,
  168. DATA_FORMAT_R16_SSCALED,
  169. DATA_FORMAT_R16_UINT,
  170. DATA_FORMAT_R16_SINT,
  171. DATA_FORMAT_R16_SFLOAT,
  172. DATA_FORMAT_R16G16_UNORM,
  173. DATA_FORMAT_R16G16_SNORM,
  174. DATA_FORMAT_R16G16_USCALED,
  175. DATA_FORMAT_R16G16_SSCALED,
  176. DATA_FORMAT_R16G16_UINT,
  177. DATA_FORMAT_R16G16_SINT,
  178. DATA_FORMAT_R16G16_SFLOAT,
  179. DATA_FORMAT_R16G16B16_UNORM,
  180. DATA_FORMAT_R16G16B16_SNORM,
  181. DATA_FORMAT_R16G16B16_USCALED,
  182. DATA_FORMAT_R16G16B16_SSCALED,
  183. DATA_FORMAT_R16G16B16_UINT,
  184. DATA_FORMAT_R16G16B16_SINT,
  185. DATA_FORMAT_R16G16B16_SFLOAT,
  186. DATA_FORMAT_R16G16B16A16_UNORM,
  187. DATA_FORMAT_R16G16B16A16_SNORM,
  188. DATA_FORMAT_R16G16B16A16_USCALED,
  189. DATA_FORMAT_R16G16B16A16_SSCALED,
  190. DATA_FORMAT_R16G16B16A16_UINT,
  191. DATA_FORMAT_R16G16B16A16_SINT,
  192. DATA_FORMAT_R16G16B16A16_SFLOAT,
  193. DATA_FORMAT_R32_UINT,
  194. DATA_FORMAT_R32_SINT,
  195. DATA_FORMAT_R32_SFLOAT,
  196. DATA_FORMAT_R32G32_UINT,
  197. DATA_FORMAT_R32G32_SINT,
  198. DATA_FORMAT_R32G32_SFLOAT,
  199. DATA_FORMAT_R32G32B32_UINT,
  200. DATA_FORMAT_R32G32B32_SINT,
  201. DATA_FORMAT_R32G32B32_SFLOAT,
  202. DATA_FORMAT_R32G32B32A32_UINT,
  203. DATA_FORMAT_R32G32B32A32_SINT,
  204. DATA_FORMAT_R32G32B32A32_SFLOAT,
  205. DATA_FORMAT_R64_UINT,
  206. DATA_FORMAT_R64_SINT,
  207. DATA_FORMAT_R64_SFLOAT,
  208. DATA_FORMAT_R64G64_UINT,
  209. DATA_FORMAT_R64G64_SINT,
  210. DATA_FORMAT_R64G64_SFLOAT,
  211. DATA_FORMAT_R64G64B64_UINT,
  212. DATA_FORMAT_R64G64B64_SINT,
  213. DATA_FORMAT_R64G64B64_SFLOAT,
  214. DATA_FORMAT_R64G64B64A64_UINT,
  215. DATA_FORMAT_R64G64B64A64_SINT,
  216. DATA_FORMAT_R64G64B64A64_SFLOAT,
  217. DATA_FORMAT_B10G11R11_UFLOAT_PACK32,
  218. DATA_FORMAT_E5B9G9R9_UFLOAT_PACK32,
  219. DATA_FORMAT_D16_UNORM,
  220. DATA_FORMAT_X8_D24_UNORM_PACK32,
  221. DATA_FORMAT_D32_SFLOAT,
  222. DATA_FORMAT_S8_UINT,
  223. DATA_FORMAT_D16_UNORM_S8_UINT,
  224. DATA_FORMAT_D24_UNORM_S8_UINT,
  225. DATA_FORMAT_D32_SFLOAT_S8_UINT,
  226. DATA_FORMAT_BC1_RGB_UNORM_BLOCK,
  227. DATA_FORMAT_BC1_RGB_SRGB_BLOCK,
  228. DATA_FORMAT_BC1_RGBA_UNORM_BLOCK,
  229. DATA_FORMAT_BC1_RGBA_SRGB_BLOCK,
  230. DATA_FORMAT_BC2_UNORM_BLOCK,
  231. DATA_FORMAT_BC2_SRGB_BLOCK,
  232. DATA_FORMAT_BC3_UNORM_BLOCK,
  233. DATA_FORMAT_BC3_SRGB_BLOCK,
  234. DATA_FORMAT_BC4_UNORM_BLOCK,
  235. DATA_FORMAT_BC4_SNORM_BLOCK,
  236. DATA_FORMAT_BC5_UNORM_BLOCK,
  237. DATA_FORMAT_BC5_SNORM_BLOCK,
  238. DATA_FORMAT_BC6H_UFLOAT_BLOCK,
  239. DATA_FORMAT_BC6H_SFLOAT_BLOCK,
  240. DATA_FORMAT_BC7_UNORM_BLOCK,
  241. DATA_FORMAT_BC7_SRGB_BLOCK,
  242. DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
  243. DATA_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
  244. DATA_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
  245. DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
  246. DATA_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
  247. DATA_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
  248. DATA_FORMAT_EAC_R11_UNORM_BLOCK,
  249. DATA_FORMAT_EAC_R11_SNORM_BLOCK,
  250. DATA_FORMAT_EAC_R11G11_UNORM_BLOCK,
  251. DATA_FORMAT_EAC_R11G11_SNORM_BLOCK,
  252. DATA_FORMAT_ASTC_4x4_UNORM_BLOCK,
  253. DATA_FORMAT_ASTC_4x4_SRGB_BLOCK,
  254. DATA_FORMAT_ASTC_5x4_UNORM_BLOCK,
  255. DATA_FORMAT_ASTC_5x4_SRGB_BLOCK,
  256. DATA_FORMAT_ASTC_5x5_UNORM_BLOCK,
  257. DATA_FORMAT_ASTC_5x5_SRGB_BLOCK,
  258. DATA_FORMAT_ASTC_6x5_UNORM_BLOCK,
  259. DATA_FORMAT_ASTC_6x5_SRGB_BLOCK,
  260. DATA_FORMAT_ASTC_6x6_UNORM_BLOCK,
  261. DATA_FORMAT_ASTC_6x6_SRGB_BLOCK,
  262. DATA_FORMAT_ASTC_8x5_UNORM_BLOCK,
  263. DATA_FORMAT_ASTC_8x5_SRGB_BLOCK,
  264. DATA_FORMAT_ASTC_8x6_UNORM_BLOCK,
  265. DATA_FORMAT_ASTC_8x6_SRGB_BLOCK,
  266. DATA_FORMAT_ASTC_8x8_UNORM_BLOCK,
  267. DATA_FORMAT_ASTC_8x8_SRGB_BLOCK,
  268. DATA_FORMAT_ASTC_10x5_UNORM_BLOCK,
  269. DATA_FORMAT_ASTC_10x5_SRGB_BLOCK,
  270. DATA_FORMAT_ASTC_10x6_UNORM_BLOCK,
  271. DATA_FORMAT_ASTC_10x6_SRGB_BLOCK,
  272. DATA_FORMAT_ASTC_10x8_UNORM_BLOCK,
  273. DATA_FORMAT_ASTC_10x8_SRGB_BLOCK,
  274. DATA_FORMAT_ASTC_10x10_UNORM_BLOCK,
  275. DATA_FORMAT_ASTC_10x10_SRGB_BLOCK,
  276. DATA_FORMAT_ASTC_12x10_UNORM_BLOCK,
  277. DATA_FORMAT_ASTC_12x10_SRGB_BLOCK,
  278. DATA_FORMAT_ASTC_12x12_UNORM_BLOCK,
  279. DATA_FORMAT_ASTC_12x12_SRGB_BLOCK,
  280. DATA_FORMAT_G8B8G8R8_422_UNORM,
  281. DATA_FORMAT_B8G8R8G8_422_UNORM,
  282. DATA_FORMAT_G8_B8_R8_3PLANE_420_UNORM,
  283. DATA_FORMAT_G8_B8R8_2PLANE_420_UNORM,
  284. DATA_FORMAT_G8_B8_R8_3PLANE_422_UNORM,
  285. DATA_FORMAT_G8_B8R8_2PLANE_422_UNORM,
  286. DATA_FORMAT_G8_B8_R8_3PLANE_444_UNORM,
  287. DATA_FORMAT_R10X6_UNORM_PACK16,
  288. DATA_FORMAT_R10X6G10X6_UNORM_2PACK16,
  289. DATA_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16,
  290. DATA_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
  291. DATA_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,
  292. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
  293. DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16,
  294. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16,
  295. DATA_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16,
  296. DATA_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16,
  297. DATA_FORMAT_R12X4_UNORM_PACK16,
  298. DATA_FORMAT_R12X4G12X4_UNORM_2PACK16,
  299. DATA_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,
  300. DATA_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
  301. DATA_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,
  302. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16,
  303. DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16,
  304. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16,
  305. DATA_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16,
  306. DATA_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16,
  307. DATA_FORMAT_G16B16G16R16_422_UNORM,
  308. DATA_FORMAT_B16G16R16G16_422_UNORM,
  309. DATA_FORMAT_G16_B16_R16_3PLANE_420_UNORM,
  310. DATA_FORMAT_G16_B16R16_2PLANE_420_UNORM,
  311. DATA_FORMAT_G16_B16_R16_3PLANE_422_UNORM,
  312. DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM,
  313. DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM,
  314. DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG,
  315. DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG,
  316. DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG,
  317. DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG,
  318. DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG,
  319. DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG,
  320. DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG,
  321. DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG,
  322. DATA_FORMAT_MAX
  323. };
  324. /*****************/
  325. /**** BARRIER ****/
  326. /*****************/
  327. enum BarrierMask {
  328. BARRIER_MASK_RASTER = 1,
  329. BARRIER_MASK_COMPUTE = 2,
  330. BARRIER_MASK_TRANSFER = 4,
  331. BARRIER_MASK_NO_BARRIER = 8,
  332. BARRIER_MASK_ALL = BARRIER_MASK_RASTER | BARRIER_MASK_COMPUTE | BARRIER_MASK_TRANSFER
  333. };
  334. /*****************/
  335. /**** TEXTURE ****/
  336. /*****************/
  337. enum TextureType {
  338. TEXTURE_TYPE_1D,
  339. TEXTURE_TYPE_2D,
  340. TEXTURE_TYPE_3D,
  341. TEXTURE_TYPE_CUBE,
  342. TEXTURE_TYPE_1D_ARRAY,
  343. TEXTURE_TYPE_2D_ARRAY,
  344. TEXTURE_TYPE_CUBE_ARRAY,
  345. TEXTURE_TYPE_MAX
  346. };
  347. enum TextureSamples {
  348. TEXTURE_SAMPLES_1,
  349. TEXTURE_SAMPLES_2,
  350. TEXTURE_SAMPLES_4,
  351. TEXTURE_SAMPLES_8,
  352. TEXTURE_SAMPLES_16,
  353. TEXTURE_SAMPLES_32,
  354. TEXTURE_SAMPLES_64,
  355. TEXTURE_SAMPLES_MAX
  356. };
  357. enum TextureUsageBits {
  358. TEXTURE_USAGE_SAMPLING_BIT = (1 << 0),
  359. TEXTURE_USAGE_COLOR_ATTACHMENT_BIT = (1 << 1),
  360. TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = (1 << 2),
  361. TEXTURE_USAGE_STORAGE_BIT = (1 << 3),
  362. TEXTURE_USAGE_STORAGE_ATOMIC_BIT = (1 << 4),
  363. TEXTURE_USAGE_CPU_READ_BIT = (1 << 5),
  364. TEXTURE_USAGE_CAN_UPDATE_BIT = (1 << 6),
  365. TEXTURE_USAGE_CAN_COPY_FROM_BIT = (1 << 7),
  366. TEXTURE_USAGE_CAN_COPY_TO_BIT = (1 << 8),
  367. TEXTURE_USAGE_RESOLVE_ATTACHMENT_BIT = (1 << 9),
  368. };
  369. enum TextureSwizzle {
  370. TEXTURE_SWIZZLE_IDENTITY,
  371. TEXTURE_SWIZZLE_ZERO,
  372. TEXTURE_SWIZZLE_ONE,
  373. TEXTURE_SWIZZLE_R,
  374. TEXTURE_SWIZZLE_G,
  375. TEXTURE_SWIZZLE_B,
  376. TEXTURE_SWIZZLE_A,
  377. TEXTURE_SWIZZLE_MAX
  378. };
  379. struct TextureFormat {
  380. DataFormat format;
  381. uint32_t width;
  382. uint32_t height;
  383. uint32_t depth;
  384. uint32_t array_layers;
  385. uint32_t mipmaps;
  386. TextureType texture_type;
  387. TextureSamples samples;
  388. uint32_t usage_bits;
  389. Vector<DataFormat> shareable_formats;
  390. TextureFormat() {
  391. format = DATA_FORMAT_R8_UNORM;
  392. width = 1;
  393. height = 1;
  394. depth = 1;
  395. array_layers = 1;
  396. mipmaps = 1;
  397. texture_type = TEXTURE_TYPE_2D;
  398. samples = TEXTURE_SAMPLES_1;
  399. usage_bits = 0;
  400. }
  401. };
  402. struct TextureView {
  403. DataFormat format_override;
  404. TextureSwizzle swizzle_r;
  405. TextureSwizzle swizzle_g;
  406. TextureSwizzle swizzle_b;
  407. TextureSwizzle swizzle_a;
  408. TextureView() {
  409. format_override = DATA_FORMAT_MAX; //means, use same as format
  410. swizzle_r = TEXTURE_SWIZZLE_R;
  411. swizzle_g = TEXTURE_SWIZZLE_G;
  412. swizzle_b = TEXTURE_SWIZZLE_B;
  413. swizzle_a = TEXTURE_SWIZZLE_A;
  414. }
  415. };
  416. virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>()) = 0;
  417. virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture) = 0;
  418. enum TextureSliceType {
  419. TEXTURE_SLICE_2D,
  420. TEXTURE_SLICE_CUBEMAP,
  421. TEXTURE_SLICE_3D,
  422. TEXTURE_SLICE_2D_ARRAY,
  423. };
  424. 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) = 0;
  425. 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) = 0;
  426. virtual Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer) = 0; // CPU textures will return immediately, while GPU textures will most likely force a flush
  427. virtual bool texture_is_format_supported_for_usage(DataFormat p_format, uint32_t p_usage) const = 0;
  428. virtual bool texture_is_shared(RID p_texture) = 0;
  429. virtual bool texture_is_valid(RID p_texture) = 0;
  430. 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) = 0;
  431. 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) = 0;
  432. virtual Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture, uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0;
  433. /*********************/
  434. /**** FRAMEBUFFER ****/
  435. /*********************/
  436. struct AttachmentFormat {
  437. DataFormat format;
  438. TextureSamples samples;
  439. uint32_t usage_flags;
  440. AttachmentFormat() {
  441. format = DATA_FORMAT_R8G8B8A8_UNORM;
  442. samples = TEXTURE_SAMPLES_1;
  443. usage_flags = 0;
  444. }
  445. };
  446. typedef int64_t FramebufferFormatID;
  447. // This ID is warranted to be unique for the same formats, does not need to be freed
  448. virtual FramebufferFormatID framebuffer_format_create(const Vector<AttachmentFormat> &p_format) = 0;
  449. virtual FramebufferFormatID framebuffer_format_create_empty(TextureSamples p_samples = TEXTURE_SAMPLES_1) = 0;
  450. virtual TextureSamples framebuffer_format_get_texture_samples(FramebufferFormatID p_format) = 0;
  451. virtual RID framebuffer_create(const Vector<RID> &p_texture_attachments, FramebufferFormatID p_format_check = INVALID_ID) = 0;
  452. virtual RID framebuffer_create_empty(const Size2i &p_size, TextureSamples p_samples = TEXTURE_SAMPLES_1, FramebufferFormatID p_format_check = INVALID_ID) = 0;
  453. virtual FramebufferFormatID framebuffer_get_format(RID p_framebuffer) = 0;
  454. /*****************/
  455. /**** SAMPLER ****/
  456. /*****************/
  457. enum SamplerFilter {
  458. SAMPLER_FILTER_NEAREST,
  459. SAMPLER_FILTER_LINEAR,
  460. };
  461. enum SamplerRepeatMode {
  462. SAMPLER_REPEAT_MODE_REPEAT,
  463. SAMPLER_REPEAT_MODE_MIRRORED_REPEAT,
  464. SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE,
  465. SAMPLER_REPEAT_MODE_CLAMP_TO_BORDER,
  466. SAMPLER_REPEAT_MODE_MIRROR_CLAMP_TO_EDGE,
  467. SAMPLER_REPEAT_MODE_MAX
  468. };
  469. enum SamplerBorderColor {
  470. SAMPLER_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
  471. SAMPLER_BORDER_COLOR_INT_TRANSPARENT_BLACK,
  472. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
  473. SAMPLER_BORDER_COLOR_INT_OPAQUE_BLACK,
  474. SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
  475. SAMPLER_BORDER_COLOR_INT_OPAQUE_WHITE,
  476. SAMPLER_BORDER_COLOR_MAX
  477. };
  478. struct SamplerState {
  479. SamplerFilter mag_filter;
  480. SamplerFilter min_filter;
  481. SamplerFilter mip_filter;
  482. SamplerRepeatMode repeat_u;
  483. SamplerRepeatMode repeat_v;
  484. SamplerRepeatMode repeat_w;
  485. float lod_bias;
  486. bool use_anisotropy;
  487. float anisotropy_max;
  488. bool enable_compare;
  489. CompareOperator compare_op;
  490. float min_lod;
  491. float max_lod;
  492. SamplerBorderColor border_color;
  493. bool unnormalized_uvw;
  494. SamplerState() {
  495. mag_filter = SAMPLER_FILTER_NEAREST;
  496. min_filter = SAMPLER_FILTER_NEAREST;
  497. mip_filter = SAMPLER_FILTER_NEAREST;
  498. repeat_u = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  499. repeat_v = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  500. repeat_w = SAMPLER_REPEAT_MODE_CLAMP_TO_EDGE;
  501. lod_bias = 0;
  502. use_anisotropy = false;
  503. anisotropy_max = 1.0;
  504. enable_compare = false;
  505. compare_op = COMPARE_OP_ALWAYS;
  506. min_lod = 0;
  507. max_lod = 1e20; //something very large should do
  508. border_color = SAMPLER_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
  509. unnormalized_uvw = false;
  510. }
  511. };
  512. virtual RID sampler_create(const SamplerState &p_state) = 0;
  513. /**********************/
  514. /**** VERTEX ARRAY ****/
  515. /**********************/
  516. enum VertexFrequency {
  517. VERTEX_FREQUENCY_VERTEX,
  518. VERTEX_FREQUENCY_INSTANCE,
  519. };
  520. struct VertexAttribute {
  521. uint32_t location; //shader location
  522. uint32_t offset;
  523. DataFormat format;
  524. uint32_t stride;
  525. VertexFrequency frequency;
  526. VertexAttribute() {
  527. location = 0;
  528. offset = 0;
  529. stride = 0;
  530. format = DATA_FORMAT_MAX;
  531. frequency = VERTEX_FREQUENCY_VERTEX;
  532. }
  533. };
  534. 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) = 0;
  535. typedef int64_t VertexFormatID;
  536. // This ID is warranted to be unique for the same formats, does not need to be freed
  537. virtual VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_formats) = 0;
  538. virtual RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector<RID> &p_src_buffers) = 0;
  539. enum IndexBufferFormat {
  540. INDEX_BUFFER_FORMAT_UINT16,
  541. INDEX_BUFFER_FORMAT_UINT32,
  542. };
  543. 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) = 0;
  544. virtual RID index_array_create(RID p_index_buffer, uint32_t p_index_offset, uint32_t p_index_count) = 0;
  545. /****************/
  546. /**** SHADER ****/
  547. /****************/
  548. virtual Vector<uint8_t> shader_compile_from_source(ShaderStage p_stage, const String &p_source_code, ShaderLanguage p_language = SHADER_LANGUAGE_GLSL, String *r_error = nullptr, bool p_allow_cache = true);
  549. static void shader_set_compile_function(ShaderCompileFunction p_function);
  550. static void shader_set_cache_function(ShaderCacheFunction p_function);
  551. struct ShaderStageData {
  552. ShaderStage shader_stage;
  553. Vector<uint8_t> spir_v;
  554. ShaderStageData() {
  555. shader_stage = SHADER_STAGE_VERTEX;
  556. }
  557. };
  558. RID shader_create_from_bytecode(const Ref<RDShaderBytecode> &p_bytecode);
  559. virtual RID shader_create(const Vector<ShaderStageData> &p_stages) = 0;
  560. virtual uint32_t shader_get_vertex_input_attribute_mask(RID p_shader) = 0;
  561. /******************/
  562. /**** UNIFORMS ****/
  563. /******************/
  564. enum UniformType {
  565. UNIFORM_TYPE_SAMPLER, //for sampling only (sampler GLSL type)
  566. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, // for sampling only, but includes a texture, (samplerXX GLSL type), first a sampler then a texture
  567. UNIFORM_TYPE_TEXTURE, //only texture, (textureXX GLSL type)
  568. UNIFORM_TYPE_IMAGE, // storage image (imageXX GLSL type), for compute mostly
  569. UNIFORM_TYPE_TEXTURE_BUFFER, // buffer texture (or TBO, textureBuffer type)
  570. UNIFORM_TYPE_SAMPLER_WITH_TEXTURE_BUFFER, // buffer texture with a sampler(or TBO, samplerBuffer type)
  571. UNIFORM_TYPE_IMAGE_BUFFER, //texel buffer, (imageBuffer type), for compute mostly
  572. UNIFORM_TYPE_UNIFORM_BUFFER, //regular uniform buffer (or UBO).
  573. UNIFORM_TYPE_STORAGE_BUFFER, //storage buffer ("buffer" qualifier) like UBO, but supports storage, for compute mostly
  574. UNIFORM_TYPE_INPUT_ATTACHMENT, //used for sub-pass read/write, for mobile mostly
  575. UNIFORM_TYPE_MAX
  576. };
  577. enum StorageBufferUsage {
  578. STORAGE_BUFFER_USAGE_DISPATCH_INDIRECT = 1
  579. };
  580. virtual RID uniform_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>()) = 0;
  581. virtual RID storage_buffer_create(uint32_t p_size, const Vector<uint8_t> &p_data = Vector<uint8_t>(), uint32_t p_usage = 0) = 0;
  582. virtual RID texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>()) = 0;
  583. struct Uniform {
  584. UniformType uniform_type;
  585. int binding; //binding index as specified in shader
  586. //for single items, provide one ID, for
  587. //multiple items (declared as arrays in shader),
  588. //provide more
  589. //for sampler with texture, supply two IDs for each.
  590. //accepted IDs are: Sampler, Texture, Uniform Buffer and Texture Buffer
  591. Vector<RID> ids;
  592. Uniform() {
  593. uniform_type = UNIFORM_TYPE_IMAGE;
  594. binding = 0;
  595. }
  596. };
  597. virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) = 0;
  598. virtual bool uniform_set_is_valid(RID p_uniform_set) = 0;
  599. 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) = 0;
  600. virtual Error buffer_clear(RID p_buffer, uint32_t p_offset, uint32_t p_size, uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0;
  601. virtual Vector<uint8_t> buffer_get_data(RID p_buffer) = 0; //this causes stall, only use to retrieve large buffers for saving
  602. /*************************/
  603. /**** RENDER PIPELINE ****/
  604. /*************************/
  605. enum RenderPrimitive {
  606. RENDER_PRIMITIVE_POINTS,
  607. RENDER_PRIMITIVE_LINES,
  608. RENDER_PRIMITIVE_LINES_WITH_ADJACENCY,
  609. RENDER_PRIMITIVE_LINESTRIPS,
  610. RENDER_PRIMITIVE_LINESTRIPS_WITH_ADJACENCY,
  611. RENDER_PRIMITIVE_TRIANGLES,
  612. RENDER_PRIMITIVE_TRIANGLES_WITH_ADJACENCY,
  613. RENDER_PRIMITIVE_TRIANGLE_STRIPS,
  614. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_AJACENCY,
  615. RENDER_PRIMITIVE_TRIANGLE_STRIPS_WITH_RESTART_INDEX,
  616. RENDER_PRIMITIVE_TESSELATION_PATCH,
  617. RENDER_PRIMITIVE_MAX
  618. };
  619. //disable optimization, tessellate control points
  620. enum PolygonCullMode {
  621. POLYGON_CULL_DISABLED,
  622. POLYGON_CULL_FRONT,
  623. POLYGON_CULL_BACK,
  624. };
  625. enum PolygonFrontFace {
  626. POLYGON_FRONT_FACE_CLOCKWISE,
  627. POLYGON_FRONT_FACE_COUNTER_CLOCKWISE,
  628. };
  629. enum StencilOperation {
  630. STENCIL_OP_KEEP,
  631. STENCIL_OP_ZERO,
  632. STENCIL_OP_REPLACE,
  633. STENCIL_OP_INCREMENT_AND_CLAMP,
  634. STENCIL_OP_DECREMENT_AND_CLAMP,
  635. STENCIL_OP_INVERT,
  636. STENCIL_OP_INCREMENT_AND_WRAP,
  637. STENCIL_OP_DECREMENT_AND_WRAP,
  638. STENCIL_OP_MAX //not an actual operator, just the amount of operators :D
  639. };
  640. enum LogicOperation {
  641. LOGIC_OP_CLEAR,
  642. LOGIC_OP_AND,
  643. LOGIC_OP_AND_REVERSE,
  644. LOGIC_OP_COPY,
  645. LOGIC_OP_AND_INVERTED,
  646. LOGIC_OP_NO_OP,
  647. LOGIC_OP_XOR,
  648. LOGIC_OP_OR,
  649. LOGIC_OP_NOR,
  650. LOGIC_OP_EQUIVALENT,
  651. LOGIC_OP_INVERT,
  652. LOGIC_OP_OR_REVERSE,
  653. LOGIC_OP_COPY_INVERTED,
  654. LOGIC_OP_OR_INVERTED,
  655. LOGIC_OP_NAND,
  656. LOGIC_OP_SET,
  657. LOGIC_OP_MAX //not an actual operator, just the amount of operators :D
  658. };
  659. enum BlendFactor {
  660. BLEND_FACTOR_ZERO,
  661. BLEND_FACTOR_ONE,
  662. BLEND_FACTOR_SRC_COLOR,
  663. BLEND_FACTOR_ONE_MINUS_SRC_COLOR,
  664. BLEND_FACTOR_DST_COLOR,
  665. BLEND_FACTOR_ONE_MINUS_DST_COLOR,
  666. BLEND_FACTOR_SRC_ALPHA,
  667. BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
  668. BLEND_FACTOR_DST_ALPHA,
  669. BLEND_FACTOR_ONE_MINUS_DST_ALPHA,
  670. BLEND_FACTOR_CONSTANT_COLOR,
  671. BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
  672. BLEND_FACTOR_CONSTANT_ALPHA,
  673. BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
  674. BLEND_FACTOR_SRC_ALPHA_SATURATE,
  675. BLEND_FACTOR_SRC1_COLOR,
  676. BLEND_FACTOR_ONE_MINUS_SRC1_COLOR,
  677. BLEND_FACTOR_SRC1_ALPHA,
  678. BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
  679. BLEND_FACTOR_MAX
  680. };
  681. enum BlendOperation {
  682. BLEND_OP_ADD,
  683. BLEND_OP_SUBTRACT,
  684. BLEND_OP_REVERSE_SUBTRACT,
  685. BLEND_OP_MINIMUM,
  686. BLEND_OP_MAXIMUM, //yes this one is an actual operator
  687. BLEND_OP_MAX //not an actual operator, just the amount of operators :D
  688. };
  689. struct PipelineRasterizationState {
  690. bool enable_depth_clamp;
  691. bool discard_primitives;
  692. bool wireframe;
  693. PolygonCullMode cull_mode;
  694. PolygonFrontFace front_face;
  695. bool depth_bias_enable;
  696. float depth_bias_constant_factor;
  697. float depth_bias_clamp;
  698. float depth_bias_slope_factor;
  699. float line_width;
  700. uint32_t patch_control_points;
  701. PipelineRasterizationState() {
  702. enable_depth_clamp = false;
  703. discard_primitives = false;
  704. wireframe = false;
  705. cull_mode = POLYGON_CULL_DISABLED;
  706. front_face = POLYGON_FRONT_FACE_CLOCKWISE;
  707. depth_bias_enable = false;
  708. depth_bias_constant_factor = 0;
  709. depth_bias_clamp = 0;
  710. depth_bias_slope_factor = 0;
  711. line_width = 1.0;
  712. patch_control_points = 1;
  713. }
  714. };
  715. struct PipelineMultisampleState {
  716. TextureSamples sample_count;
  717. bool enable_sample_shading;
  718. float min_sample_shading;
  719. Vector<uint32_t> sample_mask;
  720. bool enable_alpha_to_coverage;
  721. bool enable_alpha_to_one;
  722. PipelineMultisampleState() {
  723. sample_count = TEXTURE_SAMPLES_1;
  724. enable_sample_shading = false;
  725. min_sample_shading = 0;
  726. enable_alpha_to_coverage = false;
  727. enable_alpha_to_one = false;
  728. }
  729. };
  730. struct PipelineDepthStencilState {
  731. bool enable_depth_test;
  732. bool enable_depth_write;
  733. CompareOperator depth_compare_operator;
  734. bool enable_depth_range;
  735. float depth_range_min;
  736. float depth_range_max;
  737. bool enable_stencil;
  738. struct StencilOperationState {
  739. StencilOperation fail;
  740. StencilOperation pass;
  741. StencilOperation depth_fail;
  742. CompareOperator compare;
  743. uint32_t compare_mask;
  744. uint32_t write_mask;
  745. uint32_t reference;
  746. StencilOperationState() {
  747. fail = STENCIL_OP_ZERO;
  748. pass = STENCIL_OP_ZERO;
  749. depth_fail = STENCIL_OP_ZERO;
  750. compare = COMPARE_OP_ALWAYS;
  751. compare_mask = 0;
  752. write_mask = 0;
  753. reference = 0;
  754. }
  755. };
  756. StencilOperationState front_op;
  757. StencilOperationState back_op;
  758. PipelineDepthStencilState() {
  759. enable_depth_test = false;
  760. enable_depth_write = false;
  761. depth_compare_operator = COMPARE_OP_ALWAYS;
  762. enable_depth_range = false;
  763. depth_range_min = 0;
  764. depth_range_max = 0;
  765. enable_stencil = false;
  766. }
  767. };
  768. struct PipelineColorBlendState {
  769. bool enable_logic_op;
  770. LogicOperation logic_op;
  771. struct Attachment {
  772. bool enable_blend;
  773. BlendFactor src_color_blend_factor;
  774. BlendFactor dst_color_blend_factor;
  775. BlendOperation color_blend_op;
  776. BlendFactor src_alpha_blend_factor;
  777. BlendFactor dst_alpha_blend_factor;
  778. BlendOperation alpha_blend_op;
  779. bool write_r;
  780. bool write_g;
  781. bool write_b;
  782. bool write_a;
  783. Attachment() {
  784. enable_blend = false;
  785. src_color_blend_factor = BLEND_FACTOR_ZERO;
  786. dst_color_blend_factor = BLEND_FACTOR_ZERO;
  787. color_blend_op = BLEND_OP_ADD;
  788. src_alpha_blend_factor = BLEND_FACTOR_ZERO;
  789. dst_alpha_blend_factor = BLEND_FACTOR_ZERO;
  790. alpha_blend_op = BLEND_OP_ADD;
  791. write_r = true;
  792. write_g = true;
  793. write_b = true;
  794. write_a = true;
  795. }
  796. };
  797. static PipelineColorBlendState create_disabled(int p_attachments = 1) {
  798. PipelineColorBlendState bs;
  799. for (int i = 0; i < p_attachments; i++) {
  800. bs.attachments.push_back(Attachment());
  801. }
  802. return bs;
  803. }
  804. static PipelineColorBlendState create_blend(int p_attachments = 1) {
  805. PipelineColorBlendState bs;
  806. for (int i = 0; i < p_attachments; i++) {
  807. Attachment ba;
  808. ba.enable_blend = true;
  809. ba.src_color_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  810. ba.dst_color_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  811. ba.src_alpha_blend_factor = BLEND_FACTOR_SRC_ALPHA;
  812. ba.dst_alpha_blend_factor = BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  813. bs.attachments.push_back(ba);
  814. }
  815. return bs;
  816. }
  817. Vector<Attachment> attachments; //one per render target texture
  818. Color blend_constant;
  819. PipelineColorBlendState() {
  820. enable_logic_op = false;
  821. logic_op = LOGIC_OP_CLEAR;
  822. }
  823. };
  824. enum PipelineDynamicStateFlags {
  825. DYNAMIC_STATE_LINE_WIDTH = (1 << 0),
  826. DYNAMIC_STATE_DEPTH_BIAS = (1 << 1),
  827. DYNAMIC_STATE_BLEND_CONSTANTS = (1 << 2),
  828. DYNAMIC_STATE_DEPTH_BOUNDS = (1 << 3),
  829. DYNAMIC_STATE_STENCIL_COMPARE_MASK = (1 << 4),
  830. DYNAMIC_STATE_STENCIL_WRITE_MASK = (1 << 5),
  831. DYNAMIC_STATE_STENCIL_REFERENCE = (1 << 6),
  832. };
  833. virtual bool render_pipeline_is_valid(RID p_pipeline) = 0;
  834. 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) = 0;
  835. /**************************/
  836. /**** COMPUTE PIPELINE ****/
  837. /**************************/
  838. virtual RID compute_pipeline_create(RID p_shader) = 0;
  839. virtual bool compute_pipeline_is_valid(RID p_pipeline) = 0;
  840. /****************/
  841. /**** SCREEN ****/
  842. /****************/
  843. virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const = 0;
  844. virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const = 0;
  845. virtual FramebufferFormatID screen_get_framebuffer_format() const = 0;
  846. /********************/
  847. /**** DRAW LISTS ****/
  848. /********************/
  849. enum InitialAction {
  850. INITIAL_ACTION_CLEAR, //start rendering and clear the whole framebuffer (region or not) (supply params)
  851. INITIAL_ACTION_CLEAR_REGION, //start rendering and clear the framebuffer in the specified region (supply params)
  852. INITIAL_ACTION_CLEAR_REGION_CONTINUE, //countinue rendering and clear the framebuffer in the specified region (supply params)
  853. INITIAL_ACTION_KEEP, //start rendering, but keep attached color texture contents (depth will be cleared)
  854. INITIAL_ACTION_DROP, //start rendering, ignore what is there, just write above it
  855. INITIAL_ACTION_CONTINUE, //continue rendering (framebuffer must have been left in "continue" state as final action previously)
  856. INITIAL_ACTION_MAX
  857. };
  858. enum FinalAction {
  859. FINAL_ACTION_READ, //will no longer render to it, allows attached textures to be read again, but depth buffer contents will be dropped (Can't be read from)
  860. FINAL_ACTION_DISCARD, // discard contents after rendering
  861. FINAL_ACTION_CONTINUE, //will continue rendering later, attached textures can't be read until re-bound with "finish"
  862. FINAL_ACTION_MAX
  863. };
  864. typedef int64_t DrawListID;
  865. virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color()) = 0;
  866. 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>()) = 0;
  867. 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>()) = 0;
  868. virtual void draw_list_bind_render_pipeline(DrawListID p_list, RID p_render_pipeline) = 0;
  869. virtual void draw_list_bind_uniform_set(DrawListID p_list, RID p_uniform_set, uint32_t p_index) = 0;
  870. virtual void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array) = 0;
  871. virtual void draw_list_bind_index_array(DrawListID p_list, RID p_index_array) = 0;
  872. virtual void draw_list_set_line_width(DrawListID p_list, float p_width) = 0;
  873. virtual void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size) = 0;
  874. virtual void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0) = 0;
  875. virtual void draw_list_enable_scissor(DrawListID p_list, const Rect2 &p_rect) = 0;
  876. virtual void draw_list_disable_scissor(DrawListID p_list) = 0;
  877. virtual void draw_list_end(uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0;
  878. /***********************/
  879. /**** COMPUTE LISTS ****/
  880. /***********************/
  881. typedef int64_t ComputeListID;
  882. virtual ComputeListID compute_list_begin(bool p_allow_draw_overlap = false) = 0;
  883. virtual void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline) = 0;
  884. virtual void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index) = 0;
  885. virtual void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size) = 0;
  886. virtual void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups) = 0;
  887. virtual void compute_list_dispatch_threads(ComputeListID p_list, uint32_t p_x_threads, uint32_t p_y_threads, uint32_t p_z_threads) = 0;
  888. virtual void compute_list_dispatch_indirect(ComputeListID p_list, RID p_buffer, uint32_t p_offset) = 0;
  889. virtual void compute_list_add_barrier(ComputeListID p_list) = 0;
  890. virtual void compute_list_end(uint32_t p_post_barrier = BARRIER_MASK_ALL) = 0;
  891. virtual void barrier(uint32_t p_from = BARRIER_MASK_ALL, uint32_t p_to = BARRIER_MASK_ALL) = 0;
  892. virtual void full_barrier() = 0;
  893. /***************/
  894. /**** FREE! ****/
  895. /***************/
  896. virtual void free(RID p_id) = 0;
  897. /****************/
  898. /**** Timing ****/
  899. /****************/
  900. virtual void capture_timestamp(const String &p_name) = 0;
  901. virtual uint32_t get_captured_timestamps_count() const = 0;
  902. virtual uint64_t get_captured_timestamps_frame() const = 0;
  903. virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const = 0;
  904. virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const = 0;
  905. virtual String get_captured_timestamp_name(uint32_t p_index) const = 0;
  906. /****************/
  907. /**** LIMITS ****/
  908. /****************/
  909. enum Limit {
  910. LIMIT_MAX_BOUND_UNIFORM_SETS,
  911. LIMIT_MAX_FRAMEBUFFER_COLOR_ATTACHMENTS,
  912. LIMIT_MAX_TEXTURES_PER_UNIFORM_SET,
  913. LIMIT_MAX_SAMPLERS_PER_UNIFORM_SET,
  914. LIMIT_MAX_STORAGE_BUFFERS_PER_UNIFORM_SET,
  915. LIMIT_MAX_STORAGE_IMAGES_PER_UNIFORM_SET,
  916. LIMIT_MAX_UNIFORM_BUFFERS_PER_UNIFORM_SET,
  917. LIMIT_MAX_DRAW_INDEXED_INDEX,
  918. LIMIT_MAX_FRAMEBUFFER_HEIGHT,
  919. LIMIT_MAX_FRAMEBUFFER_WIDTH,
  920. LIMIT_MAX_TEXTURE_ARRAY_LAYERS,
  921. LIMIT_MAX_TEXTURE_SIZE_1D,
  922. LIMIT_MAX_TEXTURE_SIZE_2D,
  923. LIMIT_MAX_TEXTURE_SIZE_3D,
  924. LIMIT_MAX_TEXTURE_SIZE_CUBE,
  925. LIMIT_MAX_TEXTURES_PER_SHADER_STAGE,
  926. LIMIT_MAX_SAMPLERS_PER_SHADER_STAGE,
  927. LIMIT_MAX_STORAGE_BUFFERS_PER_SHADER_STAGE,
  928. LIMIT_MAX_STORAGE_IMAGES_PER_SHADER_STAGE,
  929. LIMIT_MAX_UNIFORM_BUFFERS_PER_SHADER_STAGE,
  930. LIMIT_MAX_PUSH_CONSTANT_SIZE,
  931. LIMIT_MAX_UNIFORM_BUFFER_SIZE,
  932. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTE_OFFSET,
  933. LIMIT_MAX_VERTEX_INPUT_ATTRIBUTES,
  934. LIMIT_MAX_VERTEX_INPUT_BINDINGS,
  935. LIMIT_MAX_VERTEX_INPUT_BINDING_STRIDE,
  936. LIMIT_MIN_UNIFORM_BUFFER_OFFSET_ALIGNMENT,
  937. LIMIT_MAX_COMPUTE_SHARED_MEMORY_SIZE,
  938. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_X,
  939. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Y,
  940. LIMIT_MAX_COMPUTE_WORKGROUP_COUNT_Z,
  941. LIMIT_MAX_COMPUTE_WORKGROUP_INVOCATIONS,
  942. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_X,
  943. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Y,
  944. LIMIT_MAX_COMPUTE_WORKGROUP_SIZE_Z,
  945. };
  946. virtual int limit_get(Limit p_limit) = 0;
  947. //methods below not exposed, used by RenderingDeviceRD
  948. virtual void prepare_screen_for_drawing() = 0;
  949. virtual void swap_buffers() = 0;
  950. virtual uint32_t get_frame_delay() const = 0;
  951. virtual void submit() = 0;
  952. virtual void sync() = 0;
  953. virtual uint64_t get_memory_usage() const = 0;
  954. virtual RenderingDevice *create_local_device() = 0;
  955. virtual void set_resource_name(RID p_id, const String p_name) = 0;
  956. virtual void draw_command_begin_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1)) = 0;
  957. virtual void draw_command_insert_label(String p_label_name, const Color p_color = Color(1, 1, 1, 1)) = 0;
  958. virtual void draw_command_end_label() = 0;
  959. virtual String get_device_vendor_name() const = 0;
  960. virtual String get_device_name() const = 0;
  961. virtual String get_device_pipeline_cache_uuid() const = 0;
  962. static RenderingDevice *get_singleton();
  963. RenderingDevice();
  964. protected:
  965. //binders to script API
  966. RID _texture_create(const Ref<RDTextureFormat> &p_format, const Ref<RDTextureView> &p_view, const TypedArray<PackedByteArray> &p_data = Array());
  967. RID _texture_create_shared(const Ref<RDTextureView> &p_view, RID p_with_texture);
  968. RID _texture_create_shared_from_slice(const Ref<RDTextureView> &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, TextureSliceType p_slice_type = TEXTURE_SLICE_2D);
  969. FramebufferFormatID _framebuffer_format_create(const TypedArray<RDAttachmentFormat> &p_attachments);
  970. RID _framebuffer_create(const Array &p_textures, FramebufferFormatID p_format_check = INVALID_ID);
  971. RID _sampler_create(const Ref<RDSamplerState> &p_state);
  972. VertexFormatID _vertex_format_create(const TypedArray<RDVertexAttribute> &p_vertex_formats);
  973. RID _vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const TypedArray<RID> &p_src_buffers);
  974. Ref<RDShaderBytecode> _shader_compile_from_source(const Ref<RDShaderSource> &p_source, bool p_allow_cache = true);
  975. RID _uniform_set_create(const Array &p_uniforms, RID p_shader, uint32_t p_shader_set);
  976. Error _buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data, uint32_t p_post_barrier = BARRIER_MASK_ALL);
  977. RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags = 0);
  978. Vector<int64_t> _draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray<RID> &p_storage_textures = TypedArray<RID>());
  979. void _draw_list_set_push_constant(DrawListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  980. void _compute_list_set_push_constant(ComputeListID p_list, const Vector<uint8_t> &p_data, uint32_t p_data_size);
  981. };
  982. VARIANT_ENUM_CAST(RenderingDevice::ShaderStage)
  983. VARIANT_ENUM_CAST(RenderingDevice::ShaderLanguage)
  984. VARIANT_ENUM_CAST(RenderingDevice::CompareOperator)
  985. VARIANT_ENUM_CAST(RenderingDevice::DataFormat)
  986. VARIANT_ENUM_CAST(RenderingDevice::TextureType)
  987. VARIANT_ENUM_CAST(RenderingDevice::TextureSamples)
  988. VARIANT_ENUM_CAST(RenderingDevice::TextureUsageBits)
  989. VARIANT_ENUM_CAST(RenderingDevice::TextureSwizzle)
  990. VARIANT_ENUM_CAST(RenderingDevice::TextureSliceType)
  991. VARIANT_ENUM_CAST(RenderingDevice::SamplerFilter)
  992. VARIANT_ENUM_CAST(RenderingDevice::SamplerRepeatMode)
  993. VARIANT_ENUM_CAST(RenderingDevice::SamplerBorderColor)
  994. VARIANT_ENUM_CAST(RenderingDevice::VertexFrequency)
  995. VARIANT_ENUM_CAST(RenderingDevice::IndexBufferFormat)
  996. VARIANT_ENUM_CAST(RenderingDevice::StorageBufferUsage)
  997. VARIANT_ENUM_CAST(RenderingDevice::UniformType)
  998. VARIANT_ENUM_CAST(RenderingDevice::RenderPrimitive)
  999. VARIANT_ENUM_CAST(RenderingDevice::PolygonCullMode)
  1000. VARIANT_ENUM_CAST(RenderingDevice::PolygonFrontFace)
  1001. VARIANT_ENUM_CAST(RenderingDevice::StencilOperation)
  1002. VARIANT_ENUM_CAST(RenderingDevice::LogicOperation)
  1003. VARIANT_ENUM_CAST(RenderingDevice::BlendFactor)
  1004. VARIANT_ENUM_CAST(RenderingDevice::BlendOperation)
  1005. VARIANT_ENUM_CAST(RenderingDevice::PipelineDynamicStateFlags)
  1006. VARIANT_ENUM_CAST(RenderingDevice::InitialAction)
  1007. VARIANT_ENUM_CAST(RenderingDevice::FinalAction)
  1008. VARIANT_ENUM_CAST(RenderingDevice::Limit)
  1009. typedef RenderingDevice RD;
  1010. #endif // RENDERING_DEVICE_H