[gtk+/wip/otte/shader: 171/175] gskspv: Variables can go different places



commit ad042201272bf5e60bec8c5e17a66e6bc4ae17f6
Author: Benjamin Otte <otte redhat com>
Date:   Sat Oct 7 23:22:09 2017 +0200

    gskspv: Variables can go different places
    
    Global variables are declared in the type definition section while local
    variables are part of the function body.

 gsk/gskslvariable.c                |    6 +++++-
 gsk/gskspvwritergeneratedprivate.h |    3 ++-
 gsk/spirv.js                       |    2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gsk/gskslvariable.c b/gsk/gskslvariable.c
index f1a7e61..3dfc495 100644
--- a/gsk/gskslvariable.c
+++ b/gsk/gskslvariable.c
@@ -152,8 +152,11 @@ gsk_sl_variable_write_spv (const GskSlVariable *variable,
                            GskSpvWriter        *writer)
 {
   guint32 result_id;
+  GskSlQualifierLocation location;
+  
+  location = gsk_sl_qualifier_get_location (gsk_sl_pointer_type_get_qualifier (variable->type));
 
-  if (gsk_sl_qualifier_get_location (gsk_sl_pointer_type_get_qualifier (variable->type)) == 
GSK_SL_QUALIFIER_PARAMETER)
+  if (location == GSK_SL_QUALIFIER_PARAMETER)
     {
       result_id = gsk_spv_writer_function_parameter (writer,
                                                      gsk_sl_pointer_type_get_type (variable->type));
@@ -168,6 +171,7 @@ gsk_sl_variable_write_spv (const GskSlVariable *variable,
         value_id = 0;
 
       result_id = gsk_spv_writer_variable (writer,
+                                           location == GSK_SL_QUALIFIER_GLOBAL ? 
GSK_SPV_WRITER_SECTION_DEFINE : GSK_SPV_WRITER_SECTION_DECLARE,
                                            variable->type,
                                            gsk_sl_qualifier_get_storage_class 
(gsk_sl_pointer_type_get_qualifier (variable->type)),
                                            value_id);
diff --git a/gsk/gskspvwritergeneratedprivate.h b/gsk/gskspvwritergeneratedprivate.h
index 5d7bc25..57795a1 100644
--- a/gsk/gskspvwritergeneratedprivate.h
+++ b/gsk/gskspvwritergeneratedprivate.h
@@ -914,11 +914,12 @@ gsk_spv_writer_function_call (GskSpvWriter *writer,
 
 static inline guint32
 gsk_spv_writer_variable (GskSpvWriter *writer,
+                         GskSpvWriterSection section,
                          GskSlPointerType * result_type,
                          GskSpvStorageClass storage_class,
                          guint32 opt_initializer)
 {
-  GArray *bytes = gsk_spv_writer_get_bytes (writer, GSK_SPV_WRITER_SECTION_DECLARE);
+  GArray *bytes = gsk_spv_writer_get_bytes (writer, section);
   guint32 result_type_id = gsk_spv_writer_get_id_for_pointer_type (writer, result_type);
   guint32 result_id = gsk_spv_writer_make_id (writer);
   guint start_index = bytes->len;
diff --git a/gsk/spirv.js b/gsk/spirv.js
index 1014e69..f025292 100644
--- a/gsk/spirv.js
+++ b/gsk/spirv.js
@@ -139,7 +139,7 @@ var Sections = {
   "OpFunctionParameter": "declare",
   "OpFunctionEnd": "code",
   "OpFunctionCall": "code",
-  "OpVariable": "declare",
+  "OpVariable": "",
   "OpImageTexelPointer": "code",
   "OpLoad": "code",
   "OpStore": "code",


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