[gtk+/wip/otte/shader: 4/44] gsksl: Add gsk_spv_writer_get_id_for_zero()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 4/44] gsksl: Add gsk_spv_writer_get_id_for_zero()
- Date: Thu, 12 Oct 2017 00:57:50 +0000 (UTC)
commit 3d58b2e7741ec21ecffe317cc1fad8213c0b3c83
Author: Benjamin Otte <otte redhat com>
Date: Wed Oct 4 04:40:44 2017 +0200
gsksl: Add gsk_spv_writer_get_id_for_zero()
and gsk_spv_writer_get_id_for_one(). Those are functions that return the
id for the value 0 or 1 in the given scalar. Note that they can be used
for FALSE/TRUE.
gsk/gskslexpression.c | 12 ++-------
gsk/gskspvwriter.c | 57 +++++++++++++++++++++++++++++++++++++++++++++
gsk/gskspvwriterprivate.h | 4 +++
3 files changed, 64 insertions(+), 9 deletions(-)
---
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index 0ba77ce..5f62b63 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -1381,12 +1381,10 @@ gsk_sl_expression_constructor_write_spv (const GskSlExpression *expression,
gsize rows = gsk_sl_type_get_length (col_type);
guint32 ids[2 + gsk_sl_type_get_length (type)];
guint32 scalar_id, zero_id, col_type_id;
- GskSlValue *value;
gsize c;
scalar_id = gsk_spv_writer_add_conversion (writer, value_id, value_type, scalar_type);
- value = gsk_sl_value_new (scalar_type);
- zero_id = gsk_spv_writer_get_id_for_value (writer, value);
+ zero_id = gsk_spv_writer_get_id_for_zero (writer, gsk_sl_type_get_scalar_type (scalar_type));
col_type_id = gsk_spv_writer_get_id_for_type (writer, col_type);
for (c = 0; c < cols; c++)
@@ -1440,12 +1438,8 @@ gsk_sl_expression_constructor_write_spv (const GskSlExpression *expression,
}
value = gsk_sl_value_new (scalar_type);
- zero_id = gsk_spv_writer_get_id_for_value (writer, value);
- if (gsk_sl_type_get_scalar_type (scalar_type) == GSK_SL_DOUBLE)
- *(double *) gsk_sl_value_get_data (value) = 1.0;
- else
- *(float *) gsk_sl_value_get_data (value) = 1.0;
- one_id = gsk_spv_writer_get_id_for_value (writer, value);
+ zero_id = gsk_spv_writer_get_id_for_zero (writer, gsk_sl_type_get_scalar_type (scalar_type));
+ one_id = gsk_spv_writer_get_id_for_one (writer, gsk_sl_type_get_scalar_type (scalar_type));
gsk_sl_value_free (value);
scalar_type_id = gsk_spv_writer_get_id_for_type (writer, scalar_type);
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index 7e0bc9d..b789fe4 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -216,6 +216,63 @@ gsk_spv_writer_get_id_for_value (GskSpvWriter *writer,
}
guint32
+gsk_spv_writer_get_id_for_zero (GskSpvWriter *writer,
+ GskSlScalarType scalar)
+{
+ GskSlValue *value;
+ guint32 result_id;
+
+ value = gsk_sl_value_new (gsk_sl_type_get_scalar (scalar));
+ result_id = gsk_spv_writer_get_id_for_value (writer, value);
+ gsk_sl_value_free (value);
+
+ return result_id;
+}
+
+guint32
+gsk_spv_writer_get_id_for_one (GskSpvWriter *writer,
+ GskSlScalarType scalar)
+{
+ GskSlValue *value;
+ guint32 result_id;
+
+ value = gsk_sl_value_new (gsk_sl_type_get_scalar (scalar));
+ switch (scalar)
+ {
+ case GSK_SL_INT:
+ *(gint32 *) gsk_sl_value_get_data (value) = 1;
+ break;
+
+ case GSK_SL_UINT:
+ *(guint32 *) gsk_sl_value_get_data (value) = 1;
+ break;
+
+ case GSK_SL_FLOAT:
+ *(float *) gsk_sl_value_get_data (value) = 1;
+ break;
+
+ case GSK_SL_DOUBLE:
+ *(double *) gsk_sl_value_get_data (value) = 1;
+ break;
+
+ case GSK_SL_BOOL:
+ *(guint32 *) gsk_sl_value_get_data (value) = TRUE;
+ break;
+
+ case GSK_SL_VOID:
+ break;
+
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ result_id = gsk_spv_writer_get_id_for_value (writer, value);
+ gsk_sl_value_free (value);
+
+ return result_id;
+}
+
+guint32
gsk_spv_writer_get_id_for_variable (GskSpvWriter *writer,
GskSlVariable *variable)
{
diff --git a/gsk/gskspvwriterprivate.h b/gsk/gskspvwriterprivate.h
index 61772df..f749668 100644
--- a/gsk/gskspvwriterprivate.h
+++ b/gsk/gskspvwriterprivate.h
@@ -302,6 +302,10 @@ guint32 gsk_spv_writer_get_id_for_pointer_type (GskSpvWriter
GskSlPointerType *type);
guint32 gsk_spv_writer_get_id_for_value (GskSpvWriter *writer,
GskSlValue *value);
+guint32 gsk_spv_writer_get_id_for_zero (GskSpvWriter *writer,
+ GskSlScalarType scalar);
+guint32 gsk_spv_writer_get_id_for_one (GskSpvWriter *writer,
+ GskSlScalarType scalar);
guint32 gsk_spv_writer_get_id_for_variable (GskSpvWriter *writer,
GskSlVariable *variable);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]