[Mesa-dev] [PATCH 6/8] i965/fs: Handle conditional discards.
Kenneth Graunke
kenneth at whitecape.org
Tue Feb 24 11:23:28 PST 2015
On Tuesday, February 24, 2015 01:25:18 PM Connor Abbott wrote:
> On Tue, Feb 24, 2015 at 5:19 AM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> > For conditional discards, we can call emit_bool_to_cond_code to generate
> > the condition in f0.0. However, we want it in f0.1. The flag value is
> > always produced by the last instruction emit_bool_to_cond_code
> > generates, so we can simply get the last instruction and patch it up.
>
> Is this left over from an earlier version? It seems to me like we're
> just doing the dumb thing (rather than emit_bool_to_cond_code()) here
> and letting the i965 optimizer clean it up for both GLSL IR and NIR.
Oops. Yes :) I was originally doing:
emit_bool_to_cond_code(new(mem_ctx) ir_expression(ir_unop_logic_not,
ir->condition))
cmp = (fs_inst *) this->instructions.get_tail();
but that seemed more fragile for no real benefit - it actually emitted
ir->condition as a boolean, then did an AND.z <bool> 1D to produce the
condition code (making cmp an AND!). Same number of instructions.
I'll fix up the commit message.
> >
> > Nothing generates these today, but that will change shortly.
> >
> > Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> > ---
> > src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 22 ++++++++++++++--------
> > src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 21 ++++++++++++---------
> > 2 files changed, 26 insertions(+), 17 deletions(-)
> >
> > diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> > index 90eecae..6354bde 100644
> > --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> > +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> > @@ -1149,16 +1149,22 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)
> > bool has_indirect = false;
> >
> > switch (instr->intrinsic) {
> > - case nir_intrinsic_discard: {
> > + case nir_intrinsic_discard:
> > + case nir_intrinsic_discard_if: {
> > /* We track our discarded pixels in f0.1. By predicating on it, we can
> > - * update just the flag bits that aren't yet discarded. By emitting a
> > - * CMP of g0 != g0, all our currently executing channels will get turned
> > - * off.
> > + * update just the flag bits that aren't yet discarded. If there's no
> > + * condition, we emit a CMP of g0 != g0, so all currently executing
> > + * channels will get turned off.
> > */
> > - fs_reg some_reg = fs_reg(retype(brw_vec8_grf(0, 0),
> > - BRW_REGISTER_TYPE_UW));
> > - fs_inst *cmp = emit(CMP(reg_null_f, some_reg, some_reg,
> > - BRW_CONDITIONAL_NZ));
> > + fs_inst *cmp;
> > + if (instr->intrinsic == nir_intrinsic_discard_if) {
> > + cmp = emit(CMP(reg_null_f, get_nir_src(instr->src[0]),
> > + fs_reg(0), BRW_CONDITIONAL_Z));
> > + } else {
> > + fs_reg some_reg = fs_reg(retype(brw_vec8_grf(0, 0),
> > + BRW_REGISTER_TYPE_UW));
> > + cmp = emit(CMP(reg_null_f, some_reg, some_reg, BRW_CONDITIONAL_NZ));
> > + }
> > cmp->predicate = BRW_PREDICATE_NORMAL;
> > cmp->flag_subreg = 1;
> >
> > diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> > index b1b75821..75254a1 100644
> > --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> > +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> > @@ -2415,17 +2415,20 @@ fs_visitor::visit(ir_swizzle *ir)
> > void
> > fs_visitor::visit(ir_discard *ir)
> > {
> > - assert(ir->condition == NULL); /* FINISHME */
> > -
> > /* We track our discarded pixels in f0.1. By predicating on it, we can
> > - * update just the flag bits that aren't yet discarded. By emitting a
> > - * CMP of g0 != g0, all our currently executing channels will get turned
> > - * off.
> > + * update just the flag bits that aren't yet discarded. If there's no
> > + * condition, we emit a CMP of g0 != g0, so all currently executing
> > + * channels will get turned off.
> > */
> > - fs_reg some_reg = fs_reg(retype(brw_vec8_grf(0, 0),
> > - BRW_REGISTER_TYPE_UW));
> > - fs_inst *cmp = emit(CMP(reg_null_f, some_reg, some_reg,
> > - BRW_CONDITIONAL_NZ));
> > + fs_inst *cmp;
> > + if (ir->condition) {
> > + ir->condition->accept(this);
> > + cmp = emit(CMP(reg_null_f, this->result, fs_reg(0), BRW_CONDITIONAL_Z));
> > + } else {
> > + fs_reg some_reg = fs_reg(retype(brw_vec8_grf(0, 0),
> > + BRW_REGISTER_TYPE_UW));
> > + cmp = emit(CMP(reg_null_f, some_reg, some_reg, BRW_CONDITIONAL_NZ));
> > + }
> > cmp->predicate = BRW_PREDICATE_NORMAL;
> > cmp->flag_subreg = 1;
> >
> > --
> > 2.2.2
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150224/86d147d7/attachment-0001.sig>
More information about the mesa-dev
mailing list