summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaihao Xiang <haihao.xiang@intel.com>2008-08-06 09:01:34 -0600
committerBrian Paul <brian.paul@tungstengraphics.com>2008-08-06 09:01:34 -0600
commit5f460939386c5bcb04b9a778c8ddc41b366c30ee (patch)
treed2c482a9784d9e332000ab027c8a7f9aebbea8fc /src
parentfb71a484133c53d37e9510b96d14ab04724ead79 (diff)
mesa: glsl: count number of temp regs used
Diffstat (limited to 'src')
-rw-r--r--src/mesa/shader/slang/slang_codegen.c2
-rw-r--r--src/mesa/shader/slang/slang_link.c39
2 files changed, 36 insertions, 5 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index ad9cf06e27..bde09fdf4a 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -2433,8 +2433,6 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var)
*/
n->Store->Swizzle = SWIZZLE_NOOP;
}
-
- A->program->NumTemporaries++; /* an approximation */
}
return n;
}
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 26959d9d15..694623f4b0 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -277,6 +277,36 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
/**
+ * Scan program instructions to update the program's NumTemporaries field.
+ * Note: this implemenation relies on the code generator allocating
+ * temps in increasing order (0, 1, 2, ... ).
+ */
+static void
+_slang_count_temporaries(struct gl_program *prog)
+{
+ GLuint i, j;
+ GLint maxIndex = -1;
+
+ for (i = 0; i < prog->NumInstructions; i++) {
+ const struct prog_instruction *inst = prog->Instructions + i;
+ const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
+ for (j = 0; j < numSrc; j++) {
+ if (inst->SrcReg[j].File == PROGRAM_TEMPORARY) {
+ if (maxIndex < inst->SrcReg[j].Index)
+ maxIndex = inst->SrcReg[j].Index;
+ }
+ if (inst->DstReg.File == PROGRAM_TEMPORARY) {
+ if (maxIndex < inst->DstReg.Index)
+ maxIndex = inst->DstReg.Index;
+ }
+ }
+ }
+
+ prog->NumTemporaries = (GLuint) (maxIndex + 1);
+}
+
+
+/**
* Scan program instructions to update the program's InputsRead and
* OutputsWritten fields.
*/
@@ -459,6 +489,7 @@ _slang_link(GLcontext *ctx,
if (shProg->VertexProgram) {
_slang_update_inputs_outputs(&shProg->VertexProgram->Base);
+ _slang_count_temporaries(&shProg->VertexProgram->Base);
if (!(shProg->VertexProgram->Base.OutputsWritten & (1 << VERT_RESULT_HPOS))) {
/* the vertex program did not compute a vertex position */
link_error(shProg,
@@ -466,8 +497,10 @@ _slang_link(GLcontext *ctx,
return;
}
}
- if (shProg->FragmentProgram)
+ if (shProg->FragmentProgram) {
+ _slang_count_temporaries(&shProg->FragmentProgram->Base);
_slang_update_inputs_outputs(&shProg->FragmentProgram->Base);
+ }
/* Check that all the varying vars needed by the fragment shader are
* actually produced by the vertex shader.
@@ -500,7 +533,7 @@ _slang_link(GLcontext *ctx,
_mesa_print_program(&fragProg->Base);
_mesa_print_program_parameters(ctx, &fragProg->Base);
#endif
-#if 0
+#if 01
printf("************** linked fragment prog\n");
_mesa_print_program(&shProg->FragmentProgram->Base);
_mesa_print_program_parameters(ctx, &shProg->FragmentProgram->Base);
@@ -516,7 +549,7 @@ _slang_link(GLcontext *ctx,
_mesa_print_program(&vertProg->Base);
_mesa_print_program_parameters(ctx, &vertProg->Base);
#endif
-#if 0
+#if 01
printf("************** linked vertex prog\n");
_mesa_print_program(&shProg->VertexProgram->Base);
_mesa_print_program_parameters(ctx, &shProg->VertexProgram->Base);