[gtk+/wip/otte/shader: 59/101] gskslvariable: Add API to query if access chain usage is possible



commit be818d8a2290f014245d4179a971827a294be7f4
Author: Benjamin Otte <otte redhat com>
Date:   Mon Oct 16 22:30:56 2017 +0200

    gskslvariable: Add API to query if access chain usage is possible
    
    This is necessary so access chain creation can fail early when a
    reference expression is asked to create one.

 gsk/gskslvariable.c        |   35 +++++++++++++++++++++++++++++++++++
 gsk/gskslvariableprivate.h |    1 +
 gsk/gskspvwriter.c         |    3 +++
 3 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskslvariable.c b/gsk/gskslvariable.c
index ff01fe3..1a4fbe3 100644
--- a/gsk/gskslvariable.c
+++ b/gsk/gskslvariable.c
@@ -45,6 +45,7 @@ struct _GskSlVariableClass
 
   void                  (* free)                                (GskSlVariable          *variable);
 
+  gboolean              (* is_direct_access_spv)                (const GskSlVariable    *variable);
   guint32               (* write_spv)                           (const GskSlVariable    *variable,
                                                                  GskSpvWriter           *writer);
   guint32               (* load_spv)                            (GskSlVariable          *variable,
@@ -80,6 +81,12 @@ gsk_sl_variable_free (GskSlVariable *variable)
 
 /* STANDARD */
 
+static gboolean
+gsk_sl_variable_standard_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return TRUE;
+}
+
 static guint32
 gsk_sl_variable_standard_write_spv (const GskSlVariable *variable,
                                     GskSpvWriter        *writer)
@@ -135,6 +142,7 @@ gsk_sl_variable_standard_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_STANDARD = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_standard_is_direct_access_spv,
   gsk_sl_variable_standard_write_spv,
   gsk_sl_variable_standard_load_spv,
   gsk_sl_variable_standard_store_spv,
@@ -142,6 +150,12 @@ static const GskSlVariableClass GSK_SL_VARIABLE_STANDARD = {
 
 /* CONSTANT */
 
+static gboolean
+gsk_sl_variable_constant_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return FALSE;
+}
+
 static guint32
 gsk_sl_variable_constant_write_spv (const GskSlVariable *variable,
                                     GskSpvWriter        *writer)
@@ -167,6 +181,7 @@ gsk_sl_variable_constant_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_CONSTANT = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_constant_is_direct_access_spv,
   gsk_sl_variable_constant_write_spv,
   gsk_sl_variable_constant_load_spv,
   gsk_sl_variable_constant_store_spv,
@@ -174,6 +189,12 @@ static const GskSlVariableClass GSK_SL_VARIABLE_CONSTANT = {
 
 /* PARAMETER */
 
+static gboolean
+gsk_sl_variable_parameter_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return TRUE;
+}
+
 static guint32
 gsk_sl_variable_parameter_write_spv (const GskSlVariable *variable,
                                      GskSpvWriter        *writer)
@@ -216,6 +237,7 @@ gsk_sl_variable_parameter_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_PARAMETER = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_parameter_is_direct_access_spv,
   gsk_sl_variable_parameter_write_spv,
   gsk_sl_variable_parameter_load_spv,
   gsk_sl_variable_parameter_store_spv,
@@ -223,6 +245,12 @@ static const GskSlVariableClass GSK_SL_VARIABLE_PARAMETER = {
 
 /* CONST_PARAMETER */
 
+static gboolean
+gsk_sl_variable_const_parameter_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return FALSE;
+}
+
 static guint32
 gsk_sl_variable_const_parameter_write_spv (const GskSlVariable *variable,
                                            GskSpvWriter        *writer)
@@ -256,6 +284,7 @@ gsk_sl_variable_const_parameter_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_CONST_PARAMETER = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_const_parameter_is_direct_access_spv,
   gsk_sl_variable_const_parameter_write_spv,
   gsk_sl_variable_const_parameter_load_spv,
   gsk_sl_variable_const_parameter_store_spv,
@@ -405,6 +434,12 @@ gsk_sl_variable_is_constant (const GskSlVariable *variable)
   return gsk_sl_qualifier_is_constant (&variable->qualifier);
 }
 
+gboolean
+gsk_sl_variable_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return variable->class->is_direct_access_spv (variable);
+}
+
 guint32
 gsk_sl_variable_write_spv (const GskSlVariable *variable,
                            GskSpvWriter        *writer)
diff --git a/gsk/gskslvariableprivate.h b/gsk/gskslvariableprivate.h
index d414ad6..2df9759 100644
--- a/gsk/gskslvariableprivate.h
+++ b/gsk/gskslvariableprivate.h
@@ -42,6 +42,7 @@ const char *            gsk_sl_variable_get_name                (const GskSlVari
 const GskSlValue *      gsk_sl_variable_get_initial_value       (const GskSlVariable    *variable);
 gboolean                gsk_sl_variable_is_constant             (const GskSlVariable    *variable);
 
+gboolean                gsk_sl_variable_is_direct_access_spv    (const GskSlVariable    *variable);
 guint32                 gsk_sl_variable_write_spv               (const GskSlVariable    *variable,
                                                                  GskSpvWriter           *writer);
 guint32                 gsk_sl_variable_load_spv                (GskSlVariable          *variable,
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index 625d1eb..57e5b38 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -754,6 +754,9 @@ gsk_spv_access_chain_new (GskSpvWriter  *writer,
 {
   GskSpvAccessChain *chain;
 
+  if (!gsk_sl_variable_is_direct_access_spv (variable))
+    return NULL;
+
   chain = g_slice_new0 (GskSpvAccessChain);
 
   chain->writer = gsk_spv_writer_ref (writer);


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