Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_qir_validate.c
4570 views
/*1* Copyright © 2016 Broadcom Limited2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "vc4_qir.h"24#include "vc4_qpu.h"2526static void27fail_instr(struct vc4_compile *c, struct qinst *inst, const char *msg)28{29fprintf(stderr, "qir_validate: %s: ", msg);30qir_dump_inst(c, inst);31fprintf(stderr, "\n");32abort();33}3435void qir_validate(struct vc4_compile *c)36{37bool already_assigned[c->num_temps];38memset(&already_assigned, 0, sizeof(already_assigned));3940/* We don't want to do validation in release builds, but we want to41* keep compiling the validation code to make sure it doesn't get42* broken.43*/44#ifndef DEBUG45return;46#endif4748for (int i = 0; i < c->num_temps; i++) {49struct qinst *def = c->defs[i];5051if (def && def->cond != QPU_COND_ALWAYS)52fail_instr(c, def, "SSA def with condition");53}5455qir_for_each_inst_inorder(inst, c) {56switch (inst->dst.file) {57case QFILE_TEMP:58if (inst->dst.index >= c->num_temps)59fail_instr(c, inst, "bad temp index");6061if (c->defs[inst->dst.index] &&62already_assigned[inst->dst.index]) {63fail_instr(c, inst, "Re-assignment of SSA value");64}65already_assigned[inst->dst.index] = true;66break;6768case QFILE_NULL:69case QFILE_VPM:70case QFILE_TLB_COLOR_WRITE:71case QFILE_TLB_COLOR_WRITE_MS:72case QFILE_TLB_Z_WRITE:73case QFILE_TLB_STENCIL_SETUP:74break;7576case QFILE_VARY:77case QFILE_UNIF:78case QFILE_FRAG_X:79case QFILE_FRAG_Y:80case QFILE_FRAG_REV_FLAG:81case QFILE_QPU_ELEMENT:82case QFILE_SMALL_IMM:83case QFILE_LOAD_IMM:84fail_instr(c, inst, "Bad dest file");85break;8687case QFILE_TEX_S:88case QFILE_TEX_T:89case QFILE_TEX_R:90case QFILE_TEX_B:91if (inst->src[qir_get_tex_uniform_src(inst)].file !=92QFILE_UNIF) {93fail_instr(c, inst,94"tex op missing implicit uniform");95}96break;9798case QFILE_TEX_S_DIRECT:99if (inst->op != QOP_ADD) {100fail_instr(c, inst,101"kernel validation requires that "102"direct texture lookups use an ADD");103}104break;105}106107for (int i = 0; i < qir_get_nsrc(inst); i++) {108struct qreg src = inst->src[i];109110switch (src.file) {111case QFILE_TEMP:112if (src.index >= c->num_temps)113fail_instr(c, inst, "bad temp index");114break;115116case QFILE_VARY:117case QFILE_UNIF:118case QFILE_VPM:119case QFILE_LOAD_IMM:120case QFILE_QPU_ELEMENT:121break;122123case QFILE_SMALL_IMM:124if (qpu_encode_small_immediate(src.index) == ~0)125fail_instr(c, inst, "bad small immediate");126break;127128case QFILE_FRAG_X:129case QFILE_FRAG_Y:130case QFILE_FRAG_REV_FLAG:131if (c->stage != QSTAGE_FRAG)132fail_instr(c, inst, "frag access in VS/CS");133break;134135case QFILE_NULL:136case QFILE_TLB_COLOR_WRITE:137case QFILE_TLB_COLOR_WRITE_MS:138case QFILE_TLB_Z_WRITE:139case QFILE_TLB_STENCIL_SETUP:140case QFILE_TEX_S_DIRECT:141case QFILE_TEX_S:142case QFILE_TEX_T:143case QFILE_TEX_R:144case QFILE_TEX_B:145fail_instr(c, inst, "Bad src file");146break;147}148}149}150}151152153