From 079e5f73d72e9ed8b06a3d14aa0e4ac93d9bac43 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 18 Jul 2019 15:04:05 +0200 Subject: [PATCH] mesa/st: rewrite src var when lowering tex_src_plane MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The assign_extra_samplers() adds the needed extra samplers but they need to be used in the nir_tex_instr. Otherwise the plane information is simply lost and all nir_tex_instr use the same sampler. Here's an example of the bug: NIR before st_nir_lower_tex_src_plane: vec1 32 ssa_8 = load_const (0x00000000 /* 0.000000 */) vec4 32 ssa_9 = tex ssa_0 (texture_deref), ssa_0 (sampler_deref), ssa_5 (coord), ssa_8 (plane) vec1 32 ssa_10 = load_const (0x00000001 /* 0.000000 */) vec4 32 ssa_11 = tex ssa_0 (texture_deref), ssa_0 (sampler_deref), ssa_5 (coord), ssa_10 (plane) After: vec4 32 ssa_9 = tex ssa_0 (texture_deref), ssa_0 (sampler_deref), ssa_5 (coord) vec4 32 ssa_11 = tex ssa_0 (texture_deref), ssa_0 (sampler_deref), ssa_5 (coord) This fixes the following piglit test for radeonsi + NIR: - ext_image_dma_buf_import-sample_nv12 - ext_image_dma_buf_import-sample_yuv420 - ext_image_dma_buf_import-sample_yvu420 Reviewed-by: Eric Anholt Signed-off-by: Marek Olšák --- .../st_nir_lower_tex_src_plane.c | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c b/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c index 99f595a72b3..090e5bf87bd 100644 --- a/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c +++ b/src/mesa/state_tracker/st_nir_lower_tex_src_plane.c @@ -31,6 +31,7 @@ #include "util/u_string.h" #include "compiler/nir/nir.h" +#include "compiler/nir/nir_builder.h" #include "st_nir.h" typedef struct { @@ -103,7 +104,7 @@ assign_extra_samplers(lower_tex_src_state *state, unsigned free_slots) } static void -lower_tex_src_plane_block(lower_tex_src_state *state, nir_block *block) +lower_tex_src_plane_block(nir_builder *b, lower_tex_src_state *state, nir_block *block) { nir_foreach_instr(instr, block) { if (instr->type != nir_instr_type_tex) @@ -129,6 +130,28 @@ lower_tex_src_plane_block(lower_tex_src_state *state, nir_block *block) state->sampler_map[y_samp][plane[0].i32 - 1]; state->shader->info.textures_used |= 1u << tex->texture_index; + + /* For drivers using PIPE_CAP_NIR_SAMPLERS_AS_DEREF, we need + * to reference the correct sampler nir variable. + */ + int tex_index = nir_tex_instr_src_index(tex, nir_tex_src_texture_deref); + int samp_index = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref); + if (tex_index >= 0 && samp_index >= 0) { + b->cursor = nir_before_instr(&tex->instr); + + nir_variable* samp = find_sampler(state, plane[0].i32); + assert(samp); + + nir_deref_instr *tex_deref_instr = nir_build_deref_var(b, samp); + nir_ssa_def *tex_deref = &tex_deref_instr->dest.ssa; + + nir_instr_rewrite_src(&tex->instr, + &tex->src[tex_index].src, + nir_src_for_ssa(tex_deref)); + nir_instr_rewrite_src(&tex->instr, + &tex->src[samp_index].src, + nir_src_for_ssa(tex_deref)); + } } nir_tex_instr_remove_src(tex, plane_index); @@ -138,8 +161,11 @@ lower_tex_src_plane_block(lower_tex_src_state *state, nir_block *block) static void lower_tex_src_plane_impl(lower_tex_src_state *state, nir_function_impl *impl) { + nir_builder b; + nir_builder_init(&b, impl); + nir_foreach_block(block, impl) { - lower_tex_src_plane_block(state, block); + lower_tex_src_plane_block(&b, state, block); } nir_metadata_preserve(impl, nir_metadata_block_index | -- 2.30.2