[gtk+/wip/otte/shader: 48/48] gskslfunction: Add gsk_sl_function_get_constant()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 48/48] gskslfunction: Add gsk_sl_function_get_constant()
- Date: Tue, 3 Oct 2017 02:16:36 +0000 (UTC)
commit c936e39c5aa2e1e5d98b29e32e9b51f26f84a6d0
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 | 25 +++++++++++++++++++++++--
gsk/gskslfunction.c | 41 +++++++++++++++++++++++++++++++++++++++++
gsk/gskslfunctionprivate.h | 3 +++
3 files changed, 67 insertions(+), 2 deletions(-)
---
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index e75405d..6fe68c0 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -993,8 +993,29 @@ 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;
+ guint i;
+
+ for (i = 0; i < function_call->n_arguments; i++)
+ {
+ values[i] = gsk_sl_expression_get_constant (function_call->arguments[i]);
+ if (values[i] == NULL)
+ {
+ guint j;
+ for (j = 0; j < i; j++)
+ gsk_sl_value_free (values[j]);
+ return NULL;
+ }
+ }
+
+ 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 11e07eb..d38bc11 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]