Path: blob/21.2-virgl/src/panfrost/midgard/midgard_nir_lower_helper_writes.c
4564 views
/*1* Copyright (C) 2020-2021 Collabora, Ltd.2* Copyright © 2020 Valve Corporation3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS21* IN THE SOFTWARE.22*/2324#include "compiler/nir/nir.h"25#include "compiler/nir/nir_builder.h"26#include "midgard_nir.h"2728static bool29nir_lower_helper_writes(nir_builder *b, nir_instr *instr, UNUSED void *data)30{31if (instr->type != nir_instr_type_intrinsic)32return false;3334nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);3536switch (intr->intrinsic) {37case nir_intrinsic_global_atomic_add:38case nir_intrinsic_global_atomic_and:39case nir_intrinsic_global_atomic_comp_swap:40case nir_intrinsic_global_atomic_exchange:41case nir_intrinsic_global_atomic_fadd:42case nir_intrinsic_global_atomic_fcomp_swap:43case nir_intrinsic_global_atomic_fmax:44case nir_intrinsic_global_atomic_fmin:45case nir_intrinsic_global_atomic_imax:46case nir_intrinsic_global_atomic_imin:47case nir_intrinsic_global_atomic_or:48case nir_intrinsic_global_atomic_umax:49case nir_intrinsic_global_atomic_umin:50case nir_intrinsic_global_atomic_xor:51case nir_intrinsic_image_atomic_add:52case nir_intrinsic_image_atomic_and:53case nir_intrinsic_image_atomic_comp_swap:54case nir_intrinsic_image_atomic_dec_wrap:55case nir_intrinsic_image_atomic_exchange:56case nir_intrinsic_image_atomic_fadd:57case nir_intrinsic_image_atomic_imax:58case nir_intrinsic_image_atomic_imin:59case nir_intrinsic_image_atomic_inc_wrap:60case nir_intrinsic_image_atomic_or:61case nir_intrinsic_image_atomic_umax:62case nir_intrinsic_image_atomic_umin:63case nir_intrinsic_image_atomic_xor:64case nir_intrinsic_image_store:65case nir_intrinsic_store_global:66break;67default:68return false;69}7071b->cursor = nir_before_instr(instr);7273nir_ssa_def *helper = nir_load_helper_invocation(b, 1);74nir_push_if(b, nir_inot(b, helper));75nir_instr_remove(instr);76nir_builder_instr_insert(b, instr);77nir_pop_if(b, NULL);7879return true;80}8182bool83midgard_nir_lower_helper_writes(nir_shader *shader)84{85if (shader->info.stage != MESA_SHADER_FRAGMENT)86return false;8788return nir_shader_instructions_pass(shader,89nir_lower_helper_writes,90nir_metadata_none,91NULL);92}939495