Mesa (gallium-0.1): tgsi: add missing functionality to support instructions with labels

Jose Fonseca jrfonseca at kemper.freedesktop.org
Tue Aug 25 09:23:53 UTC 2009


Module: Mesa
Branch: gallium-0.1
Commit: d1e4ddd7a1f8da8bf2ca3cc1204669c87c1da809
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d1e4ddd7a1f8da8bf2ca3cc1204669c87c1da809

Author: Keith Whitwell <keithw at vmware.com>
Date:   Wed Aug 19 11:54:06 2009 +0100

tgsi: add missing functionality to support instructions with labels

Could previously emit opcodes with label arguments, but was no way to
patch them with the actual destinations of those labels.

Adds two functions:

  ureg_get_instruction_number - to get the id of the next instruction
     to be emitted

  ureg_fixup_label - to patch an emitted label to point to a given
     instruction number.

Need some more complex examples than u_simple_shader, so far this has
only been compile-tested.

---

 src/gallium/auxiliary/tgsi/tgsi_ureg.c |   31 ++++++++++++++++++++++++++++++-
 src/gallium/auxiliary/tgsi/tgsi_ureg.h |   27 +++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 1b54e4f..d78c289 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -104,6 +104,7 @@ struct ureg_program
 
    unsigned nr_constants;
    unsigned nr_samplers;
+   unsigned nr_instructions;
 
    struct ureg_tokens domain[2];
 };
@@ -526,7 +527,9 @@ ureg_emit_insn(struct ureg_program *ureg,
    out[0].insn.NumSrcRegs = num_src;
    out[0].insn.Padding = 0;
    out[0].insn.Extended = 0;
-
+   
+   ureg->nr_instructions++;
+   
    return ureg->domain[DOMAIN_INSN].count - 1;
 }
 
@@ -545,6 +548,31 @@ ureg_emit_label(struct ureg_program *ureg,
 
    out[0].value = 0;
    out[0].insn_ext_label.Type = TGSI_INSTRUCTION_EXT_TYPE_LABEL;
+   
+   *label_token = ureg->domain[DOMAIN_INSN].count - 1;
+}
+
+/* Will return a number which can be used in a label to point to the
+ * next instruction to be emitted.
+ */
+unsigned
+ureg_get_instruction_number( struct ureg_program *ureg )
+{
+   return ureg->nr_instructions;
+}
+
+/* Patch a given label (expressed as a token number) to point to a
+ * given instruction (expressed as an instruction number).
+ */
+void
+ureg_fixup_label(struct ureg_program *ureg,
+                 unsigned label_token,
+                 unsigned instruction_number )
+{
+   union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, label_token );
+
+   assert(out->insn_ext_label.Type == TGSI_INSTRUCTION_EXT_TYPE_LABEL);
+   out->insn_ext_label.Label = instruction_number;
 }
 
 
@@ -572,6 +600,7 @@ ureg_fixup_insn_size(struct ureg_program *ureg,
 {
    union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_INSN, insn );
 
+   assert(out->insn.Type == TGSI_TOKEN_TYPE_INSTRUCTION);
    out->insn.Size = ureg->domain[DOMAIN_INSN].count - insn - 1;
 }
 
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index 0e551e6..7f113d1 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -185,6 +185,33 @@ ureg_DECL_immediate1f( struct ureg_program *ureg,
 }
 
 /***********************************************************************
+ * Functions for patching up labels
+ */
+
+
+/* Will return a number which can be used in a label to point to the
+ * next instruction to be emitted.
+ */
+unsigned
+ureg_get_instruction_number( struct ureg_program *ureg );
+
+
+/* Patch a given label (expressed as a token number) to point to a
+ * given instruction (expressed as an instruction number).
+ *
+ * Labels are obtained from instruction emitters, eg ureg_CAL().
+ * Instruction numbers are obtained from ureg_get_instruction_number(),
+ * above.
+ */
+void
+ureg_fixup_label(struct ureg_program *ureg,
+                 unsigned label_token,
+                 unsigned instruction_number );
+
+
+
+
+/***********************************************************************
  * Internal instruction helpers, don't call these directly:
  */
 




More information about the mesa-commit mailing list