[gtk+/wip/otte/shader: 161/175] gskslfunction: Actually write arguments to SPV
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 161/175] gskslfunction: Actually write arguments to SPV
- Date: Sun, 8 Oct 2017 03:44:18 +0000 (UTC)
commit fd7e01fdb0d2e49e86f3130856f26e531292594e
Author: Benjamin Otte <otte redhat com>
Date: Wed Oct 4 23:54:53 2017 +0200
gskslfunction: Actually write arguments to SPV
This includes code in the variable path to write parameter variables out
as parameters instead of regular global/local variables.
gsk/gskslfunction.c | 9 +++++++-
gsk/gskslqualifier.c | 29 ++++++++++++++++++++++++++
gsk/gskslqualifierprivate.h | 1 +
gsk/gskslvariable.c | 47 +++++++++++++++++++++++++++++-------------
4 files changed, 70 insertions(+), 16 deletions(-)
---
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index d38bc11..bdd142c 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -357,6 +357,7 @@ gsk_sl_function_declared_write_spv (const GskSlFunction *function,
{
GskSlFunctionDeclared *declared = (GskSlFunctionDeclared *) function;
guint32 return_type_id, function_type_id, function_id, label_id;
+ gsize i;
if (declared->statement == NULL)
return 0;
@@ -373,7 +374,6 @@ gsk_sl_function_declared_write_spv (const GskSlFunction *function,
/* add debug info */
/* FIXME */
- /* add function body */
function_id = gsk_spv_writer_next_id (writer);
gsk_spv_writer_add (writer,
GSK_SPV_WRITER_SECTION_CODE,
@@ -382,6 +382,13 @@ gsk_sl_function_declared_write_spv (const GskSlFunction *function,
function_id,
0,
function_type_id });
+ /* add function header */
+ for (i = 0; i < declared->n_arguments; i++)
+ {
+ gsk_spv_writer_get_id_for_variable (writer, declared->arguments[i]);
+ }
+
+ /* add function body */
label_id = gsk_spv_writer_next_id (writer);
gsk_spv_writer_add (writer,
GSK_SPV_WRITER_SECTION_CODE,
diff --git a/gsk/gskslqualifier.c b/gsk/gskslqualifier.c
index 98fd843..265742a 100644
--- a/gsk/gskslqualifier.c
+++ b/gsk/gskslqualifier.c
@@ -513,6 +513,35 @@ gsk_sl_qualifier_is_constant (const GskSlQualifier *qualifier)
}
}
+GskSlQualifierLocation
+gsk_sl_qualifier_get_location (const GskSlQualifier *qualifier)
+{
+ switch (qualifier->storage)
+ {
+ case GSK_SL_STORAGE_DEFAULT:
+ default:
+ g_assert_not_reached ();
+ return GSK_SL_QUALIFIER_GLOBAL;
+
+ case GSK_SL_STORAGE_GLOBAL_UNIFORM:
+ case GSK_SL_STORAGE_GLOBAL:
+ case GSK_SL_STORAGE_GLOBAL_IN:
+ case GSK_SL_STORAGE_GLOBAL_OUT:
+ case GSK_SL_STORAGE_GLOBAL_CONST:
+ return GSK_SL_QUALIFIER_GLOBAL;
+
+ case GSK_SL_STORAGE_LOCAL:
+ case GSK_SL_STORAGE_LOCAL_CONST:
+ return GSK_SL_QUALIFIER_LOCAL;
+
+ case GSK_SL_STORAGE_PARAMETER_IN:
+ case GSK_SL_STORAGE_PARAMETER_OUT:
+ case GSK_SL_STORAGE_PARAMETER_INOUT:
+ case GSK_SL_STORAGE_PARAMETER_CONST:
+ return GSK_SL_QUALIFIER_PARAMETER;
+ }
+}
+
GskSpvStorageClass
gsk_sl_qualifier_get_storage_class (const GskSlQualifier *qualifier)
{
diff --git a/gsk/gskslqualifierprivate.h b/gsk/gskslqualifierprivate.h
index f432a2d..8dd3596 100644
--- a/gsk/gskslqualifierprivate.h
+++ b/gsk/gskslqualifierprivate.h
@@ -81,6 +81,7 @@ gboolean gsk_sl_qualifier_print (const G
GskSlPrinter
*printer);
gboolean gsk_sl_qualifier_is_constant (const GskSlQualifier
*qualifier);
+GskSlQualifierLocation gsk_sl_qualifier_get_location (const GskSlQualifier
*qualifier);
GskSpvStorageClass gsk_sl_qualifier_get_storage_class (const GskSlQualifier
*qualifier);
G_END_DECLS
diff --git a/gsk/gskslvariable.c b/gsk/gskslvariable.c
index 439aa80..b223650 100644
--- a/gsk/gskslvariable.c
+++ b/gsk/gskslvariable.c
@@ -145,21 +145,38 @@ guint32
gsk_sl_variable_write_spv (const GskSlVariable *variable,
GskSpvWriter *writer)
{
- guint32 pointer_type_id, variable_id, value_id;
+ if (gsk_sl_qualifier_get_location (gsk_sl_pointer_type_get_qualifier (variable->type)) ==
GSK_SL_QUALIFIER_PARAMETER)
+ {
+ guint32 type_id, variable_id;
- pointer_type_id = gsk_spv_writer_get_id_for_pointer_type (writer, variable->type);
- variable_id = gsk_spv_writer_next_id (writer);
- if (variable->initial_value)
- value_id = gsk_spv_writer_get_id_for_value (writer, variable->initial_value);
+ type_id = gsk_spv_writer_get_id_for_type (writer, gsk_sl_pointer_type_get_type (variable->type));
+ variable_id = gsk_spv_writer_next_id (writer);
+ gsk_spv_writer_add (writer,
+ GSK_SPV_WRITER_SECTION_CODE,
+ 3, GSK_SPV_OP_FUNCTION_PARAMETER,
+ (guint32[2]) { type_id,
+ variable_id });
+
+ return variable_id;
+ }
else
- value_id = 0;
- gsk_spv_writer_add (writer,
- GSK_SPV_WRITER_SECTION_CODE,
- variable->initial_value ? 5 : 4, GSK_SPV_OP_VARIABLE,
- (guint32[4]) { pointer_type_id,
- variable_id,
- gsk_sl_qualifier_get_storage_class (gsk_sl_pointer_type_get_qualifier
(variable->type)),
- value_id });
-
- return variable_id;
+ {
+ guint32 pointer_type_id, variable_id, value_id;
+
+ pointer_type_id = gsk_spv_writer_get_id_for_pointer_type (writer, variable->type);
+ variable_id = gsk_spv_writer_next_id (writer);
+ if (variable->initial_value)
+ value_id = gsk_spv_writer_get_id_for_value (writer, variable->initial_value);
+ else
+ value_id = 0;
+ gsk_spv_writer_add (writer,
+ GSK_SPV_WRITER_SECTION_CODE,
+ variable->initial_value ? 5 : 4, GSK_SPV_OP_VARIABLE,
+ (guint32[4]) { pointer_type_id,
+ variable_id,
+ gsk_sl_qualifier_get_storage_class
(gsk_sl_pointer_type_get_qualifier (variable->type)),
+ value_id });
+
+ return variable_id;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]