diff options
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r-- | mesalib/src/glsl/.gitignore | 8 | ||||
-rw-r--r-- | mesalib/src/glsl/glcpp/.gitignore | 9 | ||||
-rw-r--r-- | mesalib/src/glsl/glcpp/README | 62 | ||||
-rw-r--r-- | mesalib/src/glsl/glcpp/glcpp-parse.y | 3 | ||||
-rw-r--r-- | mesalib/src/glsl/glsl_parser_extras.cpp | 1 | ||||
-rw-r--r-- | mesalib/src/glsl/glsl_parser_extras.h | 2 | ||||
-rw-r--r-- | mesalib/src/glsl/ir.cpp | 8 | ||||
-rw-r--r-- | mesalib/src/glsl/ir.h | 26 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_constant_expression.cpp | 47 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_validate.cpp | 16 | ||||
-rw-r--r-- | mesalib/src/glsl/loop_analysis.h | 17 | ||||
-rw-r--r-- | mesalib/src/glsl/opt_noop_swizzle.cpp | 160 | ||||
-rw-r--r-- | mesalib/src/glsl/opt_redundant_jumps.cpp | 240 | ||||
-rw-r--r-- | mesalib/src/glsl/standalone_scaffolding.cpp | 1 | ||||
-rw-r--r-- | mesalib/src/glsl/strtod.h | 86 |
15 files changed, 401 insertions, 285 deletions
diff --git a/mesalib/src/glsl/.gitignore b/mesalib/src/glsl/.gitignore new file mode 100644 index 000000000..d26839a3e --- /dev/null +++ b/mesalib/src/glsl/.gitignore @@ -0,0 +1,8 @@ +glsl_compiler +glsl_lexer.cpp +glsl_parser.cpp +glsl_parser.h +glsl_parser.output +builtin_function.cpp +builtin_compiler +glsl_test diff --git a/mesalib/src/glsl/glcpp/.gitignore b/mesalib/src/glsl/glcpp/.gitignore new file mode 100644 index 000000000..41b34bb30 --- /dev/null +++ b/mesalib/src/glsl/glcpp/.gitignore @@ -0,0 +1,9 @@ +glcpp +glcpp-lex.c +glcpp-parse.output +glcpp-parse.c +glcpp-parse.h +*.o +*.lo +*~ +tests/*.out diff --git a/mesalib/src/glsl/glcpp/README b/mesalib/src/glsl/glcpp/README index 735b27d44..0b5ef508c 100644 --- a/mesalib/src/glsl/glcpp/README +++ b/mesalib/src/glsl/glcpp/README @@ -1,32 +1,32 @@ -glcpp -- GLSL "C" preprocessor
-
-This is a simple preprocessor designed to provide the preprocessing
-needs of the GLSL language. The requirements for this preprocessor are
-specified in the GLSL 1.30 specification availble from:
-
-http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.10.pdf
-
-This specification is not precise on some semantics, (for example,
-#define and #if), defining these merely "as is standard for C++
-preprocessors". To fill in these details, I've been using a draft of
-the C99 standard as available from:
-
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
-
-Any downstream compiler accepting output from glcpp should be prepared
-to encounter and deal with the following preprocessor macros:
-
- #line
- #pragma
- #extension
-
-All other macros will be handles according to the GLSL specification
-and will not appear in the output.
-
-Known limitations
------------------
-The __LINE__ and __FILE__ macros are not yet supported.
-
-A file that ends with a function-like macro name as the last
-non-whitespace token will result in a parse error, (where it should be
+glcpp -- GLSL "C" preprocessor + +This is a simple preprocessor designed to provide the preprocessing +needs of the GLSL language. The requirements for this preprocessor are +specified in the GLSL 1.30 specification availble from: + +http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.10.pdf + +This specification is not precise on some semantics, (for example, +#define and #if), defining these merely "as is standard for C++ +preprocessors". To fill in these details, I've been using a draft of +the C99 standard as available from: + +http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf + +Any downstream compiler accepting output from glcpp should be prepared +to encounter and deal with the following preprocessor macros: + + #line + #pragma + #extension + +All other macros will be handles according to the GLSL specification +and will not appear in the output. + +Known limitations +----------------- +The __LINE__ and __FILE__ macros are not yet supported. + +A file that ends with a function-like macro name as the last +non-whitespace token will result in a parse error, (where it should be passed through as is).
\ No newline at end of file diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y index 47ba54ddf..9e8f9b2d6 100644 --- a/mesalib/src/glsl/glcpp/glcpp-parse.y +++ b/mesalib/src/glsl/glcpp/glcpp-parse.y @@ -1141,6 +1141,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api) if (extensions->OES_EGL_image_external) add_builtin_define(parser, "GL_OES_EGL_image_external", 1); + + if (extensions->ARB_shader_bit_encoding) + add_builtin_define(parser, "GL_ARB_shader_bit_encoding", 1); } language_version = 110; diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp index 46f21dd07..02c398616 100644 --- a/mesalib/src/glsl/glsl_parser_extras.cpp +++ b/mesalib/src/glsl/glsl_parser_extras.cpp @@ -295,6 +295,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = { EXT(AMD_shader_stencil_export, false, false, true, true, false, ARB_shader_stencil_export), EXT(OES_texture_3D, true, false, true, false, true, EXT_texture3D), EXT(OES_EGL_image_external, true, false, true, false, true, OES_EGL_image_external), + EXT(ARB_shader_bit_encoding, true, true, true, true, false, ARB_shader_bit_encoding), }; #undef EXT diff --git a/mesalib/src/glsl/glsl_parser_extras.h b/mesalib/src/glsl/glsl_parser_extras.h index 1a909c68b..246fc8141 100644 --- a/mesalib/src/glsl/glsl_parser_extras.h +++ b/mesalib/src/glsl/glsl_parser_extras.h @@ -205,6 +205,8 @@ struct _mesa_glsl_parse_state { bool OES_texture_3D_warn; bool OES_EGL_image_external_enable; bool OES_EGL_image_external_warn; + bool ARB_shader_bit_encoding_enable; + bool ARB_shader_bit_encoding_warn; /*@}*/ /** Extensions supported by the OpenGL implementation. */ diff --git a/mesalib/src/glsl/ir.cpp b/mesalib/src/glsl/ir.cpp index 970d8f3ba..69954998b 100644 --- a/mesalib/src/glsl/ir.cpp +++ b/mesalib/src/glsl/ir.cpp @@ -273,6 +273,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) case ir_unop_f2i: case ir_unop_b2i: case ir_unop_u2i: + case ir_unop_bitcast_f2i: this->type = glsl_type::get_instance(GLSL_TYPE_INT, op0->type->vector_elements, 1); break; @@ -280,6 +281,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) case ir_unop_b2f: case ir_unop_i2f: case ir_unop_u2f: + case ir_unop_bitcast_i2f: + case ir_unop_bitcast_u2f: this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT, op0->type->vector_elements, 1); break; @@ -291,6 +294,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) break; case ir_unop_i2u: + case ir_unop_bitcast_f2u: this->type = glsl_type::get_instance(GLSL_TYPE_UINT, op0->type->vector_elements, 1); break; @@ -427,6 +431,10 @@ static const char *const operator_strs[] = { "u2f", "i2u", "u2i", + "bitcast_i2f", + "bitcast_f2i", + "bitcast_u2f", + "bitcast_f2u", "any", "trunc", "ceil", diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h index 9c7961ab9..2c4723627 100644 --- a/mesalib/src/glsl/ir.h +++ b/mesalib/src/glsl/ir.h @@ -864,19 +864,23 @@ enum ir_expression_operation { ir_unop_rcp, ir_unop_rsq, ir_unop_sqrt, - ir_unop_exp, /**< Log base e on gentype */ - ir_unop_log, /**< Natural log on gentype */ + ir_unop_exp, /**< Log base e on gentype */ + ir_unop_log, /**< Natural log on gentype */ ir_unop_exp2, ir_unop_log2, - ir_unop_f2i, /**< Float-to-integer conversion. */ - ir_unop_i2f, /**< Integer-to-float conversion. */ - ir_unop_f2b, /**< Float-to-boolean conversion */ - ir_unop_b2f, /**< Boolean-to-float conversion */ - ir_unop_i2b, /**< int-to-boolean conversion */ - ir_unop_b2i, /**< Boolean-to-int conversion */ - ir_unop_u2f, /**< Unsigned-to-float conversion. */ - ir_unop_i2u, /**< Integer-to-unsigned conversion. */ - ir_unop_u2i, /**< Unsigned-to-integer conversion. */ + ir_unop_f2i, /**< Float-to-integer conversion. */ + ir_unop_i2f, /**< Integer-to-float conversion. */ + ir_unop_f2b, /**< Float-to-boolean conversion */ + ir_unop_b2f, /**< Boolean-to-float conversion */ + ir_unop_i2b, /**< int-to-boolean conversion */ + ir_unop_b2i, /**< Boolean-to-int conversion */ + ir_unop_u2f, /**< Unsigned-to-float conversion. */ + ir_unop_i2u, /**< Integer-to-unsigned conversion. */ + ir_unop_u2i, /**< Unsigned-to-integer conversion. */ + ir_unop_bitcast_i2f, /**< Bit-identical int-to-float "conversion" */ + ir_unop_bitcast_f2i, /**< Bit-identical float-to-int "conversion" */ + ir_unop_bitcast_u2f, /**< Bit-identical uint-to-float "conversion" */ + ir_unop_bitcast_f2u, /**< Bit-identical float-to-uint "conversion" */ ir_unop_any, /** diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp index 08a33285b..7a4d15f43 100644 --- a/mesalib/src/glsl/ir_constant_expression.cpp +++ b/mesalib/src/glsl/ir_constant_expression.cpp @@ -71,6 +71,29 @@ dot(ir_constant *op0, ir_constant *op1) return result; } +/* This method is the only one supported by gcc. Unions in particular + * are iffy, and read-through-converted-pointer is killed by strict + * aliasing. OTOH, the compiler sees through the memcpy, so the + * resulting asm is reasonable. + */ +static float +bitcast_u2f(unsigned int u) +{ + assert(sizeof(float) == sizeof(unsigned int)); + float f; + memcpy(&f, &u, sizeof(f)); + return f; +} + +static unsigned int +bitcast_f2u(float f) +{ + assert(sizeof(float) == sizeof(unsigned int)); + unsigned int u; + memcpy(&u, &f, sizeof(f)); + return u; +} + ir_constant * ir_rvalue::constant_expression_value(struct hash_table *variable_context) { @@ -207,6 +230,30 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) data.u[c] = op[0]->value.i[c]; } break; + case ir_unop_bitcast_i2f: + assert(op[0]->type->base_type == GLSL_TYPE_INT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = bitcast_u2f(op[0]->value.i[c]); + } + break; + case ir_unop_bitcast_f2i: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i[c] = bitcast_f2u(op[0]->value.f[c]); + } + break; + case ir_unop_bitcast_u2f: + assert(op[0]->type->base_type == GLSL_TYPE_UINT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = bitcast_u2f(op[0]->value.u[c]); + } + break; + case ir_unop_bitcast_f2u: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u[c] = bitcast_f2u(op[0]->value.f[c]); + } + break; case ir_unop_any: assert(op[0]->type->is_boolean()); data.b[0] = false; diff --git a/mesalib/src/glsl/ir_validate.cpp b/mesalib/src/glsl/ir_validate.cpp index 7efb43477..5721717a5 100644 --- a/mesalib/src/glsl/ir_validate.cpp +++ b/mesalib/src/glsl/ir_validate.cpp @@ -288,6 +288,22 @@ ir_validate::visit_leave(ir_expression *ir) assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); assert(ir->type->base_type == GLSL_TYPE_INT); break; + case ir_unop_bitcast_i2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + case ir_unop_bitcast_f2i: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_INT); + break; + case ir_unop_bitcast_u2f: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); + assert(ir->type->base_type == GLSL_TYPE_FLOAT); + break; + case ir_unop_bitcast_f2u: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); + assert(ir->type->base_type == GLSL_TYPE_UINT); + break; case ir_unop_any: assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); diff --git a/mesalib/src/glsl/loop_analysis.h b/mesalib/src/glsl/loop_analysis.h index 8bed1db02..05c982fc1 100644 --- a/mesalib/src/glsl/loop_analysis.h +++ b/mesalib/src/glsl/loop_analysis.h @@ -140,6 +140,23 @@ public: { hash_table_dtor(this->var_hash); } + + static void* operator new(size_t size, void *ctx) + { + void *lvs = ralloc_size(ctx, size); + assert(lvs != NULL); + + ralloc_set_destructor(lvs, (void (*)(void*)) destructor); + + return lvs; + } + +private: + static void + destructor(loop_variable_state *lvs) + { + lvs->~loop_variable_state(); + } }; diff --git a/mesalib/src/glsl/opt_noop_swizzle.cpp b/mesalib/src/glsl/opt_noop_swizzle.cpp index c034d7339..0a906aaf1 100644 --- a/mesalib/src/glsl/opt_noop_swizzle.cpp +++ b/mesalib/src/glsl/opt_noop_swizzle.cpp @@ -1,80 +1,80 @@ -/*
- * 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_noop_swizzle.cpp
- *
- * If a swizzle doesn't change the order or count of components, then
- * remove the swizzle so that other optimization passes see the value
- * behind it.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_rvalue_visitor.h"
-#include "ir_print_visitor.h"
-#include "glsl_types.h"
-
-class ir_noop_swizzle_visitor : public ir_rvalue_visitor {
-public:
- ir_noop_swizzle_visitor()
- {
- this->progress = false;
- }
-
- void handle_rvalue(ir_rvalue **rvalue);
- bool progress;
-};
-
-void
-ir_noop_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue)
-{
- if (!*rvalue)
- return;
-
- ir_swizzle *swiz = (*rvalue)->as_swizzle();
- if (!swiz || swiz->type != swiz->val->type)
- return;
-
- int elems = swiz->val->type->vector_elements;
- if (swiz->mask.x != 0)
- return;
- if (elems >= 2 && swiz->mask.y != 1)
- return;
- if (elems >= 3 && swiz->mask.z != 2)
- return;
- if (elems >= 4 && swiz->mask.w != 3)
- return;
-
- this->progress = true;
- *rvalue = swiz->val;
-}
-
-bool
-do_noop_swizzle(exec_list *instructions)
-{
- ir_noop_swizzle_visitor v;
- visit_list_elements(&v, instructions);
-
- return v.progress;
-}
+/* + * 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_noop_swizzle.cpp + * + * If a swizzle doesn't change the order or count of components, then + * remove the swizzle so that other optimization passes see the value + * behind it. + */ + +#include "ir.h" +#include "ir_visitor.h" +#include "ir_rvalue_visitor.h" +#include "ir_print_visitor.h" +#include "glsl_types.h" + +class ir_noop_swizzle_visitor : public ir_rvalue_visitor { +public: + ir_noop_swizzle_visitor() + { + this->progress = false; + } + + void handle_rvalue(ir_rvalue **rvalue); + bool progress; +}; + +void +ir_noop_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue) +{ + if (!*rvalue) + return; + + ir_swizzle *swiz = (*rvalue)->as_swizzle(); + if (!swiz || swiz->type != swiz->val->type) + return; + + int elems = swiz->val->type->vector_elements; + if (swiz->mask.x != 0) + return; + if (elems >= 2 && swiz->mask.y != 1) + return; + if (elems >= 3 && swiz->mask.z != 2) + return; + if (elems >= 4 && swiz->mask.w != 3) + return; + + this->progress = true; + *rvalue = swiz->val; +} + +bool +do_noop_swizzle(exec_list *instructions) +{ + ir_noop_swizzle_visitor v; + visit_list_elements(&v, instructions); + + return v.progress; +} diff --git a/mesalib/src/glsl/opt_redundant_jumps.cpp b/mesalib/src/glsl/opt_redundant_jumps.cpp index eb60519e2..f350fa947 100644 --- a/mesalib/src/glsl/opt_redundant_jumps.cpp +++ b/mesalib/src/glsl/opt_redundant_jumps.cpp @@ -1,120 +1,120 @@ -/*
- * 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_redundant_jumps.cpp
- * Remove certain types of redundant jumps
- */
-
-#include "ir.h"
-
-class redundant_jumps_visitor : public ir_hierarchical_visitor {
-public:
- redundant_jumps_visitor()
- {
- this->progress = false;
- }
-
- virtual ir_visitor_status visit_leave(ir_if *);
- virtual ir_visitor_status visit_leave(ir_loop *);
- virtual ir_visitor_status visit_enter(ir_assignment *);
-
- bool progress;
-};
-
-/* We only care about the top level instructions, so don't descend
- * into expressions.
- */
-ir_visitor_status
-redundant_jumps_visitor::visit_enter(ir_assignment *ir)
-{
- return visit_continue_with_parent;
-}
-
-ir_visitor_status
-redundant_jumps_visitor::visit_leave(ir_if *ir)
-{
- /* If the last instruction in both branches is a 'break' or a 'continue',
- * pull it out of the branches and insert it after the if-statment. Note
- * that both must be the same type (either 'break' or 'continue').
- */
- ir_instruction *const last_then =
- (ir_instruction *) ir->then_instructions.get_tail();
- ir_instruction *const last_else =
- (ir_instruction *) ir->else_instructions.get_tail();
-
- if ((last_then == NULL) || (last_else == NULL))
- return visit_continue;
-
- if ((last_then->ir_type != ir_type_loop_jump)
- || (last_else->ir_type != ir_type_loop_jump))
- return visit_continue;
-
- ir_loop_jump *const then_jump = (ir_loop_jump *) last_then;
- ir_loop_jump *const else_jump = (ir_loop_jump *) last_else;
-
- if (then_jump->mode != else_jump->mode)
- return visit_continue;
-
- then_jump->remove();
- else_jump->remove();
- this->progress = true;
-
- ir->insert_after(then_jump);
-
- /* If both branchs of the if-statement are now empty, remove the
- * if-statement.
- */
- if (ir->then_instructions.is_empty() && ir->else_instructions.is_empty())
- ir->remove();
-
- return visit_continue;
-}
-
-
-ir_visitor_status
-redundant_jumps_visitor::visit_leave(ir_loop *ir)
-{
- /* If the last instruction of a loop body is a 'continue', remove it.
- */
- ir_instruction *const last =
- (ir_instruction *) ir->body_instructions.get_tail();
-
- if (last && (last->ir_type == ir_type_loop_jump)
- && (((ir_loop_jump *) last)->mode == ir_loop_jump::jump_continue)) {
- last->remove();
- this->progress = true;
- }
-
- return visit_continue;
-}
-
-
-bool
-optimize_redundant_jumps(exec_list *instructions)
-{
- redundant_jumps_visitor v;
-
- v.run(instructions);
- return v.progress;
-}
+/* + * 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_redundant_jumps.cpp + * Remove certain types of redundant jumps + */ + +#include "ir.h" + +class redundant_jumps_visitor : public ir_hierarchical_visitor { +public: + redundant_jumps_visitor() + { + this->progress = false; + } + + virtual ir_visitor_status visit_leave(ir_if *); + virtual ir_visitor_status visit_leave(ir_loop *); + virtual ir_visitor_status visit_enter(ir_assignment *); + + bool progress; +}; + +/* We only care about the top level instructions, so don't descend + * into expressions. + */ +ir_visitor_status +redundant_jumps_visitor::visit_enter(ir_assignment *ir) +{ + return visit_continue_with_parent; +} + +ir_visitor_status +redundant_jumps_visitor::visit_leave(ir_if *ir) +{ + /* If the last instruction in both branches is a 'break' or a 'continue', + * pull it out of the branches and insert it after the if-statment. Note + * that both must be the same type (either 'break' or 'continue'). + */ + ir_instruction *const last_then = + (ir_instruction *) ir->then_instructions.get_tail(); + ir_instruction *const last_else = + (ir_instruction *) ir->else_instructions.get_tail(); + + if ((last_then == NULL) || (last_else == NULL)) + return visit_continue; + + if ((last_then->ir_type != ir_type_loop_jump) + || (last_else->ir_type != ir_type_loop_jump)) + return visit_continue; + + ir_loop_jump *const then_jump = (ir_loop_jump *) last_then; + ir_loop_jump *const else_jump = (ir_loop_jump *) last_else; + + if (then_jump->mode != else_jump->mode) + return visit_continue; + + then_jump->remove(); + else_jump->remove(); + this->progress = true; + + ir->insert_after(then_jump); + + /* If both branchs of the if-statement are now empty, remove the + * if-statement. + */ + if (ir->then_instructions.is_empty() && ir->else_instructions.is_empty()) + ir->remove(); + + return visit_continue; +} + + +ir_visitor_status +redundant_jumps_visitor::visit_leave(ir_loop *ir) +{ + /* If the last instruction of a loop body is a 'continue', remove it. + */ + ir_instruction *const last = + (ir_instruction *) ir->body_instructions.get_tail(); + + if (last && (last->ir_type == ir_type_loop_jump) + && (((ir_loop_jump *) last)->mode == ir_loop_jump::jump_continue)) { + last->remove(); + this->progress = true; + } + + return visit_continue; +} + + +bool +optimize_redundant_jumps(exec_list *instructions) +{ + redundant_jumps_visitor v; + + v.run(instructions); + return v.progress; +} diff --git a/mesalib/src/glsl/standalone_scaffolding.cpp b/mesalib/src/glsl/standalone_scaffolding.cpp index f15f2d882..679714e38 100644 --- a/mesalib/src/glsl/standalone_scaffolding.cpp +++ b/mesalib/src/glsl/standalone_scaffolding.cpp @@ -79,6 +79,7 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api) ctx->Extensions.NV_texture_rectangle = true; ctx->Extensions.EXT_texture3D = true; ctx->Extensions.OES_EGL_image_external = true; + ctx->Extensions.ARB_shader_bit_encoding = true; ctx->Const.GLSLVersion = 120; diff --git a/mesalib/src/glsl/strtod.h b/mesalib/src/glsl/strtod.h index c9ff0a87f..0cf6409d4 100644 --- a/mesalib/src/glsl/strtod.h +++ b/mesalib/src/glsl/strtod.h @@ -1,43 +1,43 @@ -/*
- * Copyright 2010 VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
- */
-
-
-#ifndef STRTOD_H
-#define STRTOD_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern double
-glsl_strtod(const char *s, char **end);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif
+/* + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * 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, sub license, 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 NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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. + */ + + +#ifndef STRTOD_H +#define STRTOD_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern double +glsl_strtod(const char *s, char **end); + + +#ifdef __cplusplus +} +#endif + + +#endif |