On Tue, 2008-08-05 at 08:45 -0600, Brian Paul wrote:
> Xiang, Haihao wrote:
> > On Thu, 2008-07-31 at 13:34 +0800, Xiang, Haihao wrote:
> >> Hi, Brian
> >>
> >> Currently the counter used for temporaries doesn't include all
> >> intermediate results when emitting program instructions, however a
> >> device driver needs to allocate hardware registers for these
> >> intermediate results. The attached patch tries to fix this issue, could
> >> you take a look?
> >>
> > Is it right?
>
> I think the simplest way to determine the number of registers used is to
> simply count them in the resulting program at the end.
>
> Your patch doesn't correctly count registers when a variable occupies
> more than one register (mat4 or large struct, for example).
>
> It should be a simple matter to write a function that scans a program
> and counts the number of temp regs used. Do you want to try that?
>
> The _slang_update_inputs_outputs() function is an example of scanning a
> program for certain types of registers.
>
A new patch to update the program's NumTemporaries field. Maybe only
need to scan src registers or dst registers. Please take a look.
Thanks
Haihao
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 26959d9..60f42c4 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -275,6 +275,33 @@ _slang_resolve_attributes(struct gl_shader_program *shProg,
return GL_TRUE;
}
+/**
+ * Scan program instructions to update the program's NumTemporaries field
+ */
+static void
+_slang_update_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 = maxIndex + 1;
+}
/**
* Scan program instructions to update the program's InputsRead and
@@ -459,6 +486,7 @@ _slang_link(GLcontext *ctx,
if (shProg->VertexProgram) {
_slang_update_inputs_outputs(&shProg->VertexProgram->Base);
+ _slang_update_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 +494,10 @@ _slang_link(GLcontext *ctx,
return;
}
}
- if (shProg->FragmentProgram)
+ if (shProg->FragmentProgram) {
_slang_update_inputs_outputs(&shProg->FragmentProgram->Base);
+ _slang_update_temporaries(&shProg->FragmentProgram->Base);
+ }
/* Check that all the varying vars needed by the fragment shader are
* actually produced by the vertex shader.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev