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"
44 * Stores an immediate value in the index field that can be turned
45 * into a small immediate field by qpu_encode_small_immediate().
78 /* Sets the flag register according to src. */
81 /* Note: Orderings of these compares must be the same as in
82 * qpu_defines.h. Selects the src[0] if the ns flag bit is set,
88 /* Selects the src[0] if the ns flag bit is set, otherwise src[1]. */
108 QOP_TLB_DISCARD_SETUP
,
109 QOP_TLB_STENCIL_SETUP
,
135 /** Texture x coordinate parameter write */
137 /** Texture y coordinate parameter write */
139 /** Texture border color parameter or cube map z coordinate write */
141 /** Texture LOD bias parameter write */
145 * Texture-unit 4-byte read with address provided direct in S
148 * The first operand is the offset from the start of the UBO, and the
149 * second is the uniform that has the UBO's base pointer.
154 * Signal of texture read being necessary and then reading r4 into
165 struct simple_node
*next
;
166 struct simple_node
*prev
;
169 struct queued_qpu_inst
{
170 struct simple_node link
;
175 struct simple_node link
;
184 * Coordinate shader, runs during binning, before the VS, and just
192 enum quniform_contents
{
194 * Indicates that a constant 32-bit value is copied from the program's
199 * Indicates that the program's uniform contents are used as an index
200 * into the GL uniform storage.
205 * Scaling factors from clip coordinates to relative to the viewport
208 * This is used by the coordinate and vertex shaders to produce the
209 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
210 * point offsets from the viewport ccenter.
212 QUNIFORM_VIEWPORT_X_SCALE
,
213 QUNIFORM_VIEWPORT_Y_SCALE
,
216 QUNIFORM_VIEWPORT_Z_OFFSET
,
217 QUNIFORM_VIEWPORT_Z_SCALE
,
219 QUNIFORM_USER_CLIP_PLANE
,
222 * A reference to a texture config parameter 0 uniform.
224 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
225 * defines texture type, miplevels, and such. It will be found as a
226 * parameter to the first QOP_TEX_[STRB] instruction in a sequence.
228 QUNIFORM_TEXTURE_CONFIG_P0
,
231 * A reference to a texture config parameter 1 uniform.
233 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
234 * defines texture width, height, filters, and wrap modes. It will be
235 * found as a parameter to the second QOP_TEX_[STRB] instruction in a
238 QUNIFORM_TEXTURE_CONFIG_P1
,
240 /** A reference to a texture config parameter 2 cubemap stride uniform */
241 QUNIFORM_TEXTURE_CONFIG_P2
,
245 QUNIFORM_TEXRECT_SCALE_X
,
246 QUNIFORM_TEXRECT_SCALE_Y
,
248 QUNIFORM_TEXTURE_BORDER_COLOR
,
250 QUNIFORM_BLEND_CONST_COLOR
,
256 struct vc4_varying_semantic
{
262 struct vc4_compiler_ubo_range
{
264 * offset in bytes from the start of the ubo where this range is
267 * Only set once used is set.
272 * offset in bytes from the start of the gallium uniforms where the
277 /** size in bytes of this ubo range */
281 * Set if this range is used by the shader for indirect uniforms
288 struct vc4_context
*vc4
;
289 struct tgsi_parse_context parser
;
292 * Inputs to the shader, arranged by TGSI declaration order.
294 * Not all fragment shader QFILE_VARY reads are present in this array.
297 struct qreg
*outputs
;
299 struct qreg addr
[4]; /* TGSI ARL destination. */
300 uint32_t temps_array_size
;
301 uint32_t inputs_array_size
;
302 uint32_t outputs_array_size
;
303 uint32_t uniforms_array_size
;
304 uint32_t consts_array_size
;
307 struct vc4_compiler_ubo_range
*ubo_ranges
;
308 uint32_t ubo_ranges_array_size
;
309 uint32_t num_ubo_ranges
;
310 uint32_t next_ubo_dst_offset
;
312 struct qreg line_x
, point_x
, point_y
;
316 * Array of the TGSI semantics of all FS QFILE_VARY reads.
318 * This includes those that aren't part of the VPM varyings, like
319 * point/line coordinates.
321 struct vc4_varying_semantic
*input_semantics
;
322 uint32_t num_input_semantics
;
323 uint32_t input_semantics_array_size
;
326 * An entry per outputs[] in the VS indicating what the semantic of
327 * the output is. Used to emit from the VS in the order that the FS
330 struct vc4_varying_semantic
*output_semantics
;
332 struct pipe_shader_state
*shader_state
;
334 struct vc4_fs_key
*fs_key
;
335 struct vc4_vs_key
*vs_key
;
337 uint32_t *uniform_data
;
338 enum quniform_contents
*uniform_contents
;
339 uint32_t uniform_array_size
;
340 uint32_t num_uniforms
;
341 uint32_t num_outputs
;
342 uint32_t num_texture_samples
;
343 uint32_t output_position_index
;
344 uint32_t output_clipvertex_index
;
345 uint32_t output_color_index
;
346 uint32_t output_point_size_index
;
351 struct simple_node instructions
;
352 uint32_t immediates
[1024];
354 struct simple_node qpu_inst_list
;
356 uint32_t qpu_inst_count
;
357 uint32_t qpu_inst_size
;
364 struct vc4_compile
*qir_compile_init(void);
365 void qir_compile_destroy(struct vc4_compile
*c
);
366 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
367 struct qreg src0
, struct qreg src1
);
368 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
373 void qir_remove_instruction(struct qinst
*qinst
);
374 void qir_reorder_uniforms(struct vc4_compile
*c
);
375 void qir_emit(struct vc4_compile
*c
, struct qinst
*inst
);
376 struct qreg
qir_get_temp(struct vc4_compile
*c
);
377 int qir_get_op_nsrc(enum qop qop
);
378 bool qir_reg_equals(struct qreg a
, struct qreg b
);
379 bool qir_has_side_effects(struct vc4_compile
*c
, struct qinst
*inst
);
380 bool qir_is_multi_instruction(struct qinst
*inst
);
381 bool qir_depends_on_flags(struct qinst
*inst
);
382 bool qir_writes_r4(struct qinst
*inst
);
383 bool qir_reads_r4(struct qinst
*inst
);
384 struct qreg
qir_follow_movs(struct qinst
**defs
, struct qreg reg
);
386 void qir_dump(struct vc4_compile
*c
);
387 void qir_dump_inst(struct vc4_compile
*c
, struct qinst
*inst
);
388 const char *qir_get_stage_name(enum qstage stage
);
390 void qir_optimize(struct vc4_compile
*c
);
391 bool qir_opt_algebraic(struct vc4_compile
*c
);
392 bool qir_opt_copy_propagation(struct vc4_compile
*c
);
393 bool qir_opt_cse(struct vc4_compile
*c
);
394 bool qir_opt_dead_code(struct vc4_compile
*c
);
395 bool qir_opt_small_immediates(struct vc4_compile
*c
);
396 bool qir_opt_vpm_writes(struct vc4_compile
*c
);
398 void qpu_schedule_instructions(struct vc4_compile
*c
);
400 #define QIR_ALU0(name) \
401 static inline struct qreg \
402 qir_##name(struct vc4_compile *c) \
404 struct qreg t = qir_get_temp(c); \
405 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
409 #define QIR_ALU1(name) \
410 static inline struct qreg \
411 qir_##name(struct vc4_compile *c, struct qreg a) \
413 struct qreg t = qir_get_temp(c); \
414 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
418 #define QIR_ALU2(name) \
419 static inline struct qreg \
420 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
422 struct qreg t = qir_get_temp(c); \
423 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
427 #define QIR_NODST_1(name) \
429 qir_##name(struct vc4_compile *c, struct qreg a) \
431 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
434 #define QIR_NODST_2(name) \
436 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
438 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
478 QIR_ALU2(PACK_SCALED
)
479 QIR_ALU1(PACK_8888_F
)
489 QIR_NODST_2(TEX_DIRECT
)
494 QIR_ALU0(FRAG_REV_FLAG
)
496 QIR_ALU0(TLB_COLOR_READ
)
497 QIR_NODST_1(TLB_Z_WRITE
)
498 QIR_NODST_1(TLB_DISCARD_SETUP
)
499 QIR_NODST_1(TLB_STENCIL_SETUP
)
501 static inline struct qreg
502 qir_R4_UNPACK(struct vc4_compile
*c
, struct qreg r4
, int i
)
504 struct qreg t
= qir_get_temp(c
);
505 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, r4
, c
->undef
));
509 static inline struct qreg
510 qir_SEL_X_0_COND(struct vc4_compile
*c
, int i
)
512 struct qreg t
= qir_get_temp(c
);
513 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
517 static inline struct qreg
518 qir_UNPACK_8_F(struct vc4_compile
*c
, struct qreg src
, int i
)
520 struct qreg t
= qir_get_temp(c
);
521 qir_emit(c
, qir_inst(QOP_UNPACK_8A_F
+ i
, t
, src
, c
->undef
));
525 static inline struct qreg
526 qir_UNPACK_8_I(struct vc4_compile
*c
, struct qreg src
, int i
)
528 struct qreg t
= qir_get_temp(c
);
529 qir_emit(c
, qir_inst(QOP_UNPACK_8A_I
+ i
, t
, src
, c
->undef
));
533 static inline struct qreg
534 qir_UNPACK_16_F(struct vc4_compile
*c
, struct qreg src
, int i
)
536 struct qreg t
= qir_get_temp(c
);
537 qir_emit(c
, qir_inst(QOP_UNPACK_16A_F
+ i
, t
, src
, c
->undef
));
541 static inline struct qreg
542 qir_UNPACK_16_I(struct vc4_compile
*c
, struct qreg src
, int i
)
544 struct qreg t
= qir_get_temp(c
);
545 qir_emit(c
, qir_inst(QOP_UNPACK_16A_I
+ i
, t
, src
, c
->undef
));
549 static inline struct qreg
550 qir_PACK_8_F(struct vc4_compile
*c
, struct qreg rest
, struct qreg val
, int chan
)
552 struct qreg t
= qir_get_temp(c
);
553 qir_emit(c
, qir_inst(QOP_PACK_8A_F
+ chan
, t
, rest
, val
));
557 static inline struct qreg
558 qir_POW(struct vc4_compile
*c
, struct qreg x
, struct qreg y
)
560 return qir_EXP2(c
, qir_FMUL(c
,
566 qir_VPM_WRITE(struct vc4_compile
*c
, struct qreg val
)
568 static const struct qreg vpm
= { QFILE_VPM
, 0 };
569 qir_emit(c
, qir_inst(QOP_MOV
, vpm
, val
, c
->undef
));
572 #endif /* VC4_QIR_H */