2010-05-05 10:37:25 -07:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-07-26 22:50:29 -07:00
|
|
|
* \file ir_optimization.h
|
2010-05-05 10:37:25 -07:00
|
|
|
*
|
|
|
|
|
* Prototypes for optimization passes to be called by the compiler and drivers.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-03-20 16:04:08 +00:00
|
|
|
#ifndef GLSL_IR_OPTIMIZATION_H
|
|
|
|
|
#define GLSL_IR_OPTIMIZATION_H
|
|
|
|
|
|
2018-04-08 13:13:08 -04:00
|
|
|
struct gl_linked_shader;
|
|
|
|
|
struct gl_shader_program;
|
|
|
|
|
|
2021-12-17 13:33:08 -08:00
|
|
|
/* Operations for lower_64bit_integer_instructions() */
|
|
|
|
|
#define DIV64 (1U << 0)
|
|
|
|
|
#define MOD64 (1U << 1)
|
2016-10-14 18:17:16 -07:00
|
|
|
|
2011-10-21 11:17:39 -07:00
|
|
|
bool do_common_optimization(exec_list *ir, bool linked,
|
2014-04-06 23:25:00 -07:00
|
|
|
const struct gl_shader_compiler_options *options,
|
|
|
|
|
bool native_integers);
|
2010-08-10 13:06:49 -07:00
|
|
|
|
2014-02-28 20:11:32 -08:00
|
|
|
bool do_rebalance_tree(exec_list *instructions);
|
2014-02-28 17:49:20 -08:00
|
|
|
bool do_algebraic(exec_list *instructions, bool native_integers,
|
|
|
|
|
const struct gl_shader_compiler_options *options);
|
2022-06-08 14:34:24 +10:00
|
|
|
bool do_dead_code(exec_list *instructions);
|
2010-05-05 10:37:25 -07:00
|
|
|
bool do_dead_code_local(exec_list *instructions);
|
2010-07-27 11:28:26 -07:00
|
|
|
bool do_dead_code_unlinked(exec_list *instructions);
|
2010-08-05 10:09:12 -07:00
|
|
|
bool do_dead_functions(exec_list *instructions);
|
2013-04-17 17:30:25 -07:00
|
|
|
bool opt_flip_matrices(exec_list *instructions);
|
2010-05-05 11:45:30 -07:00
|
|
|
bool do_function_inlining(exec_list *instructions);
|
2022-04-11 22:15:46 -07:00
|
|
|
bool do_lower_jumps(exec_list *instructions, bool pull_out_jumps = true, bool lower_sub_return = true, bool lower_main_return = false, bool lower_continue = false);
|
2010-05-05 11:45:30 -07:00
|
|
|
bool do_if_simplification(exec_list *instructions);
|
2013-04-03 23:56:57 -07:00
|
|
|
bool opt_flatten_nested_if_blocks(exec_list *instructions);
|
2010-07-12 11:04:07 -07:00
|
|
|
bool do_mat_op_to_vec(exec_list *instructions);
|
glsl: Optimize min/max expression trees
Original patch by Petri Latvala <petri.latvala@intel.com>:
Add an optimization pass that drops min/max expression operands that
can be proven to not contribute to the final result. The algorithm is
similar to alpha-beta pruning on a minmax search, from the field of
AI.
This optimization pass can optimize min/max expressions where operands
are min/max expressions. Such code can appear in shaders by itself, or
as the result of clamp() or AMD_shader_trinary_minmax functions.
This optimization pass improves the generated code for piglit's
AMD_shader_trinary_minmax tests as follows:
total instructions in shared programs: 75 -> 67 (-10.67%)
instructions in affected programs: 60 -> 52 (-13.33%)
GAINED: 0
LOST: 0
All tests (max3, min3, mid3) improved.
A full shader-db run:
total instructions in shared programs: 4293603 -> 4293575 (-0.00%)
instructions in affected programs: 1188 -> 1160 (-2.36%)
GAINED: 0
LOST: 0
Improvements happen in Guacamelee and Serious Sam 3. One shader from
Dungeon Defenders is hurt by shader-db metrics (26 -> 28), because of
dropping of a (constant float (0.00000)) operand, which was
compiled to a saturate modifier.
Version 2 by Iago Toral Quiroga <itoral@igalia.com>:
Changes from review feedback:
- Squashed various cosmetic changes sent by Matt Turner.
- Make less_all_components return an enum rather than setting a class member.
(Suggested by Mat Turner). Also, renamed it to compare_components.
- Make less_all_components, smaller_constant and larger_constant static.
(Suggested by Mat Turner)
- Change mixmax_range to call its limits "low" and "high" instead of
"range[0]" and "range[1]". (Suggested by Connor Abbot).
- Use ir_builder swizzle helpers in swizzle_if_required(). (Suggested by
Connor Abbot).
- Make the logic more clearer by rearrenging the code and commenting.
(Suggested by Connor Abbot).
- Added comment to explain why we need to recurse twice. (Suggested by
Connor Abbot).
- If we cannot prune an expression, do not return early. Instead, attempt
to prune its children. (Suggested by Connor Abbot).
Other changes:
- Instead of having a global "valid" visitor member, let the various functions
that can determine this status return a boolean and check for its value
to decide what to do in each case. This is more flexible and allows to
recurse into children of parents that could not be prunned due to invalid
ranges (so related to the last bullet in the review feedback).
- Make sure we always check if a range is valid before working with it. Since
any use of get_range, combine_range or range_intersection can invalidate
a range we should check for this situation every time we use any of these
functions.
Version 3 by Iago Toral Quiroga <itoral@igalia.com>:
Changes from review feedback:
- Now we can make get_range, combine_range and range_intersection static too
(suggested by Connor Abbot).
- Do not return NULL when looking for the larger or greater constant into
mixed vector constants. Instead, produce a new constant by doing a
component-wise minmax. With this we can also remove of the validations when
we call into these functions (suggested by Connor Abbot).
- Add a comment explaining the meaning of the baserange argument in
prune_expression (suggested by Connor Abbot).
Other changes:
- Eliminate minmax expressions operating on constant vectors with mixed values
by resolving them.
No piglit regressions observed with Version 3.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76861
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
2014-07-29 12:36:31 +03:00
|
|
|
bool do_minmax_prune(exec_list *instructions);
|
2010-07-30 17:04:49 -07:00
|
|
|
bool do_tree_grafting(exec_list *instructions);
|
2022-05-10 11:56:35 -07:00
|
|
|
bool do_vec_index_to_cond_assign(exec_list *instructions);
|
2010-11-25 01:09:26 -08:00
|
|
|
bool lower_discard(exec_list *instructions);
|
2012-05-15 12:27:15 +01:00
|
|
|
void lower_discard_flow(exec_list *instructions);
|
2022-10-17 21:49:44 +11:00
|
|
|
bool lower_instructions(exec_list *instructions, bool have_ldexp,
|
|
|
|
|
bool have_dfrexp, bool have_dround,
|
|
|
|
|
bool force_abs_sqrt, bool have_gpu_shader5);
|
2016-06-30 14:55:40 +10:00
|
|
|
bool lower_clip_cull_distance(struct gl_shader_program *prog,
|
|
|
|
|
gl_linked_shader *shader);
|
2022-10-17 15:28:26 +11:00
|
|
|
bool lower_packing_builtins(exec_list *instructions,
|
|
|
|
|
bool has_shading_language_packing,
|
|
|
|
|
bool has_gpu_shader5,
|
|
|
|
|
bool has_half_float_packing);
|
2016-06-30 14:55:40 +10:00
|
|
|
bool lower_vector_derefs(gl_linked_shader *shader);
|
|
|
|
|
void lower_named_interface_blocks(void *mem_ctx, gl_linked_shader *shader);
|
glsl: Eliminate unused built-in variables after compilation
After compilation (and before linking) we can eliminate quite a few
built-in variables. Basically, any uniform or constant (e.g.,
gl_MaxVertexTextureImageUnits) that isn't used (with one exception) can
be eliminated. System values, vertex shader inputs (with one
exception), and fragment shader outputs that are not used and not
re-declared in the shader text can also be removed.
gl_ModelViewProjectMatrix and gl_Vertex are used by the built-in
function ftransform. There are some complications with eliminating
these variables (see the comment in the patch), so they are not
eliminated.
Valgrind massif results for a trimmed apitrace of dota2:
n time(i) total(B) useful-heap(B) extra-heap(B) stacks(B)
Before (32-bit): 46 40,661,487,174 75,116,800 68,854,065 6,262,735 0
After (32-bit): 50 40,564,927,443 69,185,408 63,683,871 5,501,537 0
Before (64-bit): 64 37,200,329,700 104,872,672 96,514,546 8,358,126 0
After (64-bit): 59 36,822,048,449 96,526,888 89,113,000 7,413,888 0
A real savings of 4.9MiB on 32-bit and 7.0MiB on 64-bit.
v2: Don't remove any built-in with Transpose in the name.
v3: Fix comment typo noticed by Anuj.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Suggested-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Acked-by: Anuj Phogat <anuj.phogat@gmail.com>
Cc: Eric Anholt <eric@anholt.net>
2014-05-28 17:09:45 -07:00
|
|
|
void optimize_dead_builtin_variables(exec_list *instructions,
|
|
|
|
|
enum ir_variable_mode other);
|
2011-07-18 18:48:39 -07:00
|
|
|
|
2018-02-14 11:53:49 -08:00
|
|
|
bool lower_blend_equation_advanced(gl_linked_shader *shader, bool coherent);
|
2014-06-19 12:06:42 -07:00
|
|
|
|
2019-10-15 16:20:26 +02:00
|
|
|
bool lower_builtins(exec_list *instructions);
|
2015-04-23 13:34:14 +10:00
|
|
|
bool lower_subroutine(exec_list *instructions, struct _mesa_glsl_parse_state *state);
|
2021-04-16 13:50:41 -04:00
|
|
|
bool propagate_invariance(exec_list *instructions);
|
2015-04-23 13:34:14 +10:00
|
|
|
|
2017-09-18 15:04:03 -05:00
|
|
|
namespace ir_builder { class ir_factory; };
|
|
|
|
|
|
2016-10-14 18:17:16 -07:00
|
|
|
bool lower_64bit_integer_instructions(exec_list *instructions,
|
|
|
|
|
unsigned what_to_lower);
|
2017-03-20 16:04:08 +00:00
|
|
|
|
2020-06-24 03:26:31 -04:00
|
|
|
void lower_precision(const struct gl_shader_compiler_options *options,
|
2020-05-08 22:42:43 -04:00
|
|
|
exec_list *instructions);
|
2019-04-19 15:36:58 +02:00
|
|
|
|
2017-03-20 16:04:08 +00:00
|
|
|
#endif /* GLSL_IR_OPTIMIZATION_H */
|