Mesa (master): spirv: add vtn_create_builder

Alejandro Pinheiro apinheiro at kemper.freedesktop.org
Fri Mar 30 10:30:46 UTC 2018


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

Author: Alejandro Piñeiro <apinheiro at igalia.com>
Date:   Thu Jan 18 12:24:38 2018 +0100

spirv: add vtn_create_builder

Refactored from spirv_to_nir, in order to be reused later.

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

v2: renamed method (from vtn_builder_create), add explanatory comment
    (Timothy)

---

 src/compiler/spirv/spirv_to_nir.c | 51 ++++++++++++++++++++++++++-------------
 src/compiler/spirv/vtn_private.h  |  4 +++
 2 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 4297622979..d895d82055 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3972,14 +3972,12 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
    return true;
 }
 
-nir_function *
-spirv_to_nir(const uint32_t *words, size_t word_count,
-             struct nir_spirv_specialization *spec, unsigned num_spec,
-             gl_shader_stage stage, const char *entry_point_name,
-             const struct spirv_to_nir_options *options,
-             const nir_shader_compiler_options *nir_options)
+struct vtn_builder*
+vtn_create_builder(const uint32_t *words, size_t word_count,
+                   gl_shader_stage stage, const char *entry_point_name,
+                   const struct spirv_to_nir_options *options)
 {
-   /* Initialize the stn_builder object */
+   /* Initialize the vtn_builder object */
    struct vtn_builder *b = rzalloc(NULL, struct vtn_builder);
    b->spirv = words;
    b->spirv_word_count = word_count;
@@ -3991,14 +3989,6 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
    b->entry_point_name = entry_point_name;
    b->options = options;
 
-   /* See also _vtn_fail() */
-   if (setjmp(b->fail_jump)) {
-      ralloc_free(b);
-      return NULL;
-   }
-
-   const uint32_t *word_end = words + word_count;
-
    /* Handle the SPIR-V header (first 4 dwords)  */
    vtn_assert(word_count > 5);
 
@@ -4008,11 +3998,38 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
    unsigned value_id_bound = words[3];
    vtn_assert(words[4] == 0);
 
-   words+= 5;
-
    b->value_id_bound = value_id_bound;
    b->values = rzalloc_array(b, struct vtn_value, value_id_bound);
 
+   return b;
+}
+
+nir_function *
+spirv_to_nir(const uint32_t *words, size_t word_count,
+             struct nir_spirv_specialization *spec, unsigned num_spec,
+             gl_shader_stage stage, const char *entry_point_name,
+             const struct spirv_to_nir_options *options,
+             const nir_shader_compiler_options *nir_options)
+
+{
+   const uint32_t *word_end = words + word_count;
+
+   struct vtn_builder *b = vtn_create_builder(words, word_count,
+                                              stage, entry_point_name,
+                                              options);
+
+   if (b == NULL)
+      return NULL;
+
+   /* See also _vtn_fail() */
+   if (setjmp(b->fail_jump)) {
+      ralloc_free(b);
+      return NULL;
+   }
+
+   /* Skip the SPIR-V header, handled at vtn_create_builder */
+   words+= 5;
+
    /* Handle all the preamble instructions */
    words = vtn_foreach_instruction(b, words, word_end,
                                    vtn_handle_preamble_instruction);
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index bbc63ad20d..47d06f0f91 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -719,6 +719,10 @@ void vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
 bool vtn_handle_glsl450_instruction(struct vtn_builder *b, uint32_t ext_opcode,
                                     const uint32_t *words, unsigned count);
 
+struct vtn_builder* vtn_create_builder(const uint32_t *words, size_t word_count,
+                                       gl_shader_stage stage, const char *entry_point_name,
+                                       const struct spirv_to_nir_options *options);
+
 static inline uint32_t
 vtn_align_u32(uint32_t v, uint32_t a)
 {




More information about the mesa-commit mailing list