diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/spirv/vtn_glsl450.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c index c74476a48d7..6fa759b1bba 100644 --- a/src/compiler/spirv/vtn_glsl450.c +++ b/src/compiler/spirv/vtn_glsl450.c @@ -629,14 +629,14 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint, case GLSLstd450FaceForward: val->ssa->def = nir_bcsel(nb, nir_flt(nb, nir_fdot(nb, src[2], src[1]), - nir_imm_float(nb, 0.0)), + NIR_IMM_FP(nb, 0.0)), src[0], nir_fneg(nb, src[0])); return; case GLSLstd450Reflect: /* I - 2 * dot(N, I) * N */ val->ssa->def = - nir_fsub(nb, src[0], nir_fmul(nb, nir_imm_float(nb, 2.0), + nir_fsub(nb, src[0], nir_fmul(nb, NIR_IMM_FP(nb, 2.0), nir_fmul(nb, nir_fdot(nb, src[0], src[1]), src[1]))); return; @@ -646,8 +646,22 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint, nir_ssa_def *N = src[1]; nir_ssa_def *eta = src[2]; nir_ssa_def *n_dot_i = nir_fdot(nb, N, I); - nir_ssa_def *one = nir_imm_float(nb, 1.0); - nir_ssa_def *zero = nir_imm_float(nb, 0.0); + nir_ssa_def *one = NIR_IMM_FP(nb, 1.0); + nir_ssa_def *zero = NIR_IMM_FP(nb, 0.0); + /* According to the SPIR-V and GLSL specs, eta is always a float + * regardless of the type of the other operands. However in practice it + * seems that if you try to pass it a float then glslang will just + * promote it to a double and generate invalid SPIR-V. In order to + * support a hypothetical fixed version of glslang we’ll promote eta to + * double if the other operands are double also. + */ + if (I->bit_size != eta->bit_size) { + nir_op conversion_op = + nir_type_conversion_op(nir_type_float | eta->bit_size, + nir_type_float | I->bit_size, + nir_rounding_mode_undef); + eta = nir_build_alu(nb, conversion_op, eta, NULL, NULL, NULL); + } /* k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I)) */ nir_ssa_def *k = nir_fsub(nb, one, nir_fmul(nb, eta, nir_fmul(nb, eta, |