[Mesa-dev] [PATCH v2] gallivm: Make it possible to disable some optimization shortcuts in release builds
Roland Scheidegger
sroland at vmware.com
Fri Oct 5 21:46:51 UTC 2018
Looks alright to me. I'm not quite sold on the "safemath" name though,
since "safe math" is usually associated with floating point
optimizations, and this here is just filtering hacks. Maybe something
like disable_filtering_hacks would be more fitting?
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
On 10/05/2018 06:08 AM, Gert Wollny wrote:
> From: Gert Wollny <gert.wollny at collabora.com>
>
> For testing it is of interest that all tests of dEQP pass, e.g. to test
> virglrenderer on a host only providing software rendering like in a CI.
> Hence make it possible to disable certain optimizations that make tests fail.
>
> While we are there also add some documentation to the flags to make it clear
> that this is opt-out.
>
> Setting the environment variable "GALLIVM_PERF=disable_all" can be used to make
> the following tests pass in release mode:
>
> dEQP-GLES2.functional.texture.mipmap.2d.affine.*_linear_*
> dEQP-GLES2.functional.texture.mipmap.cube.generate.*
> dEQP-GLES2.functional.texture.vertex.2d.filtering.*_mipmap_linear_*
> dEQP-GLES2.functional.texture.vertex.2d.wrap.*
>
> Related:
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugs.freedesktop.org%2Fshow_bug.cgi%3Fid%3D94957&data=02%7C01%7Csroland%40vmware.com%7Cca786b57a0ab40daeddd08d62ac3e86d%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C1%7C0%7C636743418250432350&sdata=czSAaylr1oCdY5lsPRxB7EsVb6mPhMU2e1t1ZuhYnYk%3D&reserved=0
>
> v2: rename optimization disabling flag to 'safemath' and also move the
> nopt flag to the perf flags.
>
> Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
> ---
> src/gallium/auxiliary/gallivm/lp_bld_debug.h | 16 ++++++++-------
> src/gallium/auxiliary/gallivm/lp_bld_init.c | 25 +++++++++++++++--------
> src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 6 +++---
> src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 6 +++---
> 4 files changed, 32 insertions(+), 21 deletions(-)
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
> index f96a1afa7a..eeef0d6ba6 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_debug.h
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
> @@ -39,20 +39,22 @@
> #define GALLIVM_DEBUG_TGSI (1 << 0)
> #define GALLIVM_DEBUG_IR (1 << 1)
> #define GALLIVM_DEBUG_ASM (1 << 2)
> -#define GALLIVM_DEBUG_NO_OPT (1 << 3)
> -#define GALLIVM_DEBUG_PERF (1 << 4)
> -#define GALLIVM_DEBUG_NO_BRILINEAR (1 << 5)
> -#define GALLIVM_DEBUG_NO_RHO_APPROX (1 << 6)
> -#define GALLIVM_DEBUG_NO_QUAD_LOD (1 << 7)
> -#define GALLIVM_DEBUG_GC (1 << 8)
> -#define GALLIVM_DEBUG_DUMP_BC (1 << 9)
> +#define GALLIVM_DEBUG_PERF (1 << 3)
> +#define GALLIVM_DEBUG_GC (1 << 4)
> +#define GALLIVM_DEBUG_DUMP_BC (1 << 5)
>
> +#define GALLIVM_PERF_NO_BRILINEAR (1 << 0)
> +#define GALLIVM_PERF_NO_RHO_APPROX (1 << 1)
> +#define GALLIVM_PERF_NO_QUAD_LOD (1 << 2)
> +#define GALLIVM_PERF_NO_OPT (1 << 3)
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
>
> +extern unsigned gallivm_perf;
> +
> #ifdef DEBUG
> extern unsigned gallivm_debug;
> #else
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
> index 1f0a01cde6..3f7c4d3154 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
> @@ -59,6 +59,17 @@ static const bool use_mcjit = USE_MCJIT;
> static bool use_mcjit = FALSE;
> #endif
>
> +unsigned gallivm_perf = 0;
> +
> +static const struct debug_named_value lp_bld_perf_flags[] = {
> + { "no_brilinear", GALLIVM_PERF_NO_BRILINEAR, "disable brilinear optimization" },
> + { "no_rho_approx", GALLIVM_PERF_NO_RHO_APPROX, "disable rho_approx optimization" },
> + { "no_quad_lod", GALLIVM_PERF_NO_QUAD_LOD, "disable quad_lod optimization" },
> + { "nopt", GALLIVM_PERF_NO_OPT, "disable optimization passes to speed up shader compilation" },
> + { "safemath", GALLIVM_PERF_NO_BRILINEAR | GALLIVM_PERF_NO_RHO_APPROX |
> + GALLIVM_PERF_NO_QUAD_LOD, "disable unsafe optimizations" },
> + DEBUG_NAMED_VALUE_END
> +};
>
> #ifdef DEBUG
> unsigned gallivm_debug = 0;
> @@ -67,11 +78,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
> { "tgsi", GALLIVM_DEBUG_TGSI, NULL },
> { "ir", GALLIVM_DEBUG_IR, NULL },
> { "asm", GALLIVM_DEBUG_ASM, NULL },
> - { "nopt", GALLIVM_DEBUG_NO_OPT, NULL },
> { "perf", GALLIVM_DEBUG_PERF, NULL },
> - { "no_brilinear", GALLIVM_DEBUG_NO_BRILINEAR, NULL },
> - { "no_rho_approx", GALLIVM_DEBUG_NO_RHO_APPROX, NULL },
> - { "no_quad_lod", GALLIVM_DEBUG_NO_QUAD_LOD, NULL },
> { "gc", GALLIVM_DEBUG_GC, NULL },
> { "dumpbc", GALLIVM_DEBUG_DUMP_BC, NULL },
> DEBUG_NAMED_VALUE_END
> @@ -136,7 +143,7 @@ create_pass_manager(struct gallivm_state *gallivm)
> free(td_str);
> }
>
> - if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
> + if ((gallivm_perf & GALLIVM_PERF_NO_OPT) == 0) {
> /*
> * TODO: Evaluate passes some more - keeping in mind
> * both quality of generated code and compile times.
> @@ -240,7 +247,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
> char *error = NULL;
> int ret;
>
> - if (gallivm_debug & GALLIVM_DEBUG_NO_OPT) {
> + if (gallivm_perf & GALLIVM_PERF_NO_OPT) {
> optlevel = None;
> }
> else {
> @@ -420,6 +427,8 @@ lp_build_init(void)
> gallivm_debug = debug_get_option_gallivm_debug();
> #endif
>
> + gallivm_perf = debug_get_flags_option("GALLIVM_PERF", lp_bld_perf_flags, 0 );
> +
> lp_set_target_options();
>
> util_cpu_detect();
> @@ -589,10 +598,10 @@ gallivm_compile_module(struct gallivm_state *gallivm)
> LLVMWriteBitcodeToFile(gallivm->module, filename);
> debug_printf("%s written\n", filename);
> debug_printf("Invoke as \"opt %s %s | llc -O%d %s%s\"\n",
> - gallivm_debug & GALLIVM_DEBUG_NO_OPT ? "-mem2reg" :
> + gallivm_debug & GALLIVM_PERF_NO_OPT ? "-mem2reg" :
> "-sroa -early-cse -simplifycfg -reassociate "
> "-mem2reg -constprop -instcombine -gvn",
> - filename, gallivm_debug & GALLIVM_DEBUG_NO_OPT ? 0 : 2,
> + filename, gallivm_debug & GALLIVM_PERF_NO_OPT ? 0 : 2,
> (HAVE_LLVM >= 0x0305) ? "[-mcpu=<-mcpu option>] " : "",
> "[-mattr=<-mattr option(s)>]");
> }
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> index 8f760f59fe..018cca8f9d 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> @@ -2825,13 +2825,13 @@ lp_build_sample_soa_code(struct gallivm_state *gallivm,
> bld.format_desc = util_format_description(static_texture_state->format);
> bld.dims = dims;
>
> - if (gallivm_debug & GALLIVM_DEBUG_NO_QUAD_LOD || op_is_lodq) {
> + if (gallivm_perf & GALLIVM_PERF_NO_QUAD_LOD || op_is_lodq) {
> bld.no_quad_lod = TRUE;
> }
> - if (gallivm_debug & GALLIVM_DEBUG_NO_RHO_APPROX || op_is_lodq) {
> + if (gallivm_perf & GALLIVM_PERF_NO_RHO_APPROX || op_is_lodq) {
> bld.no_rho_approx = TRUE;
> }
> - if (gallivm_debug & GALLIVM_DEBUG_NO_BRILINEAR || op_is_lodq) {
> + if (gallivm_perf & GALLIVM_PERF_NO_BRILINEAR || op_is_lodq) {
> bld.no_brilinear = TRUE;
> }
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> index 79ece639e3..5fecad4ea6 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
> @@ -2037,7 +2037,7 @@ lp_build_lod_property(
> lod_property = LP_SAMPLER_LOD_SCALAR;
> }
> else if (bld_base->info->processor == PIPE_SHADER_FRAGMENT) {
> - if (gallivm_debug & GALLIVM_DEBUG_NO_QUAD_LOD) {
> + if (gallivm_perf & GALLIVM_PERF_NO_QUAD_LOD) {
> lod_property = LP_SAMPLER_LOD_PER_ELEMENT;
> }
> else {
> @@ -2225,7 +2225,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
> * cases exist in practice.
> */
> if (bld->bld_base.info->processor == PIPE_SHADER_FRAGMENT) {
> - if (gallivm_debug & GALLIVM_DEBUG_NO_QUAD_LOD) {
> + if (gallivm_perf & GALLIVM_PERF_NO_QUAD_LOD) {
> lod_property = LP_SAMPLER_LOD_PER_ELEMENT;
> }
> else {
> @@ -2394,7 +2394,7 @@ emit_sample(struct lp_build_tgsi_soa_context *bld,
> * cases exist in practice.
> */
> if (bld->bld_base.info->processor == PIPE_SHADER_FRAGMENT) {
> - if (gallivm_debug & GALLIVM_DEBUG_NO_QUAD_LOD) {
> + if (gallivm_perf & GALLIVM_PERF_NO_QUAD_LOD) {
> lod_property = LP_SAMPLER_LOD_PER_ELEMENT;
> }
> else {
>
More information about the mesa-dev
mailing list