[gtk+/wip/otte/shader: 125/127] gskslexpression: Fold constant expressions into SPIRV



commit 4998c0453c04a42d92d703990047c547f9a53e80
Author: Benjamin Otte <otte redhat com>
Date:   Thu Oct 12 02:27:28 2017 +0200

    gskslexpression: Fold constant expressions into SPIRV
    
    If an expression is constant, always get the constant expression and
    write it to the SPIRV file instead of doing an evaluation.
    
    This has immense benefits when dealing with initializations, because
    vec4(1, 2, 3, 4) will actually result in a constant instead of first
    creating 4 integers, manually converting each of them to float before
    calling the constructor. Yuck.

 gsk/gskslexpression.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c
index 357d23b..7ffa4da 100644
--- a/gsk/gskslexpression.c
+++ b/gsk/gskslexpression.c
@@ -2768,10 +2768,23 @@ guint32
 gsk_sl_expression_write_spv (const GskSlExpression *expression,
                              GskSpvWriter          *writer)
 {
+  GskSlValue *constant;
+
+  constant = gsk_sl_expression_get_constant (expression);
+  if (constant)
+    {
+      guint32 constant_id;
+      
+      constant_id = gsk_spv_writer_get_id_for_value (writer, constant);
+      gsk_sl_value_free (constant);
+
+      return constant_id;
+    }
+
   if (gsk_sl_expression_is_assignable (expression, NULL))
     {
       GskSpvAccessChain *chain;
-      guint result_id;
+      guint32 result_id;
       
       chain = gsk_sl_expression_get_spv_access_chain (expression, writer);
       result_id = gsk_spv_access_chain_load (chain);


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