From 6ae2844c520b16d19f7f51650bf4b87e2d6f3749 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Mon, 7 Aug 2023 13:43:03 +0200 Subject: [PATCH] v3d: fix texture packing lowering MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For texture instructions that don't have sampler state we have been incorrectly using sampler index to retrive texture packing information. This is incorrect for two reasons: 1. These instructions don't have a defined sampler index by definition. 2. The driver was not setting it either, so effectively, we have always been using whatever we had set for the first texture, which is obviously bogus. Fix this by running a lowering pass that sets the index to use in backend_flags, which is what the compiler expects, based on the texture index, which is what we want in GL since we make this decision based on the texture format. Reviewed-by: Alejandro Piñeiro Part-of: --- src/gallium/drivers/v3d/v3d_program.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/gallium/drivers/v3d/v3d_program.c b/src/gallium/drivers/v3d/v3d_program.c index 6c49d63..73205e9 100644 --- a/src/gallium/drivers/v3d/v3d_program.c +++ b/src/gallium/drivers/v3d/v3d_program.c @@ -307,6 +307,24 @@ lower_uniform_offset_to_bytes_cb(nir_builder *b, nir_instr *instr, void *_state) } static bool +lower_textures_cb(nir_builder *b, nir_instr *instr, void *_state) +{ + if (instr->type != nir_instr_type_tex) + return false; + + nir_tex_instr *tex = nir_instr_as_tex(instr); + if (nir_tex_instr_need_sampler(tex)) + return false; + + /* Use the texture index as sampler index for the purposes of + * lower_tex_packing, since in GL we currently make packing + * decisions based on texture format. + */ + tex->backend_flags = tex->texture_index; + return true; +} + +static bool v3d_nir_lower_uniform_offset_to_bytes(nir_shader *s) { return nir_shader_instructions_pass(s, lower_uniform_offset_to_bytes_cb, @@ -314,6 +332,14 @@ v3d_nir_lower_uniform_offset_to_bytes(nir_shader *s) nir_metadata_dominance, NULL); } +static bool +v3d_nir_lower_textures(nir_shader *s) +{ + return nir_shader_instructions_pass(s, lower_textures_cb, + nir_metadata_block_index | + nir_metadata_dominance, NULL); +} + static void * v3d_uncompiled_shader_create(struct pipe_context *pctx, enum pipe_shader_ir type, void *ir) @@ -372,6 +398,8 @@ v3d_uncompiled_shader_create(struct pipe_context *pctx, */ NIR_PASS(_, s, v3d_nir_lower_uniform_offset_to_bytes); + NIR_PASS(_, s, v3d_nir_lower_textures); + /* Garbage collect dead instructions */ nir_sweep(s); -- 2.7.4