[gtk+/wip/otte/shader: 192/226] gskspvwriter: Change get_id_for_zero/one() functions



commit fe4d17fee1882c840c15f56fcbebb12298b63082
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 17 16:56:54 2017 +0200

    gskspvwriter: Change get_id_for_zero/one() functions
    
    Accept a basic GskSlType instead of a scalar. That way, we can return
    0/1 for vectors and matrices, which is kinda common.

 gsk/gskslbinary.c         |    4 +-
 gsk/gskslexpression.c     |    6 ++--
 gsk/gskspvwriter.c        |   66 ++++++++++++++++++++++++++------------------
 gsk/gskspvwriterprivate.h |    4 +-
 4 files changed, 46 insertions(+), 34 deletions(-)
---
diff --git a/gsk/gskslbinary.c b/gsk/gskslbinary.c
index 220f3cf..e157483 100644
--- a/gsk/gskslbinary.c
+++ b/gsk/gskslbinary.c
@@ -671,7 +671,7 @@ gsk_sl_division_write_spv (GskSpvWriter *writer,
 
           tmp_id = gsk_spv_writer_f_div (writer,
                                          rtype,
-                                         gsk_spv_writer_get_id_for_one (writer, gsk_sl_type_get_scalar_type 
(type)),
+                                         gsk_spv_writer_get_id_for_one (writer, ltype),
                                          right_id);
 
           return gsk_spv_writer_matrix_times_scalar (writer,
@@ -691,7 +691,7 @@ gsk_sl_division_write_spv (GskSpvWriter *writer,
 
       tmp_id = gsk_spv_writer_f_div (writer,
                                      ltype,
-                                     gsk_spv_writer_get_id_for_one (writer, gsk_sl_type_get_scalar_type 
(type)),
+                                     gsk_spv_writer_get_id_for_one (writer, ltype),
                                      left_id);
       return gsk_spv_writer_matrix_times_scalar (writer,
                                                  type,
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index 550d5e0..231d9ad 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -908,7 +908,7 @@ gsk_sl_expression_constructor_write_spv (const GskSlExpression *expression,
           gsize c;
 
           scalar_id = gsk_spv_writer_convert (writer, value_id, value_type, scalar_type);
-          zero_id = gsk_spv_writer_get_id_for_zero (writer, gsk_sl_type_get_scalar_type (scalar_type));
+          zero_id = gsk_spv_writer_get_id_for_zero (writer, scalar_type);
 
           for (c = 0; c < cols; c++)
             {
@@ -953,8 +953,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_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));
+      zero_id = gsk_spv_writer_get_id_for_zero (writer, scalar_type);
+      one_id = gsk_spv_writer_get_id_for_one (writer, scalar_type);
       gsk_sl_value_free (value);
 
       for (c = 0; c < cols; c++)
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index ce307bb..69ad248 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -447,13 +447,15 @@ gsk_spv_writer_get_id_for_value (GskSpvWriter *writer,
 }
 
 guint32
-gsk_spv_writer_get_id_for_zero (GskSpvWriter    *writer,
-                                GskSlScalarType  scalar)
+gsk_spv_writer_get_id_for_zero (GskSpvWriter *writer,
+                                GskSlType    *type)
 {
   GskSlValue *value;
   guint32 result_id;
 
-  value = gsk_sl_value_new (gsk_sl_type_get_scalar (scalar));
+  g_return_val_if_fail (gsk_sl_type_is_basic (type), 0);
+
+  value = gsk_sl_value_new (type);
   result_id = gsk_spv_writer_get_id_for_value (writer, value);
   gsk_sl_value_free (value);
 
@@ -461,42 +463,52 @@ gsk_spv_writer_get_id_for_zero (GskSpvWriter    *writer,
 }
 
 guint32
-gsk_spv_writer_get_id_for_one (GskSpvWriter    *writer,
-                               GskSlScalarType  scalar)
+gsk_spv_writer_get_id_for_one (GskSpvWriter *writer,
+                               GskSlType    *type)
 {
   GskSlValue *value;
   guint32 result_id;
+  gpointer data;
+  gsize i;
+
+  g_return_val_if_fail (gsk_sl_type_is_basic (type), 0);
 
-  value = gsk_sl_value_new (gsk_sl_type_get_scalar (scalar));
-  switch (scalar)
+  value = gsk_sl_value_new (type);
+  data = gsk_sl_value_get_data (value);
+
+  for (i = 0; i < gsk_sl_type_get_n_components (type); i++)
     {
-    case GSK_SL_INT:
-      *(gint32 *) gsk_sl_value_get_data (value) = 1;
-      break;
+      switch (gsk_sl_type_get_scalar_type (type))
+        {
+        case GSK_SL_INT:
+          ((gint32 *) data)[i] = 1;
+          break;
 
-    case GSK_SL_UINT:
-      *(guint32 *) gsk_sl_value_get_data (value) = 1;
-      break;
+        case GSK_SL_UINT:
+          ((guint32 *) data)[i] = 1;
+          break;
 
-    case GSK_SL_FLOAT:
-      *(float *) gsk_sl_value_get_data (value) = 1;
-      break;
+        case GSK_SL_FLOAT:
+          ((float *) data)[i] = 1;
+          break;
 
-    case GSK_SL_DOUBLE:
-      *(double *) gsk_sl_value_get_data (value) = 1;
-      break;
+        case GSK_SL_DOUBLE:
+          ((double *) data)[i] = 1;
+          break;
 
-    case GSK_SL_BOOL:
-      *(guint32 *) gsk_sl_value_get_data (value) = TRUE;
-      break;
+        case GSK_SL_BOOL:
+          ((guint32 *) data)[i] = 1;
+          break;
 
-    case GSK_SL_VOID:
-      break;
+        case GSK_SL_VOID:
+          break;
 
-    default:
-      g_assert_not_reached ();
-      break;
+        default:
+          g_assert_not_reached ();
+          break;
+        }
     }
+
   result_id = gsk_spv_writer_get_id_for_value (writer, value);
   gsk_sl_value_free (value);
 
diff --git a/gsk/gskspvwriterprivate.h b/gsk/gskspvwriterprivate.h
index 74937df..37342b2 100644
--- a/gsk/gskspvwriterprivate.h
+++ b/gsk/gskspvwriterprivate.h
@@ -67,9 +67,9 @@ guint32                 gsk_spv_writer_get_id_for_pointer_type  (GskSpvWriter
 guint32                 gsk_spv_writer_get_id_for_value         (GskSpvWriter           *writer,
                                                                  GskSlValue             *value);
 guint32                 gsk_spv_writer_get_id_for_zero          (GskSpvWriter           *writer,
-                                                                 GskSlScalarType         scalar);
+                                                                 GskSlType              *type);
 guint32                 gsk_spv_writer_get_id_for_one           (GskSpvWriter           *writer,
-                                                                 GskSlScalarType         scalar);
+                                                                 GskSlType              *type);
 guint32                 gsk_spv_writer_get_id_for_variable      (GskSpvWriter           *writer,
                                                                  GskSlVariable          *variable);
 guint32                 gsk_spv_writer_get_id_for_function      (GskSpvWriter           *writer,


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