2019-04-26 10:05:08 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2019 Google, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nir.h"
|
|
|
|
|
#include "nir_builder.h"
|
|
|
|
|
|
|
|
|
|
/* Lowing for fragment shader load_output.
|
|
|
|
|
*
|
|
|
|
|
* This pass supports the blend_equation_advanced, where a fragment
|
|
|
|
|
* shader loads the output (fragcolor) to read the current framebuffer.
|
|
|
|
|
* It does this by lowering the output read to a txf_ms_fb instruction.
|
|
|
|
|
* This instruction works similarly to a normal txf_ms except without
|
|
|
|
|
* taking a texture source argument. (The driver backend is expected
|
|
|
|
|
* to wire this up to a free texture slot which is configured to read
|
|
|
|
|
* from the framebuffer.)
|
|
|
|
|
*
|
|
|
|
|
* This should be run after lower_wpos_ytransform, because the tex
|
|
|
|
|
* coordinates should be the physical fragcoord, not the logical
|
|
|
|
|
* y-flipped coord.
|
|
|
|
|
*
|
|
|
|
|
* Note that this pass explicitly does *not* add a sampler uniform
|
|
|
|
|
* (as txf_ms_fb does not reference a texture). The driver backend
|
|
|
|
|
* is going to want nif->info.num_textures to include the count of
|
|
|
|
|
* number of textures *not* including the one it inserts to sample
|
|
|
|
|
* from the framebuffer, so it more easily knows where to insert the
|
|
|
|
|
* hidden texture to read from the fb.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-08-09 16:06:06 +02:00
|
|
|
static bool
|
|
|
|
|
nir_lower_fb_read_instr(nir_builder *b, nir_instr *instr, UNUSED void *cb_data)
|
2019-04-26 10:05:08 -07:00
|
|
|
{
|
2021-08-09 16:06:06 +02:00
|
|
|
if (instr->type != nir_instr_type_intrinsic)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
|
|
|
|
if (intr->intrinsic != nir_intrinsic_load_output)
|
|
|
|
|
return false;
|
|
|
|
|
|
2019-04-26 10:05:08 -07:00
|
|
|
b->cursor = nir_before_instr(&intr->instr);
|
|
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_def *fragcoord = nir_load_frag_coord(b);
|
|
|
|
|
nir_def *sampid = nir_load_sample_id(b);
|
|
|
|
|
nir_def *layer = nir_load_layer_id(b);
|
2019-04-26 10:05:08 -07:00
|
|
|
fragcoord = nir_f2i32(b, fragcoord);
|
|
|
|
|
|
2023-02-09 14:04:46 +01:00
|
|
|
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 3);
|
2019-04-26 10:05:08 -07:00
|
|
|
tex->op = nir_texop_txf_ms_fb;
|
|
|
|
|
tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
|
2023-03-02 17:45:30 +01:00
|
|
|
tex->coord_components = 3;
|
2020-12-08 13:45:55 +01:00
|
|
|
tex->dest_type = nir_type_float32;
|
2023-03-02 17:45:30 +01:00
|
|
|
tex->is_array = true;
|
2023-05-31 20:56:31 -04:00
|
|
|
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_coord,
|
|
|
|
|
nir_vec3(b, nir_channel(b, fragcoord, 0), nir_channel(b, fragcoord, 1), layer));
|
|
|
|
|
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_ms_index, sampid);
|
2023-02-09 14:04:46 +01:00
|
|
|
struct nir_io_semantics io = nir_intrinsic_io_semantics(intr);
|
2023-05-31 20:56:31 -04:00
|
|
|
tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_texture_handle,
|
|
|
|
|
nir_imm_intN_t(b, io.location - FRAG_RESULT_DATA0, 32));
|
2019-04-26 10:05:08 -07:00
|
|
|
|
nir: Drop unused name from nir_ssa_dest_init
Since 624e799cc34 ("nir: Drop nir_ssa_def::name and nir_register::name"), SSA
defs don't have names, making the name argument unused. Drop it from the
signature and fix the call sites. This was done with the help of the following
Coccinelle semantic patch:
@@
expression A, B, C, D, E;
@@
-nir_ssa_dest_init(A, B, C, D, E);
+nir_ssa_dest_init(A, B, C, D);
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23078>
2023-05-17 09:08:22 -04:00
|
|
|
nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32);
|
2019-04-26 10:05:08 -07:00
|
|
|
nir_builder_instr_insert(b, &tex->instr);
|
|
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_def_rewrite_uses(&intr->dest.ssa, &tex->dest.ssa);
|
2021-08-09 16:06:06 +02:00
|
|
|
|
|
|
|
|
return true;
|
2019-04-26 10:05:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nir_lower_fb_read(nir_shader *shader)
|
|
|
|
|
{
|
|
|
|
|
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
|
|
|
|
|
|
2021-08-09 16:06:06 +02:00
|
|
|
return nir_shader_instructions_pass(shader, nir_lower_fb_read_instr,
|
|
|
|
|
nir_metadata_block_index |
|
2023-08-08 12:00:35 -05:00
|
|
|
nir_metadata_dominance,
|
2021-08-09 16:06:06 +02:00
|
|
|
NULL);
|
2019-04-26 10:05:08 -07:00
|
|
|
}
|