Mesa (master): spirv: Move the emit a 'return value' store logic into own function

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 14 20:55:37 UTC 2020


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

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Thu Mar 26 13:37:29 2020 +0100

spirv: Move the emit a 'return value' store logic into own function

Right now, only the structured CF path emits 'return value' stores when
an SpvOpReturnValue opcode is found. Move the emit 'return value' logic
in a separate function so we can use it from the unstructured path as well.

v2 (Karol): rephrased and removed unstructured changes

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

---

 src/compiler/spirv/vtn_cfg.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 6d4e47b3c81..1d54d7b8359 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -995,6 +995,23 @@ vtn_selection_control(struct vtn_builder *b, struct vtn_if *vtn_if)
       vtn_fail("Invalid selection control");
 }
 
+static void
+vtn_emit_ret_store(struct vtn_builder *b, struct vtn_block *block)
+{
+   if ((*block->branch & SpvOpCodeMask) != SpvOpReturnValue)
+      return;
+
+   vtn_fail_if(b->func->type->return_type->base_type == vtn_base_type_void,
+               "Return with a value from a function returning void");
+   struct vtn_ssa_value *src = vtn_ssa_value(b, block->branch[1]);
+   const struct glsl_type *ret_type =
+      glsl_get_bare_type(b->func->type->return_type->type);
+   nir_deref_instr *ret_deref =
+      nir_build_deref_cast(&b->nb, nir_load_param(&b->nb, 0),
+                           nir_var_function_temp, ret_type, 0);
+   vtn_local_store(b, src, ret_deref, 0);
+}
+
 static void
 vtn_emit_cf_list_structured(struct vtn_builder *b, struct list_head *cf_list,
                             nir_variable *switch_fall_var,
@@ -1019,18 +1036,7 @@ vtn_emit_cf_list_structured(struct vtn_builder *b, struct list_head *cf_list,
                                                      nir_intrinsic_nop);
          nir_builder_instr_insert(&b->nb, &block->end_nop->instr);
 
-         if ((*block->branch & SpvOpCodeMask) == SpvOpReturnValue) {
-            vtn_fail_if(b->func->type->return_type->base_type ==
-                        vtn_base_type_void,
-                        "Return with a value from a function returning void");
-            struct vtn_ssa_value *src = vtn_ssa_value(b, block->branch[1]);
-            const struct glsl_type *ret_type =
-               glsl_get_bare_type(b->func->type->return_type->type);
-            nir_deref_instr *ret_deref =
-               nir_build_deref_cast(&b->nb, nir_load_param(&b->nb, 0),
-                                    nir_var_function_temp, ret_type, 0);
-            vtn_local_store(b, src, ret_deref, 0);
-         }
+         vtn_emit_ret_store(b, block);
 
          if (block->branch_type != vtn_branch_type_none) {
             vtn_emit_branch(b, block->branch_type,



More information about the mesa-commit mailing list