shader_language.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /**************************************************************************/
  2. /* shader_language.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef SHADER_LANGUAGE_H
  31. #define SHADER_LANGUAGE_H
  32. #include "core/object/script_language.h"
  33. #include "core/string/string_name.h"
  34. #include "core/string/ustring.h"
  35. #include "core/templates/list.h"
  36. #include "core/templates/rb_map.h"
  37. #include "core/templates/safe_refcount.h"
  38. #include "core/typedefs.h"
  39. #include "core/variant/variant.h"
  40. #include "scene/resources/shader_include.h"
  41. #ifdef DEBUG_ENABLED
  42. #include "shader_warnings.h"
  43. #endif // DEBUG_ENABLED
  44. class ShaderLanguage {
  45. public:
  46. struct TkPos {
  47. int char_idx;
  48. int tk_line;
  49. };
  50. enum TokenType {
  51. TK_EMPTY,
  52. TK_IDENTIFIER,
  53. TK_TRUE,
  54. TK_FALSE,
  55. TK_FLOAT_CONSTANT,
  56. TK_INT_CONSTANT,
  57. TK_UINT_CONSTANT,
  58. TK_STRING_CONSTANT,
  59. TK_TYPE_VOID,
  60. TK_TYPE_BOOL,
  61. TK_TYPE_BVEC2,
  62. TK_TYPE_BVEC3,
  63. TK_TYPE_BVEC4,
  64. TK_TYPE_INT,
  65. TK_TYPE_IVEC2,
  66. TK_TYPE_IVEC3,
  67. TK_TYPE_IVEC4,
  68. TK_TYPE_UINT,
  69. TK_TYPE_UVEC2,
  70. TK_TYPE_UVEC3,
  71. TK_TYPE_UVEC4,
  72. TK_TYPE_FLOAT,
  73. TK_TYPE_VEC2,
  74. TK_TYPE_VEC3,
  75. TK_TYPE_VEC4,
  76. TK_TYPE_MAT2,
  77. TK_TYPE_MAT3,
  78. TK_TYPE_MAT4,
  79. TK_TYPE_SAMPLER2D,
  80. TK_TYPE_ISAMPLER2D,
  81. TK_TYPE_USAMPLER2D,
  82. TK_TYPE_SAMPLER2DARRAY,
  83. TK_TYPE_ISAMPLER2DARRAY,
  84. TK_TYPE_USAMPLER2DARRAY,
  85. TK_TYPE_SAMPLER3D,
  86. TK_TYPE_ISAMPLER3D,
  87. TK_TYPE_USAMPLER3D,
  88. TK_TYPE_SAMPLERCUBE,
  89. TK_TYPE_SAMPLERCUBEARRAY,
  90. TK_TYPE_SAMPLEREXT,
  91. TK_INTERPOLATION_FLAT,
  92. TK_INTERPOLATION_SMOOTH,
  93. TK_CONST,
  94. TK_STRUCT,
  95. TK_PRECISION_LOW,
  96. TK_PRECISION_MID,
  97. TK_PRECISION_HIGH,
  98. TK_OP_EQUAL,
  99. TK_OP_NOT_EQUAL,
  100. TK_OP_LESS,
  101. TK_OP_LESS_EQUAL,
  102. TK_OP_GREATER,
  103. TK_OP_GREATER_EQUAL,
  104. TK_OP_AND,
  105. TK_OP_OR,
  106. TK_OP_NOT,
  107. TK_OP_ADD,
  108. TK_OP_SUB,
  109. TK_OP_MUL,
  110. TK_OP_DIV,
  111. TK_OP_MOD,
  112. TK_OP_SHIFT_LEFT,
  113. TK_OP_SHIFT_RIGHT,
  114. TK_OP_ASSIGN,
  115. TK_OP_ASSIGN_ADD,
  116. TK_OP_ASSIGN_SUB,
  117. TK_OP_ASSIGN_MUL,
  118. TK_OP_ASSIGN_DIV,
  119. TK_OP_ASSIGN_MOD,
  120. TK_OP_ASSIGN_SHIFT_LEFT,
  121. TK_OP_ASSIGN_SHIFT_RIGHT,
  122. TK_OP_ASSIGN_BIT_AND,
  123. TK_OP_ASSIGN_BIT_OR,
  124. TK_OP_ASSIGN_BIT_XOR,
  125. TK_OP_BIT_AND,
  126. TK_OP_BIT_OR,
  127. TK_OP_BIT_XOR,
  128. TK_OP_BIT_INVERT,
  129. TK_OP_INCREMENT,
  130. TK_OP_DECREMENT,
  131. TK_CF_IF,
  132. TK_CF_ELSE,
  133. TK_CF_FOR,
  134. TK_CF_WHILE,
  135. TK_CF_DO,
  136. TK_CF_SWITCH,
  137. TK_CF_CASE,
  138. TK_CF_DEFAULT,
  139. TK_CF_BREAK,
  140. TK_CF_CONTINUE,
  141. TK_CF_RETURN,
  142. TK_CF_DISCARD,
  143. TK_BRACKET_OPEN,
  144. TK_BRACKET_CLOSE,
  145. TK_CURLY_BRACKET_OPEN,
  146. TK_CURLY_BRACKET_CLOSE,
  147. TK_PARENTHESIS_OPEN,
  148. TK_PARENTHESIS_CLOSE,
  149. TK_QUESTION,
  150. TK_COMMA,
  151. TK_COLON,
  152. TK_SEMICOLON,
  153. TK_PERIOD,
  154. TK_UNIFORM,
  155. TK_UNIFORM_GROUP,
  156. TK_INSTANCE,
  157. TK_GLOBAL,
  158. TK_VARYING,
  159. TK_ARG_IN,
  160. TK_ARG_OUT,
  161. TK_ARG_INOUT,
  162. TK_RENDER_MODE,
  163. TK_HINT_DEFAULT_WHITE_TEXTURE,
  164. TK_HINT_DEFAULT_BLACK_TEXTURE,
  165. TK_HINT_DEFAULT_TRANSPARENT_TEXTURE,
  166. TK_HINT_NORMAL_TEXTURE,
  167. TK_HINT_ROUGHNESS_NORMAL_TEXTURE,
  168. TK_HINT_ROUGHNESS_R,
  169. TK_HINT_ROUGHNESS_G,
  170. TK_HINT_ROUGHNESS_B,
  171. TK_HINT_ROUGHNESS_A,
  172. TK_HINT_ROUGHNESS_GRAY,
  173. TK_HINT_ANISOTROPY_TEXTURE,
  174. TK_HINT_SOURCE_COLOR,
  175. TK_HINT_RANGE,
  176. TK_HINT_ENUM,
  177. TK_HINT_INSTANCE_INDEX,
  178. TK_HINT_SCREEN_TEXTURE,
  179. TK_HINT_NORMAL_ROUGHNESS_TEXTURE,
  180. TK_HINT_DEPTH_TEXTURE,
  181. TK_FILTER_NEAREST,
  182. TK_FILTER_LINEAR,
  183. TK_FILTER_NEAREST_MIPMAP,
  184. TK_FILTER_LINEAR_MIPMAP,
  185. TK_FILTER_NEAREST_MIPMAP_ANISOTROPIC,
  186. TK_FILTER_LINEAR_MIPMAP_ANISOTROPIC,
  187. TK_REPEAT_ENABLE,
  188. TK_REPEAT_DISABLE,
  189. TK_SHADER_TYPE,
  190. TK_CURSOR,
  191. TK_ERROR,
  192. TK_EOF,
  193. TK_MAX
  194. };
  195. /* COMPILER */
  196. // lame work around to Apple defining this as a macro in 10.12 SDK
  197. #ifdef TYPE_BOOL
  198. #undef TYPE_BOOL
  199. #endif
  200. enum DataType {
  201. TYPE_VOID,
  202. TYPE_BOOL,
  203. TYPE_BVEC2,
  204. TYPE_BVEC3,
  205. TYPE_BVEC4,
  206. TYPE_INT,
  207. TYPE_IVEC2,
  208. TYPE_IVEC3,
  209. TYPE_IVEC4,
  210. TYPE_UINT,
  211. TYPE_UVEC2,
  212. TYPE_UVEC3,
  213. TYPE_UVEC4,
  214. TYPE_FLOAT,
  215. TYPE_VEC2,
  216. TYPE_VEC3,
  217. TYPE_VEC4,
  218. TYPE_MAT2,
  219. TYPE_MAT3,
  220. TYPE_MAT4,
  221. TYPE_SAMPLER2D,
  222. TYPE_ISAMPLER2D,
  223. TYPE_USAMPLER2D,
  224. TYPE_SAMPLER2DARRAY,
  225. TYPE_ISAMPLER2DARRAY,
  226. TYPE_USAMPLER2DARRAY,
  227. TYPE_SAMPLER3D,
  228. TYPE_ISAMPLER3D,
  229. TYPE_USAMPLER3D,
  230. TYPE_SAMPLERCUBE,
  231. TYPE_SAMPLERCUBEARRAY,
  232. TYPE_SAMPLEREXT,
  233. TYPE_STRUCT,
  234. TYPE_MAX
  235. };
  236. enum DataPrecision {
  237. PRECISION_LOWP,
  238. PRECISION_MEDIUMP,
  239. PRECISION_HIGHP,
  240. PRECISION_DEFAULT,
  241. };
  242. enum DataInterpolation {
  243. INTERPOLATION_FLAT,
  244. INTERPOLATION_SMOOTH,
  245. INTERPOLATION_DEFAULT,
  246. };
  247. enum Operator {
  248. OP_EQUAL,
  249. OP_NOT_EQUAL,
  250. OP_LESS,
  251. OP_LESS_EQUAL,
  252. OP_GREATER,
  253. OP_GREATER_EQUAL,
  254. OP_AND,
  255. OP_OR,
  256. OP_NOT,
  257. OP_NEGATE,
  258. OP_ADD,
  259. OP_SUB,
  260. OP_MUL,
  261. OP_DIV,
  262. OP_MOD,
  263. OP_SHIFT_LEFT,
  264. OP_SHIFT_RIGHT,
  265. OP_ASSIGN,
  266. OP_ASSIGN_ADD,
  267. OP_ASSIGN_SUB,
  268. OP_ASSIGN_MUL,
  269. OP_ASSIGN_DIV,
  270. OP_ASSIGN_MOD,
  271. OP_ASSIGN_SHIFT_LEFT,
  272. OP_ASSIGN_SHIFT_RIGHT,
  273. OP_ASSIGN_BIT_AND,
  274. OP_ASSIGN_BIT_OR,
  275. OP_ASSIGN_BIT_XOR,
  276. OP_BIT_AND,
  277. OP_BIT_OR,
  278. OP_BIT_XOR,
  279. OP_BIT_INVERT,
  280. OP_INCREMENT,
  281. OP_DECREMENT,
  282. OP_SELECT_IF,
  283. OP_SELECT_ELSE, //used only internally, then only IF appears with 3 arguments
  284. OP_POST_INCREMENT,
  285. OP_POST_DECREMENT,
  286. OP_CALL,
  287. OP_CONSTRUCT,
  288. OP_STRUCT,
  289. OP_INDEX,
  290. OP_EMPTY,
  291. OP_MAX
  292. };
  293. enum FlowOperation {
  294. FLOW_OP_IF,
  295. FLOW_OP_RETURN,
  296. FLOW_OP_FOR,
  297. FLOW_OP_WHILE,
  298. FLOW_OP_DO,
  299. FLOW_OP_BREAK,
  300. FLOW_OP_SWITCH,
  301. FLOW_OP_CASE,
  302. FLOW_OP_DEFAULT,
  303. FLOW_OP_CONTINUE,
  304. FLOW_OP_DISCARD
  305. };
  306. enum ArgumentQualifier {
  307. ARGUMENT_QUALIFIER_IN,
  308. ARGUMENT_QUALIFIER_OUT,
  309. ARGUMENT_QUALIFIER_INOUT,
  310. };
  311. enum SubClassTag {
  312. TAG_GLOBAL,
  313. TAG_ARRAY,
  314. };
  315. enum TextureFilter {
  316. FILTER_NEAREST,
  317. FILTER_LINEAR,
  318. FILTER_NEAREST_MIPMAP,
  319. FILTER_LINEAR_MIPMAP,
  320. FILTER_NEAREST_MIPMAP_ANISOTROPIC,
  321. FILTER_LINEAR_MIPMAP_ANISOTROPIC,
  322. FILTER_DEFAULT,
  323. };
  324. enum TextureRepeat {
  325. REPEAT_DISABLE,
  326. REPEAT_ENABLE,
  327. REPEAT_DEFAULT,
  328. };
  329. enum {
  330. MAX_INSTANCE_UNIFORM_INDICES = 16
  331. };
  332. struct VaryingFunctionNames {
  333. StringName fragment;
  334. StringName vertex;
  335. StringName light;
  336. VaryingFunctionNames() {
  337. fragment = "fragment";
  338. vertex = "vertex";
  339. light = "light";
  340. }
  341. };
  342. union Scalar {
  343. bool boolean = false;
  344. float real;
  345. int32_t sint;
  346. uint32_t uint;
  347. };
  348. struct Node {
  349. Node *next = nullptr;
  350. enum Type {
  351. NODE_TYPE_SHADER,
  352. NODE_TYPE_FUNCTION,
  353. NODE_TYPE_BLOCK,
  354. NODE_TYPE_VARIABLE,
  355. NODE_TYPE_VARIABLE_DECLARATION,
  356. NODE_TYPE_CONSTANT,
  357. NODE_TYPE_OPERATOR,
  358. NODE_TYPE_CONTROL_FLOW,
  359. NODE_TYPE_MEMBER,
  360. NODE_TYPE_ARRAY,
  361. NODE_TYPE_ARRAY_CONSTRUCT,
  362. NODE_TYPE_STRUCT,
  363. };
  364. Type type;
  365. virtual DataType get_datatype() const { return TYPE_VOID; }
  366. virtual String get_datatype_name() const { return ""; }
  367. virtual int get_array_size() const { return 0; }
  368. virtual bool is_indexed() const { return false; }
  369. virtual Vector<Scalar> get_values() const { return Vector<Scalar>(); }
  370. Node(Type t) :
  371. type(t) {}
  372. virtual ~Node() {}
  373. };
  374. template <typename T>
  375. T *alloc_node() {
  376. T *node = memnew(T);
  377. node->next = nodes;
  378. nodes = node;
  379. return node;
  380. }
  381. Node *nodes = nullptr;
  382. struct OperatorNode : public Node {
  383. DataType return_cache = TYPE_VOID;
  384. DataPrecision return_precision_cache = PRECISION_DEFAULT;
  385. int return_array_size = 0;
  386. Operator op = OP_EQUAL;
  387. StringName struct_name;
  388. Vector<Node *> arguments;
  389. Vector<Scalar> values;
  390. virtual DataType get_datatype() const override { return return_cache; }
  391. virtual String get_datatype_name() const override { return String(struct_name); }
  392. virtual int get_array_size() const override { return return_array_size; }
  393. virtual bool is_indexed() const override { return op == OP_INDEX; }
  394. virtual Vector<Scalar> get_values() const override { return values; }
  395. OperatorNode() :
  396. Node(NODE_TYPE_OPERATOR) {}
  397. };
  398. struct VariableNode : public Node {
  399. DataType datatype_cache = TYPE_VOID;
  400. StringName name;
  401. StringName rname;
  402. StringName struct_name;
  403. bool is_const = false;
  404. bool is_local = false;
  405. virtual DataType get_datatype() const override { return datatype_cache; }
  406. virtual String get_datatype_name() const override { return String(struct_name); }
  407. VariableNode() :
  408. Node(NODE_TYPE_VARIABLE) {}
  409. };
  410. struct VariableDeclarationNode : public Node {
  411. DataPrecision precision = PRECISION_DEFAULT;
  412. DataType datatype = TYPE_VOID;
  413. String struct_name;
  414. bool is_const = false;
  415. struct Declaration {
  416. StringName name;
  417. uint32_t size = 0U;
  418. Node *size_expression = nullptr;
  419. Vector<Node *> initializer;
  420. bool single_expression = false;
  421. };
  422. Vector<Declaration> declarations;
  423. virtual DataType get_datatype() const override { return datatype; }
  424. VariableDeclarationNode() :
  425. Node(NODE_TYPE_VARIABLE_DECLARATION) {}
  426. };
  427. struct ArrayNode : public Node {
  428. DataType datatype_cache = TYPE_VOID;
  429. StringName struct_name;
  430. StringName name;
  431. Node *index_expression = nullptr;
  432. Node *call_expression = nullptr;
  433. Node *assign_expression = nullptr;
  434. bool is_const = false;
  435. int array_size = 0;
  436. bool is_local = false;
  437. virtual DataType get_datatype() const override { return call_expression ? call_expression->get_datatype() : datatype_cache; }
  438. virtual String get_datatype_name() const override { return call_expression ? call_expression->get_datatype_name() : String(struct_name); }
  439. virtual int get_array_size() const override { return (index_expression || call_expression) ? 0 : array_size; }
  440. virtual bool is_indexed() const override { return index_expression != nullptr; }
  441. ArrayNode() :
  442. Node(NODE_TYPE_ARRAY) {}
  443. };
  444. struct ArrayConstructNode : public Node {
  445. DataType datatype = TYPE_VOID;
  446. String struct_name;
  447. Vector<Node *> initializer;
  448. virtual DataType get_datatype() const override { return datatype; }
  449. virtual String get_datatype_name() const override { return struct_name; }
  450. virtual int get_array_size() const override { return initializer.size(); }
  451. ArrayConstructNode() :
  452. Node(NODE_TYPE_ARRAY_CONSTRUCT) {}
  453. };
  454. struct ConstantNode : public Node {
  455. DataType datatype = TYPE_VOID;
  456. String struct_name = "";
  457. int array_size = 0;
  458. Vector<Scalar> values;
  459. Vector<VariableDeclarationNode::Declaration> array_declarations;
  460. virtual DataType get_datatype() const override { return datatype; }
  461. virtual String get_datatype_name() const override { return struct_name; }
  462. virtual int get_array_size() const override { return array_size; }
  463. virtual Vector<Scalar> get_values() const override {
  464. return values;
  465. }
  466. ConstantNode() :
  467. Node(NODE_TYPE_CONSTANT) {}
  468. };
  469. struct FunctionNode;
  470. struct BlockNode : public Node {
  471. FunctionNode *parent_function = nullptr;
  472. BlockNode *parent_block = nullptr;
  473. enum BlockType {
  474. BLOCK_TYPE_STANDARD,
  475. BLOCK_TYPE_FOR_INIT,
  476. BLOCK_TYPE_FOR_CONDITION,
  477. BLOCK_TYPE_FOR_EXPRESSION,
  478. BLOCK_TYPE_SWITCH,
  479. BLOCK_TYPE_CASE,
  480. BLOCK_TYPE_DEFAULT,
  481. };
  482. int block_type = BLOCK_TYPE_STANDARD;
  483. SubClassTag block_tag = SubClassTag::TAG_GLOBAL;
  484. struct Variable {
  485. DataType type;
  486. StringName struct_name;
  487. DataPrecision precision;
  488. int line; //for completion
  489. int array_size;
  490. bool is_const;
  491. Vector<Scalar> values;
  492. };
  493. HashMap<StringName, Variable> variables;
  494. List<Node *> statements;
  495. bool single_statement = false;
  496. bool use_comma_between_statements = false;
  497. bool use_op_eval = true;
  498. DataType expected_type = TYPE_VOID;
  499. HashSet<int> constants;
  500. BlockNode() :
  501. Node(NODE_TYPE_BLOCK) {}
  502. };
  503. struct ControlFlowNode : public Node {
  504. FlowOperation flow_op = FLOW_OP_IF;
  505. Vector<Node *> expressions;
  506. Vector<BlockNode *> blocks;
  507. ControlFlowNode() :
  508. Node(NODE_TYPE_CONTROL_FLOW) {}
  509. };
  510. struct MemberNode : public Node {
  511. DataType basetype = TYPE_VOID;
  512. bool basetype_const = false;
  513. StringName base_struct_name;
  514. DataPrecision precision = PRECISION_DEFAULT;
  515. DataType datatype = TYPE_VOID;
  516. int array_size = 0;
  517. StringName struct_name;
  518. StringName name;
  519. Node *owner = nullptr;
  520. Node *index_expression = nullptr;
  521. Node *assign_expression = nullptr;
  522. Node *call_expression = nullptr;
  523. bool has_swizzling_duplicates = false;
  524. virtual DataType get_datatype() const override { return call_expression ? call_expression->get_datatype() : datatype; }
  525. virtual String get_datatype_name() const override { return call_expression ? call_expression->get_datatype_name() : String(struct_name); }
  526. virtual int get_array_size() const override { return (index_expression || call_expression) ? 0 : array_size; }
  527. virtual bool is_indexed() const override { return index_expression != nullptr || call_expression != nullptr; }
  528. MemberNode() :
  529. Node(NODE_TYPE_MEMBER) {}
  530. };
  531. struct StructNode : public Node {
  532. List<MemberNode *> members;
  533. StructNode() :
  534. Node(NODE_TYPE_STRUCT) {}
  535. };
  536. struct ShaderNode : public Node {
  537. struct Constant {
  538. StringName name;
  539. DataType type;
  540. StringName struct_name;
  541. DataPrecision precision;
  542. Node *initializer = nullptr;
  543. int array_size;
  544. };
  545. struct Function {
  546. StringName name;
  547. StringName rname;
  548. FunctionNode *function = nullptr;
  549. HashSet<StringName> uses_function;
  550. bool callable;
  551. };
  552. struct Struct {
  553. StringName name;
  554. StructNode *shader_struct = nullptr;
  555. };
  556. struct Varying {
  557. enum Stage {
  558. STAGE_UNKNOWN,
  559. STAGE_VERTEX,
  560. STAGE_FRAGMENT,
  561. };
  562. Stage stage = STAGE_UNKNOWN;
  563. DataType type = TYPE_VOID;
  564. DataInterpolation interpolation = INTERPOLATION_FLAT;
  565. DataPrecision precision = PRECISION_DEFAULT;
  566. int array_size = 0;
  567. TkPos tkpos;
  568. Varying() {}
  569. };
  570. struct Uniform {
  571. enum Hint {
  572. HINT_NONE,
  573. HINT_RANGE,
  574. HINT_ENUM,
  575. HINT_SOURCE_COLOR,
  576. HINT_NORMAL,
  577. HINT_ROUGHNESS_NORMAL,
  578. HINT_ROUGHNESS_R,
  579. HINT_ROUGHNESS_G,
  580. HINT_ROUGHNESS_B,
  581. HINT_ROUGHNESS_A,
  582. HINT_ROUGHNESS_GRAY,
  583. HINT_DEFAULT_BLACK,
  584. HINT_DEFAULT_WHITE,
  585. HINT_DEFAULT_TRANSPARENT,
  586. HINT_ANISOTROPY,
  587. HINT_SCREEN_TEXTURE,
  588. HINT_NORMAL_ROUGHNESS_TEXTURE,
  589. HINT_DEPTH_TEXTURE,
  590. HINT_MAX
  591. };
  592. enum Scope {
  593. SCOPE_LOCAL,
  594. SCOPE_INSTANCE,
  595. SCOPE_GLOBAL,
  596. };
  597. int order = 0;
  598. int prop_order = 0;
  599. int texture_order = 0;
  600. int texture_binding = 0;
  601. DataType type = TYPE_VOID;
  602. DataPrecision precision = PRECISION_DEFAULT;
  603. int array_size = 0;
  604. Vector<Scalar> default_value;
  605. Scope scope = SCOPE_LOCAL;
  606. Hint hint = HINT_NONE;
  607. bool use_color = false;
  608. TextureFilter filter = FILTER_DEFAULT;
  609. TextureRepeat repeat = REPEAT_DEFAULT;
  610. float hint_range[3];
  611. PackedStringArray hint_enum_names;
  612. int instance_index = 0;
  613. String group;
  614. String subgroup;
  615. _FORCE_INLINE_ bool is_texture() const {
  616. // Order is assigned to -1 for texture uniforms.
  617. return order < 0;
  618. }
  619. Uniform() {
  620. hint_range[0] = 0.0f;
  621. hint_range[1] = 1.0f;
  622. hint_range[2] = 0.001f;
  623. }
  624. };
  625. HashMap<StringName, Constant> constants;
  626. HashMap<StringName, Varying> varyings;
  627. HashMap<StringName, Uniform> uniforms;
  628. HashMap<StringName, Struct> structs;
  629. HashMap<StringName, Function> functions;
  630. Vector<StringName> render_modes;
  631. Vector<Function> vfunctions;
  632. Vector<Constant> vconstants;
  633. Vector<Struct> vstructs;
  634. ShaderNode() :
  635. Node(NODE_TYPE_SHADER) {}
  636. };
  637. struct FunctionNode : public Node {
  638. struct Argument {
  639. ArgumentQualifier qualifier;
  640. StringName name;
  641. DataType type;
  642. StringName struct_name;
  643. DataPrecision precision;
  644. //for passing textures as arguments
  645. bool tex_argument_check;
  646. TextureFilter tex_argument_filter;
  647. TextureRepeat tex_argument_repeat;
  648. bool tex_builtin_check;
  649. StringName tex_builtin;
  650. ShaderNode::Uniform::Hint tex_hint;
  651. bool is_const;
  652. int array_size;
  653. HashMap<StringName, HashSet<int>> tex_argument_connect;
  654. };
  655. StringName name;
  656. StringName rname;
  657. DataType return_type = TYPE_VOID;
  658. StringName return_struct_name;
  659. DataPrecision return_precision = PRECISION_DEFAULT;
  660. int return_array_size = 0;
  661. Vector<Argument> arguments;
  662. BlockNode *body = nullptr;
  663. bool can_discard = false;
  664. virtual DataType get_datatype() const override { return return_type; }
  665. virtual String get_datatype_name() const override { return String(return_struct_name); }
  666. virtual int get_array_size() const override { return return_array_size; }
  667. FunctionNode() :
  668. Node(NODE_TYPE_FUNCTION) {}
  669. };
  670. struct UniformOrderComparator {
  671. _FORCE_INLINE_ bool operator()(const Pair<StringName, int> &A, const Pair<StringName, int> &B) const {
  672. return A.second < B.second;
  673. }
  674. };
  675. struct Expression {
  676. bool is_op;
  677. union {
  678. Operator op;
  679. Node *node = nullptr;
  680. };
  681. };
  682. struct ExpressionInfo {
  683. Vector<Expression> *expression = nullptr;
  684. TokenType tt_break = TK_EMPTY;
  685. bool is_last_expr = false;
  686. };
  687. struct VarInfo {
  688. StringName name;
  689. DataType type;
  690. };
  691. enum CompletionType {
  692. COMPLETION_NONE,
  693. COMPLETION_SHADER_TYPE,
  694. COMPLETION_RENDER_MODE,
  695. COMPLETION_MAIN_FUNCTION,
  696. COMPLETION_IDENTIFIER,
  697. COMPLETION_FUNCTION_CALL,
  698. COMPLETION_CALL_ARGUMENTS,
  699. COMPLETION_INDEX,
  700. COMPLETION_STRUCT,
  701. COMPLETION_HINT,
  702. };
  703. struct Token {
  704. TokenType type;
  705. StringName text;
  706. double constant;
  707. uint16_t line;
  708. bool is_integer_constant() const {
  709. return type == TK_INT_CONSTANT || type == TK_UINT_CONSTANT;
  710. }
  711. };
  712. static String get_operator_text(Operator p_op);
  713. static String get_token_text(Token p_token);
  714. static bool is_token_datatype(TokenType p_type);
  715. static bool is_token_variable_datatype(TokenType p_type);
  716. static DataType get_token_datatype(TokenType p_type);
  717. static bool is_token_interpolation(TokenType p_type);
  718. static DataInterpolation get_token_interpolation(TokenType p_type);
  719. static bool is_token_precision(TokenType p_type);
  720. static bool is_token_arg_qual(TokenType p_type);
  721. static DataPrecision get_token_precision(TokenType p_type);
  722. static String get_precision_name(DataPrecision p_type);
  723. static String get_interpolation_name(DataInterpolation p_interpolation);
  724. static String get_datatype_name(DataType p_type);
  725. static String get_uniform_hint_name(ShaderNode::Uniform::Hint p_hint);
  726. static String get_texture_filter_name(TextureFilter p_filter);
  727. static String get_texture_repeat_name(TextureRepeat p_repeat);
  728. static bool is_token_nonvoid_datatype(TokenType p_type);
  729. static bool is_token_operator(TokenType p_type);
  730. static bool is_token_operator_assign(TokenType p_type);
  731. static bool is_token_hint(TokenType p_type);
  732. static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, Scalar *p_value = nullptr);
  733. static DataType get_scalar_type(DataType p_type);
  734. static int get_cardinality(DataType p_type);
  735. static bool is_scalar_type(DataType p_type);
  736. static bool is_float_type(DataType p_type);
  737. static bool is_sampler_type(DataType p_type);
  738. static Variant constant_value_to_variant(const Vector<Scalar> &p_value, DataType p_type, int p_array_size, ShaderLanguage::ShaderNode::Uniform::Hint p_hint = ShaderLanguage::ShaderNode::Uniform::HINT_NONE);
  739. static PropertyInfo uniform_to_property_info(const ShaderNode::Uniform &p_uniform);
  740. static uint32_t get_datatype_size(DataType p_type);
  741. static uint32_t get_datatype_component_count(DataType p_type);
  742. static void get_keyword_list(List<String> *r_keywords);
  743. static bool is_control_flow_keyword(String p_keyword);
  744. static void get_builtin_funcs(List<String> *r_keywords);
  745. static SafeNumeric<int> instance_counter;
  746. struct BuiltInInfo {
  747. DataType type = TYPE_VOID;
  748. bool constant = false;
  749. BuiltInInfo() {}
  750. BuiltInInfo(DataType p_type, bool p_constant = false) :
  751. type(p_type),
  752. constant(p_constant) {}
  753. };
  754. struct StageFunctionInfo {
  755. struct Argument {
  756. StringName name;
  757. DataType type;
  758. Argument(const StringName &p_name = StringName(), DataType p_type = TYPE_VOID) {
  759. name = p_name;
  760. type = p_type;
  761. }
  762. };
  763. Vector<Argument> arguments;
  764. DataType return_type = TYPE_VOID;
  765. String skip_function;
  766. };
  767. struct ModeInfo {
  768. StringName name;
  769. Vector<StringName> options;
  770. ModeInfo() {}
  771. ModeInfo(const StringName &p_name) :
  772. name(p_name) {
  773. }
  774. ModeInfo(const StringName &p_name, const StringName &p_arg1, const StringName &p_arg2) :
  775. name(p_name) {
  776. options.push_back(p_arg1);
  777. options.push_back(p_arg2);
  778. }
  779. ModeInfo(const StringName &p_name, const StringName &p_arg1, const StringName &p_arg2, const StringName &p_arg3) :
  780. name(p_name) {
  781. options.push_back(p_arg1);
  782. options.push_back(p_arg2);
  783. options.push_back(p_arg3);
  784. }
  785. ModeInfo(const StringName &p_name, const StringName &p_arg1, const StringName &p_arg2, const StringName &p_arg3, const StringName &p_arg4) :
  786. name(p_name) {
  787. options.push_back(p_arg1);
  788. options.push_back(p_arg2);
  789. options.push_back(p_arg3);
  790. options.push_back(p_arg4);
  791. }
  792. ModeInfo(const StringName &p_name, const StringName &p_arg1, const StringName &p_arg2, const StringName &p_arg3, const StringName &p_arg4, const StringName &p_arg5) :
  793. name(p_name) {
  794. options.push_back(p_arg1);
  795. options.push_back(p_arg2);
  796. options.push_back(p_arg3);
  797. options.push_back(p_arg4);
  798. options.push_back(p_arg5);
  799. }
  800. ModeInfo(const StringName &p_name, const StringName &p_arg1, const StringName &p_arg2, const StringName &p_arg3, const StringName &p_arg4, const StringName &p_arg5, const StringName &p_arg6) :
  801. name(p_name) {
  802. options.push_back(p_arg1);
  803. options.push_back(p_arg2);
  804. options.push_back(p_arg3);
  805. options.push_back(p_arg4);
  806. options.push_back(p_arg5);
  807. options.push_back(p_arg6);
  808. }
  809. };
  810. struct FunctionInfo {
  811. HashMap<StringName, BuiltInInfo> built_ins;
  812. HashMap<StringName, StageFunctionInfo> stage_functions;
  813. bool can_discard = false;
  814. bool main_function = false;
  815. };
  816. static bool has_builtin(const HashMap<StringName, ShaderLanguage::FunctionInfo> &p_functions, const StringName &p_name, bool p_check_global_funcs = false);
  817. typedef DataType (*GlobalShaderUniformGetTypeFunc)(const StringName &p_name);
  818. struct FilePosition {
  819. String file;
  820. int line = 0;
  821. };
  822. private:
  823. struct KeyWord {
  824. TokenType token;
  825. const char *text;
  826. uint32_t flags;
  827. const Vector<String> excluded_shader_types;
  828. const Vector<String> excluded_functions;
  829. };
  830. static const KeyWord keyword_list[];
  831. GlobalShaderUniformGetTypeFunc global_shader_uniform_get_type_func = nullptr;
  832. bool error_set = false;
  833. String error_str;
  834. int error_line = 0;
  835. Vector<FilePosition> include_positions;
  836. HashSet<String> include_markers_handled;
  837. HashMap<StringName, int> function_overload_count;
  838. // Additional function information (eg. call hierarchy). No need to expose it to compiler.
  839. struct CallInfo {
  840. struct Item {
  841. enum ItemType {
  842. ITEM_TYPE_BUILTIN,
  843. ITEM_TYPE_VARYING,
  844. } type;
  845. TkPos pos;
  846. Item() {}
  847. Item(ItemType p_type, TkPos p_pos) :
  848. type(p_type), pos(p_pos) {}
  849. };
  850. StringName name;
  851. List<Pair<StringName, Item>> uses_restricted_items;
  852. List<CallInfo *> calls;
  853. };
  854. RBMap<StringName, CallInfo> calls_info;
  855. #ifdef DEBUG_ENABLED
  856. struct Usage {
  857. int decl_line;
  858. bool used = false;
  859. Usage(int p_decl_line = -1) {
  860. decl_line = p_decl_line;
  861. }
  862. };
  863. HashMap<StringName, Usage> used_constants;
  864. HashMap<StringName, Usage> used_varyings;
  865. HashMap<StringName, Usage> used_uniforms;
  866. HashMap<StringName, Usage> used_functions;
  867. HashMap<StringName, Usage> used_structs;
  868. HashMap<ShaderWarning::Code, HashMap<StringName, Usage> *> warnings_check_map;
  869. HashMap<StringName, HashMap<StringName, Usage>> used_local_vars;
  870. HashMap<ShaderWarning::Code, HashMap<StringName, HashMap<StringName, Usage>> *> warnings_check_map2;
  871. List<ShaderWarning> warnings;
  872. bool check_warnings = false;
  873. uint32_t warning_flags = 0;
  874. void _add_line_warning(ShaderWarning::Code p_code, const StringName &p_subject = "", const Vector<Variant> &p_extra_args = Vector<Variant>()) {
  875. warnings.push_back(ShaderWarning(p_code, tk_line, p_subject, p_extra_args));
  876. }
  877. void _add_global_warning(ShaderWarning::Code p_code, const StringName &p_subject = "", const Vector<Variant> &p_extra_args = Vector<Variant>()) {
  878. warnings.push_back(ShaderWarning(p_code, -1, p_subject, p_extra_args));
  879. }
  880. void _add_warning(ShaderWarning::Code p_code, int p_line, const StringName &p_subject = "", const Vector<Variant> &p_extra_args = Vector<Variant>()) {
  881. warnings.push_back(ShaderWarning(p_code, p_line, p_subject, p_extra_args));
  882. }
  883. void _check_warning_accums();
  884. #endif // DEBUG_ENABLED
  885. String code;
  886. int char_idx = 0;
  887. int tk_line = 0;
  888. StringName shader_type_identifier;
  889. StringName current_function;
  890. bool is_const_decl = false;
  891. StringName last_name;
  892. bool is_shader_inc = false;
  893. String current_uniform_group_name;
  894. String current_uniform_subgroup_name;
  895. VaryingFunctionNames varying_function_names;
  896. TkPos _get_tkpos() {
  897. TkPos tkp;
  898. tkp.char_idx = char_idx;
  899. tkp.tk_line = tk_line;
  900. return tkp;
  901. }
  902. void _set_tkpos(TkPos p_pos) {
  903. char_idx = p_pos.char_idx;
  904. tk_line = p_pos.tk_line;
  905. }
  906. void _set_error(const String &p_str) {
  907. if (error_set) {
  908. return;
  909. }
  910. error_line = tk_line;
  911. error_set = true;
  912. error_str = p_str;
  913. include_positions.write[include_positions.size() - 1].line = tk_line;
  914. }
  915. void _set_expected_error(const String &p_what) {
  916. _set_error(vformat(RTR("Expected a '%s'."), p_what));
  917. }
  918. void _set_expected_error(const String &p_first, const String p_second) {
  919. _set_error(vformat(RTR("Expected a '%s' or '%s'."), p_first, p_second));
  920. }
  921. void _set_expected_after_error(const String &p_what, const String &p_after) {
  922. _set_error(vformat(RTR("Expected a '%s' after '%s'."), p_what, p_after));
  923. }
  924. void _set_redefinition_error(const String &p_what) {
  925. _set_error(vformat(RTR("Redefinition of '%s'."), p_what));
  926. }
  927. void _set_parsing_error() {
  928. _set_error("Parser bug.");
  929. }
  930. static const char *token_names[TK_MAX];
  931. Token _make_token(TokenType p_type, const StringName &p_text = StringName());
  932. Token _get_token();
  933. bool _lookup_next(Token &r_tk);
  934. Token _peek();
  935. ShaderNode *shader = nullptr;
  936. enum IdentifierType {
  937. IDENTIFIER_FUNCTION,
  938. IDENTIFIER_UNIFORM,
  939. IDENTIFIER_VARYING,
  940. IDENTIFIER_FUNCTION_ARGUMENT,
  941. IDENTIFIER_LOCAL_VAR,
  942. IDENTIFIER_BUILTIN_VAR,
  943. IDENTIFIER_CONSTANT,
  944. IDENTIFIER_MAX,
  945. };
  946. IdentifierType last_type = IDENTIFIER_MAX;
  947. bool _find_identifier(const BlockNode *p_block, bool p_allow_reassign, const FunctionInfo &p_function_info, const StringName &p_identifier, DataType *r_data_type = nullptr, IdentifierType *r_type = nullptr, bool *r_is_const = nullptr, int *r_array_size = nullptr, StringName *r_struct_name = nullptr, Vector<Scalar> *r_constant_values = nullptr);
  948. #ifdef DEBUG_ENABLED
  949. void _parse_used_identifier(const StringName &p_identifier, IdentifierType p_type, const StringName &p_function);
  950. #endif // DEBUG_ENABLED
  951. bool _is_operator_assign(Operator p_op) const;
  952. bool _validate_assign(Node *p_node, const FunctionInfo &p_function_info, String *r_message = nullptr);
  953. bool _validate_operator(const BlockNode *p_block, OperatorNode *p_op, DataType *r_ret_type = nullptr, int *r_ret_size = nullptr);
  954. Vector<Scalar> _get_node_values(const BlockNode *p_block, Node *p_node);
  955. bool _eval_operator(const BlockNode *p_block, OperatorNode *p_op);
  956. Scalar _eval_unary_scalar(const Scalar &p_a, Operator p_op, DataType p_ret_type);
  957. Scalar _eval_scalar(const Scalar &p_a, const Scalar &p_b, Operator p_op, DataType p_ret_type, bool &r_is_valid);
  958. Vector<Scalar> _eval_unary_vector(const Vector<Scalar> &p_va, DataType p_ret_type, Operator p_op);
  959. Vector<Scalar> _eval_vector(const Vector<Scalar> &p_va, const Vector<Scalar> &p_vb, DataType p_left_type, DataType p_right_type, DataType p_ret_type, Operator p_op, bool &r_is_valid);
  960. Vector<Scalar> _eval_vector_transform(const Vector<Scalar> &p_va, const Vector<Scalar> &p_vb, DataType p_left_type, DataType p_right_type, DataType p_ret_type);
  961. struct BuiltinEntry {
  962. const char *name;
  963. };
  964. struct BuiltinFuncDef {
  965. enum { MAX_ARGS = 5 };
  966. const char *name;
  967. DataType rettype;
  968. const DataType args[MAX_ARGS];
  969. const char *args_names[MAX_ARGS];
  970. SubClassTag tag;
  971. bool high_end;
  972. };
  973. struct BuiltinFuncOutArgs { //arguments used as out in built in functions
  974. enum { MAX_ARGS = 2 };
  975. const char *name;
  976. const int arguments[MAX_ARGS];
  977. };
  978. struct BuiltinFuncConstArgs {
  979. const char *name;
  980. int arg;
  981. int min;
  982. int max;
  983. };
  984. CompletionType completion_type;
  985. ShaderNode::Uniform::Hint current_uniform_hint = ShaderNode::Uniform::HINT_NONE;
  986. TextureFilter current_uniform_filter = FILTER_DEFAULT;
  987. TextureRepeat current_uniform_repeat = REPEAT_DEFAULT;
  988. bool current_uniform_instance_index_defined = false;
  989. int completion_line = 0;
  990. BlockNode *completion_block = nullptr;
  991. DataType completion_base;
  992. bool completion_base_array = false;
  993. SubClassTag completion_class;
  994. StringName completion_function;
  995. StringName completion_struct;
  996. int completion_argument = 0;
  997. #ifdef DEBUG_ENABLED
  998. uint32_t keyword_completion_context;
  999. #endif // DEBUG_ENABLED
  1000. const HashMap<StringName, FunctionInfo> *stages = nullptr;
  1001. bool is_supported_frag_only_funcs = false;
  1002. bool is_discard_supported = false;
  1003. bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier);
  1004. static const BuiltinFuncDef builtin_func_defs[];
  1005. static const BuiltinFuncOutArgs builtin_func_out_args[];
  1006. static const BuiltinFuncConstArgs builtin_func_const_args[];
  1007. static const BuiltinEntry frag_only_func_defs[];
  1008. static bool is_const_suffix_lut_initialized;
  1009. Error _validate_precision(DataType p_type, DataPrecision p_precision);
  1010. bool _compare_datatypes(DataType p_datatype_a, String p_datatype_name_a, int p_array_size_a, DataType p_datatype_b, String p_datatype_name_b, int p_array_size_b);
  1011. bool _compare_datatypes_in_nodes(Node *a, Node *b);
  1012. bool _validate_function_call(BlockNode *p_block, const FunctionInfo &p_function_info, OperatorNode *p_func, DataType *r_ret_type, StringName *r_ret_type_str, bool *r_is_custom_function = nullptr);
  1013. bool _parse_function_arguments(BlockNode *p_block, const FunctionInfo &p_function_info, OperatorNode *p_func, int *r_complete_arg = nullptr);
  1014. ShaderNode::Uniform::Hint _sanitize_hint(ShaderNode::Uniform::Hint p_hint);
  1015. bool _propagate_function_call_sampler_uniform_settings(const StringName &p_name, int p_argument, TextureFilter p_filter, TextureRepeat p_repeat, ShaderNode::Uniform::Hint p_hint);
  1016. bool _propagate_function_call_sampler_builtin_reference(const StringName &p_name, int p_argument, const StringName &p_builtin);
  1017. bool _validate_varying_assign(ShaderNode::Varying &p_varying, String *r_message);
  1018. bool _check_node_constness(const Node *p_node) const;
  1019. bool _check_restricted_func(const StringName &p_name, const StringName &p_current_function) const;
  1020. bool _validate_restricted_func(const StringName &p_call_name, const CallInfo *p_func_info, bool p_is_builtin_hint = false);
  1021. Node *_parse_expression(BlockNode *p_block, const FunctionInfo &p_function_info, const ExpressionInfo *p_previous_expression_info = nullptr);
  1022. Error _parse_array_size(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_forbid_unknown_size, Node **r_size_expression, int *r_array_size, bool *r_unknown_size);
  1023. Node *_parse_array_constructor(BlockNode *p_block, const FunctionInfo &p_function_info);
  1024. Node *_parse_array_constructor(BlockNode *p_block, const FunctionInfo &p_function_info, DataType p_type, const StringName &p_struct_name, int p_array_size);
  1025. ShaderLanguage::Node *_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node);
  1026. Node *_parse_and_reduce_expression(BlockNode *p_block, const FunctionInfo &p_function_info, const ExpressionInfo *p_previous_expression_info = nullptr);
  1027. Error _parse_block(BlockNode *p_block, const FunctionInfo &p_function_info, bool p_just_one = false, bool p_can_break = false, bool p_can_continue = false);
  1028. String _get_shader_type_list(const HashSet<String> &p_shader_types) const;
  1029. String _get_qualifier_str(ArgumentQualifier p_qualifier) const;
  1030. Error _parse_shader(const HashMap<StringName, FunctionInfo> &p_functions, const Vector<ModeInfo> &p_render_modes, const HashSet<String> &p_shader_types);
  1031. Error _find_last_flow_op_in_block(BlockNode *p_block, FlowOperation p_op);
  1032. Error _find_last_flow_op_in_op(ControlFlowNode *p_flow, FlowOperation p_op);
  1033. public:
  1034. #ifdef DEBUG_ENABLED
  1035. List<ShaderWarning>::Element *get_warnings_ptr();
  1036. void enable_warning_checking(bool p_enabled);
  1037. bool is_warning_checking_enabled() const;
  1038. void set_warning_flags(uint32_t p_flags);
  1039. uint32_t get_warning_flags() const;
  1040. #endif // DEBUG_ENABLED
  1041. //static void get_keyword_list(ShaderType p_type,List<String> *p_keywords);
  1042. void clear();
  1043. static String get_shader_type(const String &p_code);
  1044. static bool is_builtin_func_out_parameter(const String &p_name, int p_param);
  1045. struct ShaderCompileInfo {
  1046. HashMap<StringName, FunctionInfo> functions;
  1047. Vector<ModeInfo> render_modes;
  1048. VaryingFunctionNames varying_function_names;
  1049. HashSet<String> shader_types;
  1050. GlobalShaderUniformGetTypeFunc global_shader_uniform_type_func = nullptr;
  1051. bool is_include = false;
  1052. };
  1053. Error compile(const String &p_code, const ShaderCompileInfo &p_info);
  1054. Error complete(const String &p_code, const ShaderCompileInfo &p_info, List<ScriptLanguage::CodeCompletionOption> *r_options, String &r_call_hint);
  1055. String get_error_text();
  1056. Vector<FilePosition> get_include_positions();
  1057. int get_error_line();
  1058. ShaderNode *get_shader();
  1059. String token_debug(const String &p_code);
  1060. ShaderLanguage();
  1061. ~ShaderLanguage();
  1062. };
  1063. #endif // SHADER_LANGUAGE_H