On Fri, Sep 18, 2015 at 10:29 AM, Eric Anholt <e...@anholt.net> wrote: > Rob Clark <robdcl...@gmail.com> writes: > >> From: Rob Clark <robcl...@freedesktop.org> >> >> Signed-off-by: Rob Clark <robcl...@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 <e...@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)); >> + } > _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev