<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 21, 2018 at 12:34 PM, Neil Roberts <span dir="ltr"><<a href="mailto:nroberts@igalia.com" target="_blank">nroberts@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The SPIR-V spec doesn’t specify a size requirement for these and the<br>
equivalent functions in the GLSL spec have explicit alternatives for<br>
doubles. Refract is a little bit more complicated due to the fact that<br>
the final argument is always supposed to be a scalar 32- or 16- bit<br>
float regardless of the other operands. However in practice it seems<br>
there is a bug in glslang that makes it convert the argument to 64-bit<br>
if you actually try to pass it a 32-bit value while the other<br>
arguments are 64-bit. This adds an optional conversion of the final<br>
argument in order to support any type.<br>
<br>
These have been tested against the automatically generated tests of<br>
glsl-4.00/execution/built-in-<wbr>functions using the ARB_gl_spirv branch<br>
which tests it with quite a large range of combinations.<br>
<br>
The issue with glslang has been filed here:<br>
<a href="https://github.com/KhronosGroup/glslang/issues/1279" rel="noreferrer" target="_blank">https://github.com/<wbr>KhronosGroup/glslang/issues/<wbr>1279</a><br>
<br>
v2: Convert the eta operand of Refract from any size in order to make<br>
it eventually cope with 16-bit floats.<br>
---<br>
src/compiler/spirv/vtn_<wbr>glsl450.c | 22 ++++++++++++++++++----<br>
1 file changed, 18 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/compiler/spirv/vtn_<wbr>glsl450.c b/src/compiler/spirv/vtn_<wbr>glsl450.c<br>
index 50783fbfb4d..0cabedf741d 100644<br>
--- a/src/compiler/spirv/vtn_<wbr>glsl450.c<br>
+++ b/src/compiler/spirv/vtn_<wbr>glsl450.c<br>
@@ -628,14 +628,14 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,<br>
case GLSLstd450FaceForward:<br>
val->ssa->def =<br>
nir_bcsel(nb, nir_flt(nb, nir_fdot(nb, src[2], src[1]),<br>
- nir_imm_float(nb, 0.0)),<br>
+ NIR_IMM_FP(nb, 0.0)),<br>
src[0], nir_fneg(nb, src[0]));<br>
return;<br>
<br>
case GLSLstd450Reflect:<br>
/* I - 2 * dot(N, I) * N */<br>
val->ssa->def =<br>
- nir_fsub(nb, src[0], nir_fmul(nb, nir_imm_float(nb, 2.0),<br>
+ nir_fsub(nb, src[0], nir_fmul(nb, NIR_IMM_FP(nb, 2.0),<br>
nir_fmul(nb, nir_fdot(nb, src[0], src[1]),<br>
src[1])));<br>
return;<br>
@@ -645,8 +645,22 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,<br>
nir_ssa_def *N = src[1];<br>
nir_ssa_def *eta = src[2];<br>
nir_ssa_def *n_dot_i = nir_fdot(nb, N, I);<br>
- nir_ssa_def *one = nir_imm_float(nb, 1.0);<br>
- nir_ssa_def *zero = nir_imm_float(nb, 0.0);<br>
+ nir_ssa_def *one = NIR_IMM_FP(nb, 1.0);<br>
+ nir_ssa_def *zero = NIR_IMM_FP(nb, 0.0);<br>
+ /* According to the SPIR-V and GLSL specs, eta is always a float<br>
+ * regardless of the type of the other operands. However in practice it<br>
+ * seems that if you try to pass it a float then glslang will just<br>
+ * promote it to a double and generate invalid SPIR-V. In order to<br>
+ * support a hypothetical fixed version of glslang we’ll promote eta to<br>
+ * double if the other operands are double also.<br>
+ */<br></blockquote><div><br></div><div>That's a bit ugly. Seems like the right thing to do though<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if (I->bit_size != eta->bit_size) {<br>
+ nir_op conversion_op =<br>
+ nir_type_conversion_op(nir_<wbr>type_float | eta->bit_size,<br>
+ nir_type_float | I->bit_size,<br>
+ nir_rounding_mode_undef);<br>
+ eta = nir_build_alu(nb, conversion_op, eta, NULL, NULL, NULL);<br>
+ }<br>
/* k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I)) */<br>
nir_ssa_def *k =<br>
nir_fsub(nb, one, nir_fmul(nb, eta, nir_fmul(nb, eta,<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.14.3<br>
<br>
______________________________<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>
</font></span></blockquote></div><br></div></div>