Module: Mesa Branch: main Commit: b4b2fd0bb4a87346fad2ead06f218bed42c173fb URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b4b2fd0bb4a87346fad2ead06f218bed42c173fb
Author: Timothy Arceri <[email protected]> Date: Mon Oct 17 21:49:44 2022 +1100 glsl: move lower instructions logic inside that pass There is now only a single called of this pass so tidy things up and move all this logic inside the pass. Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19112> --- src/compiler/glsl/ir_optimization.h | 17 +++------------- src/compiler/glsl/lower_instructions.cpp | 34 +++++++++++++++++++++++++++++++- src/compiler/glsl/test_optpass.cpp | 2 +- src/mesa/state_tracker/st_glsl_to_ir.cpp | 22 +++------------------ 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h index feb55936e58..e4b5e391102 100644 --- a/src/compiler/glsl/ir_optimization.h +++ b/src/compiler/glsl/ir_optimization.h @@ -33,19 +33,6 @@ struct gl_linked_shader; struct gl_shader_program; -/* Operations for lower_instructions() */ -#define LDEXP_TO_ARITH 0x80 -#define DOPS_TO_DFRAC 0x800 -#define DFREXP_DLDEXP_TO_ARITH 0x1000 -#define BIT_COUNT_TO_MATH 0x02000 -#define EXTRACT_TO_SHIFTS 0x04000 -#define INSERT_TO_SHIFTS 0x08000 -#define REVERSE_TO_SHIFTS 0x10000 -#define FIND_LSB_TO_FLOAT_CAST 0x20000 -#define FIND_MSB_TO_FLOAT_CAST 0x40000 -#define IMUL_HIGH_TO_MUL 0x80000 -#define SQRT_TO_ABS_SQRT 0x200000 - /* Operations for lower_64bit_integer_instructions() */ #define DIV64 (1U << 0) #define MOD64 (1U << 1) @@ -79,7 +66,9 @@ bool do_tree_grafting(exec_list *instructions); bool do_vec_index_to_cond_assign(exec_list *instructions); bool lower_discard(exec_list *instructions); void lower_discard_flow(exec_list *instructions); -bool lower_instructions(exec_list *instructions, unsigned what_to_lower); +bool lower_instructions(exec_list *instructions, bool have_ldexp, + bool have_dfrexp, bool have_dround, + bool force_abs_sqrt, bool have_gpu_shader5); bool lower_clip_cull_distance(struct gl_shader_program *prog, gl_linked_shader *shader); bool lower_packing_builtins(exec_list *instructions, diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp index 15087191572..16d691ea595 100644 --- a/src/compiler/glsl/lower_instructions.cpp +++ b/src/compiler/glsl/lower_instructions.cpp @@ -56,6 +56,19 @@ #include <math.h> +/* Operations for lower_instructions() */ +#define LDEXP_TO_ARITH 0x80 +#define DOPS_TO_DFRAC 0x800 +#define DFREXP_DLDEXP_TO_ARITH 0x1000 +#define BIT_COUNT_TO_MATH 0x02000 +#define EXTRACT_TO_SHIFTS 0x04000 +#define INSERT_TO_SHIFTS 0x08000 +#define REVERSE_TO_SHIFTS 0x10000 +#define FIND_LSB_TO_FLOAT_CAST 0x20000 +#define FIND_MSB_TO_FLOAT_CAST 0x40000 +#define IMUL_HIGH_TO_MUL 0x80000 +#define SQRT_TO_ABS_SQRT 0x200000 + using namespace ir_builder; namespace { @@ -110,8 +123,27 @@ private: #define lowering(x) (this->lower & x) bool -lower_instructions(exec_list *instructions, unsigned what_to_lower) +lower_instructions(exec_list *instructions, bool have_ldexp, bool have_dfrexp, + bool have_dround, bool force_abs_sqrt, + bool have_gpu_shader5) { + unsigned what_to_lower = + (have_ldexp ? 0 : LDEXP_TO_ARITH) | + (have_dfrexp ? 0 : DFREXP_DLDEXP_TO_ARITH) | + (have_dround ? 0 : DOPS_TO_DFRAC) | + (force_abs_sqrt ? SQRT_TO_ABS_SQRT : 0) | + /* Assume that if ARB_gpu_shader5 is not supported then all of the + * extended integer functions need lowering. It may be necessary to add + * some caps for individual instructions. + */ + (!have_gpu_shader5 ? BIT_COUNT_TO_MATH | + EXTRACT_TO_SHIFTS | + INSERT_TO_SHIFTS | + REVERSE_TO_SHIFTS | + FIND_LSB_TO_FLOAT_CAST | + FIND_MSB_TO_FLOAT_CAST | + IMUL_HIGH_TO_MUL : 0); + lower_instructions_visitor v(what_to_lower); visit_list_elements(&v, instructions); diff --git a/src/compiler/glsl/test_optpass.cpp b/src/compiler/glsl/test_optpass.cpp index da9a8e699a4..dbed2064727 100644 --- a/src/compiler/glsl/test_optpass.cpp +++ b/src/compiler/glsl/test_optpass.cpp @@ -103,7 +103,7 @@ do_optimization(struct exec_list *ir, const char *optimization, return lower_discard(ir); } else if (sscanf(optimization, "lower_instructions ( %d ) ", &int_0) == 1) { - return lower_instructions(ir, int_0); + return lower_instructions(ir, false, false, false, false, false); } else { printf("Unrecognized optimization %s\n", optimization); exit(EXIT_FAILURE); diff --git a/src/mesa/state_tracker/st_glsl_to_ir.cpp b/src/mesa/state_tracker/st_glsl_to_ir.cpp index 3f81880f457..193936e5bd7 100644 --- a/src/mesa/state_tracker/st_glsl_to_ir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_ir.cpp @@ -83,25 +83,9 @@ link_shader(struct gl_context *ctx, struct gl_shader_program *prog) lower_blend_equation_advanced( shader, ctx->Extensions.KHR_blend_equation_advanced_coherent); - lower_instructions(ir, - (have_ldexp ? 0 : LDEXP_TO_ARITH) | - (have_dfrexp ? 0 : DFREXP_DLDEXP_TO_ARITH) | - (have_dround ? 0 : DOPS_TO_DFRAC) | - (ctx->Const.ForceGLSLAbsSqrt ? SQRT_TO_ABS_SQRT : 0) | - /* Assume that if ARB_gpu_shader5 is not supported - * then all of the extended integer functions need - * lowering. It may be necessary to add some caps - * for individual instructions. - */ - (!ctx->Extensions.ARB_gpu_shader5 - ? BIT_COUNT_TO_MATH | - EXTRACT_TO_SHIFTS | - INSERT_TO_SHIFTS | - REVERSE_TO_SHIFTS | - FIND_LSB_TO_FLOAT_CAST | - FIND_MSB_TO_FLOAT_CAST | - IMUL_HIGH_TO_MUL - : 0)); + lower_instructions(ir, have_ldexp, have_dfrexp, have_dround, + ctx->Const.ForceGLSLAbsSqrt, + ctx->Extensions.ARB_gpu_shader5); do_vec_index_to_cond_assign(ir); lower_vector_insert(ir, true);
