diff options
author | marha <marha@users.sourceforge.net> | 2013-10-16 11:23:27 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2013-10-16 11:23:27 +0200 |
commit | 9e23b44bfe1e6e85231b1c07d945cadf0c868648 (patch) | |
tree | 0bd2b4d0521570bf020452591c895b90bda51095 /mesalib/src/glsl | |
parent | 81fd17c8678e89cea6610b8b2996b028b21eb5dc (diff) | |
download | vcxsrv-9e23b44bfe1e6e85231b1c07d945cadf0c868648.tar.gz vcxsrv-9e23b44bfe1e6e85231b1c07d945cadf0c868648.tar.bz2 vcxsrv-9e23b44bfe1e6e85231b1c07d945cadf0c868648.zip |
fontconfig libxcb libxcb/xcb-proto xserver mesa pixman xkbcomp git update 16 oct 2013
xserver commit 7cf1b595c8c8f9776a39559d2878cf90af3f2859
libxcb commit e4e0c6eec861f4c69da12060dc8dbe7a63fa5eb6
libxcb/xcb-proto commit 55c75accecf0e76d2aa38656efd2be4044b9e643
xkbcomp commit 839ccda42d8b088d94324cd77c4be954859914d3
pixman commit 9e81419ed5c0ee490ddacf7bada516a25cae87eb
fontconfig commit 5406919c5e186f74ccdade1a65344ce7b5c56a64
mesa commit 6e444a72c1f9e4446e025b8cb780523cb89f0584
Diffstat (limited to 'mesalib/src/glsl')
33 files changed, 1481 insertions, 284 deletions
diff --git a/mesalib/src/glsl/.dir-locals.el b/mesalib/src/glsl/.dir-locals.el deleted file mode 100644 index be19e29a5..000000000 --- a/mesalib/src/glsl/.dir-locals.el +++ /dev/null @@ -1,3 +0,0 @@ -((c-mode . ((c-basic-offset . 3))) - (c++-mode . ((c-basic-offset . 3))) -) diff --git a/mesalib/src/glsl/Makefile.am b/mesalib/src/glsl/Makefile.am index 2e161b844..cbf253cb5 100644 --- a/mesalib/src/glsl/Makefile.am +++ b/mesalib/src/glsl/Makefile.am @@ -49,6 +49,8 @@ check_PROGRAMS = \ tests/sampler-types-test \ tests/uniform-initializer-test +noinst_PROGRAMS = glsl_compiler + tests_uniform_initializer_test_SOURCES = \ $(top_srcdir)/src/mesa/main/hash_table.c \ $(top_srcdir)/src/mesa/main/imports.c \ @@ -99,6 +101,15 @@ libglsl_la_SOURCES = \ glsl_parser.cpp \ $(LIBGLSL_FILES) +glsl_compiler_SOURCES = \ + $(top_srcdir)/src/mesa/main/hash_table.c \ + $(top_srcdir)/src/mesa/main/imports.c \ + $(top_srcdir)/src/mesa/program/prog_hash_table.c \ + $(top_srcdir)/src/mesa/program/symbol_table.c \ + $(GLSL_COMPILER_CXX_FILES) + +glsl_compiler_LDADD = libglsl.la + glsl_test_SOURCES = \ $(top_srcdir)/src/mesa/main/hash_table.c \ $(top_srcdir)/src/mesa/main/imports.c \ diff --git a/mesalib/src/glsl/SConscript b/mesalib/src/glsl/SConscript index e386bdfb1..fe9d50732 100644 --- a/mesalib/src/glsl/SConscript +++ b/mesalib/src/glsl/SConscript @@ -98,11 +98,11 @@ if env['platform'] == 'windows': env.Prepend(LIBS = [glsl]) -glsl2 = env.Program( - target = 'glsl2', +glsl_compiler = env.Program( + target = 'glsl_compiler', source = compiler_objs, ) -env.Alias('glsl2', glsl2) +env.Alias('glsl_compiler', glsl_compiler) glcpp = env.Program( target = 'glcpp/glcpp', diff --git a/mesalib/src/glsl/ast_array_index.cpp b/mesalib/src/glsl/ast_array_index.cpp index 51f6b10f3..da96cc10e 100644 --- a/mesalib/src/glsl/ast_array_index.cpp +++ b/mesalib/src/glsl/ast_array_index.cpp @@ -25,6 +25,71 @@ #include "glsl_types.h" #include "ir.h" + +/** + * If \c ir is a reference to an array for which we are tracking the max array + * element accessed, track that the given element has been accessed. + * Otherwise do nothing. + * + * This function also checks whether the array is a built-in array whose + * maximum size is too small to accommodate the given index, and if so uses + * loc and state to report the error. + */ +static void +update_max_array_access(ir_rvalue *ir, unsigned idx, YYLTYPE *loc, + struct _mesa_glsl_parse_state *state) +{ + if (ir_dereference_variable *deref_var = ir->as_dereference_variable()) { + ir_variable *var = deref_var->var; + if (idx > var->max_array_access) { + var->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. + */ + check_builtin_array_max_size(var->name, idx+1, *loc, state); + } + } else if (ir_dereference_record *deref_record = + ir->as_dereference_record()) { + /* There are two possibilities we need to consider: + * + * - Accessing an element of an array that is a member of a named + * interface block (e.g. ifc.foo[i]) + * + * - Accessing an element of an array that is a member of a named + * interface block array (e.g. ifc[j].foo[i]). + */ + ir_dereference_variable *deref_var = + deref_record->record->as_dereference_variable(); + if (deref_var == NULL) { + if (ir_dereference_array *deref_array = + deref_record->record->as_dereference_array()) { + deref_var = deref_array->array->as_dereference_variable(); + } + } + + if (deref_var != NULL) { + const glsl_type *interface_type = + deref_var->var->get_interface_type(); + if (interface_type != NULL) { + unsigned field_index = + deref_record->record->type->field_index(deref_record->field); + assert(field_index < interface_type->length); + if (idx > deref_var->var->max_ifc_array_access[field_index]) { + deref_var->var->max_ifc_array_access[field_index] = idx; + + /* Check whether this access will, as a side effect, implicitly + * cause the size of a built-in array to be too large. + */ + check_builtin_array_max_size(deref_record->field, idx+1, *loc, + state); + } + } + } + } +} + + ir_rvalue * _mesa_ast_array_index_to_hir(void *mem_ctx, struct _mesa_glsl_parse_state *state, @@ -97,23 +162,8 @@ _mesa_ast_array_index_to_hir(void *mem_ctx, type_name); } - if (array->type->is_array()) { - /* If the array is a variable dereference, it dereferences the - * whole array, by definition. Use this to get the variable. - * - * FINISHME: Should some methods for getting / setting / testing - * 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)) { - 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. - */ - check_builtin_array_max_size(v->name, idx+1, loc, state); - } - } + if (array->type->is_array()) + update_max_array_access(array, idx, &loc, state); } else if (const_index == NULL && array->type->is_array()) { if (array->type->array_size() == 0) { _mesa_glsl_error(&loc, state, "unsized array index must be constant"); diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp index 0859d9e00..dfa32d920 100644 --- a/mesalib/src/glsl/ast_to_hir.cpp +++ b/mesalib/src/glsl/ast_to_hir.cpp @@ -2326,9 +2326,10 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, * A pointer to an existing variable in the current scope if the declaration * is a redeclaration, \c NULL otherwise. */ -ir_variable * -get_variable_being_redeclared(ir_variable *var, ast_declaration *decl, - struct _mesa_glsl_parse_state *state) +static ir_variable * +get_variable_being_redeclared(ir_variable *var, YYLTYPE loc, + struct _mesa_glsl_parse_state *state, + bool allow_all_redeclarations) { /* Check if this declaration is actually a re-declaration, either to * resize an array or add qualifiers to an existing variable. @@ -2336,16 +2337,14 @@ get_variable_being_redeclared(ir_variable *var, ast_declaration *decl, * This is allowed for variables in the current scope, or when at * global scope (for built-ins in the implicit outer scope). */ - ir_variable *earlier = state->symbols->get_variable(decl->identifier); + ir_variable *earlier = state->symbols->get_variable(var->name); if (earlier == NULL || (state->current_function != NULL && - !state->symbols->name_declared_this_scope(decl->identifier))) { + !state->symbols->name_declared_this_scope(var->name))) { return NULL; } - YYLTYPE loc = decl->get_location(); - /* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec, * * "It is legal to declare an array without a size and then @@ -2433,8 +2432,18 @@ get_variable_being_redeclared(ir_variable *var, ast_declaration *decl, earlier->depth_layout = var->depth_layout; + } else if (allow_all_redeclarations) { + if (earlier->mode != var->mode) { + _mesa_glsl_error(&loc, state, + "redeclaration of `%s' with incorrect qualifiers", + var->name); + } else if (earlier->type != var->type) { + _mesa_glsl_error(&loc, state, + "redeclaration of `%s' has incorrect type", + var->name); + } } else { - _mesa_glsl_error(&loc, state, "`%s' redeclared", decl->identifier); + _mesa_glsl_error(&loc, state, "`%s' redeclared", var->name); } return earlier; @@ -2649,6 +2658,36 @@ handle_geometry_shader_input_decl(struct _mesa_glsl_parse_state *state, } } + +void +validate_identifier(const char *identifier, YYLTYPE loc, + struct _mesa_glsl_parse_state *state) +{ + /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec, + * + * "Identifiers starting with "gl_" are reserved for use by + * OpenGL, and may not be declared in a shader as either a + * variable or a function." + */ + if (strncmp(identifier, "gl_", 3) == 0) { + _mesa_glsl_error(&loc, state, + "identifier `%s' uses reserved `gl_' prefix", + identifier); + } else if (strstr(identifier, "__")) { + /* From page 14 (page 20 of the PDF) of the GLSL 1.10 + * spec: + * + * "In addition, all identifiers containing two + * consecutive underscores (__) are reserved as + * possible future keywords." + */ + _mesa_glsl_error(&loc, state, + "identifier `%s' uses reserved `__' string", + identifier); + } +} + + ir_rvalue * ast_declarator_list::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) @@ -3191,7 +3230,9 @@ ast_declarator_list::hir(exec_list *instructions, * instruction stream. */ exec_list initializer_instructions; - ir_variable *earlier = get_variable_being_redeclared(var, decl, state); + ir_variable *earlier = + get_variable_being_redeclared(var, decl->get_location(), state, + false /* allow_all_redeclarations */); if (decl->initializer != NULL) { result = process_initializer((earlier == NULL) ? var : earlier, @@ -3243,28 +3284,7 @@ ast_declarator_list::hir(exec_list *instructions, * created for the declaration should be added to the IR stream. */ if (earlier == NULL) { - /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec, - * - * "Identifiers starting with "gl_" are reserved for use by - * OpenGL, and may not be declared in a shader as either a - * variable or a function." - */ - if (strncmp(decl->identifier, "gl_", 3) == 0) - _mesa_glsl_error(& loc, state, - "identifier `%s' uses reserved `gl_' prefix", - decl->identifier); - else if (strstr(decl->identifier, "__")) { - /* From page 14 (page 20 of the PDF) of the GLSL 1.10 - * spec: - * - * "In addition, all identifiers containing two - * consecutive underscores (__) are reserved as - * possible future keywords." - */ - _mesa_glsl_error(& loc, state, - "identifier `%s' uses reserved `__' string", - decl->identifier); - } + validate_identifier(decl->identifier, loc, state); /* Add the variable to the symbol table. Note that the initializer's * IR was already processed earlier (though it hasn't been emitted @@ -3505,17 +3525,7 @@ ast_function::hir(exec_list *instructions, "function body", name); } - /* From page 15 (page 21 of the PDF) of the GLSL 1.10 spec, - * - * "Identifiers starting with "gl_" are reserved for use by - * OpenGL, and may not be declared in a shader as either a - * variable or a function." - */ - if (strncmp(name, "gl_", 3) == 0) { - YYLTYPE loc = this->get_location(); - _mesa_glsl_error(&loc, state, - "identifier `%s' uses reserved `gl_' prefix", name); - } + validate_identifier(name, this->get_location(), state); /* Convert the list of function parameters to HIR now so that they can be * used below to compare this function's signature with previously seen @@ -4411,7 +4421,8 @@ ast_process_structure_or_interface_block(exec_list *instructions, YYLTYPE &loc, glsl_struct_field **fields_ret, bool is_interface, - bool block_row_major) + bool block_row_major, + bool allow_reserved_names) { unsigned decl_count = 0; @@ -4453,6 +4464,9 @@ ast_process_structure_or_interface_block(exec_list *instructions, foreach_list_typed (ast_declaration, decl, link, &decl_list->declarations) { + if (!allow_reserved_names) + validate_identifier(decl->identifier, loc, state); + /* From the GL_ARB_uniform_buffer_object spec: * * "Sampler types are not allowed inside of uniform @@ -4491,6 +4505,7 @@ ast_process_structure_or_interface_block(exec_list *instructions, } fields[i].type = field_type; fields[i].name = decl->identifier; + fields[i].location = -1; if (qual->flags.q.row_major || qual->flags.q.column_major) { if (!qual->flags.q.uniform) { @@ -4568,7 +4583,10 @@ ast_struct_specifier::hir(exec_list *instructions, loc, &fields, false, - false); + false, + false /* allow_reserved_names */); + + validate_identifier(this->name, loc, state); const glsl_type *t = glsl_type::get_record_instance(fields, decl_count, this->name); @@ -4593,6 +4611,39 @@ ast_struct_specifier::hir(exec_list *instructions, return NULL; } + +/** + * Visitor class which detects whether a given interface block has been used. + */ +class interface_block_usage_visitor : public ir_hierarchical_visitor +{ +public: + interface_block_usage_visitor(ir_variable_mode mode, const glsl_type *block) + : mode(mode), block(block), found(false) + { + } + + virtual ir_visitor_status visit(ir_dereference_variable *ir) + { + if (ir->var->mode == mode && ir->var->get_interface_type() == block) { + found = true; + return visit_stop; + } + return visit_continue; + } + + bool usage_found() const + { + return this->found; + } + +private: + ir_variable_mode mode; + const glsl_type *block; + bool found; +}; + + ir_rvalue * ast_interface_block::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) @@ -4614,6 +4665,7 @@ ast_interface_block::hir(exec_list *instructions, packing = GLSL_INTERFACE_PACKING_STD140; } + bool redeclaring_per_vertex = strcmp(this->block_name, "gl_PerVertex") == 0; bool block_row_major = this->layout.flags.q.row_major; exec_list declared_variables; glsl_struct_field *fields; @@ -4624,7 +4676,8 @@ ast_interface_block::hir(exec_list *instructions, loc, &fields, true, - block_row_major); + block_row_major, + redeclaring_per_vertex); ir_variable_mode var_mode; const char *iface_type_name; @@ -4643,6 +4696,102 @@ ast_interface_block::hir(exec_list *instructions, assert(!"interface block layout qualifier not found!"); } + if (!redeclaring_per_vertex) + validate_identifier(this->block_name, loc, state); + + const glsl_type *earlier_per_vertex = NULL; + if (redeclaring_per_vertex) { + /* Find the previous declaration of gl_PerVertex. If we're redeclaring + * the named interface block gl_in, we can find it by looking at the + * previous declaration of gl_in. Otherwise we can find it by looking + * at the previous decalartion of any of the built-in outputs, + * e.g. gl_Position. + * + * Also check that the instance name and array-ness of the redeclaration + * are correct. + */ + switch (var_mode) { + case ir_var_shader_in: + if (ir_variable *earlier_gl_in = + state->symbols->get_variable("gl_in")) { + earlier_per_vertex = earlier_gl_in->get_interface_type(); + } else { + _mesa_glsl_error(&loc, state, + "redeclaration of gl_PerVertex input not allowed " + "in the %s shader", + _mesa_glsl_shader_target_name(state->target)); + } + if (this->instance_name == NULL || + strcmp(this->instance_name, "gl_in") != 0 || !this->is_array) { + _mesa_glsl_error(&loc, state, + "gl_PerVertex input must be redeclared as " + "gl_in[]"); + } + break; + case ir_var_shader_out: + if (ir_variable *earlier_gl_Position = + state->symbols->get_variable("gl_Position")) { + earlier_per_vertex = earlier_gl_Position->get_interface_type(); + } else { + _mesa_glsl_error(&loc, state, + "redeclaration of gl_PerVertex output not " + "allowed in the %s shader", + _mesa_glsl_shader_target_name(state->target)); + } + if (this->instance_name != NULL) { + _mesa_glsl_error(&loc, state, + "gl_PerVertex input may not be redeclared with " + "an instance name"); + } + break; + default: + _mesa_glsl_error(&loc, state, + "gl_PerVertex must be declared as an input or an " + "output"); + break; + } + + if (earlier_per_vertex == NULL) { + /* An error has already been reported. Bail out to avoid null + * dereferences later in this function. + */ + return NULL; + } + + /* Copy locations from the old gl_PerVertex interface block. */ + for (unsigned i = 0; i < num_variables; i++) { + int j = earlier_per_vertex->field_index(fields[i].name); + if (j == -1) { + _mesa_glsl_error(&loc, state, + "redeclaration of gl_PerVertex must be a subset " + "of the built-in members of gl_PerVertex"); + } else { + fields[i].location = + earlier_per_vertex->fields.structure[j].location; + } + } + + /* From section 7.1 ("Built-in Language Variables") of the GLSL 4.10 + * spec: + * + * If a built-in interface block is redeclared, it must appear in + * the shader before any use of any member included in the built-in + * declaration, or a compilation error will result. + * + * This appears to be a clarification to the behaviour established for + * gl_PerVertex by GLSL 1.50, therefore we implement this behaviour + * regardless of GLSL version. + */ + interface_block_usage_visitor v(var_mode, earlier_per_vertex); + v.run(instructions); + if (v.usage_found()) { + _mesa_glsl_error(&loc, state, + "redeclaration of a built-in interface block must " + "appear before any use of any member of the " + "interface block"); + } + } + const glsl_type *block_type = glsl_type::get_interface_instance(fields, num_variables, @@ -4682,6 +4831,9 @@ ast_interface_block::hir(exec_list *instructions, * field selector ( . ) operator (analogously to structures)." */ if (this->instance_name) { + if (!redeclaring_per_vertex) + validate_identifier(this->instance_name, loc, state); + ir_variable *var; if (this->is_array) { @@ -4724,11 +4876,23 @@ ast_interface_block::hir(exec_list *instructions, var_mode); } - var->interface_type = block_type; + var->init_interface_type(block_type); if (state->target == geometry_shader && var_mode == ir_var_shader_in) handle_geometry_shader_input_decl(state, loc, var); - state->symbols->add_variable(var); - instructions->push_tail(var); + + if (ir_variable *earlier = + state->symbols->get_variable(this->instance_name)) { + if (!redeclaring_per_vertex) { + _mesa_glsl_error(&loc, state, "`%s' redeclared", + this->instance_name); + } + earlier->type = var->type; + earlier->reinit_interface_type(block_type); + delete var; + } else { + state->symbols->add_variable(var); + instructions->push_tail(var); + } } else { /* In order to have an array size, the block must also be declared with * an instane name. @@ -4740,7 +4904,24 @@ ast_interface_block::hir(exec_list *instructions, new(state) ir_variable(fields[i].type, ralloc_strdup(state, fields[i].name), var_mode); - var->interface_type = block_type; + var->init_interface_type(block_type); + + if (redeclaring_per_vertex) { + ir_variable *earlier = + get_variable_being_redeclared(var, loc, state, + true /* allow_all_redeclarations */); + if (strncmp(var->name, "gl_", 3) != 0 || earlier == NULL) { + _mesa_glsl_error(&loc, state, + "redeclaration of gl_PerVertex can only " + "include built-in variables"); + } else { + earlier->reinit_interface_type(block_type); + } + continue; + } + + if (state->symbols->get_variable(var->name) != NULL) + _mesa_glsl_error(&loc, state, "`%s' redeclared", var->name); /* Propagate the "binding" keyword into this UBO's fields; * the UBO declaration itself doesn't get an ir_variable unless it @@ -4752,6 +4933,38 @@ ast_interface_block::hir(exec_list *instructions, state->symbols->add_variable(var); instructions->push_tail(var); } + + if (redeclaring_per_vertex && block_type != earlier_per_vertex) { + /* From section 7.1 ("Built-in Language Variables") of the GLSL 4.10 spec: + * + * It is also a compilation error ... to redeclare a built-in + * block and then use a member from that built-in block that was + * not included in the redeclaration. + * + * This appears to be a clarification to the behaviour established + * for gl_PerVertex by GLSL 1.50, therefore we implement this + * behaviour regardless of GLSL version. + * + * To prevent the shader from using a member that was not included in + * the redeclaration, we disable any ir_variables that are still + * associated with the old declaration of gl_PerVertex (since we've + * already updated all of the variables contained in the new + * gl_PerVertex to point to it). + * + * As a side effect this will prevent + * validate_intrastage_interface_blocks() from getting confused and + * thinking there are conflicting definitions of gl_PerVertex in the + * shader. + */ + foreach_list_safe(node, instructions) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + if (var != NULL && + var->get_interface_type() == earlier_per_vertex) { + state->symbols->disable_variable(var->name); + var->remove(); + } + } + } } return NULL; diff --git a/mesalib/src/glsl/builtin_functions.cpp b/mesalib/src/glsl/builtin_functions.cpp index b6451089c..d40888d38 100644 --- a/mesalib/src/glsl/builtin_functions.cpp +++ b/mesalib/src/glsl/builtin_functions.cpp @@ -531,6 +531,9 @@ private: B1(fma) B2(ldexp) B2(frexp) + B1(uaddCarry) + B1(usubBorrow) + B1(mulExtended) #undef B0 #undef B1 #undef B2 @@ -1947,6 +1950,30 @@ builtin_builder::create_builtins() _frexp(glsl_type::vec3_type, glsl_type::ivec3_type), _frexp(glsl_type::vec4_type, glsl_type::ivec4_type), NULL); + add_function("uaddCarry", + _uaddCarry(glsl_type::uint_type), + _uaddCarry(glsl_type::uvec2_type), + _uaddCarry(glsl_type::uvec3_type), + _uaddCarry(glsl_type::uvec4_type), + NULL); + add_function("usubBorrow", + _usubBorrow(glsl_type::uint_type), + _usubBorrow(glsl_type::uvec2_type), + _usubBorrow(glsl_type::uvec3_type), + _usubBorrow(glsl_type::uvec4_type), + NULL); + add_function("imulExtended", + _mulExtended(glsl_type::int_type), + _mulExtended(glsl_type::ivec2_type), + _mulExtended(glsl_type::ivec3_type), + _mulExtended(glsl_type::ivec4_type), + NULL); + add_function("umulExtended", + _mulExtended(glsl_type::uint_type), + _mulExtended(glsl_type::uvec2_type), + _mulExtended(glsl_type::uvec3_type), + _mulExtended(glsl_type::uvec4_type), + NULL); #undef F #undef FI #undef FIU @@ -3720,6 +3747,52 @@ builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type) return sig; } + +ir_function_signature * +builtin_builder::_uaddCarry(const glsl_type *type) +{ + ir_variable *x = in_var(type, "x"); + ir_variable *y = in_var(type, "y"); + ir_variable *carry = out_var(type, "carry"); + MAKE_SIG(type, gpu_shader5, 3, x, y, carry); + + body.emit(assign(carry, ir_builder::carry(x, y))); + body.emit(ret(add(x, y))); + + return sig; +} + +ir_function_signature * +builtin_builder::_usubBorrow(const glsl_type *type) +{ + ir_variable *x = in_var(type, "x"); + ir_variable *y = in_var(type, "y"); + ir_variable *borrow = out_var(type, "borrow"); + MAKE_SIG(type, gpu_shader5, 3, x, y, borrow); + + body.emit(assign(borrow, ir_builder::borrow(x, y))); + body.emit(ret(sub(x, y))); + + return sig; +} + +/** + * For both imulExtended() and umulExtended() built-ins. + */ +ir_function_signature * +builtin_builder::_mulExtended(const glsl_type *type) +{ + ir_variable *x = in_var(type, "x"); + ir_variable *y = in_var(type, "y"); + ir_variable *msb = out_var(type, "msb"); + ir_variable *lsb = out_var(type, "lsb"); + MAKE_SIG(glsl_type::void_type, gpu_shader5, 4, x, y, msb, lsb); + + body.emit(assign(msb, imul_high(x, y))); + body.emit(assign(lsb, mul(x, y))); + + return sig; +} /** @} */ /******************************************************************************/ diff --git a/mesalib/src/glsl/builtin_types.cpp b/mesalib/src/glsl/builtin_types.cpp index 722eda2da..1a5e5a190 100644 --- a/mesalib/src/glsl/builtin_types.cpp +++ b/mesalib/src/glsl/builtin_types.cpp @@ -53,64 +53,64 @@ &glsl_type::_struct_##NAME##_type; static const struct glsl_struct_field gl_DepthRangeParameters_fields[] = { - { glsl_type::float_type, "near", false }, - { glsl_type::float_type, "far", false }, - { glsl_type::float_type, "diff", false }, + { glsl_type::float_type, "near", false, -1 }, + { glsl_type::float_type, "far", false, -1 }, + { glsl_type::float_type, "diff", false, -1 }, }; static const struct glsl_struct_field gl_PointParameters_fields[] = { - { glsl_type::float_type, "size", false }, - { glsl_type::float_type, "sizeMin", false }, - { glsl_type::float_type, "sizeMax", false }, - { glsl_type::float_type, "fadeThresholdSize", false }, - { glsl_type::float_type, "distanceConstantAttenuation", false }, - { glsl_type::float_type, "distanceLinearAttenuation", false }, - { glsl_type::float_type, "distanceQuadraticAttenuation", false }, + { glsl_type::float_type, "size", false, -1 }, + { glsl_type::float_type, "sizeMin", false, -1 }, + { glsl_type::float_type, "sizeMax", false, -1 }, + { glsl_type::float_type, "fadeThresholdSize", false, -1 }, + { glsl_type::float_type, "distanceConstantAttenuation", false, -1 }, + { glsl_type::float_type, "distanceLinearAttenuation", false, -1 }, + { glsl_type::float_type, "distanceQuadraticAttenuation", false, -1 }, }; static const struct glsl_struct_field gl_MaterialParameters_fields[] = { - { glsl_type::vec4_type, "emission", false }, - { glsl_type::vec4_type, "ambient", false }, - { glsl_type::vec4_type, "diffuse", false }, - { glsl_type::vec4_type, "specular", false }, - { glsl_type::float_type, "shininess", false }, + { glsl_type::vec4_type, "emission", false, -1 }, + { glsl_type::vec4_type, "ambient", false, -1 }, + { glsl_type::vec4_type, "diffuse", false, -1 }, + { glsl_type::vec4_type, "specular", false, -1 }, + { glsl_type::float_type, "shininess", false, -1 }, }; static const struct glsl_struct_field gl_LightSourceParameters_fields[] = { - { glsl_type::vec4_type, "ambient", false }, - { glsl_type::vec4_type, "diffuse", false }, - { glsl_type::vec4_type, "specular", false }, - { glsl_type::vec4_type, "position", false }, - { glsl_type::vec4_type, "halfVector", false }, - { glsl_type::vec3_type, "spotDirection", false }, - { glsl_type::float_type, "spotExponent", false }, - { glsl_type::float_type, "spotCutoff", false }, - { glsl_type::float_type, "spotCosCutoff", false }, - { glsl_type::float_type, "constantAttenuation", false }, - { glsl_type::float_type, "linearAttenuation", false }, - { glsl_type::float_type, "quadraticAttenuation", false }, + { glsl_type::vec4_type, "ambient", false, -1 }, + { glsl_type::vec4_type, "diffuse", false, -1 }, + { glsl_type::vec4_type, "specular", false, -1 }, + { glsl_type::vec4_type, "position", false, -1 }, + { glsl_type::vec4_type, "halfVector", false, -1 }, + { glsl_type::vec3_type, "spotDirection", false, -1 }, + { glsl_type::float_type, "spotExponent", false, -1 }, + { glsl_type::float_type, "spotCutoff", false, -1 }, + { glsl_type::float_type, "spotCosCutoff", false, -1 }, + { glsl_type::float_type, "constantAttenuation", false, -1 }, + { glsl_type::float_type, "linearAttenuation", false, -1 }, + { glsl_type::float_type, "quadraticAttenuation", false, -1 }, }; static const struct glsl_struct_field gl_LightModelParameters_fields[] = { - { glsl_type::vec4_type, "ambient", false }, + { glsl_type::vec4_type, "ambient", false, -1 }, }; static const struct glsl_struct_field gl_LightModelProducts_fields[] = { - { glsl_type::vec4_type, "sceneColor", false }, + { glsl_type::vec4_type, "sceneColor", false, -1 }, }; static const struct glsl_struct_field gl_LightProducts_fields[] = { - { glsl_type::vec4_type, "ambient", false }, - { glsl_type::vec4_type, "diffuse", false }, - { glsl_type::vec4_type, "specular", false }, + { glsl_type::vec4_type, "ambient", false, -1 }, + { glsl_type::vec4_type, "diffuse", false, -1 }, + { glsl_type::vec4_type, "specular", false, -1 }, }; static const struct glsl_struct_field gl_FogParameters_fields[] = { - { glsl_type::vec4_type, "color", false }, - { glsl_type::float_type, "density", false }, - { glsl_type::float_type, "start", false }, - { glsl_type::float_type, "end", false }, - { glsl_type::float_type, "scale", false }, + { glsl_type::vec4_type, "color", false, -1 }, + { glsl_type::float_type, "density", false, -1 }, + { glsl_type::float_type, "start", false, -1 }, + { glsl_type::float_type, "end", false, -1 }, + { glsl_type::float_type, "scale", false, -1 }, }; #include "builtin_type_macros.h" diff --git a/mesalib/src/glsl/builtin_variables.cpp b/mesalib/src/glsl/builtin_variables.cpp index 6a808c072..f06d2ab05 100644 --- a/mesalib/src/glsl/builtin_variables.cpp +++ b/mesalib/src/glsl/builtin_variables.cpp @@ -293,6 +293,51 @@ static const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = { namespace { +/** + * Data structure that accumulates fields for the gl_PerVertex interface + * block. + */ +class per_vertex_accumulator +{ +public: + per_vertex_accumulator(); + void add_field(int slot, const glsl_type *type, const char *name); + const glsl_type *construct_interface_instance() const; + +private: + glsl_struct_field fields[10]; + unsigned num_fields; +}; + + +per_vertex_accumulator::per_vertex_accumulator() + : num_fields(0) +{ +} + + +void +per_vertex_accumulator::add_field(int slot, const glsl_type *type, + const char *name) +{ + assert(this->num_fields < ARRAY_SIZE(this->fields)); + this->fields[this->num_fields].type = type; + this->fields[this->num_fields].name = name; + this->fields[this->num_fields].row_major = false; + this->fields[this->num_fields].location = slot; + this->num_fields++; +} + + +const glsl_type * +per_vertex_accumulator::construct_interface_instance() const +{ + return glsl_type::get_interface_instance(this->fields, this->num_fields, + GLSL_INTERFACE_PACKING_STD140, + "gl_PerVertex"); +} + + class builtin_variable_generator { public: @@ -358,6 +403,9 @@ private: const glsl_type * const vec4_t; const glsl_type * const mat3_t; const glsl_type * const mat4_t; + + per_vertex_accumulator per_vertex_in; + per_vertex_accumulator per_vertex_out; }; @@ -497,11 +545,12 @@ builtin_variable_generator::generate_constants() */ if (state->is_version(0, 300)) { add_const("gl_MaxVertexOutputVectors", - state->Const.MaxVaryingFloats / 4); + state->ctx->Const.VertexProgram.MaxOutputComponents / 4); add_const("gl_MaxFragmentInputVectors", - state->Const.MaxVaryingFloats / 4); + state->ctx->Const.FragmentProgram.MaxInputComponents / 4); } else { - add_const("gl_MaxVaryingVectors", state->Const.MaxVaryingFloats / 4); + add_const("gl_MaxVaryingVectors", + state->ctx->Const.MaxVarying); } } else { add_const("gl_MaxVertexUniformComponents", @@ -510,7 +559,7 @@ builtin_variable_generator::generate_constants() /* Note: gl_MaxVaryingFloats was deprecated in GLSL 1.30+, but not * removed */ - add_const("gl_MaxVaryingFloats", state->Const.MaxVaryingFloats); + add_const("gl_MaxVaryingFloats", state->ctx->Const.MaxVarying * 4); add_const("gl_MaxFragmentUniformComponents", state->Const.MaxFragmentUniformComponents); @@ -531,7 +580,38 @@ builtin_variable_generator::generate_constants() if (state->is_version(130, 0)) { add_const("gl_MaxClipDistances", state->Const.MaxClipPlanes); - add_const("gl_MaxVaryingComponents", state->Const.MaxVaryingFloats); + add_const("gl_MaxVaryingComponents", state->ctx->Const.MaxVarying * 4); + } + + if (state->is_version(150, 0)) { + add_const("gl_MaxVertexOutputComponents", + state->Const.MaxVertexOutputComponents); + add_const("gl_MaxGeometryInputComponents", + state->Const.MaxGeometryInputComponents); + add_const("gl_MaxGeometryOutputComponents", + state->Const.MaxGeometryOutputComponents); + add_const("gl_MaxFragmentInputComponents", + state->Const.MaxFragmentInputComponents); + add_const("gl_MaxGeometryTextureImageUnits", + state->Const.MaxGeometryTextureImageUnits); + add_const("gl_MaxGeometryOutputVertices", + state->Const.MaxGeometryOutputVertices); + add_const("gl_MaxGeometryTotalOutputComponents", + state->Const.MaxGeometryTotalOutputComponents); + add_const("gl_MaxGeometryUniformComponents", + state->Const.MaxGeometryUniformComponents); + + /* Note: the GLSL 1.50-4.40 specs require + * gl_MaxGeometryVaryingComponents to be present, and to be at least 64. + * But they do not define what it means (and there does not appear to be + * any corresponding constant in the GL specs). However, + * ARB_geometry_shader4 defines MAX_GEOMETRY_VARYING_COMPONENTS_ARB to + * be the maximum number of components available for use as geometry + * outputs. So we assume this is a synonym for + * gl_MaxGeometryOutputComponents. + */ + add_const("gl_MaxGeometryVaryingComponents", + state->Const.MaxGeometryOutputComponents); } if (compatibility) { @@ -756,10 +836,10 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type, { switch (state->target) { case geometry_shader: - add_input(slot, array(type, 0), name_as_gs_input); + this->per_vertex_in.add_field(slot, type, name); /* FALLTHROUGH */ case vertex_shader: - add_output(slot, type, name); + this->per_vertex_out.add_field(slot, type, name); break; case fragment_shader: add_input(slot, type, name); @@ -803,6 +883,25 @@ builtin_variable_generator::generate_varyings() ADD_VARYING(VARYING_SLOT_BFC1, vec4_t, "gl_BackSecondaryColor"); } } + + if (state->target == geometry_shader) { + const glsl_type *per_vertex_in_type = + this->per_vertex_in.construct_interface_instance(); + ir_variable *var = add_variable("gl_in", array(per_vertex_in_type, 0), + ir_var_shader_in, -1); + var->init_interface_type(per_vertex_in_type); + } + if (state->target == vertex_shader || state->target == geometry_shader) { + const glsl_type *per_vertex_out_type = + this->per_vertex_out.construct_interface_instance(); + const glsl_struct_field *fields = per_vertex_out_type->fields.structure; + for (unsigned i = 0; i < per_vertex_out_type->length; i++) { + ir_variable *var = + add_variable(fields[i].name, fields[i].type, ir_var_shader_out, + fields[i].location); + var->init_interface_type(per_vertex_out_type); + } + } } diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy index 912931a47..a1d593fab 100644 --- a/mesalib/src/glsl/glsl_parser.yy +++ b/mesalib/src/glsl/glsl_parser.yy @@ -1752,6 +1752,12 @@ struct_declarator: $$ = new(ctx) ast_declaration($1, false, NULL, NULL); $$->set_location(yylloc); } + | any_identifier '[' ']' + { + void *ctx = state; + $$ = new(ctx) ast_declaration($1, true, NULL, NULL); + $$->set_location(yylloc); + } | any_identifier '[' constant_expression ']' { void *ctx = state; diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index ad85db9e3..be17109e1 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -99,7 +99,6 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits; this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs; this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents; - this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4; this->Const.MaxVertexTextureImageUnits = ctx->Const.VertexProgram.MaxTextureImageUnits; this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits; this->Const.MaxTextureImageUnits = ctx->Const.FragmentProgram.MaxTextureImageUnits; @@ -109,6 +108,16 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers; + /* 1.50 constants */ + this->Const.MaxVertexOutputComponents = ctx->Const.VertexProgram.MaxOutputComponents; + this->Const.MaxGeometryInputComponents = ctx->Const.GeometryProgram.MaxInputComponents; + this->Const.MaxGeometryOutputComponents = ctx->Const.GeometryProgram.MaxOutputComponents; + this->Const.MaxFragmentInputComponents = ctx->Const.FragmentProgram.MaxInputComponents; + this->Const.MaxGeometryTextureImageUnits = ctx->Const.GeometryProgram.MaxTextureImageUnits; + this->Const.MaxGeometryOutputVertices = ctx->Const.MaxGeometryOutputVertices; + this->Const.MaxGeometryTotalOutputComponents = ctx->Const.MaxGeometryTotalOutputComponents; + this->Const.MaxGeometryUniformComponents = ctx->Const.GeometryProgram.MaxUniformComponents; + this->current_function = NULL; this->toplevel_ir = NULL; this->found_return = false; diff --git a/mesalib/src/glsl/glsl_parser_extras.h b/mesalib/src/glsl/glsl_parser_extras.h index dba1a35e5..a67438412 100644 --- a/mesalib/src/glsl/glsl_parser_extras.h +++ b/mesalib/src/glsl/glsl_parser_extras.h @@ -208,7 +208,6 @@ struct _mesa_glsl_parse_state { unsigned MaxTextureCoords; unsigned MaxVertexAttribs; unsigned MaxVertexUniformComponents; - unsigned MaxVaryingFloats; unsigned MaxVertexTextureImageUnits; unsigned MaxCombinedTextureImageUnits; unsigned MaxTextureImageUnits; @@ -220,6 +219,16 @@ struct _mesa_glsl_parse_state { /* 3.00 ES */ int MinProgramTexelOffset; int MaxProgramTexelOffset; + + /* 1.50 */ + unsigned MaxVertexOutputComponents; + unsigned MaxGeometryInputComponents; + unsigned MaxGeometryOutputComponents; + unsigned MaxFragmentInputComponents; + unsigned MaxGeometryTextureImageUnits; + unsigned MaxGeometryOutputVertices; + unsigned MaxGeometryTotalOutputComponents; + unsigned MaxGeometryUniformComponents; } Const; /** diff --git a/mesalib/src/glsl/glsl_symbol_table.cpp b/mesalib/src/glsl/glsl_symbol_table.cpp index 6e916b458..11569f47e 100644 --- a/mesalib/src/glsl/glsl_symbol_table.cpp +++ b/mesalib/src/glsl/glsl_symbol_table.cpp @@ -256,3 +256,18 @@ symbol_table_entry *glsl_symbol_table::get_entry(const char *name) return (symbol_table_entry *) _mesa_symbol_table_find_symbol(table, -1, name); } + +void +glsl_symbol_table::disable_variable(const char *name) +{ + /* Ideally we would remove the variable's entry from the symbol table, but + * that would be difficult. Fortunately, since this is only used for + * built-in variables, it won't be possible for the shader to re-introduce + * the variable later, so all we really need to do is to make sure that + * further attempts to access it using get_variable() will return NULL. + */ + symbol_table_entry *entry = get_entry(name); + if (entry != NULL) { + entry->v = NULL; + } +} diff --git a/mesalib/src/glsl/glsl_symbol_table.h b/mesalib/src/glsl/glsl_symbol_table.h index 62d26b89a..0e62448e2 100644 --- a/mesalib/src/glsl/glsl_symbol_table.h +++ b/mesalib/src/glsl/glsl_symbol_table.h @@ -121,6 +121,14 @@ public: enum ir_variable_mode mode); /*@}*/ + /** + * Disable a previously-added variable so that it no longer appears to be + * in the symbol table. This is necessary when gl_PerVertex is redeclared, + * to ensure that previously-available built-in variables are no longer + * available. + */ + void disable_variable(const char *name); + private: symbol_table_entry *get_entry(const char *name); diff --git a/mesalib/src/glsl/glsl_types.cpp b/mesalib/src/glsl/glsl_types.cpp index 3c396dd89..80a6e71a7 100644 --- a/mesalib/src/glsl/glsl_types.cpp +++ b/mesalib/src/glsl/glsl_types.cpp @@ -100,6 +100,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, this->fields.structure[i].type = fields[i].type; this->fields.structure[i].name = ralloc_strdup(this->fields.structure, fields[i].name); + this->fields.structure[i].location = fields[i].location; this->fields.structure[i].row_major = fields[i].row_major; } } @@ -124,6 +125,7 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, this->fields.structure[i].type = fields[i].type; this->fields.structure[i].name = ralloc_strdup(this->fields.structure, fields[i].name); + this->fields.structure[i].location = fields[i].location; this->fields.structure[i].row_major = fields[i].row_major; } } @@ -450,6 +452,9 @@ glsl_type::record_key_compare(const void *a, const void *b) if (key1->fields.structure[i].row_major != key2->fields.structure[i].row_major) return 1; + if (key1->fields.structure[i].location + != key2->fields.structure[i].location) + return 1; } return 0; @@ -507,9 +512,9 @@ const glsl_type * glsl_type::get_interface_instance(const glsl_struct_field *fields, unsigned num_fields, enum glsl_interface_packing packing, - const char *name) + const char *block_name) { - const glsl_type key(fields, num_fields, packing, name); + const glsl_type key(fields, num_fields, packing, block_name); if (interface_types == NULL) { interface_types = hash_table_ctor(64, record_key_hash, record_key_compare); @@ -517,14 +522,14 @@ glsl_type::get_interface_instance(const glsl_struct_field *fields, const glsl_type *t = (glsl_type *) hash_table_find(interface_types, & key); if (t == NULL) { - t = new glsl_type(fields, num_fields, packing, name); + t = new glsl_type(fields, num_fields, packing, block_name); hash_table_insert(interface_types, (void *) t, t); } assert(t->base_type == GLSL_TYPE_INTERFACE); assert(t->length == num_fields); - assert(strcmp(t->name, name) == 0); + assert(strcmp(t->name, block_name) == 0); return t; } diff --git a/mesalib/src/glsl/glsl_types.h b/mesalib/src/glsl/glsl_types.h index 9f61eee78..e60c19132 100644 --- a/mesalib/src/glsl/glsl_types.h +++ b/mesalib/src/glsl/glsl_types.h @@ -234,7 +234,7 @@ struct glsl_type { static const glsl_type *get_interface_instance(const glsl_struct_field *fields, unsigned num_fields, enum glsl_interface_packing packing, - const char *name); + const char *block_name); /** * Query the total number of scalars that make up a scalar, vector or matrix @@ -581,6 +581,15 @@ struct glsl_struct_field { const struct glsl_type *type; const char *name; bool row_major; + + /** + * For interface blocks, gl_varying_slot corresponding to the input/output + * if this is a built-in input/output (i.e. a member of the built-in + * gl_PerVertex interface block); -1 otherwise. + * + * Ignored for structs. + */ + int location; }; static inline unsigned int diff --git a/mesalib/src/glsl/ir.cpp b/mesalib/src/glsl/ir.cpp index ae67d6bdd..de9613e8f 100644 --- a/mesalib/src/glsl/ir.cpp +++ b/mesalib/src/glsl/ir.cpp @@ -398,6 +398,9 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) this->type = glsl_type::uint_type; break; + case ir_binop_imul_high: + case ir_binop_carry: + case ir_binop_borrow: case ir_binop_lshift: case ir_binop_rshift: case ir_binop_bfm: @@ -527,7 +530,10 @@ static const char *const operator_strs[] = { "+", "-", "*", + "imul_high", "/", + "carry", + "borrow", "%", "<", ">", @@ -1578,7 +1584,8 @@ ir_swizzle::variable_referenced() const ir_variable::ir_variable(const struct glsl_type *type, const char *name, ir_variable_mode mode) - : max_array_access(0), read_only(false), centroid(false), invariant(false), + : max_array_access(0), max_ifc_array_access(NULL), + read_only(false), centroid(false), invariant(false), mode(mode), interpolation(INTERP_QUALIFIER_NONE) { this->ir_type = ir_type_variable; diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h index 1a4a3a2e3..aac8cbb7d 100644 --- a/mesalib/src/glsl/ir.h +++ b/mesalib/src/glsl/ir.h @@ -392,6 +392,65 @@ public: } /** + * Set this->interface_type on a newly created variable. + */ + void init_interface_type(const struct glsl_type *type) + { + assert(this->interface_type == NULL); + this->interface_type = type; + if (this->is_interface_instance()) { + this->max_ifc_array_access = + rzalloc_array(this, unsigned, type->length); + } + } + + /** + * Change this->interface_type on a variable that previously had a + * different, but compatible, interface_type. This is used during linking + * to set the size of arrays in interface blocks. + */ + void change_interface_type(const struct glsl_type *type) + { + if (this->max_ifc_array_access != NULL) { + /* max_ifc_array_access has already been allocated, so make sure the + * new interface has the same number of fields as the old one. + */ + assert(this->interface_type->length == type->length); + } + this->interface_type = type; + } + + /** + * Change this->interface_type on a variable that previously had a + * different, and incompatible, interface_type. This is used during + * compilation to handle redeclaration of the built-in gl_PerVertex + * interface block. + */ + void reinit_interface_type(const struct glsl_type *type) + { + if (this->max_ifc_array_access != NULL) { +#ifndef _NDEBUG + /* Redeclaring gl_PerVertex is only allowed if none of the built-ins + * it defines have been accessed yet; so it's safe to throw away the + * old max_ifc_array_access pointer, since all of its values are + * zero. + */ + for (unsigned i = 0; i < this->interface_type->length; i++) + assert(this->max_ifc_array_access[i] == 0); +#endif + ralloc_free(this->max_ifc_array_access); + this->max_ifc_array_access = NULL; + } + this->interface_type = NULL; + init_interface_type(type); + } + + const glsl_type *get_interface_type() const + { + return this->interface_type; + } + + /** * Declared type of the variable */ const struct glsl_type *type; @@ -409,6 +468,19 @@ public: unsigned max_array_access; /** + * For variables which satisfy the is_interface_instance() predicate, this + * points to an array of integers such that if the ith member of the + * interface block is an array, max_ifc_array_access[i] is the maximum + * array element of that member that has been accessed. If the ith member + * of the interface block is not an array, max_ifc_array_access[i] is + * unused. + * + * For variables whose type is not an interface block, this pointer is + * NULL. + */ + unsigned *max_ifc_array_access; + + /** * Is the variable read-only? * * This is set for variables declared as \c const, shader inputs, @@ -582,6 +654,7 @@ public: */ ir_constant *constant_initializer; +private: /** * For variables that are in an interface block or are an instance of an * interface block, this is the \c GLSL_TYPE_INTERFACE type for that block. @@ -1091,10 +1164,26 @@ enum ir_expression_operation { ir_binop_add, ir_binop_sub, - ir_binop_mul, + ir_binop_mul, /**< Floating-point or low 32-bit integer multiply. */ + ir_binop_imul_high, /**< Calculates the high 32-bits of a 64-bit multiply. */ ir_binop_div, /** + * Returns the carry resulting from the addition of the two arguments. + */ + /*@{*/ + ir_binop_carry, + /*@}*/ + + /** + * Returns the borrow resulting from the subtraction of the second argument + * from the first argument. + */ + /*@{*/ + ir_binop_borrow, + /*@}*/ + + /** * Takes one of two combinations of arguments: * * - mod(vecN, vecN) diff --git a/mesalib/src/glsl/ir_builder.cpp b/mesalib/src/glsl/ir_builder.cpp index 98b432295..6c49734be 100644 --- a/mesalib/src/glsl/ir_builder.cpp +++ b/mesalib/src/glsl/ir_builder.cpp @@ -216,11 +216,26 @@ ir_expression *mul(operand a, operand b) return expr(ir_binop_mul, a, b); } +ir_expression *imul_high(operand a, operand b) +{ + return expr(ir_binop_imul_high, a, b); +} + ir_expression *div(operand a, operand b) { return expr(ir_binop_div, a, b); } +ir_expression *carry(operand a, operand b) +{ + return expr(ir_binop_carry, a, b); +} + +ir_expression *borrow(operand a, operand b) +{ + return expr(ir_binop_borrow, a, b); +} + ir_expression *round_even(operand a) { return expr(ir_unop_round_even, a); diff --git a/mesalib/src/glsl/ir_builder.h b/mesalib/src/glsl/ir_builder.h index 6a5f77119..1f0778870 100644 --- a/mesalib/src/glsl/ir_builder.h +++ b/mesalib/src/glsl/ir_builder.h @@ -133,7 +133,10 @@ ir_expression *expr(ir_expression_operation op, operand a, operand b, operand c) ir_expression *add(operand a, operand b); ir_expression *sub(operand a, operand b); ir_expression *mul(operand a, operand b); +ir_expression *imul_high(operand a, operand b); ir_expression *div(operand a, operand b); +ir_expression *carry(operand a, operand b); +ir_expression *borrow(operand a, operand b); ir_expression *round_even(operand a); ir_expression *dot(operand a, operand b); ir_expression *dotlike(operand a, operand b); diff --git a/mesalib/src/glsl/ir_clone.cpp b/mesalib/src/glsl/ir_clone.cpp index dde22e018..105f9063a 100644 --- a/mesalib/src/glsl/ir_clone.cpp +++ b/mesalib/src/glsl/ir_clone.cpp @@ -44,6 +44,12 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const (ir_variable_mode) this->mode); var->max_array_access = this->max_array_access; + if (this->is_interface_instance()) { + var->max_ifc_array_access = + rzalloc_array(var, unsigned, this->interface_type->length); + memcpy(var->max_ifc_array_access, this->max_ifc_array_access, + this->interface_type->length * sizeof(unsigned)); + } var->read_only = this->read_only; var->centroid = this->centroid; var->invariant = this->invariant; diff --git a/mesalib/src/glsl/ir_validate.cpp b/mesalib/src/glsl/ir_validate.cpp index 2c64f4e58..13e41a089 100644 --- a/mesalib/src/glsl/ir_validate.cpp +++ b/mesalib/src/glsl/ir_validate.cpp @@ -429,6 +429,19 @@ ir_validate::visit_leave(ir_expression *ir) } break; + case ir_binop_imul_high: + assert(ir->type == ir->operands[0]->type); + assert(ir->type == ir->operands[1]->type); + assert(ir->type->is_integer()); + break; + + case ir_binop_carry: + case ir_binop_borrow: + assert(ir->type == ir->operands[0]->type); + assert(ir->type == ir->operands[1]->type); + assert(ir->type->base_type == GLSL_TYPE_UINT); + break; + case ir_binop_less: case ir_binop_greater: case ir_binop_lequal: @@ -674,6 +687,26 @@ ir_validate::visit(ir_variable *ir) } } + /* If a variable is an interface block (or an array of interface blocks), + * verify that the maximum array index for each interface member is in + * bounds. + */ + if (ir->is_interface_instance()) { + const glsl_struct_field *fields = + ir->get_interface_type()->fields.structure; + for (unsigned i = 0; i < ir->get_interface_type()->length; i++) { + if (fields[i].type->array_size() > 0) { + if (ir->max_ifc_array_access[i] >= fields[i].type->length) { + printf("ir_variable has maximum access out of bounds for " + "field %s (%d vs %d)\n", fields[i].name, + ir->max_ifc_array_access[i], fields[i].type->length); + ir->print(); + abort(); + } + } + } + } + if (ir->constant_initializer != NULL && !ir->has_initializer) { printf("ir_variable didn't have an initializer, but has a constant " "initializer value.\n"); diff --git a/mesalib/src/glsl/link_functions.cpp b/mesalib/src/glsl/link_functions.cpp index b1a68fd55..fd8009998 100644 --- a/mesalib/src/glsl/link_functions.cpp +++ b/mesalib/src/glsl/link_functions.cpp @@ -223,18 +223,31 @@ public: var = ir->var->clone(linked, NULL); linked->symbols->add_variable(var); linked->ir->push_head(var); - } else if (var->type->is_array()) { - /* It is possible to have a global array declared in multiple - * shaders without a size. The array is implicitly sized by the - * maximal access to it in *any* shader. Because of this, we - * need to track the maximal access to the array as linking pulls - * more functions in that access the array. - */ - var->max_array_access = - MAX2(var->max_array_access, ir->var->max_array_access); - - if (var->type->length == 0 && ir->var->type->length != 0) - var->type = ir->var->type; + } else { + if (var->type->is_array()) { + /* It is possible to have a global array declared in multiple + * shaders without a size. The array is implicitly sized by + * the maximal access to it in *any* shader. Because of this, + * we need to track the maximal access to the array as linking + * pulls more functions in that access the array. + */ + var->max_array_access = + MAX2(var->max_array_access, ir->var->max_array_access); + + if (var->type->length == 0 && ir->var->type->length != 0) + var->type = ir->var->type; + } + if (var->is_interface_instance()) { + /* Similarly, we need implicit sizes of arrays within interface + * blocks to be sized by the maximal access in *any* shader. + */ + for (unsigned i = 0; i < var->get_interface_type()->length; + i++) { + var->max_ifc_array_access[i] = + MAX2(var->max_ifc_array_access[i], + ir->var->max_ifc_array_access[i]); + } + } } ir->var = var; diff --git a/mesalib/src/glsl/link_interface_blocks.cpp b/mesalib/src/glsl/link_interface_blocks.cpp index 928a88ee2..4f1c9d396 100644 --- a/mesalib/src/glsl/link_interface_blocks.cpp +++ b/mesalib/src/glsl/link_interface_blocks.cpp @@ -47,7 +47,7 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog, if (!var) continue; - const glsl_type *iface_type = var->interface_type; + const glsl_type *iface_type = var->get_interface_type(); if (iface_type == NULL) continue; @@ -81,32 +81,33 @@ validate_interstage_interface_blocks(struct gl_shader_program *prog, /* Add non-output interfaces from the consumer to the symbol table. */ foreach_list(node, consumer->ir) { ir_variable *var = ((ir_instruction *) node)->as_variable(); - if (!var || !var->interface_type || var->mode == ir_var_shader_out) + if (!var || !var->get_interface_type() || var->mode == ir_var_shader_out) continue; - interfaces.add_interface(var->interface_type->name, - var->interface_type, + interfaces.add_interface(var->get_interface_type()->name, + var->get_interface_type(), (enum ir_variable_mode) var->mode); } /* Verify that the producer's interfaces match. */ foreach_list(node, producer->ir) { ir_variable *var = ((ir_instruction *) node)->as_variable(); - if (!var || !var->interface_type || var->mode == ir_var_shader_in) + if (!var || !var->get_interface_type() || var->mode == ir_var_shader_in) continue; enum ir_variable_mode consumer_mode = var->mode == ir_var_uniform ? ir_var_uniform : ir_var_shader_in; const glsl_type *expected_type = - interfaces.get_interface(var->interface_type->name, consumer_mode); + interfaces.get_interface(var->get_interface_type()->name, + consumer_mode); /* The consumer doesn't use this output block. Ignore it. */ if (expected_type == NULL) continue; - if (var->interface_type != expected_type) { + if (var->get_interface_type() != expected_type) { linker_error(prog, "definitions of interface block `%s' do not " - "match\n", var->interface_type->name); + "match\n", var->get_interface_type()->name); return; } } diff --git a/mesalib/src/glsl/link_uniform_block_active_visitor.cpp b/mesalib/src/glsl/link_uniform_block_active_visitor.cpp index 56a8384e9..f2f46a211 100644 --- a/mesalib/src/glsl/link_uniform_block_active_visitor.cpp +++ b/mesalib/src/glsl/link_uniform_block_active_visitor.cpp @@ -27,12 +27,12 @@ link_uniform_block_active * process_block(void *mem_ctx, struct hash_table *ht, ir_variable *var) { - const uint32_t h = _mesa_hash_string(var->interface_type->name); + const uint32_t h = _mesa_hash_string(var->get_interface_type()->name); const hash_entry *const existing_block = - _mesa_hash_table_search(ht, h, var->interface_type->name); + _mesa_hash_table_search(ht, h, var->get_interface_type()->name); const glsl_type *const block_type = var->is_interface_instance() - ? var->type : var->interface_type; + ? var->type : var->get_interface_type(); /* If a block with this block-name has not previously been seen, add it. @@ -46,7 +46,7 @@ process_block(void *mem_ctx, struct hash_table *ht, ir_variable *var) b->type = block_type; b->has_instance_name = var->is_interface_instance(); - _mesa_hash_table_insert(ht, h, var->interface_type->name, + _mesa_hash_table_insert(ht, h, var->get_interface_type()->name, (void *) b); return b; } else { @@ -90,7 +90,7 @@ link_uniform_block_active_visitor::visit_enter(ir_dereference_array *ir) if (b == NULL) { linker_error(prog, "uniform block `%s' has mismatching definitions", - var->interface_type->name); + var->get_interface_type()->name); this->success = false; return visit_stop; } @@ -149,7 +149,7 @@ link_uniform_block_active_visitor::visit(ir_dereference_variable *ir) if (b == NULL) { linker_error(this->prog, "uniform block `%s' has mismatching definitions", - var->interface_type->name); + var->get_interface_type()->name); this->success = false; return visit_stop; } diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp index 1cdd5a922..4bd4034a0 100644 --- a/mesalib/src/glsl/link_uniforms.cpp +++ b/mesalib/src/glsl/link_uniforms.cpp @@ -199,8 +199,8 @@ public: { this->is_ubo_var = var->is_in_uniform_block(); if (var->is_interface_instance()) - program_resource_visitor::process(var->interface_type, - var->interface_type->name); + program_resource_visitor::process(var->get_interface_type(), + var->get_interface_type()->name); else program_resource_visitor::process(var); } @@ -317,10 +317,10 @@ public: ubo_block_index = -1; if (var->is_in_uniform_block()) { if (var->is_interface_instance() && var->type->is_array()) { - unsigned l = strlen(var->interface_type->name); + unsigned l = strlen(var->get_interface_type()->name); for (unsigned i = 0; i < prog->NumUniformBlocks; i++) { - if (strncmp(var->interface_type->name, + if (strncmp(var->get_interface_type()->name, prog->UniformBlocks[i].Name, l) == 0 && prog->UniformBlocks[i].Name[l] == '[') { @@ -330,7 +330,7 @@ public: } } else { for (unsigned i = 0; i < prog->NumUniformBlocks; i++) { - if (strcmp(var->interface_type->name, + if (strcmp(var->get_interface_type()->name, prog->UniformBlocks[i].Name) == 0) { ubo_block_index = i; break; @@ -362,7 +362,8 @@ public: } if (var->is_interface_instance()) - process(var->interface_type, var->interface_type->name); + process(var->get_interface_type(), + var->get_interface_type()->name); else process(var); } else diff --git a/mesalib/src/glsl/link_varyings.cpp b/mesalib/src/glsl/link_varyings.cpp index 905621daf..4ba6d8a20 100644 --- a/mesalib/src/glsl/link_varyings.cpp +++ b/mesalib/src/glsl/link_varyings.cpp @@ -972,8 +972,8 @@ public: this->toplevel_var = var; this->varying_floats = 0; if (var->is_interface_instance()) - program_resource_visitor::process(var->interface_type, - var->interface_type->name); + program_resource_visitor::process(var->get_interface_type(), + var->get_interface_type()->name); else program_resource_visitor::process(var); } @@ -1083,10 +1083,10 @@ assign_varying_locations(struct gl_context *ctx, ((ir_instruction *) node)->as_variable(); if ((input_var != NULL) && (input_var->mode == ir_var_shader_in)) { - if (input_var->interface_type != NULL) { + if (input_var->get_interface_type() != NULL) { char *const iface_field_name = ralloc_asprintf(mem_ctx, "%s.%s", - input_var->interface_type->name, + input_var->get_interface_type()->name, input_var->name); hash_table_insert(consumer_interface_inputs, input_var, iface_field_name); @@ -1108,10 +1108,10 @@ assign_varying_locations(struct gl_context *ctx, g.process(output_var); ir_variable *input_var; - if (output_var->interface_type != NULL) { + if (output_var->get_interface_type() != NULL) { char *const iface_field_name = ralloc_asprintf(mem_ctx, "%s.%s", - output_var->interface_type->name, + output_var->get_interface_type()->name, output_var->name); input_var = (ir_variable *) hash_table_find(consumer_interface_inputs, @@ -1220,39 +1220,98 @@ assign_varying_locations(struct gl_context *ctx, } bool -check_against_varying_limit(struct gl_context *ctx, - struct gl_shader_program *prog, - gl_shader *consumer) +check_against_output_limit(struct gl_context *ctx, + struct gl_shader_program *prog, + gl_shader *producer) { - unsigned varying_vectors = 0; + unsigned output_vectors = 0; + + foreach_list(node, producer->ir) { + ir_variable *const var = ((ir_instruction *) node)->as_variable(); + + if (var && var->mode == ir_var_shader_out && + is_varying_var(producer->Type, var)) { + output_vectors += var->type->count_attribute_slots(); + } + } + + unsigned max_output_components; + switch (producer->Type) { + case GL_VERTEX_SHADER: + max_output_components = ctx->Const.VertexProgram.MaxOutputComponents; + break; + case GL_GEOMETRY_SHADER: + max_output_components = ctx->Const.GeometryProgram.MaxOutputComponents; + break; + case GL_FRAGMENT_SHADER: + default: + assert(!"Should not get here."); + return false; + } + + const unsigned output_components = output_vectors * 4; + if (output_components > max_output_components) { + if (ctx->API == API_OPENGLES2 || prog->IsES) + linker_error(prog, "shader uses too many output vectors " + "(%u > %u)\n", + output_vectors, + max_output_components / 4); + else + linker_error(prog, "shader uses too many output components " + "(%u > %u)\n", + output_components, + max_output_components); + + return false; + } + + return true; +} + +bool +check_against_input_limit(struct gl_context *ctx, + struct gl_shader_program *prog, + gl_shader *consumer) +{ + unsigned input_vectors = 0; foreach_list(node, consumer->ir) { ir_variable *const var = ((ir_instruction *) node)->as_variable(); if (var && var->mode == ir_var_shader_in && is_varying_var(consumer->Type, var)) { - /* The packing rules used for vertex shader inputs are also - * used for fragment shader inputs. - */ - varying_vectors += var->type->count_attribute_slots(); + input_vectors += var->type->count_attribute_slots(); } } - if (ctx->API == API_OPENGLES2 || prog->IsES) { - if (varying_vectors > ctx->Const.MaxVarying) { - linker_error(prog, "shader uses too many varying vectors " + unsigned max_input_components; + switch (consumer->Type) { + case GL_GEOMETRY_SHADER: + max_input_components = ctx->Const.GeometryProgram.MaxInputComponents; + break; + case GL_FRAGMENT_SHADER: + max_input_components = ctx->Const.FragmentProgram.MaxInputComponents; + break; + case GL_VERTEX_SHADER: + default: + assert(!"Should not get here."); + return false; + } + + const unsigned input_components = input_vectors * 4; + if (input_components > max_input_components) { + if (ctx->API == API_OPENGLES2 || prog->IsES) + linker_error(prog, "shader uses too many input vectors " "(%u > %u)\n", - varying_vectors, ctx->Const.MaxVarying); - return false; - } - } else { - const unsigned float_components = varying_vectors * 4; - if (float_components > ctx->Const.MaxVarying * 4) { - linker_error(prog, "shader uses too many varying components " + input_vectors, + max_input_components / 4); + else + linker_error(prog, "shader uses too many input components " "(%u > %u)\n", - float_components, ctx->Const.MaxVarying * 4); - return false; - } + input_components, + max_input_components); + + return false; } return true; diff --git a/mesalib/src/glsl/link_varyings.h b/mesalib/src/glsl/link_varyings.h index 6264ef05b..6fa268176 100644 --- a/mesalib/src/glsl/link_varyings.h +++ b/mesalib/src/glsl/link_varyings.h @@ -237,8 +237,13 @@ assign_varying_locations(struct gl_context *ctx, unsigned gs_input_vertices); bool -check_against_varying_limit(struct gl_context *ctx, - struct gl_shader_program *prog, - gl_shader *consumer); +check_against_output_limit(struct gl_context *ctx, + struct gl_shader_program *prog, + gl_shader *producer); + +bool +check_against_input_limit(struct gl_context *ctx, + struct gl_shader_program *prog, + gl_shader *consumer); #endif /* GLSL_LINK_VARYINGS_H */ diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp index c54b7049b..9095a4015 100644 --- a/mesalib/src/glsl/linker.cpp +++ b/mesalib/src/glsl/linker.cpp @@ -1033,17 +1033,167 @@ get_main_function_signature(gl_shader *sh) */ class array_sizing_visitor : public ir_hierarchical_visitor { public: + array_sizing_visitor() + : mem_ctx(ralloc_context(NULL)), + unnamed_interfaces(hash_table_ctor(0, hash_table_pointer_hash, + hash_table_pointer_compare)) + { + } + + ~array_sizing_visitor() + { + hash_table_dtor(this->unnamed_interfaces); + ralloc_free(this->mem_ctx); + } + virtual ir_visitor_status visit(ir_variable *var) { - if (var->type->is_array() && (var->type->length == 0)) { - const glsl_type *type = - glsl_type::get_array_instance(var->type->fields.array, - var->max_array_access + 1); - assert(type != NULL); - var->type = type; + fixup_type(&var->type, var->max_array_access); + if (var->type->is_interface()) { + if (interface_contains_unsized_arrays(var->type)) { + const glsl_type *new_type = + resize_interface_members(var->type, var->max_ifc_array_access); + var->type = new_type; + var->change_interface_type(new_type); + } + } else if (var->type->is_array() && + var->type->fields.array->is_interface()) { + if (interface_contains_unsized_arrays(var->type->fields.array)) { + const glsl_type *new_type = + resize_interface_members(var->type->fields.array, + var->max_ifc_array_access); + var->change_interface_type(new_type); + var->type = + glsl_type::get_array_instance(new_type, var->type->length); + } + } else if (const glsl_type *ifc_type = var->get_interface_type()) { + /* Store a pointer to the variable in the unnamed_interfaces + * hashtable. + */ + ir_variable **interface_vars = (ir_variable **) + hash_table_find(this->unnamed_interfaces, ifc_type); + if (interface_vars == NULL) { + interface_vars = rzalloc_array(mem_ctx, ir_variable *, + ifc_type->length); + hash_table_insert(this->unnamed_interfaces, interface_vars, + ifc_type); + } + unsigned index = ifc_type->field_index(var->name); + assert(index < ifc_type->length); + assert(interface_vars[index] == NULL); + interface_vars[index] = var; } return visit_continue; } + + /** + * For each unnamed interface block that was discovered while running the + * visitor, adjust the interface type to reflect the newly assigned array + * sizes, and fix up the ir_variable nodes to point to the new interface + * type. + */ + void fixup_unnamed_interface_types() + { + hash_table_call_foreach(this->unnamed_interfaces, + fixup_unnamed_interface_type, NULL); + } + +private: + /** + * If the type pointed to by \c type represents an unsized array, replace + * it with a sized array whose size is determined by max_array_access. + */ + static void fixup_type(const glsl_type **type, unsigned max_array_access) + { + if ((*type)->is_array() && (*type)->length == 0) { + *type = glsl_type::get_array_instance((*type)->fields.array, + max_array_access + 1); + assert(*type != NULL); + } + } + + /** + * Determine whether the given interface type contains unsized arrays (if + * it doesn't, array_sizing_visitor doesn't need to process it). + */ + static bool interface_contains_unsized_arrays(const glsl_type *type) + { + for (unsigned i = 0; i < type->length; i++) { + const glsl_type *elem_type = type->fields.structure[i].type; + if (elem_type->is_array() && elem_type->length == 0) + return true; + } + return false; + } + + /** + * Create a new interface type based on the given type, with unsized arrays + * replaced by sized arrays whose size is determined by + * max_ifc_array_access. + */ + static const glsl_type * + resize_interface_members(const glsl_type *type, + const unsigned *max_ifc_array_access) + { + unsigned num_fields = type->length; + glsl_struct_field *fields = new glsl_struct_field[num_fields]; + memcpy(fields, type->fields.structure, + num_fields * sizeof(*fields)); + for (unsigned i = 0; i < num_fields; i++) { + fixup_type(&fields[i].type, max_ifc_array_access[i]); + } + glsl_interface_packing packing = + (glsl_interface_packing) type->interface_packing; + const glsl_type *new_ifc_type = + glsl_type::get_interface_instance(fields, num_fields, + packing, type->name); + delete [] fields; + return new_ifc_type; + } + + static void fixup_unnamed_interface_type(const void *key, void *data, + void *) + { + const glsl_type *ifc_type = (const glsl_type *) key; + ir_variable **interface_vars = (ir_variable **) data; + unsigned num_fields = ifc_type->length; + glsl_struct_field *fields = new glsl_struct_field[num_fields]; + memcpy(fields, ifc_type->fields.structure, + num_fields * sizeof(*fields)); + bool interface_type_changed = false; + for (unsigned i = 0; i < num_fields; i++) { + if (interface_vars[i] != NULL && + fields[i].type != interface_vars[i]->type) { + fields[i].type = interface_vars[i]->type; + interface_type_changed = true; + } + } + if (!interface_type_changed) { + delete [] fields; + return; + } + glsl_interface_packing packing = + (glsl_interface_packing) ifc_type->interface_packing; + const glsl_type *new_ifc_type = + glsl_type::get_interface_instance(fields, num_fields, packing, + ifc_type->name); + delete [] fields; + for (unsigned i = 0; i < num_fields; i++) { + if (interface_vars[i] != NULL) + interface_vars[i]->change_interface_type(new_ifc_type); + } + } + + /** + * Memory context used to allocate the data in \c unnamed_interfaces. + */ + void *mem_ctx; + + /** + * Hash table from const glsl_type * to an array of ir_variable *'s + * pointing to the ir_variables constituting each unnamed interface block. + */ + hash_table *unnamed_interfaces; }; /** @@ -1318,6 +1468,7 @@ link_intrastage_shaders(void *mem_ctx, */ array_sizing_visitor v; v.run(linked->ir); + v.fixup_unnamed_interface_types(); return linked; } @@ -2203,7 +2354,9 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) ; /* This must be done after all dead varyings are eliminated. */ - if (!check_against_varying_limit(ctx, prog, sh_next)) + if (!check_against_output_limit(ctx, prog, sh_i)) + goto done; + if (!check_against_input_limit(ctx, prog, sh_next)) goto done; next = i; diff --git a/mesalib/src/glsl/lower_clip_distance.cpp b/mesalib/src/glsl/lower_clip_distance.cpp index 9ddd64603..682c8fdcd 100644 --- a/mesalib/src/glsl/lower_clip_distance.cpp +++ b/mesalib/src/glsl/lower_clip_distance.cpp @@ -54,14 +54,17 @@ namespace { class lower_clip_distance_visitor : public ir_rvalue_visitor { public: - lower_clip_distance_visitor() - : progress(false), old_clip_distance_var(NULL), - new_clip_distance_var(NULL) + explicit lower_clip_distance_visitor(GLenum shader_type) + : progress(false), old_clip_distance_1d_var(NULL), + old_clip_distance_2d_var(NULL), new_clip_distance_1d_var(NULL), + new_clip_distance_2d_var(NULL), shader_type(shader_type) { } virtual ir_visitor_status visit(ir_variable *); void create_indices(ir_rvalue*, ir_rvalue *&, ir_rvalue *&); + bool is_clip_distance_vec8(ir_rvalue *ir); + ir_rvalue *lower_clip_distance_vec8(ir_rvalue *ir); virtual ir_visitor_status visit_leave(ir_assignment *); void visit_new_assignment(ir_assignment *ir); virtual ir_visitor_status visit_leave(ir_call *); @@ -74,13 +77,28 @@ public: /** * Pointer to the declaration of gl_ClipDistance, if found. + * + * Note: + * + * - the 2d_var is for geometry shader input only. + * + * - since gl_ClipDistance is available in geometry shaders as both an + * input and an output, it's possible for both old_clip_distance_1d_var + * and old_clip_distance_2d_var to be non-null. */ - ir_variable *old_clip_distance_var; + ir_variable *old_clip_distance_1d_var; + ir_variable *old_clip_distance_2d_var; /** * Pointer to the newly-created gl_ClipDistanceMESA variable. */ - ir_variable *new_clip_distance_var; + ir_variable *new_clip_distance_1d_var; + ir_variable *new_clip_distance_2d_var; + + /** + * Type of shader we are compiling (e.g. GL_VERTEX_SHADER) + */ + const GLenum shader_type; }; } /* anonymous namespace */ @@ -92,30 +110,61 @@ public: ir_visitor_status lower_clip_distance_visitor::visit(ir_variable *ir) { - /* No point in looking for the declaration of gl_ClipDistance if - * we've already found it. - */ - if (this->old_clip_distance_var) + if (!ir->name || strcmp(ir->name, "gl_ClipDistance") != 0) return visit_continue; + assert (ir->type->is_array()); + + if (!ir->type->element_type()->is_array()) { + /* 1D gl_ClipDistance (used for vertex and geometry output, and fragment + * input). + */ + if (this->old_clip_distance_1d_var) + return visit_continue; - if (ir->name && strcmp(ir->name, "gl_ClipDistance") == 0) { this->progress = true; - this->old_clip_distance_var = ir; - assert (ir->type->is_array()); + this->old_clip_distance_1d_var = ir; assert (ir->type->element_type() == glsl_type::float_type); unsigned new_size = (ir->type->array_size() + 3) / 4; /* Clone the old var so that we inherit all of its properties */ - this->new_clip_distance_var = ir->clone(ralloc_parent(ir), NULL); + this->new_clip_distance_1d_var = ir->clone(ralloc_parent(ir), NULL); /* And change the properties that we need to change */ - this->new_clip_distance_var->name - = ralloc_strdup(this->new_clip_distance_var, "gl_ClipDistanceMESA"); - this->new_clip_distance_var->type + this->new_clip_distance_1d_var->name + = ralloc_strdup(this->new_clip_distance_1d_var, + "gl_ClipDistanceMESA"); + this->new_clip_distance_1d_var->type = glsl_type::get_array_instance(glsl_type::vec4_type, new_size); - this->new_clip_distance_var->max_array_access = ir->max_array_access / 4; + this->new_clip_distance_1d_var->max_array_access + = ir->max_array_access / 4; + + ir->replace_with(this->new_clip_distance_1d_var); + } else { + /* 2D gl_ClipDistance (used for geometry input). */ + assert(ir->mode == ir_var_shader_in && + this->shader_type == GL_GEOMETRY_SHADER_ARB); + if (this->old_clip_distance_2d_var) + return visit_continue; + + this->progress = true; + this->old_clip_distance_2d_var = ir; + assert (ir->type->element_type()->element_type() == glsl_type::float_type); + unsigned new_size = (ir->type->element_type()->array_size() + 3) / 4; + + /* Clone the old var so that we inherit all of its properties */ + this->new_clip_distance_2d_var = ir->clone(ralloc_parent(ir), NULL); - ir->replace_with(this->new_clip_distance_var); + /* And change the properties that we need to change */ + this->new_clip_distance_2d_var->name + = ralloc_strdup(this->new_clip_distance_2d_var, "gl_ClipDistanceMESA"); + this->new_clip_distance_2d_var->type = glsl_type::get_array_instance( + glsl_type::get_array_instance(glsl_type::vec4_type, + new_size), + ir->type->array_size()); + this->new_clip_distance_2d_var->max_array_access + = ir->max_array_access / 4; + + ir->replace_with(this->new_clip_distance_2d_var); } return visit_continue; } @@ -180,39 +229,111 @@ lower_clip_distance_visitor::create_indices(ir_rvalue *old_index, } +/** + * Determine whether the given rvalue describes an array of 8 floats that + * needs to be lowered to an array of 2 vec4's; that is, determine whether it + * matches one of the following patterns: + * + * - gl_ClipDistance (if gl_ClipDistance is 1D) + * - gl_ClipDistance[i] (if gl_ClipDistance is 2D) + */ +bool +lower_clip_distance_visitor::is_clip_distance_vec8(ir_rvalue *ir) +{ + /* Note that geometry shaders contain gl_ClipDistance both as an input + * (which is a 2D array) and an output (which is a 1D array), so it's + * possible for both this->old_clip_distance_1d_var and + * this->old_clip_distance_2d_var to be non-NULL in the same shader. + */ + + if (this->old_clip_distance_1d_var) { + ir_dereference_variable *var_ref = ir->as_dereference_variable(); + if (var_ref && var_ref->var == this->old_clip_distance_1d_var) + return true; + } + if (this->old_clip_distance_2d_var) { + /* 2D clip distance is only possible as a geometry input */ + assert(this->shader_type == GL_GEOMETRY_SHADER_ARB); + + ir_dereference_array *array_ref = ir->as_dereference_array(); + if (array_ref) { + ir_dereference_variable *var_ref = + array_ref->array->as_dereference_variable(); + if (var_ref && var_ref->var == this->old_clip_distance_2d_var) + return true; + } + } + return false; +} + + +/** + * If the given ir satisfies is_clip_distance_vec8(), return new ir + * representing its lowered equivalent. That is, map: + * + * - gl_ClipDistance => gl_ClipDistanceMESA (if gl_ClipDistance is 1D) + * - gl_ClipDistance[i] => gl_ClipDistanceMESA[i] (if gl_ClipDistance is 2D) + * + * Otherwise return NULL. + */ +ir_rvalue * +lower_clip_distance_visitor::lower_clip_distance_vec8(ir_rvalue *ir) +{ + if (this->old_clip_distance_1d_var) { + ir_dereference_variable *var_ref = ir->as_dereference_variable(); + if (var_ref && var_ref->var == this->old_clip_distance_1d_var) { + return new(ralloc_parent(ir)) + ir_dereference_variable(this->new_clip_distance_1d_var); + } + } + if (this->old_clip_distance_2d_var) { + /* 2D clip distance is only possible as a geometry input */ + assert(this->shader_type == GL_GEOMETRY_SHADER_ARB); + + ir_dereference_array *array_ref = ir->as_dereference_array(); + if (array_ref) { + ir_dereference_variable *var_ref = + array_ref->array->as_dereference_variable(); + if (var_ref && var_ref->var == this->old_clip_distance_2d_var) { + return new(ralloc_parent(ir)) + ir_dereference_array(this->new_clip_distance_2d_var, + array_ref->array_index); + } + } + } + return NULL; +} + + void lower_clip_distance_visitor::handle_rvalue(ir_rvalue **rv) { - /* If the gl_ClipDistance var hasn't been declared yet, then - * there's no way this deref can refer to it. - */ - if (!this->old_clip_distance_var || *rv == NULL) + if (*rv == NULL) return; ir_dereference_array *const array_deref = (*rv)->as_dereference_array(); if (array_deref == NULL) return; - /* Replace any expression that indexes into the gl_ClipDistance array + /* Replace any expression that indexes one of the floats in gl_ClipDistance * with an expression that indexes into one of the vec4's in * gl_ClipDistanceMESA and accesses the appropriate component. */ - ir_dereference_variable *old_var_ref = - array_deref->array->as_dereference_variable(); - if (old_var_ref && old_var_ref->var == this->old_clip_distance_var) { + ir_rvalue *lowered_vec8 = + this->lower_clip_distance_vec8(array_deref->array); + if (lowered_vec8 != NULL) { this->progress = true; ir_rvalue *array_index; ir_rvalue *swizzle_index; this->create_indices(array_deref->array_index, array_index, swizzle_index); void *mem_ctx = ralloc_parent(array_deref); - ir_dereference_array *const ClipDistanceMESA_deref = - new(mem_ctx) ir_dereference_array(this->new_clip_distance_var, - array_index); + ir_dereference_array *const new_array_deref = + new(mem_ctx) ir_dereference_array(lowered_vec8, array_index); ir_expression *const expr = new(mem_ctx) ir_expression(ir_binop_vector_extract, - ClipDistanceMESA_deref, + new_array_deref, swizzle_index); *rv = expr; @@ -246,30 +367,34 @@ lower_clip_distance_visitor::fix_lhs(ir_assignment *ir) } /** - * Replace any assignment having gl_ClipDistance (undereferenced) as its LHS - * or RHS with a sequence of assignments, one for each component of the array. - * Each of these assignments is lowered to refer to gl_ClipDistanceMESA as - * appropriate. + * Replace any assignment having the 1D gl_ClipDistance (undereferenced) as + * its LHS or RHS with a sequence of assignments, one for each component of + * the array. Each of these assignments is lowered to refer to + * gl_ClipDistanceMESA as appropriate. + * + * We need to do a similar replacement for 2D gl_ClipDistance, however since + * it's an input, the only case we need to address is where a 1D slice of it + * is the entire RHS of an assignment, e.g.: + * + * foo = gl_in[i].gl_ClipDistance */ ir_visitor_status lower_clip_distance_visitor::visit_leave(ir_assignment *ir) { - ir_dereference_variable *lhs_var = ir->lhs->as_dereference_variable(); - ir_dereference_variable *rhs_var = ir->rhs->as_dereference_variable(); - if ((lhs_var && lhs_var->var == this->old_clip_distance_var) - || (rhs_var && rhs_var->var == this->old_clip_distance_var)) { - /* LHS or RHS of the assignment is the entire gl_ClipDistance array. - * Since we are reshaping gl_ClipDistance from an array of floats to an - * array of vec4's, this isn't going to work as a bulk assignment - * anymore, so unroll it to element-by-element assignments and lower - * each of them. + if (this->is_clip_distance_vec8(ir->lhs) || + this->is_clip_distance_vec8(ir->rhs)) { + /* LHS or RHS of the assignment is the entire 1D gl_ClipDistance array + * (or a 1D slice of a 2D gl_ClipDistance input array). Since we are + * reshaping gl_ClipDistance from an array of floats to an array of + * vec4's, this isn't going to work as a bulk assignment anymore, so + * unroll it to element-by-element assignments and lower each of them. * * Note: to unroll into element-by-element assignments, we need to make * clones of the LHS and RHS. This is safe because expressions and * l-values are side-effect free. */ void *ctx = ralloc_parent(ir); - int array_size = this->old_clip_distance_var->type->array_size(); + int array_size = ir->lhs->type->array_size(); for (int i = 0; i < array_size; ++i) { ir_dereference_array *new_lhs = new(ctx) ir_dereference_array( ir->lhs->clone(ctx, NULL), new(ctx) ir_constant(i)); @@ -329,11 +454,17 @@ lower_clip_distance_visitor::visit_new_assignment(ir_assignment *ir) /** - * If gl_ClipDistance appears as an argument in an ir_call expression, replace - * it with a temporary variable, and make sure the ir_call is preceded and/or - * followed by assignments that copy the contents of the temporary variable to - * and/or from gl_ClipDistance. Each of these assignments is then lowered to - * refer to gl_ClipDistanceMESA. + * If a 1D gl_ClipDistance variable appears as an argument in an ir_call + * expression, replace it with a temporary variable, and make sure the ir_call + * is preceded and/or followed by assignments that copy the contents of the + * temporary variable to and/or from gl_ClipDistance. Each of these + * assignments is then lowered to refer to gl_ClipDistanceMESA. + * + * We need to do a similar replacement for 2D gl_ClipDistance, however since + * it's an input, the only case we need to address is where a 1D slice of it + * is passed as an "in" parameter to an ir_call, e.g.: + * + * foo(gl_in[i].gl_ClipDistance) */ ir_visitor_status lower_clip_distance_visitor::visit_leave(ir_call *ir) @@ -352,12 +483,12 @@ lower_clip_distance_visitor::visit_leave(ir_call *ir) formal_param_node = formal_param_node->next; actual_param_node = actual_param_node->next; - ir_dereference_variable *deref = actual_param->as_dereference_variable(); - if (deref && deref->var == this->old_clip_distance_var) { - /* User is trying to pass the whole gl_ClipDistance array to a - * function call. Since we are reshaping gl_ClipDistance from an - * array of floats to an array of vec4's, this isn't going to work - * anymore, so use a temporary array instead. + if (this->is_clip_distance_vec8(actual_param)) { + /* User is trying to pass the whole 1D gl_ClipDistance array (or a 1D + * slice of a 2D gl_ClipDistance array) to a function call. Since we + * are reshaping gl_ClipDistance from an array of floats to an array + * of vec4's, this isn't going to work anymore, so use a temporary + * array instead. */ ir_variable *temp_clip_distance = new(ctx) ir_variable( actual_param->type, "temp_clip_distance", ir_var_temporary); @@ -373,7 +504,7 @@ lower_clip_distance_visitor::visit_leave(ir_call *ir) */ ir_assignment *new_assignment = new(ctx) ir_assignment( new(ctx) ir_dereference_variable(temp_clip_distance), - new(ctx) ir_dereference_variable(old_clip_distance_var)); + actual_param->clone(ctx, NULL)); this->base_ir->insert_before(new_assignment); this->visit_new_assignment(new_assignment); } @@ -385,7 +516,7 @@ lower_clip_distance_visitor::visit_leave(ir_call *ir) * afterwards to make sure it gets lowered. */ ir_assignment *new_assignment = new(ctx) ir_assignment( - new(ctx) ir_dereference_variable(old_clip_distance_var), + actual_param->clone(ctx, NULL), new(ctx) ir_dereference_variable(temp_clip_distance)); this->base_ir->insert_after(new_assignment); this->visit_new_assignment(new_assignment); @@ -400,12 +531,14 @@ lower_clip_distance_visitor::visit_leave(ir_call *ir) bool lower_clip_distance(gl_shader *shader) { - lower_clip_distance_visitor v; + lower_clip_distance_visitor v(shader->Type); visit_list_elements(&v, shader->ir); - if (v.new_clip_distance_var) - shader->symbols->add_variable(v.new_clip_distance_var); + if (v.new_clip_distance_1d_var) + shader->symbols->add_variable(v.new_clip_distance_1d_var); + if (v.new_clip_distance_2d_var) + shader->symbols->add_variable(v.new_clip_distance_2d_var); return v.progress; } diff --git a/mesalib/src/glsl/lower_named_interface_blocks.cpp b/mesalib/src/glsl/lower_named_interface_blocks.cpp index 7019185a2..f415252ba 100644 --- a/mesalib/src/glsl/lower_named_interface_blocks.cpp +++ b/mesalib/src/glsl/lower_named_interface_blocks.cpp @@ -150,8 +150,9 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions) var_name, (ir_variable_mode) var->mode); } + new_var->location = iface_t->fields.structure[i].location; - new_var->interface_type = iface_t; + new_var->init_interface_type(iface_t); hash_table_insert(interface_namespace, new_var, iface_field_name); insert_pos->insert_after(new_var); @@ -207,9 +208,9 @@ flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue) if (var->mode == ir_var_uniform) return; - if (var->interface_type != NULL) { + if (var->get_interface_type() != NULL) { char *iface_field_name = - ralloc_asprintf(mem_ctx, "%s.%s", var->interface_type->name, + ralloc_asprintf(mem_ctx, "%s.%s", var->get_interface_type()->name, ir->field); /* Find the variable in the set of flattened interface blocks */ ir_variable *found_var = diff --git a/mesalib/src/glsl/lower_ubo_reference.cpp b/mesalib/src/glsl/lower_ubo_reference.cpp index aade203e7..16b6801b8 100644 --- a/mesalib/src/glsl/lower_ubo_reference.cpp +++ b/mesalib/src/glsl/lower_ubo_reference.cpp @@ -132,7 +132,8 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue) mem_ctx = ralloc_parent(*rvalue); const char *const field_name = - interface_field_name(mem_ctx, (char *) var->interface_type->name, deref); + interface_field_name(mem_ctx, (char *) var->get_interface_type()->name, + deref); this->uniform_block = -1; for (unsigned i = 0; i < shader->NumUniformBlocks; i++) { diff --git a/mesalib/src/glsl/main.cpp b/mesalib/src/glsl/main.cpp index 57bec44be..aa188b1f1 100644 --- a/mesalib/src/glsl/main.cpp +++ b/mesalib/src/glsl/main.cpp @@ -38,6 +38,8 @@ #include "loop_analysis.h" #include "standalone_scaffolding.h" +static int glsl_version = 330; + static void initialize_context(struct gl_context *ctx, gl_api api) { @@ -46,16 +48,150 @@ initialize_context(struct gl_context *ctx, gl_api api) /* The standalone compiler needs to claim support for almost * everything in order to compile the built-in functions. */ - ctx->Const.GLSLVersion = 330; + ctx->Const.GLSLVersion = glsl_version; ctx->Extensions.ARB_ES3_compatibility = true; - ctx->Const.MaxClipPlanes = 8; - ctx->Const.MaxDrawBuffers = 2; - - /* More than the 1.10 minimum to appease parser tests taken from - * apps that (hopefully) already checked the number of coords. - */ - ctx->Const.MaxTextureCoordUnits = 4; + switch (ctx->Const.GLSLVersion) { + case 100: + ctx->Const.MaxClipPlanes = 0; + ctx->Const.MaxCombinedTextureImageUnits = 8; + ctx->Const.MaxDrawBuffers = 2; + ctx->Const.MinProgramTexelOffset = 0; + ctx->Const.MaxProgramTexelOffset = 0; + ctx->Const.MaxLights = 0; + ctx->Const.MaxTextureCoordUnits = 0; + ctx->Const.MaxTextureUnits = 8; + + ctx->Const.VertexProgram.MaxAttribs = 8; + ctx->Const.VertexProgram.MaxTextureImageUnits = 0; + ctx->Const.VertexProgram.MaxUniformComponents = 128 * 4; + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */ + ctx->Const.VertexProgram.MaxOutputComponents = 32; + + ctx->Const.FragmentProgram.MaxTextureImageUnits = + ctx->Const.MaxCombinedTextureImageUnits; + ctx->Const.FragmentProgram.MaxUniformComponents = 16 * 4; + ctx->Const.FragmentProgram.MaxInputComponents = + ctx->Const.VertexProgram.MaxOutputComponents; + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */ + + ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4; + break; + case 110: + case 120: + ctx->Const.MaxClipPlanes = 6; + ctx->Const.MaxCombinedTextureImageUnits = 2; + ctx->Const.MaxDrawBuffers = 1; + ctx->Const.MinProgramTexelOffset = 0; + ctx->Const.MaxProgramTexelOffset = 0; + ctx->Const.MaxLights = 8; + ctx->Const.MaxTextureCoordUnits = 2; + ctx->Const.MaxTextureUnits = 2; + + ctx->Const.VertexProgram.MaxAttribs = 16; + ctx->Const.VertexProgram.MaxTextureImageUnits = 0; + ctx->Const.VertexProgram.MaxUniformComponents = 512; + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */ + ctx->Const.VertexProgram.MaxOutputComponents = 32; + + ctx->Const.FragmentProgram.MaxTextureImageUnits = + ctx->Const.MaxCombinedTextureImageUnits; + ctx->Const.FragmentProgram.MaxUniformComponents = 64; + ctx->Const.FragmentProgram.MaxInputComponents = + ctx->Const.VertexProgram.MaxOutputComponents; + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */ + + ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4; + break; + case 130: + case 140: + ctx->Const.MaxClipPlanes = 8; + ctx->Const.MaxCombinedTextureImageUnits = 16; + ctx->Const.MaxDrawBuffers = 8; + ctx->Const.MinProgramTexelOffset = -8; + ctx->Const.MaxProgramTexelOffset = 7; + ctx->Const.MaxLights = 8; + ctx->Const.MaxTextureCoordUnits = 8; + ctx->Const.MaxTextureUnits = 2; + + ctx->Const.VertexProgram.MaxAttribs = 16; + ctx->Const.VertexProgram.MaxTextureImageUnits = 16; + ctx->Const.VertexProgram.MaxUniformComponents = 1024; + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */ + ctx->Const.VertexProgram.MaxOutputComponents = 64; + + ctx->Const.FragmentProgram.MaxTextureImageUnits = 16; + ctx->Const.FragmentProgram.MaxUniformComponents = 1024; + ctx->Const.FragmentProgram.MaxInputComponents = + ctx->Const.VertexProgram.MaxOutputComponents; + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */ + + ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4; + break; + case 150: + case 330: + ctx->Const.MaxClipPlanes = 8; + ctx->Const.MaxDrawBuffers = 8; + ctx->Const.MinProgramTexelOffset = -8; + ctx->Const.MaxProgramTexelOffset = 7; + ctx->Const.MaxLights = 8; + ctx->Const.MaxTextureCoordUnits = 8; + ctx->Const.MaxTextureUnits = 2; + + ctx->Const.VertexProgram.MaxAttribs = 16; + ctx->Const.VertexProgram.MaxTextureImageUnits = 16; + ctx->Const.VertexProgram.MaxUniformComponents = 1024; + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */ + ctx->Const.VertexProgram.MaxOutputComponents = 64; + + ctx->Const.GeometryProgram.MaxTextureImageUnits = 16; + ctx->Const.GeometryProgram.MaxUniformComponents = 1024; + ctx->Const.GeometryProgram.MaxInputComponents = + ctx->Const.VertexProgram.MaxOutputComponents; + ctx->Const.GeometryProgram.MaxOutputComponents = 128; + + ctx->Const.FragmentProgram.MaxTextureImageUnits = 16; + ctx->Const.FragmentProgram.MaxUniformComponents = 1024; + ctx->Const.FragmentProgram.MaxInputComponents = + ctx->Const.GeometryProgram.MaxOutputComponents; + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */ + + ctx->Const.MaxCombinedTextureImageUnits = + ctx->Const.VertexProgram.MaxTextureImageUnits + + ctx->Const.GeometryProgram.MaxTextureImageUnits + + ctx->Const.FragmentProgram.MaxTextureImageUnits; + + ctx->Const.MaxGeometryOutputVertices = 256; + ctx->Const.MaxGeometryTotalOutputComponents = 1024; + +// ctx->Const.MaxGeometryVaryingComponents = 64; + + ctx->Const.MaxVarying = 60 / 4; + break; + case 300: + ctx->Const.MaxClipPlanes = 8; + ctx->Const.MaxCombinedTextureImageUnits = 32; + ctx->Const.MaxDrawBuffers = 4; + ctx->Const.MinProgramTexelOffset = -8; + ctx->Const.MaxProgramTexelOffset = 7; + ctx->Const.MaxLights = 0; + ctx->Const.MaxTextureCoordUnits = 0; + ctx->Const.MaxTextureUnits = 0; + + ctx->Const.VertexProgram.MaxAttribs = 16; + ctx->Const.VertexProgram.MaxTextureImageUnits = 16; + ctx->Const.VertexProgram.MaxUniformComponents = 1024; + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */ + ctx->Const.VertexProgram.MaxOutputComponents = 16 * 4; + + ctx->Const.FragmentProgram.MaxTextureImageUnits = 16; + ctx->Const.FragmentProgram.MaxUniformComponents = 224; + ctx->Const.FragmentProgram.MaxInputComponents = 15 * 4; + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */ + + ctx->Const.MaxVarying = ctx->Const.FragmentProgram.MaxInputComponents / 4; + break; + } ctx->Driver.NewShader = _mesa_new_shader; } @@ -103,18 +239,17 @@ load_text_file(void *ctx, const char *file_name) return text; } -int glsl_es = 0; int dump_ast = 0; int dump_hir = 0; int dump_lir = 0; int do_link = 0; const struct option compiler_opts[] = { - { "glsl-es", 0, &glsl_es, 1 }, - { "dump-ast", 0, &dump_ast, 1 }, - { "dump-hir", 0, &dump_hir, 1 }, - { "dump-lir", 0, &dump_lir, 1 }, - { "link", 0, &do_link, 1 }, + { "dump-ast", no_argument, &dump_ast, 1 }, + { "dump-hir", no_argument, &dump_hir, 1 }, + { "dump-lir", no_argument, &dump_lir, 1 }, + { "link", no_argument, &do_link, 1 }, + { "version", required_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; @@ -159,11 +294,37 @@ main(int argc, char **argv) int status = EXIT_SUCCESS; struct gl_context local_ctx; struct gl_context *ctx = &local_ctx; + bool glsl_es = false; int c; int idx = 0; - while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1) - /* empty */ ; + while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1) { + switch (c) { + case 'v': + glsl_version = strtol(optarg, NULL, 10); + switch (glsl_version) { + case 100: + case 300: + glsl_es = true; + break; + case 110: + case 120: + case 130: + case 140: + case 150: + case 330: + glsl_es = false; + break; + default: + fprintf(stderr, "Unrecognized GLSL version `%s'\n", optarg); + usage_fail(argv[0]); + break; + } + break; + default: + break; + } + } if (argc <= optind) @@ -210,8 +371,10 @@ main(int argc, char **argv) compile_shader(ctx, shader); - if (!shader->CompileStatus) { + if (strlen(shader->InfoLog) > 0) printf("Info log for %s:\n%s\n", argv[optind], shader->InfoLog); + + if (!shader->CompileStatus) { status = EXIT_FAILURE; break; } diff --git a/mesalib/src/glsl/standalone_scaffolding.cpp b/mesalib/src/glsl/standalone_scaffolding.cpp index 3b64f2cfc..7a1cf6877 100644 --- a/mesalib/src/glsl/standalone_scaffolding.cpp +++ b/mesalib/src/glsl/standalone_scaffolding.cpp @@ -90,23 +90,33 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api) ctx->Extensions.dummy_false = false; ctx->Extensions.dummy_true = true; - ctx->Extensions.ARB_ES2_compatibility = true; - ctx->Extensions.ARB_ES3_compatibility = false; + ctx->Extensions.ARB_conservative_depth = true; ctx->Extensions.ARB_draw_instanced = true; + ctx->Extensions.ARB_ES2_compatibility = true; + ctx->Extensions.ARB_ES3_compatibility = true; + ctx->Extensions.ARB_explicit_attrib_location = true; ctx->Extensions.ARB_fragment_coord_conventions = true; - ctx->Extensions.EXT_texture_array = true; - ctx->Extensions.NV_texture_rectangle = true; - ctx->Extensions.EXT_texture3D = true; - ctx->Extensions.OES_EGL_image_external = true; + ctx->Extensions.ARB_gpu_shader5 = true; ctx->Extensions.ARB_shader_bit_encoding = true; + ctx->Extensions.ARB_shader_stencil_export = true; + ctx->Extensions.ARB_shader_texture_lod = true; + ctx->Extensions.ARB_shading_language_420pack = true; ctx->Extensions.ARB_shading_language_packing = true; - ctx->Extensions.OES_standard_derivatives = true; ctx->Extensions.ARB_texture_cube_map_array = true; + ctx->Extensions.ARB_texture_gather = true; ctx->Extensions.ARB_texture_multisample = true; ctx->Extensions.ARB_texture_query_levels = true; ctx->Extensions.ARB_texture_query_lod = true; - ctx->Extensions.ARB_gpu_shader5 = true; - ctx->Extensions.ARB_texture_gather = true; + ctx->Extensions.ARB_uniform_buffer_object = true; + + ctx->Extensions.OES_EGL_image_external = true; + ctx->Extensions.OES_standard_derivatives = true; + + ctx->Extensions.EXT_shader_integer_mix = true; + ctx->Extensions.EXT_texture3D = true; + ctx->Extensions.EXT_texture_array = true; + + ctx->Extensions.NV_texture_rectangle = true; ctx->Const.GLSLVersion = 120; |