summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-10-21 14:46:46 +0200
committerBenjamin Otte <otte@redhat.com>2017-10-30 02:58:03 +0100
commit119f7fe74aecc2e88e8c3f289fe9eb3ca742bc83 (patch)
tree87d0c037f06d06dfc9465a6c08002176c79e97a1
parent516cd4b4993b206eae31fbf4a08e204d50ad08d2 (diff)
downloadgtk+-119f7fe74aecc2e88e8c3f289fe9eb3ca742bc83.tar.gz
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.
-rw-r--r--gsk/gskslbinary.c13
-rw-r--r--gsk/gskslqualifier.c19
-rw-r--r--gsk/gsksltype.c17
-rw-r--r--gsk/gsksltypeprivate.h1
-rw-r--r--testsuite/gsksl/errors/sampler-equal.glsl8
5 files changed, 40 insertions, 18 deletions
diff --git a/gsk/gskslbinary.c b/gsk/gskslbinary.c
index e157483c0c..a2fbe0fd59 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 1dcb66d11d..cf0bf89d63 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 d16b9599ca..2ebfce5b28 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 0838b9753c..da3871b4cc 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 0000000000..27b54c6b1a
--- /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);
+}