X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglsl%2Fir_validate.cpp;h=af0b5768ac08a465a5f55d3bf4060935bb5cc5b7;hb=2acc7193743199701f8f6d1877a59ece0ec4fa5b;hp=41ffdfdbcc7f180aaed26af955ca6b023b475c56;hpb=20ef96c7ff3f17fbf97e0452a37553249b2b005c;p=mesa.git diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index 41ffdfdbcc7..af0b5768ac0 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -33,7 +33,6 @@ * a dereference chain. */ -#include #include "ir.h" #include "ir_hierarchical_visitor.h" #include "program/hash_table.h" @@ -59,7 +58,8 @@ public: virtual ir_visitor_status visit(ir_variable *v); virtual ir_visitor_status visit(ir_dereference_variable *ir); - virtual ir_visitor_status visit(ir_if *ir); + + virtual ir_visitor_status visit_enter(ir_if *ir); virtual ir_visitor_status visit_leave(ir_loop *ir); virtual ir_visitor_status visit_enter(ir_function *ir); @@ -102,7 +102,7 @@ ir_validate::visit(ir_dereference_variable *ir) } ir_visitor_status -ir_validate::visit(ir_if *ir) +ir_validate::visit_enter(ir_if *ir) { if (ir->condition->type != glsl_type::bool_type) { printf("ir_if condition %s type instead of bool.\n", @@ -254,7 +254,11 @@ ir_validate::visit_leave(ir_expression *ir) case ir_unop_f2i: assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); - assert(ir->type->is_integer()); + assert(ir->type->base_type == GLSL_TYPE_INT); + break; + case ir_unop_f2u: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_UINT); break; case ir_unop_i2f: assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); @@ -269,12 +273,12 @@ ir_validate::visit_leave(ir_expression *ir) assert(ir->type->base_type == GLSL_TYPE_FLOAT); break; case ir_unop_i2b: - assert(ir->operands[0]->type->is_integer()); + assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); assert(ir->type->base_type == GLSL_TYPE_BOOL); break; case ir_unop_b2i: assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); - assert(ir->type->is_integer()); + assert(ir->type->base_type == GLSL_TYPE_INT); break; case ir_unop_u2f: assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); @@ -288,6 +292,22 @@ ir_validate::visit_leave(ir_expression *ir) assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); assert(ir->type->base_type == GLSL_TYPE_INT); break; + case ir_unop_bitcast_i2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + case ir_unop_bitcast_f2i: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_INT); + break; + case ir_unop_bitcast_u2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + case ir_unop_bitcast_f2u: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_UINT); + break; case ir_unop_any: assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); @@ -403,6 +423,13 @@ ir_validate::visit_leave(ir_expression *ir) assert(ir->operands[0]->type == ir->operands[1]->type); break; + case ir_binop_ubo_load: + assert(ir->operands[0]->as_constant()); + assert(ir->operands[0]->type == glsl_type::uint_type); + + assert(ir->operands[1]->type == glsl_type::uint_type); + break; + case ir_quadop_vector: /* The vector operator collects some number of scalars and generates a * vector from them. @@ -455,7 +482,7 @@ ir_validate::visit_leave(ir_expression *ir) ir_visitor_status ir_validate::visit_leave(ir_swizzle *ir) { - int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w}; + unsigned int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w}; for (unsigned int i = 0; i < ir->type->vector_elements; i++) { if (chans[i] >= ir->val->type->vector_elements) { @@ -496,6 +523,13 @@ ir_validate::visit(ir_variable *ir) } } + if (ir->constant_initializer != NULL && !ir->has_initializer) { + printf("ir_variable didn't have an initializer, but has a constant " + "initializer value.\n"); + ir->print(); + abort(); + } + return visit_continue; } @@ -534,14 +568,62 @@ ir_validate::visit_enter(ir_assignment *ir) ir_visitor_status ir_validate::visit_enter(ir_call *ir) { - ir_function_signature *const callee = ir->get_callee(); + ir_function_signature *const callee = ir->callee; if (callee->ir_type != ir_type_function_signature) { printf("IR called by ir_call is not ir_function_signature!\n"); abort(); } + if (ir->return_deref) { + if (ir->return_deref->type != callee->return_type) { + printf("callee type %s does not match return storage type %s\n", + callee->return_type->name, ir->return_deref->type->name); + abort(); + } + } else if (callee->return_type != glsl_type::void_type) { + printf("ir_call has non-void callee but no return storage\n"); + abort(); + } + + const exec_node *formal_param_node = callee->parameters.head; + const exec_node *actual_param_node = ir->actual_parameters.head; + while (true) { + if (formal_param_node->is_tail_sentinel() + != actual_param_node->is_tail_sentinel()) { + printf("ir_call has the wrong number of parameters:\n"); + goto dump_ir; + } + if (formal_param_node->is_tail_sentinel()) { + break; + } + const ir_variable *formal_param + = (const ir_variable *) formal_param_node; + const ir_rvalue *actual_param + = (const ir_rvalue *) actual_param_node; + if (formal_param->type != actual_param->type) { + printf("ir_call parameter type mismatch:\n"); + goto dump_ir; + } + if (formal_param->mode == ir_var_out + || formal_param->mode == ir_var_inout) { + if (!actual_param->is_lvalue()) { + printf("ir_call out/inout parameters must be lvalues:\n"); + goto dump_ir; + } + } + formal_param_node = formal_param_node->next; + actual_param_node = actual_param_node->next; + } + return visit_continue; + +dump_ir: + ir->print(); + printf("callee:\n"); + callee->print(); + abort(); + return visit_stop; } void @@ -567,7 +649,9 @@ check_node_type(ir_instruction *ir, void *data) printf("Instruction node with unset type\n"); ir->print(); printf("\n"); } - assert(ir->type != glsl_type::error_type); + ir_rvalue *value = ir->as_rvalue(); + if (value != NULL) + assert(value->type != glsl_type::error_type); } void