<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Nov 13, 2018 at 3:21 PM Roland Scheidegger <<a href="mailto:sroland@vmware.com">sroland@vmware.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 12.11.18 um 20:40 schrieb Jason Ekstrand:<br>
> On Mon, Nov 12, 2018 at 1:29 PM Christian Gmeiner<br>
> <<a href="mailto:christian.gmeiner@gmail.com" target="_blank">christian.gmeiner@gmail.com</a> <mailto:<a href="mailto:christian.gmeiner@gmail.com" target="_blank">christian.gmeiner@gmail.com</a>>> wrote:<br>
> <br>
> Hi Jason<br>
> <br>
> Am Sa., 1. Sep. 2018 um 21:23 Uhr schrieb Jason Ekstrand<br>
> <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a> <mailto:<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>>>:<br>
> ><br>
> > I don't think either of these work for negative numbers<br>
> ><br>
> <br>
> I would like to land this patch - can you provide some details why<br>
> this does not work for<br>
> negative numbers?<br>
> <br>
> <br>
> No, this is correct. It's GLSL's definition of fract(x) that's dumb. <br>
> GLSL defines fract(x) as x - floor(x) (exactly what your formula says. <br>
> This means that<br>
> <br>
> fract(-1.4) = -1.4 - floor(-1.4) = -1.4 - (-2.0) = -1.4 + 2.0 = 0.6<br>
> <br>
> so GLSL fract() doesn't give you the fractional part at all. *sigh*<br>
Can you elaborate why you think this result to be wrong? In fact it's<br>
the only definition I've ever heard of. But yes, wikipedia says fract<br>
for negative numbers is open for debate (with 3 possible solutions). In<br>
the context of graphics shading languages, it is however most definitely<br>
the agreed-upon formula for fractional parts (and certainly the same<br>
formula was used pre-glsl or hlsl).<br></blockquote><div><br></div><div>It falls into exactly the same category as all the different ways to define modulus/remainder. You just sort-of end up having to pick one. I guess my main gripe is that, when someone says "returns the fractional part", I would expect x = trunc(x) + fract(x) or x = trunc(x) + sign(x) * fract(x). Of the possible conventions, they chose the one that I find to be the strangest. That's all.</div><div><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Roland<br>
<br>
<br>
> <br>
> Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a><br>
> <mailto:<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>>><br>
> <br>
> <br>
> > On September 1, 2018 14:16:11 Christian Gmeiner<br>
> > <<a href="mailto:christian.gmeiner@gmail.com" target="_blank">christian.gmeiner@gmail.com</a> <mailto:<a href="mailto:christian.gmeiner@gmail.com" target="_blank">christian.gmeiner@gmail.com</a>>><br>
> wrote:<br>
> ><br>
> > > Signed-off-by: Christian Gmeiner <<a href="mailto:christian.gmeiner@gmail.com" target="_blank">christian.gmeiner@gmail.com</a><br>
> <mailto:<a href="mailto:christian.gmeiner@gmail.com" target="_blank">christian.gmeiner@gmail.com</a>>><br>
> > > ---<br>
> > > src/compiler/nir/nir.h | 3 +++<br>
> > > src/compiler/nir/nir_opt_algebraic.py | 1 +<br>
> > > 2 files changed, 4 insertions(+)<br>
> > ><br>
> > > diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
> > > index 169fa1fa20..d81eefc032 100644<br>
> > > --- a/src/compiler/nir/nir.h<br>
> > > +++ b/src/compiler/nir/nir.h<br>
> > > @@ -2054,6 +2054,9 @@ typedef struct nir_shader_compiler_options {<br>
> > > */<br>
> > > bool fdot_replicates;<br>
> > ><br>
> > > + /** lowers ffloor to fsub+ffract: */<br>
> > > + bool lower_ffloor;<br>
> > > +<br>
> > > /** lowers ffract to fsub+ffloor: */<br>
> > > bool lower_ffract;<br>
> > ><br>
> > > diff --git a/src/compiler/nir/nir_opt_algebraic.py<br>
> > > b/src/compiler/nir/nir_opt_algebraic.py<br>
> > > index ae1261f874..3d2b861a42 100644<br>
> > > --- a/src/compiler/nir/nir_opt_algebraic.py<br>
> > > +++ b/src/compiler/nir/nir_opt_algebraic.py<br>
> > > @@ -118,6 +118,7 @@ optimizations = [<br>
> > > (('~flrp', a, 0.0, c), ('fadd', ('fmul', ('fneg', a), c), a)),<br>
> > > (('flrp@32', a, b, c), ('fadd', ('fmul', c, ('fsub', b, a)), a),<br>
> > > 'options->lower_flrp32'),<br>
> > > (('flrp@64', a, b, c), ('fadd', ('fmul', c, ('fsub', b, a)), a),<br>
> > > 'options->lower_flrp64'),<br>
> > > + (('ffloor', a), ('fsub', a, ('ffract', a)),<br>
> 'options->lower_ffloor'),<br>
> > > (('ffract', a), ('fsub', a, ('ffloor', a)),<br>
> 'options->lower_ffract'),<br>
> > > (('~fadd', ('fmul', a, ('fadd', 1.0, ('fneg', ('b2f', c)))),<br>
> ('fmul', b,<br>
> > > ('b2f', c))), ('bcsel', c, b, a), 'options->lower_flrp32'),<br>
> > > (('~fadd@32', ('fmul', a, ('fadd', 1.0, ('fneg', c<br>
> ))), ('fmul', b,<br>
> > > c )), ('flrp', a, b, c), '!options->lower_flrp32'),<br>
> > > --<br>
> > > 2.17.1<br>
> > ><br>
> > > _______________________________________________<br>
> > > mesa-dev mailing list<br>
> > > <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
> <mailto:<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a>><br>
> > > <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
> <<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Ce0fe2529778847ca3ef208d648d6bb83%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636776484451503870&sdata=vkUGCDEE3AeUCdZaibTXfuIwQS0FU39C3V%2FnJMraRlM%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Ce0fe2529778847ca3ef208d648d6bb83%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636776484451503870&sdata=vkUGCDEE3AeUCdZaibTXfuIwQS0FU39C3V%2FnJMraRlM%3D&reserved=0</a>><br>
> ><br>
> ><br>
> ><br>
> <br>
> -- <br>
> greets<br>
> --<br>
> Christian Gmeiner, MSc<br>
> <br>
> <a href="https://christian-gmeiner.info" rel="noreferrer" target="_blank">https://christian-gmeiner.info</a><br>
> <<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fchristian-gmeiner.info&data=02%7C01%7Csroland%40vmware.com%7Ce0fe2529778847ca3ef208d648d6bb83%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636776484451513879&sdata=IPMIs3gEGPgunAgWAoMjjR%2Bev%2FEBADnfJItCHtFuyYc%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fchristian-gmeiner.info&data=02%7C01%7Csroland%40vmware.com%7Ce0fe2529778847ca3ef208d648d6bb83%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636776484451513879&sdata=IPMIs3gEGPgunAgWAoMjjR%2Bev%2FEBADnfJItCHtFuyYc%3D&reserved=0</a>><br>
> <br>
> <br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Ce0fe2529778847ca3ef208d648d6bb83%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636776484451523879&sdata=uioIRixNYHv8b%2FKTa%2BXqkzkDVZCnlm4FYdzsnxsDo38%3D&reserved=0" rel="noreferrer" target="_blank">https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Ce0fe2529778847ca3ef208d648d6bb83%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636776484451523879&sdata=uioIRixNYHv8b%2FKTa%2BXqkzkDVZCnlm4FYdzsnxsDo38%3D&reserved=0</a><br>
> <br>
<br>
</blockquote></div></div>