Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_asm.c
4570 views
/*1* Copyright (c) 2012-2015 Etnaviv Project2*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, sub license,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 the11* next paragraph) shall be included in all copies or substantial portions12* of the 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 NON-INFRINGEMENT. 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 OTHER20* DEALINGS IN THE SOFTWARE.21*22* Authors:23* Wladimir J. van der Laan <[email protected]>24*/2526#include "etnaviv_asm.h"27#include "etnaviv_debug.h"28#include "etnaviv_util.h"2930/* An instruction can only read from one distinct uniform.31* This function verifies this property and returns true if the instruction32* is deemed correct and false otherwise.33*/34static bool35check_uniforms(const struct etna_inst *inst)36{37unsigned uni_rgroup = -1;38unsigned uni_reg = -1;39bool conflict = false;4041for (unsigned i = 0; i < ETNA_NUM_SRC; i++) {42const struct etna_inst_src *src = &inst->src[i];4344if (!etna_rgroup_is_uniform(src->rgroup))45continue;4647if (uni_reg == -1) { /* first uniform used */48uni_rgroup = src->rgroup;49uni_reg = src->reg;50} else { /* second or later; check that it is a re-use */51if (uni_rgroup != src->rgroup || uni_reg != src->reg) {52conflict = true;53}54}55}5657return !conflict;58}5960int61etna_assemble(uint32_t *out, const struct etna_inst *inst)62{63/* cannot have both src2 and imm */64if (inst->imm && inst->src[2].use)65return 1;6667if (!inst->halti5 && !check_uniforms(inst))68BUG("error: generating instruction that accesses two different uniforms");6970assert(!(inst->opcode&~0x7f));7172out[0] = VIV_ISA_WORD_0_OPCODE(inst->opcode & 0x3f) |73VIV_ISA_WORD_0_COND(inst->cond) |74COND(inst->sat, VIV_ISA_WORD_0_SAT) |75COND(inst->dst.use, VIV_ISA_WORD_0_DST_USE) |76VIV_ISA_WORD_0_DST_AMODE(inst->dst.amode) |77VIV_ISA_WORD_0_DST_REG(inst->dst.reg) |78VIV_ISA_WORD_0_DST_COMPS(inst->dst.write_mask) |79VIV_ISA_WORD_0_TEX_ID(inst->tex.id);80out[1] = VIV_ISA_WORD_1_TEX_AMODE(inst->tex.amode) |81VIV_ISA_WORD_1_TEX_SWIZ(inst->tex.swiz) |82COND(inst->src[0].use, VIV_ISA_WORD_1_SRC0_USE) |83VIV_ISA_WORD_1_SRC0_REG(inst->src[0].reg) |84COND(inst->type & 0x4, VIV_ISA_WORD_1_TYPE_BIT2) |85VIV_ISA_WORD_1_SRC0_SWIZ(inst->src[0].swiz) |86COND(inst->src[0].neg, VIV_ISA_WORD_1_SRC0_NEG) |87COND(inst->src[0].abs, VIV_ISA_WORD_1_SRC0_ABS);88out[2] = VIV_ISA_WORD_2_SRC0_AMODE(inst->src[0].amode) |89VIV_ISA_WORD_2_SRC0_RGROUP(inst->src[0].rgroup) |90COND(inst->src[1].use, VIV_ISA_WORD_2_SRC1_USE) |91VIV_ISA_WORD_2_SRC1_REG(inst->src[1].reg) |92COND(inst->opcode & 0x40, VIV_ISA_WORD_2_OPCODE_BIT6) |93VIV_ISA_WORD_2_SRC1_SWIZ(inst->src[1].swiz) |94COND(inst->src[1].neg, VIV_ISA_WORD_2_SRC1_NEG) |95COND(inst->src[1].abs, VIV_ISA_WORD_2_SRC1_ABS) |96VIV_ISA_WORD_2_SRC1_AMODE(inst->src[1].amode) |97VIV_ISA_WORD_2_TYPE_BIT01(inst->type & 0x3);98out[3] = VIV_ISA_WORD_3_SRC1_RGROUP(inst->src[1].rgroup) |99COND(inst->src[2].use, VIV_ISA_WORD_3_SRC2_USE) |100VIV_ISA_WORD_3_SRC2_REG(inst->src[2].reg) |101VIV_ISA_WORD_3_SRC2_SWIZ(inst->src[2].swiz) |102COND(inst->src[2].neg, VIV_ISA_WORD_3_SRC2_NEG) |103COND(inst->src[2].abs, VIV_ISA_WORD_3_SRC2_ABS) |104VIV_ISA_WORD_3_SRC2_AMODE(inst->src[2].amode) |105VIV_ISA_WORD_3_SRC2_RGROUP(inst->src[2].rgroup) |106COND(inst->sel_bit0, VIV_ISA_WORD_3_SEL_BIT0) |107COND(inst->sel_bit1, VIV_ISA_WORD_3_SEL_BIT1) |108COND(inst->dst_full, VIV_ISA_WORD_3_DST_FULL);109110out[3] |= VIV_ISA_WORD_3_SRC2_IMM(inst->imm);111112return 0;113}114115116