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
32 #include "util/u_simple_list.h"
75 QOP_TLB_DISCARD_SETUP
,
76 QOP_TLB_PASSTHROUGH_Z_WRITE
,
86 /** Texture x coordinate parameter write */
88 /** Texture y coordinate parameter write */
90 /** Texture border color parameter or cube map z coordinate write */
92 /** Texture LOD bias parameter write */
95 * Signal of texture read being necessary and then reading r4 into
106 struct simple_node
*next
;
107 struct simple_node
*prev
;
111 struct simple_node link
;
120 * Coordinate shader, runs during binning, before the VS, and just
128 enum quniform_contents
{
130 * Indicates that a constant 32-bit value is copied from the program's
135 * Indicates that the program's uniform contents are used as an index
136 * into the GL uniform storage.
141 * Scaling factors from clip coordinates to relative to the viewport
144 * This is used by the coordinate and vertex shaders to produce the
145 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
146 * point offsets from the viewport ccenter.
148 QUNIFORM_VIEWPORT_X_SCALE
,
149 QUNIFORM_VIEWPORT_Y_SCALE
,
152 QUNIFORM_VIEWPORT_Z_OFFSET
,
153 QUNIFORM_VIEWPORT_Z_SCALE
,
156 * A reference to a texture config parameter 0 uniform.
158 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
159 * defines texture type, miplevels, and such. It will be found as a
160 * parameter to the first QOP_TEX_[STRB] instruction in a sequence.
162 QUNIFORM_TEXTURE_CONFIG_P0
,
165 * A reference to a texture config parameter 1 uniform.
167 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
168 * defines texture width, height, filters, and wrap modes. It will be
169 * found as a parameter to the second QOP_TEX_[STRB] instruction in a
172 QUNIFORM_TEXTURE_CONFIG_P1
,
174 QUNIFORM_TEXRECT_SCALE_X
,
175 QUNIFORM_TEXRECT_SCALE_Y
,
177 QUNIFORM_BLEND_CONST_COLOR
,
184 struct simple_node instructions
;
185 uint32_t immediates
[1024];
187 struct simple_node qpu_inst_list
;
189 uint32_t qpu_inst_count
;
190 uint32_t qpu_inst_size
;
194 struct qcompile
*qir_compile_init(void);
195 void qir_compile_destroy(struct qcompile
*c
);
196 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
197 struct qreg src0
, struct qreg src1
);
198 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
203 void qir_emit(struct qcompile
*c
, struct qinst
*inst
);
204 struct qreg
qir_get_temp(struct qcompile
*c
);
205 int qir_get_op_nsrc(enum qop qop
);
206 bool qir_reg_equals(struct qreg a
, struct qreg b
);
207 bool qir_has_side_effects(struct qinst
*inst
);
209 void qir_dump(struct qcompile
*c
);
210 void qir_dump_inst(struct qinst
*inst
);
211 const char *qir_get_stage_name(enum qstage stage
);
213 void qir_optimize(struct qcompile
*c
);
214 bool qir_opt_algebraic(struct qcompile
*c
);
215 bool qir_opt_copy_propagation(struct qcompile
*c
);
216 bool qir_opt_dead_code(struct qcompile
*c
);
218 #define QIR_ALU0(name) \
219 static inline struct qreg \
220 qir_##name(struct qcompile *c) \
222 struct qreg t = qir_get_temp(c); \
223 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
227 #define QIR_ALU1(name) \
228 static inline struct qreg \
229 qir_##name(struct qcompile *c, struct qreg a) \
231 struct qreg t = qir_get_temp(c); \
232 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
236 #define QIR_ALU2(name) \
237 static inline struct qreg \
238 qir_##name(struct qcompile *c, struct qreg a, struct qreg b) \
240 struct qreg t = qir_get_temp(c); \
241 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
245 #define QIR_NODST_1(name) \
247 qir_##name(struct qcompile *c, struct qreg a) \
249 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
252 #define QIR_NODST_2(name) \
254 qir_##name(struct qcompile *c, struct qreg a, struct qreg b) \
256 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
273 QIR_ALU2(PACK_SCALED
)
275 QIR_NODST_1(VPM_WRITE
)
284 QIR_NODST_1(TLB_DISCARD_SETUP
)
286 static inline struct qreg
287 qir_CMP(struct qcompile
*c
, struct qreg cmp
, struct qreg a
, struct qreg b
)
289 struct qreg t
= qir_get_temp(c
);
290 qir_emit(c
, qir_inst4(QOP_CMP
, t
, cmp
, a
, b
, c
->undef
));
294 static inline struct qreg
295 qir_R4_UNPACK(struct qcompile
*c
, int i
)
297 struct qreg t
= qir_get_temp(c
);
298 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
302 #endif /* VC4_QIR_H */