[gtk+/wip/otte/shader: 26/44] gsksl: Introduce GskSlFunctionType



commit ef663de73bbcf80bbafce50b7116bd0d1d4c25cb
Author: Benjamin Otte <otte redhat com>
Date:   Mon Oct 9 18:26:46 2017 +0200

    gsksl: Introduce GskSlFunctionType
    
    Represents a function, its argument types and whether they are
    in/out/const arguments.
    
    For now, this is just used to not duplicate function types in SPV files.

 gsk/gskslfunction.c            |   57 ++++++------
 gsk/gskslfunctiontype.c        |  209 ++++++++++++++++++++++++++++++++++++++++
 gsk/gskslfunctiontypeprivate.h |   52 ++++++++++
 gsk/gskslqualifierprivate.h    |   18 ----
 gsk/gsksltypesprivate.h        |   19 ++++
 gsk/gskspvwriter.c             |   22 ++++-
 gsk/gskspvwriterprivate.h      |    2 +
 gsk/meson.build                |    1 +
 8 files changed, 332 insertions(+), 48 deletions(-)
---
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index 249ba1d..2e0ab08 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -20,12 +20,13 @@
 
 #include "gskslfunctionprivate.h"
 
+#include "gskslfunctiontypeprivate.h"
 #include "gskslnativefunctionprivate.h"
-#include "gskslstatementprivate.h"
 #include "gskslpreprocessorprivate.h"
 #include "gskslprinterprivate.h"
 #include "gskslqualifierprivate.h"
 #include "gskslscopeprivate.h"
+#include "gskslstatementprivate.h"
 #include "gsksltokenizerprivate.h"
 #include "gsksltypeprivate.h"
 #include "gskslvalueprivate.h"
@@ -284,10 +285,9 @@ struct _GskSlFunctionDeclared {
   GskSlFunction parent;
 
   GskSlScope *scope;
-  GskSlType *return_type;
   char *name;
+  GskSlFunctionType *function_type;
   GskSlVariable **arguments;
-  gsize n_arguments;
   GskSlStatement *statement;
 };
 
@@ -297,13 +297,12 @@ gsk_sl_function_declared_free (GskSlFunction *function)
   GskSlFunctionDeclared *declared = (GskSlFunctionDeclared *) function;
   guint i;
 
-  for (i = 0; i < declared->n_arguments; i++)
+  for (i = 0; i < gsk_sl_function_type_get_n_arguments (declared->function_type); i++)
     gsk_sl_variable_unref (declared->arguments[i]);
   g_free (declared->arguments);
   if (declared->scope)
     gsk_sl_scope_unref (declared->scope);
-  if (declared->return_type)
-    gsk_sl_type_unref (declared->return_type);
+  gsk_sl_function_type_unref (declared->function_type);
   g_free (declared->name);
   if (declared->statement)
     gsk_sl_statement_unref (declared->statement);
@@ -316,7 +315,7 @@ gsk_sl_function_declared_get_return_type (const GskSlFunction *function)
 {
   const GskSlFunctionDeclared *declared = (const GskSlFunctionDeclared *) function;
 
-  return declared->return_type;
+  return gsk_sl_function_type_get_return_type (declared->function_type);
 }
 
 static const char *
@@ -332,7 +331,7 @@ gsk_sl_function_declared_get_n_arguments (const GskSlFunction *function)
 {
   const GskSlFunctionDeclared *declared = (const GskSlFunctionDeclared *) function;
 
-  return declared->n_arguments;
+  return gsk_sl_function_type_get_n_arguments (declared->function_type);
 }
 
 static GskSlType *
@@ -341,7 +340,7 @@ gsk_sl_function_declared_get_argument_type (const GskSlFunction *function,
 {
   const GskSlFunctionDeclared *declared = (const GskSlFunctionDeclared *) function;
 
-  return gsk_sl_variable_get_type (declared->arguments[i]);
+  return gsk_sl_function_type_get_argument_type (declared->function_type, i);
 }
 
 static GskSlValue *
@@ -359,12 +358,12 @@ gsk_sl_function_declared_print (const GskSlFunction *function,
   const GskSlFunctionDeclared *declared = (const GskSlFunctionDeclared *) function;
   guint i;
 
-  gsk_sl_printer_append (printer, gsk_sl_type_get_name (declared->return_type));
+  gsk_sl_printer_append (printer, gsk_sl_type_get_name (gsk_sl_function_type_get_return_type 
(declared->function_type)));
   gsk_sl_printer_newline (printer);
 
   gsk_sl_printer_append (printer, declared->name);
   gsk_sl_printer_append (printer, " (");
-  for (i = 0; i < declared->n_arguments; i++)
+  for (i = 0; i < gsk_sl_function_type_get_n_arguments (declared->function_type); i++)
     {
       if (i > 0)
         gsk_sl_printer_append (printer, ", ");
@@ -392,24 +391,21 @@ gsk_sl_function_declared_write_spv (const GskSlFunction *function,
                                     gpointer             initializer_data)
 {
   GskSlFunctionDeclared *declared = (GskSlFunctionDeclared *) function;
-  guint32 return_type_id, function_type_id, function_id;
-  guint32 argument_types[declared->n_arguments];
+  guint32 function_type_id, function_id;
+  GskSlType *return_type;
   gsize i;
 
   if (declared->statement == NULL)
     return 0;
 
+  return_type = gsk_sl_function_type_get_return_type (declared->function_type);
+
   /* declare type of function */
-  return_type_id = gsk_spv_writer_get_id_for_type (writer, declared->return_type);
-  for (i = 0; i < declared->n_arguments; i++)
-    {
-      argument_types[i] = gsk_spv_writer_get_id_for_type (writer, gsk_sl_variable_get_type 
(declared->arguments[i]));
-    }
-  function_type_id = gsk_spv_writer_type_function (writer, return_type_id, argument_types, 
declared->n_arguments);
+  function_type_id = gsk_spv_writer_get_id_for_function_type (writer, declared->function_type);
 
-  function_id = gsk_spv_writer_function (writer, declared->return_type, 0, function_type_id);
+  function_id = gsk_spv_writer_function (writer, return_type, 0, function_type_id);
   /* add function header */
-  for (i = 0; i < declared->n_arguments; i++)
+  for (i = 0; i < gsk_sl_function_type_get_n_arguments (declared->function_type); i++)
     {
       gsk_spv_writer_get_id_for_variable (writer, declared->arguments[i]);
     }
@@ -425,7 +421,7 @@ gsk_sl_function_declared_write_spv (const GskSlFunction *function,
 
   gsk_sl_statement_write_spv (declared->statement, writer);
 
-  if (gsk_sl_type_is_void (declared->return_type) &&
+  if (gsk_sl_type_is_void (return_type) &&
       gsk_sl_statement_get_jump (declared->statement) < GSK_SL_JUMP_RETURN)
     gsk_spv_writer_return (writer);
 
@@ -445,10 +441,10 @@ gsk_sl_function_declared_write_call_spv (GskSlFunction *function,
   guint32 result;
 
   result = gsk_spv_writer_function_call (writer,
-                                         declared->return_type,
+                                         gsk_sl_function_type_get_return_type (declared->function_type),
                                          gsk_spv_writer_get_id_for_function (writer, function),
                                          arguments,
-                                         declared->n_arguments);
+                                         gsk_sl_function_type_get_n_arguments (declared->function_type));
 
   return result;
 }
@@ -509,7 +505,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
   const GskSlToken *token;
 
   function = gsk_sl_function_new (GskSlFunctionDeclared, &GSK_SL_FUNCTION_DECLARED);
-  function->return_type = gsk_sl_type_ref (return_type);
+  function->function_type = gsk_sl_function_type_new (return_type);
   function->name = g_strdup (name);
 
   token = gsk_sl_preprocessor_get (preproc);
@@ -520,7 +516,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
     }
   gsk_sl_preprocessor_consume (preproc, (GskSlStatement *) function);
 
-  function->scope = gsk_sl_scope_new (scope, function->return_type);
+  function->scope = gsk_sl_scope_new (scope, return_type);
 
   token = gsk_sl_preprocessor_get (preproc);
   if (!gsk_sl_token_is (token, GSK_SL_TOKEN_RIGHT_PAREN))
@@ -544,7 +540,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
 
               if (gsk_sl_scope_lookup_variable (function->scope, token->str))
                 {
-                  for (i = 0; i < function->n_arguments; i++)
+                  for (i = 0; i < arguments->len; i++)
                     {
                       if (g_str_equal (gsk_sl_variable_get_name (g_ptr_array_index (arguments, i)), 
token->str))
                         {
@@ -557,6 +553,9 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
                 }
 
               variable = gsk_sl_variable_new (token->str, type, &qualifier, NULL);
+              function->function_type = gsk_sl_function_type_add_argument (function->function_type,
+                                                                           qualifier.storage,
+                                                                           type);
               g_ptr_array_add (arguments, variable);
               
               gsk_sl_scope_add_variable (function->scope, variable);
@@ -576,7 +575,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
           gsk_sl_preprocessor_consume (preproc, (GskSlStatement *) function);
         }
 
-      function->n_arguments = arguments->len;
+      g_assert (gsk_sl_function_type_get_n_arguments (function->function_type) == arguments->len);
       function->arguments = (GskSlVariable **) g_ptr_array_free (arguments, FALSE);
     }
 
@@ -596,7 +595,7 @@ gsk_sl_function_new_parse (GskSlScope        *scope,
 
   function->statement = gsk_sl_statement_parse_compound (function->scope, preproc, FALSE);
 
-  if (!gsk_sl_type_is_void (function->return_type) &&
+  if (!gsk_sl_type_is_void (return_type) &&
       gsk_sl_statement_get_jump (function->statement) < GSK_SL_JUMP_RETURN)
     {
       gsk_sl_preprocessor_error (preproc, SYNTAX, "Function does not return a value.");
diff --git a/gsk/gskslfunctiontype.c b/gsk/gskslfunctiontype.c
new file mode 100644
index 0000000..3b59241
--- /dev/null
+++ b/gsk/gskslfunctiontype.c
@@ -0,0 +1,209 @@
+/* GTK - The GIMP Toolkit
+ *   
+ * Copyright © 2017 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gskslfunctiontypeprivate.h"
+
+#include "gsksltypeprivate.h"
+#include "gskspvwriterprivate.h"
+
+typedef struct _GskSlArgument GskSlArgument;
+
+struct _GskSlArgument
+{
+  GskSlStorage storage;
+  GskSlType *type;
+};
+
+struct _GskSlFunctionType
+{
+  int ref_count;
+
+  GskSlType *return_type;
+  gsize n_arguments;
+  GskSlArgument arguments[0];
+};
+
+static GskSlFunctionType *
+gsk_sl_function_type_alloc (gsize n_arguments)
+{
+  GskSlFunctionType *function_type;
+
+  function_type = g_slice_alloc0 (sizeof (GskSlFunctionType) + n_arguments * sizeof (GskSlArgument));
+
+  function_type->ref_count = 1;
+  function_type->n_arguments = n_arguments;
+
+  return function_type;
+}
+
+GskSlFunctionType *
+gsk_sl_function_type_new (GskSlType *return_type)
+{
+  GskSlFunctionType *function_type;
+
+  function_type = gsk_sl_function_type_alloc (0);
+  function_type->return_type = gsk_sl_type_ref (return_type);
+
+  return function_type;
+}
+
+GskSlFunctionType *
+gsk_sl_function_type_add_argument (GskSlFunctionType *function_type,
+                                   GskSlStorage       argument_storage,
+                                   GskSlType         *argument_type)
+{
+  GskSlFunctionType *result_type;
+  gsize i;
+
+  g_assert (argument_storage >= GSK_SL_STORAGE_PARAMETER_IN && argument_storage <= 
GSK_SL_STORAGE_PARAMETER_CONST);
+
+  result_type = gsk_sl_function_type_alloc (function_type->n_arguments + 1);
+  result_type->return_type = gsk_sl_type_ref (function_type->return_type);
+
+  for (i = 0; i < function_type->n_arguments; i++)
+    {
+      result_type->arguments[i].type = gsk_sl_type_ref (function_type->arguments[i].type);
+      result_type->arguments[i].storage = function_type->arguments[i].storage;
+    }
+
+  result_type->arguments[i].type = gsk_sl_type_ref (argument_type);
+  result_type->arguments[i].storage = argument_storage;
+
+  gsk_sl_function_type_unref (function_type);
+
+  return result_type;
+}
+
+GskSlFunctionType *
+gsk_sl_function_type_ref (GskSlFunctionType *function_type)
+{
+  g_return_val_if_fail (function_type != NULL, NULL);
+
+  function_type->ref_count += 1;
+
+  return function_type;
+}
+
+void
+gsk_sl_function_type_unref (GskSlFunctionType *function_type)
+{
+  gsize i;
+
+  if (function_type == NULL)
+    return;
+
+  function_type->ref_count -= 1;
+  if (function_type->ref_count > 0)
+    return;
+
+  for (i = 0; i < function_type->n_arguments; i++)
+    {
+      gsk_sl_type_unref (function_type->arguments[i].type);
+    }
+  gsk_sl_type_unref (function_type->return_type);
+
+  g_slice_free1 (sizeof (GskSlFunctionType) + function_type->n_arguments * sizeof (GskSlArgument), 
function_type);
+}
+
+GskSlType *
+gsk_sl_function_type_get_return_type (const GskSlFunctionType *function_type)
+{
+  return function_type->return_type;
+}
+
+gsize
+gsk_sl_function_type_get_n_arguments (const GskSlFunctionType *function_type)
+{
+  return function_type->n_arguments;
+}
+
+GskSlType *
+gsk_sl_function_type_get_argument_type (const GskSlFunctionType *function_type,
+                                        gsize                    i)
+{
+  return function_type->arguments[i].type;
+}
+
+GskSlStorage
+gsk_sl_function_type_get_argument_storage (const GskSlFunctionType *function_type,
+                                           gsize                    i)
+{
+  return function_type->arguments[i].storage;
+}
+
+guint32
+gsk_sl_function_type_write_spv (const GskSlFunctionType *function_type,
+                                GskSpvWriter            *writer)
+{
+  guint32 argument_types[function_type->n_arguments], return_type_id;
+  gsize i;
+
+  return_type_id = gsk_spv_writer_get_id_for_type (writer, function_type->return_type);
+  for (i = 0; i < function_type->n_arguments; i++)
+    {
+      argument_types[i] = gsk_spv_writer_get_id_for_type (writer, function_type->arguments[i].type);
+    }
+
+  return gsk_spv_writer_type_function (writer, return_type_id, argument_types, function_type->n_arguments);
+}
+
+gboolean
+gsk_sl_function_type_equal (gconstpointer a,
+                            gconstpointer b)
+{
+  const GskSlFunctionType *function_type_a = a;
+  const GskSlFunctionType *function_type_b = b;
+  gsize i;
+
+  if (function_type_a->n_arguments != function_type_b->n_arguments)
+    return FALSE;
+
+  if (!gsk_sl_type_equal (function_type_a->return_type, function_type_b->return_type))
+    return FALSE;
+
+  for (i = 0; i < function_type_a->n_arguments; i++)
+    {
+      if (function_type_a->arguments[i].storage != function_type_b->arguments[i].storage ||
+          !gsk_sl_type_equal (function_type_a->arguments[i].type, function_type_b->arguments[i].type))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
+guint
+gsk_sl_function_type_hash (gconstpointer value)
+{
+  const GskSlFunctionType *function_type = value;
+  guint hash;
+  gsize i;
+
+  hash = gsk_sl_type_hash (function_type->return_type);
+
+  for (i = 0; i < function_type->n_arguments; i++)
+    {
+      hash <<= 5;
+      hash ^= gsk_sl_type_hash (function_type->arguments[i].type);
+      hash ^= function_type->arguments[i].storage;
+    }
+
+  return hash;
+}
+
diff --git a/gsk/gskslfunctiontypeprivate.h b/gsk/gskslfunctiontypeprivate.h
new file mode 100644
index 0000000..4355d76
--- /dev/null
+++ b/gsk/gskslfunctiontypeprivate.h
@@ -0,0 +1,52 @@
+/* GTK - The GIMP Toolkit
+ *
+ * Copyright © 2017 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GSK_SL_FUNCTION_TYPE_PRIVATE_H__
+#define __GSK_SL_FUNCTION_TYPE_PRIVATE_H__
+
+#include <glib.h>
+
+#include "gsksltypesprivate.h"
+
+G_BEGIN_DECLS
+
+GskSlFunctionType *     gsk_sl_function_type_new                (GskSlType              *return_type);
+GskSlFunctionType *     gsk_sl_function_type_add_argument       (GskSlFunctionType      *function_type,
+                                                                 GskSlStorage            argument_storage,
+                                                                 GskSlType              *argument_type);
+
+GskSlFunctionType *     gsk_sl_function_type_ref                (GskSlFunctionType      *function_type);
+void                    gsk_sl_function_type_unref              (GskSlFunctionType      *function_type);
+
+GskSlType *             gsk_sl_function_type_get_return_type    (const GskSlFunctionType*function_type);
+gsize                   gsk_sl_function_type_get_n_arguments    (const GskSlFunctionType*function_type);
+GskSlType *             gsk_sl_function_type_get_argument_type  (const GskSlFunctionType*function_type,
+                                                                 gsize                   i);
+GskSlStorage            gsk_sl_function_type_get_argument_storage (const GskSlFunctionType*function_type,
+                                                                 gsize                   i);
+
+guint32                 gsk_sl_function_type_write_spv          (const GskSlFunctionType*function_type,
+                                                                 GskSpvWriter           *writer);
+
+gboolean                gsk_sl_function_type_equal              (gconstpointer           a,
+                                                                 gconstpointer           b);
+guint                   gsk_sl_function_type_hash               (gconstpointer           value);
+
+G_END_DECLS
+
+#endif /* __GSK_SL_FUNCTION_TYPE_PRIVATE_H__ */
diff --git a/gsk/gskslqualifierprivate.h b/gsk/gskslqualifierprivate.h
index 8dd3596..b44c1ae 100644
--- a/gsk/gskslqualifierprivate.h
+++ b/gsk/gskslqualifierprivate.h
@@ -33,24 +33,6 @@ typedef enum {
   GSK_SL_QUALIFIER_LOCAL
 } GskSlQualifierLocation;
 
-typedef enum {
-  GSK_SL_STORAGE_DEFAULT,
-
-  GSK_SL_STORAGE_GLOBAL,
-  GSK_SL_STORAGE_GLOBAL_CONST,
-  GSK_SL_STORAGE_GLOBAL_IN,
-  GSK_SL_STORAGE_GLOBAL_OUT,
-  GSK_SL_STORAGE_GLOBAL_UNIFORM,
-
-  GSK_SL_STORAGE_LOCAL,
-  GSK_SL_STORAGE_LOCAL_CONST,
-
-  GSK_SL_STORAGE_PARAMETER_IN,
-  GSK_SL_STORAGE_PARAMETER_OUT,
-  GSK_SL_STORAGE_PARAMETER_INOUT,
-  GSK_SL_STORAGE_PARAMETER_CONST
-} GskSlStorage;
-
 struct _GskSlQualifier
 {
   GskSlStorage storage;
diff --git a/gsk/gsksltypesprivate.h b/gsk/gsksltypesprivate.h
index 478dc27..9c24243 100644
--- a/gsk/gsksltypesprivate.h
+++ b/gsk/gsksltypesprivate.h
@@ -24,6 +24,7 @@
 typedef struct _GskSlExpression         GskSlExpression;
 typedef struct _GskSlFunction           GskSlFunction;
 typedef struct _GskSlFunctionMatcher    GskSlFunctionMatcher;
+typedef struct _GskSlFunctionType       GskSlFunctionType;
 typedef struct _GskSlNativeFunction     GskSlNativeFunction;
 typedef struct _GskSlPreprocessor       GskSlPreprocessor;
 typedef struct _GskSlPointerType        GskSlPointerType;
@@ -91,4 +92,22 @@ typedef enum {
   GSK_SL_BUILTIN_DMAT4
 } GskSlBuiltinType;
 
+typedef enum {
+  GSK_SL_STORAGE_DEFAULT,
+
+  GSK_SL_STORAGE_GLOBAL,
+  GSK_SL_STORAGE_GLOBAL_CONST,
+  GSK_SL_STORAGE_GLOBAL_IN,
+  GSK_SL_STORAGE_GLOBAL_OUT,
+  GSK_SL_STORAGE_GLOBAL_UNIFORM,
+
+  GSK_SL_STORAGE_LOCAL,
+  GSK_SL_STORAGE_LOCAL_CONST,
+
+  GSK_SL_STORAGE_PARAMETER_IN,
+  GSK_SL_STORAGE_PARAMETER_OUT,
+  GSK_SL_STORAGE_PARAMETER_INOUT,
+  GSK_SL_STORAGE_PARAMETER_CONST
+} GskSlStorage;
+
 #endif /* __GSK_SL_TYPES_H__ */
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index 117af01..b971d64 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -21,6 +21,7 @@
 #include "gskspvwriterprivate.h"
 
 #include "gskslfunctionprivate.h"
+#include "gskslfunctiontypeprivate.h"
 #include "gskslqualifierprivate.h"
 #include "gsksltypeprivate.h"
 #include "gskslvalueprivate.h"
@@ -55,6 +56,7 @@ struct _GskSpvWriter
   GHashTable *values;
   GHashTable *variables;
   GHashTable *functions;
+  GHashTable *function_types;
 };
 
 static GskSpvCodeBlock *
@@ -139,6 +141,8 @@ gsk_spv_writer_new (void)
                                              (GDestroyNotify) gsk_sl_variable_unref, NULL);
   writer->functions = g_hash_table_new_full (g_direct_hash, g_direct_equal,
                                              (GDestroyNotify) gsk_sl_function_unref, NULL);
+  writer->function_types = g_hash_table_new_full (gsk_sl_function_type_hash, gsk_sl_function_type_equal,
+                                                  (GDestroyNotify) gsk_sl_function_type_unref, NULL);
 
   return writer;
 }
@@ -177,6 +181,7 @@ gsk_spv_writer_unref (GskSpvWriter *writer)
   g_hash_table_destroy (writer->values);
   g_hash_table_destroy (writer->variables);
   g_hash_table_destroy (writer->functions);
+  g_hash_table_destroy (writer->function_types);
 
   g_slice_free (GskSpvWriter, writer);
 }
@@ -258,7 +263,7 @@ gsk_spv_writer_clear (GskSpvWriter *writer)
   g_hash_table_remove_all (writer->values);
   g_hash_table_remove_all (writer->variables);
   g_hash_table_remove_all (writer->functions);
-
+  g_hash_table_remove_all (writer->function_types);
 }
 
 GBytes *
@@ -439,6 +444,21 @@ gsk_spv_writer_get_id_for_function (GskSpvWriter  *writer,
 }
 
 guint32
+gsk_spv_writer_get_id_for_function_type (GskSpvWriter      *writer,
+                                         GskSlFunctionType *function_type)
+{
+  guint32 result;
+
+  result = GPOINTER_TO_UINT (g_hash_table_lookup (writer->function_types, function_type));
+  if (result != 0)
+    return result;
+  
+  result = gsk_sl_function_type_write_spv (function_type, writer);
+  g_hash_table_insert (writer->function_types, gsk_sl_function_type_ref (function_type), GUINT_TO_POINTER 
(result));
+  return result;
+}
+
+guint32
 gsk_spv_writer_make_id (GskSpvWriter *writer)
 {
   writer->last_id++;
diff --git a/gsk/gskspvwriterprivate.h b/gsk/gskspvwriterprivate.h
index 48b4eb9..58b276d 100644
--- a/gsk/gskspvwriterprivate.h
+++ b/gsk/gskspvwriterprivate.h
@@ -73,6 +73,8 @@ guint32                 gsk_spv_writer_get_id_for_variable      (GskSpvWriter
                                                                  GskSlVariable          *variable);
 guint32                 gsk_spv_writer_get_id_for_function      (GskSpvWriter           *writer,
                                                                  GskSlFunction          *function);
+guint32                 gsk_spv_writer_get_id_for_function_type (GskSpvWriter           *writer,
+                                                                 GskSlFunctionType      *function_type);
 
 guint32                 gsk_spv_writer_make_id                  (GskSpvWriter           *writer);
 GArray *                gsk_spv_writer_get_bytes                (GskSpvWriter           *writer,
diff --git a/gsk/meson.build b/gsk/meson.build
index 07378c3..e7023c2 100644
--- a/gsk/meson.build
+++ b/gsk/meson.build
@@ -39,6 +39,7 @@ gsk_private_sources = files([
   'gsksldefine.c',
   'gskslexpression.c',
   'gskslfunction.c',
+  'gskslfunctiontype.c',
   'gskslnativefunction.c',
   'gskslpreprocessor.c',
   'gskslprinter.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]