From 23eb4f345490acaa39d246c7c5ea531a10c662be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 27 Oct 2024 14:46:26 -0400 Subject: [PATCH] nir: rename nir_io_glsl_opt_varyings to nir_io_dont_optimize and deprecate it The meaning is negated. This NIR option is deprecated and shouldn't be used. It means any IO optimizations can be disabled and it's a currently a workaround for zink, which is the only driver that asks for it by default. The original option is replaced by an environment variable for the GLSL linker. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/gl_nir_linker.c | 4 ++-- src/compiler/nir/nir.h | 7 +++++-- src/gallium/drivers/radeonsi/si_get.c | 2 +- src/gallium/drivers/zink/zink_compiler.c | 4 ++-- src/util/disk_cache_os.c | 5 ++++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index b9b3d70786c..752b63a3b64 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -1513,7 +1513,7 @@ gl_nir_lower_optimize_varyings(const struct gl_constants *consts, unsigned num_shaders = 0; unsigned max_ubos = UINT_MAX; unsigned max_uniform_comps = UINT_MAX; - bool optimize_io = true; + bool optimize_io = !debug_get_bool_option("MESA_GLSL_DISABLE_IO_OPT", false); for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_linked_shader *shader = prog->_LinkedShaders[i]; @@ -1532,7 +1532,7 @@ gl_nir_lower_optimize_varyings(const struct gl_constants *consts, consts->Program[i].MaxUniformComponents); max_ubos = MIN2(max_ubos, consts->Program[i].MaxUniformBlocks); num_shaders++; - optimize_io &= !!(nir->options->io_options & nir_io_glsl_opt_varyings); + optimize_io &= !(nir->options->io_options & nir_io_dont_optimize); } /* Lower IO derefs to load and store intrinsics. */ diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 59974cbe2e5..bc1054c1815 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3859,9 +3859,12 @@ typedef enum { nir_io_has_intrinsics = BITFIELD_BIT(16), /** - * Run nir_opt_varyings in the GLSL linker. + * Don't run nir_opt_varyings and nir_opt_vectorize_io. + * + * This option is deprecated and is a hack. DO NOT USE. + * Use MESA_GLSL_DISABLE_IO_OPT=1 instead. */ - nir_io_glsl_opt_varyings = BITFIELD_BIT(17), + nir_io_dont_optimize = BITFIELD_BIT(17), } nir_io_options; typedef enum { diff --git a/src/gallium/drivers/radeonsi/si_get.c b/src/gallium/drivers/radeonsi/si_get.c index e48ef6767e4..e2b3f469c7c 100644 --- a/src/gallium/drivers/radeonsi/si_get.c +++ b/src/gallium/drivers/radeonsi/si_get.c @@ -1577,7 +1577,7 @@ void si_init_screen_get_functions(struct si_screen *sscreen) */ options->force_f2f16_rtz = true; options->io_options |= (!has_mediump ? nir_io_mediump_is_32bit : 0) | nir_io_has_intrinsics | - (sscreen->options.optimize_io ? nir_io_glsl_opt_varyings : 0); + (sscreen->options.optimize_io ? 0 : nir_io_dont_optimize); options->lower_mediump_io = has_mediump ? si_lower_mediump_io : NULL; /* HW supports indirect indexing for: | Enabled in driver * ------------------------------------------------------- diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index f5564000754..48e7193cefa 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -1402,8 +1402,6 @@ zink_screen_init_compiler(struct zink_screen *screen) } if (screen->driver_compiler_workarounds.io_opt) { - screen->nir_options.io_options |= nir_io_glsl_opt_varyings; - switch (zink_driverid(screen)) { case VK_DRIVER_ID_MESA_RADV: case VK_DRIVER_ID_AMD_OPEN_SOURCE: @@ -1416,6 +1414,8 @@ zink_screen_init_compiler(struct zink_screen *screen) screen->nir_options.varying_expression_max_cost = amd_varying_expression_max_cost; screen->nir_options.varying_estimate_instr_cost = amd_varying_estimate_instr_cost; } + } else { + screen->nir_options.io_options |= nir_io_dont_optimize; } /* diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index 17a5406b196..757694ff8a9 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -1005,7 +1005,10 @@ disk_cache_enabled() "use MESA_SHADER_CACHE_DISABLE instead ***\n"); } - if (debug_get_bool_option(envvar_name, disable_by_default)) + if (debug_get_bool_option(envvar_name, disable_by_default) || + /* MESA_GLSL_DISABLE_IO_OPT must disable the cache to get expected + * results because it only takes effect on a cache miss. */ + debug_get_bool_option("MESA_GLSL_DISABLE_IO_OPT", false)) return false; return true;