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]. */
109 QOP_TLB_DISCARD_SETUP
,
110 QOP_TLB_STENCIL_SETUP
,
136 /** Texture x coordinate parameter write */
138 /** Texture y coordinate parameter write */
140 /** Texture border color parameter or cube map z coordinate write */
142 /** Texture LOD bias parameter write */
146 * Texture-unit 4-byte read with address provided direct in S
149 * The first operand is the offset from the start of the UBO, and the
150 * second is the uniform that has the UBO's base pointer.
155 * Signal of texture read being necessary and then reading r4 into
166 struct simple_node
*next
;
167 struct simple_node
*prev
;
170 struct queued_qpu_inst
{
171 struct simple_node link
;
176 struct simple_node link
;
185 * Coordinate shader, runs during binning, before the VS, and just
193 enum quniform_contents
{
195 * Indicates that a constant 32-bit value is copied from the program's
200 * Indicates that the program's uniform contents are used as an index
201 * into the GL uniform storage.
206 * Scaling factors from clip coordinates to relative to the viewport
209 * This is used by the coordinate and vertex shaders to produce the
210 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed
211 * point offsets from the viewport ccenter.
213 QUNIFORM_VIEWPORT_X_SCALE
,
214 QUNIFORM_VIEWPORT_Y_SCALE
,
217 QUNIFORM_VIEWPORT_Z_OFFSET
,
218 QUNIFORM_VIEWPORT_Z_SCALE
,
220 QUNIFORM_USER_CLIP_PLANE
,
223 * A reference to a texture config parameter 0 uniform.
225 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
226 * defines texture type, miplevels, and such. It will be found as a
227 * parameter to the first QOP_TEX_[STRB] instruction in a sequence.
229 QUNIFORM_TEXTURE_CONFIG_P0
,
232 * A reference to a texture config parameter 1 uniform.
234 * This is a uniform implicitly loaded with a QPU_W_TMU* write, which
235 * defines texture width, height, filters, and wrap modes. It will be
236 * found as a parameter to the second QOP_TEX_[STRB] instruction in a
239 QUNIFORM_TEXTURE_CONFIG_P1
,
241 /** A reference to a texture config parameter 2 cubemap stride uniform */
242 QUNIFORM_TEXTURE_CONFIG_P2
,
246 QUNIFORM_TEXRECT_SCALE_X
,
247 QUNIFORM_TEXRECT_SCALE_Y
,
249 QUNIFORM_TEXTURE_BORDER_COLOR
,
251 QUNIFORM_BLEND_CONST_COLOR
,
257 struct vc4_varying_semantic
{
263 struct vc4_compiler_ubo_range
{
265 * offset in bytes from the start of the ubo where this range is
268 * Only set once used is set.
273 * offset in bytes from the start of the gallium uniforms where the
278 /** size in bytes of this ubo range */
282 * Set if this range is used by the shader for indirect uniforms
289 struct vc4_context
*vc4
;
290 struct tgsi_parse_context parser
;
293 * Inputs to the shader, arranged by TGSI declaration order.
295 * Not all fragment shader QFILE_VARY reads are present in this array.
298 struct qreg
*outputs
;
300 struct qreg addr
[4]; /* TGSI ARL destination. */
301 uint32_t temps_array_size
;
302 uint32_t inputs_array_size
;
303 uint32_t outputs_array_size
;
304 uint32_t uniforms_array_size
;
305 uint32_t consts_array_size
;
308 struct vc4_compiler_ubo_range
*ubo_ranges
;
309 uint32_t ubo_ranges_array_size
;
310 uint32_t num_ubo_ranges
;
311 uint32_t next_ubo_dst_offset
;
313 struct qreg line_x
, point_x
, point_y
;
317 * Array of the TGSI semantics of all FS QFILE_VARY reads.
319 * This includes those that aren't part of the VPM varyings, like
320 * point/line coordinates.
322 struct vc4_varying_semantic
*input_semantics
;
323 uint32_t num_input_semantics
;
324 uint32_t input_semantics_array_size
;
327 * An entry per outputs[] in the VS indicating what the semantic of
328 * the output is. Used to emit from the VS in the order that the FS
331 struct vc4_varying_semantic
*output_semantics
;
333 struct pipe_shader_state
*shader_state
;
335 struct vc4_fs_key
*fs_key
;
336 struct vc4_vs_key
*vs_key
;
338 uint32_t *uniform_data
;
339 enum quniform_contents
*uniform_contents
;
340 uint32_t uniform_array_size
;
341 uint32_t num_uniforms
;
342 uint32_t num_outputs
;
343 uint32_t num_texture_samples
;
344 uint32_t output_position_index
;
345 uint32_t output_clipvertex_index
;
346 uint32_t output_color_index
;
347 uint32_t output_point_size_index
;
352 struct simple_node instructions
;
353 uint32_t immediates
[1024];
355 struct simple_node qpu_inst_list
;
357 uint32_t qpu_inst_count
;
358 uint32_t qpu_inst_size
;
365 struct vc4_compile
*qir_compile_init(void);
366 void qir_compile_destroy(struct vc4_compile
*c
);
367 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
368 struct qreg src0
, struct qreg src1
);
369 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
374 void qir_remove_instruction(struct qinst
*qinst
);
375 void qir_reorder_uniforms(struct vc4_compile
*c
);
376 void qir_emit(struct vc4_compile
*c
, struct qinst
*inst
);
377 struct qreg
qir_get_temp(struct vc4_compile
*c
);
378 int qir_get_op_nsrc(enum qop qop
);
379 bool qir_reg_equals(struct qreg a
, struct qreg b
);
380 bool qir_has_side_effects(struct vc4_compile
*c
, struct qinst
*inst
);
381 bool qir_is_multi_instruction(struct qinst
*inst
);
382 bool qir_depends_on_flags(struct qinst
*inst
);
383 bool qir_writes_r4(struct qinst
*inst
);
384 bool qir_reads_r4(struct qinst
*inst
);
385 struct qreg
qir_follow_movs(struct qinst
**defs
, struct qreg reg
);
387 void qir_dump(struct vc4_compile
*c
);
388 void qir_dump_inst(struct vc4_compile
*c
, struct qinst
*inst
);
389 const char *qir_get_stage_name(enum qstage stage
);
391 void qir_optimize(struct vc4_compile
*c
);
392 bool qir_opt_algebraic(struct vc4_compile
*c
);
393 bool qir_opt_copy_propagation(struct vc4_compile
*c
);
394 bool qir_opt_cse(struct vc4_compile
*c
);
395 bool qir_opt_dead_code(struct vc4_compile
*c
);
396 bool qir_opt_small_immediates(struct vc4_compile
*c
);
397 bool qir_opt_vpm_writes(struct vc4_compile
*c
);
399 void qpu_schedule_instructions(struct vc4_compile
*c
);
401 #define QIR_ALU0(name) \
402 static inline struct qreg \
403 qir_##name(struct vc4_compile *c) \
405 struct qreg t = qir_get_temp(c); \
406 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
410 #define QIR_ALU1(name) \
411 static inline struct qreg \
412 qir_##name(struct vc4_compile *c, struct qreg a) \
414 struct qreg t = qir_get_temp(c); \
415 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
419 #define QIR_ALU2(name) \
420 static inline struct qreg \
421 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
423 struct qreg t = qir_get_temp(c); \
424 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
428 #define QIR_NODST_1(name) \
430 qir_##name(struct vc4_compile *c, struct qreg a) \
432 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
435 #define QIR_NODST_2(name) \
437 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
439 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
479 QIR_ALU2(PACK_SCALED
)
480 QIR_ALU1(PACK_8888_F
)
490 QIR_NODST_2(TEX_DIRECT
)
495 QIR_ALU0(FRAG_REV_FLAG
)
497 QIR_ALU0(TLB_COLOR_READ
)
498 QIR_NODST_1(TLB_Z_WRITE
)
499 QIR_NODST_1(TLB_DISCARD_SETUP
)
500 QIR_NODST_1(TLB_STENCIL_SETUP
)
502 static inline struct qreg
503 qir_R4_UNPACK(struct vc4_compile
*c
, struct qreg r4
, int i
)
505 struct qreg t
= qir_get_temp(c
);
506 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, r4
, c
->undef
));
510 static inline struct qreg
511 qir_SEL_X_0_COND(struct vc4_compile
*c
, int i
)
513 struct qreg t
= qir_get_temp(c
);
514 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
518 static inline struct qreg
519 qir_UNPACK_8_F(struct vc4_compile
*c
, struct qreg src
, int i
)
521 struct qreg t
= qir_get_temp(c
);
522 qir_emit(c
, qir_inst(QOP_UNPACK_8A_F
+ i
, t
, src
, c
->undef
));
526 static inline struct qreg
527 qir_UNPACK_8_I(struct vc4_compile
*c
, struct qreg src
, int i
)
529 struct qreg t
= qir_get_temp(c
);
530 qir_emit(c
, qir_inst(QOP_UNPACK_8A_I
+ i
, t
, src
, c
->undef
));
534 static inline struct qreg
535 qir_UNPACK_16_F(struct vc4_compile
*c
, struct qreg src
, int i
)
537 struct qreg t
= qir_get_temp(c
);
538 qir_emit(c
, qir_inst(QOP_UNPACK_16A_F
+ i
, t
, src
, c
->undef
));
542 static inline struct qreg
543 qir_UNPACK_16_I(struct vc4_compile
*c
, struct qreg src
, int i
)
545 struct qreg t
= qir_get_temp(c
);
546 qir_emit(c
, qir_inst(QOP_UNPACK_16A_I
+ i
, t
, src
, c
->undef
));
550 static inline struct qreg
551 qir_PACK_8_F(struct vc4_compile
*c
, struct qreg rest
, struct qreg val
, int chan
)
553 struct qreg t
= qir_get_temp(c
);
554 qir_emit(c
, qir_inst(QOP_PACK_8A_F
+ chan
, t
, rest
, val
));
558 static inline struct qreg
559 qir_POW(struct vc4_compile
*c
, struct qreg x
, struct qreg y
)
561 return qir_EXP2(c
, qir_FMUL(c
,
567 qir_VPM_WRITE(struct vc4_compile
*c
, struct qreg val
)
569 static const struct qreg vpm
= { QFILE_VPM
, 0 };
570 qir_emit(c
, qir_inst(QOP_MOV
, vpm
, val
, c
->undef
));
573 #endif /* VC4_QIR_H */