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



commit 0e78b789ffecb7686acee9d0bf12c679ae55c2c3
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 fedfe48..f8fe210 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -460,12 +460,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 9712002..f2ab69e 100644
--- a/gsk/gskspvwritergeneratedprivate.h
+++ b/gsk/gskspvwritergeneratedprivate.h
@@ -4504,9 +4504,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 b675f7a..9f1fb03 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]