Path: blob/21.2-virgl/src/intel/blorp/blorp_nir_builder.h
7136 views
/*1* Copyright © 2017 Intel Corporation2*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 "compiler/nir/nir_builder.h"2425static inline void26blorp_nir_init_shader(nir_builder *b,27void *mem_ctx,28gl_shader_stage stage,29const char *name)30{31*b = nir_builder_init_simple_shader(stage, NULL, "%s", name ? name : "");32ralloc_steal(mem_ctx, b->shader);33if (stage == MESA_SHADER_FRAGMENT)34b->shader->info.fs.origin_upper_left = true;35}3637static inline nir_ssa_def *38blorp_nir_txf_ms_mcs(nir_builder *b, nir_ssa_def *xy_pos, nir_ssa_def *layer)39{40nir_tex_instr *tex = nir_tex_instr_create(b->shader, 1);41tex->op = nir_texop_txf_ms_mcs;42tex->sampler_dim = GLSL_SAMPLER_DIM_MS;43tex->dest_type = nir_type_int32;4445nir_ssa_def *coord;46if (layer) {47tex->is_array = true;48tex->coord_components = 3;49coord = nir_vec3(b, nir_channel(b, xy_pos, 0),50nir_channel(b, xy_pos, 1),51layer);52} else {53tex->is_array = false;54tex->coord_components = 2;55coord = nir_channels(b, xy_pos, 0x3);56}57tex->src[0].src_type = nir_tex_src_coord;58tex->src[0].src = nir_src_for_ssa(coord);5960/* Blorp only has one texture and it's bound at unit 0 */61tex->texture_index = 0;62tex->sampler_index = 0;6364nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, NULL);65nir_builder_instr_insert(b, &tex->instr);6667return &tex->dest.ssa;68}6970static inline nir_ssa_def *71blorp_nir_mcs_is_clear_color(nir_builder *b,72nir_ssa_def *mcs,73uint32_t samples)74{75switch (samples) {76case 2:77/* Empirical evidence suggests that the value returned from the78* sampler is not always 0x3 for clear color so we need to mask it.79*/80return nir_ieq_imm(b, nir_iand(b, nir_channel(b, mcs, 0),81nir_imm_int(b, 0x3)),820x3);8384case 4:85return nir_ieq_imm(b, nir_channel(b, mcs, 0), 0xff);8687case 8:88return nir_ieq_imm(b, nir_channel(b, mcs, 0), ~0);8990case 16:91/* For 16x MSAA, the MCS is actually an ivec2 */92return nir_iand(b, nir_ieq_imm(b, nir_channel(b, mcs, 0), ~0),93nir_ieq_imm(b, nir_channel(b, mcs, 1), ~0));9495default:96unreachable("Invalid sample count");97}98}99100101