diff options
author | marha <marha@users.sourceforge.net> | 2011-11-10 09:37:16 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-11-10 09:37:16 +0100 |
commit | 7381bc7b9f63b2a6bf9ea9cbe04614adfc4b2369 (patch) | |
tree | 77cb2af2337d035d6d0b6acb57379b62cfd2c648 /mesalib/src/glsl/lower_vec_index_to_swizzle.cpp | |
parent | 5e98834988b1f5ab74ef6561e493615d55f8c10c (diff) | |
parent | ba1993a2eefbd475b13f373a861a401f06584cf8 (diff) | |
download | vcxsrv-7381bc7b9f63b2a6bf9ea9cbe04614adfc4b2369.tar.gz vcxsrv-7381bc7b9f63b2a6bf9ea9cbe04614adfc4b2369.tar.bz2 vcxsrv-7381bc7b9f63b2a6bf9ea9cbe04614adfc4b2369.zip |
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'mesalib/src/glsl/lower_vec_index_to_swizzle.cpp')
-rw-r--r-- | mesalib/src/glsl/lower_vec_index_to_swizzle.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp b/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp index c7630c28a..46fd6ace1 100644 --- a/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp +++ b/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp @@ -33,6 +33,7 @@ #include "ir_visitor.h" #include "ir_optimization.h" #include "glsl_types.h" +#include "main/macros.h" /** * Visitor class for replacing expressions with ir_constant values. @@ -76,8 +77,25 @@ ir_vec_index_to_swizzle_visitor::convert_vec_index_to_swizzle(ir_rvalue *ir) void *ctx = ralloc_parent(ir); this->progress = true; - return new(ctx) ir_swizzle(deref->array, - ir_constant->value.i[0], 0, 0, 0, 1); + + /* Page 40 of the GLSL 1.20 spec says: + * + * "When indexing with non-constant expressions, behavior is undefined + * if the index is negative, or greater than or equal to the size of + * the vector." + * + * The quoted spec text mentions non-constant expressions, but this code + * operates on constants. These constants are the result of non-constant + * expressions that have been optimized to constants. The common case here + * is a loop counter from an unrolled loop that is used to index a vector. + * + * The ir_swizzle constructor gets angry if the index is negative or too + * large. For simplicity sake, just clamp the index to [0, size-1]. + */ + const int i = MIN2(MAX2(ir_constant->value.i[0], 0), + (deref->array->type->vector_elements - 1)); + + return new(ctx) ir_swizzle(deref->array, i, 0, 0, 0, 1); } ir_visitor_status |