vc4_qir.h revision d9d1c14430aaeb5b22aa66b269ba288e3df24103
1/* 2 * Copyright © 2014 Broadcom 3 * 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: 10 * 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 13 * Software. 14 * 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 21 * IN THE SOFTWARE. 22 */ 23 24#ifndef VC4_QIR_H 25#define VC4_QIR_H 26 27#include <stdbool.h> 28#include <stdint.h> 29 30#include "util/u_simple_list.h" 31 32enum qfile { 33 QFILE_NULL, 34 QFILE_TEMP, 35 QFILE_VARY, 36 QFILE_UNIF, 37}; 38 39struct qreg { 40 enum qfile file; 41 uint32_t index; 42}; 43 44enum qop { 45 QOP_UNDEF, 46 QOP_MOV, 47 QOP_FADD, 48 QOP_FSUB, 49 QOP_FMUL, 50 QOP_FMIN, 51 QOP_FMAX, 52 QOP_FMINABS, 53 QOP_FMAXABS, 54 55 QOP_SEQ, 56 QOP_SNE, 57 QOP_SGE, 58 QOP_SLT, 59 QOP_CMP, 60 61 QOP_FTOI, 62 QOP_RCP, 63 QOP_RSQ, 64 QOP_EXP2, 65 QOP_LOG2, 66 QOP_VW_SETUP, 67 QOP_VR_SETUP, 68 QOP_PACK_SCALED, 69 QOP_PACK_COLORS, 70 QOP_VPM_WRITE, 71 QOP_VPM_READ, 72 QOP_TLB_COLOR_WRITE, 73 QOP_VARY_ADD_C, 74}; 75 76struct simple_node { 77 struct simple_node *next; 78 struct simple_node *prev; 79}; 80 81struct qinst { 82 struct simple_node link; 83 84 enum qop op; 85 struct qreg dst; 86 struct qreg *src; 87}; 88 89enum qstage { 90 /** 91 * Coordinate shader, runs during binning, before the VS, and just 92 * outputs position. 93 */ 94 QSTAGE_COORD, 95 QSTAGE_VERT, 96 QSTAGE_FRAG, 97}; 98 99enum quniform_contents { 100 /** 101 * Indicates that a constant 32-bit value is copied from the program's 102 * uniform contents. 103 */ 104 QUNIFORM_CONSTANT, 105 /** 106 * Indicates that the program's uniform contents are used as an index 107 * into the GL uniform storage. 108 */ 109 QUNIFORM_UNIFORM, 110 111 /** @{ 112 * Scaling factors from clip coordinates to relative to the viewport 113 * center. 114 * 115 * This is used by the coordinate and vertex shaders to produce the 116 * 32-bit entry consisting of 2 16-bit fields with 12.4 signed fixed 117 * point offsets from the viewport ccenter. 118 */ 119 QUNIFORM_VIEWPORT_X_SCALE, 120 QUNIFORM_VIEWPORT_Y_SCALE, 121 /** @} */ 122}; 123 124struct qcompile { 125 struct qreg undef; 126 enum qstage stage; 127 uint32_t num_temps; 128 struct simple_node instructions; 129 uint32_t immediates[1024]; 130 131 struct simple_node qpu_inst_list; 132 uint64_t *qpu_insts; 133 uint32_t qpu_inst_count; 134 uint32_t qpu_inst_size; 135}; 136 137struct qcompile *qir_compile_init(void); 138void qir_compile_destroy(struct qcompile *c); 139struct qinst *qir_inst(enum qop op, struct qreg dst, 140 struct qreg src0, struct qreg src1); 141struct qinst *qir_inst4(enum qop op, struct qreg dst, 142 struct qreg a, 143 struct qreg b, 144 struct qreg c, 145 struct qreg d); 146void qir_emit(struct qcompile *c, struct qinst *inst); 147struct qreg qir_get_temp(struct qcompile *c); 148int qir_get_op_nsrc(enum qop qop); 149bool qir_reg_equals(struct qreg a, struct qreg b); 150bool qir_has_side_effects(struct qinst *inst); 151 152void qir_dump(struct qcompile *c); 153void qir_dump_inst(struct qinst *inst); 154const char *qir_get_stage_name(enum qstage stage); 155 156void qir_optimize(struct qcompile *c); 157bool qir_opt_algebraic(struct qcompile *c); 158bool qir_opt_dead_code(struct qcompile *c); 159 160#define QIR_ALU1(name) \ 161static inline struct qreg \ 162qir_##name(struct qcompile *c, struct qreg a) \ 163{ \ 164 struct qreg t = qir_get_temp(c); \ 165 qir_emit(c, qir_inst(QOP_##name, t, a, c->undef)); \ 166 return t; \ 167} 168 169#define QIR_ALU2(name) \ 170static inline struct qreg \ 171qir_##name(struct qcompile *c, struct qreg a, struct qreg b) \ 172{ \ 173 struct qreg t = qir_get_temp(c); \ 174 qir_emit(c, qir_inst(QOP_##name, t, a, b)); \ 175 return t; \ 176} 177 178QIR_ALU1(MOV) 179QIR_ALU2(FADD) 180QIR_ALU2(FSUB) 181QIR_ALU2(FMUL) 182QIR_ALU2(FMIN) 183QIR_ALU2(FMAX) 184QIR_ALU2(FMINABS) 185QIR_ALU2(FMAXABS) 186QIR_ALU1(FTOI) 187QIR_ALU1(RCP) 188QIR_ALU1(RSQ) 189QIR_ALU1(EXP2) 190QIR_ALU1(LOG2) 191QIR_ALU2(PACK_SCALED) 192QIR_ALU1(VARY_ADD_C) 193 194static inline void 195qir_VPM_WRITE(struct qcompile *c, struct qreg a) 196{ 197 qir_emit(c, qir_inst(QOP_VPM_WRITE, c->undef, a, c->undef)); 198} 199 200#endif /* VC4_QIR_H */ 201