From ec10a37a5266321dd01bfe336a3c900a1c1f9f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Mon, 13 Jun 2022 14:26:17 +0200 Subject: [PATCH] broadcom/compiler: don't call nir_opt_load_store_vectorize on all v3d_optimize_nir calls For compute shaders, to avoid a crash with that optimization, it requires doing some optimizations and lowerings before. Example: static void lower_cs_shared(struct nir_shader *nir) { NIR_PASS_V(nir, nir_lower_vars_to_explicit_types, nir_var_mem_shared, shared_type_info); NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_shared, nir_address_format_32bit_offset); } In the same way other drivers (like anv) calls nir_opt_load_store_vectorize as part of their post-process-nir. So one option would be to move nir_opt_load_store_vectorize outsize the common v3d_nir_optimize, to a post-process nir method. To make things simpler, this change calls that optimization only if we have a v3d_compiler object, that is when each frontend has already done their lowerings, and call the v3d_compiler to get the final assembly (so we are already on a kind of post processing nir step). This avoids dEQP-VK.memory_model.shared.basic_types.3 crashing if we start to call v3d_optimize_nir on v3dv directly. Slight shaderdb changes, but not significant. Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/compiler/nir_to_vir.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index bfcee6218e5..af1b2d241eb 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -2164,12 +2164,22 @@ v3d_optimize_nir(struct v3d_compile *c, struct nir_shader *s) .robust_modes = 0, }; bool vectorize_progress = false; - NIR_PASS(vectorize_progress, s, nir_opt_load_store_vectorize, - &vectorize_opts); - if (vectorize_progress) { - NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL, NULL); - NIR_PASS(progress, s, nir_lower_pack); - progress = true; + + + /* This requires that we have called + * nir_lower_vars_to_explicit_types / nir_lower_explicit_io + * first, which we may not have done yet if we call here too + * early durign NIR pre-processing. We can detect this because + * in that case we won't have a compile object + */ + if (c) { + NIR_PASS(vectorize_progress, s, nir_opt_load_store_vectorize, + &vectorize_opts); + if (vectorize_progress) { + NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL, NULL); + NIR_PASS(progress, s, nir_lower_pack); + progress = true; + } } if (lower_flrp != 0) {