OSDN Git Service

ir_to_mesa: Remove the BURG code.
[android-x86/external-mesa.git] / ir_to_mesa.h
1 /*
2  * Copyright © 2010 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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.
22  */
23
24 #include "ir.h"
25 extern "C" {
26 #include "shader/prog_instruction.h"
27 };
28
29 /**
30  * \file ir_to_mesa.h
31  *
32  * Translates the IR to Mesa IR if possible.
33  */
34
35 /**
36  * This struct is a corresponding struct to Mesa prog_src_register, with
37  * wider fields.
38  */
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. */
45 } ir_to_mesa_src_reg;
46
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] */
51 } ir_to_mesa_dst_reg;
52
53 extern ir_to_mesa_src_reg ir_to_mesa_undef;
54
55 class ir_to_mesa_instruction : public exec_node {
56 public:
57    enum prog_opcode op;
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 */
61    ir_instruction *ir;
62 };
63
64 struct mbtree {
65    struct mbtree *left;
66    struct mbtree *right;
67    void *state;
68    uint16_t op;
69    class ir_to_mesa_visitor *v;
70
71    /** Pointer to the ir source this tree came from for debugging */
72    ir_instruction *ir;
73
74    ir_to_mesa_dst_reg dst_reg;
75
76    /**
77     * This is the representation of this tree node's results as a
78     * source register for its consumer.
79     */
80    ir_to_mesa_src_reg src_reg;
81 };
82
83 void do_ir_to_mesa(exec_list *instructions);
84
85 class temp_entry : public exec_node {
86 public:
87    temp_entry(ir_variable *var, int file, int index)
88       : file(file), index(index), var(var)
89    {
90       /* empty */
91    }
92
93    int file;
94    int index;
95    ir_variable *var; /* variable that maps to this, if any */
96 };
97
98 class ir_to_mesa_visitor : public ir_visitor {
99 public:
100    ir_to_mesa_visitor();
101
102    int next_temp;
103    int next_constant;
104
105    ir_to_mesa_src_reg get_temp(int size);
106
107    ir_to_mesa_src_reg get_temp_for_var(ir_variable *var);
108
109    struct ir_to_mesa_src_reg src_reg_for_float(float val);
110
111    /**
112     * \name Visit methods
113     *
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.
117     */
118    /*@{*/
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 *);
135    /*@}*/
136
137    struct ir_to_mesa_src_reg result;
138
139    /** List of temp_entry */
140    exec_list variable_storage;
141
142    /** List of ir_to_mesa_instruction */
143    exec_list instructions;
144
145    ir_to_mesa_instruction *ir_to_mesa_emit_op1(ir_instruction *ir,
146                                                enum prog_opcode op,
147                                                ir_to_mesa_dst_reg dst,
148                                                ir_to_mesa_src_reg src0);
149
150    ir_to_mesa_instruction *ir_to_mesa_emit_op2(ir_instruction *ir,
151                                                enum prog_opcode op,
152                                                ir_to_mesa_dst_reg dst,
153                                                ir_to_mesa_src_reg src0,
154                                                ir_to_mesa_src_reg src1);
155
156    ir_to_mesa_instruction *ir_to_mesa_emit_op3(ir_instruction *ir,
157                                                enum prog_opcode op,
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);
162
163    void ir_to_mesa_emit_scalar_op1(ir_instruction *ir,
164                                    enum prog_opcode op,
165                                    ir_to_mesa_dst_reg dst,
166                                    ir_to_mesa_src_reg src0);
167 };
168
169 extern ir_to_mesa_src_reg ir_to_mesa_undef;
170 extern ir_to_mesa_dst_reg ir_to_mesa_undef_dst;
171