/*1* Copyright © 2016 Bas Nieuwenhuizen2*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 "ac_nir.h"2425bool26ac_nir_lower_indirect_derefs(nir_shader *shader,27enum chip_class chip_class)28{29bool progress = false;3031/* Lower large variables to scratch first so that we won't bloat the32* shader by generating large if ladders for them. We later lower33* scratch to alloca's, assuming LLVM won't generate VGPR indexing.34*/35NIR_PASS(progress, shader, nir_lower_vars_to_scratch, nir_var_function_temp, 256,36glsl_get_natural_size_align_bytes);3738/* LLVM doesn't support VGPR indexing on GFX9. */39bool llvm_has_working_vgpr_indexing = chip_class != GFX9;4041/* TODO: Indirect indexing of GS inputs is unimplemented.42*43* TCS and TES load inputs directly from LDS or offchip memory, so44* indirect indexing is trivial.45*/46nir_variable_mode indirect_mask = 0;47if (shader->info.stage == MESA_SHADER_GEOMETRY ||48(shader->info.stage != MESA_SHADER_TESS_CTRL && shader->info.stage != MESA_SHADER_TESS_EVAL &&49!llvm_has_working_vgpr_indexing)) {50indirect_mask |= nir_var_shader_in;51}52if (!llvm_has_working_vgpr_indexing && shader->info.stage != MESA_SHADER_TESS_CTRL)53indirect_mask |= nir_var_shader_out;5455/* TODO: We shouldn't need to do this, however LLVM isn't currently56* smart enough to handle indirects without causing excess spilling57* causing the gpu to hang.58*59* See the following thread for more details of the problem:60* https://lists.freedesktop.org/archives/mesa-dev/2017-July/162106.html61*/62indirect_mask |= nir_var_function_temp;6364progress |= nir_lower_indirect_derefs(shader, indirect_mask, UINT32_MAX);65return progress;66}676869