Path: blob/21.2-virgl/src/broadcom/compiler/v3d_nir_lower_txf_ms.c
4564 views
/*1* Copyright © 2015 Broadcom2*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 "v3d_compiler.h"24#include "compiler/nir/nir_builder.h"2526/** @file v3d_nir_lower_txf_ms.c27*28* V3D's MSAA surfaces are laid out in UIF textures where each pixel is a 2x229* quad in the texture. This pass lowers the txf_ms with a ms_index source to30* a plain txf with the sample_index pulling out the correct texel from the31* 2x2 quad.32*/3334#define V3D_MAX_SAMPLES 43536static nir_ssa_def *37v3d_nir_lower_txf_ms_instr(nir_builder *b, nir_instr *in_instr, void *data)38{39nir_tex_instr *instr = nir_instr_as_tex(in_instr);4041b->cursor = nir_before_instr(&instr->instr);4243int coord_index = nir_tex_instr_src_index(instr, nir_tex_src_coord);44int sample_index = nir_tex_instr_src_index(instr, nir_tex_src_ms_index);45nir_ssa_def *coord = instr->src[coord_index].src.ssa;46nir_ssa_def *sample = instr->src[sample_index].src.ssa;4748nir_ssa_def *one = nir_imm_int(b, 1);49nir_ssa_def *x = nir_iadd(b,50nir_ishl(b, nir_channel(b, coord, 0), one),51nir_iand(b, sample, one));52nir_ssa_def *y = nir_iadd(b,53nir_ishl(b, nir_channel(b, coord, 1), one),54nir_iand(b, nir_ushr(b, sample, one), one));55if (instr->is_array)56coord = nir_vec3(b, x, y, nir_channel(b, coord, 2));57else58coord = nir_vec2(b, x, y);5960nir_instr_rewrite_src(&instr->instr,61&instr->src[nir_tex_src_coord].src,62nir_src_for_ssa(coord));63nir_tex_instr_remove_src(instr, sample_index);64instr->op = nir_texop_txf;65instr->sampler_dim = GLSL_SAMPLER_DIM_2D;6667return NIR_LOWER_INSTR_PROGRESS;68}6970static bool71v3d_nir_lower_txf_ms_filter(const nir_instr *instr, const void *data)72{73return (instr->type == nir_instr_type_tex &&74nir_instr_as_tex(instr)->op == nir_texop_txf_ms);75}7677void78v3d_nir_lower_txf_ms(nir_shader *s, struct v3d_compile *c)79{80nir_shader_lower_instructions(s,81v3d_nir_lower_txf_ms_filter,82v3d_nir_lower_txf_ms_instr,83NULL);84}858687