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_STENCIL_SETUP
,
111 /** Texture x coordinate parameter write */
113 /** Texture y coordinate parameter write */
115 /** Texture border color parameter or cube map z coordinate write */
117 /** Texture LOD bias parameter write */
120 * Signal of texture read being necessary and then reading r4 into
131 struct simple_node
*next
;
132 struct simple_node
*prev
;
136 struct simple_node link
;
145 * Coordinate shader, runs during binning, before the VS, and just
153 enum quniform_contents
{
155 * Indicates that a constant 32-bit value is copied from the program's
160 * Indicates that the program's uniform contents are used as an index
161 * into the GL uniform storage.
166 * Scaling factors from clip coordinates to relative to the viewport
169 * This is used by the coordinate and vertex shaders to produce the
170 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
171 * point offsets from the viewport ccenter.
173 QUNIFORM_VIEWPORT_X_SCALE
,
174 QUNIFORM_VIEWPORT_Y_SCALE
,
177 QUNIFORM_VIEWPORT_Z_OFFSET
,
178 QUNIFORM_VIEWPORT_Z_SCALE
,
181 * A reference to a texture config parameter 0 uniform.
183 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
184 * defines texture type, miplevels, and such. It will be found as a
185 * parameter to the first QOP_TEX_[STRB] instruction in a sequence.
187 QUNIFORM_TEXTURE_CONFIG_P0
,
190 * A reference to a texture config parameter 1 uniform.
192 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
193 * defines texture width, height, filters, and wrap modes. It will be
194 * found as a parameter to the second QOP_TEX_[STRB] instruction in a
197 QUNIFORM_TEXTURE_CONFIG_P1
,
199 QUNIFORM_TEXRECT_SCALE_X
,
200 QUNIFORM_TEXRECT_SCALE_Y
,
202 QUNIFORM_BLEND_CONST_COLOR
,
207 struct tgsi_parse_context parser
;
210 struct qreg
*outputs
;
211 struct qreg
*uniforms
;
213 uint32_t temps_array_size
;
214 uint32_t inputs_array_size
;
215 uint32_t outputs_array_size
;
216 uint32_t uniforms_array_size
;
217 uint32_t consts_array_size
;
219 struct qreg line_x
, point_x
, point_y
;
222 struct pipe_shader_state
*shader_state
;
224 struct vc4_fs_key
*fs_key
;
225 struct vc4_vs_key
*vs_key
;
227 uint32_t *uniform_data
;
228 enum quniform_contents
*uniform_contents
;
229 uint32_t num_uniforms
;
230 uint32_t num_outputs
;
231 uint32_t num_texture_samples
;
232 uint32_t output_position_index
;
233 uint32_t output_color_index
;
238 struct simple_node instructions
;
239 uint32_t immediates
[1024];
241 struct simple_node qpu_inst_list
;
243 uint32_t qpu_inst_count
;
244 uint32_t qpu_inst_size
;
248 struct vc4_compile
*qir_compile_init(void);
249 void qir_compile_destroy(struct vc4_compile
*c
);
250 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
251 struct qreg src0
, struct qreg src1
);
252 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
257 void qir_remove_instruction(struct qinst
*qinst
);
258 void qir_reorder_uniforms(struct vc4_compile
*c
);
259 void qir_emit(struct vc4_compile
*c
, struct qinst
*inst
);
260 struct qreg
qir_get_temp(struct vc4_compile
*c
);
261 int qir_get_op_nsrc(enum qop qop
);
262 bool qir_reg_equals(struct qreg a
, struct qreg b
);
263 bool qir_has_side_effects(struct qinst
*inst
);
264 bool qir_depends_on_flags(struct qinst
*inst
);
265 bool qir_writes_r4(struct qinst
*inst
);
266 bool qir_reads_r4(struct qinst
*inst
);
268 void qir_dump(struct vc4_compile
*c
);
269 void qir_dump_inst(struct qinst
*inst
);
270 const char *qir_get_stage_name(enum qstage stage
);
272 void qir_optimize(struct vc4_compile
*c
);
273 bool qir_opt_algebraic(struct vc4_compile
*c
);
274 bool qir_opt_copy_propagation(struct vc4_compile
*c
);
275 bool qir_opt_cse(struct vc4_compile
*c
);
276 bool qir_opt_dead_code(struct vc4_compile
*c
);
278 #define QIR_ALU0(name) \
279 static inline struct qreg \
280 qir_##name(struct vc4_compile *c) \
282 struct qreg t = qir_get_temp(c); \
283 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
287 #define QIR_ALU1(name) \
288 static inline struct qreg \
289 qir_##name(struct vc4_compile *c, struct qreg a) \
291 struct qreg t = qir_get_temp(c); \
292 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
296 #define QIR_ALU2(name) \
297 static inline struct qreg \
298 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
300 struct qreg t = qir_get_temp(c); \
301 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
305 #define QIR_NODST_1(name) \
307 qir_##name(struct vc4_compile *c, struct qreg a) \
309 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
312 #define QIR_NODST_2(name) \
314 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
316 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
356 QIR_ALU2(PACK_SCALED
)
358 QIR_NODST_1(VPM_WRITE
)
368 QIR_ALU0(TLB_COLOR_READ
)
369 QIR_NODST_1(TLB_Z_WRITE
)
370 QIR_NODST_1(TLB_DISCARD_SETUP
)
371 QIR_NODST_1(TLB_STENCIL_SETUP
)
373 static inline struct qreg
374 qir_R4_UNPACK(struct vc4_compile
*c
, struct qreg r4
, int i
)
376 struct qreg t
= qir_get_temp(c
);
377 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, r4
, c
->undef
));
381 static inline struct qreg
382 qir_SEL_X_0_COND(struct vc4_compile
*c
, int i
)
384 struct qreg t
= qir_get_temp(c
);
385 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
389 #endif /* VC4_QIR_H */