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

Rob Clark robdclark at gmail.com
Fri Sep 18 17:25:06 PDT 2015


On Fri, Sep 18, 2015 at 10:29 AM, Eric Anholt <eric at anholt.net> wrote:
> 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)?

oh, didn't even realize nir would do what I want when combining vec1
w/ vec4 in the later bcsel..  (although I guess I should have realized
that nir_imm_float() was just giving me a vec1)..

so yeah, nir_channel() actually works.. I was assuming I'd need
nir_swizzle() in order to have a vec4 for the bcsel..

BR,
-R

> 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));
>> +   }
>


More information about the mesa-dev mailing list