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