Path: blob/21.2-virgl/src/panfrost/bifrost/bi_lower_swizzle.c
4564 views
/*1* Copyright (C) 2020 Collabora Ltd.2*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, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#include "compiler.h"24#include "bi_builder.h"2526/* Not all 8-bit and 16-bit instructions support all swizzles on all sources.27* These passes, intended to run after NIR->BIR but before scheduling/RA, lower28* away swizzles that cannot be represented. In the future, we should try to29* recombine swizzles where we can as an optimization.30*/3132static void33bi_lower_swizzle_16(bi_context *ctx, bi_instr *ins, unsigned src)34{35/* TODO: Use the opcode table and be a lot more methodical about this... */36switch (ins->op) {37/* Some instructions used with 16-bit data never have swizzles */38case BI_OPCODE_CSEL_V2F16:39case BI_OPCODE_CSEL_V2I16:40case BI_OPCODE_CSEL_V2S16:41case BI_OPCODE_CSEL_V2U16:4243/* Despite ostensibly being 32-bit instructions, CLPER does not44* inherently interpret the data, so it can be used for v2f1645* derivatives, which might require swizzle lowering */46case BI_OPCODE_CLPER_V6_I32:47case BI_OPCODE_CLPER_V7_I32:48break;4950case BI_OPCODE_IADD_V2S16:51case BI_OPCODE_IADD_V2U16:52case BI_OPCODE_ISUB_V2S16:53case BI_OPCODE_ISUB_V2U16:54if (src == 0 && ins->src[src].swizzle != BI_SWIZZLE_H10)55break;56else57return;58case BI_OPCODE_LSHIFT_AND_V2I16:59case BI_OPCODE_LSHIFT_OR_V2I16:60case BI_OPCODE_LSHIFT_XOR_V2I16:61case BI_OPCODE_RSHIFT_AND_V2I16:62case BI_OPCODE_RSHIFT_OR_V2I16:63case BI_OPCODE_RSHIFT_XOR_V2I16:64if (src == 2)65return;66else67break;68default:69return;70}7172/* Identity is ok (TODO: what about replicate only?) */73if (ins->src[src].swizzle == BI_SWIZZLE_H01)74return;7576/* If the instruction is scalar we can ignore the other component */77if (ins->dest[0].swizzle == BI_SWIZZLE_H00 &&78ins->src[src].swizzle == BI_SWIZZLE_H00)79{80ins->src[src].swizzle = BI_SWIZZLE_H01;81return;82}8384/* Lower it away */85bi_builder b = bi_init_builder(ctx, bi_before_instr(ins));86ins->src[src] = bi_replace_index(ins->src[src],87bi_swz_v2i16(&b, ins->src[src]));88ins->src[src].swizzle = BI_SWIZZLE_H01;89}9091void92bi_lower_swizzle(bi_context *ctx)93{94bi_foreach_instr_global_safe(ctx, ins) {95bi_foreach_src(ins, s) {96if (!bi_is_null(ins->src[s]))97bi_lower_swizzle_16(ctx, ins, s);98}99}100}101102103