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"
34 #include "tgsi/tgsi_parse.h"
71 /* Sets the flag register according to src. */
74 /* Note: Orderings of these compares must be the same as in
75 * qpu_defines.h. Selects the src[0] if the ns flag bit is set,
81 /* Selects the src[0] if the ns flag bit is set, otherwise src[1]. */
99 QOP_TLB_DISCARD_SETUP
,
100 QOP_TLB_PASSTHROUGH_Z_WRITE
,
110 /** Texture x coordinate parameter write */
112 /** Texture y coordinate parameter write */
114 /** Texture border color parameter or cube map z coordinate write */
116 /** Texture LOD bias parameter write */
119 * Signal of texture read being necessary and then reading r4 into
130 struct simple_node
*next
;
131 struct simple_node
*prev
;
135 struct simple_node link
;
144 * Coordinate shader, runs during binning, before the VS, and just
152 enum quniform_contents
{
154 * Indicates that a constant 32-bit value is copied from the program's
159 * Indicates that the program's uniform contents are used as an index
160 * into the GL uniform storage.
165 * Scaling factors from clip coordinates to relative to the viewport
168 * This is used by the coordinate and vertex shaders to produce the
169 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
170 * point offsets from the viewport ccenter.
172 QUNIFORM_VIEWPORT_X_SCALE
,
173 QUNIFORM_VIEWPORT_Y_SCALE
,
176 QUNIFORM_VIEWPORT_Z_OFFSET
,
177 QUNIFORM_VIEWPORT_Z_SCALE
,
180 * A reference to a texture config parameter 0 uniform.
182 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
183 * defines texture type, miplevels, and such. It will be found as a
184 * parameter to the first QOP_TEX_[STRB] instruction in a sequence.
186 QUNIFORM_TEXTURE_CONFIG_P0
,
189 * A reference to a texture config parameter 1 uniform.
191 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
192 * defines texture width, height, filters, and wrap modes. It will be
193 * found as a parameter to the second QOP_TEX_[STRB] instruction in a
196 QUNIFORM_TEXTURE_CONFIG_P1
,
198 QUNIFORM_TEXRECT_SCALE_X
,
199 QUNIFORM_TEXRECT_SCALE_Y
,
201 QUNIFORM_BLEND_CONST_COLOR
,
205 struct tgsi_parse_context parser
;
208 struct qreg
*outputs
;
209 struct qreg
*uniforms
;
212 struct qreg line_x
, point_x
, point_y
;
215 struct pipe_shader_state
*shader_state
;
217 struct vc4_fs_key
*fs_key
;
218 struct vc4_vs_key
*vs_key
;
220 uint32_t *uniform_data
;
221 enum quniform_contents
*uniform_contents
;
222 uint32_t num_uniforms
;
223 uint32_t num_outputs
;
224 uint32_t num_texture_samples
;
229 struct simple_node instructions
;
230 uint32_t immediates
[1024];
232 struct simple_node qpu_inst_list
;
234 uint32_t qpu_inst_count
;
235 uint32_t qpu_inst_size
;
239 struct vc4_compile
*qir_compile_init(void);
240 void qir_compile_destroy(struct vc4_compile
*c
);
241 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
242 struct qreg src0
, struct qreg src1
);
243 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
248 void qir_emit(struct vc4_compile
*c
, struct qinst
*inst
);
249 struct qreg
qir_get_temp(struct vc4_compile
*c
);
250 int qir_get_op_nsrc(enum qop qop
);
251 bool qir_reg_equals(struct qreg a
, struct qreg b
);
252 bool qir_has_side_effects(struct qinst
*inst
);
253 bool qir_depends_on_flags(struct qinst
*inst
);
254 bool qir_writes_r4(struct qinst
*inst
);
255 bool qir_reads_r4(struct qinst
*inst
);
257 void qir_dump(struct vc4_compile
*c
);
258 void qir_dump_inst(struct qinst
*inst
);
259 const char *qir_get_stage_name(enum qstage stage
);
261 void qir_optimize(struct vc4_compile
*c
);
262 bool qir_opt_algebraic(struct vc4_compile
*c
);
263 bool qir_opt_copy_propagation(struct vc4_compile
*c
);
264 bool qir_opt_cse(struct vc4_compile
*c
);
265 bool qir_opt_dead_code(struct vc4_compile
*c
);
267 #define QIR_ALU0(name) \
268 static inline struct qreg \
269 qir_##name(struct vc4_compile *c) \
271 struct qreg t = qir_get_temp(c); \
272 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
276 #define QIR_ALU1(name) \
277 static inline struct qreg \
278 qir_##name(struct vc4_compile *c, struct qreg a) \
280 struct qreg t = qir_get_temp(c); \
281 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
285 #define QIR_ALU2(name) \
286 static inline struct qreg \
287 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
289 struct qreg t = qir_get_temp(c); \
290 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
294 #define QIR_NODST_1(name) \
296 qir_##name(struct vc4_compile *c, struct qreg a) \
298 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
301 #define QIR_NODST_2(name) \
303 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
305 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
345 QIR_ALU2(PACK_SCALED
)
347 QIR_NODST_1(VPM_WRITE
)
356 QIR_NODST_1(TLB_DISCARD_SETUP
)
358 static inline struct qreg
359 qir_R4_UNPACK(struct vc4_compile
*c
, int i
)
361 struct qreg t
= qir_get_temp(c
);
362 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
366 static inline struct qreg
367 qir_SEL_X_0_COND(struct vc4_compile
*c
, int i
)
369 struct qreg t
= qir_get_temp(c
);
370 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
374 #endif /* VC4_QIR_H */