2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
26 #include "shader/prog_instruction.h"
32 * Translates the IR to Mesa IR if possible.
36 * This struct is a corresponding struct to Mesa prog_src_register, with
39 typedef struct ir_to_mesa_src_reg {
40 int file; /**< PROGRAM_* from Mesa */
41 int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */
42 int swizzle; /**< SWIZZLE_XYZWONEZERO swizzles from Mesa. */
43 int negate; /**< NEGATE_XYZW mask from mesa */
44 bool reladdr; /**< Register index should be offset by address reg. */
47 typedef struct ir_to_mesa_dst_reg {
48 int file; /**< PROGRAM_* from Mesa */
49 int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */
50 int writemask; /**< Bitfield of WRITEMASK_[XYZW] */
53 extern ir_to_mesa_src_reg ir_to_mesa_undef;
55 class ir_to_mesa_instruction : public exec_node {
58 ir_to_mesa_dst_reg dst_reg;
59 ir_to_mesa_src_reg src_reg[3];
60 /** Pointer to the ir source this tree came from for debugging */
69 class ir_to_mesa_visitor *v;
71 /** Pointer to the ir source this tree came from for debugging */
74 ir_to_mesa_dst_reg dst_reg;
77 * This is the representation of this tree node's results as a
78 * source register for its consumer.
80 ir_to_mesa_src_reg src_reg;
83 void do_ir_to_mesa(exec_list *instructions);
85 class temp_entry : public exec_node {
87 temp_entry(ir_variable *var, int file, int index)
88 : file(file), index(index), var(var)
95 ir_variable *var; /* variable that maps to this, if any */
98 class ir_to_mesa_visitor : public ir_visitor {
100 ir_to_mesa_visitor();
105 ir_to_mesa_src_reg get_temp(int size);
107 ir_to_mesa_src_reg get_temp_for_var(ir_variable *var);
109 struct ir_to_mesa_src_reg src_reg_for_float(float val);
112 * \name Visit methods
114 * As typical for the visitor pattern, there must be one \c visit method for
115 * each concrete subclass of \c ir_instruction. Virtual base classes within
116 * the hierarchy should not have \c visit methods.
119 virtual void visit(ir_variable *);
120 virtual void visit(ir_loop *);
121 virtual void visit(ir_loop_jump *);
122 virtual void visit(ir_function_signature *);
123 virtual void visit(ir_function *);
124 virtual void visit(ir_expression *);
125 virtual void visit(ir_swizzle *);
126 virtual void visit(ir_dereference_variable *);
127 virtual void visit(ir_dereference_array *);
128 virtual void visit(ir_dereference_record *);
129 virtual void visit(ir_assignment *);
130 virtual void visit(ir_constant *);
131 virtual void visit(ir_call *);
132 virtual void visit(ir_return *);
133 virtual void visit(ir_texture *);
134 virtual void visit(ir_if *);
137 struct ir_to_mesa_src_reg result;
139 /** List of temp_entry */
140 exec_list variable_storage;
142 /** List of ir_to_mesa_instruction */
143 exec_list instructions;
145 ir_to_mesa_instruction *ir_to_mesa_emit_op1(ir_instruction *ir,
147 ir_to_mesa_dst_reg dst,
148 ir_to_mesa_src_reg src0);
150 ir_to_mesa_instruction *ir_to_mesa_emit_op2(ir_instruction *ir,
152 ir_to_mesa_dst_reg dst,
153 ir_to_mesa_src_reg src0,
154 ir_to_mesa_src_reg src1);
156 ir_to_mesa_instruction *ir_to_mesa_emit_op3(ir_instruction *ir,
158 ir_to_mesa_dst_reg dst,
159 ir_to_mesa_src_reg src0,
160 ir_to_mesa_src_reg src1,
161 ir_to_mesa_src_reg src2);
163 void ir_to_mesa_emit_scalar_op1(ir_instruction *ir,
165 ir_to_mesa_dst_reg dst,
166 ir_to_mesa_src_reg src0);
169 extern ir_to_mesa_src_reg ir_to_mesa_undef;
170 extern ir_to_mesa_dst_reg ir_to_mesa_undef_dst;