From 8d1627c25a24f7bc14946bfe268d2d1c5dcde470 Mon Sep 17 00:00:00 2001 From: Haihao Xiang Date: Wed, 6 Aug 2008 09:05:09 -0600 Subject: mesa: glsl: count number of temp regs used --- src/mesa/shader/slang/slang_link.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/mesa/shader/slang/slang_link.c') diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 1de561930a..53de4232be 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -276,6 +276,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. -- cgit v1.2.3 From 95d3642122f48439e356b781f62649553f97c7ee Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 6 Aug 2008 16:29:10 -0600 Subject: mesa: glsl: additional error checking --- src/mesa/shader/slang/slang_link.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/mesa/shader/slang/slang_link.c') diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 53de4232be..8f07406ee4 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -445,6 +445,18 @@ _slang_link(GLcontext *ctx, _mesa_problem(ctx, "unexpected shader target in slang_link()"); } +#if FEATURE_es2_glsl + /* must have both a vertex and fragment program for ES2 */ + if (!vertProg) { + link_error(shProg, "missing vertex shader\n"); + return; + } + if (!fragProg) { + link_error(shProg, "missing fragment shader\n"); + return; + } +#endif + /* * Make copies of the vertex/fragment programs now since we'll be * changing src/dst registers after merging the uniforms and varying vars. -- cgit v1.2.3