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
,
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
;
211 uint32_t temps_array_size
;
212 uint32_t inputs_array_size
;
213 uint32_t outputs_array_size
;
214 uint32_t uniforms_array_size
;
215 uint32_t consts_array_size
;
217 struct qreg line_x
, point_x
, point_y
;
220 struct pipe_shader_state
*shader_state
;
222 struct vc4_fs_key
*fs_key
;
223 struct vc4_vs_key
*vs_key
;
225 uint32_t *uniform_data
;
226 enum quniform_contents
*uniform_contents
;
227 uint32_t num_uniforms
;
228 uint32_t num_outputs
;
229 uint32_t num_texture_samples
;
230 uint32_t output_position_index
;
231 uint32_t output_color_index
;
236 struct simple_node instructions
;
237 uint32_t immediates
[1024];
239 struct simple_node qpu_inst_list
;
241 uint32_t qpu_inst_count
;
242 uint32_t qpu_inst_size
;
246 struct vc4_compile
*qir_compile_init(void);
247 void qir_compile_destroy(struct vc4_compile
*c
);
248 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
249 struct qreg src0
, struct qreg src1
);
250 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
255 void qir_remove_instruction(struct qinst
*qinst
);
256 void qir_emit(struct vc4_compile
*c
, struct qinst
*inst
);
257 struct qreg
qir_get_temp(struct vc4_compile
*c
);
258 int qir_get_op_nsrc(enum qop qop
);
259 bool qir_reg_equals(struct qreg a
, struct qreg b
);
260 bool qir_has_side_effects(struct qinst
*inst
);
261 bool qir_depends_on_flags(struct qinst
*inst
);
262 bool qir_writes_r4(struct qinst
*inst
);
263 bool qir_reads_r4(struct qinst
*inst
);
265 void qir_dump(struct vc4_compile
*c
);
266 void qir_dump_inst(struct qinst
*inst
);
267 const char *qir_get_stage_name(enum qstage stage
);
269 void qir_optimize(struct vc4_compile
*c
);
270 bool qir_opt_algebraic(struct vc4_compile
*c
);
271 bool qir_opt_copy_propagation(struct vc4_compile
*c
);
272 bool qir_opt_cse(struct vc4_compile
*c
);
273 bool qir_opt_dead_code(struct vc4_compile
*c
);
275 #define QIR_ALU0(name) \
276 static inline struct qreg \
277 qir_##name(struct vc4_compile *c) \
279 struct qreg t = qir_get_temp(c); \
280 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
284 #define QIR_ALU1(name) \
285 static inline struct qreg \
286 qir_##name(struct vc4_compile *c, struct qreg a) \
288 struct qreg t = qir_get_temp(c); \
289 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
293 #define QIR_ALU2(name) \
294 static inline struct qreg \
295 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
297 struct qreg t = qir_get_temp(c); \
298 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
302 #define QIR_NODST_1(name) \
304 qir_##name(struct vc4_compile *c, struct qreg a) \
306 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
309 #define QIR_NODST_2(name) \
311 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
313 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
353 QIR_ALU2(PACK_SCALED
)
355 QIR_NODST_1(VPM_WRITE
)
365 QIR_ALU0(TLB_COLOR_READ
)
366 QIR_NODST_1(TLB_Z_WRITE
)
367 QIR_NODST_1(TLB_DISCARD_SETUP
)
369 static inline struct qreg
370 qir_R4_UNPACK(struct vc4_compile
*c
, struct qreg r4
, int i
)
372 struct qreg t
= qir_get_temp(c
);
373 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, r4
, c
->undef
));
377 static inline struct qreg
378 qir_SEL_X_0_COND(struct vc4_compile
*c
, int i
)
380 struct qreg t
= qir_get_temp(c
);
381 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
385 #endif /* VC4_QIR_H */