[Mesa-dev] [PATCH 1/2] nir: add two-sided-color lowering pass

Eric Anholt eric at anholt.net
Fri Sep 18 07:29:47 PDT 2015


Rob Clark <robdclark at gmail.com> writes:

> From: Rob Clark <robclark at freedesktop.org>
>
> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> ---

> +static bool
> +nir_lower_two_sided_color_block(nir_block *block, void *void_state)
> +{
> +   lower_2side_state *state = void_state;
> +   nir_builder *b = &state->b;
> +
> +   nir_foreach_instr_safe(block, instr) {
> +      if (instr->type != nir_instr_type_intrinsic)
> +         continue;
> +
> +      nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
> +
> +      if (intr->intrinsic != nir_intrinsic_load_input)
> +         continue;
> +
> +      int idx;
> +      for (idx = 0; idx < state->colors_count; idx++) {
> +         unsigned drvloc =
> +            state->colors[idx].front->data.driver_location;
> +         if (intr->const_index[0] == drvloc) {
> +            break;
> +         }
> +      }
> +
> +      if (idx == state->colors_count)
> +         continue;
> +
> +      /* replace load_input(COLn) with
> +       * bcsel(load_input(FACE), load_input(COLn), load_input(BFCn))
> +       */
> +      b->cursor = nir_before_instr(&intr->instr);
> +      nir_ssa_def *face  = load_input(b, state->face);
> +      nir_ssa_def *front = load_input(b, state->colors[idx].front);
> +      nir_ssa_def *back  = load_input(b, state->colors[idx].back);
> +      face = nir_swizzle(b, face, (unsigned[]){0,0,0,0}, 4, true);

nir_channel(b, face, 0)?

Other than that this looks like a fairly obvious implementation.

Reviewed-by: Eric Anholt <eric at anholt.net>

> +      nir_ssa_def *cond  = nir_flt(b, face, nir_imm_float(b, 0.0));
> +      nir_ssa_def *color = nir_bcsel(b, cond, back, front);
> +
> +      assert(intr->dest.is_ssa);
> +      nir_ssa_def_rewrite_uses(&intr->dest.ssa, nir_src_for_ssa(color));
> +   }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150918/e819134e/attachment.sig>


More information about the mesa-dev mailing list