summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/tgsi/tgsi_ureg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/tgsi/tgsi_ureg.c')
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_ureg.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index ba84a82b2b..7922931361 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -31,6 +31,7 @@
#include "tgsi/tgsi_ureg.h"
#include "tgsi/tgsi_dump.h"
#include "util/u_memory.h"
+#include "util/u_math.h"
union tgsi_any_token {
struct tgsi_version version;
@@ -103,6 +104,7 @@ struct ureg_program
unsigned nr_constants;
unsigned nr_samplers;
+ unsigned nr_instructions;
struct ureg_tokens domain[2];
};
@@ -301,7 +303,7 @@ out:
*/
struct ureg_src ureg_DECL_constant(struct ureg_program *ureg )
{
- return ureg_src_register( TGSI_FILE_TEMPORARY, ureg->nr_constants++ );
+ return ureg_src_register( TGSI_FILE_CONSTANT, ureg->nr_constants++ );
}
@@ -392,7 +394,7 @@ struct ureg_src ureg_DECL_immediate( struct ureg_program *ureg,
unsigned nr )
{
unsigned i;
- unsigned swizzle;
+ unsigned swizzle = 0;
/* Could do a first pass where we examine all existing immediates
* without expanding.
@@ -525,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;
}
@@ -544,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;
}
@@ -571,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.NrTokens = ureg->domain[DOMAIN_INSN].count - insn - 1;
}
@@ -710,8 +740,7 @@ static void copy_instructions( struct ureg_program *ureg )
static void
-fixup_header_size(struct ureg_program *ureg,
- unsigned insn )
+fixup_header_size(struct ureg_program *ureg )
{
union tgsi_any_token *out = retrieve_token( ureg, DOMAIN_DECL, 1 );
@@ -739,12 +768,11 @@ emit_header( struct ureg_program *ureg )
void *ureg_create_shader( struct ureg_program *ureg )
{
struct pipe_shader_state state;
- unsigned insn;
emit_header( ureg );
emit_decls( ureg );
copy_instructions( ureg );
- fixup_header_size( ureg, insn );
+ fixup_header_size( ureg );
if (ureg->domain[0].tokens == error_tokens ||
ureg->domain[1].tokens == error_tokens) {