<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Mar 3, 2018 at 11:57 PM, Pohjolainen, Topi <span dir="ltr"><<a href="mailto:topi.pohjolainen@gmail.com" target="_blank">topi.pohjolainen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Jan 26, 2018 at 05:59:37PM -0800, Jason Ekstrand wrote:<br>
> ---<br>
>  src/compiler/nir/nir_format_<wbr>convert.h | 26 ++++++++++++++++++++++++++<br>
>  1 file changed, 26 insertions(+)<br>
<br>
</span>I don't what is the official reference for the formulas and I just took what<br>
google gave me first. There was discussion about the cutoff point between<br>
linear and curved. I got the impression that what you chose below<br>
(open-ended: 0 <= linear < 0.0031308f and 0 <= linear < 0.04045f instead of<br>
close-ended) was more "correct". Just thought I check that anyway (that you<br>
chose that on purpose).<br></blockquote><div><br></div><div>I did some digging.  Everyone agrees that it's supposed to be <= 0.04045 for sRGB -> linear.  For linear -> sRGB, it's a bit more confused.  OpenGL 4.5, OpenGL ES 3.2, and the WSI chapter of Vulkan 1.0 all say < 0.0031308 but the Khronos data format spec, the W3C spec it references, and Wikipedia all say <= 0.0031308.  I've sent an e-mail off to Andrew Garrard, the author of the data format spec, to see if he can shed some light on it.  In any case, no 8-bit UNORM value will ever hit this corner case, so I don't think it matters in practice.  In the mean time, I've adjusted the  NIR helpers to match the OpenGL [ES] convention for both formulas.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Reviewed-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>><br>
<div><div class="h5"><br>
><br>
> diff --git a/src/compiler/nir/nir_format_<wbr>convert.h b/src/compiler/nir/nir_format_<wbr>convert.h<br>
> index e09c955..07618dc 100644<br>
> --- a/src/compiler/nir/nir_format_<wbr>convert.h<br>
> +++ b/src/compiler/nir/nir_format_<wbr>convert.h<br>
> @@ -104,3 +104,29 @@ nir_format_pack_uint(nir_<wbr>builder *b, nir_ssa_def *color,<br>
>     return nir_format_pack_uint_unmasked(<wbr>b, nir_iand(b, color, mask_imm),<br>
>                                          bits, num_components);<br>
>  }<br>
> +<br>
> +static inline nir_ssa_def *<br>
> +nir_format_linear_to_srgb(<wbr>nir_builder *b, nir_ssa_def *c)<br>
> +{<br>
> +   nir_ssa_def *linear = nir_fmul(b, c, nir_imm_float(b, 12.92f));<br>
> +   nir_ssa_def *curved =<br>
> +      nir_fsub(b, nir_fmul(b, nir_imm_float(b, 1.055f),<br>
> +                              nir_fpow(b, c, nir_imm_float(b, 1.0 / 2.4))),<br>
> +                  nir_imm_float(b, 0.055f));<br>
> +<br>
> +   return nir_fsat(b, nir_bcsel(b, nir_flt(b, c, nir_imm_float(b, 0.0031308f)),<br>
> +                                   linear, curved));<br>
> +}<br>
> +<br>
> +static inline nir_ssa_def *<br>
> +nir_format_srgb_to_linear(<wbr>nir_builder *b, nir_ssa_def *c)<br>
> +{<br>
> +   nir_ssa_def *linear = nir_fdiv(b, c, nir_imm_float(b, 12.92f));<br>
> +   nir_ssa_def *curved =<br>
> +      nir_fpow(b, nir_fdiv(b, nir_fadd(b, c, nir_imm_float(b, 0.055f)),<br>
> +                              nir_imm_float(b, 1.055f)),<br>
> +                  nir_imm_float(b, 2.4f));<br>
> +<br>
> +   return nir_fsat(b, nir_bcsel(b, nir_flt(b, c, nir_imm_float(b, 0.04045f)),<br>
> +                                   linear, curved));<br>
> +}<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">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/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>