[gtk+/wip/otte/shader: 144/151] gsksl: Comparisons aren't allowed between opaque types



commit 09731c56208d2977554d28afa4b216c10b700228
Author: Benjamin Otte <otte redhat com>
Date:   Sat Oct 21 14:46:46 2017 +0200

    gsksl: Comparisons aren't allowed between opaque types
    
    For that purpose, export gsk_sl_type_contains_opaque() as it's used in
    multiple places. It checks if a type or any of it's members are opaque.

 gsk/gskslbinary.c                         |   13 +++++++++++++
 gsk/gskslqualifier.c                      |   19 +------------------
 gsk/gsksltype.c                           |   17 +++++++++++++++++
 gsk/gsksltypeprivate.h                    |    1 +
 testsuite/gsksl/errors/sampler-equal.glsl |    8 ++++++++
 5 files changed, 40 insertions(+), 18 deletions(-)
---
diff --git a/gsk/gskslbinary.c b/gsk/gskslbinary.c
index 05a49bd..7486d7d 100644
--- a/gsk/gskslbinary.c
+++ b/gsk/gskslbinary.c
@@ -1598,6 +1598,19 @@ gsk_sl_equal_check_type (GskSlPreprocessor *preproc,
                          GskSlType         *ltype,
                          GskSlType         *rtype)
 {
+  if (gsk_sl_type_contains_opaque (ltype))
+    {
+      gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH, "Cannot do equality conversion with opaque type 
%s.",
+                                 gsk_sl_type_get_name (ltype));
+      return NULL;
+    }
+  if (gsk_sl_type_contains_opaque (rtype))
+    {
+      gsk_sl_preprocessor_error (preproc, TYPE_MISMATCH, "Cannot do equality conversion with opaque type 
%s.",
+                                 gsk_sl_type_get_name (rtype));
+      return NULL;
+    }
+
   if (gsk_sl_type_can_convert (ltype, rtype))
     return gsk_sl_type_get_scalar (GSK_SL_BOOL);
   if (gsk_sl_type_can_convert (rtype, ltype))
diff --git a/gsk/gskslqualifier.c b/gsk/gskslqualifier.c
index 1dcb66d..cf0bf89 100644
--- a/gsk/gskslqualifier.c
+++ b/gsk/gskslqualifier.c
@@ -590,23 +590,6 @@ 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,
                                     const GskSlType      *type)
@@ -631,7 +614,7 @@ 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))
+      else if (gsk_sl_type_contains_opaque (type))
         return GSK_SPV_STORAGE_CLASS_UNIFORM_CONSTANT;
       else
         return GSK_SPV_STORAGE_CLASS_UNIFORM;
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index d16b959..2ebfce5 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -2449,6 +2449,23 @@ gsk_sl_type_is_opaque (const GskSlType *type)
   return gsk_sl_type_is_sampler (type);
 }
 
+gboolean
+gsk_sl_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 (gsk_sl_type_contains_opaque (gsk_sl_type_get_member_type (type, i)))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 GskSlScalarType
 gsk_sl_type_get_scalar_type (const GskSlType *type)
 {
diff --git a/gsk/gsksltypeprivate.h b/gsk/gsksltypeprivate.h
index 0838b97..da3871b 100644
--- a/gsk/gsksltypeprivate.h
+++ b/gsk/gsksltypeprivate.h
@@ -54,6 +54,7 @@ gboolean                gsk_sl_type_is_struct                   (const GskSlType
 gboolean                gsk_sl_type_is_block                    (const GskSlType     *type);
 gboolean                gsk_sl_type_is_sampler                  (const GskSlType     *type);
 gboolean                gsk_sl_type_is_opaque                   (const GskSlType     *type);
+gboolean                gsk_sl_type_contains_opaque             (const GskSlType     *type);
 
 const char *            gsk_sl_type_get_name                    (const GskSlType     *type);
 GskSlScalarType         gsk_sl_type_get_scalar_type             (const GskSlType     *type);
diff --git a/testsuite/gsksl/errors/sampler-equal.glsl b/testsuite/gsksl/errors/sampler-equal.glsl
new file mode 100644
index 0000000..27b54c6
--- /dev/null
+++ b/testsuite/gsksl/errors/sampler-equal.glsl
@@ -0,0 +1,8 @@
+uniform sampler2D x;
+uniform sampler2D y;
+
+void
+main  ()
+{
+  bool b = (x == y);
+}


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