From fffd436e9c2ec6f5aa501ee57d0e4ade7293ee60 Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 13 Apr 2012 11:34:03 +0200 Subject: fontconfig xserver xkeyboard-config mesa git update 13 Apr 2012 --- mesalib/configure.ac | 15 +- mesalib/docs/viewperf.html | 15 +- mesalib/src/glsl/Makefile.sources | 1 + mesalib/src/glsl/glsl_parser_extras.cpp | 1 + mesalib/src/glsl/ir_optimization.h | 1 + mesalib/src/glsl/opt_array_splitting.cpp | 384 +++++++++++++++++++++++++++++++ mesalib/src/mapi/Android.mk | 11 +- mesalib/src/mesa/main/bufferobj.c | 30 +++ mesalib/src/mesa/main/bufferobj.h | 2 + mesalib/src/mesa/main/texobj.c | 59 +++++ mesalib/src/mesa/main/texobj.h | 3 + mesalib/src/mesa/program/ir_to_mesa.cpp | 2 +- 12 files changed, 505 insertions(+), 19 deletions(-) create mode 100644 mesalib/src/glsl/opt_array_splitting.cpp (limited to 'mesalib') diff --git a/mesalib/configure.ac b/mesalib/configure.ac index 21e4308fa..65d358e0a 100644 --- a/mesalib/configure.ac +++ b/mesalib/configure.ac @@ -82,18 +82,6 @@ solaris*) ;; esac -AC_PATH_PROG([GTESTCONFIG], [gtest-config]) -if test "x$GTESTCONFIG" != "x"; then - GTEST_CFLAGS=`gtest-config --cppflags --cxxflags` - GTEST_LIBS=`gtest-config --ldflags --libs` - AC_SUBST([GTEST_CFLAGS]) - AC_SUBST([GTEST_LIBS]) - HAVE_GTEST=yes -else - HAVE_GTEST=no -fi -AM_CONDITIONAL(HAVE_GTEST, test x$HAVE_GTEST = xyes) - dnl clang is mostly GCC-compatible, but its version is much lower, dnl so we have to check for it. AC_MSG_CHECKING([if compiling with clang]) @@ -794,7 +782,7 @@ dnl dnl this variable will be prepended to SRC_DIRS and is not exported CORE_DIRS="" -SRC_DIRS="" +SRC_DIRS="gtest" GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_TARGET_DIRS="" @@ -1999,6 +1987,7 @@ AC_CONFIG_FILES([configs/autoconf src/egl/wayland/wayland-drm/Makefile src/glx/Makefile src/mapi/shared-glapi/Makefile + src/gtest/Makefile src/mesa/drivers/dri/dri.pc src/mesa/drivers/dri/Makefile src/mesa/drivers/dri/common/Makefile diff --git a/mesalib/docs/viewperf.html b/mesalib/docs/viewperf.html index bb3852734..c294255ac 100644 --- a/mesalib/docs/viewperf.html +++ b/mesalib/docs/viewperf.html @@ -67,7 +67,7 @@ Subsequent drawing calls become no-ops and the rendering is incorrect. -

sw-02 tests 1, 2, 4

+

sw-02 tests 1, 2, 4, 6

These tests depend on the @@ -81,6 +81,19 @@ be incorrect and the test will fail.

+ +

sw-02 test 6

+ +

+The lines drawn in this test appear in a random color. +That's because texture mapping is enabled when the lines are drawn, but no +texture image is defined (glTexImage2D() is called with pixels=NULL). +Since GL says the contents of the texture image are undefined in that +situation, we get a random color. +

+ + +

Lightwave-01 test 3

diff --git a/mesalib/src/glsl/Makefile.sources b/mesalib/src/glsl/Makefile.sources index 06728daf7..15f5e1f50 100644 --- a/mesalib/src/glsl/Makefile.sources +++ b/mesalib/src/glsl/Makefile.sources @@ -62,6 +62,7 @@ LIBGLSL_CXX_FILES := \ lower_vector.cpp \ lower_output_reads.cpp \ opt_algebraic.cpp \ + opt_array_splitting.cpp \ opt_constant_folding.cpp \ opt_constant_propagation.cpp \ opt_constant_variable.cpp \ diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index 6547ad2d3..ae7a365f4 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -1044,6 +1044,7 @@ do_common_optimization(exec_list *ir, bool linked, progress = do_swizzle_swizzle(ir) || progress; progress = do_noop_swizzle(ir) || progress; + progress = optimize_split_arrays(ir, linked) || progress; progress = optimize_redundant_jumps(ir) || progress; loop_state *ls = analyze_loop_variables(ir); diff --git a/mesalib/src/glsl/ir_optimization.h b/mesalib/src/glsl/ir_optimization.h index 085b96903..356783583 100644 --- a/mesalib/src/glsl/ir_optimization.h +++ b/mesalib/src/glsl/ir_optimization.h @@ -74,6 +74,7 @@ bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz); bool lower_clip_distance(exec_list *instructions); void lower_output_reads(exec_list *instructions); bool optimize_redundant_jumps(exec_list *instructions); +bool optimize_split_arrays(exec_list *instructions, bool linked); ir_rvalue * compare_index_block(exec_list *instructions, ir_variable *index, diff --git a/mesalib/src/glsl/opt_array_splitting.cpp b/mesalib/src/glsl/opt_array_splitting.cpp new file mode 100644 index 000000000..f11b51631 --- /dev/null +++ b/mesalib/src/glsl/opt_array_splitting.cpp @@ -0,0 +1,384 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file opt_array_splitting.cpp + * + * If an array is always dereferenced with a constant index, then + * split it apart into its elements, making it more amenable to other + * optimization passes. + * + * This skips uniform/varying arrays, which would need careful + * handling due to their ir->location fields tying them to the GL API + * and other shader stages. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_print_visitor.h" +#include "glsl_types.h" + +static bool debug = false; + +namespace opt_array_splitting { + +class variable_entry : public exec_node +{ +public: + variable_entry(ir_variable *var) + { + this->var = var; + this->whole_array_access = 0; + this->declaration = false; + this->components = NULL; + this->mem_ctx = NULL; + if (var->type->is_array()) + this->size = var->type->length; + else + this->size = var->type->matrix_columns; + } + + ir_variable *var; /* The key: the variable's pointer. */ + unsigned size; /* array length or matrix columns */ + + /** Number of times the variable is referenced, including assignments. */ + unsigned whole_array_access; + + bool declaration; /* If the variable had a decl in the instruction stream */ + + ir_variable **components; + + /** ralloc_parent(this->var) -- the shader's talloc context. */ + void *mem_ctx; +}; + +} /* namespace */ +using namespace opt_array_splitting; + +/** + * This class does a walk over the tree, coming up with the set of + * variables that could be split by looking to see if they are arrays + * that are only ever constant-index dereferenced. + */ +class ir_array_reference_visitor : public ir_hierarchical_visitor { +public: + ir_array_reference_visitor(void) + { + this->mem_ctx = ralloc_context(NULL); + this->variable_list.make_empty(); + } + + ~ir_array_reference_visitor(void) + { + ralloc_free(mem_ctx); + } + + bool get_split_list(exec_list *instructions, bool linked); + + virtual ir_visitor_status visit(ir_variable *); + virtual ir_visitor_status visit(ir_dereference_variable *); + virtual ir_visitor_status visit_enter(ir_dereference_array *); + + variable_entry *get_variable_entry(ir_variable *var); + + /* List of variable_entry */ + exec_list variable_list; + + void *mem_ctx; +}; + +variable_entry * +ir_array_reference_visitor::get_variable_entry(ir_variable *var) +{ + assert(var); + + if (var->mode != ir_var_auto && + var->mode != ir_var_temporary) + return NULL; + + if (!(var->type->is_array() || var->type->is_matrix())) + return NULL; + + /* If the array hasn't been sized yet, we can't split it. After + * linking, this should be resolved. + */ + if (var->type->is_array() && var->type->length == 0) + return NULL; + + foreach_iter(exec_list_iterator, iter, this->variable_list) { + variable_entry *entry = (variable_entry *)iter.get(); + if (entry->var == var) + return entry; + } + + variable_entry *entry = new(mem_ctx) variable_entry(var); + this->variable_list.push_tail(entry); + return entry; +} + + +ir_visitor_status +ir_array_reference_visitor::visit(ir_variable *ir) +{ + variable_entry *entry = this->get_variable_entry(ir); + + if (entry) + entry->declaration = true; + + return visit_continue; +} + +ir_visitor_status +ir_array_reference_visitor::visit(ir_dereference_variable *ir) +{ + variable_entry *entry = this->get_variable_entry(ir->var); + + /* If we made it to here, then the dereference of this array didn't + * have a constant index (see the visit_continue_with_parent + * below), so we can't split the variable. + */ + if (entry) + entry->whole_array_access++; + + return visit_continue; +} + +ir_visitor_status +ir_array_reference_visitor::visit_enter(ir_dereference_array *ir) +{ + ir_dereference_variable *deref = ir->array->as_dereference_variable(); + if (!deref) + return visit_continue; + + variable_entry *entry = this->get_variable_entry(deref->var); + + if (entry && !ir->array_index->as_constant()) + entry->whole_array_access++; + + return visit_continue_with_parent; +} + +bool +ir_array_reference_visitor::get_split_list(exec_list *instructions, + bool linked) +{ + visit_list_elements(this, instructions); + + /* If the shaders aren't linked yet, we can't mess with global + * declarations, which need to be matched by name across shaders. + */ + if (!linked) { + foreach_list(node, instructions) { + ir_variable *var = ((ir_instruction *)node)->as_variable(); + if (var) { + variable_entry *entry = get_variable_entry(var); + if (entry) + entry->remove(); + } + } + } + + /* 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(); + + if (debug) { + printf("array %s@%p: decl %d, whole_access %d\n", + entry->var->name, (void *) entry->var, entry->declaration, + entry->whole_array_access); + } + + if (!entry->declaration || entry->whole_array_access) { + entry->remove(); + } + } + + return !variable_list.is_empty(); +} + +/** This is the class that does the actual work of splitting. */ +class ir_array_splitting_visitor : public ir_rvalue_visitor { +public: + ir_array_splitting_visitor(exec_list *vars) + { + this->variable_list = vars; + } + + virtual ~ir_array_splitting_visitor() + { + } + + virtual ir_visitor_status visit_leave(ir_assignment *); + + void split_deref(ir_dereference **deref); + void handle_rvalue(ir_rvalue **rvalue); + variable_entry *get_splitting_entry(ir_variable *var); + + exec_list *variable_list; + void *mem_ctx; +}; + +variable_entry * +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(); + if (entry->var == var) { + return entry; + } + } + + return NULL; +} + +void +ir_array_splitting_visitor::split_deref(ir_dereference **deref) +{ + ir_dereference_array *deref_array = (*deref)->as_dereference_array(); + if (!deref_array) + return; + + ir_dereference_variable *deref_var = deref_array->array->as_dereference_variable(); + if (!deref_var) + return; + ir_variable *var = deref_var->var; + + variable_entry *entry = get_splitting_entry(var); + if (!entry) + return; + + ir_constant *constant = deref_array->array_index->as_constant(); + assert(constant); + + if (constant->value.i[0] < (int)entry->size) { + *deref = new(entry->mem_ctx) + ir_dereference_variable(entry->components[constant->value.i[0]]); + } else { + /* There was a constant array access beyond the end of the + * array. This might have happened due to constant folding + * after the initial parse. This produces an undefined value, + * but shouldn't crash. Just give them an uninitialized + * variable. + */ + ir_variable *temp = new(entry->mem_ctx) ir_variable(deref_array->type, + "undef", + ir_var_temporary); + entry->components[0]->insert_before(temp); + *deref = new(entry->mem_ctx) ir_dereference_variable(temp); + } +} + +void +ir_array_splitting_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_dereference *deref = (*rvalue)->as_dereference(); + + if (!deref) + return; + + split_deref(&deref); + *rvalue = deref; +} + +ir_visitor_status +ir_array_splitting_visitor::visit_leave(ir_assignment *ir) +{ + /* The normal rvalue visitor skips the LHS of assignments, but we + * need to process those just the same. + */ + ir_rvalue *lhs = ir->lhs; + + handle_rvalue(&lhs); + ir->lhs = lhs->as_dereference(); + + ir->lhs->accept(this); + + handle_rvalue(&ir->rhs); + ir->rhs->accept(this); + + if (ir->condition) { + handle_rvalue(&ir->condition); + ir->condition->accept(this); + } + + return visit_continue; +} + +bool +optimize_split_arrays(exec_list *instructions, bool linked) +{ + ir_array_reference_visitor refs; + if (!refs.get_split_list(instructions, linked)) + return false; + + void *mem_ctx = ralloc_context(NULL); + + /* 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(); + const struct glsl_type *type = entry->var->type; + const struct glsl_type *subtype; + + if (type->is_matrix()) + subtype = glsl_type::get_instance(GLSL_TYPE_FLOAT, + type->vector_elements, 1); + else + subtype = type->fields.array; + + entry->mem_ctx = ralloc_parent(entry->var); + + entry->components = ralloc_array(mem_ctx, + ir_variable *, + entry->size); + + for (unsigned int i = 0; i < entry->size; i++) { + const char *name = ralloc_asprintf(mem_ctx, "%s_%d", + entry->var->name, i); + + entry->components[i] = + new(entry->mem_ctx) ir_variable(subtype, name, ir_var_temporary); + entry->var->insert_before(entry->components[i]); + } + + entry->var->remove(); + } + + ir_array_splitting_visitor split(&refs.variable_list); + visit_list_elements(&split, instructions); + + if (debug) + _mesa_print_ir(instructions, NULL); + + ralloc_free(mem_ctx); + + return true; + +} diff --git a/mesalib/src/mapi/Android.mk b/mesalib/src/mapi/Android.mk index b75361f46..d1749a262 100644 --- a/mesalib/src/mapi/Android.mk +++ b/mesalib/src/mapi/Android.mk @@ -25,9 +25,6 @@ LOCAL_PATH := $(call my-dir) -# get MAPI_GLAPI_FILES -include $(LOCAL_PATH)/mapi/sources.mak - mapi_abi_headers := # --------------------------------------- @@ -38,7 +35,13 @@ include $(CLEAR_VARS) abi_header := shared-glapi/glapi_mapi_tmp.h -LOCAL_SRC_FILES := $(MAPI_GLAPI_FILES) +LOCAL_SRC_FILES := \ + mapi/entry.c \ + mapi/mapi_glapi.c \ + mapi/stub.c \ + mapi/table.c \ + mapi/u_current.c \ + mapi/u_execmem.c LOCAL_CFLAGS := \ -DMAPI_MODE_GLAPI \ diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c index eef10c422..ae7bac14d 100644 --- a/mesalib/src/mesa/main/bufferobj.c +++ b/mesalib/src/mesa/main/bufferobj.c @@ -347,6 +347,36 @@ _mesa_initialize_buffer_object( struct gl_context *ctx, } + +/** + * Callback called from _mesa_HashWalk() + */ +static void +count_buffer_size(GLuint key, void *data, void *userData) +{ + const struct gl_buffer_object *bufObj = + (const struct gl_buffer_object *) data; + GLuint *total = (GLuint *) userData; + + *total = *total + bufObj->Size; +} + + +/** + * Compute total size (in bytes) of all buffer objects for the given context. + * For debugging purposes. + */ +GLuint +_mesa_total_buffer_object_memory(struct gl_context *ctx) +{ + GLuint total = 0; + + _mesa_HashWalk(ctx->Shared->BufferObjects, count_buffer_size, &total); + + return total; +} + + /** * Allocate space for and store data in a buffer object. Any data that was * previously stored in the buffer object is lost. If \c data is \c NULL, diff --git a/mesalib/src/mesa/main/bufferobj.h b/mesalib/src/mesa/main/bufferobj.h index a7ce37928..66343c3cd 100644 --- a/mesalib/src/mesa/main/bufferobj.h +++ b/mesalib/src/mesa/main/bufferobj.h @@ -89,6 +89,8 @@ _mesa_reference_buffer_object(struct gl_context *ctx, _mesa_reference_buffer_object_(ctx, ptr, bufObj); } +extern GLuint +_mesa_total_buffer_object_memory(struct gl_context *ctx); extern void _mesa_init_buffer_object_functions(struct dd_function_table *driver); diff --git a/mesalib/src/mesa/main/texobj.c b/mesalib/src/mesa/main/texobj.c index 4c3eed2b6..155b255a7 100644 --- a/mesalib/src/mesa/main/texobj.c +++ b/mesalib/src/mesa/main/texobj.c @@ -841,6 +841,65 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex) } +/** + * Compute the size of the given texture object, in bytes. + */ +static GLuint +texture_size(const struct gl_texture_object *texObj) +{ + const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1; + GLuint face, level, size = 0; + + for (face = 0; face < numFaces; face++) { + for (level = 0; level < MAX_TEXTURE_LEVELS; level++) { + const struct gl_texture_image *img = texObj->Image[face][level]; + if (img) { + GLuint sz = _mesa_format_image_size(img->TexFormat, img->Width, + img->Height, img->Depth); + size += sz; + } + } + } + + return size; +} + + +/** + * Callback called from _mesa_HashWalk() + */ +static void +count_tex_size(GLuint key, void *data, void *userData) +{ + const struct gl_texture_object *texObj = + (const struct gl_texture_object *) data; + GLuint *total = (GLuint *) userData; + + *total = *total + texture_size(texObj); +} + + +/** + * Compute total size (in bytes) of all textures for the given context. + * For debugging purposes. + */ +GLuint +_mesa_total_texture_memory(struct gl_context *ctx) +{ + GLuint tgt, total = 0; + + _mesa_HashWalk(ctx->Shared->TexObjects, count_tex_size, &total); + + /* plus, the default texture objects */ + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + total += texture_size(ctx->Shared->DefaultTex[tgt]); + } + + return total; +} + + + /*@}*/ diff --git a/mesalib/src/mesa/main/texobj.h b/mesalib/src/mesa/main/texobj.h index c020b9013..23e1ade09 100644 --- a/mesalib/src/mesa/main/texobj.h +++ b/mesalib/src/mesa/main/texobj.h @@ -112,6 +112,9 @@ _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj, extern struct gl_texture_object * _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex); +extern GLuint +_mesa_total_texture_memory(struct gl_context *ctx); + extern void _mesa_unlock_context_textures( struct gl_context *ctx ); diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index 6f4a095dd..840648e04 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -2358,7 +2358,7 @@ class add_uniform_to_shader : public uniform_field_visitor { public: add_uniform_to_shader(struct gl_shader_program *shader_program, struct gl_program_parameter_list *params) - : shader_program(shader_program), params(params) + : shader_program(shader_program), params(params), idx(-1) { /* empty */ } -- cgit v1.2.3