2 * Copyright © 2014 Broadcom
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 DEALINGS
33 #include "util/u_simple_list.h"
70 /* Sets the flag register according to src. */
73 /* Note: Orderings of these compares must be the same as in
74 * qpu_defines.h. Selects the src[0] if the ns flag bit is set,
80 /* Selects the src[0] if the ns flag bit is set, otherwise src[1]. */
98 QOP_TLB_DISCARD_SETUP
,
99 QOP_TLB_PASSTHROUGH_Z_WRITE
,
109 /** Texture x coordinate parameter write */
111 /** Texture y coordinate parameter write */
113 /** Texture border color parameter or cube map z coordinate write */
115 /** Texture LOD bias parameter write */
118 * Signal of texture read being necessary and then reading r4 into
129 struct simple_node
*next
;
130 struct simple_node
*prev
;
134 struct simple_node link
;
143 * Coordinate shader, runs during binning, before the VS, and just
151 enum quniform_contents
{
153 * Indicates that a constant 32-bit value is copied from the program's
158 * Indicates that the program's uniform contents are used as an index
159 * into the GL uniform storage.
164 * Scaling factors from clip coordinates to relative to the viewport
167 * This is used by the coordinate and vertex shaders to produce the
168 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
169 * point offsets from the viewport ccenter.
171 QUNIFORM_VIEWPORT_X_SCALE
,
172 QUNIFORM_VIEWPORT_Y_SCALE
,
175 QUNIFORM_VIEWPORT_Z_OFFSET
,
176 QUNIFORM_VIEWPORT_Z_SCALE
,
179 * A reference to a texture config parameter 0 uniform.
181 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
182 * defines texture type, miplevels, and such. It will be found as a
183 * parameter to the first QOP_TEX_[STRB] instruction in a sequence.
185 QUNIFORM_TEXTURE_CONFIG_P0
,
188 * A reference to a texture config parameter 1 uniform.
190 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
191 * defines texture width, height, filters, and wrap modes. It will be
192 * found as a parameter to the second QOP_TEX_[STRB] instruction in a
195 QUNIFORM_TEXTURE_CONFIG_P1
,
197 QUNIFORM_TEXRECT_SCALE_X
,
198 QUNIFORM_TEXRECT_SCALE_Y
,
200 QUNIFORM_BLEND_CONST_COLOR
,
207 struct simple_node instructions
;
208 uint32_t immediates
[1024];
210 struct simple_node qpu_inst_list
;
212 uint32_t qpu_inst_count
;
213 uint32_t qpu_inst_size
;
217 struct qcompile
*qir_compile_init(void);
218 void qir_compile_destroy(struct qcompile
*c
);
219 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
220 struct qreg src0
, struct qreg src1
);
221 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
226 void qir_emit(struct qcompile
*c
, struct qinst
*inst
);
227 struct qreg
qir_get_temp(struct qcompile
*c
);
228 int qir_get_op_nsrc(enum qop qop
);
229 bool qir_reg_equals(struct qreg a
, struct qreg b
);
230 bool qir_has_side_effects(struct qinst
*inst
);
231 bool qir_depends_on_flags(struct qinst
*inst
);
232 bool qir_writes_r4(struct qinst
*inst
);
233 bool qir_reads_r4(struct qinst
*inst
);
235 void qir_dump(struct qcompile
*c
);
236 void qir_dump_inst(struct qinst
*inst
);
237 const char *qir_get_stage_name(enum qstage stage
);
239 void qir_optimize(struct qcompile
*c
);
240 bool qir_opt_algebraic(struct qcompile
*c
);
241 bool qir_opt_copy_propagation(struct qcompile
*c
);
242 bool qir_opt_cse(struct qcompile
*c
);
243 bool qir_opt_dead_code(struct qcompile
*c
);
245 #define QIR_ALU0(name) \
246 static inline struct qreg \
247 qir_##name(struct qcompile *c) \
249 struct qreg t = qir_get_temp(c); \
250 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
254 #define QIR_ALU1(name) \
255 static inline struct qreg \
256 qir_##name(struct qcompile *c, struct qreg a) \
258 struct qreg t = qir_get_temp(c); \
259 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
263 #define QIR_ALU2(name) \
264 static inline struct qreg \
265 qir_##name(struct qcompile *c, struct qreg a, struct qreg b) \
267 struct qreg t = qir_get_temp(c); \
268 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
272 #define QIR_NODST_1(name) \
274 qir_##name(struct qcompile *c, struct qreg a) \
276 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
279 #define QIR_NODST_2(name) \
281 qir_##name(struct qcompile *c, struct qreg a, struct qreg b) \
283 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
323 QIR_ALU2(PACK_SCALED
)
325 QIR_NODST_1(VPM_WRITE
)
334 QIR_NODST_1(TLB_DISCARD_SETUP
)
336 static inline struct qreg
337 qir_R4_UNPACK(struct qcompile
*c
, int i
)
339 struct qreg t
= qir_get_temp(c
);
340 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
344 static inline struct qreg
345 qir_SEL_X_0_COND(struct qcompile
*c
, int i
)
347 struct qreg t
= qir_get_temp(c
);
348 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
352 #endif /* VC4_QIR_H */