[Mesa-dev] [PATCH 118/133] nir: Add a sampler index indirect to nir_tex_instr

Jason Ekstrand jason at jlekstrand.net
Wed Jan 7 09:58:42 PST 2015


On Wed, Jan 7, 2015 at 9:58 AM, Jason Ekstrand <jason at jlekstrand.net> wrote:

>
>
> On Wed, Jan 7, 2015 at 7:55 AM, Connor Abbott <cwabbott0 at gmail.com> wrote:
>
>> On Tue, Jan 6, 2015 at 6:36 PM, Jason Ekstrand <jason at jlekstrand.net>
>> wrote:
>> >
>> >
>> > On Mon, Jan 5, 2015 at 10:45 PM, Connor Abbott <cwabbott0 at gmail.com>
>> wrote:
>> >>
>> >> I created nir_tex_src_sampler_index for exactly this purpose, which
>> >> fits in with the "stick all the sources in an array so we can easily
>> >> iterate over them" philosophy. If you decide to keep with this
>> >> solution, though, at least remove that.
>> >
>> >
>> > Sorry, I completely missed that.  My only gripe is that it doesn't
>> really
>> > follow the rest of our base_offset + indirect philosophy.  Is that the
>> way
>> > you were intending to use it?  i.e. direct just has sampler_index and
>> > indirect is sampler_index + nir_tex_src_sampler_index.  If so, maybe we
>> > should rename it to nir_tex_src_sampler_indirect.
>> >
>> > I'm 100% ok with that, It just isn't at all clear how the two work
>> together.
>> > --Jason
>>
>> Well, when I added nir_tex_src_sampler_index, it was more of a "I know
>> we'll need something like this eventually so I'll stick it here to
>> remind myself/other people when the time comes" thing, and I wasn't
>> sure which option would be better. So you can keep it and always set
>> sampler_index to 0 when it's indirect, or rename it - whatever's
>> easier to do, so long as it's consistent.
>>
>
> I think I'll go ahead and rename it.  It's more consistent with the rest
> of the texture instruction stuff to have it in the list and it's more
> consistent with other things to have it be an offset applied to the index.
> It's going to generate the same backend code either way.
>

Also, it allows backends to do something more interesting if they know that
the index is always the base of the array.


> --Jason
>
>
>>
>> >
>> >>
>> >>
>> >> On Tue, Dec 16, 2014 at 1:13 AM, Jason Ekstrand <jason at jlekstrand.net>
>> >> wrote:
>> >> > ---
>> >> >  src/glsl/nir/nir.c          | 11 +++++++++++
>> >> >  src/glsl/nir/nir.h          | 10 ++++++++++
>> >> >  src/glsl/nir/nir_print.c    |  4 ++++
>> >> >  src/glsl/nir/nir_validate.c |  3 +++
>> >> >  4 files changed, 28 insertions(+)
>> >> >
>> >> > diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
>> >> > index 60c9cff..8bcc64a 100644
>> >> > --- a/src/glsl/nir/nir.c
>> >> > +++ b/src/glsl/nir/nir.c
>> >> > @@ -461,6 +461,13 @@ nir_tex_instr_create(void *mem_ctx, unsigned
>> >> > num_srcs)
>> >> >     instr->has_predicate = false;
>> >> >     src_init(&instr->predicate);
>> >> >
>> >> > +   instr->sampler_index = 0;
>> >> > +   instr->has_sampler_indirect = false;
>> >> > +   src_init(&instr->sampler_indirect);
>> >> > +   instr->sampler_indirect_max = 0;
>> >> > +
>> >> > +   instr->sampler = NULL;
>> >> > +
>> >> >     return instr;
>> >> >  }
>> >> >
>> >> > @@ -1529,6 +1536,10 @@ visit_tex_src(nir_tex_instr *instr,
>> >> > nir_foreach_src_cb cb, void *state)
>> >> >        if (!visit_src(&instr->predicate, cb, state))
>> >> >           return false;
>> >> >
>> >> > +   if (instr->has_sampler_indirect)
>> >> > +      if (!visit_src(&instr->sampler_indirect, cb, state))
>> >> > +         return false;
>> >> > +
>> >> >     if (instr->sampler != NULL)
>> >> >        if (!visit_deref_src(instr->sampler, cb, state))
>> >> >           return false;
>> >> > diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
>> >> > index 32bf634..bc7a226 100644
>> >> > --- a/src/glsl/nir/nir.h
>> >> > +++ b/src/glsl/nir/nir.h
>> >> > @@ -838,7 +838,17 @@ typedef struct {
>> >> >     /* gather component selector */
>> >> >     unsigned component : 2;
>> >> >
>> >> > +   /** The sampler index
>> >> > +    *
>> >> > +    * If has_indirect is true, then the sampler index is given by
>> >> > +    * sampler_index + sampler_indirect where sampler_indirect has a
>> >> > maximum
>> >> > +    * possible value of sampler_indirect_max.
>> >> > +    */
>> >> >     unsigned sampler_index;
>> >> > +   bool has_sampler_indirect;
>> >> > +   nir_src sampler_indirect;
>> >> > +   unsigned sampler_indirect_max;
>> >> > +
>> >> >     nir_deref_var *sampler; /* if this is NULL, use sampler_index
>> >> > instead */
>> >> >  } nir_tex_instr;
>> >> >
>> >> > diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
>> >> > index 962e408..67df9a5 100644
>> >> > --- a/src/glsl/nir/nir_print.c
>> >> > +++ b/src/glsl/nir/nir_print.c
>> >> > @@ -498,6 +498,10 @@ print_tex_instr(nir_tex_instr *instr,
>> >> > print_var_state *state, FILE *fp)
>> >> >        print_deref(instr->sampler, state, fp);
>> >> >     } else {
>> >> >        fprintf(fp, "%u", instr->sampler_index);
>> >> > +      if (instr->has_sampler_indirect) {
>> >> > +         fprintf(fp, " + ");
>> >> > +         print_src(&instr->sampler_indirect, fp);
>> >> > +      }
>> >> >     }
>> >> >
>> >> >     fprintf(fp, " (sampler)");
>> >> > diff --git a/src/glsl/nir/nir_validate.c
>> b/src/glsl/nir/nir_validate.c
>> >> > index e565b3c..ed6e482 100644
>> >> > --- a/src/glsl/nir/nir_validate.c
>> >> > +++ b/src/glsl/nir/nir_validate.c
>> >> > @@ -399,6 +399,9 @@ validate_tex_instr(nir_tex_instr *instr,
>> >> > validate_state *state)
>> >> >        validate_src(&instr->src[i], state);
>> >> >     }
>> >> >
>> >> > +   if (instr->has_sampler_indirect)
>> >> > +      validate_src(&instr->sampler_indirect, state);
>> >> > +
>> >> >     if (instr->sampler != NULL)
>> >> >        validate_deref_var(instr->sampler, state);
>> >> >  }
>> >> > --
>> >> > 2.2.0
>> >> >
>> >> > _______________________________________________
>> >> > mesa-dev mailing list
>> >> > mesa-dev at lists.freedesktop.org
>> >> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150107/ab02423c/attachment-0001.html>


More information about the mesa-dev mailing list