glsl: Combine nop-swizzle optimization with swizzle-swizzle optimization
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: <thomashelland90@gmail.com>
This commit is contained in:
@@ -130,11 +130,10 @@ LIBGLSL_FILES = \
|
|||||||
glsl/opt_function_inlining.cpp \
|
glsl/opt_function_inlining.cpp \
|
||||||
glsl/opt_if_simplification.cpp \
|
glsl/opt_if_simplification.cpp \
|
||||||
glsl/opt_minmax.cpp \
|
glsl/opt_minmax.cpp \
|
||||||
glsl/opt_noop_swizzle.cpp \
|
|
||||||
glsl/opt_rebalance_tree.cpp \
|
glsl/opt_rebalance_tree.cpp \
|
||||||
glsl/opt_redundant_jumps.cpp \
|
glsl/opt_redundant_jumps.cpp \
|
||||||
glsl/opt_structure_splitting.cpp \
|
glsl/opt_structure_splitting.cpp \
|
||||||
glsl/opt_swizzle_swizzle.cpp \
|
glsl/opt_swizzle.cpp \
|
||||||
glsl/opt_tree_grafting.cpp \
|
glsl/opt_tree_grafting.cpp \
|
||||||
glsl/opt_vectorize.cpp \
|
glsl/opt_vectorize.cpp \
|
||||||
glsl/program.h \
|
glsl/program.h \
|
||||||
|
@@ -2226,8 +2226,7 @@ do_common_optimization(exec_list *ir, bool linked,
|
|||||||
options->EmitNoCont, options->EmitNoLoops);
|
options->EmitNoCont, options->EmitNoLoops);
|
||||||
OPT(do_vec_index_to_swizzle, ir);
|
OPT(do_vec_index_to_swizzle, ir);
|
||||||
OPT(lower_vector_insert, ir, false);
|
OPT(lower_vector_insert, ir, false);
|
||||||
OPT(do_swizzle_swizzle, ir);
|
OPT(optimize_swizzles, ir);
|
||||||
OPT(do_noop_swizzle, ir);
|
|
||||||
|
|
||||||
OPT(optimize_split_arrays, ir, linked);
|
OPT(optimize_split_arrays, ir, linked);
|
||||||
OPT(optimize_redundant_jumps, ir);
|
OPT(optimize_redundant_jumps, ir);
|
||||||
|
@@ -123,9 +123,8 @@ bool lower_if_to_cond_assign(gl_shader_stage stage, exec_list *instructions,
|
|||||||
unsigned max_depth = 0, unsigned min_branch_cost = 0);
|
unsigned max_depth = 0, unsigned min_branch_cost = 0);
|
||||||
bool do_mat_op_to_vec(exec_list *instructions);
|
bool do_mat_op_to_vec(exec_list *instructions);
|
||||||
bool do_minmax_prune(exec_list *instructions);
|
bool do_minmax_prune(exec_list *instructions);
|
||||||
bool do_noop_swizzle(exec_list *instructions);
|
|
||||||
bool do_structure_splitting(exec_list *instructions);
|
bool do_structure_splitting(exec_list *instructions);
|
||||||
bool do_swizzle_swizzle(exec_list *instructions);
|
bool optimize_swizzles(exec_list *instructions);
|
||||||
bool do_vectorize(exec_list *instructions);
|
bool do_vectorize(exec_list *instructions);
|
||||||
bool do_tree_grafting(exec_list *instructions);
|
bool do_tree_grafting(exec_list *instructions);
|
||||||
bool do_vec_index_to_cond_assign(exec_list *instructions);
|
bool do_vec_index_to_cond_assign(exec_list *instructions);
|
||||||
|
@@ -169,11 +169,10 @@ files_libglsl = files(
|
|||||||
'opt_function_inlining.cpp',
|
'opt_function_inlining.cpp',
|
||||||
'opt_if_simplification.cpp',
|
'opt_if_simplification.cpp',
|
||||||
'opt_minmax.cpp',
|
'opt_minmax.cpp',
|
||||||
'opt_noop_swizzle.cpp',
|
|
||||||
'opt_rebalance_tree.cpp',
|
'opt_rebalance_tree.cpp',
|
||||||
'opt_redundant_jumps.cpp',
|
'opt_redundant_jumps.cpp',
|
||||||
'opt_structure_splitting.cpp',
|
'opt_structure_splitting.cpp',
|
||||||
'opt_swizzle_swizzle.cpp',
|
'opt_swizzle.cpp',
|
||||||
'opt_tree_grafting.cpp',
|
'opt_tree_grafting.cpp',
|
||||||
'opt_vectorize.cpp',
|
'opt_vectorize.cpp',
|
||||||
'program.h',
|
'program.h',
|
||||||
|
@@ -22,11 +22,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file opt_noop_swizzle.cpp
|
* \file opt_swizzle.cpp
|
||||||
|
* Optimize swizzle operations.
|
||||||
*
|
*
|
||||||
* If a swizzle doesn't change the order or count of components, then
|
* First, compact a sequence of swizzled swizzles into a single swizzle.
|
||||||
* remove the swizzle so that other optimization passes see the value
|
*
|
||||||
* behind it.
|
* If the final resulting 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.h"
|
||||||
@@ -36,9 +39,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class ir_noop_swizzle_visitor : public ir_rvalue_visitor {
|
class ir_opt_swizzle_visitor : public ir_rvalue_visitor {
|
||||||
public:
|
public:
|
||||||
ir_noop_swizzle_visitor()
|
ir_opt_swizzle_visitor()
|
||||||
{
|
{
|
||||||
this->progress = false;
|
this->progress = false;
|
||||||
}
|
}
|
||||||
@@ -50,13 +53,46 @@ public:
|
|||||||
} /* unnamed namespace */
|
} /* unnamed namespace */
|
||||||
|
|
||||||
void
|
void
|
||||||
ir_noop_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue)
|
ir_opt_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue)
|
||||||
{
|
{
|
||||||
if (!*rvalue)
|
if (!*rvalue)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ir_swizzle *swiz = (*rvalue)->as_swizzle();
|
ir_swizzle *swiz = (*rvalue)->as_swizzle();
|
||||||
if (!swiz || swiz->type != swiz->val->type)
|
|
||||||
|
if (!swiz)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ir_swizzle *swiz2;
|
||||||
|
|
||||||
|
while ((swiz2 = swiz->val->as_swizzle()) != NULL) {
|
||||||
|
int mask2[4];
|
||||||
|
|
||||||
|
memset(&mask2, 0, sizeof(mask2));
|
||||||
|
if (swiz2->mask.num_components >= 1)
|
||||||
|
mask2[0] = swiz2->mask.x;
|
||||||
|
if (swiz2->mask.num_components >= 2)
|
||||||
|
mask2[1] = swiz2->mask.y;
|
||||||
|
if (swiz2->mask.num_components >= 3)
|
||||||
|
mask2[2] = swiz2->mask.z;
|
||||||
|
if (swiz2->mask.num_components >= 4)
|
||||||
|
mask2[3] = swiz2->mask.w;
|
||||||
|
|
||||||
|
if (swiz->mask.num_components >= 1)
|
||||||
|
swiz->mask.x = mask2[swiz->mask.x];
|
||||||
|
if (swiz->mask.num_components >= 2)
|
||||||
|
swiz->mask.y = mask2[swiz->mask.y];
|
||||||
|
if (swiz->mask.num_components >= 3)
|
||||||
|
swiz->mask.z = mask2[swiz->mask.z];
|
||||||
|
if (swiz->mask.num_components >= 4)
|
||||||
|
swiz->mask.w = mask2[swiz->mask.w];
|
||||||
|
|
||||||
|
swiz->val = swiz2->val;
|
||||||
|
|
||||||
|
this->progress = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (swiz->type != swiz->val->type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int elems = swiz->val->type->vector_elements;
|
int elems = swiz->val->type->vector_elements;
|
||||||
@@ -74,9 +110,9 @@ ir_noop_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
do_noop_swizzle(exec_list *instructions)
|
optimize_swizzles(exec_list *instructions)
|
||||||
{
|
{
|
||||||
ir_noop_swizzle_visitor v;
|
ir_opt_swizzle_visitor v;
|
||||||
visit_list_elements(&v, instructions);
|
visit_list_elements(&v, instructions);
|
||||||
|
|
||||||
return v.progress;
|
return v.progress;
|
@@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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_swizzle_swizzle.cpp
|
|
||||||
* Compact a sequence of swizzled swizzles into a single swizzle.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ir.h"
|
|
||||||
#include "ir_visitor.h"
|
|
||||||
#include "ir_optimization.h"
|
|
||||||
#include "compiler/glsl_types.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
class ir_swizzle_swizzle_visitor : public ir_hierarchical_visitor {
|
|
||||||
public:
|
|
||||||
ir_swizzle_swizzle_visitor()
|
|
||||||
{
|
|
||||||
progress = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ir_visitor_status visit_enter(ir_swizzle *);
|
|
||||||
|
|
||||||
bool progress;
|
|
||||||
};
|
|
||||||
|
|
||||||
} /* unnamed namespace */
|
|
||||||
|
|
||||||
ir_visitor_status
|
|
||||||
ir_swizzle_swizzle_visitor::visit_enter(ir_swizzle *ir)
|
|
||||||
{
|
|
||||||
ir_swizzle *swiz2;
|
|
||||||
|
|
||||||
while ((swiz2 = ir->val->as_swizzle()) != NULL) {
|
|
||||||
int mask2[4];
|
|
||||||
|
|
||||||
memset(&mask2, 0, sizeof(mask2));
|
|
||||||
if (swiz2->mask.num_components >= 1)
|
|
||||||
mask2[0] = swiz2->mask.x;
|
|
||||||
if (swiz2->mask.num_components >= 2)
|
|
||||||
mask2[1] = swiz2->mask.y;
|
|
||||||
if (swiz2->mask.num_components >= 3)
|
|
||||||
mask2[2] = swiz2->mask.z;
|
|
||||||
if (swiz2->mask.num_components >= 4)
|
|
||||||
mask2[3] = swiz2->mask.w;
|
|
||||||
|
|
||||||
if (ir->mask.num_components >= 1)
|
|
||||||
ir->mask.x = mask2[ir->mask.x];
|
|
||||||
if (ir->mask.num_components >= 2)
|
|
||||||
ir->mask.y = mask2[ir->mask.y];
|
|
||||||
if (ir->mask.num_components >= 3)
|
|
||||||
ir->mask.z = mask2[ir->mask.z];
|
|
||||||
if (ir->mask.num_components >= 4)
|
|
||||||
ir->mask.w = mask2[ir->mask.w];
|
|
||||||
|
|
||||||
ir->val = swiz2->val;
|
|
||||||
|
|
||||||
this->progress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return visit_continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does a copy propagation pass on the code present in the instruction stream.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
do_swizzle_swizzle(exec_list *instructions)
|
|
||||||
{
|
|
||||||
ir_swizzle_swizzle_visitor v;
|
|
||||||
|
|
||||||
v.run(instructions);
|
|
||||||
|
|
||||||
return v.progress;
|
|
||||||
}
|
|
@@ -102,12 +102,10 @@ do_optimization(struct exec_list *ir, const char *optimization,
|
|||||||
return lower_if_to_cond_assign(MESA_SHADER_VERTEX, ir, int_0);
|
return lower_if_to_cond_assign(MESA_SHADER_VERTEX, ir, int_0);
|
||||||
} else if (strcmp(optimization, "do_mat_op_to_vec") == 0) {
|
} else if (strcmp(optimization, "do_mat_op_to_vec") == 0) {
|
||||||
return do_mat_op_to_vec(ir);
|
return do_mat_op_to_vec(ir);
|
||||||
} else if (strcmp(optimization, "do_noop_swizzle") == 0) {
|
} else if (strcmp(optimization, "optimize_swizzles") == 0) {
|
||||||
return do_noop_swizzle(ir);
|
return optimize_swizzles(ir);
|
||||||
} else if (strcmp(optimization, "do_structure_splitting") == 0) {
|
} else if (strcmp(optimization, "do_structure_splitting") == 0) {
|
||||||
return do_structure_splitting(ir);
|
return do_structure_splitting(ir);
|
||||||
} else if (strcmp(optimization, "do_swizzle_swizzle") == 0) {
|
|
||||||
return do_swizzle_swizzle(ir);
|
|
||||||
} else if (strcmp(optimization, "do_tree_grafting") == 0) {
|
} else if (strcmp(optimization, "do_tree_grafting") == 0) {
|
||||||
return do_tree_grafting(ir);
|
return do_tree_grafting(ir);
|
||||||
} else if (strcmp(optimization, "do_vec_index_to_cond_assign") == 0) {
|
} else if (strcmp(optimization, "do_vec_index_to_cond_assign") == 0) {
|
||||||
|
Reference in New Issue
Block a user