[gtk+/wip/otte/shader: 18/98] gskslfunction: Add gsk_sl_function_get_constant()



commit 4350cdc71ad4a3b4971371f85fd3a27707671503
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 3 02:43:53 2017 +0200

    gskslfunction: Add gsk_sl_function_get_constant()
    
    Also, call it from the function call expression.
    
    It's completely unimplemented so far, so it's not that useful.

 gsk/gskslexpression.c      |   27 +++++++++++++++++++++++++--
 gsk/gskslfunction.c        |   41 +++++++++++++++++++++++++++++++++++++++++
 gsk/gskslfunctionprivate.h |    3 +++
 3 files changed, 69 insertions(+), 2 deletions(-)
---
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index 4c54b66..3dcea1c 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -995,8 +995,31 @@ gsk_sl_expression_function_call_get_return_type (const GskSlExpression *expressi
 static GskSlValue *
 gsk_sl_expression_function_call_get_constant (const GskSlExpression *expression)
 {
-  /* FIXME: some functions are constant */
-  return NULL;
+  const GskSlExpressionFunctionCall *function_call = (const GskSlExpressionFunctionCall *) expression;
+  GskSlValue *values[function_call->n_arguments];
+  GskSlValue *result, *tmp;
+  guint i;
+
+  for (i = 0; i < function_call->n_arguments; i++)
+    {
+      tmp = gsk_sl_expression_get_constant (function_call->arguments[i]);
+      if (tmp == NULL)
+        {
+          guint j;
+          for (j = 0; j < i; j++)
+            gsk_sl_value_free (values[j]);
+          return NULL;
+        }
+      values[i] = gsk_sl_value_new_convert (tmp, gsk_sl_function_get_argument_type (function_call->function, 
i));
+      gsk_sl_value_free (tmp);
+    }
+
+  result = gsk_sl_function_get_constant (function_call->function, values, function_call->n_arguments);
+
+  for (i = 0; i < function_call->n_arguments; i++)
+    gsk_sl_value_free (values[i]);
+
+  return result;
 }
 
 static guint32
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index 2f98e35..9fd5ca2 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -29,6 +29,7 @@
 #include "gskslscopeprivate.h"
 #include "gsksltokenizerprivate.h"
 #include "gsksltypeprivate.h"
+#include "gskslvalueprivate.h"
 #include "gskslvariableprivate.h"
 #include "gskspvwriterprivate.h"
 
@@ -49,6 +50,9 @@ struct _GskSlFunctionClass {
   gsize                 (* get_n_arguments)                     (const GskSlFunction    *function);
   GskSlType *           (* get_argument_type)                   (const GskSlFunction    *function,
                                                                  gsize                   i);
+  GskSlValue *          (* get_constant)                        (const GskSlFunction    *function,
+                                                                 GskSlValue            **values,
+                                                                 gsize                   n_values);
   void                  (* print)                               (const GskSlFunction    *function,
                                                                  GskSlPrinter           *printer);
   guint32               (* write_spv)                           (const GskSlFunction    *function,
@@ -123,6 +127,14 @@ gsk_sl_function_constructor_get_argument_type (const GskSlFunction *function,
   return gsk_sl_type_get_member_type (constructor->type, i);
 }
 
+static GskSlValue *
+gsk_sl_function_constructor_get_constant (const GskSlFunction  *function,
+                                          GskSlValue          **values,
+                                          gsize                 n_values)
+{
+  return NULL;
+}
+
 static void
 gsk_sl_function_constructor_print (const GskSlFunction *function,
                                    GskSlPrinter        *printer)
@@ -142,6 +154,7 @@ static const GskSlFunctionClass GSK_SL_FUNCTION_CONSTRUCTOR = {
   gsk_sl_function_constructor_get_name,
   gsk_sl_function_constructor_get_n_arguments,
   gsk_sl_function_constructor_get_argument_type,
+  gsk_sl_function_constructor_get_constant,
   gsk_sl_function_constructor_print,
   gsk_sl_function_constructor_write_spv,
 };
@@ -196,6 +209,15 @@ gsk_sl_function_native_get_argument_type (const GskSlFunction *function,
 
   return gsk_sl_type_get_builtin (native->native->argument_types[i]);
 }
+
+static GskSlValue *
+gsk_sl_function_native_get_constant (const GskSlFunction  *function,
+                                     GskSlValue          **values,
+                                     gsize                 n_values)
+{
+  return NULL;
+}
+
 static void
 gsk_sl_function_native_print (const GskSlFunction *function,
                               GskSlPrinter        *printer)
@@ -215,6 +237,7 @@ static const GskSlFunctionClass GSK_SL_FUNCTION_NATIVE = {
   gsk_sl_function_native_get_name,
   gsk_sl_function_native_get_n_arguments,
   gsk_sl_function_native_get_argument_type,
+  gsk_sl_function_native_get_constant,
   gsk_sl_function_native_print,
   gsk_sl_function_native_write_spv
 };
@@ -286,6 +309,15 @@ gsk_sl_function_declared_get_argument_type (const GskSlFunction *function,
 
   return gsk_sl_pointer_type_get_type (gsk_sl_variable_get_type (declared->arguments[i]));
 }
+
+static GskSlValue *
+gsk_sl_function_declared_get_constant (const GskSlFunction  *function,
+                                       GskSlValue          **values,
+                                       gsize                 n_values)
+{
+  return NULL;
+}
+
 static void
 gsk_sl_function_declared_print (const GskSlFunction *function,
                                 GskSlPrinter        *printer)
@@ -380,6 +412,7 @@ static const GskSlFunctionClass GSK_SL_FUNCTION_DECLARED = {
   gsk_sl_function_declared_get_name,
   gsk_sl_function_declared_get_n_arguments,
   gsk_sl_function_declared_get_argument_type,
+  gsk_sl_function_declared_get_constant,
   gsk_sl_function_declared_print,
   gsk_sl_function_declared_write_spv,
 };
@@ -575,6 +608,14 @@ gsk_sl_function_get_argument_type (const GskSlFunction *function,
   return function->class->get_argument_type (function, i);
 }
 
+GskSlValue *
+gsk_sl_function_get_constant (const GskSlFunction  *function,
+                              GskSlValue          **values,
+                              gsize                 n_values)
+{
+  return function->class->get_constant (function, values, n_values);
+}
+
 void
 gsk_sl_function_print (const GskSlFunction *function,
                        GskSlPrinter        *printer)
diff --git a/gsk/gskslfunctionprivate.h b/gsk/gskslfunctionprivate.h
index 321d195..5ca1933 100644
--- a/gsk/gskslfunctionprivate.h
+++ b/gsk/gskslfunctionprivate.h
@@ -43,6 +43,9 @@ GskSlType *             gsk_sl_function_get_return_type         (const GskSlFunc
 gsize                   gsk_sl_function_get_n_arguments         (const GskSlFunction    *function);
 GskSlType *             gsk_sl_function_get_argument_type       (const GskSlFunction    *function,
                                                                  gsize                   i);
+GskSlValue *            gsk_sl_function_get_constant            (const GskSlFunction    *function,
+                                                                 GskSlValue            **values,
+                                                                 gsize                   n_values);
 guint32                 gsk_sl_function_write_spv               (const GskSlFunction    *function,
                                                                  GskSpvWriter           *writer);
 


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