compiler/spirv: flag nclamp/nmin/nmax as exact
authorRhys Perry <pendingchaos02@gmail.com>
Mon, 3 Feb 2020 21:18:42 +0000 (21:18 +0000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 7 May 2020 10:39:19 +0000 (10:39 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3716>

src/compiler/spirv/vtn_glsl450.c

index 8a234827dc57afaeeb1e0f58aa9484b0a50a1c8c..ca836bde61b0e609ce9b49dd5d4a7a6c0799cacf 100644 (file)
@@ -219,8 +219,10 @@ build_asin(nir_builder *b, nir_ssa_def *x, float p0, float p1)
 static nir_op
 vtn_nir_alu_op_for_spirv_glsl_opcode(struct vtn_builder *b,
                                      enum GLSLstd450 opcode,
-                                     unsigned execution_mode)
+                                     unsigned execution_mode,
+                                     bool *exact)
 {
+   *exact = false;
    switch (opcode) {
    case GLSLstd450Round:         return nir_op_fround_even;
    case GLSLstd450RoundEven:     return nir_op_fround_even;
@@ -239,11 +241,11 @@ vtn_nir_alu_op_for_spirv_glsl_opcode(struct vtn_builder *b,
    case GLSLstd450Log2:          return nir_op_flog2;
    case GLSLstd450Sqrt:          return nir_op_fsqrt;
    case GLSLstd450InverseSqrt:   return nir_op_frsq;
-   case GLSLstd450NMin:          return nir_op_fmin;
+   case GLSLstd450NMin:          *exact = true; return nir_op_fmin;
    case GLSLstd450FMin:          return nir_op_fmin;
    case GLSLstd450UMin:          return nir_op_umin;
    case GLSLstd450SMin:          return nir_op_imin;
-   case GLSLstd450NMax:          return nir_op_fmax;
+   case GLSLstd450NMax:          *exact = true; return nir_op_fmax;
    case GLSLstd450FMax:          return nir_op_fmax;
    case GLSLstd450UMax:          return nir_op_umax;
    case GLSLstd450SMax:          return nir_op_imax;
@@ -353,8 +355,12 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
       return;
 
    case GLSLstd450FClamp:
+      val->ssa->def = nir_fclamp(nb, src[0], src[1], src[2]);
+      return;
    case GLSLstd450NClamp:
+      nb->exact = true;
       val->ssa->def = nir_fclamp(nb, src[0], src[1], src[2]);
+      nb->exact = false;
       return;
    case GLSLstd450UClamp:
       val->ssa->def = nir_uclamp(nb, src[0], src[1], src[2]);
@@ -515,10 +521,11 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
    default: {
       unsigned execution_mode =
          b->shader->info.float_controls_execution_mode;
-      val->ssa->def =
-         nir_build_alu(&b->nb,
-                       vtn_nir_alu_op_for_spirv_glsl_opcode(b, entrypoint, execution_mode),
-                       src[0], src[1], src[2], NULL);
+      bool exact;
+      nir_op op = vtn_nir_alu_op_for_spirv_glsl_opcode(b, entrypoint, execution_mode, &exact);
+      b->nb.exact = exact;
+      val->ssa->def = nir_build_alu(&b->nb, op, src[0], src[1], src[2], NULL);
+      b->nb.exact = false;
       return;
    }
    }