Mesa (master): glsl: Apply implicit conversions to structure constructor parameters.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Sep 2 03:40:11 UTC 2010


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Sep  1 20:03:17 2010 -0700

glsl: Apply implicit conversions to structure constructor parameters.

The code for handling implicit conversions should probably get
refactored, but for now, this is easy.

Fixes piglit test constructor-26.vert.

---

 src/glsl/ast_function.cpp |   11 +++++++++--
 src/glsl/ast_to_hir.cpp   |    2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 1a5a193..61012b8 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -30,6 +30,10 @@
 static ir_rvalue *
 convert_component(ir_rvalue *src, const glsl_type *desired_type);
 
+bool
+apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from,
+                          struct _mesa_glsl_parse_state *state);
+
 static unsigned
 process_parameters(exec_list *instructions, exec_list *actual_parameters,
 		   exec_list *parameters,
@@ -1185,7 +1189,7 @@ ast_function_expression::hir(exec_list *instructions,
       if ((type != NULL) && type->is_record()) {
 	 exec_node *node = actual_parameters.head;
 	 for (unsigned i = 0; i < type->length; i++) {
-	    ir_instruction *ir = (ir_instruction *) node;
+	    ir_rvalue *ir = (ir_rvalue *) node;
 
 	    if (node->is_tail_sentinel()) {
 	       _mesa_glsl_error(&loc, state,
@@ -1195,7 +1199,10 @@ ast_function_expression::hir(exec_list *instructions,
 	       return ir_call::get_error_instruction(ctx);
 	    }
 
-	    if (ir->type != type->fields.structure[i].type) {
+	    if (apply_implicit_conversion(type->fields.structure[i].type, ir,
+					  state)) {
+	       node->replace_with(ir);
+	    } else {
 	       _mesa_glsl_error(&loc, state,
 				"parameter type mismatch in constructor "
 				"for `%s.%s' (%s vs %s)",
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 5bdf3da..762f802 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -97,7 +97,7 @@ _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
  * If a conversion is possible (or unnecessary), \c true is returned.
  * Otherwise \c false is returned.
  */
-static bool
+bool
 apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from,
 			  struct _mesa_glsl_parse_state *state)
 {




More information about the mesa-commit mailing list