[Mesa-dev] [PATCH 4/6] nir/lower_tex: support for lowering RECT textures
Ilia Mirkin
imirkin at alum.mit.edu
Thu Sep 17 08:51:15 PDT 2015
On Thu, Sep 17, 2015 at 8:48 AM, Rob Clark <robdclark at gmail.com> wrote:
> From: Rob Clark <robclark at freedesktop.org>
>
> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> ---
> src/glsl/nir/nir.h | 7 +++++
> src/glsl/nir/nir_lower_tex.c | 66 ++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 70 insertions(+), 3 deletions(-)
>
> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
> index 04dfc97..a40dbae 100644
> --- a/src/glsl/nir/nir.h
> +++ b/src/glsl/nir/nir.h
> @@ -1837,6 +1837,13 @@ typedef struct nir_lower_tex_options {
> * sampler types a texture projector is lowered.
> */
> unsigned lower_txp;
> +
> + /**
> + * If true, lower rect textures to 2D, using txs to fetch the
> + * texture dimensions and dividing the texture coords by the
> + * texture dims to normalize.
> + */
> + bool lower_rect;
> } nir_lower_tex_options;
>
> void nir_lower_tex(nir_shader *shader,
> diff --git a/src/glsl/nir/nir_lower_tex.c b/src/glsl/nir/nir_lower_tex.c
> index 281fc9f..002c82d 100644
> --- a/src/glsl/nir/nir_lower_tex.c
> +++ b/src/glsl/nir/nir_lower_tex.c
> @@ -22,9 +22,13 @@
> */
>
> /*
> - * This lowering pass converts the coordinate division for texture projection
> - * to be done in ALU instructions instead of asking the texture operation to
> - * do so.
> + * This lowering pass supports (as configured via nir_lower_tex_options)
> + * various texture related conversions:
> + * + texture projector lowering: converts the coordinate division for
> + * texture projection to be done in ALU instructions instead of
> + * asking the texture operation to do so.
> + * + lowering RECT: converts the un-normalized RECT texture coordinates
> + * to normalized coordinates with txs plus ALU instructions
> */
>
> #include "nir.h"
> @@ -111,6 +115,59 @@ project_src(nir_builder *b, nir_tex_instr *tex)
> tex->num_srcs--;
> }
>
> +static void
> +lower_rect(nir_builder *b, nir_tex_instr *tex)
> +{
> + b->cursor = nir_before_instr(&tex->instr);
> +
> + nir_tex_instr *txs;
> + txs = nir_tex_instr_create(b->shader, 1);
> + txs->op = nir_texop_txs;
> + txs->sampler_dim = GLSL_SAMPLER_DIM_RECT;
> + txs->sampler_index = tex->sampler_index;
> + /* TODO we don't actually need the array dimension.. is it valid
> + * to have is_array==false even for RECT_ARRAY?
> + */
There's no such thing as RECT_ARRAY... you can drop the array handling
here and below I think.
> + txs->is_array = tex->is_array;
> +
> + /* only single src, the lod: */
> + txs->src[0].src = nir_src_for_ssa(nir_imm_int(b, 0));
> + txs->src[0].src_type = nir_tex_src_lod;
> +
> + nir_ssa_dest_init(&txs->instr, &txs->dest, 3, NULL);
> + nir_builder_instr_insert(b, &txs->instr);
> +
> + nir_ssa_def *x = nir_i2f(b, nir_channel(b, &txs->dest.ssa, 0));
> + nir_ssa_def *y = nir_i2f(b, nir_channel(b, &txs->dest.ssa, 1));
> + nir_ssa_def *scalex = nir_frcp(b, x);
> + nir_ssa_def *scaley = nir_frcp(b, y);
> + nir_ssa_def *scale;
> +
> + if (tex->is_array)
> + scale = nir_vec3(b, scalex, scaley, nir_imm_float(b, 1.0));
> + else
> + scale = nir_vec2(b, scalex, scaley);
> +
> + /* Walk through the sources normalizing the requested arguments. */
> + for (unsigned i = 0; i < tex->num_srcs; i++) {
> + switch (tex->src[i].src_type) {
> + case nir_tex_src_coord:
> + break;
> + default:
> + continue;
> + }
this feels like a really convoluted way of saying
if (tex->src[i].src_type != nir_tex_src_coord)
continue;
> + nir_ssa_def *src =
> + nir_ssa_for_src(b, tex->src[i].src, tex->coord_components);
> +
> + /* normalize coords: */
> + src = nir_fmul(b, src, scale);
> +
> + nir_instr_rewrite_src(&tex->instr,
> + &tex->src[i].src,
> + nir_src_for_ssa(src));
> + }
> +}
> +
> static bool
> nir_lower_tex_block(nir_block *block, void *void_state)
> {
> @@ -127,6 +184,9 @@ nir_lower_tex_block(nir_block *block, void *void_state)
> if (lower_txp)
> project_src(b, tex);
>
> + if ((tex->sampler_dim == GLSL_SAMPLER_DIM_RECT) &&
> + state->options->lower_rect)
> + lower_rect(b, tex);
> }
>
> return true;
> --
> 2.4.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list