Path: blob/21.2-virgl/src/panfrost/util/pan_lower_helper_invocation.c
4560 views
/*1* Copyright (C) 2021 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 "pan_ir.h"24#include "compiler/nir/nir_builder.h"2526/* Lower gl_HelperInvocation to (gl_SampleMaskIn == 0), this depends on27* architectural details but is required for correct operation with28* multisampling. NIR's lowering won't work for us, since there is no in-spec29* way to implement load_sample_id_no_per_sample. */3031static bool32pan_lower_helper_invocation_instr(nir_builder *b, nir_instr *instr, void *data)33{34if (instr->type != nir_instr_type_intrinsic)35return false;3637nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);38if (intr->intrinsic != nir_intrinsic_load_helper_invocation)39return false;4041b->cursor = nir_before_instr(instr);4243nir_ssa_def *mask = nir_load_sample_mask_in(b);44nir_ssa_def *eq = nir_ieq(b, mask, nir_imm_int(b, 0));45nir_ssa_def_rewrite_uses(&intr->dest.ssa, eq);4647return true;48}4950bool51pan_lower_helper_invocation(nir_shader *shader)52{53return nir_shader_instructions_pass(shader,54pan_lower_helper_invocation_instr,55nir_metadata_block_index | nir_metadata_dominance,56NULL);57}585960