summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>2020-12-16 14:31:32 -0800
committerDylan Baker <dylan.c.baker@intel.com>2020-12-18 13:54:49 -0800
commitd54de72aa0e8f6c0b52a235f951a032053ec53bd (patch)
tree3d1279e46bb8a5d19fc9a19d8025a6a1c3ec7a31
parenta46b833725f509ce2b8c2d33ba343ffc108a2339 (diff)
spirv: Remove more dead variables
SPIR-V modules can have multiple shaders (including of the same stage), but the global variables are all declared for the whole module. This can result in variables with same Binding but incompatible types, so those need to be removed before we use. Previously, a similar issue but with a narrower scope was fixed by 6775665e5ee ("spirv: Eliminate dead input/output variables after translation."). This patch depends on the previous patch that prevents variables used only in pointer initializers to be considered dead. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3686 Fixes: 3a266a18 ("nir/spirv: Add support for declaring variables") Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8133> (cherry picked from commit c4c9c780b131939fa10ede84e079a90fc090e17a)
-rw-r--r--.pick_status.json2
-rw-r--r--src/compiler/spirv/spirv_to_nir.c26
2 files changed, 16 insertions, 12 deletions
diff --git a/.pick_status.json b/.pick_status.json
index 85c13b49fb5..05d707607ce 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -22,7 +22,7 @@
"description": "spirv: Remove more dead variables",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "3a266a18ae5df27f78c442628a84ba2ab11dfb9d"
},
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index a5288a6032c..c0315042d88 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -5841,19 +5841,23 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
/* structurize the CFG */
nir_lower_goto_ifs(b->shader);
- /* When multiple shader stages exist in the same SPIR-V module, we
- * generate input and output variables for every stage, in the same
- * NIR program. These dead variables can be invalid NIR. For example,
- * TCS outputs must be per-vertex arrays (or decorated 'patch'), while
- * VS output variables wouldn't be.
+ /* A SPIR-V module can have multiple shaders stages and also multiple
+ * shaders of the same stage. Global variables are declared per-module, so
+ * they are all collected when parsing a single shader. These dead
+ * variables can result in invalid NIR, e.g.
*
- * To ensure we have valid NIR, we eliminate any dead inputs and outputs
- * right away. In order to do so, we must lower any constant initializers
- * on outputs so nir_remove_dead_variables sees that they're written to.
+ * - TCS outputs must be per-vertex arrays (or decorated 'patch'), while VS
+ * output variables wouldn't be;
+ * - Two vertex shaders have two different typed blocks associated to the
+ * same Binding.
+ *
+ * Before cleaning the dead variables, we must lower any constant
+ * initializers on outputs so nir_remove_dead_variables sees that they're
+ * written to.
*/
- nir_lower_variable_initializers(b->shader, nir_var_shader_out);
- nir_remove_dead_variables(b->shader,
- nir_var_shader_in | nir_var_shader_out, NULL);
+ nir_lower_variable_initializers(b->shader, nir_var_shader_out |
+ nir_var_system_value);
+ nir_remove_dead_variables(b->shader, ~nir_var_function_temp, NULL);
/* We sometimes generate bogus derefs that, while never used, give the
* validator a bit of heartburn. Run dead code to get rid of them.