Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ir.h 24KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. /* -*- c++ -*- */
  2. /*
  3. * Copyright © 2010 Intel Corporation
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #pragma once
  25. #ifndef IR_H
  26. #define IR_H
  27. #include "list.h"
  28. #include "ir_visitor.h"
  29. #include "ir_hierarchical_visitor.h"
  30. struct ir_program {
  31. void *bong_hits;
  32. };
  33. /**
  34. * Base class of all IR instructions
  35. */
  36. class ir_instruction : public exec_node {
  37. public:
  38. const struct glsl_type *type;
  39. class ir_constant *constant_expression_value();
  40. virtual void accept(ir_visitor *) = 0;
  41. virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
  42. /**
  43. * \name IR instruction downcast functions
  44. *
  45. * These functions either cast the object to a derived class or return
  46. * \c NULL if the object's type does not match the specified derived class.
  47. * Additional downcast functions will be added as needed.
  48. */
  49. /*@{*/
  50. virtual class ir_variable * as_variable() { return NULL; }
  51. virtual class ir_function * as_function() { return NULL; }
  52. virtual class ir_dereference * as_dereference() { return NULL; }
  53. virtual class ir_dereference_array * as_dereference_array() { return NULL; }
  54. virtual class ir_rvalue * as_rvalue() { return NULL; }
  55. virtual class ir_loop * as_loop() { return NULL; }
  56. virtual class ir_assignment * as_assignment() { return NULL; }
  57. virtual class ir_call * as_call() { return NULL; }
  58. virtual class ir_return * as_return() { return NULL; }
  59. virtual class ir_if * as_if() { return NULL; }
  60. virtual class ir_swizzle * as_swizzle() { return NULL; }
  61. virtual class ir_constant * as_constant() { return NULL; }
  62. /*@}*/
  63. protected:
  64. ir_instruction()
  65. {
  66. /* empty */
  67. }
  68. };
  69. class ir_rvalue : public ir_instruction {
  70. public:
  71. virtual ir_rvalue * as_rvalue()
  72. {
  73. return this;
  74. }
  75. virtual bool is_lvalue()
  76. {
  77. return false;
  78. }
  79. /**
  80. * Get the variable that is ultimately referenced by an r-value
  81. */
  82. virtual ir_variable *variable_referenced()
  83. {
  84. return NULL;
  85. }
  86. /**
  87. * If an r-value is a reference to a whole variable, get that variable
  88. *
  89. * \return
  90. * Pointer to a variable that is completely dereferenced by the r-value. If
  91. * the r-value is not a dereference or the dereference does not access the
  92. * entire variable (i.e., it's just one array element, struct field), \c NULL
  93. * is returned.
  94. */
  95. virtual ir_variable *whole_variable_referenced()
  96. {
  97. return NULL;
  98. }
  99. protected:
  100. ir_rvalue()
  101. {
  102. /* empty */
  103. }
  104. };
  105. enum ir_variable_mode {
  106. ir_var_auto = 0,
  107. ir_var_uniform,
  108. ir_var_in,
  109. ir_var_out,
  110. ir_var_inout
  111. };
  112. enum ir_varaible_interpolation {
  113. ir_var_smooth = 0,
  114. ir_var_flat,
  115. ir_var_noperspective
  116. };
  117. class ir_variable : public ir_instruction {
  118. public:
  119. ir_variable(const struct glsl_type *, const char *);
  120. virtual ir_variable *as_variable()
  121. {
  122. return this;
  123. }
  124. virtual void accept(ir_visitor *v)
  125. {
  126. v->visit(this);
  127. }
  128. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  129. /**
  130. * Duplicate an IR variable
  131. *
  132. * \note
  133. * This will probably be made \c virtual and moved to the base class
  134. * eventually.
  135. */
  136. ir_variable *clone() const
  137. {
  138. ir_variable *var = new ir_variable(type, name);
  139. var->max_array_access = this->max_array_access;
  140. var->read_only = this->read_only;
  141. var->centroid = this->centroid;
  142. var->invariant = this->invariant;
  143. var->mode = this->mode;
  144. var->interpolation = this->interpolation;
  145. return var;
  146. }
  147. const char *name;
  148. /**
  149. * Highest element accessed with a constant expression array index
  150. *
  151. * Not used for non-array variables.
  152. */
  153. unsigned max_array_access;
  154. unsigned read_only:1;
  155. unsigned centroid:1;
  156. unsigned invariant:1;
  157. /** If the variable is initialized outside of the scope of the shader */
  158. unsigned shader_in:1;
  159. /**
  160. * If the variable value is later used outside of the scope of the shader.
  161. */
  162. unsigned shader_out:1;
  163. unsigned mode:3;
  164. unsigned interpolation:2;
  165. /**
  166. * Flag that the whole array is assignable
  167. *
  168. * In GLSL 1.20 and later whole arrays are assignable (and comparable for
  169. * equality). This flag enables this behavior.
  170. */
  171. unsigned array_lvalue:1;
  172. /**
  173. * Emit a warning if this variable is accessed.
  174. */
  175. const char *warn_extension;
  176. /**
  177. * Value assigned in the initializer of a variable declared "const"
  178. */
  179. ir_constant *constant_value;
  180. };
  181. /*@{*/
  182. /**
  183. * The representation of a function instance; may be the full definition or
  184. * simply a prototype.
  185. */
  186. class ir_function_signature : public ir_instruction {
  187. /* An ir_function_signature will be part of the list of signatures in
  188. * an ir_function.
  189. */
  190. public:
  191. ir_function_signature(const glsl_type *return_type);
  192. virtual void accept(ir_visitor *v)
  193. {
  194. v->visit(this);
  195. }
  196. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  197. /**
  198. * Get the name of the function for which this is a signature
  199. */
  200. const char *function_name() const;
  201. /**
  202. * Check whether the qualifiers match between this signature's parameters
  203. * and the supplied parameter list. If not, returns the name of the first
  204. * parameter with mismatched qualifiers (for use in error messages).
  205. */
  206. const char *qualifiers_match(exec_list *params);
  207. /**
  208. * Replace the current parameter list with the given one. This is useful
  209. * if the current information came from a prototype, and either has invalid
  210. * or missing parameter names.
  211. */
  212. void replace_parameters(exec_list *new_params);
  213. /**
  214. * Function return type.
  215. *
  216. * \note This discards the optional precision qualifier.
  217. */
  218. const struct glsl_type *return_type;
  219. /**
  220. * List of ir_variable of function parameters.
  221. *
  222. * This represents the storage. The paramaters passed in a particular
  223. * call will be in ir_call::actual_paramaters.
  224. */
  225. struct exec_list parameters;
  226. /** Whether or not this function has a body (which may be empty). */
  227. unsigned is_defined:1;
  228. /** Body of instructions in the function. */
  229. struct exec_list body;
  230. private:
  231. /** Function of which this signature is one overload. */
  232. class ir_function *function;
  233. friend class ir_function;
  234. };
  235. /**
  236. * Header for tracking multiple overloaded functions with the same name.
  237. * Contains a list of ir_function_signatures representing each of the
  238. * actual functions.
  239. */
  240. class ir_function : public ir_instruction {
  241. public:
  242. ir_function(const char *name);
  243. virtual ir_function *as_function()
  244. {
  245. return this;
  246. }
  247. virtual void accept(ir_visitor *v)
  248. {
  249. v->visit(this);
  250. }
  251. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  252. void add_signature(ir_function_signature *sig)
  253. {
  254. sig->function = this;
  255. signatures.push_tail(sig);
  256. }
  257. /**
  258. * Get an iterator for the set of function signatures
  259. */
  260. exec_list_iterator iterator()
  261. {
  262. return signatures.iterator();
  263. }
  264. /**
  265. * Find a signature that matches a set of actual parameters, taking implicit
  266. * conversions into account.
  267. */
  268. const ir_function_signature *matching_signature(exec_list *actual_param);
  269. /**
  270. * Find a signature that exactly matches a set of actual parameters without
  271. * any implicit type conversions.
  272. */
  273. ir_function_signature *exact_matching_signature(exec_list *actual_ps);
  274. /**
  275. * Name of the function.
  276. */
  277. const char *name;
  278. private:
  279. /**
  280. * List of ir_function_signature for each overloaded function with this name.
  281. */
  282. struct exec_list signatures;
  283. };
  284. inline const char *ir_function_signature::function_name() const
  285. {
  286. return function->name;
  287. }
  288. /*@}*/
  289. /**
  290. * IR instruction representing high-level if-statements
  291. */
  292. class ir_if : public ir_instruction {
  293. public:
  294. ir_if(ir_rvalue *condition)
  295. : condition(condition)
  296. {
  297. /* empty */
  298. }
  299. virtual ir_if *as_if()
  300. {
  301. return this;
  302. }
  303. virtual void accept(ir_visitor *v)
  304. {
  305. v->visit(this);
  306. }
  307. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  308. ir_rvalue *condition;
  309. /** List of ir_instruction for the body of the then branch */
  310. exec_list then_instructions;
  311. /** List of ir_instruction for the body of the else branch */
  312. exec_list else_instructions;
  313. };
  314. /**
  315. * IR instruction representing a high-level loop structure.
  316. */
  317. class ir_loop : public ir_instruction {
  318. public:
  319. ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL)
  320. {
  321. /* empty */
  322. }
  323. virtual void accept(ir_visitor *v)
  324. {
  325. v->visit(this);
  326. }
  327. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  328. virtual ir_loop *as_loop()
  329. {
  330. return this;
  331. }
  332. /**
  333. * Get an iterator for the instructions of the loop body
  334. */
  335. exec_list_iterator iterator()
  336. {
  337. return body_instructions.iterator();
  338. }
  339. /** List of ir_instruction that make up the body of the loop. */
  340. exec_list body_instructions;
  341. /**
  342. * \name Loop counter and controls
  343. */
  344. /*@{*/
  345. ir_rvalue *from;
  346. ir_rvalue *to;
  347. ir_rvalue *increment;
  348. ir_variable *counter;
  349. /*@}*/
  350. };
  351. class ir_assignment : public ir_rvalue {
  352. public:
  353. ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
  354. virtual void accept(ir_visitor *v)
  355. {
  356. v->visit(this);
  357. }
  358. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  359. virtual ir_assignment * as_assignment()
  360. {
  361. return this;
  362. }
  363. /**
  364. * Left-hand side of the assignment.
  365. */
  366. ir_rvalue *lhs;
  367. /**
  368. * Value being assigned
  369. */
  370. ir_rvalue *rhs;
  371. /**
  372. * Optional condition for the assignment.
  373. */
  374. ir_rvalue *condition;
  375. };
  376. /* Update ir_expression::num_operands() and operator_strs when
  377. * updating this list.
  378. */
  379. enum ir_expression_operation {
  380. ir_unop_bit_not,
  381. ir_unop_logic_not,
  382. ir_unop_neg,
  383. ir_unop_abs,
  384. ir_unop_sign,
  385. ir_unop_rcp,
  386. ir_unop_rsq,
  387. ir_unop_sqrt,
  388. ir_unop_exp,
  389. ir_unop_log,
  390. ir_unop_exp2,
  391. ir_unop_log2,
  392. ir_unop_f2i, /**< Float-to-integer conversion. */
  393. ir_unop_i2f, /**< Integer-to-float conversion. */
  394. ir_unop_f2b, /**< Float-to-boolean conversion */
  395. ir_unop_b2f, /**< Boolean-to-float conversion */
  396. ir_unop_i2b, /**< int-to-boolean conversion */
  397. ir_unop_b2i, /**< Boolean-to-int conversion */
  398. ir_unop_u2f, /**< Unsigned-to-float conversion. */
  399. /**
  400. * \name Unary floating-point rounding operations.
  401. */
  402. /*@{*/
  403. ir_unop_trunc,
  404. ir_unop_ceil,
  405. ir_unop_floor,
  406. /*@}*/
  407. /**
  408. * \name Trigonometric operations.
  409. */
  410. /*@{*/
  411. ir_unop_sin,
  412. ir_unop_cos,
  413. /*@}*/
  414. /**
  415. * \name Partial derivatives.
  416. */
  417. /*@{*/
  418. ir_unop_dFdx,
  419. ir_unop_dFdy,
  420. /*@}*/
  421. ir_binop_add,
  422. ir_binop_sub,
  423. ir_binop_mul,
  424. ir_binop_div,
  425. ir_binop_mod,
  426. /**
  427. * \name Binary comparison operators
  428. */
  429. /*@{*/
  430. ir_binop_less,
  431. ir_binop_greater,
  432. ir_binop_lequal,
  433. ir_binop_gequal,
  434. ir_binop_equal,
  435. ir_binop_nequal,
  436. /*@}*/
  437. /**
  438. * \name Bit-wise binary operations.
  439. */
  440. /*@{*/
  441. ir_binop_lshift,
  442. ir_binop_rshift,
  443. ir_binop_bit_and,
  444. ir_binop_bit_xor,
  445. ir_binop_bit_or,
  446. /*@}*/
  447. ir_binop_logic_and,
  448. ir_binop_logic_xor,
  449. ir_binop_logic_or,
  450. ir_binop_dot,
  451. ir_binop_min,
  452. ir_binop_max,
  453. ir_binop_pow
  454. };
  455. class ir_expression : public ir_rvalue {
  456. public:
  457. ir_expression(int op, const struct glsl_type *type,
  458. ir_rvalue *, ir_rvalue *);
  459. static unsigned int get_num_operands(ir_expression_operation);
  460. unsigned int get_num_operands()
  461. {
  462. return get_num_operands(operation);
  463. }
  464. /**
  465. * Return a string representing this expression's operator.
  466. */
  467. const char *operator_string();
  468. /**
  469. * Do a reverse-lookup to translate the given string into an operator.
  470. */
  471. static ir_expression_operation get_operator(const char *);
  472. virtual void accept(ir_visitor *v)
  473. {
  474. v->visit(this);
  475. }
  476. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  477. ir_expression *clone();
  478. ir_expression_operation operation;
  479. ir_rvalue *operands[2];
  480. };
  481. /**
  482. * IR instruction representing a function call
  483. */
  484. class ir_call : public ir_rvalue {
  485. public:
  486. ir_call(const ir_function_signature *callee, exec_list *actual_parameters)
  487. : callee(callee)
  488. {
  489. assert(callee->return_type != NULL);
  490. type = callee->return_type;
  491. actual_parameters->move_nodes_to(& this->actual_parameters);
  492. }
  493. virtual ir_call *as_call()
  494. {
  495. return this;
  496. }
  497. virtual void accept(ir_visitor *v)
  498. {
  499. v->visit(this);
  500. }
  501. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  502. /**
  503. * Get a generic ir_call object when an error occurs
  504. */
  505. static ir_call *get_error_instruction();
  506. /**
  507. * Get an iterator for the set of acutal parameters
  508. */
  509. exec_list_iterator iterator()
  510. {
  511. return actual_parameters.iterator();
  512. }
  513. /**
  514. * Get the name of the function being called.
  515. */
  516. const char *callee_name() const
  517. {
  518. return callee->function_name();
  519. }
  520. const ir_function_signature *get_callee()
  521. {
  522. return callee;
  523. }
  524. /**
  525. * Generates an inline version of the function before @ir,
  526. * returning the return value of the function.
  527. */
  528. ir_rvalue *generate_inline(ir_instruction *ir);
  529. private:
  530. ir_call()
  531. : callee(NULL)
  532. {
  533. /* empty */
  534. }
  535. const ir_function_signature *callee;
  536. /* List of ir_rvalue of paramaters passed in this call. */
  537. exec_list actual_parameters;
  538. };
  539. /**
  540. * \name Jump-like IR instructions.
  541. *
  542. * These include \c break, \c continue, \c return, and \c discard.
  543. */
  544. /*@{*/
  545. class ir_jump : public ir_instruction {
  546. protected:
  547. ir_jump()
  548. {
  549. /* empty */
  550. }
  551. };
  552. class ir_return : public ir_jump {
  553. public:
  554. ir_return()
  555. : value(NULL)
  556. {
  557. /* empty */
  558. }
  559. ir_return(ir_rvalue *value)
  560. : value(value)
  561. {
  562. /* empty */
  563. }
  564. virtual ir_return *as_return()
  565. {
  566. return this;
  567. }
  568. ir_rvalue *get_value() const
  569. {
  570. return value;
  571. }
  572. virtual void accept(ir_visitor *v)
  573. {
  574. v->visit(this);
  575. }
  576. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  577. ir_rvalue *value;
  578. };
  579. /**
  580. * Jump instructions used inside loops
  581. *
  582. * These include \c break and \c continue. The \c break within a loop is
  583. * different from the \c break within a switch-statement.
  584. *
  585. * \sa ir_switch_jump
  586. */
  587. class ir_loop_jump : public ir_jump {
  588. public:
  589. enum jump_mode {
  590. jump_break,
  591. jump_continue
  592. };
  593. ir_loop_jump(ir_loop *loop, jump_mode mode)
  594. : loop(loop), mode(mode)
  595. {
  596. /* empty */
  597. }
  598. virtual void accept(ir_visitor *v)
  599. {
  600. v->visit(this);
  601. }
  602. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  603. bool is_break() const
  604. {
  605. return mode == jump_break;
  606. }
  607. bool is_continue() const
  608. {
  609. return mode == jump_continue;
  610. }
  611. private:
  612. /** Loop containing this break instruction. */
  613. ir_loop *loop;
  614. /** Mode selector for the jump instruction. */
  615. enum jump_mode mode;
  616. };
  617. /*@}*/
  618. /**
  619. * Texture sampling opcodes used in ir_texture
  620. */
  621. enum ir_texture_opcode {
  622. ir_tex, /* Regular texture look-up */
  623. ir_txb, /* Texture look-up with LOD bias */
  624. ir_txl, /* Texture look-up with explicit LOD */
  625. ir_txd, /* Texture look-up with partial derivatvies */
  626. ir_txf /* Texel fetch with explicit LOD */
  627. };
  628. /**
  629. * IR instruction to sample a texture
  630. *
  631. * The specific form of the IR instruction depends on the \c mode value
  632. * selected from \c ir_texture_opcodes. In the printed IR, these will
  633. * appear as:
  634. *
  635. * Texel offset
  636. * | Projection divisor
  637. * | | Shadow comparitor
  638. * | | |
  639. * v v v
  640. * (tex (sampler) (coordinate) (0 0 0) (1) ( ))
  641. * (txb (sampler) (coordinate) (0 0 0) (1) ( ) (bias))
  642. * (txl (sampler) (coordinate) (0 0 0) (1) ( ) (lod))
  643. * (txd (sampler) (coordinate) (0 0 0) (1) ( ) (dPdx dPdy))
  644. * (txf (sampler) (coordinate) (0 0 0) (lod))
  645. */
  646. class ir_texture : public ir_rvalue {
  647. public:
  648. ir_texture(enum ir_texture_opcode op)
  649. : op(op), projector(NULL), shadow_comparitor(NULL)
  650. {
  651. /* empty */
  652. }
  653. virtual void accept(ir_visitor *v)
  654. {
  655. v->visit(this);
  656. }
  657. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  658. /**
  659. * Return a string representing the ir_texture_opcode.
  660. */
  661. const char *opcode_string();
  662. /** Set the sampler and infer the type. */
  663. void set_sampler(ir_dereference *sampler);
  664. /**
  665. * Do a reverse-lookup to translate a string into an ir_texture_opcode.
  666. */
  667. static ir_texture_opcode get_opcode(const char *);
  668. enum ir_texture_opcode op;
  669. /** Sampler to use for the texture access. */
  670. ir_dereference *sampler;
  671. /** Texture coordinate to sample */
  672. ir_rvalue *coordinate;
  673. /**
  674. * Value used for projective divide.
  675. *
  676. * If there is no projective divide (the common case), this will be
  677. * \c NULL. Optimization passes should check for this to point to a constant
  678. * of 1.0 and replace that with \c NULL.
  679. */
  680. ir_rvalue *projector;
  681. /**
  682. * Coordinate used for comparison on shadow look-ups.
  683. *
  684. * If there is no shadow comparison, this will be \c NULL. For the
  685. * \c ir_txf opcode, this *must* be \c NULL.
  686. */
  687. ir_rvalue *shadow_comparitor;
  688. /** Explicit texel offsets. */
  689. signed char offsets[3];
  690. union {
  691. ir_rvalue *lod; /**< Floating point LOD */
  692. ir_rvalue *bias; /**< Floating point LOD bias */
  693. struct {
  694. ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
  695. ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
  696. } grad;
  697. } lod_info;
  698. };
  699. struct ir_swizzle_mask {
  700. unsigned x:2;
  701. unsigned y:2;
  702. unsigned z:2;
  703. unsigned w:2;
  704. /**
  705. * Number of components in the swizzle.
  706. */
  707. unsigned num_components:3;
  708. /**
  709. * Does the swizzle contain duplicate components?
  710. *
  711. * L-value swizzles cannot contain duplicate components.
  712. */
  713. unsigned has_duplicates:1;
  714. };
  715. class ir_swizzle : public ir_rvalue {
  716. public:
  717. ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
  718. unsigned count);
  719. ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
  720. virtual ir_swizzle *as_swizzle()
  721. {
  722. return this;
  723. }
  724. ir_swizzle *clone()
  725. {
  726. return new ir_swizzle(this->val, this->mask);
  727. }
  728. /**
  729. * Construct an ir_swizzle from the textual representation. Can fail.
  730. */
  731. static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length);
  732. virtual void accept(ir_visitor *v)
  733. {
  734. v->visit(this);
  735. }
  736. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  737. bool is_lvalue()
  738. {
  739. return val->is_lvalue() && !mask.has_duplicates;
  740. }
  741. /**
  742. * Get the variable that is ultimately referenced by an r-value
  743. */
  744. virtual ir_variable *variable_referenced();
  745. ir_rvalue *val;
  746. ir_swizzle_mask mask;
  747. };
  748. class ir_dereference : public ir_rvalue {
  749. public:
  750. virtual ir_dereference *as_dereference()
  751. {
  752. return this;
  753. }
  754. bool is_lvalue();
  755. /**
  756. * Get the variable that is ultimately referenced by an r-value
  757. */
  758. virtual ir_variable *variable_referenced() = 0;
  759. };
  760. class ir_dereference_variable : public ir_dereference {
  761. public:
  762. ir_dereference_variable(ir_variable *var);
  763. /**
  764. * Get the variable that is ultimately referenced by an r-value
  765. */
  766. virtual ir_variable *variable_referenced()
  767. {
  768. return this->var;
  769. }
  770. virtual ir_variable *whole_variable_referenced()
  771. {
  772. /* ir_dereference_variable objects always dereference the entire
  773. * variable. However, if this dereference is dereferenced by anything
  774. * else, the complete deferefernce chain is not a whole-variable
  775. * dereference. This method should only be called on the top most
  776. * ir_rvalue in a dereference chain.
  777. */
  778. return this->var;
  779. }
  780. virtual void accept(ir_visitor *v)
  781. {
  782. v->visit(this);
  783. }
  784. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  785. /**
  786. * Object being dereferenced.
  787. */
  788. ir_variable *var;
  789. };
  790. class ir_dereference_array : public ir_dereference {
  791. public:
  792. ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index);
  793. ir_dereference_array(ir_variable *var, ir_rvalue *array_index);
  794. virtual ir_dereference_array *as_dereference_array()
  795. {
  796. return this;
  797. }
  798. /**
  799. * Get the variable that is ultimately referenced by an r-value
  800. */
  801. virtual ir_variable *variable_referenced()
  802. {
  803. return this->array->variable_referenced();
  804. }
  805. virtual void accept(ir_visitor *v)
  806. {
  807. v->visit(this);
  808. }
  809. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  810. ir_rvalue *array;
  811. ir_rvalue *array_index;
  812. private:
  813. void set_array(ir_rvalue *value);
  814. };
  815. class ir_dereference_record : public ir_dereference {
  816. public:
  817. ir_dereference_record(ir_rvalue *value, const char *field);
  818. ir_dereference_record(ir_variable *var, const char *field);
  819. /**
  820. * Get the variable that is ultimately referenced by an r-value
  821. */
  822. virtual ir_variable *variable_referenced()
  823. {
  824. return this->record->variable_referenced();
  825. }
  826. virtual void accept(ir_visitor *v)
  827. {
  828. v->visit(this);
  829. }
  830. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  831. ir_rvalue *record;
  832. const char *field;
  833. };
  834. class ir_constant : public ir_rvalue {
  835. public:
  836. ir_constant(const struct glsl_type *type, const void *data);
  837. ir_constant(bool b);
  838. ir_constant(unsigned int u);
  839. ir_constant(int i);
  840. ir_constant(float f);
  841. virtual ir_constant *as_constant()
  842. {
  843. return this;
  844. }
  845. virtual void accept(ir_visitor *v)
  846. {
  847. v->visit(this);
  848. }
  849. virtual ir_visitor_status accept(ir_hierarchical_visitor *);
  850. ir_constant *clone()
  851. {
  852. return new ir_constant(this->type, &this->value);
  853. }
  854. /**
  855. * Value of the constant.
  856. *
  857. * The field used to back the values supplied by the constant is determined
  858. * by the type associated with the \c ir_instruction. Constants may be
  859. * scalars, vectors, or matrices.
  860. */
  861. union {
  862. unsigned u[16];
  863. int i[16];
  864. float f[16];
  865. bool b[16];
  866. } value;
  867. };
  868. void
  869. visit_exec_list(exec_list *list, ir_visitor *visitor);
  870. extern void
  871. _mesa_glsl_initialize_variables(exec_list *instructions,
  872. struct _mesa_glsl_parse_state *state);
  873. extern void
  874. _mesa_glsl_initialize_functions(exec_list *instructions,
  875. struct _mesa_glsl_parse_state *state);
  876. #endif /* IR_H */