Mesa (master): spirv: Add support for the CL Round instruction

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 18 16:16:34 UTC 2020


Module: Mesa
Branch: master
Commit: 165009bc7021a0f2310222959cbb41e74b7de8d3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=165009bc7021a0f2310222959cbb41e74b7de8d3

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Tue Jul 28 08:42:53 2020 +0200

spirv: Add support for the CL Round instruction

Add a round() implementation that's conformant with the CL spec.

Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Karol Herbst <kherbst at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6256>

---

 src/compiler/spirv/vtn_opencl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c
index 6018184fe21..a4eb41d241b 100644
--- a/src/compiler/spirv/vtn_opencl.c
+++ b/src/compiler/spirv/vtn_opencl.c
@@ -281,6 +281,21 @@ handle_printf(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
    return nir_imm_int(&b->nb, -1);
 }
 
+static nir_ssa_def *
+handle_round(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode,
+             unsigned num_srcs, nir_ssa_def **srcs,
+             const struct glsl_type *dest_type)
+{
+   nir_ssa_def *src = srcs[0];
+   nir_builder *nb = &b->nb;
+   nir_ssa_def *half = nir_imm_floatN_t(nb, 0.5, src->bit_size);
+   nir_ssa_def *truncated = nir_ftrunc(nb, src);
+   nir_ssa_def *remainder = nir_fsub(nb, src, truncated);
+
+   return nir_bcsel(nb, nir_fge(nb, nir_fabs(nb, remainder), half),
+                    nir_fadd(nb, truncated, nir_fsign(nb, src)), truncated);
+}
+
 static nir_ssa_def *
 handle_shuffle(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, unsigned num_srcs,
                nir_ssa_def **srcs, const struct glsl_type *dest_type)
@@ -435,6 +450,9 @@ vtn_handle_opencl_instruction(struct vtn_builder *b, SpvOp ext_opcode,
    case OpenCLstd_Shuffle2:
       handle_instr(b, cl_opcode, w, count, handle_shuffle2);
       return true;
+   case OpenCLstd_Round:
+      handle_instr(b, cl_opcode, w, count, handle_round);
+      return true;
    case OpenCLstd_Printf:
       handle_instr(b, cl_opcode, w, count, handle_printf);
       return true;



More information about the mesa-commit mailing list