shader_language.h 35 KB

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