[Mesa-dev] [PATCH 09/12] nir: Add lowering support for packing opcodes.

Jason Ekstrand jason at jlekstrand.net
Fri Jan 29 03:05:10 PST 2016


On Jan 29, 2016 8:44 AM, "Iago Toral" <itoral at igalia.com> wrote:
>
> On Thu, 2016-01-28 at 09:21 -0800, Matt Turner wrote:
> > On Thu, Jan 28, 2016 at 12:32 AM, Iago Toral <itoral at igalia.com> wrote:
> > > On Mon, 2016-01-25 at 15:18 -0800, Matt Turner wrote:
> (...)
> > >> diff --git a/src/glsl/nir/nir_opt_algebraic.py
b/src/glsl/nir/nir_opt_algebraic.py
> > >> index b761b54..56b0f5e 100644
> > >> --- a/src/glsl/nir/nir_opt_algebraic.py
> > >> +++ b/src/glsl/nir/nir_opt_algebraic.py
> > >> @@ -258,6 +258,26 @@ optimizations = [
> > >>     (('extract_uword', a, b),
> > >>      ('iand', ('ushr', a, ('imul', b, 16)), 0xffff),
> > >>      'options->lower_extract_word'),
> > >> +
> > >> +    (('pack_unorm_2x16', 'v'),
> > >> +     ('pack_uvec2_to_uint',
> > >> +        ('f2u', ('fround_even', ('fmul', ('fsat', 'v'), 65535.0)))),
> > >> +     'options->lower_pack_unorm_2x16'),
> > >> +
> > >> +    (('pack_unorm_4x8', 'v'),
> > >> +     ('pack_uvec4_to_uint',
> > >> +        ('f2u', ('fround_even', ('fmul', ('fsat', 'v'), 255.0)))),
> > >> +     'options->lower_pack_unorm_4x8'),
> > >> +
> > >> +    (('pack_snorm_2x16', 'v'),
> > >> +     ('pack_uvec2_to_uint',
> > >> +        ('f2i', ('fround_even', ('fmul', ('fmin', 1.0, ('fmax',
-1.0, 'v')), 32767.0)))),
> > >> +     'options->lower_pack_snorm_2x16'),
> > >> +
> > >> +    (('pack_snorm_4x8', 'v'),
> > >> +     ('pack_uvec4_to_uint',
> > >> +        ('f2i', ('fround_even', ('fmul', ('fmin', 1.0, ('fmax',
-1.0, 'v')), 127.0)))),
> > >> +     'options->lower_pack_snorm_4x8'),
> > >
> > > I think the pack_snorm_* opcodes need a i2u conversion at the end.
> > > That's what the GLSL IR lowering is doing and also what the spec [1]
> > > seems to indicate:
> >
> > Right, but since NIR operands are typeless, there's nothing to do (NIR
> > doesn't even have i2u/u2i).
>
> I suppose that since these pack the incoming vector components into an
> uint it does not really matter in the end, since that won't affect the
> bits involved. Anyway, why not use f2u instead of f2i, seems like that
> would represent the semantics expected more accurately.

Actually, since this is for snorm, I think signed integers are, in fact,
what you want. The fact that we're packing things into a single uint later
doesn't matter.  I don't know off-hand what happens if you run a negative
number through f2u.

> Iago
>
>
>
> _______________________________________________
> 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/20160129/5d974867/attachment.html>


More information about the mesa-dev mailing list