[gtk+/wip/otte/shader: 148/156] gskslqualifier: Require type to determine storage class



commit 1b73874ffb523df636f422747fd43e6b18b5414a
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 18 05:39:25 2017 +0200

    gskslqualifier: Require type to determine storage class
    
    Opaque type uniforms have a different storage class than regular
    uniforms.

 gsk/gskslqualifier.c        |   22 +++++++++++++++++++++-
 gsk/gskslqualifierprivate.h |    3 ++-
 gsk/gskslvariable.c         |    6 ++++--
 gsk/gskspvwriter.c          |    3 ++-
 4 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/gsk/gskslqualifier.c b/gsk/gskslqualifier.c
index fed676c..82429f1 100644
--- a/gsk/gskslqualifier.c
+++ b/gsk/gskslqualifier.c
@@ -590,8 +590,26 @@ gsk_sl_qualifier_get_location (const GskSlQualifier *qualifier)
     }
 }
 
+static gboolean
+type_contains_opaque (const GskSlType *type)
+{
+  gsize i;
+
+  if (gsk_sl_type_is_opaque (type))
+    return TRUE;
+
+  for (i = 0; i < gsk_sl_type_get_n_members (type); i++)
+    {
+      if (type_contains_opaque (gsk_sl_type_get_member_type (type, i)))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 GskSpvStorageClass
-gsk_sl_qualifier_get_storage_class (const GskSlQualifier *qualifier)
+gsk_sl_qualifier_get_storage_class (const GskSlQualifier *qualifier,
+                                    const GskSlType      *type)
 {
   switch (qualifier->storage)
     {
@@ -613,6 +631,8 @@ gsk_sl_qualifier_get_storage_class (const GskSlQualifier *qualifier)
     case GSK_SL_STORAGE_GLOBAL_UNIFORM:
       if (qualifier->layout.push_constant)
         return GSK_SPV_STORAGE_CLASS_PUSH_CONSTANT;
+      else if (type_contains_opaque (type))
+        return GSK_SPV_STORAGE_CLASS_UNIFORM_CONSTANT;
       else
         return GSK_SPV_STORAGE_CLASS_UNIFORM;
 
diff --git a/gsk/gskslqualifierprivate.h b/gsk/gskslqualifierprivate.h
index a21841b..393dd0b 100644
--- a/gsk/gskslqualifierprivate.h
+++ b/gsk/gskslqualifierprivate.h
@@ -72,7 +72,8 @@ gboolean                gsk_sl_qualifier_print                          (const G
 
 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);
+GskSpvStorageClass      gsk_sl_qualifier_get_storage_class              (const GskSlQualifier       
*qualifier,
+                                                                         const GskSlType            *type);
 
 gboolean                gsk_sl_qualifier_check_type                     (const GskSlQualifier       
*qualifier,
                                                                          GskSlPreprocessor          *preproc,
diff --git a/gsk/gskslvariable.c b/gsk/gskslvariable.c
index 44697ca..26cee59 100644
--- a/gsk/gskslvariable.c
+++ b/gsk/gskslvariable.c
@@ -94,6 +94,7 @@ gsk_sl_variable_standard_write_spv (const GskSlVariable *variable,
   guint32 result_id;
   guint32 value_id;
   GskSlQualifierLocation location;
+  GskSpvStorageClass storage_class;
 
   location = gsk_sl_qualifier_get_location (&variable->qualifier);
 
@@ -102,11 +103,12 @@ gsk_sl_variable_standard_write_spv (const GskSlVariable *variable,
   else
     value_id = 0;
 
+  storage_class = gsk_sl_qualifier_get_storage_class (&variable->qualifier, variable->type);
   result_id = gsk_spv_writer_variable (writer,
                                        location == GSK_SL_QUALIFIER_GLOBAL ? GSK_SPV_WRITER_SECTION_DEFINE : 
GSK_SPV_WRITER_SECTION_DECLARE,
                                        variable->type,
-                                       gsk_sl_qualifier_get_storage_class (&variable->qualifier),
-                                       gsk_sl_qualifier_get_storage_class (&variable->qualifier),
+                                       storage_class,
+                                       storage_class,
                                        value_id);
 
   if (variable->name)
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index 9445235..8b82515 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -889,7 +889,8 @@ gsk_spv_access_get_variable (GskSpvAccessChain *chain)
   if (chain->chain)
     variable_id = gsk_spv_writer_access_chain (chain->writer,
                                                chain->type,
-                                               gsk_sl_qualifier_get_storage_class 
(gsk_sl_variable_get_qualifier (chain->variable)),
+                                               gsk_sl_qualifier_get_storage_class 
(gsk_sl_variable_get_qualifier (chain->variable),
+                                                                                   gsk_sl_variable_get_type 
(chain->variable)),
                                                variable_id,
                                                (guint32 *) chain->chain->data,
                                                chain->chain->len);


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