From f9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4 Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 9 Sep 2011 08:40:24 +0200 Subject: mesa git update 9 sep 2011 --- mesalib/src/glsl/ast_to_hir.cpp | 92 ++++++-- mesalib/src/glsl/glsl_parser_extras.cpp | 2 +- mesalib/src/glsl/ir_set_program_inouts.cpp | 330 ++++++++++++++--------------- mesalib/src/glsl/ir_variable.cpp | 43 +++- mesalib/src/glsl/linker.cpp | 19 ++ 5 files changed, 297 insertions(+), 189 deletions(-) (limited to 'mesalib/src/glsl') diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp index 9e7496b4b..777f190a4 100644 --- a/mesalib/src/glsl/ast_to_hir.cpp +++ b/mesalib/src/glsl/ast_to_hir.cpp @@ -679,16 +679,20 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state, lhs->variable_referenced()->name); error_emitted = true; + } else if (state->language_version <= 110 && lhs->type->is_array()) { + /* From page 32 (page 38 of the PDF) of the GLSL 1.10 spec: + * + * "Other binary or unary expressions, non-dereferenced + * arrays, function names, swizzles with repeated fields, + * and constants cannot be l-values." + */ + _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not " + "allowed in GLSL 1.10 or GLSL ES 1.00."); + error_emitted = true; } else if (!lhs->is_lvalue()) { _mesa_glsl_error(& lhs_loc, state, "non-lvalue in assignment"); error_emitted = true; } - - if (state->es_shader && lhs->type->is_array()) { - _mesa_glsl_error(&lhs_loc, state, "whole array assignment is not " - "allowed in GLSL ES 1.00."); - error_emitted = true; - } } ir_rvalue *new_rhs = @@ -723,6 +727,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state, rhs->type->array_size()); d->type = var->type; } + mark_whole_array_access(rhs); mark_whole_array_access(lhs); } @@ -893,6 +898,44 @@ get_scalar_boolean_operand(exec_list *instructions, return new(ctx) ir_constant(true); } +/** + * If name refers to a builtin array whose maximum allowed size is less than + * size, report an error and return true. Otherwise return false. + */ +static bool +check_builtin_array_max_size(const char *name, unsigned size, + YYLTYPE loc, struct _mesa_glsl_parse_state *state) +{ + if ((strcmp("gl_TexCoord", name) == 0) + && (size > state->Const.MaxTextureCoords)) { + /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: + * + * "The size [of gl_TexCoord] can be at most + * gl_MaxTextureCoords." + */ + _mesa_glsl_error(&loc, state, "`gl_TexCoord' array size cannot " + "be larger than gl_MaxTextureCoords (%u)\n", + state->Const.MaxTextureCoords); + return true; + } else if (strcmp("gl_ClipDistance", name) == 0 + && size > state->Const.MaxClipPlanes) { + /* From section 7.1 (Vertex Shader Special Variables) of the + * GLSL 1.30 spec: + * + * "The gl_ClipDistance array is predeclared as unsized and + * must be sized by the shader either redeclaring it with a + * size or indexing it only with integral constant + * expressions. ... The size can be at most + * gl_MaxClipDistances." + */ + _mesa_glsl_error(&loc, state, "`gl_ClipDistance' array size cannot " + "be larger than gl_MaxClipDistances (%u)\n", + state->Const.MaxClipPlanes); + return true; + } + return false; +} + ir_rvalue * ast_expression::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) @@ -1550,8 +1593,15 @@ ast_expression::hir(exec_list *instructions, * FINISHME: array access limits be added to ir_dereference? */ ir_variable *const v = array->whole_variable_referenced(); - if ((v != NULL) && (unsigned(idx) > v->max_array_access)) + if ((v != NULL) && (unsigned(idx) > v->max_array_access)) { v->max_array_access = idx; + + /* Check whether this access will, as a side effect, implicitly + * cause the size of a built-in array to be too large. + */ + if (check_builtin_array_max_size(v->name, idx+1, loc, state)) + error_emitted = true; + } } } else if (array->type->array_size() == 0) { _mesa_glsl_error(&loc, state, "unsized array index must be constant"); @@ -2071,6 +2121,21 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, else var->depth_layout = ir_depth_layout_none; + /* From page 46 (page 52 of the PDF) of the GLSL ES specification: + * + * "Array variables are l-values and may be passed to parameters + * declared as out or inout. However, they may not be used as + * the target of an assignment." + * + * From page 32 (page 38 of the PDF) of the GLSL 1.10 spec: + * + * "Other binary or unary expressions, non-dereferenced arrays, + * function names, swizzles with repeated fields, and constants + * cannot be l-values." + * + * So we only mark 1.10 as non-lvalues, and check for array + * assignment in 100 specifically in do_assignment. + */ if (var->type->is_array() && state->language_version != 110) { var->array_lvalue = true; } @@ -2121,18 +2186,9 @@ get_variable_being_redeclared(ir_variable *var, ast_declaration *decl, * FINISHME: required or not. */ - /* From page 54 (page 60 of the PDF) of the GLSL 1.20 spec: - * - * "The size [of gl_TexCoord] can be at most - * gl_MaxTextureCoords." - */ const unsigned size = unsigned(var->type->array_size()); - if ((strcmp("gl_TexCoord", var->name) == 0) - && (size > state->Const.MaxTextureCoords)) { - _mesa_glsl_error(& loc, state, "`gl_TexCoord' array size cannot " - "be larger than gl_MaxTextureCoords (%u)\n", - state->Const.MaxTextureCoords); - } else if ((size > 0) && (size <= earlier->max_array_access)) { + check_builtin_array_max_size(var->name, size, loc, state); + if ((size > 0) && (size <= earlier->max_array_access)) { _mesa_glsl_error(& loc, state, "array size must be > %u due to " "previous access", earlier->max_array_access); diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index 8f740e6a8..8faddc578 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -891,8 +891,8 @@ do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iteration if (linked) { progress = do_function_inlining(ir) || progress; progress = do_dead_functions(ir) || progress; + progress = do_structure_splitting(ir) || progress; } - progress = do_structure_splitting(ir) || progress; progress = do_if_simplification(ir) || progress; progress = do_discard_simplification(ir) || progress; progress = do_copy_propagation(ir) || progress; diff --git a/mesalib/src/glsl/ir_set_program_inouts.cpp b/mesalib/src/glsl/ir_set_program_inouts.cpp index c5533c8cd..3b10b9097 100644 --- a/mesalib/src/glsl/ir_set_program_inouts.cpp +++ b/mesalib/src/glsl/ir_set_program_inouts.cpp @@ -1,166 +1,164 @@ -/* - * Copyright © 2010 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -/** - * \file ir_set_program_inouts.cpp - * - * Sets the InputsRead and OutputsWritten of Mesa programs. - * - * Mesa programs (gl_program, not gl_shader_program) have a set of - * flags indicating which varyings are read and written. Computing - * which are actually read from some sort of backend code can be - * tricky when variable array indexing involved. So this pass - * provides support for setting InputsRead and OutputsWritten right - * from the GLSL IR. - */ - -extern "C" { -#include "main/core.h" /* for struct gl_program */ -#include "program/hash_table.h" -} -#include "ir.h" -#include "ir_visitor.h" -#include "glsl_types.h" - -class ir_set_program_inouts_visitor : public ir_hierarchical_visitor { -public: - ir_set_program_inouts_visitor(struct gl_program *prog) - { - this->prog = prog; - this->ht = hash_table_ctor(0, - hash_table_pointer_hash, - hash_table_pointer_compare); - } - ~ir_set_program_inouts_visitor() - { - hash_table_dtor(this->ht); - } - - virtual ir_visitor_status visit_enter(ir_dereference_array *); - virtual ir_visitor_status visit_enter(ir_function_signature *); - virtual ir_visitor_status visit(ir_dereference_variable *); - virtual ir_visitor_status visit(ir_variable *); - - struct gl_program *prog; - struct hash_table *ht; -}; - -static void -mark(struct gl_program *prog, ir_variable *var, int offset, int len) -{ - /* As of GLSL 1.20, varyings can only be floats, floating-point - * vectors or matrices, or arrays of them. For Mesa programs using - * InputsRead/OutputsWritten, everything but matrices uses one - * slot, while matrices use a slot per column. Presumably - * something doing a more clever packing would use something other - * than InputsRead/OutputsWritten. - */ - - for (int i = 0; i < len; i++) { - if (var->mode == ir_var_in) - prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i); - else if (var->mode == ir_var_system_value) - prog->SystemValuesRead |= (1 << (var->location + offset + i)); - else - prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i); - } -} - -/* Default handler: Mark all the locations in the variable as used. */ -ir_visitor_status -ir_set_program_inouts_visitor::visit(ir_dereference_variable *ir) -{ - if (hash_table_find(this->ht, ir->var) == NULL) - return visit_continue; - - if (ir->type->is_array()) { - for (unsigned int i = 0; i < ir->type->length; i++) { - mark(this->prog, ir->var, i, - ir->type->length * ir->type->fields.array->matrix_columns); - } - } else { - mark(this->prog, ir->var, 0, ir->type->matrix_columns); - } - - return visit_continue; -} - -ir_visitor_status -ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir) -{ - ir_dereference_variable *deref_var; - ir_constant *index = ir->array_index->as_constant(); - deref_var = ir->array->as_dereference_variable(); - ir_variable *var = NULL; - - /* Check that we're dereferencing a shader in or out */ - if (deref_var) - var = (ir_variable *)hash_table_find(this->ht, deref_var->var); - - if (index && var) { - int width = 1; - - if (deref_var->type->is_array() && - deref_var->type->fields.array->is_matrix()) { - width = deref_var->type->fields.array->matrix_columns; - } - - mark(this->prog, var, index->value.i[0] * width, width); - return visit_continue_with_parent; - } - - return visit_continue; -} - -ir_visitor_status -ir_set_program_inouts_visitor::visit(ir_variable *ir) -{ - if (ir->mode == ir_var_in || - ir->mode == ir_var_out || - ir->mode == ir_var_system_value) { - hash_table_insert(this->ht, ir, ir); - } - - return visit_continue; -} - -ir_visitor_status -ir_set_program_inouts_visitor::visit_enter(ir_function_signature *ir) -{ - /* We don't want to descend into the function parameters and - * consider them as shader inputs or outputs. - */ - visit_list_elements(this, &ir->body); - return visit_continue_with_parent; -} - -void -do_set_program_inouts(exec_list *instructions, struct gl_program *prog) -{ - ir_set_program_inouts_visitor v(prog); - - prog->InputsRead = 0; - prog->OutputsWritten = 0; - prog->SystemValuesRead = 0; - visit_list_elements(&v, instructions); -} +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_set_program_inouts.cpp + * + * Sets the InputsRead and OutputsWritten of Mesa programs. + * + * Mesa programs (gl_program, not gl_shader_program) have a set of + * flags indicating which varyings are read and written. Computing + * which are actually read from some sort of backend code can be + * tricky when variable array indexing involved. So this pass + * provides support for setting InputsRead and OutputsWritten right + * from the GLSL IR. + */ + +extern "C" { +#include "main/core.h" /* for struct gl_program */ +#include "program/hash_table.h" +} +#include "ir.h" +#include "ir_visitor.h" +#include "glsl_types.h" + +class ir_set_program_inouts_visitor : public ir_hierarchical_visitor { +public: + ir_set_program_inouts_visitor(struct gl_program *prog) + { + this->prog = prog; + this->ht = hash_table_ctor(0, + hash_table_pointer_hash, + hash_table_pointer_compare); + } + ~ir_set_program_inouts_visitor() + { + hash_table_dtor(this->ht); + } + + virtual ir_visitor_status visit_enter(ir_dereference_array *); + virtual ir_visitor_status visit_enter(ir_function_signature *); + virtual ir_visitor_status visit(ir_dereference_variable *); + virtual ir_visitor_status visit(ir_variable *); + + struct gl_program *prog; + struct hash_table *ht; +}; + +static void +mark(struct gl_program *prog, ir_variable *var, int offset, int len) +{ + /* As of GLSL 1.20, varyings can only be floats, floating-point + * vectors or matrices, or arrays of them. For Mesa programs using + * InputsRead/OutputsWritten, everything but matrices uses one + * slot, while matrices use a slot per column. Presumably + * something doing a more clever packing would use something other + * than InputsRead/OutputsWritten. + */ + + for (int i = 0; i < len; i++) { + if (var->mode == ir_var_in) + prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i); + else if (var->mode == ir_var_system_value) + prog->SystemValuesRead |= (1 << (var->location + offset + i)); + else + prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i); + } +} + +/* Default handler: Mark all the locations in the variable as used. */ +ir_visitor_status +ir_set_program_inouts_visitor::visit(ir_dereference_variable *ir) +{ + if (hash_table_find(this->ht, ir->var) == NULL) + return visit_continue; + + if (ir->type->is_array()) { + mark(this->prog, ir->var, 0, + ir->type->length * ir->type->fields.array->matrix_columns); + } else { + mark(this->prog, ir->var, 0, ir->type->matrix_columns); + } + + return visit_continue; +} + +ir_visitor_status +ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir) +{ + ir_dereference_variable *deref_var; + ir_constant *index = ir->array_index->as_constant(); + deref_var = ir->array->as_dereference_variable(); + ir_variable *var = NULL; + + /* Check that we're dereferencing a shader in or out */ + if (deref_var) + var = (ir_variable *)hash_table_find(this->ht, deref_var->var); + + if (index && var) { + int width = 1; + + if (deref_var->type->is_array() && + deref_var->type->fields.array->is_matrix()) { + width = deref_var->type->fields.array->matrix_columns; + } + + mark(this->prog, var, index->value.i[0] * width, width); + return visit_continue_with_parent; + } + + return visit_continue; +} + +ir_visitor_status +ir_set_program_inouts_visitor::visit(ir_variable *ir) +{ + if (ir->mode == ir_var_in || + ir->mode == ir_var_out || + ir->mode == ir_var_system_value) { + hash_table_insert(this->ht, ir, ir); + } + + return visit_continue; +} + +ir_visitor_status +ir_set_program_inouts_visitor::visit_enter(ir_function_signature *ir) +{ + /* We don't want to descend into the function parameters and + * consider them as shader inputs or outputs. + */ + visit_list_elements(this, &ir->body); + return visit_continue_with_parent; +} + +void +do_set_program_inouts(exec_list *instructions, struct gl_program *prog) +{ + ir_set_program_inouts_visitor v(prog); + + prog->InputsRead = 0; + prog->OutputsWritten = 0; + prog->SystemValuesRead = 0; + visit_list_elements(&v, instructions); +} diff --git a/mesalib/src/glsl/ir_variable.cpp b/mesalib/src/glsl/ir_variable.cpp index b8487694c..e0b6f38f1 100644 --- a/mesalib/src/glsl/ir_variable.cpp +++ b/mesalib/src/glsl/ir_variable.cpp @@ -584,6 +584,17 @@ generate_120_vs_variables(exec_list *instructions, } +static void +generate_130_uniforms(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + glsl_symbol_table *const symtab = state->symbols; + + add_builtin_constant(instructions, symtab, "gl_MaxClipDistances", + state->Const.MaxClipPlanes); +} + + static void generate_130_vs_variables(exec_list *instructions, struct _mesa_glsl_parse_state *state) @@ -595,9 +606,20 @@ generate_130_vs_variables(exec_list *instructions, & builtin_130_vs_variables[i]); } + generate_130_uniforms(instructions, state); + + /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special + * Variables): + * + * The gl_ClipDistance array is predeclared as unsized and must + * be sized by the shader either redeclaring it with a size or + * indexing it only with integral constant expressions. + * + * We represent this in Mesa by initially declaring the array as + * size 0. + */ const glsl_type *const clip_distance_array_type = - glsl_type::get_array_instance(glsl_type::float_type, - state->Const.MaxClipPlanes); + glsl_type::get_array_instance(glsl_type::float_type, 0); /* FINISHME: gl_ClipDistance needs a real location assigned. */ add_variable(instructions, state->symbols, @@ -802,9 +824,22 @@ generate_130_fs_variables(exec_list *instructions, { generate_120_fs_variables(instructions, state); + generate_130_uniforms(instructions, state); + + /* From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special + * Variables): + * + * The built-in input variable gl_ClipDistance array contains linearly + * interpolated values for the vertex values written by the vertex shader + * to the gl_ClipDistance vertex output variable. This array must be + * sized in the fragment shader either implicitly or explicitly to be the + * same size as it was sized in the vertex shader. + * + * In other words, the array must be pre-declared as implicitly sized. We + * represent this in Mesa by initially declaring the array as size 0. + */ const glsl_type *const clip_distance_array_type = - glsl_type::get_array_instance(glsl_type::float_type, - state->Const.MaxClipPlanes); + glsl_type::get_array_instance(glsl_type::float_type, 0); /* FINISHME: gl_ClipDistance needs a real location assigned. */ add_variable(instructions, state->symbols, diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp index ba81c59ff..195f58f29 100644 --- a/mesalib/src/glsl/linker.cpp +++ b/mesalib/src/glsl/linker.cpp @@ -262,6 +262,25 @@ validate_vertex_shader_executable(struct gl_shader_program *prog, return false; } + if (prog->Version >= 130) { + /* From section 7.1 (Vertex Shader Special Variables) of the + * GLSL 1.30 spec: + * + * "It is an error for a shader to statically write both + * gl_ClipVertex and gl_ClipDistance." + */ + find_assignment_visitor clip_vertex("gl_ClipVertex"); + find_assignment_visitor clip_distance("gl_ClipDistance"); + + clip_vertex.run(shader->ir); + clip_distance.run(shader->ir); + if (clip_vertex.variable_found() && clip_distance.variable_found()) { + linker_error(prog, "vertex shader writes to both `gl_ClipVertex' " + "and `gl_ClipDistance'\n"); + return false; + } + } + return true; } -- cgit v1.2.3