diff options
-rw-r--r-- | src/compiler/clc/clc.c | 32 | ||||
-rw-r--r-- | src/compiler/clc/nir_clc_helpers.h | 3 | ||||
-rw-r--r-- | src/compiler/clc/nir_load_libclc.c | 34 | ||||
-rw-r--r-- | src/gallium/frontends/clover/nir/invocation.cpp | 3 | ||||
-rw-r--r-- | src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs | 8 | ||||
-rw-r--r-- | src/intel/compiler/brw_kernel.c | 3 |
6 files changed, 47 insertions, 36 deletions
diff --git a/src/compiler/clc/clc.c b/src/compiler/clc/clc.c index 29d207d7d56..4d2c39ee7b6 100644 --- a/src/compiler/clc/clc.c +++ b/src/compiler/clc/clc.c @@ -88,31 +88,6 @@ clc_print_kernels_info(const struct clc_parsed_spirv *obj) } } -static void -clc_libclc_optimize(nir_shader *s) -{ - bool progress; - do { - progress = false; - NIR_PASS(progress, s, nir_split_var_copies); - NIR_PASS(progress, s, nir_opt_copy_prop_vars); - NIR_PASS(progress, s, nir_lower_var_copies); - NIR_PASS(progress, s, nir_lower_vars_to_ssa); - NIR_PASS(progress, s, nir_copy_prop); - NIR_PASS(progress, s, nir_opt_remove_phis); - NIR_PASS(progress, s, nir_opt_dce); - NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false); - NIR_PASS(progress, s, nir_opt_dead_cf); - NIR_PASS(progress, s, nir_opt_cse); - NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true); - NIR_PASS(progress, s, nir_opt_algebraic); - NIR_PASS(progress, s, nir_opt_constant_folding); - NIR_PASS(progress, s, nir_opt_undef); - NIR_PASS(progress, s, nir_lower_undef_to_zero); - NIR_PASS(progress, s, nir_opt_deref); - } while (progress); -} - struct clc_libclc { const nir_shader *libclc_nir; }; @@ -145,16 +120,15 @@ clc_libclc_new(const struct clc_logger *logger, const struct clc_libclc_options }; glsl_type_singleton_init_or_ref(); - nir_shader *s = nir_load_libclc_shader(64, NULL, &libclc_spirv_options, options->nir_options); + bool optimize = options && options->optimize; + nir_shader *s = + nir_load_libclc_shader(64, NULL, &libclc_spirv_options, options->nir_options, optimize); if (!s) { clc_error(logger, "D3D12: spirv_to_nir failed on libclc blob"); ralloc_free(ctx); return NULL; } - if (options && options->optimize) - clc_libclc_optimize(s); - ralloc_steal(ctx, s); ctx->libclc_nir = s; diff --git a/src/compiler/clc/nir_clc_helpers.h b/src/compiler/clc/nir_clc_helpers.h index 02a69ae5df4..922456037d6 100644 --- a/src/compiler/clc/nir_clc_helpers.h +++ b/src/compiler/clc/nir_clc_helpers.h @@ -21,7 +21,8 @@ nir_shader * nir_load_libclc_shader(unsigned ptr_bit_size, struct disk_cache *disk_cache, const struct spirv_to_nir_options *spirv_options, - const nir_shader_compiler_options *nir_options); + const nir_shader_compiler_options *nir_options, + bool optimize); bool nir_lower_libclc(nir_shader *shader, const nir_shader *clc_shader); diff --git a/src/compiler/clc/nir_load_libclc.c b/src/compiler/clc/nir_load_libclc.c index c1469313a85..4472f744754 100644 --- a/src/compiler/clc/nir_load_libclc.c +++ b/src/compiler/clc/nir_load_libclc.c @@ -304,7 +304,8 @@ nir_shader * nir_load_libclc_shader(unsigned ptr_bit_size, struct disk_cache *disk_cache, const struct spirv_to_nir_options *spirv_options, - const nir_shader_compiler_options *nir_options) + const nir_shader_compiler_options *nir_options, + bool optimize) { assert(ptr_bit_size == nir_address_format_bit_size(spirv_options->global_addr_format)); @@ -356,9 +357,36 @@ nir_load_libclc_shader(unsigned ptr_bit_size, NIR_PASS_V(nir, libclc_add_generic_variants); - /* TODO: One day, we may want to run some optimizations on the libclc - * shader once and cache them to save time in each shader call. + /* Run some optimization passes. Those used here should be considered safe + * for all use cases and drivers. */ + if (optimize) { + NIR_PASS_V(nir, nir_split_var_copies); + + bool progress; + do { + progress = false; + NIR_PASS(progress, nir, nir_opt_copy_prop_vars); + NIR_PASS(progress, nir, nir_lower_var_copies); + NIR_PASS(progress, nir, nir_lower_vars_to_ssa); + NIR_PASS(progress, nir, nir_copy_prop); + NIR_PASS(progress, nir, nir_opt_remove_phis); + NIR_PASS(progress, nir, nir_opt_dce); + NIR_PASS(progress, nir, nir_opt_if, false); + NIR_PASS(progress, nir, nir_opt_dead_cf); + NIR_PASS(progress, nir, nir_opt_cse); + /* drivers run this pass, so don't be too aggressive. More aggressive + * values only increase effectiveness by <5% + */ + NIR_PASS(progress, nir, nir_opt_peephole_select, 0, false, false); + NIR_PASS(progress, nir, nir_opt_algebraic); + NIR_PASS(progress, nir, nir_opt_constant_folding); + NIR_PASS(progress, nir, nir_opt_undef); + NIR_PASS(progress, nir, nir_opt_deref); + } while(progress); + + nir_sweep(nir); + } #ifdef ENABLE_SHADER_CACHE if (disk_cache) { diff --git a/src/gallium/frontends/clover/nir/invocation.cpp b/src/gallium/frontends/clover/nir/invocation.cpp index 9b62529d1a6..f3bcc982f8d 100644 --- a/src/gallium/frontends/clover/nir/invocation.cpp +++ b/src/gallium/frontends/clover/nir/invocation.cpp @@ -257,7 +257,8 @@ nir_shader *clover::nir::load_libclc_nir(const device &dev, std::string &r_log) auto *compiler_options = dev_get_nir_compiler_options(dev); return nir_load_libclc_shader(dev.address_bits(), dev.clc_cache, - &spirv_options, compiler_options); + &spirv_options, compiler_options, + dev.clc_cache != nullptr); } static bool diff --git a/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs b/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs index 802d712db96..43656dcd692 100644 --- a/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs +++ b/src/gallium/frontends/rusticl/mesa/compiler/clc/spirv.rs @@ -379,7 +379,13 @@ impl SPIRVBin { let shader_cache = DiskCacheBorrowed::as_ptr(&screen.shader_cache()); NirShader::new(unsafe { - nir_load_libclc_shader(address_bits, shader_cache, &spirv_options, nir_options) + nir_load_libclc_shader( + address_bits, + shader_cache, + &spirv_options, + nir_options, + true, + ) }) } diff --git a/src/intel/compiler/brw_kernel.c b/src/intel/compiler/brw_kernel.c index 3945ad35b08..13e8bee0827 100644 --- a/src/intel/compiler/brw_kernel.c +++ b/src/intel/compiler/brw_kernel.c @@ -39,7 +39,8 @@ load_clc_shader(struct brw_compiler *compiler, struct disk_cache *disk_cache, return compiler->clc_shader; nir_shader *nir = nir_load_libclc_shader(64, disk_cache, - spirv_options, nir_options); + spirv_options, nir_options, + disk_cache != NULL); if (nir == NULL) return NULL; |