From e420e9d48577de57f912ab39d59c2d1d4d14b8f6 Mon Sep 17 00:00:00 2001 From: michal Date: Sun, 28 Oct 2007 14:42:26 +0000 Subject: [PATCH] Declare temporaries in a more compact fashion. The following declarations: DCL TEMP[0] DCL TEMP[1] DCL TEMP[2] DCL TEMP[4] become: DCL TEMP[0..2] DCL TEMP[4] --- src/mesa/state_tracker/st_mesa_to_tgsi.c | 116 ++++++++++++++++--------------- 1 file changed, 61 insertions(+), 55 deletions(-) diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 621159e..cb0c961 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -572,34 +572,36 @@ make_output_decl( return decl; } - - -static struct tgsi_full_declaration -make_temp_decl(GLuint index) -{ - struct tgsi_full_declaration decl; - decl = tgsi_default_full_declaration(); - decl.Declaration.File = TGSI_FILE_TEMPORARY; - decl.Declaration.Declare = TGSI_DECLARE_RANGE; - decl.u.DeclarationRange.First = index; - decl.u.DeclarationRange.Last = index; - return decl; -} - + + +static struct tgsi_full_declaration +make_temp_decl( + GLuint start_index, + GLuint end_index ) +{ + struct tgsi_full_declaration decl; + decl = tgsi_default_full_declaration(); + decl.Declaration.File = TGSI_FILE_TEMPORARY; + decl.Declaration.Declare = TGSI_DECLARE_RANGE; + decl.u.DeclarationRange.First = start_index; + decl.u.DeclarationRange.Last = end_index; + return decl; +} + /** * Find the temporaries which are used in the given program. - * Put the indices of the temporaries in 'tempsUsed'. - * \return number of temporaries used - */ -static GLuint -find_temporaries(const struct gl_program *program, - GLuint tempsUsed[MAX_PROGRAM_TEMPS]) -{ - GLuint i, j, count; - - for (i = 0; i < MAX_PROGRAM_TEMPS; i++) - tempsUsed[i] = GL_FALSE; + * Put the indices of the temporaries in 'tempsUsed'. + * \return number of temporaries used + */ +static void +find_temporaries(const struct gl_program *program, + GLboolean tempsUsed[MAX_PROGRAM_TEMPS]) +{ + GLuint i, j; + + for (i = 0; i < MAX_PROGRAM_TEMPS; i++) + tempsUsed[i] = GL_FALSE; for (i = 0; i < program->NumInstructions; i++) { const struct prog_instruction *inst = program->Instructions + i; @@ -608,20 +610,12 @@ find_temporaries(const struct gl_program *program, if (inst->SrcReg[j].File == PROGRAM_TEMPORARY) tempsUsed[inst->SrcReg[j].Index] = GL_TRUE; if (inst->DstReg.File == PROGRAM_TEMPORARY) - tempsUsed[inst->DstReg.Index] = GL_TRUE; - } - } - - /* convert flags to list of indices */ - count = 0; - for (i = 0; i < MAX_PROGRAM_TEMPS; i++) { - if (tempsUsed[i]) - tempsUsed[count++] = i; - } - return count; -} - - + tempsUsed[inst->DstReg.Index] = GL_TRUE; + } + } +} + + /** @@ -781,22 +775,34 @@ tgsi_translate_mesa_program( maxTokens - ti ); } } - - /* temporary decls */ - { - GLuint tempsUsed[MAX_PROGRAM_TEMPS]; - uint numTemps = find_temporaries(program, tempsUsed); - for (i = 0; i < numTemps; i++) { - struct tgsi_full_declaration fulldecl; - fulldecl = make_temp_decl(tempsUsed[i]); - ti += tgsi_build_full_declaration( - &fulldecl, - &tokens[ti], - header, - maxTokens - ti ); - } - } - + + /* temporary decls */ + { + GLboolean tempsUsed[MAX_PROGRAM_TEMPS + 1]; + GLboolean inside_range = GL_FALSE; + GLuint start_range; + + find_temporaries(program, tempsUsed); + tempsUsed[MAX_PROGRAM_TEMPS] = GL_FALSE; + for (i = 0; i < MAX_PROGRAM_TEMPS + 1; i++) { + if (tempsUsed[i] && !inside_range) { + inside_range = GL_TRUE; + start_range = i; + } + else if (!tempsUsed[i] && inside_range) { + struct tgsi_full_declaration fulldecl; + + inside_range = GL_FALSE; + fulldecl = make_temp_decl( start_range, i - 1 ); + ti += tgsi_build_full_declaration( + &fulldecl, + &tokens[ti], + header, + maxTokens - ti ); + } + } + } + /* immediates/literals */ #if EMIT_IMMEDIATES for (i = 0; i < program->Parameters->NumParameters; i++) { -- 2.7.4