From 744548369143d02a31ebecb9579aefb5eaa9e9ad Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 12 Oct 2017 02:27:28 +0200 Subject: [PATCH] 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gsk/gskslexpression.c b/gsk/gskslexpression.c index 97ad76501a..26d8c94136 100644 --- a/gsk/gskslexpression.c +++ b/gsk/gskslexpression.c @@ -2774,8 +2774,18 @@ gsk_sl_expression_write_spv (const GskSlExpression *expression, GskSpvWriter *writer) { GskSpvAccessChain *chain; + GskSlValue *constant; guint32 result_id; + constant = gsk_sl_expression_get_constant (expression); + if (constant) + { + result_id = gsk_spv_writer_get_id_for_value (writer, constant); + gsk_sl_value_free (constant); + + return result_id; + } + chain = gsk_sl_expression_get_spv_access_chain (expression, writer); if (chain) {