[gtk+/wip/otte/shader: 13/13] gskspv: Ensure function labels come before variables



commit 53d3fb4a951560f4cb175ab8a9bce758eb0556b5
Author: Benjamin Otte <otte redhat com>
Date:   Mon Oct 9 05:51:57 2017 +0200

    gskspv: Ensure function labels come before variables

 gsk/gskspvwriter.c                 |   10 +++++++++-
 gsk/gskspvwritergeneratedprivate.h |    5 +++--
 gsk/spirv.js                       |    2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index 2cff22c..6a1182b 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -469,12 +469,20 @@ guint32
 gsk_spv_writer_push_new_code_block (GskSpvWriter *writer)
 {
   GskSpvCodeBlock *block;
+  GskSpvWriterSection label_section;
 
   block = gsk_spv_code_block_new ();
+  /* This is ugly code that ensures the function block label
+   * goes before variables but subblock labels do not.
+   */
+  if (writer->blocks && writer->blocks->next)
+    label_section = GSK_SPV_WRITER_SECTION_CODE;
+  else
+    label_section = GSK_SPV_WRITER_SECTION_DECLARE;
 
   gsk_spv_writer_push_code_block (writer, block);
 
-  block->label = gsk_spv_writer_label (writer);
+  block->label = gsk_spv_writer_label (writer, label_section);
 
   return block->label;
 }
diff --git a/gsk/gskspvwritergeneratedprivate.h b/gsk/gskspvwritergeneratedprivate.h
index 3fdfc33..5ea309d 100644
--- a/gsk/gskspvwritergeneratedprivate.h
+++ b/gsk/gskspvwritergeneratedprivate.h
@@ -4526,9 +4526,10 @@ gsk_spv_writer_selection_merge (GskSpvWriter *writer,
 }
 
 static inline guint32
-gsk_spv_writer_label (GskSpvWriter *writer)
+gsk_spv_writer_label (GskSpvWriter *writer,
+                      GskSpvWriterSection section)
 {
-  GArray *bytes = gsk_spv_writer_get_bytes (writer, GSK_SPV_WRITER_SECTION_CODE);
+  GArray *bytes = gsk_spv_writer_get_bytes (writer, section);
   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 6fab1dc..8d0c252 100644
--- a/gsk/spirv.js
+++ b/gsk/spirv.js
@@ -313,7 +313,7 @@ var Sections = {
   "OpPhi": "code",
   "OpLoopMerge": "code",
   "OpSelectionMerge": "code",
-  "OpLabel": "code",
+  "OpLabel": "",
   "OpBranch": "code",
   "OpBranchConditional": "code",
   "OpSwitch": "code",


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