[Mesa-dev] [PATCH 06/16] nir/lower_tex: Add some helpers for working with tex sources
Pohjolainen, Topi
topi.pohjolainen at intel.com
Fri Jul 22 08:03:26 UTC 2016
On Thu, Jul 21, 2016 at 09:21:51PM -0700, Jason Ekstrand wrote:
> Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
> Cc: "12.0" <mesa-dev at lists.freedesktop.org>
> ---
> src/compiler/nir/nir_lower_tex.c | 46 ++++++++++++++++++++++++++--------------
> 1 file changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
> index 195cb1d..0cf1071 100644
> --- a/src/compiler/nir/nir_lower_tex.c
> +++ b/src/compiler/nir/nir_lower_tex.c
> @@ -38,16 +38,39 @@
> #include "nir.h"
> #include "nir_builder.h"
>
> +static int
> +tex_instr_find_src(nir_tex_instr *tex, nir_tex_src_type src)
Maybe use "src_type" as the name of the argument...
> +{
> + for (unsigned i = 0; i < tex->num_srcs; i++) {
> + if (tex->src[i].src_type == src)
> + return i;
> + }
> +
> + return -1;
> +}
> +
> +static void
> +tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx)
> +{
> + assert(src_idx < tex->num_srcs);
> +
> + /* First rewrite the source to NIR_SRC_INIT */
> + nir_instr_rewrite_src(&tex->instr, &tex->src[src_idx].src, NIR_SRC_INIT);
> +
> + /* Now, move all of the other sources down */
> + for (unsigned i = src_idx + 1; i < tex->num_srcs; i++) {
> + tex->src[i-1].src_type = tex->src[i].src_type;
> + nir_instr_move_src(&tex->instr, &tex->src[i-1].src, &tex->src[i].src);
> + }
> + tex->num_srcs--;
> +}
> +
> static void
> project_src(nir_builder *b, nir_tex_instr *tex)
> {
> /* Find the projector in the srcs list, if present. */
> - unsigned proj_index;
> - for (proj_index = 0; proj_index < tex->num_srcs; proj_index++) {
> - if (tex->src[proj_index].src_type == nir_tex_src_projector)
> - break;
> - }
> - if (proj_index == tex->num_srcs)
> + int proj_index = tex_instr_find_src(tex, nir_tex_src_projector);
This could be declared 'const' while we are at it.
> + if (proj_index < 0)
> return;
>
> b->cursor = nir_before_instr(&tex->instr);
> @@ -102,16 +125,7 @@ project_src(nir_builder *b, nir_tex_instr *tex)
> nir_src_for_ssa(projected));
> }
>
> - /* Now move the later tex sources down the array so that the projector
> - * disappears.
> - */
> - nir_instr_rewrite_src(&tex->instr, &tex->src[proj_index].src,
> - NIR_SRC_INIT);
> - for (unsigned i = proj_index + 1; i < tex->num_srcs; i++) {
> - tex->src[i-1].src_type = tex->src[i].src_type;
> - nir_instr_move_src(&tex->instr, &tex->src[i-1].src, &tex->src[i].src);
> - }
> - tex->num_srcs--;
> + tex_instr_remove_src(tex, proj_index);
> }
>
> static nir_ssa_def *
> --
> 2.5.0.400.gff86faf
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list