76e46ff107f3a419ae09b00f6f1a1866ba3426ad
[mesa.git] / src / gallium / drivers / vc4 / vc4_qir.h
1 /*
2 * Copyright © 2014 Broadcom
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 DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef VC4_QIR_H
25 #define VC4_QIR_H
26
27 #include <stdint.h>
28
29 #include "util/u_simple_list.h"
30
31 enum qfile {
32 QFILE_NULL,
33 QFILE_TEMP,
34 QFILE_VARY,
35 QFILE_UNIF,
36 };
37
38 struct qreg {
39 enum qfile file;
40 uint32_t index;
41 };
42
43 enum qop {
44 QOP_UNDEF,
45 QOP_MOV,
46 QOP_FADD,
47 QOP_FSUB,
48 QOP_FMUL,
49 QOP_FMIN,
50 QOP_FMAX,
51 QOP_FMINABS,
52 QOP_FMAXABS,
53
54 QOP_SEQ,
55 QOP_SNE,
56 QOP_SGE,
57 QOP_SLT,
58 QOP_CMP,
59
60 QOP_FTOI,
61 QOP_RCP,
62 QOP_RSQ,
63 QOP_EXP2,
64 QOP_LOG2,
65 QOP_VW_SETUP,
66 QOP_VR_SETUP,
67 QOP_PACK_SCALED,
68 QOP_PACK_COLORS,
69 QOP_VPM_WRITE,
70 QOP_VPM_READ,
71 QOP_TLB_COLOR_WRITE,
72 QOP_VARY_ADD_C,
73 };
74
75 struct simple_node {
76 struct simple_node *next;
77 struct simple_node *prev;
78 };
79
80 struct qinst {
81 struct simple_node link;
82
83 enum qop op;
84 struct qreg dst;
85 struct qreg *src;
86 };
87
88 enum qstage {
89 /**
90 * Coordinate shader, runs during binning, before the VS, and just
91 * outputs position.
92 */
93 QSTAGE_COORD,
94 QSTAGE_VERT,
95 QSTAGE_FRAG,
96 };
97
98 enum quniform_contents {
99 /**
100 * Indicates that a constant 32-bit value is copied from the program's
101 * uniform contents.
102 */
103 QUNIFORM_CONSTANT,
104 /**
105 * Indicates that the program's uniform contents are used as an index
106 * into the GL uniform storage.
107 */
108 QUNIFORM_UNIFORM,
109
110 /** @{
111 * Scaling factors from clip coordinates to relative to the viewport
112 * center.
113 *
114 * This is used by the coordinate and vertex shaders to produce the
115 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
116 * point offsets from the viewport ccenter.
117 */
118 QUNIFORM_VIEWPORT_X_SCALE,
119 QUNIFORM_VIEWPORT_Y_SCALE,
120 /** @} */
121 };
122
123 struct qcompile {
124 struct qreg undef;
125 enum qstage stage;
126 uint32_t num_temps;
127 struct simple_node instructions;
128 uint32_t immediates[1024];
129
130 struct simple_node qpu_inst_list;
131 uint64_t *qpu_insts;
132 uint32_t qpu_inst_count;
133 uint32_t qpu_inst_size;
134 };
135
136 struct qcompile *qir_compile_init(void);
137 void qir_compile_destroy(struct qcompile *c);
138 struct qinst *qir_inst(enum qop op, struct qreg dst,
139 struct qreg src0, struct qreg src1);
140 struct qinst *qir_inst4(enum qop op, struct qreg dst,
141 struct qreg a,
142 struct qreg b,
143 struct qreg c,
144 struct qreg d);
145 void qir_emit(struct qcompile *c, struct qinst *inst);
146 struct qreg qir_get_temp(struct qcompile *c);
147 int qir_get_op_nsrc(enum qop qop);
148
149 void qir_dump(struct qcompile *c);
150 void qir_dump_inst(struct qinst *inst);
151 const char *qir_get_stage_name(enum qstage stage);
152
153 #define QIR_ALU1(name) \
154 static inline struct qreg \
155 qir_##name(struct qcompile *c, struct qreg a) \
156 { \
157 struct qreg t = qir_get_temp(c); \
158 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
159 return t; \
160 }
161
162 #define QIR_ALU2(name) \
163 static inline struct qreg \
164 qir_##name(struct qcompile *c, struct qreg a, struct qreg b) \
165 { \
166 struct qreg t = qir_get_temp(c); \
167 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
168 return t; \
169 }
170
171 QIR_ALU1(MOV)
172 QIR_ALU2(FADD)
173 QIR_ALU2(FSUB)
174 QIR_ALU2(FMUL)
175 QIR_ALU2(FMIN)
176 QIR_ALU2(FMAX)
177 QIR_ALU2(FMINABS)
178 QIR_ALU2(FMAXABS)
179 QIR_ALU1(FTOI)
180 QIR_ALU1(RCP)
181 QIR_ALU1(RSQ)
182 QIR_ALU1(EXP2)
183 QIR_ALU1(LOG2)
184 QIR_ALU2(PACK_SCALED)
185 QIR_ALU1(VARY_ADD_C)
186
187 static inline void
188 qir_VPM_WRITE(struct qcompile *c, struct qreg a)
189 {
190 qir_emit(c, qir_inst(QOP_VPM_WRITE, c->undef, a, c->undef));
191 }
192
193 #endif /* VC4_QIR_H */