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/macros.h"
34 #include "util/u_simple_list.h"
35 #include "tgsi/tgsi_parse.h"
45 * Stores an immediate value in the index field that can be turned
46 * into a small immediate field by qpu_encode_small_immediate().
79 /* Sets the flag register according to src. */
82 /* Note: Orderings of these compares must be the same as in
83 * qpu_defines.h. Selects the src[0] if the ns flag bit is set,
89 /* 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
;
316 uint8_t vattr_sizes
[8];
319 * Array of the TGSI semantics of all FS QFILE_VARY reads.
321 * This includes those that aren't part of the VPM varyings, like
322 * point/line coordinates.
324 struct vc4_varying_semantic
*input_semantics
;
325 uint32_t num_input_semantics
;
326 uint32_t input_semantics_array_size
;
329 * An entry per outputs[] in the VS indicating what the semantic of
330 * the output is. Used to emit from the VS in the order that the FS
333 struct vc4_varying_semantic
*output_semantics
;
335 struct pipe_shader_state
*shader_state
;
337 struct vc4_fs_key
*fs_key
;
338 struct vc4_vs_key
*vs_key
;
340 uint32_t *uniform_data
;
341 enum quniform_contents
*uniform_contents
;
342 uint32_t uniform_array_size
;
343 uint32_t num_uniforms
;
344 uint32_t num_outputs
;
345 uint32_t num_texture_samples
;
346 uint32_t output_position_index
;
347 uint32_t output_clipvertex_index
;
348 uint32_t output_color_index
;
349 uint32_t output_point_size_index
;
354 struct simple_node instructions
;
355 uint32_t immediates
[1024];
357 struct simple_node qpu_inst_list
;
359 uint32_t qpu_inst_count
;
360 uint32_t qpu_inst_size
;
367 struct vc4_compile
*qir_compile_init(void);
368 void qir_compile_destroy(struct vc4_compile
*c
);
369 struct qinst
*qir_inst(enum qop op
, struct qreg dst
,
370 struct qreg src0
, struct qreg src1
);
371 struct qinst
*qir_inst4(enum qop op
, struct qreg dst
,
376 void qir_remove_instruction(struct qinst
*qinst
);
377 void qir_reorder_uniforms(struct vc4_compile
*c
);
378 void qir_emit(struct vc4_compile
*c
, struct qinst
*inst
);
379 struct qreg
qir_get_temp(struct vc4_compile
*c
);
380 int qir_get_op_nsrc(enum qop qop
);
381 bool qir_reg_equals(struct qreg a
, struct qreg b
);
382 bool qir_has_side_effects(struct vc4_compile
*c
, struct qinst
*inst
);
383 bool qir_has_side_effect_reads(struct vc4_compile
*c
, struct qinst
*inst
);
384 bool qir_is_multi_instruction(struct qinst
*inst
);
385 bool qir_depends_on_flags(struct qinst
*inst
);
386 bool qir_writes_r4(struct qinst
*inst
);
387 bool qir_reads_r4(struct qinst
*inst
);
388 struct qreg
qir_follow_movs(struct qinst
**defs
, struct qreg reg
);
390 void qir_dump(struct vc4_compile
*c
);
391 void qir_dump_inst(struct vc4_compile
*c
, struct qinst
*inst
);
392 const char *qir_get_stage_name(enum qstage stage
);
394 void qir_optimize(struct vc4_compile
*c
);
395 bool qir_opt_algebraic(struct vc4_compile
*c
);
396 bool qir_opt_copy_propagation(struct vc4_compile
*c
);
397 bool qir_opt_cse(struct vc4_compile
*c
);
398 bool qir_opt_dead_code(struct vc4_compile
*c
);
399 bool qir_opt_small_immediates(struct vc4_compile
*c
);
400 bool qir_opt_vpm_writes(struct vc4_compile
*c
);
402 void qpu_schedule_instructions(struct vc4_compile
*c
);
404 #define QIR_ALU0(name) \
405 static inline struct qreg \
406 qir_##name(struct vc4_compile *c) \
408 struct qreg t = qir_get_temp(c); \
409 qir_emit(c, qir_inst(QOP_##name, t, c->undef, c->undef)); \
413 #define QIR_ALU1(name) \
414 static inline struct qreg \
415 qir_##name(struct vc4_compile *c, struct qreg a) \
417 struct qreg t = qir_get_temp(c); \
418 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \
422 #define QIR_ALU2(name) \
423 static inline struct qreg \
424 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
426 struct qreg t = qir_get_temp(c); \
427 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \
431 #define QIR_NODST_1(name) \
433 qir_##name(struct vc4_compile *c, struct qreg a) \
435 qir_emit(c, qir_inst(QOP_##name, c->undef, a, c->undef)); \
438 #define QIR_NODST_2(name) \
440 qir_##name(struct vc4_compile *c, struct qreg a, struct qreg b) \
442 qir_emit(c, qir_inst(QOP_##name, c->undef, a, b)); \
482 QIR_ALU2(PACK_SCALED
)
483 QIR_ALU1(PACK_8888_F
)
493 QIR_NODST_2(TEX_DIRECT
)
498 QIR_ALU0(FRAG_REV_FLAG
)
500 QIR_ALU0(TLB_COLOR_READ
)
501 QIR_NODST_1(TLB_Z_WRITE
)
502 QIR_NODST_1(TLB_DISCARD_SETUP
)
503 QIR_NODST_1(TLB_STENCIL_SETUP
)
505 static inline struct qreg
506 qir_R4_UNPACK(struct vc4_compile
*c
, struct qreg r4
, int i
)
508 struct qreg t
= qir_get_temp(c
);
509 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, r4
, c
->undef
));
513 static inline struct qreg
514 qir_SEL_X_0_COND(struct vc4_compile
*c
, int i
)
516 struct qreg t
= qir_get_temp(c
);
517 qir_emit(c
, qir_inst(QOP_R4_UNPACK_A
+ i
, t
, c
->undef
, c
->undef
));
521 static inline struct qreg
522 qir_UNPACK_8_F(struct vc4_compile
*c
, struct qreg src
, int i
)
524 struct qreg t
= qir_get_temp(c
);
525 qir_emit(c
, qir_inst(QOP_UNPACK_8A_F
+ i
, t
, src
, c
->undef
));
529 static inline struct qreg
530 qir_UNPACK_8_I(struct vc4_compile
*c
, struct qreg src
, int i
)
532 struct qreg t
= qir_get_temp(c
);
533 qir_emit(c
, qir_inst(QOP_UNPACK_8A_I
+ i
, t
, src
, c
->undef
));
537 static inline struct qreg
538 qir_UNPACK_16_F(struct vc4_compile
*c
, struct qreg src
, int i
)
540 struct qreg t
= qir_get_temp(c
);
541 qir_emit(c
, qir_inst(QOP_UNPACK_16A_F
+ i
, t
, src
, c
->undef
));
545 static inline struct qreg
546 qir_UNPACK_16_I(struct vc4_compile
*c
, struct qreg src
, int i
)
548 struct qreg t
= qir_get_temp(c
);
549 qir_emit(c
, qir_inst(QOP_UNPACK_16A_I
+ i
, t
, src
, c
->undef
));
553 static inline struct qreg
554 qir_PACK_8_F(struct vc4_compile
*c
, struct qreg rest
, struct qreg val
, int chan
)
556 struct qreg t
= qir_get_temp(c
);
557 qir_emit(c
, qir_inst(QOP_PACK_8A_F
+ chan
, t
, rest
, val
));
561 static inline struct qreg
562 qir_POW(struct vc4_compile
*c
, struct qreg x
, struct qreg y
)
564 return qir_EXP2(c
, qir_FMUL(c
,
570 qir_VPM_WRITE(struct vc4_compile
*c
, struct qreg val
)
572 static const struct qreg vpm
= { QFILE_VPM
, 0 };
573 qir_emit(c
, qir_inst(QOP_MOV
, vpm
, val
, c
->undef
));
576 #endif /* VC4_QIR_H */