diff options
Diffstat (limited to 'mesalib/src/glsl')
54 files changed, 704 insertions, 800 deletions
diff --git a/mesalib/src/glsl/ast_function.cpp b/mesalib/src/glsl/ast_function.cpp index e4c0fd1c4..2d05d0723 100644 --- a/mesalib/src/glsl/ast_function.cpp +++ b/mesalib/src/glsl/ast_function.cpp @@ -293,15 +293,10 @@ generate_call(exec_list *instructions, ir_function_signature *sig, * call takes place. Since we haven't emitted the call yet, we'll place * the post-call conversions in a temporary exec_list, and emit them later. */ - exec_list_iterator actual_iter = actual_parameters->iterator(); - exec_list_iterator formal_iter = sig->parameters.iterator(); - - while (actual_iter.has_next()) { - ir_rvalue *actual = (ir_rvalue *) actual_iter.get(); - ir_variable *formal = (ir_variable *) formal_iter.get(); - - assert(actual != NULL); - assert(formal != NULL); + foreach_two_lists(formal_node, &sig->parameters, + actual_node, actual_parameters) { + ir_rvalue *actual = (ir_rvalue *) actual_node; + ir_variable *formal = (ir_variable *) formal_node; if (formal->type->is_numeric() || formal->type->is_boolean()) { switch (formal->data.mode) { @@ -323,9 +318,6 @@ generate_call(exec_list *instructions, ir_function_signature *sig, break; } } - - actual_iter.next(); - formal_iter.next(); } /* If the function call is a constant expression, don't generate any diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp index 91810f985..4cc8eb18d 100644 --- a/mesalib/src/glsl/ast_to_hir.cpp +++ b/mesalib/src/glsl/ast_to_hir.cpp @@ -1860,7 +1860,7 @@ ast_fully_specified_type::glsl_type(const char **name, if (type->base_type == GLSL_TYPE_FLOAT && state->es_shader - && state->target == MESA_SHADER_FRAGMENT + && state->stage == MESA_SHADER_FRAGMENT && this->qualifier.precision == ast_precision_none && state->symbols->get_variable("#default precision") == NULL) { YYLTYPE loc = this->get_location(); @@ -1882,7 +1882,7 @@ ast_fully_specified_type::glsl_type(const char **name, * this function will produce undefined results. */ static bool -is_varying_var(ir_variable *var, gl_shader_type target) +is_varying_var(ir_variable *var, gl_shader_stage target) { switch (target) { case MESA_SHADER_VERTEX: @@ -1983,18 +1983,7 @@ validate_binding_qualifier(struct _mesa_glsl_parse_state *state, * with an array of size N, all elements of the array from binding * through binding + N - 1 must be within this range." */ - unsigned limit = 0; - switch (state->target) { - case MESA_SHADER_VERTEX: - limit = ctx->Const.VertexProgram.MaxTextureImageUnits; - break; - case MESA_SHADER_GEOMETRY: - limit = ctx->Const.GeometryProgram.MaxTextureImageUnits; - break; - case MESA_SHADER_FRAGMENT: - limit = ctx->Const.FragmentProgram.MaxTextureImageUnits; - break; - } + unsigned limit = ctx->Const.Program[state->stage].MaxTextureImageUnits; if (max_index >= limit) { _mesa_glsl_error(loc, state, "layout(binding = %d) for %d samplers " @@ -2049,8 +2038,8 @@ interpret_interpolation_qualifier(const struct ast_type_qualifier *qual, } - if ((state->target == MESA_SHADER_VERTEX && mode == ir_var_shader_in) || - (state->target == MESA_SHADER_FRAGMENT && mode == ir_var_shader_out)) { + if ((state->stage == MESA_SHADER_VERTEX && mode == ir_var_shader_in) || + (state->stage == MESA_SHADER_FRAGMENT && mode == ir_var_shader_out)) { _mesa_glsl_error(loc, state, "interpolation qualifier `%s' cannot be applied to " "vertex shader inputs or fragment shader outputs", @@ -2076,7 +2065,7 @@ validate_explicit_location(const struct ast_type_qualifier *qual, * In the fragment shader only shader outputs can be given explicit * locations. */ - switch (state->target) { + switch (state->stage) { case MESA_SHADER_VERTEX: if (var->data.mode == ir_var_shader_in) { if (!state->check_explicit_attrib_location_allowed(loc, var)) @@ -2110,7 +2099,7 @@ validate_explicit_location(const struct ast_type_qualifier *qual, _mesa_glsl_error(loc, state, "%s cannot be given an explicit location in %s shader", mode_string(var), - _mesa_shader_type_to_string(state->target)); + _mesa_shader_stage_to_string(state->stage)); } else { var->data.explicit_location = true; @@ -2122,7 +2111,7 @@ validate_explicit_location(const struct ast_type_qualifier *qual, * ensures that negative values stay negative. */ if (qual->location >= 0) { - var->data.location = (state->target == MESA_SHADER_VERTEX) + var->data.location = (state->stage == MESA_SHADER_VERTEX) ? (qual->location + VERT_ATTRIB_GENERIC0) : (qual->location + FRAG_RESULT_DATA0); } else { @@ -2174,7 +2163,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, if (qual->flags.q.constant || qual->flags.q.attribute || qual->flags.q.uniform - || (qual->flags.q.varying && (state->target == MESA_SHADER_FRAGMENT))) + || (qual->flags.q.varying && (state->stage == MESA_SHADER_FRAGMENT))) var->data.read_only = 1; if (qual->flags.q.centroid) @@ -2183,12 +2172,12 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, if (qual->flags.q.sample) var->data.sample = 1; - if (qual->flags.q.attribute && state->target != MESA_SHADER_VERTEX) { + if (qual->flags.q.attribute && state->stage != MESA_SHADER_VERTEX) { var->type = glsl_type::error_type; _mesa_glsl_error(loc, state, "`attribute' variables may not be declared in the " "%s shader", - _mesa_shader_type_to_string(state->target)); + _mesa_shader_stage_to_string(state->stage)); } /* Section 6.1.1 (Function Calling Conventions) of the GLSL 1.10 spec says: @@ -2214,16 +2203,16 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, else if (qual->flags.q.in) var->data.mode = is_parameter ? ir_var_function_in : ir_var_shader_in; else if (qual->flags.q.attribute - || (qual->flags.q.varying && (state->target == MESA_SHADER_FRAGMENT))) + || (qual->flags.q.varying && (state->stage == MESA_SHADER_FRAGMENT))) var->data.mode = ir_var_shader_in; else if (qual->flags.q.out) var->data.mode = is_parameter ? ir_var_function_out : ir_var_shader_out; - else if (qual->flags.q.varying && (state->target == MESA_SHADER_VERTEX)) + else if (qual->flags.q.varying && (state->stage == MESA_SHADER_VERTEX)) var->data.mode = ir_var_shader_out; else if (qual->flags.q.uniform) var->data.mode = ir_var_uniform; - if (!is_parameter && is_varying_var(var, state->target)) { + if (!is_parameter && is_varying_var(var, state->stage)) { /* This variable is being used to link data between shader stages (in * pre-glsl-1.30 parlance, it's a "varying"). Check that it has a type * that is allowed for such purposes. @@ -2272,7 +2261,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual, } if (state->all_invariant && (state->current_function == NULL)) { - switch (state->target) { + switch (state->stage) { case MESA_SHADER_VERTEX: if (var->data.mode == ir_var_shader_out) var->data.invariant = true; @@ -2599,8 +2588,8 @@ process_initializer(ir_variable *var, ast_declaration *decl, if ((var->data.mode == ir_var_shader_in) && (state->current_function == NULL)) { _mesa_glsl_error(& initializer_loc, state, "cannot initialize %s shader input / %s", - _mesa_shader_type_to_string(state->target), - (state->target == MESA_SHADER_VERTEX) + _mesa_shader_stage_to_string(state->stage), + (state->stage == MESA_SHADER_VERTEX) ? "attribute" : "varying"); } @@ -2844,12 +2833,12 @@ ast_declarator_list::hir(exec_list *instructions, _mesa_glsl_error(& loc, state, "undeclared variable `%s' cannot be marked " "invariant", decl->identifier); - } else if ((state->target == MESA_SHADER_VERTEX) + } else if ((state->stage == MESA_SHADER_VERTEX) && (earlier->data.mode != ir_var_shader_out)) { _mesa_glsl_error(& loc, state, "`%s' cannot be marked invariant, vertex shader " "outputs only", decl->identifier); - } else if ((state->target == MESA_SHADER_FRAGMENT) + } else if ((state->stage == MESA_SHADER_FRAGMENT) && (earlier->data.mode != ir_var_shader_in)) { _mesa_glsl_error(& loc, state, "`%s' cannot be marked invariant, fragment shader " @@ -3034,12 +3023,12 @@ ast_declarator_list::hir(exec_list *instructions, & loc, false); if (this->type->qualifier.flags.q.invariant) { - if ((state->target == MESA_SHADER_VERTEX) && + if ((state->stage == MESA_SHADER_VERTEX) && var->data.mode != ir_var_shader_out) { _mesa_glsl_error(& loc, state, "`%s' cannot be marked invariant, vertex shader " "outputs only", var->name); - } else if ((state->target == MESA_SHADER_FRAGMENT) && + } else if ((state->stage == MESA_SHADER_FRAGMENT) && var->data.mode != ir_var_shader_in) { /* FINISHME: Note that this doesn't work for invariant on * a function signature inval @@ -3080,7 +3069,7 @@ ast_declarator_list::hir(exec_list *instructions, } else if (var->data.mode == ir_var_shader_in) { var->data.read_only = true; - if (state->target == MESA_SHADER_VERTEX) { + if (state->stage == MESA_SHADER_VERTEX) { bool error_emitted = false; /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec: @@ -3135,7 +3124,7 @@ ast_declarator_list::hir(exec_list *instructions, "cannot have array type")) { error_emitted = true; } - } else if (state->target == MESA_SHADER_GEOMETRY) { + } else if (state->stage == MESA_SHADER_GEOMETRY) { /* From section 4.3.4 (Inputs) of the GLSL 1.50 spec: * * Geometry shader input variables get the per-vertex values @@ -3185,10 +3174,10 @@ ast_declarator_list::hir(exec_list *instructions, if (state->is_version(130, 300) && var->type->contains_integer() && var->data.interpolation != INTERP_QUALIFIER_FLAT && - ((state->target == MESA_SHADER_FRAGMENT && var->data.mode == ir_var_shader_in) - || (state->target == MESA_SHADER_VERTEX && var->data.mode == ir_var_shader_out + ((state->stage == MESA_SHADER_FRAGMENT && var->data.mode == ir_var_shader_in) + || (state->stage == MESA_SHADER_VERTEX && var->data.mode == ir_var_shader_out && state->es_shader))) { - const char *var_type = (state->target == MESA_SHADER_VERTEX) ? + const char *var_type = (state->stage == MESA_SHADER_VERTEX) ? "vertex output" : "fragment input"; _mesa_glsl_error(&loc, state, "if a %s is (or contains) " "an integer, then it must be qualified with 'flat'", @@ -3244,7 +3233,7 @@ ast_declarator_list::hir(exec_list *instructions, const char *i = this->type->qualifier.interpolation_string(); assert(i != NULL); - switch (state->target) { + switch (state->stage) { case MESA_SHADER_VERTEX: if (this->type->qualifier.flags.q.in) { _mesa_glsl_error(&loc, state, @@ -3275,13 +3264,13 @@ ast_declarator_list::hir(exec_list *instructions, if (state->is_version(130, 300) && this->type->qualifier.flags.q.centroid && this->type->qualifier.flags.q.in - && state->target == MESA_SHADER_VERTEX) { + && state->stage == MESA_SHADER_VERTEX) { _mesa_glsl_error(&loc, state, "'centroid in' cannot be used in a vertex shader"); } - if (state->target == MESA_SHADER_VERTEX + if (state->stage == MESA_SHADER_VERTEX && this->type->qualifier.flags.q.sample && this->type->qualifier.flags.q.in) { @@ -3296,7 +3285,7 @@ ast_declarator_list::hir(exec_list *instructions, * "It is an error to use auxiliary storage qualifiers or interpolation * qualifiers on an output in a fragment shader." */ - if (state->target == MESA_SHADER_FRAGMENT && + if (state->stage == MESA_SHADER_FRAGMENT && this->type->qualifier.flags.q.out && this->type->qualifier.has_auxiliary_storage()) { _mesa_glsl_error(&loc, state, @@ -3829,8 +3818,8 @@ ast_function_definition::hir(exec_list *instructions, * Add these to the symbol table. */ state->symbols->push_scope(); - foreach_iter(exec_list_iterator, iter, signature->parameters) { - ir_variable *const var = ((ir_instruction *) iter.get())->as_variable(); + foreach_list(n, &signature->parameters) { + ir_variable *const var = ((ir_instruction *) n)->as_variable(); assert(var != NULL); @@ -3954,7 +3943,7 @@ ast_jump_statement::hir(exec_list *instructions, } case ast_discard: - if (state->target != MESA_SHADER_FRAGMENT) { + if (state->stage != MESA_SHADER_FRAGMENT) { YYLTYPE loc = this->get_location(); _mesa_glsl_error(& loc, state, @@ -4492,7 +4481,7 @@ ast_type_specifier::hir(exec_list *instructions, if (type->base_type == GLSL_TYPE_FLOAT && state->es_shader - && state->target == MESA_SHADER_FRAGMENT) { + && state->stage == MESA_SHADER_FRAGMENT) { /* Section 4.5.3 (Default Precision Qualifiers) of the GLSL ES 1.00 * spec says: * @@ -4890,7 +4879,7 @@ ast_interface_block::hir(exec_list *instructions, _mesa_glsl_error(&loc, state, "redeclaration of gl_PerVertex input not allowed " "in the %s shader", - _mesa_shader_type_to_string(state->target)); + _mesa_shader_stage_to_string(state->stage)); } if (this->instance_name == NULL || strcmp(this->instance_name, "gl_in") != 0 || !this->is_array) { @@ -4907,7 +4896,7 @@ ast_interface_block::hir(exec_list *instructions, _mesa_glsl_error(&loc, state, "redeclaration of gl_PerVertex output not " "allowed in the %s shader", - _mesa_shader_type_to_string(state->target)); + _mesa_shader_stage_to_string(state->stage)); } if (this->instance_name != NULL) { _mesa_glsl_error(&loc, state, @@ -4995,7 +4984,7 @@ ast_interface_block::hir(exec_list *instructions, * variable (or input block, see interface blocks below) needs to be * declared as an array. */ - if (state->target == MESA_SHADER_GEOMETRY && !this->is_array && + if (state->stage == MESA_SHADER_GEOMETRY && !this->is_array && var_mode == ir_var_shader_in) { _mesa_glsl_error(&loc, state, "geometry shader inputs must be arrays"); } @@ -5050,7 +5039,7 @@ ast_interface_block::hir(exec_list *instructions, * geometry shader input. */ if (this->array_size == NULL && - (state->target != MESA_SHADER_GEOMETRY || !this->layout.flags.q.in)) { + (state->stage != MESA_SHADER_GEOMETRY || !this->layout.flags.q.in)) { _mesa_glsl_error(&loc, state, "only geometry shader inputs may be unsized " "instance block arrays"); @@ -5069,7 +5058,7 @@ ast_interface_block::hir(exec_list *instructions, var_mode); } - if (state->target == MESA_SHADER_GEOMETRY && var_mode == ir_var_shader_in) + if (state->stage == MESA_SHADER_GEOMETRY && var_mode == ir_var_shader_in) handle_geometry_shader_input_decl(state, loc, var); if (ir_variable *earlier = @@ -5265,7 +5254,7 @@ detect_conflicting_assignments(struct _mesa_glsl_parse_state *state, else if (strcmp(var->name, "gl_FragData") == 0) gl_FragData_assigned = true; else if (strncmp(var->name, "gl_", 3) != 0) { - if (state->target == MESA_SHADER_FRAGMENT && + if (state->stage == MESA_SHADER_FRAGMENT && var->data.mode == ir_var_shader_out) { user_defined_fs_output_assigned = true; user_defined_fs_output = var; diff --git a/mesalib/src/glsl/builtin_functions.cpp b/mesalib/src/glsl/builtin_functions.cpp index f22ace19d..b1065f48d 100644..100755 --- a/mesalib/src/glsl/builtin_functions.cpp +++ b/mesalib/src/glsl/builtin_functions.cpp @@ -77,7 +77,7 @@ always_available(const _mesa_glsl_parse_state *state) static bool compatibility_vs_only(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_VERTEX && + return state->stage == MESA_SHADER_VERTEX && state->language_version <= 130 && !state->es_shader; } @@ -85,13 +85,13 @@ compatibility_vs_only(const _mesa_glsl_parse_state *state) static bool fs_only(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_FRAGMENT; + return state->stage == MESA_SHADER_FRAGMENT; } static bool gs_only(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_GEOMETRY; + return state->stage == MESA_SHADER_GEOMETRY; } static bool @@ -103,7 +103,7 @@ v110(const _mesa_glsl_parse_state *state) static bool v110_fs_only(const _mesa_glsl_parse_state *state) { - return !state->es_shader && state->target == MESA_SHADER_FRAGMENT; + return !state->es_shader && state->stage == MESA_SHADER_FRAGMENT; } static bool @@ -122,7 +122,7 @@ static bool v130_fs_only(const _mesa_glsl_parse_state *state) { return state->is_version(130, 300) && - state->target == MESA_SHADER_FRAGMENT; + state->stage == MESA_SHADER_FRAGMENT; } static bool @@ -155,7 +155,7 @@ lod_exists_in_stage(const _mesa_glsl_parse_state *state) * Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we * don't need to explicitly check state->es_shader. */ - return state->target == MESA_SHADER_VERTEX || + return state->stage == MESA_SHADER_VERTEX || state->is_version(130, 300) || state->ARB_shader_texture_lod_enable; } @@ -223,7 +223,7 @@ texture_array_lod(const _mesa_glsl_parse_state *state) static bool fs_texture_array(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_FRAGMENT && + return state->stage == MESA_SHADER_FRAGMENT && state->EXT_texture_array_enable; } @@ -243,7 +243,7 @@ texture_multisample(const _mesa_glsl_parse_state *state) static bool fs_texture_cube_map_array(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_FRAGMENT && + return state->stage == MESA_SHADER_FRAGMENT && (state->is_version(400, 0) || state->ARB_texture_cube_map_array_enable); } @@ -265,7 +265,7 @@ texture_query_levels(const _mesa_glsl_parse_state *state) static bool texture_query_lod(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_FRAGMENT && + return state->stage == MESA_SHADER_FRAGMENT && state->ARB_texture_query_lod_enable; } @@ -292,7 +292,7 @@ texture_gather_only(const _mesa_glsl_parse_state *state) static bool fs_oes_derivatives(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_FRAGMENT && + return state->stage == MESA_SHADER_FRAGMENT && (state->is_version(110, 300) || state->OES_standard_derivatives_enable); } @@ -318,7 +318,7 @@ tex3d(const _mesa_glsl_parse_state *state) static bool fs_tex3d(const _mesa_glsl_parse_state *state) { - return state->target == MESA_SHADER_FRAGMENT && + return state->stage == MESA_SHADER_FRAGMENT && (!state->es_shader || state->OES_texture_3D_enable); } @@ -334,6 +334,12 @@ shader_atomic_counters(const _mesa_glsl_parse_state *state) return state->ARB_shader_atomic_counters_enable; } +static bool +shader_trinary_minmax(const _mesa_glsl_parse_state *state) +{ + return state->AMD_shader_trinary_minmax_enable; +} + /** @} */ /******************************************************************************/ @@ -570,6 +576,21 @@ private: ir_function_signature *_atomic_op(const char *intrinsic, builtin_available_predicate avail); + ir_function_signature *_min3(builtin_available_predicate avail, + const glsl_type *x_type, + const glsl_type *y_type, + const glsl_type *z_type); + + ir_function_signature *_max3(builtin_available_predicate avail, + const glsl_type *x_type, + const glsl_type *y_type, + const glsl_type *z_type); + + ir_function_signature *_mid3(builtin_available_predicate avail, + const glsl_type *x_type, + const glsl_type *y_type, + const glsl_type *z_type); + #undef B0 #undef B1 #undef B2 @@ -2106,6 +2127,57 @@ builtin_builder::create_builtins() shader_atomic_counters), NULL); + add_function("min3", + _min3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type), + _min3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type), + _min3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type), + _min3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type), + + _min3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type), + _min3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type), + _min3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type), + _min3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type), + + _min3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type), + _min3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type), + _min3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type), + _min3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type), + NULL); + + add_function("max3", + _max3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type), + _max3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type), + _max3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type), + _max3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type), + + _max3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type), + _max3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type), + _max3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type), + _max3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type), + + _max3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type), + _max3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type), + _max3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type), + _max3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type), + NULL); + + add_function("mid3", + _mid3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type), + _mid3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type), + _mid3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type), + _mid3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type), + + _mid3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type), + _mid3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type), + _mid3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type), + _mid3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type), + + _mid3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type), + _mid3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type), + _mid3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type), + _mid3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type), + NULL); + #undef F #undef FI #undef FIU @@ -2326,8 +2398,8 @@ builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params) { exec_list actual_params; - foreach_iter(exec_list_iterator, it, params) { - ir_variable *var = ((ir_instruction *)it.get())->as_variable(); + foreach_list(node, ¶ms) { + ir_variable *var = (ir_variable *) node; actual_params.push_tail(var_ref(var)); } @@ -3864,7 +3936,7 @@ builtin_builder::_fma_mesa(const glsl_type *type) ir_variable *c = in_var(type, "c"); MAKE_SIG(type, gpu_shader5, 3, a, b, c); - body.emit(ret(fma_mesa(a, b, c))); + body.emit(ret(ir_builder::fma(a, b, c))); return sig; } @@ -3991,6 +4063,54 @@ builtin_builder::_atomic_op(const char *intrinsic, return sig; } +ir_function_signature * +builtin_builder::_min3(builtin_available_predicate avail, + const glsl_type *x_type, const glsl_type *y_type, + const glsl_type *z_type) +{ + ir_variable *x = in_var(x_type, "x"); + ir_variable *y = in_var(y_type, "y"); + ir_variable *z = in_var(z_type, "z"); + MAKE_SIG(x_type, avail, 3, x, y, z); + + ir_expression *min3 = min2(x, min2(y,z)); + body.emit(ret(min3)); + + return sig; +} + +ir_function_signature * +builtin_builder::_max3(builtin_available_predicate avail, + const glsl_type *x_type, const glsl_type *y_type, + const glsl_type *z_type) +{ + ir_variable *x = in_var(x_type, "x"); + ir_variable *y = in_var(y_type, "y"); + ir_variable *z = in_var(z_type, "z"); + MAKE_SIG(x_type, avail, 3, x, y, z); + + ir_expression *max3 = max2(x, max2(y,z)); + body.emit(ret(max3)); + + return sig; +} + +ir_function_signature * +builtin_builder::_mid3(builtin_available_predicate avail, + const glsl_type *x_type, const glsl_type *y_type, + const glsl_type *z_type) +{ + ir_variable *x = in_var(x_type, "x"); + ir_variable *y = in_var(y_type, "y"); + ir_variable *z = in_var(z_type, "z"); + MAKE_SIG(x_type, avail, 3, x, y, z); + + ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z))); + body.emit(ret(mid3)); + + return sig; +} + /** @} */ /******************************************************************************/ diff --git a/mesalib/src/glsl/builtin_variables.cpp b/mesalib/src/glsl/builtin_variables.cpp index ff9acb8d0..f630923ed 100644 --- a/mesalib/src/glsl/builtin_variables.cpp +++ b/mesalib/src/glsl/builtin_variables.cpp @@ -554,9 +554,9 @@ builtin_variable_generator::generate_constants() */ if (state->is_version(0, 300)) { add_const("gl_MaxVertexOutputVectors", - state->ctx->Const.VertexProgram.MaxOutputComponents / 4); + state->ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4); add_const("gl_MaxFragmentInputVectors", - state->ctx->Const.FragmentProgram.MaxInputComponents / 4); + state->ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents / 4); } else { add_const("gl_MaxVaryingVectors", state->ctx->Const.MaxVarying); @@ -876,7 +876,7 @@ builtin_variable_generator::add_varying(int slot, const glsl_type *type, const char *name, const char *name_as_gs_input) { - switch (state->target) { + switch (state->stage) { case MESA_SHADER_GEOMETRY: this->per_vertex_in.add_field(slot, type, name); /* FALLTHROUGH */ @@ -901,7 +901,7 @@ builtin_variable_generator::generate_varyings() add_varying(loc, type, name, name "In") /* gl_Position and gl_PointSize are not visible from fragment shaders. */ - if (state->target != MESA_SHADER_FRAGMENT) { + if (state->stage != MESA_SHADER_FRAGMENT) { ADD_VARYING(VARYING_SLOT_POS, vec4_t, "gl_Position"); ADD_VARYING(VARYING_SLOT_PSIZ, float_t, "gl_PointSize"); } @@ -914,7 +914,7 @@ builtin_variable_generator::generate_varyings() if (compatibility) { ADD_VARYING(VARYING_SLOT_TEX0, array(vec4_t, 0), "gl_TexCoord"); ADD_VARYING(VARYING_SLOT_FOGC, float_t, "gl_FogFragCoord"); - if (state->target == MESA_SHADER_FRAGMENT) { + if (state->stage == MESA_SHADER_FRAGMENT) { ADD_VARYING(VARYING_SLOT_COL0, vec4_t, "gl_Color"); ADD_VARYING(VARYING_SLOT_COL1, vec4_t, "gl_SecondaryColor"); } else { @@ -926,13 +926,13 @@ builtin_variable_generator::generate_varyings() } } - if (state->target == MESA_SHADER_GEOMETRY) { + if (state->stage == MESA_SHADER_GEOMETRY) { const glsl_type *per_vertex_in_type = this->per_vertex_in.construct_interface_instance(); add_variable("gl_in", array(per_vertex_in_type, 0), ir_var_shader_in, -1); } - if (state->target == MESA_SHADER_VERTEX || state->target == MESA_SHADER_GEOMETRY) { + if (state->stage == MESA_SHADER_VERTEX || state->stage == MESA_SHADER_GEOMETRY) { 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; @@ -963,7 +963,7 @@ _mesa_glsl_initialize_variables(exec_list *instructions, gen.generate_varyings(); - switch (state->target) { + switch (state->stage) { case MESA_SHADER_VERTEX: gen.generate_vs_special_vars(); break; diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y index ef084b639..55c498195 100644 --- a/mesalib/src/glsl/glcpp/glcpp-parse.y +++ b/mesalib/src/glsl/glcpp/glcpp-parse.y @@ -1281,6 +1281,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api) if (extensions->ARB_shader_atomic_counters) add_builtin_define(parser, "GL_ARB_shader_atomic_counters", 1); + + if (extensions->AMD_shader_trinary_minmax) + add_builtin_define(parser, "GL_AMD_shader_trinary_minmax", 1); } } diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy index 6cd129cae..52f674b63 100644 --- a/mesalib/src/glsl/glsl_parser.yy +++ b/mesalib/src/glsl/glsl_parser.yy @@ -2220,11 +2220,11 @@ basic_interface_block: * "It is illegal to have an input block in a vertex shader * or an output block in a fragment shader" */ - if ((state->target == MESA_SHADER_VERTEX) && $1.flags.q.in) { + if ((state->stage == MESA_SHADER_VERTEX) && $1.flags.q.in) { _mesa_glsl_error(& @1, state, "`in' interface block is not allowed for " "a vertex shader"); - } else if ((state->target == MESA_SHADER_FRAGMENT) && $1.flags.q.out) { + } else if ((state->stage == MESA_SHADER_FRAGMENT) && $1.flags.q.out) { _mesa_glsl_error(& @1, state, "`out' interface block is not allowed for " "a fragment shader"); @@ -2378,7 +2378,7 @@ layout_defaults: { void *ctx = state; $$ = NULL; - if (state->target != MESA_SHADER_GEOMETRY) { + if (state->stage != MESA_SHADER_GEOMETRY) { _mesa_glsl_error(& @1, state, "input layout qualifiers only valid in " "geometry shaders"); @@ -2406,7 +2406,7 @@ layout_defaults: | layout_qualifier OUT_TOK ';' { - if (state->target != MESA_SHADER_GEOMETRY) { + if (state->stage != MESA_SHADER_GEOMETRY) { _mesa_glsl_error(& @1, state, "out layout qualifiers only valid in " "geometry shaders"); diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index fc9a8b204..21dc3abd7 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -54,14 +54,12 @@ static unsigned known_desktop_glsl_versions[] = _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, - GLenum target, void *mem_ctx) + gl_shader_stage stage, + void *mem_ctx) : ctx(_ctx), switch_state() { - switch (target) { - case GL_VERTEX_SHADER: this->target = MESA_SHADER_VERTEX; break; - case GL_FRAGMENT_SHADER: this->target = MESA_SHADER_FRAGMENT; break; - case GL_GEOMETRY_SHADER: this->target = MESA_SHADER_GEOMETRY; break; - } + assert(stage < MESA_SHADER_STAGES); + this->stage = stage; this->scanner = NULL; this->translation_unit.make_empty(); @@ -98,30 +96,30 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes; this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits; this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits; - this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs; - this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents; - this->Const.MaxVertexTextureImageUnits = ctx->Const.VertexProgram.MaxTextureImageUnits; + this->Const.MaxVertexAttribs = ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs; + this->Const.MaxVertexUniformComponents = ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents; + this->Const.MaxVertexTextureImageUnits = ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits; this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits; - this->Const.MaxTextureImageUnits = ctx->Const.FragmentProgram.MaxTextureImageUnits; - this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents; + this->Const.MaxTextureImageUnits = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; + this->Const.MaxFragmentUniformComponents = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents; this->Const.MinProgramTexelOffset = ctx->Const.MinProgramTexelOffset; this->Const.MaxProgramTexelOffset = ctx->Const.MaxProgramTexelOffset; 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.MaxVertexOutputComponents = ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents; + this->Const.MaxGeometryInputComponents = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxInputComponents; + this->Const.MaxGeometryOutputComponents = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxOutputComponents; + this->Const.MaxFragmentInputComponents = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents; + this->Const.MaxGeometryTextureImageUnits = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits; this->Const.MaxGeometryOutputVertices = ctx->Const.MaxGeometryOutputVertices; this->Const.MaxGeometryTotalOutputComponents = ctx->Const.MaxGeometryTotalOutputComponents; - this->Const.MaxGeometryUniformComponents = ctx->Const.GeometryProgram.MaxUniformComponents; + this->Const.MaxGeometryUniformComponents = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxUniformComponents; - this->Const.MaxVertexAtomicCounters = ctx->Const.VertexProgram.MaxAtomicCounters; - this->Const.MaxGeometryAtomicCounters = ctx->Const.GeometryProgram.MaxAtomicCounters; - this->Const.MaxFragmentAtomicCounters = ctx->Const.FragmentProgram.MaxAtomicCounters; + this->Const.MaxVertexAtomicCounters = ctx->Const.Program[MESA_SHADER_VERTEX].MaxAtomicCounters; + this->Const.MaxGeometryAtomicCounters = ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxAtomicCounters; + this->Const.MaxFragmentAtomicCounters = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxAtomicCounters; this->Const.MaxCombinedAtomicCounters = ctx->Const.MaxCombinedAtomicCounters; this->Const.MaxAtomicBufferBindings = ctx->Const.MaxAtomicBufferBindings; @@ -331,44 +329,15 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version, } } -extern "C" { - -/** - * Translate a GLenum to a short shader stage name for debug printouts and - * error messages. - * - * It recognizes the PROGRAM variants of the names so it can be used - * with a struct gl_program->Target, not just a struct - * gl_shader->Type. - */ -const char * -_mesa_shader_enum_to_string(GLenum type) -{ - switch (type) { - case GL_VERTEX_SHADER: - case GL_VERTEX_PROGRAM_ARB: - return "vertex"; - case GL_FRAGMENT_SHADER: - case GL_FRAGMENT_PROGRAM_ARB: - return "fragment"; - case GL_GEOMETRY_SHADER: - return "geometry"; - default: - assert(!"Should not get here."); - return "unknown"; - } -} - -} /* extern "C" */ /** - * Translate a gl_shader_type to a short shader stage name for debug printouts - * and error messages. + * Translate a gl_shader_stage to a short shader stage name for debug + * printouts and error messages. */ const char * -_mesa_shader_type_to_string(unsigned target) +_mesa_shader_stage_to_string(unsigned stage) { - switch (target) { + switch (stage) { case MESA_SHADER_VERTEX: return "vertex"; case MESA_SHADER_FRAGMENT: return "fragment"; case MESA_SHADER_GEOMETRY: return "geometry"; @@ -543,6 +512,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = { EXT(ARB_texture_gather, true, false, ARB_texture_gather), EXT(ARB_shader_atomic_counters, true, false, ARB_shader_atomic_counters), EXT(ARB_sample_shading, true, false, ARB_sample_shading), + EXT(AMD_shader_trinary_minmax, true, false, dummy_true), }; #undef EXT @@ -650,11 +620,11 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, if (behavior == extension_require) { _mesa_glsl_error(name_locp, state, fmt, - name, _mesa_shader_type_to_string(state->target)); + name, _mesa_shader_stage_to_string(state->stage)); return false; } else { _mesa_glsl_warning(name_locp, state, fmt, - name, _mesa_shader_type_to_string(state->target)); + name, _mesa_shader_stage_to_string(state->stage)); } } } @@ -1447,7 +1417,7 @@ static void set_shader_inout_layout(struct gl_shader *shader, struct _mesa_glsl_parse_state *state) { - if (shader->Type != GL_GEOMETRY_SHADER) { + if (shader->Stage != MESA_SHADER_GEOMETRY) { /* Should have been prevented by the parser. */ assert(!state->gs_input_prim_type_specified); assert(!state->out_qualifier->flags.i); @@ -1478,7 +1448,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, bool dump_ast, bool dump_hir) { struct _mesa_glsl_parse_state *state = - new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); + new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader); const char *source = shader->Source; state->error = glcpp_preprocess(state, &source, &state->info_log, @@ -1515,7 +1485,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, if (!state->error && !shader->ir->is_empty()) { struct gl_shader_compiler_options *options = - &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)]; + &ctx->ShaderCompilerOptions[shader->Stage]; /* Do some optimization at compile time to reduce shader IR size * and reduce later work if the same shader is linked multiple times diff --git a/mesalib/src/glsl/glsl_parser_extras.h b/mesalib/src/glsl/glsl_parser_extras.h index 6cfa2d661..21a27c9ea 100644 --- a/mesalib/src/glsl/glsl_parser_extras.h +++ b/mesalib/src/glsl/glsl_parser_extras.h @@ -68,7 +68,7 @@ extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state, struct _mesa_glsl_parse_state { - _mesa_glsl_parse_state(struct gl_context *_ctx, GLenum target, + _mesa_glsl_parse_state(struct gl_context *_ctx, gl_shader_stage stage, void *mem_ctx); DECLARE_RALLOC_CXX_OPERATORS(_mesa_glsl_parse_state); @@ -169,7 +169,7 @@ struct _mesa_glsl_parse_state { bool es_shader; unsigned language_version; - gl_shader_type target; + gl_shader_stage stage; /** * Number of nested struct_specifier levels @@ -354,6 +354,8 @@ struct _mesa_glsl_parse_state { bool EXT_shader_integer_mix_warn; bool ARB_shader_atomic_counters_enable; bool ARB_shader_atomic_counters_warn; + bool AMD_shader_trinary_minmax_enable; + bool AMD_shader_trinary_minmax_warn; /*@}*/ /** Extensions supported by the OpenGL implementation. */ @@ -425,14 +427,6 @@ extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, YYLTYPE *behavior_locp, _mesa_glsl_parse_state *state); -/** - * Get the textual name of the specified shader target (which is a - * gl_shader_type). - */ -extern const char * -_mesa_shader_type_to_string(unsigned target); - - #endif /* __cplusplus */ @@ -443,8 +437,12 @@ _mesa_shader_type_to_string(unsigned target); extern "C" { #endif +/** + * Get the textual name of the specified shader stage (which is a + * gl_shader_stage). + */ extern const char * -_mesa_shader_enum_to_string(GLenum type); +_mesa_shader_stage_to_string(unsigned stage); extern int glcpp_preprocess(void *ctx, const char **shader, char **info_log, const struct gl_extensions *extensions, struct gl_context *gl_ctx); diff --git a/mesalib/src/glsl/ir.cpp b/mesalib/src/glsl/ir.cpp index 8af58b847..77638ef26 100644 --- a/mesalib/src/glsl/ir.cpp +++ b/mesalib/src/glsl/ir.cpp @@ -1122,27 +1122,31 @@ ir_constant::has_value(const ir_constant *c) const } bool -ir_constant::is_zero() const +ir_constant::is_value(float f, int i) const { if (!this->type->is_scalar() && !this->type->is_vector()) return false; + /* Only accept boolean values for 0/1. */ + if (int(bool(i)) != i && this->type->is_boolean()) + return false; + for (unsigned c = 0; c < this->type->vector_elements; c++) { switch (this->type->base_type) { case GLSL_TYPE_FLOAT: - if (this->value.f[c] != 0.0) + if (this->value.f[c] != f) return false; break; case GLSL_TYPE_INT: - if (this->value.i[c] != 0) + if (this->value.i[c] != i) return false; break; case GLSL_TYPE_UINT: - if (this->value.u[c] != 0) + if (this->value.u[c] != unsigned(i)) return false; break; case GLSL_TYPE_BOOL: - if (this->value.b[c] != false) + if (this->value.b[c] != bool(i)) return false; break; default: @@ -1159,76 +1163,21 @@ ir_constant::is_zero() const } bool -ir_constant::is_one() const +ir_constant::is_zero() const { - if (!this->type->is_scalar() && !this->type->is_vector()) - return false; - - for (unsigned c = 0; c < this->type->vector_elements; c++) { - switch (this->type->base_type) { - case GLSL_TYPE_FLOAT: - if (this->value.f[c] != 1.0) - return false; - break; - case GLSL_TYPE_INT: - if (this->value.i[c] != 1) - return false; - break; - case GLSL_TYPE_UINT: - if (this->value.u[c] != 1) - return false; - break; - case GLSL_TYPE_BOOL: - if (this->value.b[c] != true) - return false; - break; - default: - /* The only other base types are structures, arrays, and samplers. - * Samplers cannot be constants, and the others should have been - * filtered out above. - */ - assert(!"Should not get here."); - return false; - } - } + return is_value(0.0, 0); +} - return true; +bool +ir_constant::is_one() const +{ + return is_value(1.0, 1); } bool ir_constant::is_negative_one() const { - if (!this->type->is_scalar() && !this->type->is_vector()) - return false; - - if (this->type->is_boolean()) - return false; - - for (unsigned c = 0; c < this->type->vector_elements; c++) { - switch (this->type->base_type) { - case GLSL_TYPE_FLOAT: - if (this->value.f[c] != -1.0) - return false; - break; - case GLSL_TYPE_INT: - if (this->value.i[c] != -1) - return false; - break; - case GLSL_TYPE_UINT: - if (int(this->value.u[c]) != -1) - return false; - break; - default: - /* The only other base types are structures, arrays, samplers, and - * booleans. Samplers cannot be constants, and the others should - * have been filtered out above. - */ - assert(!"Should not get here."); - return false; - } - } - - return true; + return is_value(-1.0, -1); } bool @@ -1700,13 +1649,10 @@ modes_match(unsigned a, unsigned b) const char * ir_function_signature::qualifiers_match(exec_list *params) { - exec_list_iterator iter_a = parameters.iterator(); - exec_list_iterator iter_b = params->iterator(); - /* check that the qualifiers match. */ - while (iter_a.has_next()) { - ir_variable *a = (ir_variable *)iter_a.get(); - ir_variable *b = (ir_variable *)iter_b.get(); + foreach_two_lists(a_node, &this->parameters, b_node, params) { + ir_variable *a = (ir_variable *) a_node; + ir_variable *b = (ir_variable *) b_node; if (a->data.read_only != b->data.read_only || !modes_match(a->data.mode, b->data.mode) || @@ -1717,9 +1663,6 @@ ir_function_signature::qualifiers_match(exec_list *params) /* parameter a's qualifiers don't match */ return a->name; } - - iter_a.next(); - iter_b.next(); } return NULL; } @@ -1768,8 +1711,8 @@ ir_rvalue::error_value(void *mem_ctx) void visit_exec_list(exec_list *list, ir_visitor *visitor) { - foreach_iter(exec_list_iterator, iter, *list) { - ((ir_instruction *)iter.get())->accept(visitor); + foreach_list_safe(n, list) { + ((ir_instruction *) n)->accept(visitor); } } @@ -1790,8 +1733,8 @@ steal_memory(ir_instruction *ir, void *new_ctx) */ if (constant != NULL) { if (constant->type->is_record()) { - foreach_iter(exec_list_iterator, iter, constant->components) { - ir_constant *field = (ir_constant *)iter.get(); + foreach_list(n, &constant->components) { + ir_constant *field = (ir_constant *) n; steal_memory(field, ir); } } else if (constant->type->is_array()) { diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h index 780959b73..2ae8513a6 100644 --- a/mesalib/src/glsl/ir.h +++ b/mesalib/src/glsl/ir.h @@ -914,14 +914,6 @@ public: } /** - * Get an iterator for the set of function signatures - */ - exec_list_iterator iterator() - { - return signatures.iterator(); - } - - /** * Find a signature that matches a set of actual parameters, taking implicit * conversions into account. Also flags whether the match was exact. */ @@ -1018,14 +1010,6 @@ public: return this; } - /** - * Get an iterator for the instructions of the loop body - */ - exec_list_iterator iterator() - { - return body_instructions.iterator(); - } - /** List of ir_instruction that make up the body of the loop. */ exec_list body_instructions; }; @@ -1521,14 +1505,6 @@ public: virtual ir_visitor_status accept(ir_hierarchical_visitor *); /** - * Get an iterator for the set of acutal parameters - */ - exec_list_iterator iterator() - { - return actual_parameters.iterator(); - } - - /** * Get the name of the function being called. */ const char *callee_name() const @@ -2186,6 +2162,12 @@ public: */ bool has_value(const ir_constant *) const; + /** + * Return true if this ir_constant represents the given value. + * + * For vectors, this checks that each component is the given value. + */ + virtual bool is_value(float f, int i) const; virtual bool is_zero() const; virtual bool is_one() const; virtual bool is_negative_one() const; @@ -2345,7 +2327,7 @@ ir_has_call(ir_instruction *ir); extern void do_set_program_inouts(exec_list *instructions, struct gl_program *prog, - GLenum shader_type); + gl_shader_stage shader_stage); extern char * prototype_string(const glsl_type *return_type, const char *name, diff --git a/mesalib/src/glsl/ir_basic_block.cpp b/mesalib/src/glsl/ir_basic_block.cpp index 2cbc682d4..426fda2f2 100644 --- a/mesalib/src/glsl/ir_basic_block.cpp +++ b/mesalib/src/glsl/ir_basic_block.cpp @@ -58,8 +58,8 @@ void call_for_basic_blocks(exec_list *instructions, ir_instruction *leader = NULL; ir_instruction *last = NULL; - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; ir_if *ir_if; ir_loop *ir_loop; ir_function *ir_function; @@ -90,10 +90,8 @@ void call_for_basic_blocks(exec_list *instructions, * and the body of main(). Perhaps those instructions ought * to live inside of main(). */ - foreach_iter(exec_list_iterator, fun_iter, *ir_function) { - ir_function_signature *ir_sig; - - ir_sig = (ir_function_signature *)fun_iter.get(); + foreach_list(func_node, &ir_function->signatures) { + ir_function_signature *ir_sig = (ir_function_signature *) func_node; call_for_basic_blocks(&ir_sig->body, callback, data); } diff --git a/mesalib/src/glsl/ir_builder.cpp b/mesalib/src/glsl/ir_builder.cpp index 6fd58de0e..1e0dd5419 100644 --- a/mesalib/src/glsl/ir_builder.cpp +++ b/mesalib/src/glsl/ir_builder.cpp @@ -211,6 +211,16 @@ ir_expression *sub(operand a, operand b) return expr(ir_binop_sub, a, b); } +ir_expression *min2(operand a, operand b) +{ + return expr(ir_binop_min, a, b); +} + +ir_expression *max2(operand a, operand b) +{ + return expr(ir_binop_max, a, b); +} + ir_expression *mul(operand a, operand b) { return expr(ir_binop_mul, a, b); diff --git a/mesalib/src/glsl/ir_builder.h b/mesalib/src/glsl/ir_builder.h index 52cc2168f..f00e6f3b3 100644..100755 --- a/mesalib/src/glsl/ir_builder.h +++ b/mesalib/src/glsl/ir_builder.h @@ -184,7 +184,10 @@ ir_expression *i2b(operand a); ir_expression *f2b(operand a); ir_expression *b2f(operand a); -ir_expression *fma_mesa(operand a, operand b, operand c); +ir_expression *min2(operand a, operand b); +ir_expression *max2(operand a, operand b); + +ir_expression *fma(operand a, operand b, operand c); ir_expression *lrp(operand x, operand y, operand a); ir_expression *csel(operand a, operand b, operand c); ir_expression *bitfield_insert(operand a, operand b, operand c, operand d); diff --git a/mesalib/src/glsl/ir_clone.cpp b/mesalib/src/glsl/ir_clone.cpp index 4e5cf68ca..cb732a51a 100644 --- a/mesalib/src/glsl/ir_clone.cpp +++ b/mesalib/src/glsl/ir_clone.cpp @@ -123,13 +123,13 @@ ir_if::clone(void *mem_ctx, struct hash_table *ht) const { ir_if *new_if = new(mem_ctx) ir_if(this->condition->clone(mem_ctx, ht)); - foreach_iter(exec_list_iterator, iter, this->then_instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, &this->then_instructions) { + ir_instruction *ir = (ir_instruction *) n; new_if->then_instructions.push_tail(ir->clone(mem_ctx, ht)); } - foreach_iter(exec_list_iterator, iter, this->else_instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, &this->else_instructions) { + ir_instruction *ir = (ir_instruction *) n; new_if->else_instructions.push_tail(ir->clone(mem_ctx, ht)); } @@ -141,8 +141,8 @@ ir_loop::clone(void *mem_ctx, struct hash_table *ht) const { ir_loop *new_loop = new(mem_ctx) ir_loop(); - foreach_iter(exec_list_iterator, iter, this->body_instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, &this->body_instructions) { + ir_instruction *ir = (ir_instruction *) n; new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht)); } @@ -158,8 +158,8 @@ ir_call::clone(void *mem_ctx, struct hash_table *ht) const exec_list new_parameters; - foreach_iter(exec_list_iterator, iter, this->actual_parameters) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, &this->actual_parameters) { + ir_instruction *ir = (ir_instruction *) n; new_parameters.push_tail(ir->clone(mem_ctx, ht)); } diff --git a/mesalib/src/glsl/ir_expression_flattening.cpp b/mesalib/src/glsl/ir_expression_flattening.cpp index b44e68ca3..c1cadb122 100644 --- a/mesalib/src/glsl/ir_expression_flattening.cpp +++ b/mesalib/src/glsl/ir_expression_flattening.cpp @@ -59,8 +59,8 @@ do_expression_flattening(exec_list *instructions, { ir_expression_flattening_visitor v(predicate); - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; ir->accept(&v); } diff --git a/mesalib/src/glsl/ir_function.cpp b/mesalib/src/glsl/ir_function.cpp index bd5318d23..40cf5894a 100644 --- a/mesalib/src/glsl/ir_function.cpp +++ b/mesalib/src/glsl/ir_function.cpp @@ -141,9 +141,8 @@ ir_function::matching_signature(_mesa_glsl_parse_state *state, * multiple ways to apply these conversions to the actual arguments of a * call such that the call can be made to match multiple signatures." */ - foreach_iter(exec_list_iterator, iter, signatures) { - ir_function_signature *const sig = - (ir_function_signature *) iter.get(); + foreach_list(n, &this->signatures) { + ir_function_signature *const sig = (ir_function_signature *) n; /* Skip over any built-ins that aren't available in this shader. */ if (sig->is_builtin() && !sig->is_builtin_available(state)) @@ -212,9 +211,8 @@ ir_function_signature * ir_function::exact_matching_signature(_mesa_glsl_parse_state *state, const exec_list *actual_parameters) { - foreach_iter(exec_list_iterator, iter, signatures) { - ir_function_signature *const sig = - (ir_function_signature *) iter.get(); + foreach_list(n, &this->signatures) { + ir_function_signature *const sig = (ir_function_signature *) n; /* Skip over any built-ins that aren't available in this shader. */ if (sig->is_builtin() && !sig->is_builtin_available(state)) diff --git a/mesalib/src/glsl/ir_print_visitor.cpp b/mesalib/src/glsl/ir_print_visitor.cpp index 01c5f7f1c..935782184 100644 --- a/mesalib/src/glsl/ir_print_visitor.cpp +++ b/mesalib/src/glsl/ir_print_visitor.cpp @@ -61,8 +61,8 @@ _mesa_print_ir(exec_list *instructions, } printf("(\n"); - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; ir->print(); if (ir->ir_type != ir_type_function) printf("\n"); @@ -179,8 +179,8 @@ void ir_print_visitor::visit(ir_function_signature *ir) printf("(parameters\n"); indentation++; - foreach_iter(exec_list_iterator, iter, ir->parameters) { - ir_variable *const inst = (ir_variable *) iter.get(); + foreach_list(n, &ir->parameters) { + ir_variable *const inst = (ir_variable *) n; indent(); inst->accept(this); @@ -196,8 +196,8 @@ void ir_print_visitor::visit(ir_function_signature *ir) printf("(\n"); indentation++; - foreach_iter(exec_list_iterator, iter, ir->body) { - ir_instruction *const inst = (ir_instruction *) iter.get(); + foreach_list(n, &ir->body) { + ir_instruction *const inst = (ir_instruction *) n; indent(); inst->accept(this); @@ -215,8 +215,8 @@ void ir_print_visitor::visit(ir_function *ir) { printf("(function %s\n", ir->name); indentation++; - foreach_iter(exec_list_iterator, iter, *ir) { - ir_function_signature *const sig = (ir_function_signature *) iter.get(); + foreach_list(n, &ir->signatures) { + ir_function_signature *const sig = (ir_function_signature *) n; indent(); sig->accept(this); printf("\n"); @@ -440,10 +440,10 @@ ir_print_visitor::visit(ir_call *ir) if (ir->return_deref) ir->return_deref->accept(this); printf(" ("); - foreach_iter(exec_list_iterator, iter, *ir) { - ir_instruction *const inst = (ir_instruction *) iter.get(); + foreach_list(n, &ir->actual_parameters) { + ir_rvalue *const param = (ir_rvalue *) n; - inst->accept(this); + param->accept(this); } printf("))\n"); } @@ -487,8 +487,8 @@ ir_print_visitor::visit(ir_if *ir) printf("(\n"); indentation++; - foreach_iter(exec_list_iterator, iter, ir->then_instructions) { - ir_instruction *const inst = (ir_instruction *) iter.get(); + foreach_list(n, &ir->then_instructions) { + ir_instruction *const inst = (ir_instruction *) n; indent(); inst->accept(this); @@ -504,8 +504,8 @@ ir_print_visitor::visit(ir_if *ir) printf("(\n"); indentation++; - foreach_iter(exec_list_iterator, iter, ir->else_instructions) { - ir_instruction *const inst = (ir_instruction *) iter.get(); + foreach_list(n, &ir->else_instructions) { + ir_instruction *const inst = (ir_instruction *) n; indent(); inst->accept(this); @@ -526,8 +526,8 @@ ir_print_visitor::visit(ir_loop *ir) printf("(loop (\n"); indentation++; - foreach_iter(exec_list_iterator, iter, ir->body_instructions) { - ir_instruction *const inst = (ir_instruction *) iter.get(); + foreach_list(n, &ir->body_instructions) { + ir_instruction *const inst = (ir_instruction *) n; indent(); inst->accept(this); diff --git a/mesalib/src/glsl/ir_reader.cpp b/mesalib/src/glsl/ir_reader.cpp index 7970112ec..28923f3b8 100644 --- a/mesalib/src/glsl/ir_reader.cpp +++ b/mesalib/src/glsl/ir_reader.cpp @@ -170,8 +170,8 @@ ir_reader::scan_for_prototypes(exec_list *instructions, s_expression *expr) return; } - foreach_iter(exec_list_iterator, it, list->subexpressions) { - s_list *sub = SX_AS_LIST(it.get()); + foreach_list(n, &list->subexpressions) { + s_list *sub = SX_AS_LIST(n); if (sub == NULL) continue; // not a (function ...); ignore it. @@ -205,11 +205,12 @@ ir_reader::read_function(s_expression *expr, bool skip_body) assert(added); } - exec_list_iterator it = ((s_list *) expr)->subexpressions.iterator(); - it.next(); // skip "function" tag - it.next(); // skip function name - for (/* nothing */; it.has_next(); it.next()) { - s_expression *s_sig = (s_expression *) it.get(); + /* Skip over "function" tag and function name (which are guaranteed to be + * present by the above PARTIAL_MATCH call). + */ + exec_node *node = ((s_list *) expr)->subexpressions.head->next->next; + for (/* nothing */; !node->is_tail_sentinel(); node = node->next) { + s_expression *s_sig = (s_expression *) node; read_function_sig(f, s_sig, skip_body); } return added ? f : NULL; @@ -249,9 +250,10 @@ ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body) exec_list hir_parameters; state->symbols->push_scope(); - exec_list_iterator it = paramlist->subexpressions.iterator(); - for (it.next() /* skip "parameters" */; it.has_next(); it.next()) { - ir_variable *var = read_declaration((s_expression *) it.get()); + /* Skip over the "parameters" tag. */ + exec_node *node = paramlist->subexpressions.head->next; + for (/* nothing */; !node->is_tail_sentinel(); node = node->next) { + ir_variable *var = read_declaration((s_expression *) node); if (var == NULL) return; @@ -315,8 +317,8 @@ ir_reader::read_instructions(exec_list *instructions, s_expression *expr, return; } - foreach_iter(exec_list_iterator, it, list->subexpressions) { - s_expression *sub = (s_expression*) it.get(); + foreach_list(n, &list->subexpressions) { + s_expression *sub = (s_expression *) n; ir_instruction *ir = read_instruction(sub, loop_ctx); if (ir != NULL) { /* Global variable declarations should be moved to the top, before @@ -403,8 +405,8 @@ ir_reader::read_declaration(s_expression *expr) ir_variable *var = new(mem_ctx) ir_variable(type, s_name->value(), ir_var_auto); - foreach_iter(exec_list_iterator, it, s_quals->subexpressions) { - s_symbol *qualifier = SX_AS_SYMBOL(it.get()); + foreach_list(n, &s_quals->subexpressions) { + s_symbol *qualifier = SX_AS_SYMBOL(n); if (qualifier == NULL) { ir_read_error(expr, "qualifier list must contain only symbols"); return NULL; @@ -656,8 +658,8 @@ ir_reader::read_call(s_expression *expr) exec_list parameters; - foreach_iter(exec_list_iterator, it, params->subexpressions) { - s_expression *expr = (s_expression*) it.get(); + foreach_list(n, ¶ms->subexpressions) { + s_expression *expr = (s_expression *) n; ir_rvalue *param = read_rvalue(expr); if (param == NULL) { ir_read_error(expr, "when reading parameter to function call"); @@ -796,8 +798,8 @@ ir_reader::read_constant(s_expression *expr) if (type->is_array()) { unsigned elements_supplied = 0; exec_list elements; - foreach_iter(exec_list_iterator, it, values->subexpressions) { - s_expression *elt = (s_expression *) it.get(); + foreach_list(n, &values->subexpressions) { + s_expression *elt = (s_expression *) n; ir_constant *ir_elt = read_constant(elt); if (ir_elt == NULL) return NULL; @@ -817,13 +819,13 @@ ir_reader::read_constant(s_expression *expr) // Read in list of values (at most 16). unsigned k = 0; - foreach_iter(exec_list_iterator, it, values->subexpressions) { + foreach_list(n, &values->subexpressions) { if (k >= 16) { ir_read_error(values, "expected at most 16 numbers"); return NULL; } - s_expression *expr = (s_expression*) it.get(); + s_expression *expr = (s_expression *) n; if (type->base_type == GLSL_TYPE_FLOAT) { s_number *value = SX_AS_NUMBER(expr); diff --git a/mesalib/src/glsl/ir_rvalue_visitor.cpp b/mesalib/src/glsl/ir_rvalue_visitor.cpp index 9d8ccd94a..fcbe9448d 100644 --- a/mesalib/src/glsl/ir_rvalue_visitor.cpp +++ b/mesalib/src/glsl/ir_rvalue_visitor.cpp @@ -123,8 +123,8 @@ ir_rvalue_base_visitor::rvalue_visit(ir_assignment *ir) ir_visitor_status ir_rvalue_base_visitor::rvalue_visit(ir_call *ir) { - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param = (ir_rvalue *)iter.get(); + foreach_list_safe(n, &ir->actual_parameters) { + ir_rvalue *param = (ir_rvalue *) n; ir_rvalue *new_param = param; handle_rvalue(&new_param); diff --git a/mesalib/src/glsl/ir_set_program_inouts.cpp b/mesalib/src/glsl/ir_set_program_inouts.cpp index 0b49eb2b6..5163eb215 100644 --- a/mesalib/src/glsl/ir_set_program_inouts.cpp +++ b/mesalib/src/glsl/ir_set_program_inouts.cpp @@ -46,10 +46,11 @@ namespace { class ir_set_program_inouts_visitor : public ir_hierarchical_visitor { public: - ir_set_program_inouts_visitor(struct gl_program *prog, GLenum shader_type) + ir_set_program_inouts_visitor(struct gl_program *prog, + gl_shader_stage shader_stage) { this->prog = prog; - this->shader_type = shader_type; + this->shader_stage = shader_stage; } ~ir_set_program_inouts_visitor() { @@ -67,7 +68,7 @@ private: bool try_mark_partial_variable(ir_variable *var, ir_rvalue *index); struct gl_program *prog; - GLenum shader_type; + gl_shader_stage shader_stage; }; } /* anonymous namespace */ @@ -124,13 +125,13 @@ void ir_set_program_inouts_visitor::mark_whole_variable(ir_variable *var) { const glsl_type *type = var->type; - if (this->shader_type == GL_GEOMETRY_SHADER && + if (this->shader_stage == MESA_SHADER_GEOMETRY && var->data.mode == ir_var_shader_in && type->is_array()) { type = type->fields.array; } mark(this->prog, var, 0, type->count_attribute_slots(), - this->shader_type == GL_FRAGMENT_SHADER); + this->shader_stage == MESA_SHADER_FRAGMENT); } /* Default handler: Mark all the locations in the variable as used. */ @@ -163,7 +164,7 @@ ir_set_program_inouts_visitor::try_mark_partial_variable(ir_variable *var, { const glsl_type *type = var->type; - if (this->shader_type == GL_GEOMETRY_SHADER && + if (this->shader_stage == MESA_SHADER_GEOMETRY && var->data.mode == ir_var_shader_in) { /* The only geometry shader input that is not an array is * gl_PrimitiveIDIn, and in that case, this code will never be reached, @@ -227,7 +228,7 @@ ir_set_program_inouts_visitor::try_mark_partial_variable(ir_variable *var, } mark(this->prog, var, index_as_constant->value.u[0] * elem_width, - elem_width, this->shader_type == GL_FRAGMENT_SHADER); + elem_width, this->shader_stage == MESA_SHADER_FRAGMENT); return true; } @@ -245,7 +246,7 @@ ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir) */ if (ir_dereference_variable * const deref_var = inner_array->array->as_dereference_variable()) { - if (this->shader_type == GL_GEOMETRY_SHADER && + if (this->shader_stage == MESA_SHADER_GEOMETRY && deref_var->var->data.mode == ir_var_shader_in) { /* foo is a geometry shader input, so i is the vertex, and j the * part of the input we're accessing. @@ -264,7 +265,7 @@ ir_set_program_inouts_visitor::visit_enter(ir_dereference_array *ir) } else if (ir_dereference_variable * const deref_var = ir->array->as_dereference_variable()) { /* ir => foo[i], where foo is a variable. */ - if (this->shader_type == GL_GEOMETRY_SHADER && + if (this->shader_stage == MESA_SHADER_GEOMETRY && deref_var->var->data.mode == ir_var_shader_in) { /* foo is a geometry shader input, so i is the vertex, and we're * accessing the entire input. @@ -304,7 +305,7 @@ ir_set_program_inouts_visitor::visit_enter(ir_function_signature *ir) ir_visitor_status ir_set_program_inouts_visitor::visit_enter(ir_expression *ir) { - if (this->shader_type == GL_FRAGMENT_SHADER && + if (this->shader_stage == MESA_SHADER_FRAGMENT && ir->operation == ir_unop_dFdy) { gl_fragment_program *fprog = (gl_fragment_program *) prog; fprog->UsesDFdy = true; @@ -316,7 +317,7 @@ ir_visitor_status ir_set_program_inouts_visitor::visit_enter(ir_discard *) { /* discards are only allowed in fragment shaders. */ - assert(this->shader_type == GL_FRAGMENT_SHADER); + assert(this->shader_stage == MESA_SHADER_FRAGMENT); gl_fragment_program *fprog = (gl_fragment_program *) prog; fprog->UsesKill = true; @@ -334,14 +335,14 @@ ir_set_program_inouts_visitor::visit_enter(ir_texture *ir) void do_set_program_inouts(exec_list *instructions, struct gl_program *prog, - GLenum shader_type) + gl_shader_stage shader_stage) { - ir_set_program_inouts_visitor v(prog, shader_type); + ir_set_program_inouts_visitor v(prog, shader_stage); prog->InputsRead = 0; prog->OutputsWritten = 0; prog->SystemValuesRead = 0; - if (shader_type == GL_FRAGMENT_SHADER) { + if (shader_stage == MESA_SHADER_FRAGMENT) { gl_fragment_program *fprog = (gl_fragment_program *) prog; memset(fprog->InterpQualifier, 0, sizeof(fprog->InterpQualifier)); fprog->IsCentroid = 0; diff --git a/mesalib/src/glsl/ir_uniform.h b/mesalib/src/glsl/ir_uniform.h index 13faab7c0..f678c2c5c 100644 --- a/mesalib/src/glsl/ir_uniform.h +++ b/mesalib/src/glsl/ir_uniform.h @@ -116,7 +116,7 @@ struct gl_uniform_storage { * Whether this sampler is used in this shader stage. */ bool active; - } sampler[MESA_SHADER_TYPES]; + } sampler[MESA_SHADER_STAGES]; /** * Storage used by the driver for the uniform diff --git a/mesalib/src/glsl/ir_validate.cpp b/mesalib/src/glsl/ir_validate.cpp index 4bbb3ce65..527acea4c 100644 --- a/mesalib/src/glsl/ir_validate.cpp +++ b/mesalib/src/glsl/ir_validate.cpp @@ -813,8 +813,8 @@ validate_ir_tree(exec_list *instructions) v.run(instructions); - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; visit_tree(ir, check_node_type, NULL); } diff --git a/mesalib/src/glsl/link_atomics.cpp b/mesalib/src/glsl/link_atomics.cpp index 603329c50..db9c53965 100644 --- a/mesalib/src/glsl/link_atomics.cpp +++ b/mesalib/src/glsl/link_atomics.cpp @@ -64,7 +64,7 @@ namespace { active_atomic_counter *counters; unsigned num_counters; - unsigned stage_references[MESA_SHADER_TYPES]; + unsigned stage_references[MESA_SHADER_STAGES]; unsigned size; }; @@ -96,7 +96,7 @@ namespace { *num_buffers = 0; - for (unsigned i = 0; i < MESA_SHADER_TYPES; ++i) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; ++i) { struct gl_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) continue; @@ -199,7 +199,7 @@ link_assign_atomic_counter_resources(struct gl_context *ctx, } /* Assign stage-specific fields. */ - for (unsigned j = 0; j < MESA_SHADER_TYPES; ++j) + for (unsigned j = 0; j < MESA_SHADER_STAGES; ++j) mab.StageReferences[j] = (ab.stage_references[j] ? GL_TRUE : GL_FALSE); @@ -214,23 +214,11 @@ void link_check_atomic_counter_resources(struct gl_context *ctx, struct gl_shader_program *prog) { - const unsigned max_atomic_counters[] = { - ctx->Const.VertexProgram.MaxAtomicCounters, - ctx->Const.GeometryProgram.MaxAtomicCounters, - ctx->Const.FragmentProgram.MaxAtomicCounters - }; - STATIC_ASSERT(Elements(max_atomic_counters) == MESA_SHADER_TYPES); - const unsigned max_atomic_buffers[] = { - ctx->Const.VertexProgram.MaxAtomicBuffers, - ctx->Const.GeometryProgram.MaxAtomicBuffers, - ctx->Const.FragmentProgram.MaxAtomicBuffers - }; - STATIC_ASSERT(Elements(max_atomic_buffers) == MESA_SHADER_TYPES); unsigned num_buffers; active_atomic_buffer *const abs = find_active_atomic_counters(ctx, prog, &num_buffers); - unsigned atomic_counters[MESA_SHADER_TYPES] = {}; - unsigned atomic_buffers[MESA_SHADER_TYPES] = {}; + unsigned atomic_counters[MESA_SHADER_STAGES] = {}; + unsigned atomic_buffers[MESA_SHADER_STAGES] = {}; unsigned total_atomic_counters = 0; unsigned total_atomic_buffers = 0; @@ -243,7 +231,7 @@ link_check_atomic_counter_resources(struct gl_context *ctx, if (abs[i].size == 0) continue; - for (unsigned j = 0; j < MESA_SHADER_TYPES; ++j) { + for (unsigned j = 0; j < MESA_SHADER_STAGES; ++j) { const unsigned n = abs[i].stage_references[j]; if (n) { @@ -256,14 +244,14 @@ link_check_atomic_counter_resources(struct gl_context *ctx, } /* Check that they are within the supported limits. */ - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { - if (atomic_counters[i] > max_atomic_counters[i]) + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + if (atomic_counters[i] > ctx->Const.Program[i].MaxAtomicCounters) linker_error(prog, "Too many %s shader atomic counters", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); - if (atomic_buffers[i] > max_atomic_buffers[i]) + if (atomic_buffers[i] > ctx->Const.Program[i].MaxAtomicBuffers) linker_error(prog, "Too many %s shader atomic counter buffers", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); } if (total_atomic_counters > ctx->Const.MaxCombinedAtomicCounters) diff --git a/mesalib/src/glsl/link_interface_blocks.cpp b/mesalib/src/glsl/link_interface_blocks.cpp index 476963642..52552cc68 100644 --- a/mesalib/src/glsl/link_interface_blocks.cpp +++ b/mesalib/src/glsl/link_interface_blocks.cpp @@ -313,7 +313,7 @@ validate_interstage_inout_blocks(struct gl_shader_program *prog, const gl_shader *consumer) { interface_block_definitions definitions; - const bool extra_array_level = consumer->Type == GL_GEOMETRY_SHADER; + const bool extra_array_level = consumer->Stage == MESA_SHADER_GEOMETRY; /* Add input interfaces from the consumer to the symbol table. */ foreach_list(node, consumer->ir) { diff --git a/mesalib/src/glsl/link_uniform_initializers.cpp b/mesalib/src/glsl/link_uniform_initializers.cpp index 04daa1760..7d5c1472d 100644 --- a/mesalib/src/glsl/link_uniform_initializers.cpp +++ b/mesalib/src/glsl/link_uniform_initializers.cpp @@ -106,7 +106,7 @@ set_uniform_binding(void *mem_ctx, gl_shader_program *prog, storage->storage[i].i = binding + i; } - for (int sh = 0; sh < MESA_SHADER_TYPES; sh++) { + for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) { gl_shader *shader = prog->_LinkedShaders[sh]; if (shader && storage->sampler[sh].active) { @@ -119,7 +119,7 @@ set_uniform_binding(void *mem_ctx, gl_shader_program *prog, } } else if (storage->block_index != -1) { /* This is a field of a UBO. val is the binding index. */ - for (int i = 0; i < MESA_SHADER_TYPES; i++) { + for (int i = 0; i < MESA_SHADER_STAGES; i++) { int stage_index = prog->UniformBlockStageIndex[i][storage->block_index]; if (stage_index != -1) { @@ -194,7 +194,7 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog, val->type->components()); if (storage->type->is_sampler()) { - for (int sh = 0; sh < MESA_SHADER_TYPES; sh++) { + for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) { gl_shader *shader = prog->_LinkedShaders[sh]; if (shader && storage->sampler[sh].active) { @@ -215,7 +215,7 @@ link_set_uniform_initializers(struct gl_shader_program *prog) { void *mem_ctx = NULL; - for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_shader *shader = prog->_LinkedShaders[i]; if (shader == NULL) diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp index 1cbe80b2e..2255f7e6e 100644 --- a/mesalib/src/glsl/link_uniforms.cpp +++ b/mesalib/src/glsl/link_uniforms.cpp @@ -356,9 +356,9 @@ public: { } - void start_shader(gl_shader_type shader_type) + void start_shader(gl_shader_stage shader_type) { - assert(shader_type < MESA_SHADER_TYPES); + assert(shader_type < MESA_SHADER_STAGES); this->shader_type = shader_type; this->shader_samplers_used = 0; @@ -429,7 +429,7 @@ public: int ubo_block_index; int ubo_byte_offset; bool ubo_row_major; - gl_shader_type shader_type; + gl_shader_stage shader_type; private: void handle_samplers(const glsl_type *base_type, @@ -741,7 +741,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog) * glGetUniformLocation. */ count_uniform_size uniform_size(prog->UniformHash); - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) @@ -809,11 +809,11 @@ link_assign_uniform_locations(struct gl_shader_program *prog) parcel_out_uniform_storage parcel(prog->UniformHash, uniforms, data); - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; - parcel.start_shader((gl_shader_type)i); + parcel.start_shader((gl_shader_stage)i); foreach_list(node, prog->_LinkedShaders[i]->ir) { ir_variable *const var = ((ir_instruction *) node)->as_variable(); diff --git a/mesalib/src/glsl/link_varyings.cpp b/mesalib/src/glsl/link_varyings.cpp index 98f902ca4..c925c00e3 100644 --- a/mesalib/src/glsl/link_varyings.cpp +++ b/mesalib/src/glsl/link_varyings.cpp @@ -48,13 +48,13 @@ static void cross_validate_types_and_qualifiers(struct gl_shader_program *prog, const ir_variable *input, const ir_variable *output, - GLenum consumer_type, - GLenum producer_type) + gl_shader_stage consumer_stage, + gl_shader_stage producer_stage) { /* Check that the types match between stages. */ const glsl_type *type_to_match = input->type; - if (consumer_type == GL_GEOMETRY_SHADER) { + if (consumer_stage == MESA_SHADER_GEOMETRY) { assert(type_to_match->is_array()); /* Enforced by ast_to_hir */ type_to_match = type_to_match->element_type(); } @@ -82,10 +82,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog, linker_error(prog, "%s shader output `%s' declared as type `%s', " "but %s shader input declared as type `%s'\n", - _mesa_shader_enum_to_string(producer_type), + _mesa_shader_stage_to_string(producer_stage), output->name, output->type->name, - _mesa_shader_enum_to_string(consumer_type), + _mesa_shader_stage_to_string(consumer_stage), input->type->name); return; } @@ -97,10 +97,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog, linker_error(prog, "%s shader output `%s' %s centroid qualifier, " "but %s shader input %s centroid qualifier\n", - _mesa_shader_enum_to_string(producer_type), + _mesa_shader_stage_to_string(producer_stage), output->name, (output->data.centroid) ? "has" : "lacks", - _mesa_shader_enum_to_string(consumer_type), + _mesa_shader_stage_to_string(consumer_stage), (input->data.centroid) ? "has" : "lacks"); return; } @@ -109,10 +109,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog, linker_error(prog, "%s shader output `%s' %s sample qualifier, " "but %s shader input %s sample qualifier\n", - _mesa_shader_enum_to_string(producer_type), + _mesa_shader_stage_to_string(producer_stage), output->name, (output->data.sample) ? "has" : "lacks", - _mesa_shader_enum_to_string(consumer_type), + _mesa_shader_stage_to_string(consumer_stage), (input->data.sample) ? "has" : "lacks"); return; } @@ -121,10 +121,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog, linker_error(prog, "%s shader output `%s' %s invariant qualifier, " "but %s shader input %s invariant qualifier\n", - _mesa_shader_enum_to_string(producer_type), + _mesa_shader_stage_to_string(producer_stage), output->name, (output->data.invariant) ? "has" : "lacks", - _mesa_shader_enum_to_string(consumer_type), + _mesa_shader_stage_to_string(consumer_stage), (input->data.invariant) ? "has" : "lacks"); return; } @@ -135,10 +135,10 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog, "interpolation qualifier, " "but %s shader input specifies %s " "interpolation qualifier\n", - _mesa_shader_enum_to_string(producer_type), + _mesa_shader_stage_to_string(producer_stage), output->name, interpolation_string(output->data.interpolation), - _mesa_shader_enum_to_string(consumer_type), + _mesa_shader_stage_to_string(consumer_stage), interpolation_string(input->data.interpolation)); return; } @@ -152,16 +152,16 @@ cross_validate_front_and_back_color(struct gl_shader_program *prog, const ir_variable *input, const ir_variable *front_color, const ir_variable *back_color, - GLenum consumer_type, - GLenum producer_type) + gl_shader_stage consumer_stage, + gl_shader_stage producer_stage) { if (front_color != NULL && front_color->data.assigned) cross_validate_types_and_qualifiers(prog, input, front_color, - consumer_type, producer_type); + consumer_stage, producer_stage); if (back_color != NULL && back_color->data.assigned) cross_validate_types_and_qualifiers(prog, input, back_color, - consumer_type, producer_type); + consumer_stage, producer_stage); } /** @@ -208,7 +208,7 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, cross_validate_front_and_back_color(prog, input, front_color, back_color, - consumer->Type, producer->Type); + consumer->Stage, producer->Stage); } else if (strcmp(input->name, "gl_SecondaryColor") == 0 && input->data.used) { const ir_variable *const front_color = parameters.get_variable("gl_FrontSecondaryColor"); @@ -218,12 +218,12 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, cross_validate_front_and_back_color(prog, input, front_color, back_color, - consumer->Type, producer->Type); + consumer->Stage, producer->Stage); } else { ir_variable *const output = parameters.get_variable(input->name); if (output != NULL) { cross_validate_types_and_qualifiers(prog, input, output, - consumer->Type, producer->Type); + consumer->Stage, producer->Stage); } } } @@ -943,10 +943,10 @@ varying_matches::match_comparator(const void *x_generic, const void *y_generic) * varyings, but excludes variables such as gl_FrontFacing and gl_FragCoord. */ static bool -is_varying_var(GLenum shaderType, const ir_variable *var) +is_varying_var(gl_shader_stage stage, const ir_variable *var) { /* Only fragment shaders will take a varying variable as an input */ - if (shaderType == GL_FRAGMENT_SHADER && + if (stage == MESA_SHADER_FRAGMENT && var->data.mode == ir_var_shader_in) { switch (var->data.location) { case VARYING_SLOT_POS: @@ -1072,7 +1072,7 @@ assign_varying_locations(struct gl_context *ctx, const unsigned producer_base = VARYING_SLOT_VAR0; const unsigned consumer_base = VARYING_SLOT_VAR0; varying_matches matches(ctx->Const.DisableVaryingPacking, - consumer && consumer->Type == GL_FRAGMENT_SHADER); + consumer && consumer->Stage == MESA_SHADER_FRAGMENT); hash_table *tfeedback_candidates = hash_table_ctor(0, hash_table_string_hash, hash_table_string_compare); hash_table *consumer_inputs @@ -1217,9 +1217,9 @@ assign_varying_locations(struct gl_context *ctx, linker_error(prog, "%s shader varying %s not written " "by %s shader\n.", - _mesa_shader_enum_to_string(consumer->Type), + _mesa_shader_stage_to_string(consumer->Stage), var->name, - _mesa_shader_enum_to_string(producer->Type)); + _mesa_shader_stage_to_string(producer->Stage)); } /* An 'in' variable is only really a shader input if its @@ -1244,24 +1244,14 @@ check_against_output_limit(struct gl_context *ctx, ir_variable *const var = ((ir_instruction *) node)->as_variable(); if (var && var->data.mode == ir_var_shader_out && - is_varying_var(producer->Type, var)) { + is_varying_var(producer->Stage, 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; - } + assert(producer->Stage != MESA_SHADER_FRAGMENT); + unsigned max_output_components = + ctx->Const.Program[producer->Stage].MaxOutputComponents; const unsigned output_components = output_vectors * 4; if (output_components > max_output_components) { @@ -1293,24 +1283,14 @@ check_against_input_limit(struct gl_context *ctx, ir_variable *const var = ((ir_instruction *) node)->as_variable(); if (var && var->data.mode == ir_var_shader_in && - is_varying_var(consumer->Type, var)) { + is_varying_var(consumer->Stage, var)) { input_vectors += var->type->count_attribute_slots(); } } - 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; - } + assert(consumer->Stage != MESA_SHADER_VERTEX); + unsigned max_input_components = + ctx->Const.Program[consumer->Stage].MaxInputComponents; const unsigned input_components = input_vectors * 4; if (input_components > max_input_components) { diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp index a81e10737..85a4d3883 100644 --- a/mesalib/src/glsl/linker.cpp +++ b/mesalib/src/glsl/linker.cpp @@ -109,10 +109,10 @@ public: virtual ir_visitor_status visit_enter(ir_call *ir) { - exec_list_iterator sig_iter = ir->callee->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param_rval = (ir_rvalue *)iter.get(); - ir_variable *sig_param = (ir_variable *)sig_iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_rvalue *param_rval = (ir_rvalue *) actual_node; + ir_variable *sig_param = (ir_variable *) formal_node; if (sig_param->data.mode == ir_var_function_out || sig_param->data.mode == ir_var_function_inout) { @@ -122,7 +122,6 @@ public: return visit_stop; } } - sig_iter.next(); } if (ir->return_deref != NULL) { @@ -438,7 +437,7 @@ analyze_clip_usage(struct gl_shader_program *prog, if (clip_vertex.variable_found() && clip_distance.variable_found()) { linker_error(prog, "%s shader writes to both `gl_ClipVertex' " "and `gl_ClipDistance'\n", - _mesa_shader_enum_to_string(shader->Type)); + _mesa_shader_stage_to_string(shader->Stage)); return; } *UsesClipDistance = clip_distance.variable_found(); @@ -786,7 +785,7 @@ void cross_validate_uniforms(struct gl_shader_program *prog) { cross_validate_globals(prog, prog->_LinkedShaders, - MESA_SHADER_TYPES, true); + MESA_SHADER_STAGES, true); } /** @@ -797,12 +796,12 @@ static bool interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog) { unsigned max_num_uniform_blocks = 0; - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i]) max_num_uniform_blocks += prog->_LinkedShaders[i]->NumUniformBlocks; } - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_shader *sh = prog->_LinkedShaders[i]; prog->UniformBlockStageIndex[i] = ralloc_array(prog, int, @@ -1209,7 +1208,7 @@ link_gs_inout_layout_qualifiers(struct gl_shader_program *prog, /* No in/out qualifiers defined for anything but GLSL 1.50+ * geometry shaders so far. */ - if (linked_shader->Type != GL_GEOMETRY_SHADER || prog->Version < 150) + if (linked_shader->Stage != MESA_SHADER_GEOMETRY || prog->Version < 150) return; /* From the GLSL 1.50 spec, page 46: @@ -1338,9 +1337,8 @@ link_intrastage_shaders(void *mem_ctx, if (other == NULL) continue; - foreach_iter (exec_list_iterator, iter, *f) { - ir_function_signature *sig = - (ir_function_signature *) iter.get(); + foreach_list(n, &f->signatures) { + ir_function_signature *sig = (ir_function_signature *) n; if (!sig->is_defined || sig->is_builtin()) continue; @@ -1376,7 +1374,7 @@ link_intrastage_shaders(void *mem_ctx, if (main == NULL) { linker_error(prog, "%s shader lacks `main'\n", - _mesa_shader_enum_to_string(shader_list[0]->Type)); + _mesa_shader_stage_to_string(shader_list[0]->Stage)); return NULL; } @@ -1450,11 +1448,11 @@ link_intrastage_shaders(void *mem_ctx, validate_ir_tree(linked->ir); /* Set the size of geometry shader input arrays */ - if (linked->Type == GL_GEOMETRY_SHADER) { + if (linked->Stage == MESA_SHADER_GEOMETRY) { unsigned num_vertices = vertices_per_prim(prog->Geom.InputType); geom_array_resize_visitor input_resize_visitor(num_vertices, prog); - foreach_iter(exec_list_iterator, iter, *linked->ir) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, linked->ir) { + ir_instruction *ir = (ir_instruction *) n; ir->accept(&input_resize_visitor); } } @@ -1488,7 +1486,7 @@ link_intrastage_shaders(void *mem_ctx, static void update_array_sizes(struct gl_shader_program *prog) { - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; @@ -1511,7 +1509,7 @@ update_array_sizes(struct gl_shader_program *prog) continue; unsigned int size = var->data.max_array_access; - for (unsigned j = 0; j < MESA_SHADER_TYPES; j++) { + for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) { if (prog->_LinkedShaders[j] == NULL) continue; @@ -1894,80 +1892,51 @@ store_fragdepth_layout(struct gl_shader_program *prog) static void check_resources(struct gl_context *ctx, struct gl_shader_program *prog) { - const unsigned max_samplers[] = { - ctx->Const.VertexProgram.MaxTextureImageUnits, - ctx->Const.GeometryProgram.MaxTextureImageUnits, - ctx->Const.FragmentProgram.MaxTextureImageUnits - }; - STATIC_ASSERT(Elements(max_samplers) == MESA_SHADER_TYPES); - - const unsigned max_default_uniform_components[] = { - ctx->Const.VertexProgram.MaxUniformComponents, - ctx->Const.GeometryProgram.MaxUniformComponents, - ctx->Const.FragmentProgram.MaxUniformComponents - }; - STATIC_ASSERT(Elements(max_default_uniform_components) == - MESA_SHADER_TYPES); - - const unsigned max_combined_uniform_components[] = { - ctx->Const.VertexProgram.MaxCombinedUniformComponents, - ctx->Const.GeometryProgram.MaxCombinedUniformComponents, - ctx->Const.FragmentProgram.MaxCombinedUniformComponents - }; - STATIC_ASSERT(Elements(max_combined_uniform_components) == - MESA_SHADER_TYPES); - - const unsigned max_uniform_blocks[] = { - ctx->Const.VertexProgram.MaxUniformBlocks, - ctx->Const.GeometryProgram.MaxUniformBlocks, - ctx->Const.FragmentProgram.MaxUniformBlocks - }; - STATIC_ASSERT(Elements(max_uniform_blocks) == MESA_SHADER_TYPES); - - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_shader *sh = prog->_LinkedShaders[i]; if (sh == NULL) continue; - if (sh->num_samplers > max_samplers[i]) { + if (sh->num_samplers > ctx->Const.Program[i].MaxTextureImageUnits) { linker_error(prog, "Too many %s shader texture samplers", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); } - if (sh->num_uniform_components > max_default_uniform_components[i]) { + if (sh->num_uniform_components > + ctx->Const.Program[i].MaxUniformComponents) { if (ctx->Const.GLSLSkipStrictMaxUniformLimitCheck) { linker_warning(prog, "Too many %s shader default uniform block " "components, but the driver will try to optimize " "them out; this is non-portable out-of-spec " "behavior\n", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); } else { linker_error(prog, "Too many %s shader default uniform block " "components", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); } } if (sh->num_combined_uniform_components > - max_combined_uniform_components[i]) { + ctx->Const.Program[i].MaxCombinedUniformComponents) { if (ctx->Const.GLSLSkipStrictMaxUniformLimitCheck) { linker_warning(prog, "Too many %s shader uniform components, " "but the driver will try to optimize them out; " "this is non-portable out-of-spec behavior\n", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); } else { linker_error(prog, "Too many %s shader uniform components", - _mesa_shader_type_to_string(i)); + _mesa_shader_stage_to_string(i)); } } } - unsigned blocks[MESA_SHADER_TYPES] = {0}; + unsigned blocks[MESA_SHADER_STAGES] = {0}; unsigned total_uniform_blocks = 0; for (unsigned i = 0; i < prog->NumUniformBlocks; i++) { - for (unsigned j = 0; j < MESA_SHADER_TYPES; j++) { + for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) { if (prog->UniformBlockStageIndex[j][i] != -1) { blocks[j]++; total_uniform_blocks++; @@ -1979,12 +1948,14 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog) prog->NumUniformBlocks, ctx->Const.MaxCombinedUniformBlocks); } else { - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { - if (blocks[i] > max_uniform_blocks[i]) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + const unsigned max_uniform_blocks = + ctx->Const.Program[i].MaxUniformBlocks; + if (blocks[i] > max_uniform_blocks) { linker_error(prog, "Too many %s uniform blocks (%d/%d)", - _mesa_shader_type_to_string(i), + _mesa_shader_stage_to_string(i), blocks[i], - max_uniform_blocks[i]); + max_uniform_blocks); break; } } @@ -2010,7 +1981,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) ralloc_free(prog->UniformBlocks); prog->UniformBlocks = NULL; prog->NumUniformBlocks = 0; - for (int i = 0; i < MESA_SHADER_TYPES; i++) { + for (int i = 0; i < MESA_SHADER_STAGES; i++) { ralloc_free(prog->UniformBlockStageIndex[i]); prog->UniformBlockStageIndex[i] = NULL; } @@ -2049,16 +2020,16 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) goto done; } - switch (prog->Shaders[i]->Type) { - case GL_VERTEX_SHADER: + switch (prog->Shaders[i]->Stage) { + case MESA_SHADER_VERTEX: vert_shader_list[num_vert_shaders] = prog->Shaders[i]; num_vert_shaders++; break; - case GL_FRAGMENT_SHADER: + case MESA_SHADER_FRAGMENT: frag_shader_list[num_frag_shaders] = prog->Shaders[i]; num_frag_shaders++; break; - case GL_GEOMETRY_SHADER: + case MESA_SHADER_GEOMETRY: geom_shader_list[num_geom_shaders] = prog->Shaders[i]; num_geom_shaders++; break; @@ -2085,7 +2056,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) goto done; } - for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] != NULL) ctx->Driver.DeleteShader(ctx, prog->_LinkedShaders[i]); @@ -2154,7 +2125,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) unsigned prev; - for (prev = 0; prev < MESA_SHADER_TYPES; prev++) { + for (prev = 0; prev < MESA_SHADER_STAGES; prev++) { if (prog->_LinkedShaders[prev] != NULL) break; } @@ -2162,7 +2133,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) /* Validate the inputs of each stage with the output of the preceding * stage. */ - for (unsigned i = prev + 1; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = prev + 1; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; @@ -2182,11 +2153,11 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) /* Cross-validate uniform blocks between shader stages */ validate_interstage_uniform_blocks(prog, prog->_LinkedShaders, - MESA_SHADER_TYPES); + MESA_SHADER_STAGES); if (!prog->LinkStatus) goto done; - for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] != NULL) lower_named_interface_blocks(mem_ctx, prog->_LinkedShaders[i]); } @@ -2211,7 +2182,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) * uniforms, and varyings. Later optimization could possibly make * some of that unused. */ - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; @@ -2257,7 +2228,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) } unsigned first; - for (first = 0; first < MESA_SHADER_TYPES; first++) { + for (first = 0; first < MESA_SHADER_STAGES; first++) { if (prog->_LinkedShaders[first] != NULL) break; } @@ -2289,7 +2260,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) * eliminated if they are (transitively) not used in a later stage. */ int last, next; - for (last = MESA_SHADER_TYPES-1; last >= 0; last--) { + for (last = MESA_SHADER_STAGES-1; last >= 0; last--) { if (prog->_LinkedShaders[last] != NULL) break; } @@ -2404,7 +2375,7 @@ done: free(frag_shader_list); free(geom_shader_list); - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; diff --git a/mesalib/src/glsl/list.h b/mesalib/src/glsl/list.h index 2934539fe..b2e249657 100644 --- a/mesalib/src/glsl/list.h +++ b/mesalib/src/glsl/list.h @@ -210,62 +210,8 @@ struct exec_node { #ifdef __cplusplus struct exec_node; - -class iterator { -public: - void next() - { - } - - void *get() - { - return NULL; - } - - bool has_next() const - { - return false; - } -}; - -class exec_list_iterator : public iterator { -public: - exec_list_iterator(exec_node *n) : node(n), _next(n->next) - { - /* empty */ - } - - void next() - { - node = _next; - _next = node->next; - } - - void remove() - { - node->remove(); - } - - exec_node *get() - { - return node; - } - - bool has_next() const - { - return _next != NULL; - } - -private: - exec_node *node; - exec_node *_next; -}; - -#define foreach_iter(iter_type, iter, container) \ - for (iter_type iter = (container) . iterator(); iter.has_next(); iter.next()) #endif - struct exec_list { struct exec_node *head; struct exec_node *tail; @@ -412,16 +358,6 @@ struct exec_list { */ source->make_empty(); } - - exec_list_iterator iterator() - { - return exec_list_iterator(head); - } - - exec_list_iterator iterator() const - { - return exec_list_iterator((exec_node *) head); - } #endif }; @@ -455,6 +391,22 @@ inline void exec_node::insert_before(exec_list *before) ; (__node)->next != NULL \ ; (__node) = (__node)->next) +/** + * Iterate through two lists at once. Stops at the end of the shorter list. + * + * This is safe against either current node being removed or replaced. + */ +#define foreach_two_lists(__node1, __list1, __node2, __list2) \ + for (exec_node * __node1 = (__list1)->head, \ + * __node2 = (__list2)->head, \ + * __next1 = __node1->next, \ + * __next2 = __node2->next \ + ; __next1 != NULL && __next2 != NULL \ + ; __node1 = __next1, \ + __node2 = __next2, \ + __next1 = __next1->next, \ + __next2 = __next2->next) + #define foreach_list_const(__node, __list) \ for (const exec_node * __node = (__list)->head \ ; (__node)->next != NULL \ diff --git a/mesalib/src/glsl/lower_clip_distance.cpp b/mesalib/src/glsl/lower_clip_distance.cpp index bb4f6ab11..2d6138d5a 100644 --- a/mesalib/src/glsl/lower_clip_distance.cpp +++ b/mesalib/src/glsl/lower_clip_distance.cpp @@ -54,10 +54,10 @@ namespace { class lower_clip_distance_visitor : public ir_rvalue_visitor { public: - explicit lower_clip_distance_visitor(GLenum shader_type) + explicit lower_clip_distance_visitor(gl_shader_stage shader_stage) : 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) + new_clip_distance_2d_var(NULL), shader_stage(shader_stage) { } @@ -96,9 +96,9 @@ public: ir_variable *new_clip_distance_2d_var; /** - * Type of shader we are compiling (e.g. GL_VERTEX_SHADER) + * Type of shader we are compiling (e.g. MESA_SHADER_VERTEX) */ - const GLenum shader_type; + const gl_shader_stage shader_stage; }; } /* anonymous namespace */ @@ -142,7 +142,7 @@ lower_clip_distance_visitor::visit(ir_variable *ir) } else { /* 2D gl_ClipDistance (used for geometry input). */ assert(ir->data.mode == ir_var_shader_in && - this->shader_type == GL_GEOMETRY_SHADER_ARB); + this->shader_stage == MESA_SHADER_GEOMETRY); if (this->old_clip_distance_2d_var) return visit_continue; @@ -253,7 +253,7 @@ lower_clip_distance_visitor::is_clip_distance_vec8(ir_rvalue *ir) } 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); + assert(this->shader_stage == MESA_SHADER_GEOMETRY); ir_dereference_array *array_ref = ir->as_dereference_array(); if (array_ref) { @@ -288,7 +288,7 @@ lower_clip_distance_visitor::lower_clip_distance_vec8(ir_rvalue *ir) } 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); + assert(this->shader_stage == MESA_SHADER_GEOMETRY); ir_dereference_array *array_ref = ir->as_dereference_array(); if (array_ref) { @@ -536,7 +536,7 @@ lower_clip_distance_visitor::visit_leave(ir_call *ir) bool lower_clip_distance(gl_shader *shader) { - lower_clip_distance_visitor v(shader->Type); + lower_clip_distance_visitor v(shader->Stage); visit_list_elements(&v, shader->ir); diff --git a/mesalib/src/glsl/lower_if_to_cond_assign.cpp b/mesalib/src/glsl/lower_if_to_cond_assign.cpp index 1e7ce51c7..f15b217e0 100644 --- a/mesalib/src/glsl/lower_if_to_cond_assign.cpp +++ b/mesalib/src/glsl/lower_if_to_cond_assign.cpp @@ -178,12 +178,12 @@ ir_if_to_cond_assign_visitor::visit_leave(ir_if *ir) ir_assignment *assign; /* Check that both blocks don't contain anything we can't support. */ - foreach_iter(exec_list_iterator, then_iter, ir->then_instructions) { - ir_instruction *then_ir = (ir_instruction *)then_iter.get(); + foreach_list(n, &ir->then_instructions) { + ir_instruction *then_ir = (ir_instruction *) n; visit_tree(then_ir, check_control_flow, &found_control_flow); } - foreach_iter(exec_list_iterator, else_iter, ir->else_instructions) { - ir_instruction *else_ir = (ir_instruction *)else_iter.get(); + foreach_list(n, &ir->else_instructions) { + ir_instruction *else_ir = (ir_instruction *) n; visit_tree(else_ir, check_control_flow, &found_control_flow); } if (found_control_flow) diff --git a/mesalib/src/glsl/lower_packed_varyings.cpp b/mesalib/src/glsl/lower_packed_varyings.cpp index 9edef5d04..c23d1801b 100644 --- a/mesalib/src/glsl/lower_packed_varyings.cpp +++ b/mesalib/src/glsl/lower_packed_varyings.cpp @@ -669,7 +669,7 @@ lower_packed_varyings(void *mem_ctx, unsigned location_base, gs_input_vertices, &new_instructions); visitor.run(instructions); if (mode == ir_var_shader_out) { - if (shader->Type == GL_GEOMETRY_SHADER) { + if (shader->Stage == MESA_SHADER_GEOMETRY) { /* For geometry shaders, outputs need to be lowered before each call * to EmitVertex() */ diff --git a/mesalib/src/glsl/lower_vec_index_to_cond_assign.cpp b/mesalib/src/glsl/lower_vec_index_to_cond_assign.cpp index 8080006c1..fe6a3f208 100644 --- a/mesalib/src/glsl/lower_vec_index_to_cond_assign.cpp +++ b/mesalib/src/glsl/lower_vec_index_to_cond_assign.cpp @@ -197,8 +197,8 @@ ir_vec_index_to_cond_assign_visitor::visit_leave(ir_assignment *ir) ir_visitor_status ir_vec_index_to_cond_assign_visitor::visit_enter(ir_call *ir) { - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param = (ir_rvalue *)iter.get(); + foreach_list_safe(n, &ir->actual_parameters) { + ir_rvalue *param = (ir_rvalue *) n; ir_rvalue *new_param = convert_vector_extract_to_cond_assign(param); if (new_param != param) { diff --git a/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp b/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp index 46985791e..b5bb00c30 100644 --- a/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp +++ b/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp @@ -131,8 +131,8 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_assignment *ir) ir_visitor_status ir_vec_index_to_swizzle_visitor::visit_enter(ir_call *ir) { - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param = (ir_rvalue *)iter.get(); + foreach_list_safe(n, &ir->actual_parameters) { + ir_rvalue *param = (ir_rvalue *) n; ir_rvalue *new_param = convert_vector_extract_to_swizzle(param); if (new_param != param) { diff --git a/mesalib/src/glsl/main.cpp b/mesalib/src/glsl/main.cpp index 4a5570608..56c32e688 100644 --- a/mesalib/src/glsl/main.cpp +++ b/mesalib/src/glsl/main.cpp @@ -73,20 +73,20 @@ initialize_context(struct gl_context *ctx, gl_api api) 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.Program[MESA_SHADER_VERTEX].MaxAttribs = 8; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 128 * 4; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxInputComponents = 0; /* not used */ + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32; - ctx->Const.FragmentProgram.MaxTextureImageUnits = + ctx->Const.Program[MESA_SHADER_FRAGMENT].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.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 16 * 4; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxOutputComponents = 0; /* not used */ - ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4; + ctx->Const.MaxVarying = ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4; break; case 110: case 120: @@ -99,20 +99,20 @@ initialize_context(struct gl_context *ctx, gl_api api) 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.Program[MESA_SHADER_VERTEX].MaxAttribs = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 512; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxInputComponents = 0; /* not used */ + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32; - ctx->Const.FragmentProgram.MaxTextureImageUnits = + ctx->Const.Program[MESA_SHADER_FRAGMENT].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.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 64; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxOutputComponents = 0; /* not used */ - ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4; + ctx->Const.MaxVarying = ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4; break; case 130: case 140: @@ -125,19 +125,19 @@ initialize_context(struct gl_context *ctx, gl_api api) 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.Program[MESA_SHADER_VERTEX].MaxAttribs = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 1024; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxInputComponents = 0; /* not used */ + ctx->Const.Program[MESA_SHADER_VERTEX].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.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 1024; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxOutputComponents = 0; /* not used */ - ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4; + ctx->Const.MaxVarying = ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents / 4; break; case 150: case 330: @@ -149,28 +149,28 @@ initialize_context(struct gl_context *ctx, gl_api api) 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.Program[MESA_SHADER_VERTEX].MaxAttribs = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 1024; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxInputComponents = 0; /* not used */ + ctx->Const.Program[MESA_SHADER_VERTEX].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.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxUniformComponents = 1024; + ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxInputComponents = + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents; + ctx->Const.Program[MESA_SHADER_GEOMETRY].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.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 1024; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = + ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxOutputComponents; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxOutputComponents = 0; /* not used */ ctx->Const.MaxCombinedTextureImageUnits = - ctx->Const.VertexProgram.MaxTextureImageUnits - + ctx->Const.GeometryProgram.MaxTextureImageUnits - + ctx->Const.FragmentProgram.MaxTextureImageUnits; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits + + ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits + + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; ctx->Const.MaxGeometryOutputVertices = 256; ctx->Const.MaxGeometryTotalOutputComponents = 1024; @@ -189,18 +189,18 @@ initialize_context(struct gl_context *ctx, gl_api api) 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.Program[MESA_SHADER_VERTEX].MaxAttribs = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 1024; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxInputComponents = 0; /* not used */ + ctx->Const.Program[MESA_SHADER_VERTEX].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.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 16; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 224; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 15 * 4; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxOutputComponents = 0; /* not used */ - ctx->Const.MaxVarying = ctx->Const.FragmentProgram.MaxInputComponents / 4; + ctx->Const.MaxVarying = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents / 4; break; } @@ -287,7 +287,7 @@ void compile_shader(struct gl_context *ctx, struct gl_shader *shader) { struct _mesa_glsl_parse_state *state = - new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); + new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader); _mesa_glsl_compile_shader(ctx, shader, dump_ast, dump_hir); @@ -373,6 +373,7 @@ main(int argc, char **argv) shader->Type = GL_FRAGMENT_SHADER; else usage_fail(argv[0]); + shader->Stage = _mesa_shader_enum_to_shader_stage(shader->Type); shader->Source = load_text_file(whole_program, argv[optind]); if (shader->Source == NULL) { @@ -399,7 +400,7 @@ main(int argc, char **argv) printf("Info log for linking:\n%s\n", whole_program->InfoLog); } - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) ralloc_free(whole_program->_LinkedShaders[i]); ralloc_free(whole_program); diff --git a/mesalib/src/glsl/opt_algebraic.cpp b/mesalib/src/glsl/opt_algebraic.cpp index 05a589989..332f0b77b 100644 --- a/mesalib/src/glsl/opt_algebraic.cpp +++ b/mesalib/src/glsl/opt_algebraic.cpp @@ -88,6 +88,12 @@ is_vec_one(ir_constant *ir) } static inline bool +is_vec_two(ir_constant *ir) +{ + return (ir == NULL) ? false : ir->is_value(2.0, 2); +} + +static inline bool is_vec_negative_one(ir_constant *ir) { return (ir == NULL) ? false : ir->is_negative_one(); @@ -416,6 +422,17 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) } break; + case ir_binop_pow: + /* 1^x == 1 */ + if (is_vec_one(op_const[0])) + return op_const[0]; + + /* pow(2,x) == exp2(x) */ + if (is_vec_two(op_const[0])) + return expr(ir_unop_exp2, ir->operands[1]); + + break; + case ir_unop_rcp: if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp) return op_expr[0]->operands[0]; diff --git a/mesalib/src/glsl/opt_array_splitting.cpp b/mesalib/src/glsl/opt_array_splitting.cpp index e946e0ae5..f37d09022 100644 --- a/mesalib/src/glsl/opt_array_splitting.cpp +++ b/mesalib/src/glsl/opt_array_splitting.cpp @@ -135,8 +135,8 @@ ir_array_reference_visitor::get_variable_entry(ir_variable *var) if (var->type->is_unsized_array()) return NULL; - foreach_iter(exec_list_iterator, iter, this->variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list(n, &this->variable_list) { + variable_entry *entry = (variable_entry *) n; if (entry->var == var) return entry; } @@ -224,8 +224,8 @@ ir_array_reference_visitor::get_split_list(exec_list *instructions, } /* Trim out variables we found that we can't split. */ - foreach_iter(exec_list_iterator, iter, variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list_safe(n, &variable_list) { + variable_entry *entry = (variable_entry *) n; if (debug) { printf("array %s@%p: decl %d, split %d\n", @@ -270,8 +270,8 @@ ir_array_splitting_visitor::get_splitting_entry(ir_variable *var) { assert(var); - foreach_iter(exec_list_iterator, iter, *this->variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list(n, this->variable_list) { + variable_entry *entry = (variable_entry *) n; if (entry->var == var) { return entry; } @@ -368,8 +368,8 @@ optimize_split_arrays(exec_list *instructions, bool linked) /* Replace the decls of the arrays to be split with their split * components. */ - foreach_iter(exec_list_iterator, iter, refs.variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list(n, &refs.variable_list) { + variable_entry *entry = (variable_entry *) n; const struct glsl_type *type = entry->var->type; const struct glsl_type *subtype; diff --git a/mesalib/src/glsl/opt_constant_folding.cpp b/mesalib/src/glsl/opt_constant_folding.cpp index 08a47b96b..d0e575460 100644 --- a/mesalib/src/glsl/opt_constant_folding.cpp +++ b/mesalib/src/glsl/opt_constant_folding.cpp @@ -122,10 +122,10 @@ ir_visitor_status ir_constant_folding_visitor::visit_enter(ir_call *ir) { /* Attempt to constant fold parameters */ - exec_list_iterator sig_iter = ir->callee->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param_rval = (ir_rvalue *)iter.get(); - ir_variable *sig_param = (ir_variable *)sig_iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_rvalue *param_rval = (ir_rvalue *) actual_node; + ir_variable *sig_param = (ir_variable *) formal_node; if (sig_param->data.mode == ir_var_function_in || sig_param->data.mode == ir_var_const_in) { @@ -136,7 +136,6 @@ ir_constant_folding_visitor::visit_enter(ir_call *ir) param_rval->replace_with(new_param); } } - sig_iter.next(); } /* Next, see if the call can be replaced with an assignment of a constant */ diff --git a/mesalib/src/glsl/opt_constant_propagation.cpp b/mesalib/src/glsl/opt_constant_propagation.cpp index f1a6fbdaa..18f5da689 100644 --- a/mesalib/src/glsl/opt_constant_propagation.cpp +++ b/mesalib/src/glsl/opt_constant_propagation.cpp @@ -172,8 +172,8 @@ ir_constant_propagation_visitor::handle_rvalue(ir_rvalue **rvalue) channel = i; } - foreach_iter(exec_list_iterator, iter, *this->acp) { - acp_entry *entry = (acp_entry *)iter.get(); + foreach_list(n, this->acp) { + acp_entry *entry = (acp_entry *) n; if (entry->var == deref->var && entry->write_mask & (1 << channel)) { found = entry; break; @@ -281,10 +281,10 @@ ir_visitor_status ir_constant_propagation_visitor::visit_enter(ir_call *ir) { /* Do constant propagation on call parameters, but skip any out params */ - exec_list_iterator sig_param_iter = ir->callee->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { - ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); - ir_rvalue *param = (ir_rvalue *)iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *param = (ir_rvalue *) actual_node; if (sig_param->data.mode != ir_var_function_out && sig_param->data.mode != ir_var_function_inout) { ir_rvalue *new_param = param; @@ -294,7 +294,6 @@ ir_constant_propagation_visitor::visit_enter(ir_call *ir) else param->accept(this); } - sig_param_iter.next(); } /* Since we're unlinked, we don't (necssarily) know the side effects of @@ -318,8 +317,8 @@ ir_constant_propagation_visitor::handle_if_block(exec_list *instructions) this->killed_all = false; /* Populate the initial acp with a constant of the original */ - foreach_iter(exec_list_iterator, iter, *orig_acp) { - acp_entry *a = (acp_entry *)iter.get(); + foreach_list(n, orig_acp) { + acp_entry *a = (acp_entry *) n; this->acp->push_tail(new(this->mem_ctx) acp_entry(a)); } @@ -334,8 +333,8 @@ ir_constant_propagation_visitor::handle_if_block(exec_list *instructions) this->acp = orig_acp; this->killed_all = this->killed_all || orig_killed_all; - foreach_iter(exec_list_iterator, iter, *new_kills) { - kill_entry *k = (kill_entry *)iter.get(); + foreach_list(n, new_kills) { + kill_entry *k = (kill_entry *) n; kill(k->var, k->write_mask); } } @@ -379,8 +378,8 @@ ir_constant_propagation_visitor::visit_enter(ir_loop *ir) this->acp = orig_acp; this->killed_all = this->killed_all || orig_killed_all; - foreach_iter(exec_list_iterator, iter, *new_kills) { - kill_entry *k = (kill_entry *)iter.get(); + foreach_list(n, new_kills) { + kill_entry *k = (kill_entry *) n; kill(k->var, k->write_mask); } @@ -398,8 +397,8 @@ ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask) return; /* Remove any entries currently in the ACP for this kill. */ - foreach_iter(exec_list_iterator, iter, *this->acp) { - acp_entry *entry = (acp_entry *)iter.get(); + foreach_list_safe(n, this->acp) { + acp_entry *entry = (acp_entry *) n; if (entry->var == var) { entry->write_mask &= ~write_mask; @@ -411,8 +410,8 @@ ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask) /* Add this writemask of the variable to the list of killed * variables in this block. */ - foreach_iter(exec_list_iterator, iter, *this->kills) { - kill_entry *entry = (kill_entry *)iter.get(); + foreach_list(n, this->kills) { + kill_entry *entry = (kill_entry *) n; if (entry->var == var) { entry->write_mask |= write_mask; diff --git a/mesalib/src/glsl/opt_constant_variable.cpp b/mesalib/src/glsl/opt_constant_variable.cpp index a026c51c3..961b8aa06 100644 --- a/mesalib/src/glsl/opt_constant_variable.cpp +++ b/mesalib/src/glsl/opt_constant_variable.cpp @@ -132,10 +132,10 @@ ir_visitor_status ir_constant_variable_visitor::visit_enter(ir_call *ir) { /* Mark any out parameters as assigned to */ - exec_list_iterator sig_iter = ir->callee->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param_rval = (ir_rvalue *)iter.get(); - ir_variable *param = (ir_variable *)sig_iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_rvalue *param_rval = (ir_rvalue *) actual_node; + ir_variable *param = (ir_variable *) formal_node; if (param->data.mode == ir_var_function_out || param->data.mode == ir_var_function_inout) { @@ -146,7 +146,6 @@ ir_constant_variable_visitor::visit_enter(ir_call *ir) entry = get_assignment_entry(var, &this->list); entry->assignment_count++; } - sig_iter.next(); } /* Mark the return storage as having been assigned to */ @@ -194,13 +193,12 @@ do_constant_variable_unlinked(exec_list *instructions) { bool progress = false; - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; ir_function *f = ir->as_function(); if (f) { - foreach_iter(exec_list_iterator, sigiter, *f) { - ir_function_signature *sig = - (ir_function_signature *) sigiter.get(); + foreach_list(signode, &f->signatures) { + ir_function_signature *sig = (ir_function_signature *) signode; if (do_constant_variable(&sig->body)) progress = true; } diff --git a/mesalib/src/glsl/opt_copy_propagation.cpp b/mesalib/src/glsl/opt_copy_propagation.cpp index db5dfc153..195cc8baa 100644 --- a/mesalib/src/glsl/opt_copy_propagation.cpp +++ b/mesalib/src/glsl/opt_copy_propagation.cpp @@ -167,8 +167,8 @@ ir_copy_propagation_visitor::visit(ir_dereference_variable *ir) ir_variable *var = ir->var; - foreach_iter(exec_list_iterator, iter, *this->acp) { - acp_entry *entry = (acp_entry *)iter.get(); + foreach_list(n, this->acp) { + acp_entry *entry = (acp_entry *) n; if (var == entry->lhs) { ir->var = entry->rhs; @@ -185,15 +185,14 @@ ir_visitor_status ir_copy_propagation_visitor::visit_enter(ir_call *ir) { /* Do copy propagation on call parameters, but skip any out params */ - exec_list_iterator sig_param_iter = ir->callee->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { - ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *ir = (ir_rvalue *) actual_node; if (sig_param->data.mode != ir_var_function_out && sig_param->data.mode != ir_var_function_inout) { ir->accept(this); } - sig_param_iter.next(); } /* Since we're unlinked, we don't (necessarily) know the side effects of @@ -217,8 +216,8 @@ ir_copy_propagation_visitor::handle_if_block(exec_list *instructions) this->killed_all = false; /* Populate the initial acp with a copy of the original */ - foreach_iter(exec_list_iterator, iter, *orig_acp) { - acp_entry *a = (acp_entry *)iter.get(); + foreach_list(n, orig_acp) { + acp_entry *a = (acp_entry *) n; this->acp->push_tail(new(this->mem_ctx) acp_entry(a->lhs, a->rhs)); } @@ -233,8 +232,8 @@ ir_copy_propagation_visitor::handle_if_block(exec_list *instructions) this->acp = orig_acp; this->killed_all = this->killed_all || orig_killed_all; - foreach_iter(exec_list_iterator, iter, *new_kills) { - kill_entry *k = (kill_entry *)iter.get(); + foreach_list(n, new_kills) { + kill_entry *k = (kill_entry *) n; kill(k->var); } } @@ -277,8 +276,8 @@ ir_copy_propagation_visitor::visit_enter(ir_loop *ir) this->acp = orig_acp; this->killed_all = this->killed_all || orig_killed_all; - foreach_iter(exec_list_iterator, iter, *new_kills) { - kill_entry *k = (kill_entry *)iter.get(); + foreach_list(n, new_kills) { + kill_entry *k = (kill_entry *) n; kill(k->var); } @@ -292,8 +291,8 @@ ir_copy_propagation_visitor::kill(ir_variable *var) assert(var != NULL); /* Remove any entries currently in the ACP for this kill. */ - foreach_iter(exec_list_iterator, iter, *acp) { - acp_entry *entry = (acp_entry *)iter.get(); + foreach_list_safe(n, acp) { + acp_entry *entry = (acp_entry *) n; if (entry->lhs == var || entry->rhs == var) { entry->remove(); diff --git a/mesalib/src/glsl/opt_copy_propagation_elements.cpp b/mesalib/src/glsl/opt_copy_propagation_elements.cpp index ba8a0f532..cc53e0dd0 100644 --- a/mesalib/src/glsl/opt_copy_propagation_elements.cpp +++ b/mesalib/src/glsl/opt_copy_propagation_elements.cpp @@ -244,8 +244,8 @@ ir_copy_propagation_elements_visitor::handle_rvalue(ir_rvalue **ir) /* Try to find ACP entries covering swizzle_chan[], hoping they're * the same source variable. */ - foreach_iter(exec_list_iterator, iter, *this->acp) { - acp_entry *entry = (acp_entry *)iter.get(); + foreach_list(n, this->acp) { + acp_entry *entry = (acp_entry *) n; if (var == entry->lhs) { for (int c = 0; c < chans; c++) { @@ -293,15 +293,14 @@ ir_visitor_status ir_copy_propagation_elements_visitor::visit_enter(ir_call *ir) { /* Do copy propagation on call parameters, but skip any out params */ - exec_list_iterator sig_param_iter = ir->callee->parameters.iterator(); - foreach_iter(exec_list_iterator, iter, ir->actual_parameters) { - ir_variable *sig_param = (ir_variable *)sig_param_iter.get(); - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *ir = (ir_rvalue *) actual_node; if (sig_param->data.mode != ir_var_function_out && sig_param->data.mode != ir_var_function_inout) { ir->accept(this); } - sig_param_iter.next(); } /* Since we're unlinked, we don't (necessarily) know the side effects of @@ -325,8 +324,8 @@ ir_copy_propagation_elements_visitor::handle_if_block(exec_list *instructions) this->killed_all = false; /* Populate the initial acp with a copy of the original */ - foreach_iter(exec_list_iterator, iter, *orig_acp) { - acp_entry *a = (acp_entry *)iter.get(); + foreach_list(n, orig_acp) { + acp_entry *a = (acp_entry *) n; this->acp->push_tail(new(this->mem_ctx) acp_entry(a)); } diff --git a/mesalib/src/glsl/opt_dead_builtin_varyings.cpp b/mesalib/src/glsl/opt_dead_builtin_varyings.cpp index a939a2b64..c2a306e7b 100644 --- a/mesalib/src/glsl/opt_dead_builtin_varyings.cpp +++ b/mesalib/src/glsl/opt_dead_builtin_varyings.cpp @@ -512,7 +512,7 @@ do_dead_builtin_varyings(struct gl_context *ctx, tfeedback_decl *tfeedback_decls) { /* Lower the gl_FragData array to separate variables. */ - if (consumer && consumer->Type == GL_FRAGMENT_SHADER) { + if (consumer && consumer->Stage == MESA_SHADER_FRAGMENT) { lower_fragdata_array(consumer->ir); } @@ -574,7 +574,7 @@ do_dead_builtin_varyings(struct gl_context *ctx, * This doesn't prevent elimination of the gl_TexCoord elements which * are not read by the fragment shader. We want to eliminate those anyway. */ - if (consumer->Type == GL_FRAGMENT_SHADER) { + if (consumer->Stage == MESA_SHADER_FRAGMENT) { producer_info.texcoord_usage = (1 << MAX_TEXTURE_COORD_UNITS) - 1; } diff --git a/mesalib/src/glsl/opt_dead_code.cpp b/mesalib/src/glsl/opt_dead_code.cpp index a8d8b4a39..af53d94fd 100644 --- a/mesalib/src/glsl/opt_dead_code.cpp +++ b/mesalib/src/glsl/opt_dead_code.cpp @@ -129,13 +129,12 @@ do_dead_code_unlinked(exec_list *instructions) { bool progress = false; - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; ir_function *f = ir->as_function(); if (f) { - foreach_iter(exec_list_iterator, sigiter, *f) { - ir_function_signature *sig = - (ir_function_signature *) sigiter.get(); + foreach_list(signode, &f->signatures) { + ir_function_signature *sig = (ir_function_signature *) signode; /* The setting of the uniform_locations_assigned flag here is * irrelevent. If there is a uniform declaration encountered * inside the body of the function, something has already gone diff --git a/mesalib/src/glsl/opt_dead_code_local.cpp b/mesalib/src/glsl/opt_dead_code_local.cpp index 43a01662a..e7d46edbe 100644 --- a/mesalib/src/glsl/opt_dead_code_local.cpp +++ b/mesalib/src/glsl/opt_dead_code_local.cpp @@ -70,8 +70,8 @@ public: void kill_channels(ir_variable *const var, int used) { - foreach_iter(exec_list_iterator, iter, *this->assignments) { - assignment_entry *entry = (assignment_entry *)iter.get(); + foreach_list_safe(n, this->assignments) { + assignment_entry *entry = (assignment_entry *) n; if (entry->lhs == var) { if (var->type->is_scalar() || var->type->is_vector()) { @@ -119,8 +119,8 @@ public: /* For the purpose of dead code elimination, emitting a vertex counts as * "reading" all of the currently assigned output variables. */ - foreach_iter(exec_list_iterator, iter, *this->assignments) { - assignment_entry *entry = (assignment_entry *)iter.get(); + foreach_list_safe(n, this->assignments) { + assignment_entry *entry = (assignment_entry *) n; if (entry->lhs->data.mode == ir_var_shader_out) { if (debug) printf("kill %s\n", entry->lhs->name); @@ -196,8 +196,8 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments) printf("looking for %s.0x%01x to remove\n", var->name, ir->write_mask); - foreach_iter(exec_list_iterator, iter, *assignments) { - assignment_entry *entry = (assignment_entry *)iter.get(); + foreach_list_safe(n, assignments) { + assignment_entry *entry = (assignment_entry *) n; if (entry->lhs != var) continue; @@ -258,8 +258,8 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments) */ if (debug) printf("looking for %s to remove\n", var->name); - foreach_iter(exec_list_iterator, iter, *assignments) { - assignment_entry *entry = (assignment_entry *)iter.get(); + foreach_list_safe(n, assignments) { + assignment_entry *entry = (assignment_entry *) n; if (entry->lhs == var) { if (debug) @@ -280,8 +280,8 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments) printf("add %s\n", var->name); printf("current entries\n"); - foreach_iter(exec_list_iterator, iter, *assignments) { - assignment_entry *entry = (assignment_entry *)iter.get(); + foreach_list(n, assignments) { + assignment_entry *entry = (assignment_entry *) n; printf(" %s (0x%01x)\n", entry->lhs->name, entry->available); } diff --git a/mesalib/src/glsl/opt_dead_functions.cpp b/mesalib/src/glsl/opt_dead_functions.cpp index cd3b2c12e..8bb278e45 100644 --- a/mesalib/src/glsl/opt_dead_functions.cpp +++ b/mesalib/src/glsl/opt_dead_functions.cpp @@ -74,8 +74,8 @@ public: signature_entry * ir_dead_functions_visitor::get_signature_entry(ir_function_signature *sig) { - foreach_iter(exec_list_iterator, iter, this->signature_list) { - signature_entry *entry = (signature_entry *)iter.get(); + foreach_list(n, &this->signature_list) { + signature_entry *entry = (signature_entry *) n; if (entry->signature == sig) return entry; } @@ -123,8 +123,8 @@ do_dead_functions(exec_list *instructions) * the unused ones, and remove function definitions that have no more * signatures. */ - foreach_iter(exec_list_iterator, iter, v.signature_list) { - signature_entry *entry = (signature_entry *)iter.get(); + foreach_list_safe(n, &v.signature_list) { + signature_entry *entry = (signature_entry *) n; if (!entry->used) { entry->signature->remove(); @@ -137,8 +137,8 @@ do_dead_functions(exec_list *instructions) /* We don't just do this above when we nuked a signature because of * const pointers. */ - foreach_iter(exec_list_iterator, iter, *instructions) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list_safe(n, instructions) { + ir_instruction *ir = (ir_instruction *) n; ir_function *func = ir->as_function(); if (func && func->signatures.is_empty()) { diff --git a/mesalib/src/glsl/opt_function_inlining.cpp b/mesalib/src/glsl/opt_function_inlining.cpp index c8f42a424..9649598dd 100644 --- a/mesalib/src/glsl/opt_function_inlining.cpp +++ b/mesalib/src/glsl/opt_function_inlining.cpp @@ -107,7 +107,7 @@ ir_call::generate_inline(ir_instruction *next_ir) ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare); num_parameters = 0; - foreach_iter(exec_list_iterator, iter_sig, this->callee->parameters) + foreach_list(n, &this->callee->parameters) num_parameters++; parameters = new ir_variable *[num_parameters]; @@ -116,11 +116,10 @@ ir_call::generate_inline(ir_instruction *next_ir) * and set up the mapping of real function body variables to ours. */ i = 0; - exec_list_iterator sig_param_iter = this->callee->parameters.iterator(); - exec_list_iterator param_iter = this->actual_parameters.iterator(); - for (i = 0; i < num_parameters; i++) { - ir_variable *sig_param = (ir_variable *) sig_param_iter.get(); - ir_rvalue *param = (ir_rvalue *) param_iter.get(); + foreach_two_lists(formal_node, &this->callee->parameters, + actual_node, &this->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *param = (ir_rvalue *) actual_node; /* Generate a new variable for the parameter. */ if (sig_param->type->contains_opaque()) { @@ -154,15 +153,14 @@ ir_call::generate_inline(ir_instruction *next_ir) next_ir->insert_before(assign); } - sig_param_iter.next(); - param_iter.next(); + ++i; } exec_list new_instructions; /* Generate the inlined body of the function to a new list */ - foreach_iter(exec_list_iterator, iter, callee->body) { - ir_instruction *ir = (ir_instruction *)iter.get(); + foreach_list(n, &callee->body) { + ir_instruction *ir = (ir_instruction *) n; ir_instruction *new_ir = ir->clone(ctx, ht); new_instructions.push_tail(new_ir); @@ -172,11 +170,10 @@ ir_call::generate_inline(ir_instruction *next_ir) /* If any opaque types were passed in, replace any deref of the * opaque variable with a deref of the argument. */ - param_iter = this->actual_parameters.iterator(); - sig_param_iter = this->callee->parameters.iterator(); - for (i = 0; i < num_parameters; i++) { - ir_instruction *const param = (ir_instruction *) param_iter.get(); - ir_variable *sig_param = (ir_variable *) sig_param_iter.get(); + foreach_two_lists(formal_node, &this->callee->parameters, + actual_node, &this->actual_parameters) { + ir_rvalue *const param = (ir_rvalue *) actual_node; + ir_variable *sig_param = (ir_variable *) formal_node; if (sig_param->type->contains_opaque()) { ir_dereference *deref = param->as_dereference(); @@ -184,8 +181,6 @@ ir_call::generate_inline(ir_instruction *next_ir) assert(deref); do_variable_replacement(&new_instructions, sig_param, deref); } - param_iter.next(); - sig_param_iter.next(); } /* Now push those new instructions in. */ @@ -195,11 +190,10 @@ ir_call::generate_inline(ir_instruction *next_ir) * variables to our own. */ i = 0; - param_iter = this->actual_parameters.iterator(); - sig_param_iter = this->callee->parameters.iterator(); - for (i = 0; i < num_parameters; i++) { - ir_instruction *const param = (ir_instruction *) param_iter.get(); - const ir_variable *const sig_param = (ir_variable *) sig_param_iter.get(); + foreach_two_lists(formal_node, &this->callee->parameters, + actual_node, &this->actual_parameters) { + ir_rvalue *const param = (ir_rvalue *) actual_node; + const ir_variable *const sig_param = (ir_variable *) formal_node; /* Move our param variable into the actual param if it's an 'out' type. */ if (parameters[i] && (sig_param->data.mode == ir_var_function_out || @@ -212,8 +206,7 @@ ir_call::generate_inline(ir_instruction *next_ir) next_ir->insert_before(assign); } - param_iter.next(); - sig_param_iter.next(); + ++i; } delete [] parameters; @@ -349,8 +342,8 @@ ir_variable_replacement_visitor::visit_leave(ir_dereference_record *ir) ir_visitor_status ir_variable_replacement_visitor::visit_leave(ir_call *ir) { - foreach_iter(exec_list_iterator, iter, *ir) { - ir_rvalue *param = (ir_rvalue *)iter.get(); + foreach_list_safe(n, &ir->actual_parameters) { + ir_rvalue *param = (ir_rvalue *) n; ir_rvalue *new_param = param; replace_rvalue(&new_param); diff --git a/mesalib/src/glsl/opt_if_simplification.cpp b/mesalib/src/glsl/opt_if_simplification.cpp index db59b131d..2bec8252e 100644 --- a/mesalib/src/glsl/opt_if_simplification.cpp +++ b/mesalib/src/glsl/opt_if_simplification.cpp @@ -90,13 +90,13 @@ ir_if_simplification_visitor::visit_leave(ir_if *ir) * that matters out. */ if (condition_constant->value.b[0]) { - foreach_iter(exec_list_iterator, then_iter, ir->then_instructions) { - ir_instruction *then_ir = (ir_instruction *)then_iter.get(); + foreach_list_safe(n, &ir->then_instructions) { + ir_instruction *then_ir = (ir_instruction *) n; ir->insert_before(then_ir); } } else { - foreach_iter(exec_list_iterator, else_iter, ir->else_instructions) { - ir_instruction *else_ir = (ir_instruction *)else_iter.get(); + foreach_list_safe(n, &ir->else_instructions) { + ir_instruction *else_ir = (ir_instruction *) n; ir->insert_before(else_ir); } } diff --git a/mesalib/src/glsl/opt_structure_splitting.cpp b/mesalib/src/glsl/opt_structure_splitting.cpp index 414f0000d..1ec537b13 100644 --- a/mesalib/src/glsl/opt_structure_splitting.cpp +++ b/mesalib/src/glsl/opt_structure_splitting.cpp @@ -107,8 +107,8 @@ ir_structure_reference_visitor::get_variable_entry(ir_variable *var) || var->data.mode == ir_var_shader_in || var->data.mode == ir_var_shader_out) return NULL; - foreach_iter(exec_list_iterator, iter, this->variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list(n, &this->variable_list) { + variable_entry *entry = (variable_entry *) n; if (entry->var == var) return entry; } @@ -209,8 +209,8 @@ ir_structure_splitting_visitor::get_splitting_entry(ir_variable *var) if (!var->type->is_record()) return NULL; - foreach_iter(exec_list_iterator, iter, *this->variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list(n, this->variable_list) { + variable_entry *entry = (variable_entry *) n; if (entry->var == var) { return entry; } @@ -315,8 +315,8 @@ do_structure_splitting(exec_list *instructions) visit_list_elements(&refs, instructions); /* Trim out variables we can't split. */ - foreach_iter(exec_list_iterator, iter, refs.variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list_safe(n, &refs.variable_list) { + variable_entry *entry = (variable_entry *) n; if (debug) { printf("structure %s@%p: decl %d, whole_access %d\n", @@ -337,8 +337,8 @@ do_structure_splitting(exec_list *instructions) /* Replace the decls of the structures to be split with their split * components. */ - foreach_iter(exec_list_iterator, iter, refs.variable_list) { - variable_entry *entry = (variable_entry *)iter.get(); + foreach_list_safe(n, &refs.variable_list) { + variable_entry *entry = (variable_entry *) n; const struct glsl_type *type = entry->var->type; entry->mem_ctx = ralloc_parent(entry->var); diff --git a/mesalib/src/glsl/opt_tree_grafting.cpp b/mesalib/src/glsl/opt_tree_grafting.cpp index 6d75a1573..f3bd580af 100644 --- a/mesalib/src/glsl/opt_tree_grafting.cpp +++ b/mesalib/src/glsl/opt_tree_grafting.cpp @@ -204,11 +204,10 @@ ir_tree_grafting_visitor::visit_enter(ir_function_signature *ir) ir_visitor_status ir_tree_grafting_visitor::visit_enter(ir_call *ir) { - exec_list_iterator sig_iter = ir->callee->parameters.iterator(); - /* Reminder: iterating ir_call iterates its parameters. */ - foreach_iter(exec_list_iterator, iter, *ir) { - ir_variable *sig_param = (ir_variable *)sig_iter.get(); - ir_rvalue *ir = (ir_rvalue *)iter.get(); + foreach_two_lists(formal_node, &ir->callee->parameters, + actual_node, &ir->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *ir = (ir_rvalue *) actual_node; ir_rvalue *new_ir = ir; if (sig_param->data.mode != ir_var_function_in @@ -222,7 +221,6 @@ ir_tree_grafting_visitor::visit_enter(ir_call *ir) ir->replace_with(new_ir); return visit_stop; } - sig_iter.next(); } if (ir->return_deref && check_graft(ir, ir->return_deref->var) == visit_stop) diff --git a/mesalib/src/glsl/s_expression.cpp b/mesalib/src/glsl/s_expression.cpp index 1bdf6bca6..6906ff0eb 100644 --- a/mesalib/src/glsl/s_expression.cpp +++ b/mesalib/src/glsl/s_expression.cpp @@ -162,8 +162,8 @@ void s_symbol::print() void s_list::print() { printf("("); - foreach_iter(exec_list_iterator, it, this->subexpressions) { - s_expression *expr = (s_expression*) it.get(); + foreach_list(n, &this->subexpressions) { + s_expression *expr = (s_expression *) n; expr->print(); if (!expr->next->is_tail_sentinel()) printf(" "); @@ -201,11 +201,11 @@ s_match(s_expression *top, unsigned n, s_pattern *pattern, bool partial) return false; unsigned i = 0; - foreach_iter(exec_list_iterator, it, list->subexpressions) { + foreach_list(node, &list->subexpressions) { if (i >= n) return partial; /* More actual items than the pattern expected */ - s_expression *expr = (s_expression *) it.get(); + s_expression *expr = (s_expression *) node; if (expr == NULL || !pattern[i].match(expr)) return false; diff --git a/mesalib/src/glsl/standalone_scaffolding.cpp b/mesalib/src/glsl/standalone_scaffolding.cpp index cbff6d182..257d2e7a9 100644 --- a/mesalib/src/glsl/standalone_scaffolding.cpp +++ b/mesalib/src/glsl/standalone_scaffolding.cpp @@ -76,6 +76,7 @@ _mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type) shader = rzalloc(NULL, struct gl_shader); if (shader) { shader->Type = type; + shader->Stage = _mesa_shader_enum_to_shader_stage(type); shader->Name = name; shader->RefCount = 1; } @@ -126,16 +127,16 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api) ctx->Const.MaxClipPlanes = 6; ctx->Const.MaxTextureUnits = 2; ctx->Const.MaxTextureCoordUnits = 2; - ctx->Const.VertexProgram.MaxAttribs = 16; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs = 16; - ctx->Const.VertexProgram.MaxUniformComponents = 512; - ctx->Const.VertexProgram.MaxOutputComponents = 32; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents = 512; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = 32; ctx->Const.MaxVarying = 8; /* == gl_MaxVaryingFloats / 4 */ - ctx->Const.VertexProgram.MaxTextureImageUnits = 0; + ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = 0; ctx->Const.MaxCombinedTextureImageUnits = 2; - ctx->Const.FragmentProgram.MaxTextureImageUnits = 2; - ctx->Const.FragmentProgram.MaxUniformComponents = 64; - ctx->Const.FragmentProgram.MaxInputComponents = 32; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = 2; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents = 64; + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 32; ctx->Const.MaxDrawBuffers = 1; @@ -148,6 +149,6 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api) /* Default pragma settings */ options.DefaultPragmas.Optimize = true; - for (int sh = 0; sh < MESA_SHADER_TYPES; ++sh) + for (int sh = 0; sh < MESA_SHADER_STAGES; ++sh) memcpy(&ctx->ShaderCompilerOptions[sh], &options, sizeof(options)); } diff --git a/mesalib/src/glsl/standalone_scaffolding.h b/mesalib/src/glsl/standalone_scaffolding.h index 9f4818a8a..327fef2df 100644 --- a/mesalib/src/glsl/standalone_scaffolding.h +++ b/mesalib/src/glsl/standalone_scaffolding.h @@ -48,8 +48,8 @@ extern "C" void _mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id, const char *msg, int len); -static inline gl_shader_type -_mesa_shader_type_to_index(GLenum v) +static inline gl_shader_stage +_mesa_shader_enum_to_shader_stage(GLenum v) { switch (v) { case GL_VERTEX_SHADER: @@ -59,7 +59,7 @@ _mesa_shader_type_to_index(GLenum v) case GL_GEOMETRY_SHADER: return MESA_SHADER_GEOMETRY; default: - assert(!"bad value in _mesa_shader_type_to_index()"); + assert(!"bad value in _mesa_shader_enum_to_shader_stage()"); return MESA_SHADER_VERTEX; } } diff --git a/mesalib/src/glsl/test_optpass.cpp b/mesalib/src/glsl/test_optpass.cpp index 67e2ab2b1..1a15f3c63 100644 --- a/mesalib/src/glsl/test_optpass.cpp +++ b/mesalib/src/glsl/test_optpass.cpp @@ -204,11 +204,12 @@ int test_optpass(int argc, char **argv) struct gl_shader *shader = rzalloc(NULL, struct gl_shader); shader->Type = shader_type; + shader->Stage = _mesa_shader_enum_to_shader_stage(shader_type); string input = read_stdin_to_eof(); struct _mesa_glsl_parse_state *state - = new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); + = new(shader) _mesa_glsl_parse_state(ctx, shader->Stage, shader); if (input_format_ir) { shader->ir = new(shader) exec_list; @@ -242,7 +243,7 @@ int test_optpass(int argc, char **argv) if (!state->error) { GLboolean progress; const struct gl_shader_compiler_options *options = - &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader_type)]; + &ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader_type)]; do { progress = do_optimization_passes(shader->ir, &argv[optind], argc - optind, quiet != 0, options); |