Path: blob/21.2-virgl/src/panfrost/util/pan_lower_64bit_intrin.c
4560 views
/*1* Copyright (C) 2020 Icecream95 <[email protected]>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 "pan_ir.h"24#include "compiler/nir/nir_builder.h"2526/* OpenCL uses 64-bit types for some intrinsic functions, including27* global_invocation_id(). This could be worked around during conversion to28* MIR, except that global_invocation_id is a vec3, and the 128-bit registers29* on Midgard can only hold a 64-bit vec2.30* Rather than attempting to add hacky 64-bit vec3 support, convert these31* intrinsics to 32-bit and add a cast back to 64-bit, and rely on NIR not32* vectorizing back to vec3.33*/3435static bool36nir_lower_64bit_intrin_instr(nir_builder *b, nir_instr *instr, void *data)37{38if (instr->type != nir_instr_type_intrinsic)39return false;4041nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);4243switch (intr->intrinsic) {44case nir_intrinsic_load_global_invocation_id:45case nir_intrinsic_load_global_invocation_id_zero_base:46case nir_intrinsic_load_workgroup_id:47case nir_intrinsic_load_num_workgroups:48break;4950default:51return false;52}5354if (nir_dest_bit_size(intr->dest) != 64)55return false;5657b->cursor = nir_after_instr(instr);5859assert(intr->dest.is_ssa);60intr->dest.ssa.bit_size = 32;6162nir_ssa_def *conv = nir_u2u64(b, &intr->dest.ssa);6364nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, conv,65conv->parent_instr);6667return true;68}6970bool71pan_nir_lower_64bit_intrin(nir_shader *shader)72{73return nir_shader_instructions_pass(shader,74nir_lower_64bit_intrin_instr,75nir_metadata_block_index | nir_metadata_dominance,76NULL);77}787980