Path: blob/21.2-virgl/src/panfrost/midgard/nir_fuse_io_16.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, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* Authors (Collabora):23* Alyssa Rosenzweig <[email protected]>24*/2526/* Fuses f2f16 modifiers into loads */2728#include "compiler/nir/nir.h"29#include "compiler/nir/nir_builder.h"30#include "panfrost/util/pan_ir.h"3132bool nir_fuse_io_16(nir_shader *shader);3334static bool35nir_src_is_f2fmp(nir_src *use)36{37nir_instr *parent = use->parent_instr;3839if (parent->type != nir_instr_type_alu)40return false;4142nir_alu_instr *alu = nir_instr_as_alu(parent);43return (alu->op == nir_op_f2fmp);44}4546bool47nir_fuse_io_16(nir_shader *shader)48{49bool progress = false;5051nir_foreach_function(function, shader) {52if (!function->impl) continue;5354nir_builder b;55nir_builder_init(&b, function->impl);5657nir_foreach_block(block, function->impl) {58nir_foreach_instr_safe(instr, block) {59if (instr->type != nir_instr_type_intrinsic) continue;6061nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);6263if (intr->intrinsic != nir_intrinsic_load_interpolated_input)64continue;6566if (nir_dest_bit_size(intr->dest) != 32)67continue;6869/* We swizzle at a 32-bit level so need a multiple of 2. We could70* do a bit better and handle even components though */71if (nir_intrinsic_component(intr))72continue;7374if (!intr->dest.is_ssa)75continue;7677if (!list_is_empty(&intr->dest.ssa.if_uses))78return false;7980bool valid = true;8182nir_foreach_use(src, &intr->dest.ssa)83valid &= nir_src_is_f2fmp(src);8485if (!valid)86continue;8788intr->dest.ssa.bit_size = 16;8990nir_builder b;91nir_builder_init(&b, function->impl);92b.cursor = nir_after_instr(instr);9394/* The f2f32(f2fmp(x)) will cancel by opt_algebraic */95nir_ssa_def *conv = nir_f2f32(&b, &intr->dest.ssa);96nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, conv,97conv->parent_instr);9899progress |= true;100}101}102103nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance);104105}106107return progress;108}109110111