From 4f005bade376d15ee60e90ca45a831aff9725087 Mon Sep 17 00:00:00 2001 From: marha Date: Wed, 26 Oct 2011 10:58:41 +0200 Subject: libX11 libXft mesa mkfontscale pixman xserver git update 26 okt 2011 --- mesalib/src/glsl/Makefile | 1 + mesalib/src/glsl/SConscript | 1 + mesalib/src/glsl/glsl_parser_extras.cpp | 23 +++++++- mesalib/src/glsl/ir_constant_expression.cpp | 29 ++++++++++ mesalib/src/glsl/ir_optimization.h | 6 +- mesalib/src/glsl/ir_variable.cpp | 8 ++- mesalib/src/glsl/link_uniforms.cpp | 85 ++++++++++++++++++++++++++++ mesalib/src/glsl/linker.cpp | 28 +++++++-- mesalib/src/glsl/linker.h | 43 ++++++++++++++ mesalib/src/glsl/lower_if_to_cond_assign.cpp | 3 + mesalib/src/glsl/main.cpp | 2 +- mesalib/src/glsl/opt_dead_code.cpp | 14 +++-- mesalib/src/glsl/ralloc.c | 28 +++++++-- mesalib/src/glsl/ralloc.h | 57 +++++++++++++++++++ mesalib/src/glsl/test_optpass.cpp | 4 +- 15 files changed, 309 insertions(+), 23 deletions(-) create mode 100644 mesalib/src/glsl/link_uniforms.cpp (limited to 'mesalib/src/glsl') diff --git a/mesalib/src/glsl/Makefile b/mesalib/src/glsl/Makefile index b2efb2abc..504f1fb43 100644 --- a/mesalib/src/glsl/Makefile +++ b/mesalib/src/glsl/Makefile @@ -53,6 +53,7 @@ CXX_SOURCES = \ ir_variable_refcount.cpp \ linker.cpp \ link_functions.cpp \ + link_uniforms.cpp \ loop_analysis.cpp \ loop_controls.cpp \ loop_unroll.cpp \ diff --git a/mesalib/src/glsl/SConscript b/mesalib/src/glsl/SConscript index b4786c5e5..09c7edbc4 100644 --- a/mesalib/src/glsl/SConscript +++ b/mesalib/src/glsl/SConscript @@ -64,6 +64,7 @@ glsl_sources = [ 'ir_variable_refcount.cpp', 'linker.cpp', 'link_functions.cpp', + 'link_uniforms.cpp', 'loop_analysis.cpp', 'loop_controls.cpp', 'loop_unroll.cpp', diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index a9075b2b1..e2112fe6d 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -883,8 +883,27 @@ ast_struct_specifier::ast_struct_specifier(char *identifier, this->declarations.push_degenerate_list_at_head(&declarator_list->link); } +/** + * Do the set of common optimizations passes + * + * \param ir List of instructions to be optimized + * \param linked Is the shader linked? This enables + * optimizations passes that remove code at + * global scope and could cause linking to + * fail. + * \param uniform_locations_assigned Have locations already been assigned for + * uniforms? This prevents the declarations + * of unused uniforms from being removed. + * The setting of this flag only matters if + * \c linked is \c true. + * \param max_unroll_iterations Maximum number of loop iterations to be + * unrolled. Setting to 0 forces all loops + * to be unrolled. + */ bool -do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations) +do_common_optimization(exec_list *ir, bool linked, + bool uniform_locations_assigned, + unsigned max_unroll_iterations) { GLboolean progress = GL_FALSE; @@ -900,7 +919,7 @@ do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iteration progress = do_copy_propagation(ir) || progress; progress = do_copy_propagation_elements(ir) || progress; if (linked) - progress = do_dead_code(ir) || progress; + progress = do_dead_code(ir, uniform_locations_assigned) || progress; else progress = do_dead_code_unlinked(ir) || progress; progress = do_dead_code_local(ir) || progress; diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp index b3fe6cf96..83f084d88 100644 --- a/mesalib/src/glsl/ir_constant_expression.cpp +++ b/mesalib/src/glsl/ir_constant_expression.cpp @@ -39,6 +39,25 @@ #include "ir_visitor.h" #include "glsl_types.h" +/* Using C99 rounding functions for roundToEven() implementation is + * difficult, because round(), rint, and nearbyint() are affected by + * fesetenv(), which the application may have done for its own + * purposes. Mesa's IROUND macro is close to what we want, but it + * rounds away from 0 on n + 0.5. + */ +static int +round_to_even(float val) +{ + int rounded = IROUND(val); + + if (val - floor(val) == 0.5) { + if (rounded % 2 != 0) + rounded += val > 0 ? -1 : 1; + } + + return rounded; +} + static float dot(ir_constant *op0, ir_constant *op1) { @@ -196,6 +215,13 @@ ir_expression::constant_expression_value() } break; + case ir_unop_round_even: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = round_to_even(op[0]->value.f[c]); + } + break; + case ir_unop_ceil: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { @@ -1324,6 +1350,9 @@ ir_call::constant_expression_value() * op[1]->value.f[c]; } } + } else if (strcmp(callee, "round") == 0 || + strcmp(callee, "roundEven") == 0) { + expr = new(mem_ctx) ir_expression(ir_unop_round_even, op[0]); } else if (strcmp(callee, "sign") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL); } else if (strcmp(callee, "sin") == 0) { diff --git a/mesalib/src/glsl/ir_optimization.h b/mesalib/src/glsl/ir_optimization.h index af80e26b9..7b32e84f0 100644 --- a/mesalib/src/glsl/ir_optimization.h +++ b/mesalib/src/glsl/ir_optimization.h @@ -37,7 +37,9 @@ #define MOD_TO_FRACT 0x20 #define INT_DIV_TO_MUL_RCP 0x40 -bool do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations); +bool do_common_optimization(exec_list *ir, bool linked, + bool uniform_locations_assigned, + unsigned max_unroll_iterations); bool do_algebraic(exec_list *instructions); bool do_constant_folding(exec_list *instructions); @@ -46,7 +48,7 @@ bool do_constant_variable_unlinked(exec_list *instructions); bool do_copy_propagation(exec_list *instructions); bool do_copy_propagation_elements(exec_list *instructions); bool do_constant_propagation(exec_list *instructions); -bool do_dead_code(exec_list *instructions); +bool do_dead_code(exec_list *instructions, bool uniform_locations_assigned); bool do_dead_code_local(exec_list *instructions); bool do_dead_code_unlinked(exec_list *instructions); bool do_dead_functions(exec_list *instructions); diff --git a/mesalib/src/glsl/ir_variable.cpp b/mesalib/src/glsl/ir_variable.cpp index 6ae3b1f9e..8337e15b8 100644 --- a/mesalib/src/glsl/ir_variable.cpp +++ b/mesalib/src/glsl/ir_variable.cpp @@ -232,11 +232,11 @@ MATRIX(gl_TextureMatrixInverseTranspose, static struct gl_builtin_uniform_element gl_NormalMatrix_elements[] = { { NULL, { STATE_MODELVIEW_MATRIX, 0, 0, 0, STATE_MATRIX_INVERSE}, - SWIZZLE_XYZW }, + MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) }, { NULL, { STATE_MODELVIEW_MATRIX, 0, 1, 1, STATE_MATRIX_INVERSE}, - SWIZZLE_XYZW }, + MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) }, { NULL, { STATE_MODELVIEW_MATRIX, 0, 2, 2, STATE_MATRIX_INVERSE}, - SWIZZLE_XYZW }, + MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_Z) }, }; #undef MATRIX @@ -615,6 +615,8 @@ generate_130_uniforms(exec_list *instructions, add_builtin_constant(instructions, symtab, "gl_MaxClipDistances", state->Const.MaxClipPlanes); + add_builtin_constant(instructions, symtab, "gl_MaxVaryingComponents", + state->Const.MaxVaryingFloats); } diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp new file mode 100644 index 000000000..6dd1f5354 --- /dev/null +++ b/mesalib/src/glsl/link_uniforms.cpp @@ -0,0 +1,85 @@ +/* + * Copyright © 2011 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "main/core.h" +#include "ir.h" +#include "linker.h" +#include "glsl_symbol_table.h" +#include "program/hash_table.h" + +/** + * \file link_uniforms.cpp + * Assign locations for GLSL uniforms. + * + * \author Ian Romanick + */ + +void +uniform_field_visitor::process(ir_variable *var) +{ + const glsl_type *t = var->type; + + /* Only strdup the name if we actually will need to modify it. */ + if (t->is_record() || (t->is_array() && t->fields.array->is_record())) { + char *name = ralloc_strdup(NULL, var->name); + recursion(var->type, &name, strlen(name)); + ralloc_free(name); + } else { + this->visit_field(t, var->name); + } +} + +void +uniform_field_visitor::recursion(const glsl_type *t, char **name, + unsigned name_length) +{ + /* Records need to have each field processed individually. + * + * Arrays of records need to have each array element processed + * individually, then each field of the resulting array elements processed + * individually. + */ + if (t->is_record()) { + for (unsigned i = 0; i < t->length; i++) { + const char *field = t->fields.structure[i].name; + + /* Append '.field' to the current uniform name. */ + ralloc_asprintf_rewrite_tail(name, name_length, ".%s", field); + + recursion(t->fields.structure[i].type, name, + name_length + 1 + strlen(field)); + } + } else if (t->is_array() && t->fields.array->is_record()) { + for (unsigned i = 0; i < t->length; i++) { + char subscript[13]; + + /* Append the subscript to the current uniform name */ + const unsigned subscript_length = snprintf(subscript, 13, "[%u]", i); + ralloc_asprintf_rewrite_tail(name, name_length, "%s", subscript); + + recursion(t->fields.array, name, name_length + subscript_length); + } + } else { + this->visit_field(t, *name); + } +} diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp index a7c38a342..beadec6f6 100644 --- a/mesalib/src/glsl/linker.cpp +++ b/mesalib/src/glsl/linker.cpp @@ -1742,14 +1742,10 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if (ctx->ShaderCompilerOptions[i].LowerClipDistance) lower_clip_distance(prog->_LinkedShaders[i]->ir); - while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, 32)) + while (do_common_optimization(prog->_LinkedShaders[i]->ir, true, false, 32)) ; } - update_array_sizes(prog); - - assign_uniform_locations(prog); - /* FINISHME: The value of the max_attribute_index parameter is * FINISHME: implementation dependent based on the value of * FINISHME: GL_MAX_VERTEX_ATTRIBS. GL_MAX_VERTEX_ATTRIBS must be @@ -1785,6 +1781,12 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if (prog->_LinkedShaders[MESA_SHADER_VERTEX] != NULL) { demote_shader_inputs_and_outputs(prog->_LinkedShaders[MESA_SHADER_VERTEX], ir_var_out); + + /* Eliminate code that is now dead due to unused vertex outputs being + * demoted. + */ + while (do_dead_code(prog->_LinkedShaders[MESA_SHADER_VERTEX]->ir, false)) + ; } if (prog->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) { @@ -1793,14 +1795,30 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) demote_shader_inputs_and_outputs(sh, ir_var_in); demote_shader_inputs_and_outputs(sh, ir_var_inout); demote_shader_inputs_and_outputs(sh, ir_var_out); + + /* Eliminate code that is now dead due to unused geometry outputs being + * demoted. + */ + while (do_dead_code(prog->_LinkedShaders[MESA_SHADER_GEOMETRY]->ir, false)) + ; } if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] != NULL) { gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]; demote_shader_inputs_and_outputs(sh, ir_var_in); + + /* Eliminate code that is now dead due to unused fragment inputs being + * demoted. This shouldn't actually do anything other than remove + * declarations of the (now unused) global variables. + */ + while (do_dead_code(prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir, false)) + ; } + update_array_sizes(prog); + assign_uniform_locations(prog); + /* OpenGL ES requires that a vertex shader and a fragment shader both be * present in a linked program. By checking for use of shading language * version 1.00, we also catch the GL_ARB_ES2_compatibility case. diff --git a/mesalib/src/glsl/linker.h b/mesalib/src/glsl/linker.h index 769cf68b6..78c632961 100644 --- a/mesalib/src/glsl/linker.h +++ b/mesalib/src/glsl/linker.h @@ -1,3 +1,4 @@ +/* -*- c++ -*- */ /* * Copyright © 2010 Intel Corporation * @@ -29,4 +30,46 @@ extern bool link_function_calls(gl_shader_program *prog, gl_shader *main, gl_shader **shader_list, unsigned num_shaders); +/** + * Class for processing all of the leaf fields of an uniform + * + * Leaves are, roughly speaking, the parts of the uniform that the application + * could query with \c glGetUniformLocation (or that could be returned by + * \c glGetActiveUniforms). + * + * Classes my derive from this class to implement specific functionality. + * This class only provides the mechanism to iterate over the leaves. Derived + * classes must implement \c ::visit_field and may override \c ::process. + */ +class uniform_field_visitor { +public: + /** + * Begin processing a uniform + * + * Classes that overload this function should call \c ::process from the + * base class to start the recursive processing of the uniform. + * + * \param var The uniform variable that is to be processed + * + * Calls \c ::visit_field for each leaf of the uniform. + */ + void process(ir_variable *var); + +protected: + /** + * Method invoked for each leaf of the uniform + * + * \param type Type of the field. + * \param name Fully qualified name of the field. + */ + virtual void visit_field(const glsl_type *type, const char *name) = 0; + +private: + /** + * \param name_length Length of the current name \b not including the + * terminating \c NUL character. + */ + void recursion(const glsl_type *t, char **name, unsigned name_length); +}; + #endif /* GLSL_LINKER_H */ diff --git a/mesalib/src/glsl/lower_if_to_cond_assign.cpp b/mesalib/src/glsl/lower_if_to_cond_assign.cpp index 7b89a1539..2c5d5612d 100644 --- a/mesalib/src/glsl/lower_if_to_cond_assign.cpp +++ b/mesalib/src/glsl/lower_if_to_cond_assign.cpp @@ -79,6 +79,9 @@ public: bool lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth) { + if (max_depth == UINT_MAX) + return false; + ir_if_to_cond_assign_visitor v(max_depth); visit_list_elements(&v, instructions); diff --git a/mesalib/src/glsl/main.cpp b/mesalib/src/glsl/main.cpp index 019213750..e17422471 100644 --- a/mesalib/src/glsl/main.cpp +++ b/mesalib/src/glsl/main.cpp @@ -166,7 +166,7 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader) if (!state->error && !shader->ir->is_empty()) { bool progress; do { - progress = do_common_optimization(shader->ir, false, 32); + progress = do_common_optimization(shader->ir, false, false, 32); } while (progress); validate_ir_tree(shader->ir); diff --git a/mesalib/src/glsl/opt_dead_code.cpp b/mesalib/src/glsl/opt_dead_code.cpp index cb500d2d1..5b9546ad4 100644 --- a/mesalib/src/glsl/opt_dead_code.cpp +++ b/mesalib/src/glsl/opt_dead_code.cpp @@ -42,7 +42,7 @@ static bool debug = false; * for usage on an unlinked instruction stream. */ bool -do_dead_code(exec_list *instructions) +do_dead_code(exec_list *instructions, bool uniform_locations_assigned) { ir_variable_refcount_visitor v; bool progress = false; @@ -94,10 +94,11 @@ do_dead_code(exec_list *instructions) */ /* uniform initializers are precious, and could get used by another - * stage. + * stage. Also, once uniform locations have been assigned, the + * declaration cannot be deleted. */ if (entry->var->mode == ir_var_uniform && - entry->var->constant_value) + (uniform_locations_assigned || entry->var->constant_value)) continue; entry->var->remove(); @@ -132,7 +133,12 @@ do_dead_code_unlinked(exec_list *instructions) foreach_iter(exec_list_iterator, sigiter, *f) { ir_function_signature *sig = (ir_function_signature *) sigiter.get(); - if (do_dead_code(&sig->body)) + /* 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 + * terribly, terribly wrong. + */ + if (do_dead_code(&sig->body, false)) progress = true; } } diff --git a/mesalib/src/glsl/ralloc.c b/mesalib/src/glsl/ralloc.c index fb48a91c5..f5f3934ac 100644 --- a/mesalib/src/glsl/ralloc.c +++ b/mesalib/src/glsl/ralloc.c @@ -439,7 +439,28 @@ ralloc_asprintf_append(char **str, const char *fmt, ...) bool ralloc_vasprintf_append(char **str, const char *fmt, va_list args) { - size_t existing_length, new_length; + size_t existing_length; + assert(str != NULL); + existing_length = *str ? strlen(*str) : 0; + return ralloc_vasprintf_rewrite_tail(str, existing_length, fmt, args); +} + +bool +ralloc_asprintf_rewrite_tail(char **str, size_t start, const char *fmt, ...) +{ + bool success; + va_list args; + va_start(args, fmt); + success = ralloc_vasprintf_rewrite_tail(str, start, fmt, args); + va_end(args); + return success; +} + +bool +ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt, + va_list args) +{ + size_t new_length; char *ptr; assert(str != NULL); @@ -450,14 +471,13 @@ ralloc_vasprintf_append(char **str, const char *fmt, va_list args) return true; } - existing_length = strlen(*str); new_length = printf_length(fmt, args); - ptr = resize(*str, existing_length + new_length + 1); + ptr = resize(*str, start + new_length + 1); if (unlikely(ptr == NULL)) return false; - vsnprintf(ptr + existing_length, new_length + 1, fmt, args); + vsnprintf(ptr + start, new_length + 1, fmt, args); *str = ptr; return true; } diff --git a/mesalib/src/glsl/ralloc.h b/mesalib/src/glsl/ralloc.h index d5338152f..1324f3466 100644 --- a/mesalib/src/glsl/ralloc.h +++ b/mesalib/src/glsl/ralloc.h @@ -313,10 +313,61 @@ char *ralloc_asprintf (const void *ctx, const char *fmt, ...); */ char *ralloc_vasprintf(const void *ctx, const char *fmt, va_list args); +/** + * Rewrite the tail of an existing string, starting at a given index. + * + * Overwrites the contents of *str starting at \p start with newly formatted + * text, including a new null-terminator. Allocates more memory as necessary. + * + * This can be used to append formatted text when the length of the existing + * string is already known, saving a strlen() call. + * + * \sa ralloc_asprintf_append + * + * \param str The string to be updated. + * \param start The index to start appending new data at. + * \param fmt A printf-style formatting string + * + * \p str will be updated to the new pointer unless allocation fails. + * + * \return True unless allocation failed. + */ +bool ralloc_asprintf_rewrite_tail(char **str, size_t start, + const char *fmt, ...); + +/** + * Rewrite the tail of an existing string, starting at a given index. + * + * Overwrites the contents of *str starting at \p start with newly formatted + * text, including a new null-terminator. Allocates more memory as necessary. + * + * This can be used to append formatted text when the length of the existing + * string is already known, saving a strlen() call. + * + * \sa ralloc_vasprintf_append + * + * \param str The string to be updated. + * \param start The index to start appending new data at. + * \param fmt A printf-style formatting string + * \param args A va_list containing the data to be formatted + * + * \p str will be updated to the new pointer unless allocation fails. + * + * \return True unless allocation failed. + */ +bool ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt, + va_list args); + /** * Append formatted text to the supplied string. * + * This is equivalent to + * \code + * ralloc_asprintf_rewrite_tail(str, strlen(*str), fmt, ...) + * \endcode + * * \sa ralloc_asprintf + * \sa ralloc_asprintf_rewrite_tail * \sa ralloc_strcat * * \p str will be updated to the new pointer unless allocation fails. @@ -328,7 +379,13 @@ bool ralloc_asprintf_append (char **str, const char *fmt, ...); /** * Append formatted text to the supplied string, given a va_list. * + * This is equivalent to + * \code + * ralloc_vasprintf_rewrite_tail(str, strlen(*str), fmt, args) + * \endcode + * * \sa ralloc_vasprintf + * \sa ralloc_vasprintf_rewrite_tail * \sa ralloc_strcat * * \p str will be updated to the new pointer unless allocation fails. diff --git a/mesalib/src/glsl/test_optpass.cpp b/mesalib/src/glsl/test_optpass.cpp index 89b7f8338..6abafb5d3 100644 --- a/mesalib/src/glsl/test_optpass.cpp +++ b/mesalib/src/glsl/test_optpass.cpp @@ -64,7 +64,7 @@ do_optimization(struct exec_list *ir, const char *optimization) if (sscanf(optimization, "do_common_optimization ( %d , %d ) ", &int_0, &int_1) == 2) { - return do_common_optimization(ir, int_0 != 0, int_1); + return do_common_optimization(ir, int_0 != 0, false, int_1); } else if (strcmp(optimization, "do_algebraic") == 0) { return do_algebraic(ir); } else if (strcmp(optimization, "do_constant_folding") == 0) { @@ -80,7 +80,7 @@ do_optimization(struct exec_list *ir, const char *optimization) } else if (strcmp(optimization, "do_constant_propagation") == 0) { return do_constant_propagation(ir); } else if (strcmp(optimization, "do_dead_code") == 0) { - return do_dead_code(ir); + return do_dead_code(ir, false); } else if (strcmp(optimization, "do_dead_code_local") == 0) { return do_dead_code_local(ir); } else if (strcmp(optimization, "do_dead_code_unlinked") == 0) { -- cgit v1.2.3 From d662d461634660f5c0f3998b5eb7d7ed3bd5a25f Mon Sep 17 00:00:00 2001 From: marha Date: Thu, 27 Oct 2011 08:32:52 +0200 Subject: mesa git update 27 okt 2011 --- mesalib/src/glsl/builtin_variables.h | 6 +-- mesalib/src/glsl/ir_variable.cpp | 12 ++--- mesalib/src/mesa/main/ff_fragment_shader.cpp | 6 +-- mesalib/src/mesa/main/mtypes.h | 14 ++++++ mesalib/src/mesa/main/teximage.c | 67 ++++++++++++++++++++++++-- mesalib/src/mesa/main/texstore.c | 9 ++++ mesalib/src/mesa/state_tracker/st_cb_texture.c | 58 ++-------------------- mesalib/src/mesa/state_tracker/st_context.c | 4 ++ mesalib/src/mesa/state_tracker/st_extensions.c | 2 + 9 files changed, 108 insertions(+), 70 deletions(-) (limited to 'mesalib/src/glsl') diff --git a/mesalib/src/glsl/builtin_variables.h b/mesalib/src/glsl/builtin_variables.h index d25bbf42a..237b361d8 100644 --- a/mesalib/src/glsl/builtin_variables.h +++ b/mesalib/src/glsl/builtin_variables.h @@ -103,8 +103,8 @@ static const builtin_variable builtin_110_deprecated_uniforms[] = { { ir_var_uniform, -1, "gl_LightModelParameters", "gl_LightModel"}, /* Mesa-internal ATI_envmap_bumpmap state. */ - { ir_var_uniform, -1, "vec2", "gl_MESABumpRotMatrix0"}, - { ir_var_uniform, -1, "vec2", "gl_MESABumpRotMatrix1"}, - { ir_var_uniform, -1, "vec4", "gl_MESAFogParamsOptimized"}, + { ir_var_uniform, -1, "vec2", "gl_BumpRotMatrix0MESA"}, + { ir_var_uniform, -1, "vec2", "gl_BumpRotMatrix1MESA"}, + { ir_var_uniform, -1, "vec4", "gl_FogParamsOptimizedMESA"}, }; diff --git a/mesalib/src/glsl/ir_variable.cpp b/mesalib/src/glsl/ir_variable.cpp index 8337e15b8..1ee84d219 100644 --- a/mesalib/src/glsl/ir_variable.cpp +++ b/mesalib/src/glsl/ir_variable.cpp @@ -166,15 +166,15 @@ static struct gl_builtin_uniform_element gl_NormalScale_elements[] = { {NULL, {STATE_NORMAL_SCALE}, SWIZZLE_XXXX}, }; -static struct gl_builtin_uniform_element gl_MESABumpRotMatrix0_elements[] = { +static struct gl_builtin_uniform_element gl_BumpRotMatrix0MESA_elements[] = { {NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_0}, SWIZZLE_XYZW}, }; -static struct gl_builtin_uniform_element gl_MESABumpRotMatrix1_elements[] = { +static struct gl_builtin_uniform_element gl_BumpRotMatrix1MESA_elements[] = { {NULL, {STATE_INTERNAL, STATE_ROT_MATRIX_1}, SWIZZLE_XYZW}, }; -static struct gl_builtin_uniform_element gl_MESAFogParamsOptimized_elements[] = { +static struct gl_builtin_uniform_element gl_FogParamsOptimizedMESA_elements[] = { {NULL, {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED}, SWIZZLE_XYZW}, }; @@ -289,9 +289,9 @@ const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[] = { STATEVAR(gl_NormalMatrix), STATEVAR(gl_NormalScale), - STATEVAR(gl_MESABumpRotMatrix0), - STATEVAR(gl_MESABumpRotMatrix1), - STATEVAR(gl_MESAFogParamsOptimized), + STATEVAR(gl_BumpRotMatrix0MESA), + STATEVAR(gl_BumpRotMatrix1MESA), + STATEVAR(gl_FogParamsOptimizedMESA), STATEVAR(gl_CurrentAttribVertMESA), STATEVAR(gl_CurrentAttribFragMESA), diff --git a/mesalib/src/mesa/main/ff_fragment_shader.cpp b/mesalib/src/mesa/main/ff_fragment_shader.cpp index 3e449b03e..b5500714b 100644 --- a/mesalib/src/mesa/main/ff_fragment_shader.cpp +++ b/mesalib/src/mesa/main/ff_fragment_shader.cpp @@ -1137,8 +1137,8 @@ load_texunit_bumpmap( struct texenv_fragment_program *p, GLuint unit ) ir_variable *rot_mat_0_var, *rot_mat_1_var; ir_dereference_variable *rot_mat_0, *rot_mat_1; - rot_mat_0_var = p->shader->symbols->get_variable("gl_MESABumpRotMatrix0"); - rot_mat_1_var = p->shader->symbols->get_variable("gl_MESABumpRotMatrix1"); + rot_mat_0_var = p->shader->symbols->get_variable("gl_BumpRotMatrix0MESA"); + rot_mat_1_var = p->shader->symbols->get_variable("gl_BumpRotMatrix1MESA"); rot_mat_0 = new(p->mem_ctx) ir_dereference_variable(rot_mat_0_var); rot_mat_1 = new(p->mem_ctx) ir_dereference_variable(rot_mat_1_var); @@ -1229,7 +1229,7 @@ emit_fog_instructions(struct texenv_fragment_program *p, temp = new(p->mem_ctx) ir_dereference_variable(fog_result); fragcolor = new(p->mem_ctx) ir_swizzle(temp, 0, 1, 2, 3, 3); - oparams = p->shader->symbols->get_variable("gl_MESAFogParamsOptimized"); + oparams = p->shader->symbols->get_variable("gl_FogParamsOptimizedMESA"); fogcoord = p->shader->symbols->get_variable("gl_FogFragCoord"); params = p->shader->symbols->get_variable("gl_Fog"); f = new(p->mem_ctx) ir_dereference_variable(fogcoord); diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index 719dff3af..411768641 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -2732,6 +2732,20 @@ struct gl_constants /* GL_ARB_robustness */ GLenum ResetStrategy; + + /** + * Whether the implementation strips out and ignores texture borders. + * + * Many GPU hardware implementations don't support rendering with texture + * borders and mipmapped textures. (Note: not static border color, but the + * old 1-pixel border around each edge). Implementations then have to do + * slow fallbacks to be correct, or just ignore the border and be fast but + * wrong. Setting the flag stripts the border off of TexImage calls, + * providing "fast but wrong" at significantly reduced driver complexity. + * + * Texture borders are deprecated in GL 3.0. + **/ + GLboolean StripTextureBorder; }; diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c index 798201a60..acf7187fd 100644 --- a/mesalib/src/mesa/main/teximage.c +++ b/mesalib/src/mesa/main/teximage.c @@ -2246,6 +2246,45 @@ _mesa_choose_texture_format(struct gl_context *ctx, return f; } +/** + * Adjust pixel unpack params and image dimensions to strip off the + * texture border. + * + * Gallium and intel don't support texture borders. They've seldem been used + * and seldom been implemented correctly anyway. + * + * \param unpackNew returns the new pixel unpack parameters + */ +static void +strip_texture_border(GLint *border, + GLint *width, GLint *height, GLint *depth, + const struct gl_pixelstore_attrib *unpack, + struct gl_pixelstore_attrib *unpackNew) +{ + assert(*border > 0); /* sanity check */ + + *unpackNew = *unpack; + + if (unpackNew->RowLength == 0) + unpackNew->RowLength = *width; + + if (depth && unpackNew->ImageHeight == 0) + unpackNew->ImageHeight = *height; + + unpackNew->SkipPixels += *border; + if (height) + unpackNew->SkipRows += *border; + if (depth) + unpackNew->SkipImages += *border; + + assert(*width >= 3); + *width = *width - 2 * *border; + if (height && *height >= 3) + *height = *height - 2 * *border; + if (depth && *depth >= 3) + *depth = *depth - 2 * *border; + *border = 0; +} /** * Common code to implement all the glTexImage1D/2D/3D functions. @@ -2258,6 +2297,8 @@ teximage(struct gl_context *ctx, GLuint dims, const GLvoid *pixels) { GLboolean error; + struct gl_pixelstore_attrib unpack_no_border; + const struct gl_pixelstore_attrib *unpack = &ctx->Unpack; ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); @@ -2322,6 +2363,16 @@ teximage(struct gl_context *ctx, GLuint dims, return; /* error was recorded */ } + /* Allow a hardware driver to just strip out the border, to provide + * reliable but slightly incorrect hardware rendering instead of + * rarely-tested software fallback rendering. + */ + if (border && ctx->Const.StripTextureBorder) { + strip_texture_border(&border, &width, &height, &depth, unpack, + &unpack_no_border); + unpack = &unpack_no_border; + } + if (ctx->NewState & _NEW_PIXEL) _mesa_update_state(ctx); @@ -2354,19 +2405,19 @@ teximage(struct gl_context *ctx, GLuint dims, case 1: ctx->Driver.TexImage1D(ctx, target, level, internalFormat, width, border, format, - type, pixels, &ctx->Unpack, texObj, + type, pixels, unpack, texObj, texImage); break; case 2: ctx->Driver.TexImage2D(ctx, target, level, internalFormat, width, height, border, format, - type, pixels, &ctx->Unpack, texObj, + type, pixels, unpack, texObj, texImage); break; case 3: ctx->Driver.TexImage3D(ctx, target, level, internalFormat, width, height, depth, border, format, - type, pixels, &ctx->Unpack, texObj, + type, pixels, unpack, texObj, texImage); break; default: @@ -2662,6 +2713,16 @@ copyteximage(struct gl_context *ctx, GLuint dims, texObj = _mesa_get_current_tex_object(ctx, target); + if (border && ctx->Const.StripTextureBorder) { + x += border; + width -= border * 2; + if (dims == 2) { + y += border; + height -= border * 2; + } + border = 0; + } + _mesa_lock_texture(ctx, texObj); { texImage = _mesa_get_tex_image(ctx, texObj, target, level); diff --git a/mesalib/src/mesa/main/texstore.c b/mesalib/src/mesa/main/texstore.c index cd9249630..05c1964d6 100644 --- a/mesalib/src/mesa/main/texstore.c +++ b/mesalib/src/mesa/main/texstore.c @@ -4499,6 +4499,9 @@ _mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level, (void) border; + if (width == 0) + return; + /* allocate storage for texture data */ if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat, width, 1, 1)) { @@ -4560,6 +4563,9 @@ _mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level, (void) border; + if (width == 0 || height == 0) + return; + /* allocate storage for texture data */ if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat, width, height, 1)) { @@ -4651,6 +4657,9 @@ _mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level, (void) border; + if (width == 0 || height == 0 || depth == 0) + return; + /* allocate storage for texture data */ if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat, width, height, depth)) { diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c index 169e235ac..f82346bc6 100644 --- a/mesalib/src/mesa/state_tracker/st_cb_texture.c +++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c @@ -543,45 +543,6 @@ st_AllocTextureImageBuffer(struct gl_context *ctx, } } - -/** - * Adjust pixel unpack params and image dimensions to strip off the - * texture border. - * Gallium doesn't support texture borders. They've seldem been used - * and seldom been implemented correctly anyway. - * \param unpackNew returns the new pixel unpack parameters - */ -static void -strip_texture_border(GLint border, - GLint *width, GLint *height, GLint *depth, - const struct gl_pixelstore_attrib *unpack, - struct gl_pixelstore_attrib *unpackNew) -{ - assert(border > 0); /* sanity check */ - - *unpackNew = *unpack; - - if (unpackNew->RowLength == 0) - unpackNew->RowLength = *width; - - if (depth && unpackNew->ImageHeight == 0) - unpackNew->ImageHeight = *height; - - unpackNew->SkipPixels += border; - if (height) - unpackNew->SkipRows += border; - if (depth) - unpackNew->SkipImages += border; - - assert(*width >= 3); - *width = *width - 2 * border; - if (height && *height >= 3) - *height = *height - 2 * border; - if (depth && *depth >= 3) - *depth = *depth - 2 * border; -} - - /** * Do glTexImage1/2/3D(). */ @@ -602,7 +563,6 @@ st_TexImage(struct gl_context * ctx, struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride = 0; - struct gl_pixelstore_attrib unpackNB; enum pipe_transfer_usage transfer_usage = 0; GLubyte *dstMap; @@ -627,21 +587,9 @@ st_TexImage(struct gl_context * ctx, stObj->surface_based = GL_FALSE; } - /* gallium does not support texture borders, strip it off */ - if (border) { - strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB); - unpack = &unpackNB; - texImage->Width = width; - texImage->Height = height; - texImage->Depth = depth; - texImage->Border = 0; - border = 0; - } - else { - assert(texImage->Width == width); - assert(texImage->Height == height); - assert(texImage->Depth == depth); - } + assert(texImage->Width == width); + assert(texImage->Height == height); + assert(texImage->Depth == depth); stImage->base.Face = _mesa_tex_target_to_face(target); stImage->base.Level = level; diff --git a/mesalib/src/mesa/state_tracker/st_context.c b/mesalib/src/mesa/state_tracker/st_context.c index 6d4bc544d..a1817720d 100644 --- a/mesalib/src/mesa/state_tracker/st_context.c +++ b/mesalib/src/mesa/state_tracker/st_context.c @@ -144,6 +144,10 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe ) /* we want all vertex data to be placed in buffer objects */ vbo_use_buffer_objects(ctx); + + /* make sure that no VBOs are left mapped when we're drawing. */ + vbo_always_unmap_buffers(ctx); + /* Need these flags: */ st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index 37f36de93..6b9ff6b72 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -222,6 +222,8 @@ void st_init_limits(struct st_context *st) _mesa_override_glsl_version(st->ctx); c->UniformBooleanTrue = ~0; } + + c->StripTextureBorder = GL_TRUE; } -- cgit v1.2.3