Mesa (master): r300/compiler: cleanup rc_run_compiler

Marek Olšák mareko at kemper.freedesktop.org
Wed Dec 8 03:43:39 UTC 2010


Module: Mesa
Branch: master
Commit: 8fac29d49e2b87c058cb6332211721c979fc231e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8fac29d49e2b87c058cb6332211721c979fc231e

Author: Marek Olšák <maraeo at gmail.com>
Date:   Wed Dec  8 00:18:05 2010 +0100

r300/compiler: cleanup rc_run_compiler

---

 src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c |    3 +-
 src/mesa/drivers/dri/r300/compiler/r3xx_vertprog.c |    3 +-
 .../drivers/dri/r300/compiler/radeon_compiler.c    |   34 +++++++++++++------
 .../drivers/dri/r300/compiler/radeon_compiler.h    |   11 +++++-
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
index 23671e3..3716dea 100644
--- a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
+++ b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
@@ -138,9 +138,10 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
 		{NULL, 0, 0, NULL, NULL}
 	};
 
+	c->Base.type = RC_FRAGMENT_PROGRAM;
 	c->Base.SwizzleCaps = c->Base.is_r500 ? &r500_swizzle_caps : &r300_swizzle_caps;
 
-	rc_run_compiler(&c->Base, fs_list, "Fragment Program");
+	rc_run_compiler(&c->Base, fs_list);
 
 	rc_constants_copy(&c->code->constants, &c->Base.Program.Constants);
 }
diff --git a/src/mesa/drivers/dri/r300/compiler/r3xx_vertprog.c b/src/mesa/drivers/dri/r300/compiler/r3xx_vertprog.c
index 0152bc9..54f4cf3 100644
--- a/src/mesa/drivers/dri/r300/compiler/r3xx_vertprog.c
+++ b/src/mesa/drivers/dri/r300/compiler/r3xx_vertprog.c
@@ -1066,9 +1066,10 @@ void r3xx_compile_vertex_program(struct r300_vertex_program_compiler *c)
 		{NULL, 0, 0, NULL, NULL}
 	};
 
+	c->Base.type = RC_VERTEX_PROGRAM;
 	c->Base.SwizzleCaps = &r300_vertprog_swizzle_caps;
 
-	rc_run_compiler(&c->Base, vs_list, "Vertex Program");
+	rc_run_compiler(&c->Base, vs_list);
 
 	c->code->InputsRead = c->Base.Program.InputsRead;
 	c->code->OutputsWritten = c->Base.Program.OutputsWritten;
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c
index 7cd86fb..72673d7 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c
@@ -398,7 +398,7 @@ void rc_get_stats(struct radeon_compiler *c, struct rc_program_stats *s)
 	s->num_temp_regs = max_reg + 1;
 }
 
-static void print_stats(struct radeon_compiler * c)
+static void print_stats(struct radeon_compiler * c, const char *shader)
 {
 	struct rc_program_stats s;
 
@@ -407,6 +407,7 @@ static void print_stats(struct radeon_compiler * c)
 	if (s.num_insts < 4)
 		return;
 	fprintf(stderr,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
+		       "~ %s:\n"
 		       "~%4u Instructions\n"
 		       "~%4u Vector Instructions (RGB)\n"
 		       "~%4u Scalar Instructions (Alpha)\n"
@@ -415,20 +416,19 @@ static void print_stats(struct radeon_compiler * c)
 		       "~%4u Presub Operations\n"
 		       "~%4u Temporary Registers\n"
 		       "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
+		       shader,
 		       s.num_insts, s.num_rgb_insts, s.num_alpha_insts,
 		       s.num_fc_insts, s.num_tex_insts, s.num_presub_ops,
 		       s.num_temp_regs);
 }
 
-/* Executes a list of compiler passes given in the parameter 'list'. */
-void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list,
-		     const char *shader_name)
-{
-	if (c->Debug & RC_DBG_LOG) {
-		fprintf(stderr, "%s: before compilation\n", shader_name);
-		rc_print_program(&c->Program);
-	}
+static const char *shader_name[RC_NUM_PROGRAM_TYPES] = {
+	"Vertex Program",
+	"Fragment Program"
+};
 
+void rc_run_compiler_passes(struct radeon_compiler *c, struct radeon_compiler_pass *list)
+{
 	for (unsigned i = 0; list[i].name; i++) {
 		if (list[i].predicate) {
 			list[i].run(c, list[i].user);
@@ -437,13 +437,25 @@ void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *lis
 				return;
 
 			if ((c->Debug & RC_DBG_LOG) && list[i].dump) {
-				fprintf(stderr, "%s: after '%s'\n", shader_name, list[i].name);
+				fprintf(stderr, "%s: after '%s'\n", shader_name[c->type], list[i].name);
 				rc_print_program(&c->Program);
 			}
 		}
 	}
+}
+
+/* Executes a list of compiler passes given in the parameter 'list'. */
+void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list)
+{
+	if (c->Debug & RC_DBG_LOG) {
+		fprintf(stderr, "%s: before compilation\n", shader_name[c->type]);
+		rc_print_program(&c->Program);
+	}
+
+	rc_run_compiler_passes(c, list);
+
 	if (c->Debug & RC_DBG_STATS)
-		print_stats(c);
+		print_stats(c, shader_name[c->type]);
 }
 
 void rc_validate_final_shader(struct radeon_compiler *c, void *user)
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
index 2aa7978..e663339 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
@@ -35,9 +35,16 @@
 
 struct rc_swizzle_caps;
 
+enum rc_program_type {
+	RC_VERTEX_PROGRAM,
+	RC_FRAGMENT_PROGRAM,
+	RC_NUM_PROGRAM_TYPES
+};
+
 struct radeon_compiler {
 	struct memory_pool Pool;
 	struct rc_program Program;
+	enum rc_program_type type;
 	unsigned Debug:2;
 	unsigned Error:1;
 	char * ErrorMsg;
@@ -153,8 +160,8 @@ struct rc_program_stats {
 void rc_get_stats(struct radeon_compiler *c, struct rc_program_stats *s);
 
 /* Executes a list of compiler passes given in the parameter 'list'. */
-void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list,
-		     const char *shader_name);
+void rc_run_compiler_passes(struct radeon_compiler *c, struct radeon_compiler_pass *list);
+void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list);
 void rc_validate_final_shader(struct radeon_compiler *c, void *user);
 
 #endif /* RADEON_COMPILER_H */




More information about the mesa-commit mailing list